From 6e3a0fc66903559fa8f9a6c9dbab0d76d5fe4fb6 Mon Sep 17 00:00:00 2001 From: Henri Chataing Date: Fri, 31 Jan 2025 13:45:38 -0800 Subject: [PATCH] Sync with aosp main Synchronized to packages/modules/Bluetooth commit b6245f8beee5e87e66659d54136bc9714826585f Changelist: - Set support for APCF Transport Discovery Service filter to false - Use Jacobian Coordinates in Point implementation - Use pow for consistency - Do not report an invalid packet for unsupported LE Apcf Transport Discovert Service command - Send well formatted Apcf command complete event - Update to pdl 0.3.0 - Typo in LE Apcf Transport Discovery Data command handling - Reset APCF scanner in LinkLayerController::Reset() - Set the default value of acl_data_packet_length to 1023 - Encryption Change V2 - Implement the command LE Read Local P-256 Public Key - Add Authenticated Payload Timeout Expired event - Update to Core version 6.0 - Update build.rs to directly use the pdl_compiler library - Add INTEL_BE200 controller preset - Update controller_info.py script --- .github/workflows/avatar.yml | 2 +- .github/workflows/build.yml | 4 +- BUILD | 138 +- MODULE.bazel | 2 +- desktop/root_canal_main.cc | 25 +- desktop/test_environment.cc | 193 +- desktop/test_environment.h | 69 +- include/crypto/crypto.h | 3 +- include/hci/address.h | 25 +- include/hci/address_with_type.h | 23 +- include/hci/pcap_filter.h | 53 +- include/log.h | 67 +- include/phy.h | 2 +- lib/hci/address.cc | 11 +- lib/hci/pcap_filter.cc | 191 +- lib/log.cc | 38 +- model/controller/acl_connection.cc | 21 +- model/controller/acl_connection.h | 11 +- model/controller/acl_connection_handler.cc | 116 +- model/controller/acl_connection_handler.h | 46 +- model/controller/controller_properties.cc | 1425 +++---- model/controller/controller_properties.h | 9 +- model/controller/dual_mode_controller.cc | 3548 ++++++++--------- model/controller/dual_mode_controller.h | 62 +- model/controller/ffi.cc | 87 +- model/controller/ffi.h | 14 +- model/controller/le_advertiser.cc | 520 +-- model/controller/le_advertiser.h | 40 +- model/controller/link_layer_controller.cc | 2708 ++++++------- model/controller/link_layer_controller.h | 634 ++- model/controller/sco_connection.cc | 133 +- model/controller/sco_connection.h | 16 +- model/controller/vendor_commands/le_apcf.cc | 372 +- model/controller/vendor_commands/le_apcf.h | 3 +- model/devices/baseband_sniffer.cc | 94 +- model/devices/baseband_sniffer.h | 13 +- model/devices/beacon.cc | 37 +- model/devices/beacon.h | 11 +- model/devices/beacon_swarm.cc | 56 +- model/devices/beacon_swarm.h | 4 +- model/devices/device.cc | 16 +- model/devices/device.h | 20 +- model/devices/hci_device.cc | 98 +- model/devices/hci_device.h | 12 +- model/devices/link_layer_socket_device.cc | 15 +- model/devices/link_layer_socket_device.h | 20 +- model/devices/scripted_beacon.cc | 116 +- model/devices/scripted_beacon.h | 23 +- model/devices/sniffer.cc | 10 +- model/devices/sniffer.h | 9 +- model/hci/h4_data_channel_packetizer.cc | 20 +- model/hci/h4_data_channel_packetizer.h | 12 +- model/hci/h4_parser.cc | 32 +- model/hci/h4_parser.h | 18 +- model/hci/hci_sniffer.cc | 29 +- model/hci/hci_sniffer.h | 20 +- model/hci/hci_socket_transport.cc | 54 +- model/hci/hci_socket_transport.h | 13 +- model/hci/hci_transport.h | 11 +- model/setup/async_manager.cc | 132 +- model/setup/async_manager.h | 10 +- model/setup/device_boutique.cc | 17 +- model/setup/device_boutique.h | 13 +- model/setup/phy_device.cc | 22 +- model/setup/phy_device.h | 9 +- model/setup/phy_layer.cc | 6 +- model/setup/phy_layer.h | 7 +- model/setup/test_channel_transport.cc | 38 +- model/setup/test_channel_transport.h | 21 +- model/setup/test_command_handler.cc | 60 +- model/setup/test_command_handler.h | 12 +- model/setup/test_model.cc | 103 +- model/setup/test_model.h | 71 +- net/async_data_channel.h | 5 +- net/async_data_channel_connector.h | 5 +- net/async_data_channel_server.h | 12 +- net/posix/posix_async_socket.cc | 18 +- net/posix/posix_async_socket.h | 7 +- net/posix/posix_async_socket_connector.cc | 41 +- net/posix/posix_async_socket_connector.h | 7 +- net/posix/posix_async_socket_server.cc | 21 +- net/posix/posix_async_socket_server.h | 6 +- packets/hci_packets.pdl | 1133 +++++- proto/rootcanal/configuration.proto | 2 + rust/Cargo.toml | 5 +- rust/build.rs | 39 +- rust/include/rootcanal_rs.h | 35 +- rust/src/llcp/iso.rs | 10 +- rust/src/lmp/ec.rs | 141 +- rust/src/lmp/manager.rs | 8 +- rust/src/lmp/procedure/mod.rs | 5 +- scripts/controller_info.py | 62 +- test/HCI/AEN/BV_06_C.py | 51 + test/LL/CIS/CEN/BV_01_C.py | 32 +- test/LL/CIS/CEN/BV_03_C.py | 4 +- test/LL/CIS/CEN/BV_10_C.py | 64 +- test/LL/CIS/CEN/BV_26_C.py | 64 +- test/LL/CIS/PER/BV_01_C.py | 32 +- test/LL/CON_/CEN/BV_41_C.py | 57 +- test/LL/CON_/CEN/BV_43_C.py | 57 +- test/LL/CON_/INI/BV_08_C.py | 20 +- test/LL/CON_/INI/BV_09_C.py | 22 +- test/LL/CON_/INI/BV_10_C.py | 20 +- test/LL/CON_/INI/BV_11_C.py | 22 +- test/LL/CON_/PER/BV_40_C.py | 18 +- test/LL/CON_/PER/BV_42_C.py | 18 +- test/LL/DDI/ADV/BV_06_C.py | 18 +- test/LL/DDI/ADV/BV_07_C.py | 18 +- test/LL/DDI/ADV/BV_09_C.py | 4 +- test/LL/DDI/ADV/BV_11_C.py | 35 +- test/LL/DDI/ADV/BV_19_C.py | 18 +- test/LL/DDI/ADV/BV_21_C.py | 14 +- test/LL/DDI/ADV/BV_22_C.py | 14 +- test/LL/DDI/ADV/BV_26_C.py | 29 +- test/LL/DDI/ADV/BV_47_C.py | 21 +- test/LL/DDI/SCN/BV_79_C.py | 14 +- test/LL/SEC/ADV/BV_11_C.py | 2 +- test/async_manager_unittest.cc | 113 +- ...e_add_device_to_filter_accept_list_test.cc | 62 +- ...device_to_periodic_advertiser_list_test.cc | 40 +- .../le_add_device_to_resolving_list_test.cc | 73 +- .../le/le_clear_filter_accept_list_test.cc | 55 +- .../le_clear_periodic_advertiser_list_test.cc | 19 +- .../le/le_clear_resolving_list_test.cc | 33 +- .../le/le_create_connection_cancel_test.cc | 28 +- .../le/le_create_connection_test.cc | 153 +- .../le/le_extended_create_connection_test.cc | 332 +- ...dic_advertising_create_sync_cancel_test.cc | 16 +- ...e_periodic_advertising_create_sync_test.cc | 62 +- ...ove_device_from_filter_accept_list_test.cc | 70 +- ...vice_from_periodic_advertiser_list_test.cc | 28 +- ..._remove_device_from_resolving_list_test.cc | 47 +- .../le/le_scanning_filter_duplicates_test.cc | 94 +- .../le_set_address_resolution_enable_test.cc | 38 +- .../le/le_set_advertising_enable_test.cc | 51 +- .../le/le_set_advertising_parameters_test.cc | 60 +- .../le_set_extended_advertising_data_test.cc | 305 +- ...le_set_extended_advertising_enable_test.cc | 284 +- ...et_extended_advertising_parameters_test.cc | 314 +- .../le/le_set_extended_scan_enable_test.cc | 120 +- .../le_set_extended_scan_parameters_test.cc | 78 +- ...le_set_extended_scan_response_data_test.cc | 345 +- .../le_set_periodic_advertising_data_test.cc | 228 +- ...le_set_periodic_advertising_enable_test.cc | 98 +- ...et_periodic_advertising_parameters_test.cc | 148 +- .../le/le_set_random_address_test.cc | 23 +- test/controller/le/le_set_scan_enable_test.cc | 51 +- .../le/le_set_scan_parameters_test.cc | 67 +- test/controller/le/rpa_generation_test.cc | 5 +- test/controller/le/test_helpers.h | 19 +- test/h4_parser_unittest.cc | 64 +- test/invalid_packet_handler_unittest.cc | 36 +- test/main.py | 1 + test/pcap_filter_unittest.cc | 56 +- test/posix_socket_unittest.cc | 53 +- 155 files changed, 8352 insertions(+), 9442 deletions(-) create mode 100644 test/HCI/AEN/BV_06_C.py diff --git a/.github/workflows/avatar.yml b/.github/workflows/avatar.yml index 7f1a8f9..e7030c0 100644 --- a/.github/workflows/avatar.yml +++ b/.github/workflows/avatar.yml @@ -37,7 +37,7 @@ jobs: python -m pip install pandora-avatar - name: Rootcanal run: | - cargo install pdl-compiler --version 0.2.2 + cargo install pdl-compiler --version 0.3.2 bazel build :rootcanal - name: Test run: | diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 001228a..372fecc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ jobs: - name: Install dependencies run: | - cargo install pdl-compiler --version 0.2.2 + cargo install pdl-compiler --version 0.3.2 - name: Build run: | @@ -65,7 +65,7 @@ jobs: - name: Install dependencies run: | - cargo install pdl-compiler --version 0.2.2 + cargo install pdl-compiler --version 0.3.2 python3 -m pip install hatch - name: Set VERSION diff --git a/BUILD b/BUILD index f6f35a9..6775c02 100644 --- a/BUILD +++ b/BUILD @@ -34,21 +34,21 @@ cc_proto_library( genrule( name = "lmp_packets_rs", - cmd = "pdlc --output-format rust $(location rust/lmp_packets.pdl) > $(location lmp_packets.rs)", + cmd = "pdlc --output-format rust_legacy $(location rust/lmp_packets.pdl) > $(location lmp_packets.rs)", outs = ["lmp_packets.rs"], srcs = ["rust/lmp_packets.pdl"], ) genrule( name = "llcp_packets_rs", - cmd = "pdlc --output-format rust $(location rust/llcp_packets.pdl) > $(location llcp_packets.rs)", + cmd = "pdlc --output-format rust_legacy $(location rust/llcp_packets.pdl) > $(location llcp_packets.rs)", outs = ["llcp_packets.rs"], srcs = ["rust/llcp_packets.pdl"], ) genrule( name = "hci_packets_rs", - cmd = "pdlc --output-format rust $(location //packets:hci_packets.pdl) > $(location hci_packets.rs)", + cmd = "pdlc --output-format rust_legacy $(location //packets:hci_packets.pdl) > $(location hci_packets.rs)", outs = ["hci_packets.rs"], srcs = ["//packets:hci_packets.pdl"], visibility = ["//visibility:public"], @@ -103,10 +103,10 @@ rust_static_library( ], ) -cc_library( - name = "rootcanal_lib", +cc_binary( + name = "librootcanal_ffi.so", + linkopts = ["-shared"], srcs = [ - "desktop/test_environment.cc", "include/crypto/crypto.h", "include/hci/address.h", "include/hci/address_with_type.h", @@ -116,7 +116,6 @@ cc_library( "include/phy.h", "lib/crypto/crypto.cc", "lib/hci/address.cc", - "lib/hci/pcap_filter.cc", "model/controller/acl_connection.cc", "model/controller/acl_connection.h", "model/controller/acl_connection_handler.cc", @@ -134,58 +133,12 @@ cc_library( "model/controller/vendor_commands/csr.h", "model/controller/vendor_commands/le_apcf.cc", "model/controller/vendor_commands/le_apcf.h", - "model/devices/baseband_sniffer.cc", - "model/devices/baseband_sniffer.h", - "model/devices/beacon.cc", - "model/devices/beacon.h", - "model/devices/beacon_swarm.cc", - "model/devices/beacon_swarm.h", + "model/controller/ffi.cc", + "model/controller/ffi.h", "model/devices/device.cc", "model/devices/device.h", - "model/devices/hci_device.cc", - "model/devices/hci_device.h", - "model/devices/link_layer_socket_device.cc", - "model/devices/link_layer_socket_device.h", - "model/devices/sniffer.cc", - "model/devices/sniffer.h", - "model/hci/h4.h", - "model/hci/h4_data_channel_packetizer.cc", - "model/hci/h4_data_channel_packetizer.h", - "model/hci/h4_parser.cc", - "model/hci/h4_parser.h", - "model/hci/hci_sniffer.cc", - "model/hci/hci_sniffer.h", - "model/hci/hci_socket_transport.cc", - "model/hci/hci_socket_transport.h", - "model/hci/hci_transport.h", - "model/setup/async_manager.cc", - "model/setup/device_boutique.cc", - "model/setup/device_boutique.h", - "model/setup/phy_device.cc", - "model/setup/phy_device.h", - "model/setup/phy_layer.cc", - "model/setup/phy_layer.h", - "model/setup/test_channel_transport.cc", - "model/setup/test_channel_transport.h", - "model/setup/test_command_handler.cc", - "model/setup/test_command_handler.h", - "model/setup/test_model.cc", - "model/setup/test_model.h", - "net/async_data_channel.h", - "net/async_data_channel_connector.h", - "net/async_data_channel_server.h", - "net/posix/posix_async_socket.cc", - "net/posix/posix_async_socket.h", - "net/posix/posix_async_socket_connector.cc", - "net/posix/posix_async_socket_server.cc", "rust/include/rootcanal_rs.h", ], - hdrs = [ - "desktop/test_environment.h", - "model/setup/async_manager.h", - "net/posix/posix_async_socket_connector.h", - "net/posix/posix_async_socket_server.h", - ], copts = [ "-std=c++17", "-Wno-c99-designator", @@ -210,16 +163,18 @@ cc_library( ":rootcanal_log", ":rootcanal_rs", "//packets:generated", + "@pdl//:packet_runtime", "@fmtlib", "@openssl//:crypto", - "@pdl//:packet_runtime", ], ) cc_binary( - name = "librootcanal_ffi.so", - linkopts = ["-shared"], + name = "rootcanal", srcs = [ + "desktop/root_canal_main.cc", + "desktop/test_environment.cc", + "desktop/test_environment.h", "include/crypto/crypto.h", "include/hci/address.h", "include/hci/address_with_type.h", @@ -229,6 +184,7 @@ cc_binary( "include/phy.h", "lib/crypto/crypto.cc", "lib/hci/address.cc", + "lib/hci/pcap_filter.cc", "model/controller/acl_connection.cc", "model/controller/acl_connection.h", "model/controller/acl_connection_handler.cc", @@ -246,10 +202,53 @@ cc_binary( "model/controller/vendor_commands/csr.h", "model/controller/vendor_commands/le_apcf.cc", "model/controller/vendor_commands/le_apcf.h", - "model/controller/ffi.cc", - "model/controller/ffi.h", + "model/devices/baseband_sniffer.cc", + "model/devices/baseband_sniffer.h", + "model/devices/beacon.cc", + "model/devices/beacon.h", + "model/devices/beacon_swarm.cc", + "model/devices/beacon_swarm.h", "model/devices/device.cc", "model/devices/device.h", + "model/devices/hci_device.cc", + "model/devices/hci_device.h", + "model/devices/link_layer_socket_device.cc", + "model/devices/link_layer_socket_device.h", + "model/devices/sniffer.cc", + "model/devices/sniffer.h", + "model/hci/h4.h", + "model/hci/h4_data_channel_packetizer.cc", + "model/hci/h4_data_channel_packetizer.h", + "model/hci/h4_parser.cc", + "model/hci/h4_parser.h", + "model/hci/hci_sniffer.cc", + "model/hci/hci_sniffer.h", + "model/hci/hci_socket_transport.cc", + "model/hci/hci_socket_transport.h", + "model/hci/hci_transport.h", + "model/setup/async_manager.cc", + "model/setup/async_manager.h", + "model/setup/device_boutique.cc", + "model/setup/device_boutique.h", + "model/setup/phy_device.cc", + "model/setup/phy_device.h", + "model/setup/phy_layer.cc", + "model/setup/phy_layer.h", + "model/setup/test_channel_transport.cc", + "model/setup/test_channel_transport.h", + "model/setup/test_command_handler.cc", + "model/setup/test_command_handler.h", + "model/setup/test_model.cc", + "model/setup/test_model.h", + "net/async_data_channel.h", + "net/async_data_channel_connector.h", + "net/async_data_channel_server.h", + "net/posix/posix_async_socket.cc", + "net/posix/posix_async_socket.h", + "net/posix/posix_async_socket_connector.cc", + "net/posix/posix_async_socket_connector.h", + "net/posix/posix_async_socket_server.cc", + "net/posix/posix_async_socket_server.h", "rust/include/rootcanal_rs.h", ], copts = [ @@ -276,27 +275,12 @@ cc_binary( ":rootcanal_log", ":rootcanal_rs", "//packets:generated", - "@pdl//:packet_runtime", + "@gflags", "@fmtlib", "@openssl//:crypto", + "@pdl//:packet_runtime", ], -) - -cc_binary( - name = "rootcanal", - srcs = ["desktop/root_canal_main.cc"], - copts = ["-std=c++17"], # TODO enable thin_lto # breaks the device registration # features = ["-thin_lto"], - visibility = ["//visibility:public"], - deps = [ - ":rootcanal_lib", - ":rootcanal_config", - ":rootcanal_log", - ":rootcanal_rs", - "@gflags", - "@fmtlib", - "@openssl//:crypto", - ], ) diff --git a/MODULE.bazel b/MODULE.bazel index a72cfa8..c888365 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -37,7 +37,7 @@ crate.spec(package = "num-derive", version = "0.3.3") crate.spec(package = "num-integer", version = "0.1.45") crate.spec(package = "num-traits", version = "0.2.14") crate.spec(package = "paste", version = "1.0.4") -crate.spec(package = "pdl-runtime", version = "0.2.2") +crate.spec(package = "pdl-runtime", version = "0.3.2") crate.spec(package = "pin-utils", version = "0.1.0") crate.spec(package = "rand", version = "0.8.3") crate.spec(package = "thiserror", version = "1.0.23") diff --git a/desktop/root_canal_main.cc b/desktop/root_canal_main.cc index 1144729..f6366c9 100644 --- a/desktop/root_canal_main.cc +++ b/desktop/root_canal_main.cc @@ -40,15 +40,13 @@ using namespace rootcanal; DEFINE_string(controller_properties_file, "", "deprecated"); DEFINE_string(configuration, "", "controller configuration (see config.proto)"); -DEFINE_string(configuration_file, "", - "controller configuration file path (see config.proto)"); +DEFINE_string(configuration_file, "", "controller configuration file path (see config.proto)"); DEFINE_string(default_commands_file, "", "deprecated"); DEFINE_bool(enable_log_color, false, "enable log colors"); DEFINE_bool(enable_hci_sniffer, false, "enable hci sniffer"); DEFINE_bool(enable_baseband_sniffer, false, "enable baseband sniffer"); DEFINE_bool(enable_pcap_filter, false, "enable PCAP filter"); -DEFINE_bool(disable_address_reuse, false, - "prevent rootcanal from reusing device addresses"); +DEFINE_bool(disable_address_reuse, false, "prevent rootcanal from reusing device addresses"); DEFINE_uint32(test_port, 6401, "test tcp port"); DEFINE_uint32(hci_port, 6402, "hci server tcp port"); DEFINE_uint32(link_port, 6403, "link server tcp port"); @@ -95,17 +93,14 @@ int main(int argc, char** argv) { } TestEnvironment root_canal( - [](AsyncManager* am, int port) { - return std::make_shared(port, am); - }, - [](AsyncManager* am) { - return std::make_shared(am); - }, - static_cast(FLAGS_test_port), static_cast(FLAGS_hci_port), - static_cast(FLAGS_link_port), static_cast(FLAGS_link_ble_port), - configuration_str, FLAGS_enable_hci_sniffer, - FLAGS_enable_baseband_sniffer, FLAGS_enable_pcap_filter, - FLAGS_disable_address_reuse); + [](AsyncManager* am, int port) { + return std::make_shared(port, am); + }, + [](AsyncManager* am) { return std::make_shared(am); }, + static_cast(FLAGS_test_port), static_cast(FLAGS_hci_port), + static_cast(FLAGS_link_port), static_cast(FLAGS_link_ble_port), + configuration_str, FLAGS_enable_hci_sniffer, FLAGS_enable_baseband_sniffer, + FLAGS_enable_pcap_filter, FLAGS_disable_address_reuse); std::promise barrier; std::future barrier_future = barrier.get_future(); diff --git a/desktop/test_environment.cc b/desktop/test_environment.cc index 512bab2..f556b84 100644 --- a/desktop/test_environment.cc +++ b/desktop/test_environment.cc @@ -56,14 +56,11 @@ using rootcanal::LinkLayerSocketDevice; using rootcanal::TaskCallback; TestEnvironment::TestEnvironment( - std::function(AsyncManager*, int)> - open_server, - std::function(AsyncManager*)> - open_connector, - int test_port, int hci_port, int link_port, int link_ble_port, - const std::string& config_str, - bool enable_hci_sniffer, bool enable_baseband_sniffer, - bool enable_pcap_filter, bool disable_address_reuse) + std::function(AsyncManager*, int)> open_server, + std::function(AsyncManager*)> open_connector, + int test_port, int hci_port, int link_port, int link_ble_port, + const std::string& config_str, bool enable_hci_sniffer, bool enable_baseband_sniffer, + bool enable_pcap_filter, bool disable_address_reuse) : enable_hci_sniffer_(enable_hci_sniffer), enable_baseband_sniffer_(enable_baseband_sniffer), enable_pcap_filter_(enable_pcap_filter) { @@ -76,8 +73,7 @@ TestEnvironment::TestEnvironment( // Get a user ID for tasks scheduled within the test environment. socket_user_id_ = async_manager_.GetNextUserId(); - rootcanal::configuration::Configuration* config = - new rootcanal::configuration::Configuration(); + rootcanal::configuration::Configuration* config = new rootcanal::configuration::Configuration(); if (!google::protobuf::TextFormat::ParseFromString(config_str, config) || config->tcp_server_size() == 0) { // Default configuration with default hci port if the input @@ -88,8 +84,7 @@ TestEnvironment::TestEnvironment( // the caller. int num_controllers = config->tcp_server_size(); for (int index = 0; index < num_controllers; index++) { - rootcanal::configuration::TcpServer const& tcp_server = - config->tcp_server(index); + rootcanal::configuration::TcpServer const& tcp_server = config->tcp_server(index); SetUpHciServer(open_server, tcp_server.tcp_port(), rootcanal::ControllerProperties(tcp_server.configuration())); } @@ -99,52 +94,48 @@ TestEnvironment::TestEnvironment( // Open an HCI server listening on the port `tcp_port`. Established connections // are bound to a controller with the specified `properties`. void TestEnvironment::SetUpHciServer( - std::function(AsyncManager*, int)> - open_server, - int tcp_port, rootcanal::ControllerProperties properties) { + std::function(AsyncManager*, int)> open_server, + int tcp_port, rootcanal::ControllerProperties properties) { INFO("Opening an HCI with port {}", tcp_port); - std::shared_ptr server = - open_server(&async_manager_, tcp_port); - server->SetOnConnectCallback([this, properties = std::move(properties)]( - std::shared_ptr socket, - AsyncDataChannelServer* server) { - // AddHciConnection needs to be executed in task thread to - // prevent data races on test model. - async_manager_.ExecAsync(socket_user_id_, std::chrono::milliseconds(0), - [=]() { - auto transport = HciSocketTransport::Create(socket); - if (enable_hci_sniffer_) { - transport = HciSniffer::Create(transport); - } - auto device = HciDevice::Create(transport, properties); - auto device_id = test_model_.AddHciConnection(device); - - if (enable_hci_sniffer_) { - auto filename = "rootcanal_" + std::to_string(device_id) + "_" + - device->GetAddress().ToString() + ".pcap"; - for (auto i = 0; std::filesystem::exists(filename); i++) { - filename = "rootcanal_" + std::to_string(device_id) + "_" + - device->GetAddress().ToString() + "_" + std::to_string(i) + - ".pcap"; - } - auto file = std::make_shared(filename, std::ios::binary); - auto sniffer = std::static_pointer_cast(transport); - - // Add PCAP output stream. - sniffer->SetOutputStream(file); - - // Add a PCAP filter if the option is enabled. - // TODO: ideally the filter should be shared between all transport - // instances to use the same user information remapping between traces. - if (enable_pcap_filter_) { - sniffer->SetPcapFilter(std::make_shared()); - } - } - }); + std::shared_ptr server = open_server(&async_manager_, tcp_port); + server->SetOnConnectCallback( + [this, properties = std::move(properties)](std::shared_ptr socket, + AsyncDataChannelServer* server) { + // AddHciConnection needs to be executed in task thread to + // prevent data races on test model. + async_manager_.ExecAsync(socket_user_id_, std::chrono::milliseconds(0), [=, this]() { + auto transport = HciSocketTransport::Create(socket); + if (enable_hci_sniffer_) { + transport = HciSniffer::Create(transport); + } + auto device = HciDevice::Create(transport, properties); + auto device_id = test_model_.AddHciConnection(device); + + if (enable_hci_sniffer_) { + auto filename = "rootcanal_" + std::to_string(device_id) + "_" + + device->GetAddress().ToString() + ".pcap"; + for (auto i = 0; std::filesystem::exists(filename); i++) { + filename = "rootcanal_" + std::to_string(device_id) + "_" + + device->GetAddress().ToString() + "_" + std::to_string(i) + ".pcap"; + } + auto file = std::make_shared(filename, std::ios::binary); + auto sniffer = std::static_pointer_cast(transport); + + // Add PCAP output stream. + sniffer->SetOutputStream(file); + + // Add a PCAP filter if the option is enabled. + // TODO: ideally the filter should be shared between all transport + // instances to use the same user information remapping between traces. + if (enable_pcap_filter_) { + sniffer->SetPcapFilter(std::make_shared()); + } + } + }); - server->StartListening(); - }); + server->StartListening(); + }); hci_socket_servers_.emplace_back(std::move(server)); } @@ -153,17 +144,16 @@ void TestEnvironment::initialize(std::promise barrier) { barrier_ = std::move(barrier); - test_channel_transport_.RegisterCommandHandler( - [this](const std::string& name, const std::vector& args) { - async_manager_.ExecAsync(socket_user_id_, std::chrono::milliseconds(0), - [this, name, args]() { - if (name == "END_SIMULATION") { - barrier_.set_value(); - } else { - test_channel_.HandleCommand(name, args); - } - }); - }); + test_channel_transport_.RegisterCommandHandler([this](const std::string& name, + const std::vector& args) { + async_manager_.ExecAsync(socket_user_id_, std::chrono::milliseconds(0), [this, name, args]() { + if (name == "END_SIMULATION") { + barrier_.set_value(); + } else { + test_channel_.HandleCommand(name, args); + } + }); + }); SetUpTestChannel(); SetUpLinkLayerServer(); @@ -179,8 +169,7 @@ void TestEnvironment::initialize(std::promise barrier) { filename = "baseband_" + std::to_string(i) + ".pcap"; } - test_model_.AddLinkLayerConnection(BaseBandSniffer::Create(filename), - Phy::Type::BR_EDR); + test_model_.AddLinkLayerConnection(BaseBandSniffer::Create(filename), Phy::Type::BR_EDR); } INFO("{}: Finished", __func__); @@ -192,31 +181,27 @@ void TestEnvironment::close() { } void TestEnvironment::SetUpLinkBleLayerServer() { - link_ble_socket_server_->SetOnConnectCallback( - [this](std::shared_ptr socket, - AsyncDataChannelServer* srv) { - auto phy_type = Phy::Type::LOW_ENERGY; - test_model_.AddLinkLayerConnection( - LinkLayerSocketDevice::Create(socket, phy_type), phy_type); - srv->StartListening(); - }); + link_ble_socket_server_->SetOnConnectCallback([this](std::shared_ptr socket, + AsyncDataChannelServer* srv) { + auto phy_type = Phy::Type::LOW_ENERGY; + test_model_.AddLinkLayerConnection(LinkLayerSocketDevice::Create(socket, phy_type), phy_type); + srv->StartListening(); + }); link_ble_socket_server_->StartListening(); } void TestEnvironment::SetUpLinkLayerServer() { - link_socket_server_->SetOnConnectCallback( - [this](std::shared_ptr socket, - AsyncDataChannelServer* srv) { - auto phy_type = Phy::Type::BR_EDR; - test_model_.AddLinkLayerConnection( - LinkLayerSocketDevice::Create(socket, phy_type), phy_type); - srv->StartListening(); - }); + link_socket_server_->SetOnConnectCallback([this](std::shared_ptr socket, + AsyncDataChannelServer* srv) { + auto phy_type = Phy::Type::BR_EDR; + test_model_.AddLinkLayerConnection(LinkLayerSocketDevice::Create(socket, phy_type), phy_type); + srv->StartListening(); + }); link_socket_server_->StartListening(); } -std::shared_ptr TestEnvironment::ConnectToRemoteServer( - const std::string& server, int port, Phy::Type phy_type) { +std::shared_ptr TestEnvironment::ConnectToRemoteServer(const std::string& server, int port, + Phy::Type phy_type) { auto socket = connector_->ConnectToRemoteServer(server, port); if (!socket->Connected()) { return nullptr; @@ -226,28 +211,26 @@ std::shared_ptr TestEnvironment::ConnectToRemoteServer( void TestEnvironment::SetUpTestChannel() { bool transport_configured = test_channel_transport_.SetUp( - test_socket_server_, [this](std::shared_ptr conn_fd, - AsyncDataChannelServer* server) { - INFO("Test channel connection accepted."); - server->StartListening(); - if (test_channel_open_) { - WARNING("Only one connection at a time is supported"); - rootcanal::TestChannelTransport::SendResponse( - conn_fd, "The connection is broken"); - return false; - } - test_channel_open_ = true; - test_channel_.RegisterSendResponse( - [conn_fd](const std::string& response) { + test_socket_server_, + [this](std::shared_ptr conn_fd, AsyncDataChannelServer* server) { + INFO("Test channel connection accepted."); + server->StartListening(); + if (test_channel_open_) { + WARNING("Only one connection at a time is supported"); + rootcanal::TestChannelTransport::SendResponse(conn_fd, "The connection is broken"); + return false; + } + test_channel_open_ = true; + test_channel_.RegisterSendResponse([conn_fd](const std::string& response) { rootcanal::TestChannelTransport::SendResponse(conn_fd, response); }); - conn_fd->WatchForNonBlockingRead([this](AsyncDataChannel* conn_fd) { - test_channel_transport_.OnCommandReady( - conn_fd, [this]() { test_channel_open_ = false; }); - }); - return false; - }); + conn_fd->WatchForNonBlockingRead([this](AsyncDataChannel* conn_fd) { + test_channel_transport_.OnCommandReady(conn_fd, + [this]() { test_channel_open_ = false; }); + }); + return false; + }); test_channel_.AddPhy({"BR_EDR"}); test_channel_.AddPhy({"LOW_ENERGY"}); diff --git a/desktop/test_environment.h b/desktop/test_environment.h index 5947d07..7f15811 100644 --- a/desktop/test_environment.h +++ b/desktop/test_environment.h @@ -47,21 +47,19 @@ using rootcanal::Device; using rootcanal::Phy; class TestEnvironment { - public: +public: TestEnvironment( - std::function(AsyncManager*, int)> - open_server, - std::function(AsyncManager*)> - open_connector, - int test_port, int hci_port, int link_port, int link_ble_port, - std::string const& config_str, - bool enable_hci_sniffer = false, bool enable_baseband_sniffer = false, - bool enable_pcap_filter = false, bool disable_address_reuse = false); + std::function(AsyncManager*, int)> open_server, + std::function(AsyncManager*)> open_connector, + int test_port, int hci_port, int link_port, int link_ble_port, + std::string const& config_str, bool enable_hci_sniffer = false, + bool enable_baseband_sniffer = false, bool enable_pcap_filter = false, + bool disable_address_reuse = false); void initialize(std::promise barrier); void close(); - private: +private: rootcanal::AsyncManager async_manager_; rootcanal::TestChannelTransport test_channel_transport_; std::shared_ptr test_socket_server_; @@ -78,40 +76,33 @@ class TestEnvironment { void SetUpTestChannel(); void SetUpHciServer( - std::function(AsyncManager*, int)> - open_server, - int tcp_port, rootcanal::ControllerProperties properties); + std::function(AsyncManager*, int)> open_server, + int tcp_port, rootcanal::ControllerProperties properties); void SetUpLinkLayerServer(); void SetUpLinkBleLayerServer(); - std::shared_ptr ConnectToRemoteServer(const std::string& server, - int port, Phy::Type phy_type); + std::shared_ptr ConnectToRemoteServer(const std::string& server, int port, + Phy::Type phy_type); rootcanal::TestModel test_model_{ - [this]() { return async_manager_.GetNextUserId(); }, - [this](rootcanal::AsyncUserId user_id, std::chrono::milliseconds delay, - const rootcanal::TaskCallback& task) { - return async_manager_.ExecAsync(user_id, delay, 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](rootcanal::AsyncUserId user) { - async_manager_.CancelAsyncTasksFromUser(user); - }, - - [this](rootcanal::AsyncTaskId task) { - async_manager_.CancelAsyncTask(task); - }, - - [this](const std::string& server, int port, Phy::Type phy_type) { - return ConnectToRemoteServer(server, port, phy_type); - }}; + [this]() { return async_manager_.GetNextUserId(); }, + [this](rootcanal::AsyncUserId user_id, std::chrono::milliseconds delay, + const rootcanal::TaskCallback& task) { + return async_manager_.ExecAsync(user_id, delay, 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](rootcanal::AsyncUserId user) { async_manager_.CancelAsyncTasksFromUser(user); }, + + [this](rootcanal::AsyncTaskId task) { async_manager_.CancelAsyncTask(task); }, + + [this](const std::string& server, int port, Phy::Type phy_type) { + return ConnectToRemoteServer(server, port, phy_type); + }}; rootcanal::TestCommandHandler test_channel_{test_model_}; }; diff --git a/include/crypto/crypto.h b/include/crypto/crypto.h index f73d0f2..6249b16 100644 --- a/include/crypto/crypto.h +++ b/include/crypto/crypto.h @@ -30,8 +30,7 @@ Octet16 aes_128(const Octet16& key, const Octet16& message); /* This function computes AES_128(key, message). |key| must be 128bit. * |message| can be at most 16 bytes long, its length in bytes is given in * |length| */ -inline Octet16 aes_128(const Octet16& key, const uint8_t* message, - const uint8_t length) { +inline Octet16 aes_128(const Octet16& key, const uint8_t* message, const uint8_t length) { Octet16 padded_message{0}; std::copy(message, message + length, padded_message.begin()); return aes_128(key, padded_message); diff --git a/include/hci/address.h b/include/hci/address.h index 18b38ee..fe4d454 100644 --- a/include/hci/address.h +++ b/include/hci/address.h @@ -32,7 +32,7 @@ namespace bluetooth::hci { class Address final : public pdl::packet::Builder { - public: +public: static constexpr size_t kLength = 6; // Bluetooth MAC address bytes saved in little endian format. @@ -52,7 +52,7 @@ class Address final : public pdl::packet::Builder { bool operator<(const Address& rhs) const { return address < rhs.address; } bool operator==(const Address& rhs) const { return address == rhs.address; } - bool operator>(const Address& rhs) const { return (rhs < *this); } + bool operator>(const Address& rhs) const { return rhs < *this; } bool operator<=(const Address& rhs) const { return !(*this > rhs); } bool operator>=(const Address& rhs) const { return !(*this < rhs); } bool operator!=(const Address& rhs) const { return !(*this == rhs); } @@ -112,8 +112,7 @@ struct fmt::formatter { char presentation = 'x'; // Parses format specifications of the form ['x' | 'X']. - constexpr auto parse(format_parse_context& ctx) - -> format_parse_context::iterator { + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator { // Parse the presentation format and store it in the formatter: auto it = ctx.begin(); auto end = ctx.end(); @@ -132,16 +131,14 @@ struct fmt::formatter { // Formats the address a using the parsed format specification (presentation) // stored in this formatter. - auto format(const bluetooth::hci::Address& a, format_context& ctx) const - -> format_context::iterator { + auto format(const bluetooth::hci::Address& a, + format_context& ctx) const -> format_context::iterator { return presentation == 'x' - ? fmt::format_to(ctx.out(), - "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", - a.address[5], a.address[4], a.address[3], - a.address[2], a.address[1], a.address[0]) - : fmt::format_to(ctx.out(), - "{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}", - a.address[5], a.address[4], a.address[3], - a.address[2], a.address[1], a.address[0]); + ? fmt::format_to(ctx.out(), "{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", + a.address[5], a.address[4], a.address[3], a.address[2], + a.address[1], a.address[0]) + : fmt::format_to(ctx.out(), "{:02X}:{:02X}:{:02X}:{:02X}:{:02X}:{:02X}", + a.address[5], a.address[4], a.address[3], a.address[2], + a.address[1], a.address[0]); } }; diff --git a/include/hci/address_with_type.h b/include/hci/address_with_type.h index 65c4223..1172ac7 100644 --- a/include/hci/address_with_type.h +++ b/include/hci/address_with_type.h @@ -34,13 +34,12 @@ namespace bluetooth::hci { class AddressWithType final { - public: +public: AddressWithType(Address address, AddressType address_type) : address_(std::move(address)), address_type_(address_type) {} explicit AddressWithType() - : address_(Address::kEmpty), - address_type_(AddressType::PUBLIC_DEVICE_ADDRESS) {} + : address_(Address::kEmpty), address_type_(AddressType::PUBLIC_DEVICE_ADDRESS) {} inline Address GetAddress() const { return address_; } @@ -65,8 +64,7 @@ class AddressWithType final { prand[1] = address_.address[4]; prand[2] = address_.address[5]; /* generate X = E irk(R0, R1, R2) and R is random address 3 LSO */ - rootcanal::crypto::Octet16 computed_hash = - rootcanal::crypto::aes_128(irk, &prand[0], 3); + rootcanal::crypto::Octet16 computed_hash = rootcanal::crypto::aes_128(irk, &prand[0], 3); uint8_t hash[3]; hash[0] = address_.address[0]; hash[1] = address_.address[1]; @@ -75,13 +73,12 @@ class AddressWithType final { } bool operator<(const AddressWithType& rhs) const { - return (address_ != rhs.address_) ? address_ < rhs.address_ - : address_type_ < rhs.address_type_; + return (address_ != rhs.address_) ? address_ < rhs.address_ : address_type_ < rhs.address_type_; } bool operator==(const AddressWithType& rhs) const { return address_ == rhs.address_ && address_type_ == rhs.address_type_; } - bool operator>(const AddressWithType& rhs) const { return (rhs < *this); } + bool operator>(const AddressWithType& rhs) const { return rhs < *this; } bool operator<=(const AddressWithType& rhs) const { return !(*this > rhs); } bool operator>=(const AddressWithType& rhs) const { return !(*this < rhs); } bool operator!=(const AddressWithType& rhs) const { return !(*this == rhs); } @@ -114,7 +111,7 @@ class AddressWithType final { return ss.str(); } - private: +private: Address address_; AddressType address_type_; }; @@ -146,8 +143,7 @@ struct fmt::formatter { char presentation = 'x'; // Parses format specifications of the form ['x' | 'X']. - constexpr auto parse(format_parse_context& ctx) - -> format_parse_context::iterator { + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator { // Parse the presentation format and store it in the formatter: auto it = ctx.begin(); auto end = ctx.end(); @@ -168,9 +164,8 @@ struct fmt::formatter { // stored in this formatter. auto format(const bluetooth::hci::AddressWithType& a, format_context& ctx) const -> format_context::iterator { - auto out = presentation == 'x' - ? fmt::format_to(ctx.out(), "{:x}", a.GetAddress()) - : fmt::format_to(ctx.out(), "{:X}", a.GetAddress()); + auto out = presentation == 'x' ? fmt::format_to(ctx.out(), "{:x}", a.GetAddress()) + : fmt::format_to(ctx.out(), "{:X}", a.GetAddress()); return fmt::format_to(out, "[{}]", AddressTypeText(a.GetAddressType())); } }; diff --git a/include/hci/pcap_filter.h b/include/hci/pcap_filter.h index 1731ce8..64f55f5 100644 --- a/include/hci/pcap_filter.h +++ b/include/hci/pcap_filter.h @@ -42,45 +42,33 @@ namespace rootcanal { // RootCanal issues, and can be safely removed. class PcapFilter final { - public: +public: PcapFilter() = default; // Main function to filter out user data in HCI packets. - std::vector FilterHciPacket(std::vector const& packet, - uint8_t idc); + std::vector FilterHciPacket(std::vector const& packet, uint8_t idc); std::vector FilterHciCommand(std::vector const& packet); std::vector FilterHciEvent(std::vector const& packet); // Specific filters for HCI commands. - std::vector FilterWriteLocalName( - bluetooth::hci::CommandView& command); - std::vector FilterWriteExtendedInquiryResponse( - bluetooth::hci::CommandView& command); - std::vector FilterLeSetAdvertisingData( - bluetooth::hci::CommandView& command); - std::vector FilterLeSetScanResponseData( - bluetooth::hci::CommandView& command); - std::vector FilterLeSetExtendedAdvertisingData( - bluetooth::hci::CommandView& command); - std::vector FilterLeSetExtendedScanResponseData( - bluetooth::hci::CommandView& command); - std::vector FilterLeSetPeriodicAdvertisingData( - bluetooth::hci::CommandView& command); + std::vector FilterWriteLocalName(bluetooth::hci::CommandView& command); + std::vector FilterWriteExtendedInquiryResponse(bluetooth::hci::CommandView& command); + std::vector FilterLeSetAdvertisingData(bluetooth::hci::CommandView& command); + std::vector FilterLeSetScanResponseData(bluetooth::hci::CommandView& command); + std::vector FilterLeSetExtendedAdvertisingData(bluetooth::hci::CommandView& command); + std::vector FilterLeSetExtendedScanResponseData(bluetooth::hci::CommandView& command); + std::vector FilterLeSetPeriodicAdvertisingData(bluetooth::hci::CommandView& command); // Specific filters for HCI events. std::vector FilterReadLocalNameComplete( - bluetooth::hci::CommandCompleteView& command_complete); + bluetooth::hci::CommandCompleteView& command_complete); std::vector FilterReadExtendedInquiryResponseComplete( - bluetooth::hci::CommandCompleteView& command_complete); - std::vector FilterRemoteNameRequestComplete( - bluetooth::hci::EventView& event); - std::vector FilterExtendedInquiryResult( - bluetooth::hci::EventView& event); - std::vector FilterLeAdvertisingReport( - bluetooth::hci::LeMetaEventView& event); - std::vector FilterLeExtendedAdvertisingReport( - bluetooth::hci::LeMetaEventView& event); + bluetooth::hci::CommandCompleteView& command_complete); + std::vector FilterRemoteNameRequestComplete(bluetooth::hci::EventView& event); + std::vector FilterExtendedInquiryResult(bluetooth::hci::EventView& event); + std::vector FilterLeAdvertisingReport(bluetooth::hci::LeMetaEventView& event); + std::vector FilterLeExtendedAdvertisingReport(bluetooth::hci::LeMetaEventView& event); // Specific filter for any Gap data array. // The Gap data entries are modified in place. @@ -88,15 +76,12 @@ class PcapFilter final { void FilterGapData(std::vector& gap_data); // Helpers to replace local names. - std::array ChangeDeviceName( - std::array const& device_name); - std::vector ChangeDeviceName( - std::vector const& device_name); + std::array ChangeDeviceName(std::array const& device_name); + std::vector ChangeDeviceName(std::vector const& device_name); - private: +private: // Map device names to anonymous replacements. - std::vector, std::vector>> - device_name_map{}; + std::vector, std::vector>> device_name_map{}; }; } // namespace rootcanal diff --git a/include/log.h b/include/log.h index 130800a..9367f5b 100644 --- a/include/log.h +++ b/include/log.h @@ -34,13 +34,12 @@ enum Verbosity { void SetLogColorEnable(bool); -void VLog(Verbosity verb, char const* file, int line, - std::optional instance, char const* format, - fmt::format_args args); +void VLog(Verbosity verb, char const* file, int line, std::optional instance, + char const* format, fmt::format_args args); template -static void Log(Verbosity verb, char const* file, int line, int instance, - char const* format, const Args&... args) { +static void Log(Verbosity verb, char const* file, int line, int instance, char const* format, + const Args&... args) { VLog(verb, file, line, instance, format, fmt::make_format_args(args...)); } @@ -50,37 +49,31 @@ static void Log(Verbosity verb, char const* file, int line, char const* format, VLog(verb, file, line, {}, format, fmt::make_format_args(args...)); } -#define DEBUG(...) \ - rootcanal::log::Log(rootcanal::log::Verbosity::kDebug, __FILE__, __LINE__, \ - __VA_ARGS__) - -#define INFO(...) \ - rootcanal::log::Log(rootcanal::log::Verbosity::kInfo, __FILE__, __LINE__, \ - __VA_ARGS__) - -#define WARNING(...) \ - rootcanal::log::Log(rootcanal::log::Verbosity::kWarning, __FILE__, __LINE__, \ - __VA_ARGS__) - -#define ERROR(...) \ - rootcanal::log::Log(rootcanal::log::Verbosity::kError, __FILE__, __LINE__, \ - __VA_ARGS__) - -#define FATAL(...) \ - rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, \ - __VA_ARGS__) - -#define ASSERT(x) \ - __builtin_expect((x) != 0, true) || \ - (rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, \ - __LINE__, "Check failed: {}", #x), \ - false) - -#define ASSERT_LOG(x, ...) \ - __builtin_expect((x) != 0, true) || \ - (rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, \ - __LINE__, "Check failed: {}, {}", #x, \ - fmt::sprintf(__VA_ARGS__)), \ - false) +#define DEBUG(...) \ + rootcanal::log::Log(rootcanal::log::Verbosity::kDebug, __FILE__, __LINE__, __VA_ARGS__) + +#define INFO(...) \ + rootcanal::log::Log(rootcanal::log::Verbosity::kInfo, __FILE__, __LINE__, __VA_ARGS__) + +#define WARNING(...) \ + rootcanal::log::Log(rootcanal::log::Verbosity::kWarning, __FILE__, __LINE__, __VA_ARGS__) + +#define ERROR(...) \ + rootcanal::log::Log(rootcanal::log::Verbosity::kError, __FILE__, __LINE__, __VA_ARGS__) + +#define FATAL(...) \ + rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, __VA_ARGS__) + +#define ASSERT(x) \ + __builtin_expect((x) != 0, true) || \ + (rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, \ + "Check failed: {}", #x), \ + false) + +#define ASSERT_LOG(x, ...) \ + __builtin_expect((x) != 0, true) || \ + (rootcanal::log::Log(rootcanal::log::Verbosity::kFatal, __FILE__, __LINE__, \ + "Check failed: {}, {}", #x, fmt::sprintf(__VA_ARGS__)), \ + false) } // namespace rootcanal::log diff --git a/include/phy.h b/include/phy.h index 1e82c15..5f25fa2 100644 --- a/include/phy.h +++ b/include/phy.h @@ -19,7 +19,7 @@ namespace rootcanal { class Phy { - public: +public: enum class Type { LOW_ENERGY, BR_EDR, diff --git a/lib/hci/address.cc b/lib/hci/address.cc index 3f9103c..fa85501 100644 --- a/lib/hci/address.cc +++ b/lib/hci/address.cc @@ -39,8 +39,7 @@ const Address Address::kEmpty{0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Address cannot initialize member variables as it is a POD type // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) -constexpr Address::Address(std::array const& address) - : address(address) {} +constexpr Address::Address(std::array const& address) : address(address) {} Address::Address(const uint8_t (&address)[kLength]) { std::copy(address, address + kLength, this->address.begin()); @@ -56,9 +55,8 @@ bool Address::Parse(pdl::packet::slice& input, Address* output) { } std::array address{ - input.read_le(), input.read_le(), - input.read_le(), input.read_le(), - input.read_le(), input.read_le(), + input.read_le(), input.read_le(), input.read_le(), + input.read_le(), input.read_le(), input.read_le(), }; *output = Address(address); return true; @@ -67,8 +65,7 @@ bool Address::Parse(pdl::packet::slice& input, Address* output) { std::string Address::ToString() const { std::stringstream ss; for (auto it = address.rbegin(); it != address.rend(); it++) { - ss << std::nouppercase << std::hex << std::setw(2) << std::setfill('0') - << +*it; + ss << std::nouppercase << std::hex << std::setw(2) << std::setfill('0') << +*it; if (std::next(it) != address.rend()) { ss << ':'; } diff --git a/lib/hci/pcap_filter.cc b/lib/hci/pcap_filter.cc index 4a05da0..abd20ed 100644 --- a/lib/hci/pcap_filter.cc +++ b/lib/hci/pcap_filter.cc @@ -35,21 +35,19 @@ using namespace bluetooth::hci; namespace rootcanal { -static pdl::packet::slice create_packet_view( - std::vector const& packet) { +static pdl::packet::slice create_packet_view(std::vector const& packet) { // Wrap the reference to the packet in a shared_ptr with created // a no-op deleter. The packet view will be short lived so there is no // risk of the reference leaking. return pdl::packet::slice(std::shared_ptr const>( - &packet, [](std::vector const* /* ptr */) {})); + &packet, [](std::vector const* /* ptr */) {})); } static std::vector FilterHciAcl(std::vector const& packet); static std::vector FilterHciSco(std::vector const& packet); static std::vector FilterHciIso(std::vector const& packet); -std::vector PcapFilter::FilterHciPacket( - std::vector const& packet, uint8_t idc) { +std::vector PcapFilter::FilterHciPacket(std::vector const& packet, uint8_t idc) { switch (idc) { case 0x1: return FilterHciCommand(packet); @@ -67,8 +65,7 @@ std::vector PcapFilter::FilterHciPacket( return std::vector(packet); } -std::vector PcapFilter::FilterHciCommand( - std::vector const& packet) { +std::vector PcapFilter::FilterHciCommand(std::vector const& packet) { auto command = CommandView::Create(create_packet_view(packet)); ASSERT(command.IsValid()); switch (command.GetOpCode()) { @@ -92,8 +89,7 @@ std::vector PcapFilter::FilterHciCommand( return std::vector(packet); } -std::vector PcapFilter::FilterHciEvent( - std::vector const& packet) { +std::vector PcapFilter::FilterHciEvent(std::vector const& packet) { auto event = EventView::Create(create_packet_view(packet)); ASSERT(event.IsValid()); switch (event.GetEventCode()) { @@ -101,9 +97,9 @@ std::vector PcapFilter::FilterHciEvent( auto le_meta_event = LeMetaEventView::Create(event); ASSERT(le_meta_event.IsValid()); switch (le_meta_event.GetSubeventCode()) { - case SubeventCode::ADVERTISING_REPORT: + case SubeventCode::LE_ADVERTISING_REPORT: return FilterLeAdvertisingReport(le_meta_event); - case SubeventCode::EXTENDED_ADVERTISING_REPORT: + case SubeventCode::LE_EXTENDED_ADVERTISING_REPORT: return FilterLeExtendedAdvertisingReport(le_meta_event); default: break; @@ -138,9 +134,9 @@ static std::vector FilterHciAcl(std::vector const& packet) { std::vector payload; payload.resize(acl.GetPayload().size()); ASSERT(acl.IsValid()); - return AclBuilder::Create(acl.GetHandle(), acl.GetPacketBoundaryFlag(), - acl.GetBroadcastFlag(), std::move(payload)) - ->SerializeToBytes(); + return AclBuilder::Create(acl.GetHandle(), acl.GetPacketBoundaryFlag(), acl.GetBroadcastFlag(), + std::move(payload)) + ->SerializeToBytes(); } static std::vector FilterHciSco(std::vector const& packet) { @@ -148,8 +144,7 @@ static std::vector FilterHciSco(std::vector const& packet) { std::vector data; data.resize(sco.GetData().size()); ASSERT(sco.IsValid()); - return ScoBuilder::Create(sco.GetHandle(), sco.GetPacketStatusFlag(), data) - ->SerializeToBytes(); + return ScoBuilder::Create(sco.GetHandle(), sco.GetPacketStatusFlag(), data)->SerializeToBytes(); } static std::vector FilterHciIso(std::vector const& packet) { @@ -157,9 +152,9 @@ static std::vector FilterHciIso(std::vector const& packet) { std::vector payload; payload.resize(iso.GetPayload().size()); ASSERT(iso.IsValid()); - return IsoBuilder::Create(iso.GetConnectionHandle(), iso.GetPbFlag(), - iso.GetTsFlag(), std::move(payload)) - ->SerializeToBytes(); + return IsoBuilder::Create(iso.GetConnectionHandle(), iso.GetPbFlag(), iso.GetTsFlag(), + std::move(payload)) + ->SerializeToBytes(); } // Replace device names in GAP entries. @@ -190,8 +185,7 @@ void PcapFilter::FilterGapData(uint8_t* gap_data, size_t gap_data_len) { case GapDataType::SHORTENED_LOCAL_NAME: { auto start_pos = gap_data + offset + 1; auto end_pos = gap_data + offset + length; - std::vector new_name = - ChangeDeviceName(std::vector{start_pos, end_pos}); + std::vector new_name = ChangeDeviceName(std::vector{start_pos, end_pos}); std::copy(new_name.begin(), new_name.end(), start_pos); break; } @@ -212,97 +206,86 @@ std::vector PcapFilter::FilterWriteLocalName(CommandView& command) { auto parameters = WriteLocalNameView::Create(command); ASSERT(parameters.IsValid()); - std::array local_name = - ChangeDeviceName(parameters.GetLocalName()); + std::array local_name = ChangeDeviceName(parameters.GetLocalName()); return WriteLocalNameBuilder::Create(local_name)->SerializeToBytes(); } // Replace the device names in the GAP entries of the extended inquiry response. -std::vector PcapFilter::FilterWriteExtendedInquiryResponse( - CommandView& command) { +std::vector PcapFilter::FilterWriteExtendedInquiryResponse(CommandView& command) { auto parameters = WriteExtendedInquiryResponseView::Create(command); ASSERT(parameters.IsValid()); - std::array extended_inquiry_response = - parameters.GetExtendedInquiryResponse(); - FilterGapData(extended_inquiry_response.data(), - extended_inquiry_response.size()); - return WriteExtendedInquiryResponseBuilder::Create( - parameters.GetFecRequired(), extended_inquiry_response) - ->SerializeToBytes(); + std::array extended_inquiry_response = parameters.GetExtendedInquiryResponse(); + FilterGapData(extended_inquiry_response.data(), extended_inquiry_response.size()); + return WriteExtendedInquiryResponseBuilder::Create(parameters.GetFecRequired(), + extended_inquiry_response) + ->SerializeToBytes(); } // Replace the device names in the GAP entries of the advertising data. -std::vector PcapFilter::FilterLeSetAdvertisingData( - CommandView& command) { +std::vector PcapFilter::FilterLeSetAdvertisingData(CommandView& command) { auto parameters = LeSetAdvertisingDataView::Create(command); ASSERT(parameters.IsValid()); std::vector advertising_data = parameters.GetAdvertisingData(); FilterGapData(advertising_data); - return LeSetAdvertisingDataBuilder::Create(advertising_data) - ->SerializeToBytes(); + return LeSetAdvertisingDataBuilder::Create(advertising_data)->SerializeToBytes(); } // Replace the device names in the GAP entries of the scan response data. -std::vector PcapFilter::FilterLeSetScanResponseData( - CommandView& command) { +std::vector PcapFilter::FilterLeSetScanResponseData(CommandView& command) { auto parameters = LeSetScanResponseDataView::Create(command); ASSERT(parameters.IsValid()); std::vector advertising_data = parameters.GetAdvertisingData(); FilterGapData(advertising_data); - return LeSetScanResponseDataBuilder::Create(advertising_data) - ->SerializeToBytes(); + return LeSetScanResponseDataBuilder::Create(advertising_data)->SerializeToBytes(); } // Replace the device names in the GAP entries of the extended advertising data. -std::vector PcapFilter::FilterLeSetExtendedAdvertisingData( - CommandView& command) { +std::vector PcapFilter::FilterLeSetExtendedAdvertisingData(CommandView& command) { auto parameters = LeSetExtendedAdvertisingDataView::Create(command); ASSERT(parameters.IsValid()); std::vector advertising_data = parameters.GetAdvertisingData(); FilterGapData(advertising_data); return LeSetExtendedAdvertisingDataBuilder::Create( - parameters.GetAdvertisingHandle(), parameters.GetOperation(), - parameters.GetFragmentPreference(), advertising_data) - ->SerializeToBytes(); + parameters.GetAdvertisingHandle(), parameters.GetOperation(), + parameters.GetFragmentPreference(), advertising_data) + ->SerializeToBytes(); } // Replace the device names in the GAP entries of the extended scan response // data. -std::vector PcapFilter::FilterLeSetExtendedScanResponseData( - CommandView& command) { +std::vector PcapFilter::FilterLeSetExtendedScanResponseData(CommandView& command) { auto parameters = LeSetExtendedScanResponseDataView::Create(command); ASSERT(parameters.IsValid()); std::vector advertising_data = parameters.GetScanResponseData(); FilterGapData(advertising_data); return LeSetExtendedScanResponseDataBuilder::Create( - parameters.GetAdvertisingHandle(), parameters.GetOperation(), - parameters.GetFragmentPreference(), advertising_data) - ->SerializeToBytes(); + parameters.GetAdvertisingHandle(), parameters.GetOperation(), + parameters.GetFragmentPreference(), advertising_data) + ->SerializeToBytes(); } // Replace the device names in the GAP entries of the periodic advertising // data. std::vector PcapFilter::FilterLeSetPeriodicAdvertisingData( - bluetooth::hci::CommandView& command) { + bluetooth::hci::CommandView& command) { auto parameters = LeSetPeriodicAdvertisingDataView::Create(command); ASSERT(parameters.IsValid()); std::vector advertising_data = parameters.GetAdvertisingData(); FilterGapData(advertising_data); - return LeSetPeriodicAdvertisingDataBuilder::Create( - parameters.GetAdvertisingHandle(), parameters.GetOperation(), - advertising_data) - ->SerializeToBytes(); + return LeSetPeriodicAdvertisingDataBuilder::Create(parameters.GetAdvertisingHandle(), + parameters.GetOperation(), advertising_data) + ->SerializeToBytes(); } // Replace the local device name in the read local name complete event. std::vector PcapFilter::FilterReadLocalNameComplete( - bluetooth::hci::CommandCompleteView& command_complete) { + bluetooth::hci::CommandCompleteView& command_complete) { auto parameters = ReadLocalNameCompleteView::Create(command_complete); ASSERT(parameters.IsValid()); @@ -311,35 +294,30 @@ std::vector PcapFilter::FilterReadLocalNameComplete( local_name = ChangeDeviceName(local_name); } - return ReadLocalNameCompleteBuilder::Create( - parameters.GetNumHciCommandPackets(), parameters.GetStatus(), - local_name) - ->SerializeToBytes(); + return ReadLocalNameCompleteBuilder::Create(parameters.GetNumHciCommandPackets(), + parameters.GetStatus(), local_name) + ->SerializeToBytes(); } // Replace the device names in the GAP entries of the extended inquiry response. std::vector PcapFilter::FilterReadExtendedInquiryResponseComplete( - bluetooth::hci::CommandCompleteView& command_complete) { - auto parameters = - ReadExtendedInquiryResponseCompleteView::Create(command_complete); + bluetooth::hci::CommandCompleteView& command_complete) { + auto parameters = ReadExtendedInquiryResponseCompleteView::Create(command_complete); ASSERT(parameters.IsValid()); - std::array extended_inquiry_response = - parameters.GetExtendedInquiryResponse(); + std::array extended_inquiry_response = parameters.GetExtendedInquiryResponse(); if (parameters.GetStatus() == ErrorCode::SUCCESS) { - FilterGapData(extended_inquiry_response.data(), - extended_inquiry_response.size()); + FilterGapData(extended_inquiry_response.data(), extended_inquiry_response.size()); } return ReadExtendedInquiryResponseCompleteBuilder::Create( - parameters.GetNumHciCommandPackets(), parameters.GetStatus(), - parameters.GetFecRequired(), extended_inquiry_response) - ->SerializeToBytes(); + parameters.GetNumHciCommandPackets(), parameters.GetStatus(), + parameters.GetFecRequired(), extended_inquiry_response) + ->SerializeToBytes(); } // Replace the remote device name in the remote name request complete event. -std::vector PcapFilter::FilterRemoteNameRequestComplete( - bluetooth::hci::EventView& event) { +std::vector PcapFilter::FilterRemoteNameRequestComplete(bluetooth::hci::EventView& event) { auto parameters = RemoteNameRequestCompleteView::Create(event); ASSERT(parameters.IsValid()); @@ -348,31 +326,27 @@ std::vector PcapFilter::FilterRemoteNameRequestComplete( remote_name = ChangeDeviceName(remote_name); } - return RemoteNameRequestCompleteBuilder::Create( - parameters.GetStatus(), parameters.GetBdAddr(), remote_name) - ->SerializeToBytes(); + return RemoteNameRequestCompleteBuilder::Create(parameters.GetStatus(), parameters.GetBdAddr(), + remote_name) + ->SerializeToBytes(); } // Replace the device names in the GAP entries in the extended inquiry result. -std::vector PcapFilter::FilterExtendedInquiryResult( - bluetooth::hci::EventView& event) { +std::vector PcapFilter::FilterExtendedInquiryResult(bluetooth::hci::EventView& event) { auto parameters = ExtendedInquiryResultView::Create(event); ASSERT(parameters.IsValid()); - std::array extended_inquiry_response = - parameters.GetExtendedInquiryResponse(); - FilterGapData(extended_inquiry_response.data(), - extended_inquiry_response.size()); + std::array extended_inquiry_response = parameters.GetExtendedInquiryResponse(); + FilterGapData(extended_inquiry_response.data(), extended_inquiry_response.size()); return ExtendedInquiryResultBuilder::Create( - parameters.GetAddress(), parameters.GetPageScanRepetitionMode(), - parameters.GetClassOfDevice(), parameters.GetClockOffset(), - parameters.GetRssi(), extended_inquiry_response) - ->SerializeToBytes(); + parameters.GetAddress(), parameters.GetPageScanRepetitionMode(), + parameters.GetClassOfDevice(), parameters.GetClockOffset(), parameters.GetRssi(), + extended_inquiry_response) + ->SerializeToBytes(); } // Replace the device names in the GAP entries in the advertising report. -std::vector PcapFilter::FilterLeAdvertisingReport( - bluetooth::hci::LeMetaEventView& event) { +std::vector PcapFilter::FilterLeAdvertisingReport(bluetooth::hci::LeMetaEventView& event) { auto parameters = LeAdvertisingReportView::Create(event); ASSERT(parameters.IsValid()); @@ -387,31 +361,28 @@ std::vector PcapFilter::FilterLeAdvertisingReport( // Replace the device names in the GAP entries in the extended advertising // report. std::vector PcapFilter::FilterLeExtendedAdvertisingReport( - bluetooth::hci::LeMetaEventView& event) { + bluetooth::hci::LeMetaEventView& event) { auto parameters = LeExtendedAdvertisingReportView::Create(event); ASSERT(parameters.IsValid()); - std::vector responses = - parameters.GetResponses(); + std::vector responses = parameters.GetResponses(); for (auto& response : responses) { FilterGapData(response.advertising_data_); } - return LeExtendedAdvertisingReportBuilder::Create(responses) - ->SerializeToBytes(); + return LeExtendedAdvertisingReportBuilder::Create(responses)->SerializeToBytes(); } // Generate a device name of the specified length. // device_nr is a unique identifier used for the generation. // padded indicates if the name should be padded to length with // spaces. -static std::vector generate_device_name(size_t device_nr, - size_t device_name_len, +static std::vector generate_device_name(size_t device_nr, size_t device_name_len, bool padded) { std::vector output; output.resize(device_name_len + 1); - int written_len = std::snprintf(reinterpret_cast(output.data()), - output.size(), "#%02zu device", device_nr); + int written_len = std::snprintf(reinterpret_cast(output.data()), output.size(), + "#%02zu device", device_nr); // Remove the null terminator, not used for the device name // since it is framed in most cases. output.resize(device_name_len); @@ -422,8 +393,7 @@ static std::vector generate_device_name(size_t device_nr, return output; } -std::vector PcapFilter::ChangeDeviceName( - std::vector const& device_name) { +std::vector PcapFilter::ChangeDeviceName(std::vector const& device_name) { for (auto const& [old_device_name, new_device_name] : device_name_map) { if (old_device_name == device_name) { return std::vector(new_device_name); @@ -431,34 +401,31 @@ std::vector PcapFilter::ChangeDeviceName( } std::vector new_device_name = - generate_device_name(device_name_map.size(), device_name.size(), true); + generate_device_name(device_name_map.size(), device_name.size(), true); device_name_map.push_back(std::pair{ - std::vector(device_name), - new_device_name, + std::vector(device_name), + new_device_name, }); return new_device_name; } -std::array PcapFilter::ChangeDeviceName( - std::array const& device_name) { +std::array PcapFilter::ChangeDeviceName(std::array const& device_name) { for (auto const& [old_device_name, new_device_name] : device_name_map) { - if (std::equal(old_device_name.begin(), old_device_name.end(), - device_name.begin(), device_name.end())) { + if (std::equal(old_device_name.begin(), old_device_name.end(), device_name.begin(), + device_name.end())) { std::array out_device_name{}; - std::copy(new_device_name.begin(), new_device_name.end(), - out_device_name.begin()); + std::copy(new_device_name.begin(), new_device_name.end(), out_device_name.begin()); return out_device_name; } } std::vector new_device_name = - generate_device_name(device_name_map.size(), device_name.size(), false); + generate_device_name(device_name_map.size(), device_name.size(), false); std::array out_device_name{}; - std::copy(new_device_name.begin(), new_device_name.end(), - out_device_name.begin()); + std::copy(new_device_name.begin(), new_device_name.end(), out_device_name.begin()); device_name_map.push_back(std::pair{ - std::vector(device_name.begin(), device_name.end()), - std::move(new_device_name), + std::vector(device_name.begin(), device_name.end()), + std::move(new_device_name), }); return out_device_name; } diff --git a/lib/log.cc b/lib/log.cc index 9c78b16..dc843f3 100644 --- a/lib/log.cc +++ b/lib/log.cc @@ -37,34 +37,30 @@ void SetLogColorEnable(bool enable) { enable_log_color = enable; } static std::array verbosity_tag = {'D', 'I', 'W', 'E', 'F'}; static std::array text_style = { - fmt::fg(fmt::color::dim_gray), - fmt::fg(fmt::color::floral_white), - fmt::emphasis::bold | fmt::fg(fmt::color::yellow), - fmt::emphasis::bold | fmt::fg(fmt::color::orange_red), - fmt::emphasis::bold | fmt::fg(fmt::color::red), + fmt::fg(fmt::color::dim_gray), + fmt::fg(fmt::color::floral_white), + fmt::emphasis::bold | fmt::fg(fmt::color::yellow), + fmt::emphasis::bold | fmt::fg(fmt::color::orange_red), + fmt::emphasis::bold | fmt::fg(fmt::color::red), }; static std::array text_color = { - fmt::color::cadet_blue, fmt::color::aquamarine, - fmt::color::indian_red, fmt::color::blue_violet, - fmt::color::chartreuse, fmt::color::medium_sea_green, - fmt::color::deep_pink, fmt::color::medium_orchid, - fmt::color::green_yellow, fmt::color::dark_orange, - fmt::color::golden_rod, fmt::color::medium_slate_blue, - fmt::color::coral, fmt::color::lemon_chiffon, - fmt::color::wheat, fmt::color::turquoise, + fmt::color::cadet_blue, fmt::color::aquamarine, fmt::color::indian_red, + fmt::color::blue_violet, fmt::color::chartreuse, fmt::color::medium_sea_green, + fmt::color::deep_pink, fmt::color::medium_orchid, fmt::color::green_yellow, + fmt::color::dark_orange, fmt::color::golden_rod, fmt::color::medium_slate_blue, + fmt::color::coral, fmt::color::lemon_chiffon, fmt::color::wheat, + fmt::color::turquoise, }; -void VLog(Verbosity verb, char const* file, int line, - std::optional instance, char const* format, - fmt::format_args args) { +void VLog(Verbosity verb, char const* file, int line, std::optional instance, + char const* format, fmt::format_args args) { // Generate the time label. auto now = std::chrono::system_clock::now(); auto now_ms = std::chrono::time_point_cast(now); auto now_t = std::chrono::system_clock::to_time_t(now); char time_str[19]; // "mm-dd_HH:MM:SS.mmm\0" is 19 byte long - auto n = std::strftime(time_str, sizeof(time_str), "%m-%d %H:%M:%S", - std::localtime(&now_t)); + auto n = std::strftime(time_str, sizeof(time_str), "%m-%d %H:%M:%S", std::localtime(&now_t)); snprintf(time_str + n, sizeof(time_str) - n, ".%03u", static_cast(now_ms.time_since_epoch().count() % 1000)); @@ -75,13 +71,11 @@ void VLog(Verbosity verb, char const* file, int line, char file_str[40]; // file:line limited to 40 characters snprintf(file_str, sizeof(file_str), "%.35s:%d", file_name, line); - fmt::print("root-canal {} {} {:<35.35} ", verbosity_tag[verb], time_str, - file_str); + fmt::print("root-canal {} {} {:<35.35} ", verbosity_tag[verb], time_str, file_str); if (instance.has_value() && enable_log_color) { fmt::color instance_color = text_color[*instance % text_color.size()]; - fmt::print(fmt::bg(instance_color) | fmt::fg(fmt::color::black), " {:>2} ", - *instance); + fmt::print(fmt::bg(instance_color) | fmt::fg(fmt::color::black), " {:>2} ", *instance); fmt::print(" "); } else if (instance.has_value()) { fmt::print(" {:>2} ", *instance); diff --git a/model/controller/acl_connection.cc b/model/controller/acl_connection.cc index 33e4c36..3cb4172 100644 --- a/model/controller/acl_connection.cc +++ b/model/controller/acl_connection.cc @@ -23,10 +23,9 @@ #include "phy.h" namespace rootcanal { -AclConnection::AclConnection(AddressWithType address, - AddressWithType own_address, - AddressWithType resolved_address, - Phy::Type phy_type, bluetooth::hci::Role role) +AclConnection::AclConnection(AddressWithType address, AddressWithType own_address, + AddressWithType resolved_address, Phy::Type phy_type, + bluetooth::hci::Role role) : address_(address), own_address_(own_address), resolved_address_(resolved_address), @@ -39,9 +38,7 @@ void AclConnection::Encrypt() { encrypted_ = true; } bool AclConnection::IsEncrypted() const { return encrypted_; } -void AclConnection::SetLinkPolicySettings(uint16_t settings) { - link_policy_settings_ = settings; -} +void AclConnection::SetLinkPolicySettings(uint16_t settings) { link_policy_settings_ = settings; } bluetooth::hci::Role AclConnection::GetRole() const { return role_; } @@ -51,14 +48,10 @@ int8_t AclConnection::GetRssi() const { return rssi_; } void AclConnection::SetRssi(int8_t rssi) { rssi_ = rssi; } -void AclConnection::ResetLinkTimer() { - last_packet_timestamp_ = std::chrono::steady_clock::now(); -} +void AclConnection::ResetLinkTimer() { last_packet_timestamp_ = std::chrono::steady_clock::now(); } -std::chrono::steady_clock::duration AclConnection::TimeUntilNearExpiring() - const { - return (last_packet_timestamp_ + timeout_ / 2) - - std::chrono::steady_clock::now(); +std::chrono::steady_clock::duration AclConnection::TimeUntilNearExpiring() const { + return (last_packet_timestamp_ + timeout_ / 2) - std::chrono::steady_clock::now(); } bool AclConnection::IsNearExpiring() const { diff --git a/model/controller/acl_connection.h b/model/controller/acl_connection.h index 86ba951..793f9e8 100644 --- a/model/controller/acl_connection.h +++ b/model/controller/acl_connection.h @@ -35,10 +35,9 @@ enum AclConnectionState { // Model the connection of a device to the controller. class AclConnection { - public: +public: AclConnection(AddressWithType address, AddressWithType own_address, - AddressWithType resolved_address, Phy::Type phy_type, - bluetooth::hci::Role role); + AddressWithType resolved_address, Phy::Type phy_type, bluetooth::hci::Role role); virtual ~AclConnection() = default; @@ -53,9 +52,7 @@ class AclConnection { void SetLinkPolicySettings(uint16_t settings); uint16_t GetLinkPolicySettings() const { return link_policy_settings_; } - bool IsRoleSwitchEnabled() const { - return (link_policy_settings_ & 0x1) != 0; - } + bool IsRoleSwitchEnabled() const { return (link_policy_settings_ & 0x1) != 0; } bool IsHoldModeEnabled() const { return (link_policy_settings_ & 0x2) != 0; } bool IsSniffModeEnabled() const { return (link_policy_settings_ & 0x4) != 0; } @@ -82,7 +79,7 @@ class AclConnection { void SetTxPhy(bluetooth::hci::PhyType phy) { tx_phy_ = phy; } void SetRxPhy(bluetooth::hci::PhyType phy) { rx_phy_ = phy; } - private: +private: AddressWithType address_; AddressWithType own_address_; AddressWithType resolved_address_; diff --git a/model/controller/acl_connection_handler.cc b/model/controller/acl_connection_handler.cc index 656c495..bdcd1f7 100644 --- a/model/controller/acl_connection_handler.cc +++ b/model/controller/acl_connection_handler.cc @@ -59,8 +59,7 @@ uint16_t AclConnectionHandler::GetUnusedHandle() { // Keep a reserved range of handles for CIS connections implemented // in the rust module. while (HasHandle(last_handle_) || HasScoHandle(last_handle_) || - (last_handle_ >= kCisHandleRangeStart && - last_handle_ < kCisHandleRangeEnd)) { + (last_handle_ >= kCisHandleRangeStart && last_handle_ < kCisHandleRangeEnd)) { last_handle_ = (last_handle_ + 1) % kReservedHandle; } uint16_t unused_handle = last_handle_; @@ -68,8 +67,7 @@ uint16_t AclConnectionHandler::GetUnusedHandle() { return unused_handle; } -bool AclConnectionHandler::CreatePendingConnection(Address addr, - bool authenticate_on_connect, +bool AclConnectionHandler::CreatePendingConnection(Address addr, bool authenticate_on_connect, bool allow_role_switch) { if (classic_connection_pending_ || GetAclConnectionHandle(addr).has_value()) { return false; @@ -99,17 +97,15 @@ bool AclConnectionHandler::CancelPendingConnection(Address addr) { return true; } -bool AclConnectionHandler::CreatePendingLeConnection( - AddressWithType peer, AddressWithType resolved_peer, - AddressWithType local_address) { +bool AclConnectionHandler::CreatePendingLeConnection(AddressWithType peer, + AddressWithType resolved_peer, + AddressWithType local_address) { for (auto pair : acl_connections_) { auto connection = std::get(pair); - if (connection.GetAddress() == peer || - connection.GetResolvedAddress() == resolved_peer) { + if (connection.GetAddress() == peer || connection.GetResolvedAddress() == resolved_peer) { INFO("{}: {} is already connected", __func__, peer); if (connection.GetResolvedAddress() == resolved_peer) { - INFO("{}: allowing a second connection with {}", __func__, - resolved_peer); + INFO("{}: allowing a second connection with {}", __func__, resolved_peer); } else { return false; } @@ -136,44 +132,38 @@ bool AclConnectionHandler::CancelPendingLeConnection(AddressWithType addr) { } le_connection_pending_ = false; pending_le_connection_address_ = - AddressWithType{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; pending_le_connection_resolved_address_ = - AddressWithType{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; return true; } -uint16_t AclConnectionHandler::CreateConnection(Address addr, Address own_addr, - bool pending) { +uint16_t AclConnectionHandler::CreateConnection(Address addr, Address own_addr, bool pending) { if (!pending || CancelPendingConnection(addr)) { uint16_t handle = GetUnusedHandle(); acl_connections_.emplace( - handle, - AclConnection{ - AddressWithType{addr, AddressType::PUBLIC_DEVICE_ADDRESS}, - AddressWithType{own_addr, AddressType::PUBLIC_DEVICE_ADDRESS}, - AddressWithType(), Phy::Type::BR_EDR, - bluetooth::hci::Role::CENTRAL}); + handle, + AclConnection{AddressWithType{addr, AddressType::PUBLIC_DEVICE_ADDRESS}, + AddressWithType{own_addr, AddressType::PUBLIC_DEVICE_ADDRESS}, + AddressWithType(), Phy::Type::BR_EDR, bluetooth::hci::Role::CENTRAL}); return handle; } return kReservedHandle; } -uint16_t AclConnectionHandler::CreateLeConnection(AddressWithType addr, - AddressWithType own_addr, +uint16_t AclConnectionHandler::CreateLeConnection(AddressWithType addr, AddressWithType own_addr, bluetooth::hci::Role role) { AddressWithType resolved_peer = pending_le_connection_resolved_address_; if (CancelPendingLeConnection(addr)) { uint16_t handle = GetUnusedHandle(); - acl_connections_.emplace(handle, - AclConnection{addr, own_addr, resolved_peer, - Phy::Type::LOW_ENERGY, role}); + acl_connections_.emplace( + handle, AclConnection{addr, own_addr, resolved_peer, Phy::Type::LOW_ENERGY, role}); return handle; } return kReservedHandle; } -bool AclConnectionHandler::Disconnect(uint16_t handle, - std::function stopStream) { +bool AclConnectionHandler::Disconnect(uint16_t handle, std::function stopStream) { if (HasScoHandle(handle)) { sco_connections_.at(handle).StopStream(std::move(stopStream)); sco_connections_.erase(handle); @@ -199,8 +189,7 @@ uint16_t AclConnectionHandler::GetHandle(AddressWithType addr) const { return kReservedHandle; } -uint16_t AclConnectionHandler::GetHandleOnlyAddress( - bluetooth::hci::Address addr) const { +uint16_t AclConnectionHandler::GetHandleOnlyAddress(bluetooth::hci::Address addr) const { for (auto pair : acl_connections_) { if (std::get(pair).GetAddress().GetAddress() == addr) { return std::get<0>(pair); @@ -210,7 +199,7 @@ uint16_t AclConnectionHandler::GetHandleOnlyAddress( } std::optional AclConnectionHandler::GetAclConnectionHandle( - bluetooth::hci::Address bd_addr) const { + bluetooth::hci::Address bd_addr) const { for (auto const& [handle, connection] : acl_connections_) { if (connection.GetAddress().GetAddress() == bd_addr && connection.GetPhyType() == Phy::Type::BR_EDR) { @@ -230,8 +219,7 @@ AddressWithType AclConnectionHandler::GetAddress(uint16_t handle) const { return acl_connections_.at(handle).GetAddress(); } -std::optional AclConnectionHandler::GetAddressSafe( - uint16_t handle) const { +std::optional AclConnectionHandler::GetAddressSafe(uint16_t handle) const { return HasHandle(handle) ? acl_connections_.at(handle).GetAddress() : std::optional(); } @@ -246,8 +234,7 @@ AddressWithType AclConnectionHandler::GetOwnAddress(uint16_t handle) const { return acl_connections_.at(handle).GetOwnAddress(); } -AddressWithType AclConnectionHandler::GetResolvedAddress( - uint16_t handle) const { +AddressWithType AclConnectionHandler::GetResolvedAddress(uint16_t handle) const { ASSERT_LOG(HasHandle(handle), "Unknown handle %hd", handle); return acl_connections_.at(handle).GetResolvedAddress(); } @@ -287,8 +274,7 @@ uint16_t AclConnectionHandler::GetAclLinkPolicySettings(uint16_t handle) const { return acl_connections_.at(handle).GetLinkPolicySettings(); } -void AclConnectionHandler::SetAclLinkPolicySettings(uint16_t handle, - uint16_t settings) { +void AclConnectionHandler::SetAclLinkPolicySettings(uint16_t handle, uint16_t settings) { acl_connections_.at(handle).SetLinkPolicySettings(settings); } @@ -296,34 +282,29 @@ bluetooth::hci::Role AclConnectionHandler::GetAclRole(uint16_t handle) const { return acl_connections_.at(handle).GetRole(); } -void AclConnectionHandler::SetAclRole(uint16_t handle, - bluetooth::hci::Role role) { +void AclConnectionHandler::SetAclRole(uint16_t handle, bluetooth::hci::Role role) { acl_connections_.at(handle).SetRole(role); } -void AclConnectionHandler::CreateScoConnection( - bluetooth::hci::Address addr, ScoConnectionParameters const& parameters, - ScoState state, ScoDatapath datapath, bool legacy) { +void AclConnectionHandler::CreateScoConnection(bluetooth::hci::Address addr, + ScoConnectionParameters const& parameters, + ScoState state, ScoDatapath datapath, bool legacy) { uint16_t sco_handle = GetUnusedHandle(); - sco_connections_.emplace( - sco_handle, ScoConnection(addr, parameters, state, datapath, legacy)); + sco_connections_.emplace(sco_handle, ScoConnection(addr, parameters, state, datapath, 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(pair).GetAddress() == addr) { ScoState state = std::get(pair).GetState(); - return state == SCO_STATE_PENDING || - state == SCO_STATE_SENT_ESCO_CONNECTION_REQUEST || + return state == SCO_STATE_PENDING || state == SCO_STATE_SENT_ESCO_CONNECTION_REQUEST || state == SCO_STATE_SENT_SCO_CONNECTION_REQUEST; } } 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(pair).GetAddress() == addr) { return std::get(pair).GetState(); @@ -332,8 +313,7 @@ ScoState AclConnectionHandler::GetScoConnectionState( 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(pair).GetAddress() == addr) { return std::get(pair).IsLegacy(); @@ -342,8 +322,7 @@ bool AclConnectionHandler::IsLegacyScoConnection( 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(*it).GetAddress() == addr) { sco_connections_.erase(it); @@ -352,9 +331,9 @@ void AclConnectionHandler::CancelPendingScoConnection( } } -bool AclConnectionHandler::AcceptPendingScoConnection( - bluetooth::hci::Address addr, ScoLinkParameters const& parameters, - std::function startStream) { +bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr, + ScoLinkParameters const& parameters, + std::function startStream) { for (auto& pair : sco_connections_) { if (std::get(pair).GetAddress() == addr) { std::get(pair).SetLinkParameters(parameters); @@ -366,13 +345,12 @@ bool AclConnectionHandler::AcceptPendingScoConnection( return false; } -bool AclConnectionHandler::AcceptPendingScoConnection( - bluetooth::hci::Address addr, ScoConnectionParameters const& parameters, - std::function startStream) { +bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr, + ScoConnectionParameters const& parameters, + std::function startStream) { for (auto& pair : sco_connections_) { if (std::get(pair).GetAddress() == addr) { - bool ok = - std::get(pair).NegotiateLinkParameters(parameters); + bool ok = std::get(pair).NegotiateLinkParameters(parameters); std::get(pair).SetState(ok ? ScoState::SCO_STATE_OPENED : ScoState::SCO_STATE_CLOSED); if (ok) { @@ -384,8 +362,7 @@ bool AclConnectionHandler::AcceptPendingScoConnection( 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(pair).GetAddress() == addr) { return std::get<0>(pair); @@ -395,7 +372,7 @@ uint16_t AclConnectionHandler::GetScoHandle( } ScoConnectionParameters AclConnectionHandler::GetScoConnectionParameters( - bluetooth::hci::Address addr) const { + bluetooth::hci::Address addr) const { for (const auto& pair : sco_connections_) { if (std::get(pair).GetAddress() == addr) { return std::get(pair).GetConnectionParameters(); @@ -404,8 +381,7 @@ 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(pair).GetAddress() == addr) { return std::get(pair).GetLinkParameters(); @@ -427,8 +403,8 @@ void AclConnectionHandler::ResetLinkTimer(uint16_t handle) { acl_connections_.at(handle).ResetLinkTimer(); } -std::chrono::steady_clock::duration -AclConnectionHandler::TimeUntilLinkNearExpiring(uint16_t handle) const { +std::chrono::steady_clock::duration AclConnectionHandler::TimeUntilLinkNearExpiring( + uint16_t handle) const { return acl_connections_.at(handle).TimeUntilNearExpiring(); } @@ -437,7 +413,7 @@ bool AclConnectionHandler::IsLinkNearExpiring(uint16_t handle) const { } std::chrono::steady_clock::duration AclConnectionHandler::TimeUntilLinkExpired( - uint16_t handle) const { + uint16_t handle) const { return acl_connections_.at(handle).TimeUntilExpired(); } diff --git a/model/controller/acl_connection_handler.h b/model/controller/acl_connection_handler.h index 146cc47..b25181b 100644 --- a/model/controller/acl_connection_handler.h +++ b/model/controller/acl_connection_handler.h @@ -36,7 +36,7 @@ static constexpr uint16_t kCisHandleRangeStart = 0xE00; static constexpr uint16_t kCisHandleRangeEnd = 0xEFE; class AclConnectionHandler { - public: +public: AclConnectionHandler() = default; virtual ~AclConnectionHandler() = default; @@ -46,8 +46,7 @@ class AclConnectionHandler { // SCO connections. void Reset(std::function stopStream); - bool CreatePendingConnection(bluetooth::hci::Address addr, - bool authenticate_on_connect, + bool CreatePendingConnection(bluetooth::hci::Address addr, bool authenticate_on_connect, bool allow_role_switch); bool HasPendingConnection(bluetooth::hci::Address addr) const; bool CancelPendingConnection(bluetooth::hci::Address addr); @@ -56,20 +55,16 @@ class AclConnectionHandler { bool HasPendingScoConnection(bluetooth::hci::Address addr) const; ScoState GetScoConnectionState(bluetooth::hci::Address addr) const; bool IsLegacyScoConnection(bluetooth::hci::Address addr) const; - void CreateScoConnection(bluetooth::hci::Address addr, - ScoConnectionParameters const& parameters, - ScoState state, ScoDatapath datapath, - bool legacy = false); + void CreateScoConnection(bluetooth::hci::Address addr, ScoConnectionParameters const& parameters, + ScoState state, ScoDatapath datapath, bool legacy = false); void CancelPendingScoConnection(bluetooth::hci::Address addr); - bool AcceptPendingScoConnection(bluetooth::hci::Address addr, - ScoLinkParameters const& parameters, + bool AcceptPendingScoConnection(bluetooth::hci::Address addr, ScoLinkParameters const& parameters, std::function startStream); bool AcceptPendingScoConnection(bluetooth::hci::Address addr, ScoConnectionParameters const& parameters, std::function startStream); uint16_t GetScoHandle(bluetooth::hci::Address addr) const; - ScoConnectionParameters GetScoConnectionParameters( - bluetooth::hci::Address addr) const; + ScoConnectionParameters GetScoConnectionParameters(bluetooth::hci::Address addr) const; ScoLinkParameters GetScoLinkParameters(bluetooth::hci::Address addr) const; bool CreatePendingLeConnection(bluetooth::hci::AddressWithType peer, @@ -80,20 +75,17 @@ class AclConnectionHandler { // \p pending is true if the connection is expected to be // in pending state. - uint16_t CreateConnection(bluetooth::hci::Address addr, - bluetooth::hci::Address own_addr, + uint16_t CreateConnection(bluetooth::hci::Address addr, bluetooth::hci::Address own_addr, bool pending = true); uint16_t CreateLeConnection(bluetooth::hci::AddressWithType addr, - bluetooth::hci::AddressWithType own_addr, - bluetooth::hci::Role role); + bluetooth::hci::AddressWithType own_addr, bluetooth::hci::Role role); bool Disconnect(uint16_t handle, std::function stopStream); bool HasHandle(uint16_t handle) const; bool HasScoHandle(uint16_t handle) const; // Return the connection handle for a classic ACL connection only. // \p bd_addr is the peer address. - std::optional GetAclConnectionHandle( - bluetooth::hci::Address bd_addr) const; + std::optional GetAclConnectionHandle(bluetooth::hci::Address bd_addr) const; uint16_t GetHandle(bluetooth::hci::AddressWithType addr) const; uint16_t GetHandleOnlyAddress(bluetooth::hci::Address addr) const; @@ -124,33 +116,27 @@ class AclConnectionHandler { std::vector GetAclHandles() const; void ResetLinkTimer(uint16_t handle); - std::chrono::steady_clock::duration TimeUntilLinkNearExpiring( - uint16_t handle) const; + std::chrono::steady_clock::duration TimeUntilLinkNearExpiring(uint16_t handle) const; bool IsLinkNearExpiring(uint16_t handle) const; - std::chrono::steady_clock::duration TimeUntilLinkExpired( - uint16_t handle) const; + std::chrono::steady_clock::duration TimeUntilLinkExpired(uint16_t handle) const; bool HasLinkExpired(uint16_t handle) const; bool IsRoleSwitchAllowedForPendingConnection() const; - private: +private: std::unordered_map acl_connections_; std::unordered_map sco_connections_; bool classic_connection_pending_{false}; - bluetooth::hci::Address pending_connection_address_{ - bluetooth::hci::Address::kEmpty}; + bluetooth::hci::Address pending_connection_address_{bluetooth::hci::Address::kEmpty}; bool authenticate_pending_classic_connection_{false}; bool pending_classic_connection_allow_role_switch_{false}; bool le_connection_pending_{false}; bluetooth::hci::AddressWithType pending_le_connection_address_{ - bluetooth::hci::Address::kEmpty, - bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS}; + bluetooth::hci::Address::kEmpty, bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS}; bluetooth::hci::AddressWithType pending_le_connection_own_address_{ - bluetooth::hci::Address::kEmpty, - bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS}; + bluetooth::hci::Address::kEmpty, bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS}; bluetooth::hci::AddressWithType pending_le_connection_resolved_address_{ - bluetooth::hci::Address::kEmpty, - bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS}; + bluetooth::hci::Address::kEmpty, bluetooth::hci::AddressType::PUBLIC_DEVICE_ADDRESS}; uint16_t GetUnusedHandle(); uint16_t last_handle_{kReservedHandle - 2}; diff --git a/model/controller/controller_properties.cc b/model/controller/controller_properties.cc index 4919887..3f6c918 100644 --- a/model/controller/controller_properties.cc +++ b/model/controller/controller_properties.cc @@ -30,55 +30,55 @@ using namespace bluetooth::hci; static constexpr uint64_t Page0LmpFeatures() { LMPFeaturesPage0Bits features[] = { - LMPFeaturesPage0Bits::LMP_3_SLOT_PACKETS, - LMPFeaturesPage0Bits::LMP_5_SLOT_PACKETS, - LMPFeaturesPage0Bits::ENCRYPTION, - LMPFeaturesPage0Bits::SLOT_OFFSET, - LMPFeaturesPage0Bits::TIMING_ACCURACY, - LMPFeaturesPage0Bits::ROLE_SWITCH, - LMPFeaturesPage0Bits::HOLD_MODE, - LMPFeaturesPage0Bits::SNIFF_MODE, - LMPFeaturesPage0Bits::POWER_CONTROL_REQUESTS, - LMPFeaturesPage0Bits::CHANNEL_QUALITY_DRIVEN_DATA_RATE, - LMPFeaturesPage0Bits::SCO_LINK, - LMPFeaturesPage0Bits::HV2_PACKETS, - LMPFeaturesPage0Bits::HV3_PACKETS, - LMPFeaturesPage0Bits::M_LAW_LOG_SYNCHRONOUS_DATA, - LMPFeaturesPage0Bits::A_LAW_LOG_SYNCHRONOUS_DATA, - LMPFeaturesPage0Bits::CVSD_SYNCHRONOUS_DATA, - LMPFeaturesPage0Bits::PAGING_PARAMETER_NEGOTIATION, - LMPFeaturesPage0Bits::POWER_CONTROL, - LMPFeaturesPage0Bits::TRANSPARENT_SYNCHRONOUS_DATA, - LMPFeaturesPage0Bits::BROADCAST_ENCRYPTION, - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE, - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE, - LMPFeaturesPage0Bits::ENHANCED_INQUIRY_SCAN, - LMPFeaturesPage0Bits::INTERLACED_INQUIRY_SCAN, - LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN, - LMPFeaturesPage0Bits::RSSI_WITH_INQUIRY_RESULTS, - LMPFeaturesPage0Bits::EXTENDED_SCO_LINK, - LMPFeaturesPage0Bits::EV4_PACKETS, - LMPFeaturesPage0Bits::EV5_PACKETS, - LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL, - LMPFeaturesPage0Bits::AFH_CLASSIFICATION_PERIPHERAL, - LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER, - LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS, - LMPFeaturesPage0Bits::LMP_5_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS, - LMPFeaturesPage0Bits::SNIFF_SUBRATING, - LMPFeaturesPage0Bits::PAUSE_ENCRYPTION, - LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL, - LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL, - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE, - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_3_MB_S_MODE, - LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS, - LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE, - LMPFeaturesPage0Bits::SIMULTANEOUS_LE_AND_BR_CONTROLLER, - LMPFeaturesPage0Bits::SECURE_SIMPLE_PAIRING_CONTROLLER, - LMPFeaturesPage0Bits::ENCAPSULATED_PDU, - LMPFeaturesPage0Bits::HCI_LINK_SUPERVISION_TIMEOUT_CHANGED_EVENT, - LMPFeaturesPage0Bits::VARIABLE_INQUIRY_TX_POWER_LEVEL, - LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL, - LMPFeaturesPage0Bits::EXTENDED_FEATURES}; + LMPFeaturesPage0Bits::LMP_3_SLOT_PACKETS, + LMPFeaturesPage0Bits::LMP_5_SLOT_PACKETS, + LMPFeaturesPage0Bits::ENCRYPTION, + LMPFeaturesPage0Bits::SLOT_OFFSET, + LMPFeaturesPage0Bits::TIMING_ACCURACY, + LMPFeaturesPage0Bits::ROLE_SWITCH, + LMPFeaturesPage0Bits::HOLD_MODE, + LMPFeaturesPage0Bits::SNIFF_MODE, + LMPFeaturesPage0Bits::POWER_CONTROL_REQUESTS, + LMPFeaturesPage0Bits::CHANNEL_QUALITY_DRIVEN_DATA_RATE, + LMPFeaturesPage0Bits::SCO_LINK, + LMPFeaturesPage0Bits::HV2_PACKETS, + LMPFeaturesPage0Bits::HV3_PACKETS, + LMPFeaturesPage0Bits::M_LAW_LOG_SYNCHRONOUS_DATA, + LMPFeaturesPage0Bits::A_LAW_LOG_SYNCHRONOUS_DATA, + LMPFeaturesPage0Bits::CVSD_SYNCHRONOUS_DATA, + LMPFeaturesPage0Bits::PAGING_PARAMETER_NEGOTIATION, + LMPFeaturesPage0Bits::POWER_CONTROL, + LMPFeaturesPage0Bits::TRANSPARENT_SYNCHRONOUS_DATA, + LMPFeaturesPage0Bits::BROADCAST_ENCRYPTION, + LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE, + LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE, + LMPFeaturesPage0Bits::ENHANCED_INQUIRY_SCAN, + LMPFeaturesPage0Bits::INTERLACED_INQUIRY_SCAN, + LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN, + LMPFeaturesPage0Bits::RSSI_WITH_INQUIRY_RESULTS, + LMPFeaturesPage0Bits::EXTENDED_SCO_LINK, + LMPFeaturesPage0Bits::EV4_PACKETS, + LMPFeaturesPage0Bits::EV5_PACKETS, + LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL, + LMPFeaturesPage0Bits::AFH_CLASSIFICATION_PERIPHERAL, + LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER, + LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS, + LMPFeaturesPage0Bits::LMP_5_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS, + LMPFeaturesPage0Bits::SNIFF_SUBRATING, + LMPFeaturesPage0Bits::PAUSE_ENCRYPTION, + LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL, + LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL, + LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE, + LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_3_MB_S_MODE, + LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS, + LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE, + LMPFeaturesPage0Bits::SIMULTANEOUS_LE_AND_BR_CONTROLLER, + LMPFeaturesPage0Bits::SECURE_SIMPLE_PAIRING_CONTROLLER, + LMPFeaturesPage0Bits::ENCAPSULATED_PDU, + LMPFeaturesPage0Bits::HCI_LINK_SUPERVISION_TIMEOUT_CHANGED_EVENT, + LMPFeaturesPage0Bits::VARIABLE_INQUIRY_TX_POWER_LEVEL, + LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL, + LMPFeaturesPage0Bits::EXTENDED_FEATURES}; uint64_t value = 0; for (auto feature : features) { @@ -89,8 +89,8 @@ static constexpr uint64_t Page0LmpFeatures() { static constexpr uint64_t Page2LmpFeatures() { LMPFeaturesPage2Bits features[] = { - LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT, - LMPFeaturesPage2Bits::PING, + LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT, + LMPFeaturesPage2Bits::PING, }; uint64_t value = 0; @@ -102,20 +102,20 @@ static constexpr uint64_t Page2LmpFeatures() { static constexpr uint64_t LlFeatures() { LLFeaturesBits features[] = { - LLFeaturesBits::LE_ENCRYPTION, - LLFeaturesBits::CONNECTION_PARAMETERS_REQUEST_PROCEDURE, - LLFeaturesBits::EXTENDED_REJECT_INDICATION, - LLFeaturesBits::PERIPHERAL_INITIATED_FEATURES_EXCHANGE, - LLFeaturesBits::LE_PING, - LLFeaturesBits::LL_PRIVACY, - LLFeaturesBits::EXTENDED_SCANNER_FILTER_POLICIES, - LLFeaturesBits::LE_2M_PHY, - LLFeaturesBits::LE_CODED_PHY, - LLFeaturesBits::LE_EXTENDED_ADVERTISING, - LLFeaturesBits::LE_PERIODIC_ADVERTISING, + LLFeaturesBits::LE_ENCRYPTION, + LLFeaturesBits::CONNECTION_PARAMETERS_REQUEST_PROCEDURE, + LLFeaturesBits::EXTENDED_REJECT_INDICATION, + LLFeaturesBits::PERIPHERAL_INITIATED_FEATURES_EXCHANGE, + LLFeaturesBits::LE_PING, + LLFeaturesBits::LL_PRIVACY, + LLFeaturesBits::EXTENDED_SCANNER_FILTER_POLICIES, + LLFeaturesBits::LE_2M_PHY, + LLFeaturesBits::LE_CODED_PHY, + LLFeaturesBits::LE_EXTENDED_ADVERTISING, + LLFeaturesBits::LE_PERIODIC_ADVERTISING, - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL, - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL, + LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL, + LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL, }; uint64_t value = 0; @@ -127,283 +127,245 @@ static constexpr uint64_t LlFeatures() { static std::array SupportedCommands() { OpCodeIndex supported_commands[] = { - // LINK_CONTROL - OpCodeIndex::INQUIRY, OpCodeIndex::INQUIRY_CANCEL, - // OpCodeIndex::PERIODIC_INQUIRY_MODE, - // OpCodeIndex::EXIT_PERIODIC_INQUIRY_MODE, - OpCodeIndex::CREATE_CONNECTION, OpCodeIndex::DISCONNECT, - OpCodeIndex::ADD_SCO_CONNECTION, OpCodeIndex::CREATE_CONNECTION_CANCEL, - OpCodeIndex::ACCEPT_CONNECTION_REQUEST, - OpCodeIndex::REJECT_CONNECTION_REQUEST, - OpCodeIndex::LINK_KEY_REQUEST_REPLY, - OpCodeIndex::LINK_KEY_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::PIN_CODE_REQUEST_REPLY, - OpCodeIndex::PIN_CODE_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::CHANGE_CONNECTION_PACKET_TYPE, - OpCodeIndex::AUTHENTICATION_REQUESTED, - OpCodeIndex::SET_CONNECTION_ENCRYPTION, - OpCodeIndex::CHANGE_CONNECTION_LINK_KEY, OpCodeIndex::CENTRAL_LINK_KEY, - OpCodeIndex::REMOTE_NAME_REQUEST, - // OpCodeIndex::REMOTE_NAME_REQUEST_CANCEL, - OpCodeIndex::READ_REMOTE_SUPPORTED_FEATURES, - OpCodeIndex::READ_REMOTE_EXTENDED_FEATURES, - OpCodeIndex::READ_REMOTE_VERSION_INFORMATION, - OpCodeIndex::READ_CLOCK_OFFSET, OpCodeIndex::READ_LMP_HANDLE, - OpCodeIndex::SETUP_SYNCHRONOUS_CONNECTION, - OpCodeIndex::ACCEPT_SYNCHRONOUS_CONNECTION, - OpCodeIndex::REJECT_SYNCHRONOUS_CONNECTION, - OpCodeIndex::IO_CAPABILITY_REQUEST_REPLY, - OpCodeIndex::USER_CONFIRMATION_REQUEST_REPLY, - OpCodeIndex::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::USER_PASSKEY_REQUEST_REPLY, - OpCodeIndex::USER_PASSKEY_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::REMOTE_OOB_DATA_REQUEST_REPLY, - OpCodeIndex::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::ENHANCED_SETUP_SYNCHRONOUS_CONNECTION, - OpCodeIndex::ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, - // OpCodeIndex::TRUNCATED_PAGE, - // OpCodeIndex::TRUNCATED_PAGE_CANCEL, - // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST, - // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, - // OpCodeIndex::START_SYNCHRONIZATION_TRAIN, - // OpCodeIndex::RECEIVE_SYNCHRONIZATION_TRAIN, - OpCodeIndex::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY, + // LINK_CONTROL + OpCodeIndex::INQUIRY, OpCodeIndex::INQUIRY_CANCEL, + // OpCodeIndex::PERIODIC_INQUIRY_MODE, + // OpCodeIndex::EXIT_PERIODIC_INQUIRY_MODE, + OpCodeIndex::CREATE_CONNECTION, OpCodeIndex::DISCONNECT, OpCodeIndex::ADD_SCO_CONNECTION, + OpCodeIndex::CREATE_CONNECTION_CANCEL, OpCodeIndex::ACCEPT_CONNECTION_REQUEST, + OpCodeIndex::REJECT_CONNECTION_REQUEST, OpCodeIndex::LINK_KEY_REQUEST_REPLY, + OpCodeIndex::LINK_KEY_REQUEST_NEGATIVE_REPLY, OpCodeIndex::PIN_CODE_REQUEST_REPLY, + OpCodeIndex::PIN_CODE_REQUEST_NEGATIVE_REPLY, OpCodeIndex::CHANGE_CONNECTION_PACKET_TYPE, + OpCodeIndex::AUTHENTICATION_REQUESTED, OpCodeIndex::SET_CONNECTION_ENCRYPTION, + OpCodeIndex::CHANGE_CONNECTION_LINK_KEY, OpCodeIndex::CENTRAL_LINK_KEY, + OpCodeIndex::REMOTE_NAME_REQUEST, + // OpCodeIndex::REMOTE_NAME_REQUEST_CANCEL, + OpCodeIndex::READ_REMOTE_SUPPORTED_FEATURES, OpCodeIndex::READ_REMOTE_EXTENDED_FEATURES, + OpCodeIndex::READ_REMOTE_VERSION_INFORMATION, OpCodeIndex::READ_CLOCK_OFFSET, + OpCodeIndex::READ_LMP_HANDLE, OpCodeIndex::SETUP_SYNCHRONOUS_CONNECTION, + OpCodeIndex::ACCEPT_SYNCHRONOUS_CONNECTION, OpCodeIndex::REJECT_SYNCHRONOUS_CONNECTION, + OpCodeIndex::IO_CAPABILITY_REQUEST_REPLY, OpCodeIndex::USER_CONFIRMATION_REQUEST_REPLY, + OpCodeIndex::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, + OpCodeIndex::USER_PASSKEY_REQUEST_REPLY, OpCodeIndex::USER_PASSKEY_REQUEST_NEGATIVE_REPLY, + OpCodeIndex::REMOTE_OOB_DATA_REQUEST_REPLY, + OpCodeIndex::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, + OpCodeIndex::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, + OpCodeIndex::ENHANCED_SETUP_SYNCHRONOUS_CONNECTION, + OpCodeIndex::ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, + // OpCodeIndex::TRUNCATED_PAGE, + // OpCodeIndex::TRUNCATED_PAGE_CANCEL, + // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST, + // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, + // OpCodeIndex::START_SYNCHRONIZATION_TRAIN, + // OpCodeIndex::RECEIVE_SYNCHRONIZATION_TRAIN, + OpCodeIndex::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY, - // LINK_POLICY - OpCodeIndex::HOLD_MODE, OpCodeIndex::SNIFF_MODE, - OpCodeIndex::EXIT_SNIFF_MODE, OpCodeIndex::QOS_SETUP, - OpCodeIndex::ROLE_DISCOVERY, OpCodeIndex::SWITCH_ROLE, - OpCodeIndex::READ_LINK_POLICY_SETTINGS, - OpCodeIndex::WRITE_LINK_POLICY_SETTINGS, - OpCodeIndex::READ_DEFAULT_LINK_POLICY_SETTINGS, - OpCodeIndex::WRITE_DEFAULT_LINK_POLICY_SETTINGS, - OpCodeIndex::FLOW_SPECIFICATION, OpCodeIndex::SNIFF_SUBRATING, + // LINK_POLICY + OpCodeIndex::HOLD_MODE, OpCodeIndex::SNIFF_MODE, OpCodeIndex::EXIT_SNIFF_MODE, + OpCodeIndex::QOS_SETUP, OpCodeIndex::ROLE_DISCOVERY, OpCodeIndex::SWITCH_ROLE, + OpCodeIndex::READ_LINK_POLICY_SETTINGS, OpCodeIndex::WRITE_LINK_POLICY_SETTINGS, + OpCodeIndex::READ_DEFAULT_LINK_POLICY_SETTINGS, + OpCodeIndex::WRITE_DEFAULT_LINK_POLICY_SETTINGS, OpCodeIndex::FLOW_SPECIFICATION, + OpCodeIndex::SNIFF_SUBRATING, - // CONTROLLER_AND_BASEBAND - OpCodeIndex::SET_EVENT_MASK, OpCodeIndex::RESET, - OpCodeIndex::SET_EVENT_FILTER, OpCodeIndex::FLUSH, - // OpCodeIndex::READ_PIN_TYPE, - // OpCodeIndex::WRITE_PIN_TYPE, - // OpCodeIndex::READ_STORED_LINK_KEY, - // OpCodeIndex::WRITE_STORED_LINK_KEY, - OpCodeIndex::DELETE_STORED_LINK_KEY, OpCodeIndex::WRITE_LOCAL_NAME, - OpCodeIndex::READ_LOCAL_NAME, OpCodeIndex::READ_CONNECTION_ACCEPT_TIMEOUT, - OpCodeIndex::WRITE_CONNECTION_ACCEPT_TIMEOUT, - OpCodeIndex::READ_PAGE_TIMEOUT, OpCodeIndex::WRITE_PAGE_TIMEOUT, - OpCodeIndex::READ_SCAN_ENABLE, OpCodeIndex::WRITE_SCAN_ENABLE, - OpCodeIndex::READ_PAGE_SCAN_ACTIVITY, - OpCodeIndex::WRITE_PAGE_SCAN_ACTIVITY, - OpCodeIndex::READ_INQUIRY_SCAN_ACTIVITY, - OpCodeIndex::WRITE_INQUIRY_SCAN_ACTIVITY, - OpCodeIndex::READ_AUTHENTICATION_ENABLE, - OpCodeIndex::WRITE_AUTHENTICATION_ENABLE, - OpCodeIndex::READ_CLASS_OF_DEVICE, OpCodeIndex::WRITE_CLASS_OF_DEVICE, - OpCodeIndex::READ_VOICE_SETTING, OpCodeIndex::WRITE_VOICE_SETTING, - OpCodeIndex::READ_AUTOMATIC_FLUSH_TIMEOUT, - OpCodeIndex::WRITE_AUTOMATIC_FLUSH_TIMEOUT, - // OpCodeIndex::READ_NUM_BROADCAST_RETRANSMITS, - // OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS, - OpCodeIndex::READ_HOLD_MODE_ACTIVITY, - OpCodeIndex::WRITE_HOLD_MODE_ACTIVITY, - OpCodeIndex::READ_TRANSMIT_POWER_LEVEL, - OpCodeIndex::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, - OpCodeIndex::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, - OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL, - OpCodeIndex::HOST_BUFFER_SIZE, - OpCodeIndex::HOST_NUMBER_OF_COMPLETED_PACKETS, - OpCodeIndex::READ_LINK_SUPERVISION_TIMEOUT, - OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT, - OpCodeIndex::READ_NUMBER_OF_SUPPORTED_IAC, - OpCodeIndex::READ_CURRENT_IAC_LAP, OpCodeIndex::WRITE_CURRENT_IAC_LAP, - OpCodeIndex::SET_AFH_HOST_CHANNEL_CLASSIFICATION, - OpCodeIndex::READ_INQUIRY_SCAN_TYPE, OpCodeIndex::WRITE_INQUIRY_SCAN_TYPE, - OpCodeIndex::READ_INQUIRY_MODE, OpCodeIndex::WRITE_INQUIRY_MODE, - OpCodeIndex::READ_PAGE_SCAN_TYPE, OpCodeIndex::WRITE_PAGE_SCAN_TYPE, - OpCodeIndex::READ_AFH_CHANNEL_ASSESSMENT_MODE, - OpCodeIndex::WRITE_AFH_CHANNEL_ASSESSMENT_MODE, - OpCodeIndex::READ_EXTENDED_INQUIRY_RESPONSE, - OpCodeIndex::WRITE_EXTENDED_INQUIRY_RESPONSE, - OpCodeIndex::REFRESH_ENCRYPTION_KEY, - OpCodeIndex::READ_SIMPLE_PAIRING_MODE, - OpCodeIndex::WRITE_SIMPLE_PAIRING_MODE, OpCodeIndex::READ_LOCAL_OOB_DATA, - OpCodeIndex::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL, - OpCodeIndex::WRITE_INQUIRY_TRANSMIT_POWER_LEVEL, - // OpCodeIndex::READ_DEFAULT_ERRONEOUS_DATA_REPORTING, - // OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, - OpCodeIndex::ENHANCED_FLUSH, OpCodeIndex::SEND_KEYPRESS_NOTIFICATION, - OpCodeIndex::SET_EVENT_MASK_PAGE_2, - // OpCodeIndex::READ_FLOW_CONTROL_MODE, - // OpCodeIndex::WRITE_FLOW_CONTROL_MODE, - OpCodeIndex::READ_ENHANCED_TRANSMIT_POWER_LEVEL, - OpCodeIndex::READ_LE_HOST_SUPPORT, OpCodeIndex::WRITE_LE_HOST_SUPPORT, - // OpCodeIndex::SET_MWS_CHANNEL_PARAMETERS, - // OpCodeIndex::SET_EXTERNAL_FRAME_CONFIGURATION, - // OpCodeIndex::SET_MWS_SIGNALING, - // OpCodeIndex::SET_MWS_TRANSPORT_LAYER, - // OpCodeIndex::SET_MWS_SCAN_FREQUENCY_TABLE, - // OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION, - // OpCodeIndex::SET_RESERVED_LT_ADDR, - // OpCodeIndex::DELETE_RESERVED_LT_ADDR, - // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA, - // OpCodeIndex::READ_SYNCHRONIZATION_TRAIN_PARAMETERS, - // OpCodeIndex::WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS, - OpCodeIndex::READ_SECURE_CONNECTIONS_HOST_SUPPORT, - OpCodeIndex::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, - OpCodeIndex::READ_AUTHENTICATED_PAYLOAD_TIMEOUT, - OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT, - OpCodeIndex::READ_LOCAL_OOB_EXTENDED_DATA, - // OpCodeIndex::READ_EXTENDED_PAGE_TIMEOUT, - // OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT, - // OpCodeIndex::READ_EXTENDED_INQUIRY_LENGTH, - // OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH, - // OpCodeIndex::SET_ECOSYSTEM_BASE_INTERVAL, - // OpCodeIndex::CONFIGURE_DATA_PATH, - // OpCodeIndex::SET_MIN_ENCRYPTION_KEY_SIZE, + // CONTROLLER_AND_BASEBAND + OpCodeIndex::SET_EVENT_MASK, OpCodeIndex::RESET, OpCodeIndex::SET_EVENT_FILTER, + OpCodeIndex::FLUSH, + // OpCodeIndex::READ_PIN_TYPE, + // OpCodeIndex::WRITE_PIN_TYPE, + // OpCodeIndex::READ_STORED_LINK_KEY, + // OpCodeIndex::WRITE_STORED_LINK_KEY, + OpCodeIndex::DELETE_STORED_LINK_KEY, OpCodeIndex::WRITE_LOCAL_NAME, + OpCodeIndex::READ_LOCAL_NAME, OpCodeIndex::READ_CONNECTION_ACCEPT_TIMEOUT, + OpCodeIndex::WRITE_CONNECTION_ACCEPT_TIMEOUT, OpCodeIndex::READ_PAGE_TIMEOUT, + OpCodeIndex::WRITE_PAGE_TIMEOUT, OpCodeIndex::READ_SCAN_ENABLE, + OpCodeIndex::WRITE_SCAN_ENABLE, OpCodeIndex::READ_PAGE_SCAN_ACTIVITY, + OpCodeIndex::WRITE_PAGE_SCAN_ACTIVITY, OpCodeIndex::READ_INQUIRY_SCAN_ACTIVITY, + OpCodeIndex::WRITE_INQUIRY_SCAN_ACTIVITY, OpCodeIndex::READ_AUTHENTICATION_ENABLE, + OpCodeIndex::WRITE_AUTHENTICATION_ENABLE, OpCodeIndex::READ_CLASS_OF_DEVICE, + OpCodeIndex::WRITE_CLASS_OF_DEVICE, OpCodeIndex::READ_VOICE_SETTING, + OpCodeIndex::WRITE_VOICE_SETTING, OpCodeIndex::READ_AUTOMATIC_FLUSH_TIMEOUT, + OpCodeIndex::WRITE_AUTOMATIC_FLUSH_TIMEOUT, + // OpCodeIndex::READ_NUM_BROADCAST_RETRANSMITS, + // OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS, + OpCodeIndex::READ_HOLD_MODE_ACTIVITY, OpCodeIndex::WRITE_HOLD_MODE_ACTIVITY, + OpCodeIndex::READ_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, + OpCodeIndex::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, + OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL, OpCodeIndex::HOST_BUFFER_SIZE, + OpCodeIndex::HOST_NUMBER_OF_COMPLETED_PACKETS, OpCodeIndex::READ_LINK_SUPERVISION_TIMEOUT, + OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT, OpCodeIndex::READ_NUMBER_OF_SUPPORTED_IAC, + OpCodeIndex::READ_CURRENT_IAC_LAP, OpCodeIndex::WRITE_CURRENT_IAC_LAP, + OpCodeIndex::SET_AFH_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::READ_INQUIRY_SCAN_TYPE, + OpCodeIndex::WRITE_INQUIRY_SCAN_TYPE, OpCodeIndex::READ_INQUIRY_MODE, + OpCodeIndex::WRITE_INQUIRY_MODE, OpCodeIndex::READ_PAGE_SCAN_TYPE, + OpCodeIndex::WRITE_PAGE_SCAN_TYPE, OpCodeIndex::READ_AFH_CHANNEL_ASSESSMENT_MODE, + OpCodeIndex::WRITE_AFH_CHANNEL_ASSESSMENT_MODE, + OpCodeIndex::READ_EXTENDED_INQUIRY_RESPONSE, OpCodeIndex::WRITE_EXTENDED_INQUIRY_RESPONSE, + OpCodeIndex::REFRESH_ENCRYPTION_KEY, OpCodeIndex::READ_SIMPLE_PAIRING_MODE, + OpCodeIndex::WRITE_SIMPLE_PAIRING_MODE, OpCodeIndex::READ_LOCAL_OOB_DATA, + OpCodeIndex::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL, + OpCodeIndex::WRITE_INQUIRY_TRANSMIT_POWER_LEVEL, + // OpCodeIndex::READ_DEFAULT_ERRONEOUS_DATA_REPORTING, + // OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, + OpCodeIndex::ENHANCED_FLUSH, OpCodeIndex::SEND_KEYPRESS_NOTIFICATION, + OpCodeIndex::SET_EVENT_MASK_PAGE_2, + // OpCodeIndex::READ_FLOW_CONTROL_MODE, + // OpCodeIndex::WRITE_FLOW_CONTROL_MODE, + OpCodeIndex::READ_ENHANCED_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_LE_HOST_SUPPORT, + OpCodeIndex::WRITE_LE_HOST_SUPPORT, + // OpCodeIndex::SET_MWS_CHANNEL_PARAMETERS, + // OpCodeIndex::SET_EXTERNAL_FRAME_CONFIGURATION, + // OpCodeIndex::SET_MWS_SIGNALING, + // OpCodeIndex::SET_MWS_TRANSPORT_LAYER, + // OpCodeIndex::SET_MWS_SCAN_FREQUENCY_TABLE, + // OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION, + // OpCodeIndex::SET_RESERVED_LT_ADDR, + // OpCodeIndex::DELETE_RESERVED_LT_ADDR, + // OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA, + // OpCodeIndex::READ_SYNCHRONIZATION_TRAIN_PARAMETERS, + // OpCodeIndex::WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS, + OpCodeIndex::READ_SECURE_CONNECTIONS_HOST_SUPPORT, + OpCodeIndex::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, + OpCodeIndex::READ_AUTHENTICATED_PAYLOAD_TIMEOUT, + OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT, + OpCodeIndex::READ_LOCAL_OOB_EXTENDED_DATA, + // OpCodeIndex::READ_EXTENDED_PAGE_TIMEOUT, + // OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT, + // OpCodeIndex::READ_EXTENDED_INQUIRY_LENGTH, + // OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH, + // OpCodeIndex::SET_ECOSYSTEM_BASE_INTERVAL, + // OpCodeIndex::CONFIGURE_DATA_PATH, + // OpCodeIndex::SET_MIN_ENCRYPTION_KEY_SIZE, - // INFORMATIONAL_PARAMETERS - OpCodeIndex::READ_LOCAL_VERSION_INFORMATION, - OpCodeIndex::READ_LOCAL_SUPPORTED_FEATURES, - OpCodeIndex::READ_LOCAL_EXTENDED_FEATURES, OpCodeIndex::READ_BUFFER_SIZE, - OpCodeIndex::READ_BD_ADDR, - // OpCodeIndex::READ_DATA_BLOCK_SIZE, - OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V1, - // OpCodeIndex::READ_LOCAL_SIMPLE_PAIRING_OPTIONS, - // OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2, - // OpCodeIndex::READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES, - // OpCodeIndex::READ_LOCAL_SUPPORTED_CONTROLLER_DELAY, + // INFORMATIONAL_PARAMETERS + OpCodeIndex::READ_LOCAL_VERSION_INFORMATION, OpCodeIndex::READ_LOCAL_SUPPORTED_FEATURES, + OpCodeIndex::READ_LOCAL_EXTENDED_FEATURES, OpCodeIndex::READ_BUFFER_SIZE, + OpCodeIndex::READ_BD_ADDR, + // OpCodeIndex::READ_DATA_BLOCK_SIZE, + OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V1, + // OpCodeIndex::READ_LOCAL_SIMPLE_PAIRING_OPTIONS, + // OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2, + // OpCodeIndex::READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES, + // OpCodeIndex::READ_LOCAL_SUPPORTED_CONTROLLER_DELAY, - // STATUS_PARAMETERS - OpCodeIndex::READ_FAILED_CONTACT_COUNTER, - OpCodeIndex::RESET_FAILED_CONTACT_COUNTER, - // OpCodeIndex::READ_LINK_QUALITY, - OpCodeIndex::READ_RSSI, OpCodeIndex::READ_AFH_CHANNEL_MAP, - // OpCodeIndex::READ_CLOCK, - OpCodeIndex::READ_ENCRYPTION_KEY_SIZE, - // OpCodeIndex::GET_MWS_TRANSPORT_LAYER_CONFIGURATION, - // OpCodeIndex::SET_TRIGGERED_CLOCK_CAPTURE, + // STATUS_PARAMETERS + OpCodeIndex::READ_FAILED_CONTACT_COUNTER, OpCodeIndex::RESET_FAILED_CONTACT_COUNTER, + // OpCodeIndex::READ_LINK_QUALITY, + OpCodeIndex::READ_RSSI, OpCodeIndex::READ_AFH_CHANNEL_MAP, + // OpCodeIndex::READ_CLOCK, + OpCodeIndex::READ_ENCRYPTION_KEY_SIZE, + // OpCodeIndex::GET_MWS_TRANSPORT_LAYER_CONFIGURATION, + // OpCodeIndex::SET_TRIGGERED_CLOCK_CAPTURE, - // TESTING - OpCodeIndex::READ_LOOPBACK_MODE, OpCodeIndex::WRITE_LOOPBACK_MODE, - OpCodeIndex::ENABLE_DEVICE_UNDER_TEST_MODE, - OpCodeIndex::WRITE_SIMPLE_PAIRING_DEBUG_MODE, - OpCodeIndex::WRITE_SECURE_CONNECTIONS_TEST_MODE, + // TESTING + OpCodeIndex::READ_LOOPBACK_MODE, OpCodeIndex::WRITE_LOOPBACK_MODE, + OpCodeIndex::ENABLE_IMPLEMENTATION_UNDER_TEST_MODE, + OpCodeIndex::WRITE_SIMPLE_PAIRING_DEBUG_MODE, + OpCodeIndex::WRITE_SECURE_CONNECTIONS_TEST_MODE, - // LE_CONTROLLER - OpCodeIndex::LE_SET_EVENT_MASK, OpCodeIndex::LE_READ_BUFFER_SIZE_V1, - OpCodeIndex::LE_READ_LOCAL_SUPPORTED_FEATURES, - OpCodeIndex::LE_SET_RANDOM_ADDRESS, - OpCodeIndex::LE_SET_ADVERTISING_PARAMETERS, - OpCodeIndex::LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER, - OpCodeIndex::LE_SET_ADVERTISING_DATA, - OpCodeIndex::LE_SET_SCAN_RESPONSE_DATA, - OpCodeIndex::LE_SET_ADVERTISING_ENABLE, - OpCodeIndex::LE_SET_SCAN_PARAMETERS, OpCodeIndex::LE_SET_SCAN_ENABLE, - OpCodeIndex::LE_CREATE_CONNECTION, - OpCodeIndex::LE_CREATE_CONNECTION_CANCEL, - OpCodeIndex::LE_READ_FILTER_ACCEPT_LIST_SIZE, - OpCodeIndex::LE_CLEAR_FILTER_ACCEPT_LIST, - OpCodeIndex::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST, - OpCodeIndex::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, - OpCodeIndex::LE_CONNECTION_UPDATE, - OpCodeIndex::LE_SET_HOST_CHANNEL_CLASSIFICATION, - OpCodeIndex::LE_READ_CHANNEL_MAP, OpCodeIndex::LE_READ_REMOTE_FEATURES, - OpCodeIndex::LE_ENCRYPT, OpCodeIndex::LE_RAND, - OpCodeIndex::LE_START_ENCRYPTION, - OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_REPLY, - OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::LE_READ_SUPPORTED_STATES, OpCodeIndex::LE_RECEIVER_TEST_V1, - OpCodeIndex::LE_TRANSMITTER_TEST_V1, OpCodeIndex::LE_TEST_END, - OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, - OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, - // OpCodeIndex::LE_SET_DATA_LENGTH, - OpCodeIndex::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, - OpCodeIndex::LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, - // OpCodeIndex::LE_READ_LOCAL_P_256_PUBLIC_KEY, - // OpCodeIndex::LE_GENERATE_DHKEY_V1, - OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST, - OpCodeIndex::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, - OpCodeIndex::LE_CLEAR_RESOLVING_LIST, - OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE, - OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS, - OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS, - OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE, - OpCodeIndex::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, - OpCodeIndex::LE_READ_MAXIMUM_DATA_LENGTH, OpCodeIndex::LE_READ_PHY, - OpCodeIndex::LE_SET_DEFAULT_PHY, OpCodeIndex::LE_SET_PHY, - // OpCodeIndex::LE_RECEIVER_TEST_V2, - // OpCodeIndex::LE_TRANSMITTER_TEST_V2, - OpCodeIndex::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA, - OpCodeIndex::LE_SET_EXTENDED_SCAN_RESPONSE_DATA, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_ENABLE, - OpCodeIndex::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, - OpCodeIndex::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, - OpCodeIndex::LE_REMOVE_ADVERTISING_SET, - OpCodeIndex::LE_CLEAR_ADVERTISING_SETS, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_ENABLE, - OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS, - OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE, - OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION, - OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC, - OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, - OpCodeIndex::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC, - OpCodeIndex::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, - OpCodeIndex::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, - OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST, - OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, - // OpCodeIndex::LE_READ_TRANSMIT_POWER, - OpCodeIndex::LE_READ_RF_PATH_COMPENSATION_POWER, - OpCodeIndex::LE_WRITE_RF_PATH_COMPENSATION_POWER, - OpCodeIndex::LE_SET_PRIVACY_MODE, - // OpCodeIndex::LE_RECEIVER_TEST_V3, - // OpCodeIndex::LE_TRANSMITTER_TEST_V3, - // OpCodeIndex::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS, - // OpCodeIndex::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_ENABLE, - // OpCodeIndex::LE_SET_CONNECTIONLESS_IQ_SAMPLING_ENABLE, - // OpCodeIndex::LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS, - // OpCodeIndex::LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS, - // OpCodeIndex::LE_CONNECTION_CTE_REQUEST_ENABLE, - // OpCodeIndex::LE_CONNECTION_CTE_RESPONSE_ENABLE, - // OpCodeIndex::LE_READ_ANTENNA_INFORMATION, - // OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, - // OpCodeIndex::LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, - // OpCodeIndex::LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, - // OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, - // OpCodeIndex::LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, - // OpCodeIndex::LE_GENERATE_DHKEY_V2, - // OpCodeIndex::LE_MODIFY_SLEEP_CLOCK_ACCURACY, - OpCodeIndex::LE_READ_BUFFER_SIZE_V2, - // OpCodeIndex::LE_READ_ISO_TX_SYNC, - OpCodeIndex::LE_SET_CIG_PARAMETERS, - OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST, OpCodeIndex::LE_CREATE_CIS, - OpCodeIndex::LE_REMOVE_CIG, OpCodeIndex::LE_ACCEPT_CIS_REQUEST, - OpCodeIndex::LE_REJECT_CIS_REQUEST, - // OpCodeIndex::LE_CREATE_BIG, - // OpCodeIndex::LE_CREATE_BIG_TEST, - // OpCodeIndex::LE_TERMINATE_BIG, - // OpCodeIndex::LE_BIG_CREATE_SYNC, - // OpCodeIndex::LE_BIG_TERMINATE_SYNC, - OpCodeIndex::LE_REQUEST_PEER_SCA, OpCodeIndex::LE_SETUP_ISO_DATA_PATH, - OpCodeIndex::LE_REMOVE_ISO_DATA_PATH, - // OpCodeIndex::LE_ISO_TRANSMIT_TEST, - // OpCodeIndex::LE_ISO_RECEIVE_TEST, - // OpCodeIndex::LE_ISO_READ_TEST_COUNTERS, - // OpCodeIndex::LE_ISO_TEST_END, - OpCodeIndex::LE_SET_HOST_FEATURE, - // OpCodeIndex::LE_READ_ISO_LINK_QUALITY, - // OpCodeIndex::LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL, - // OpCodeIndex::LE_READ_REMOTE_TRANSMIT_POWER_LEVEL, - // OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_PARAMETERS, - // OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_ENABLE, - // OpCodeIndex::LE_SET_TRANSMIT_POWER_REPORTING_ENABLE, - // OpCodeIndex::LE_TRANSMITTER_TEST_V4, - // OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES, - // OpCodeIndex::LE_SET_DEFAULT_SUBRATE, - // OpCodeIndex::LE_SUBRATE_REQUEST, + // LE_CONTROLLER + OpCodeIndex::LE_SET_EVENT_MASK, OpCodeIndex::LE_READ_BUFFER_SIZE_V1, + OpCodeIndex::LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0, OpCodeIndex::LE_SET_RANDOM_ADDRESS, + OpCodeIndex::LE_SET_ADVERTISING_PARAMETERS, + OpCodeIndex::LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER, + OpCodeIndex::LE_SET_ADVERTISING_DATA, OpCodeIndex::LE_SET_SCAN_RESPONSE_DATA, + OpCodeIndex::LE_SET_ADVERTISING_ENABLE, OpCodeIndex::LE_SET_SCAN_PARAMETERS, + OpCodeIndex::LE_SET_SCAN_ENABLE, OpCodeIndex::LE_CREATE_CONNECTION, + OpCodeIndex::LE_CREATE_CONNECTION_CANCEL, OpCodeIndex::LE_READ_FILTER_ACCEPT_LIST_SIZE, + OpCodeIndex::LE_CLEAR_FILTER_ACCEPT_LIST, + OpCodeIndex::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST, + OpCodeIndex::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, OpCodeIndex::LE_CONNECTION_UPDATE, + OpCodeIndex::LE_SET_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::LE_READ_CHANNEL_MAP, + OpCodeIndex::LE_READ_REMOTE_FEATURES_PAGE_0, OpCodeIndex::LE_ENCRYPT, + OpCodeIndex::LE_RAND, OpCodeIndex::LE_START_ENCRYPTION, + OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_REPLY, + OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY, + OpCodeIndex::LE_READ_SUPPORTED_STATES, OpCodeIndex::LE_RECEIVER_TEST_V1, + OpCodeIndex::LE_TRANSMITTER_TEST_V1, OpCodeIndex::LE_TEST_END, + OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, + OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, + // OpCodeIndex::LE_SET_DATA_LENGTH, + OpCodeIndex::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, + OpCodeIndex::LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, + OpCodeIndex::LE_READ_LOCAL_P_256_PUBLIC_KEY, + // OpCodeIndex::LE_GENERATE_DHKEY_V1, + OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST, + OpCodeIndex::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, OpCodeIndex::LE_CLEAR_RESOLVING_LIST, + OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE, OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS, + OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS, + OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE, + OpCodeIndex::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, + OpCodeIndex::LE_READ_MAXIMUM_DATA_LENGTH, OpCodeIndex::LE_READ_PHY, + OpCodeIndex::LE_SET_DEFAULT_PHY, OpCodeIndex::LE_SET_PHY, + // OpCodeIndex::LE_RECEIVER_TEST_V2, + // OpCodeIndex::LE_TRANSMITTER_TEST_V2, + OpCodeIndex::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA, + OpCodeIndex::LE_SET_EXTENDED_SCAN_RESPONSE_DATA, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_ENABLE, + OpCodeIndex::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, + OpCodeIndex::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, + OpCodeIndex::LE_REMOVE_ADVERTISING_SET, OpCodeIndex::LE_CLEAR_ADVERTISING_SETS, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_ENABLE, + OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS, OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE, + OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V1, + OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC, + OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, + OpCodeIndex::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC, + OpCodeIndex::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, + OpCodeIndex::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, + OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST, + OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, + // OpCodeIndex::LE_READ_TRANSMIT_POWER, + OpCodeIndex::LE_READ_RF_PATH_COMPENSATION_POWER, + OpCodeIndex::LE_WRITE_RF_PATH_COMPENSATION_POWER, OpCodeIndex::LE_SET_PRIVACY_MODE, + // OpCodeIndex::LE_RECEIVER_TEST_V3, + // OpCodeIndex::LE_TRANSMITTER_TEST_V3, + // OpCodeIndex::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS, + // OpCodeIndex::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_ENABLE, + // OpCodeIndex::LE_SET_CONNECTIONLESS_IQ_SAMPLING_ENABLE, + // OpCodeIndex::LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS, + // OpCodeIndex::LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS, + // OpCodeIndex::LE_CONNECTION_CTE_REQUEST_ENABLE, + // OpCodeIndex::LE_CONNECTION_CTE_RESPONSE_ENABLE, + // OpCodeIndex::LE_READ_ANTENNA_INFORMATION, + // OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, + // OpCodeIndex::LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, + // OpCodeIndex::LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, + // OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, + // OpCodeIndex::LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, + // OpCodeIndex::LE_GENERATE_DHKEY_V2, + // OpCodeIndex::LE_MODIFY_SLEEP_CLOCK_ACCURACY, + OpCodeIndex::LE_READ_BUFFER_SIZE_V2, + // OpCodeIndex::LE_READ_ISO_TX_SYNC, + OpCodeIndex::LE_SET_CIG_PARAMETERS, OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST, + OpCodeIndex::LE_CREATE_CIS, OpCodeIndex::LE_REMOVE_CIG, + OpCodeIndex::LE_ACCEPT_CIS_REQUEST, OpCodeIndex::LE_REJECT_CIS_REQUEST, + // OpCodeIndex::LE_CREATE_BIG, + // OpCodeIndex::LE_CREATE_BIG_TEST, + // OpCodeIndex::LE_TERMINATE_BIG, + // OpCodeIndex::LE_BIG_CREATE_SYNC, + // OpCodeIndex::LE_BIG_TERMINATE_SYNC, + OpCodeIndex::LE_REQUEST_PEER_SCA, OpCodeIndex::LE_SETUP_ISO_DATA_PATH, + OpCodeIndex::LE_REMOVE_ISO_DATA_PATH, + // OpCodeIndex::LE_ISO_TRANSMIT_TEST, + // OpCodeIndex::LE_ISO_RECEIVE_TEST, + // OpCodeIndex::LE_ISO_READ_TEST_COUNTERS, + // OpCodeIndex::LE_ISO_TEST_END, + OpCodeIndex::LE_SET_HOST_FEATURE_V1, + // OpCodeIndex::LE_READ_ISO_LINK_QUALITY, + // OpCodeIndex::LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL, + // OpCodeIndex::LE_READ_REMOTE_TRANSMIT_POWER_LEVEL, + // OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_PARAMETERS, + // OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_ENABLE, + // OpCodeIndex::LE_SET_TRANSMIT_POWER_REPORTING_ENABLE, + // OpCodeIndex::LE_TRANSMITTER_TEST_V4, + // OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES, + // OpCodeIndex::LE_SET_DEFAULT_SUBRATE, + // OpCodeIndex::LE_SUBRATE_REQUEST, }; std::array value{}; @@ -480,20 +442,16 @@ bool ControllerProperties::CheckSupportedFeatures() const { } if ((lmp_page_0_reserved_bits & lmp_features[0]) != 0) { - INFO( - "The page 0 feature bits 0x{:016x}" - " are reserved in the specification {}", - lmp_page_0_reserved_bits & lmp_features[0], - LmpVersionText(lmp_version)); + INFO("The page 0 feature bits 0x{:016x}" + " are reserved in the specification {}", + lmp_page_0_reserved_bits & lmp_features[0], LmpVersionText(lmp_version)); return false; } if ((lmp_page_2_reserved_bits & lmp_features[2]) != 0) { - INFO( - "The page 2 feature bits 0x{:016x}" - " are reserved in the specification {}", - lmp_page_2_reserved_bits & lmp_features[2], - LmpVersionText(lmp_version)); + INFO("The page 2 feature bits 0x{:016x}" + " are reserved in the specification {}", + lmp_page_2_reserved_bits & lmp_features[2], LmpVersionText(lmp_version)); return false; } @@ -508,8 +466,7 @@ bool ControllerProperties::CheckSupportedFeatures() const { // The features listed in Table 3.5 are mandatory in this version of the // specification (see Section 3.1) and these feature bits shall be set. if (!SupportsLMPFeature(LMPFeaturesPage0Bits::ENCRYPTION) || - !SupportsLMPFeature( - LMPFeaturesPage0Bits::SECURE_SIMPLE_PAIRING_CONTROLLER) || + !SupportsLMPFeature(LMPFeaturesPage0Bits::SECURE_SIMPLE_PAIRING_CONTROLLER) || !SupportsLMPFeature(LMPFeaturesPage0Bits::ENCAPSULATED_PDU)) { INFO("Table 3.5 validation failed"); return false; @@ -579,13 +536,10 @@ bool ControllerProperties::CheckSupportedFeatures() const { INFO("Table 3.9 validation failed; expected Sco Link or Extended Sco Link"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE) && - !SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) { - INFO( - "Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s " - "mode"); + if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE) && + !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) { + INFO("Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s " + "mode"); return false; } if (SupportsLMPFeature(LMPFeaturesPage0Bits::EV4_PACKETS) && @@ -603,22 +557,16 @@ bool ControllerProperties::CheckSupportedFeatures() const { INFO("Table 3.9 validation failed; expected AFH Capable Peripheral"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS) && - !SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) { - INFO( - "Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s " - "mode"); + if (SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS) && + !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) { + INFO("Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s " + "mode"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage0Bits::LMP_5_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS) && - !SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) { - INFO( - "Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s " - "mode"); + if (SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_5_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS) && + !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE)) { + INFO("Table 3.9 validation failed; expected Enhanced Data Rate ACL 2Mb/s " + "mode"); return false; } if (SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL) && @@ -626,28 +574,21 @@ bool ControllerProperties::CheckSupportedFeatures() const { INFO("Table 3.9 validation failed; expected AFH Capable Central"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE) && + if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE) && !SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)) { INFO("Table 3.9 validation failed; expected Extended Sco Link"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_3_MB_S_MODE) && - !SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE)) { - INFO( - "Table 3.9 validation failed; expected Enhanced Data Rate eSCO 2Mb/s " - "mode"); + if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_3_MB_S_MODE) && + !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE)) { + INFO("Table 3.9 validation failed; expected Enhanced Data Rate eSCO 2Mb/s " + "mode"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS) && - !SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE)) { - INFO( - "Table 3.9 validation failed; expected Enhanced Data Rate eSCO 2Mb/s " - "mode"); + if (SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ESCO_PACKETS) && + !SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ESCO_2_MB_S_MODE)) { + INFO("Table 3.9 validation failed; expected Enhanced Data Rate eSCO 2Mb/s " + "mode"); return false; } if (SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE) && @@ -655,8 +596,7 @@ bool ControllerProperties::CheckSupportedFeatures() const { INFO("Table 3.9 validation failed; expected RSSI with Inquiry Results"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage0Bits::SIMULTANEOUS_LE_AND_BR_CONTROLLER) && + if (SupportsLMPFeature(LMPFeaturesPage0Bits::SIMULTANEOUS_LE_AND_BR_CONTROLLER) && !SupportsLMPFeature(LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER)) { INFO("Table 3.9 validation failed; expected LE Supported (Controller)"); return false; @@ -670,21 +610,18 @@ bool ControllerProperties::CheckSupportedFeatures() const { if (SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL) && (!SupportsLMPFeature(LMPFeaturesPage0Bits::POWER_CONTROL_REQUESTS) || !SupportsLMPFeature(LMPFeaturesPage0Bits::POWER_CONTROL))) { - INFO( - "Table 3.9 validation failed; expected Power Control Request and Power " - "Control"); + INFO("Table 3.9 validation failed; expected Power Control Request and Power " + "Control"); return false; } if (SupportsLMPFeature( - LMPFeaturesPage2Bits:: - CONNECTIONLESS_PERIPHERAL_BROADCAST_TRANSMITTER_OPERATION) && + LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_TRANSMITTER_OPERATION) && !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_TRAIN)) { INFO("Table 3.9 validation failed; expected Synchronization Train"); return false; } if (SupportsLMPFeature( - LMPFeaturesPage2Bits:: - CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVER_OPERATION) && + LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVER_OPERATION) && !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_SCAN)) { INFO("Table 3.9 validation failed; expected Synchronization Scan"); return false; @@ -692,9 +629,8 @@ bool ControllerProperties::CheckSupportedFeatures() const { if (SupportsLMPFeature(LMPFeaturesPage2Bits::GENERALIZED_INTERLACED_SCAN) && !SupportsLMPFeature(LMPFeaturesPage0Bits::INTERLACED_INQUIRY_SCAN) && !SupportsLMPFeature(LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN)) { - INFO( - "Table 3.9 validation failed; expected Interlaced Inquiry Scan or " - "Interlaced Page Scan"); + INFO("Table 3.9 validation failed; expected Interlaced Inquiry Scan or " + "Interlaced Page Scan"); return false; } if (SupportsLMPFeature(LMPFeaturesPage2Bits::COARSE_CLOCK_ADJUSTMENT) && @@ -702,13 +638,11 @@ bool ControllerProperties::CheckSupportedFeatures() const { !SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL) || !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_TRAIN) || !SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_SCAN))) { - INFO( - "Table 3.9 validation failed; expected AFH Capable Central/Peripheral " - "and Synchronization Train/Scan"); + INFO("Table 3.9 validation failed; expected AFH Capable Central/Peripheral " + "and Synchronization Train/Scan"); return false; } - if (SupportsLMPFeature( - LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT) && + if (SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT) && (!SupportsLMPFeature(LMPFeaturesPage0Bits::PAUSE_ENCRYPTION) || !SupportsLMPFeature(LMPFeaturesPage2Bits::PING))) { INFO("Table 3.9 validation failed; expected Pause Encryption and Ping"); @@ -759,15 +693,9 @@ bool ControllerProperties::CheckSupportedCommands() const { constexpr auto mandatory = kMandatory; constexpr auto optional = kOptional; constexpr auto excluded = kExcluded; - auto mandatory_or_excluded = [](bool cond) { - return cond ? kMandatory : kExcluded; - }; - auto mandatory_or_optional = [](bool cond) { - return cond ? kMandatory : kOptional; - }; - auto optional_or_excluded = [](bool cond) { - return cond ? kMandatory : kExcluded; - }; + auto mandatory_or_excluded = [](bool cond) { return cond ? kMandatory : kExcluded; }; + auto mandatory_or_optional = [](bool cond) { return cond ? kMandatory : kOptional; }; + auto optional_or_excluded = [](bool cond) { return cond ? kMandatory : kExcluded; }; auto mandatory_or_optional_or_excluded = [](bool cond1, bool cond2) { return cond1 ? kMandatory : cond2 ? kOptional : kExcluded; }; @@ -778,26 +706,24 @@ bool ControllerProperties::CheckSupportedCommands() const { // or event if it is shown as optional for at least one of the transports // that the Controller supports, otherwise it shall not support the // command or event. - auto check_command_requirement = - [](bool br_supported, Requirement br_requirement, bool le_supported, - Requirement le_requirement, bool command_supported) { - Requirement command_requirement = - !br_supported ? le_requirement - : !le_supported ? br_requirement - : le_requirement == kMandatory || br_requirement == kMandatory - ? kMandatory - : le_requirement == kOptional || br_requirement == kOptional - ? kOptional - : kExcluded; + auto check_command_requirement = [](bool br_supported, Requirement br_requirement, + bool le_supported, Requirement le_requirement, + bool command_supported) { + Requirement command_requirement = + !br_supported ? le_requirement + : !le_supported ? br_requirement + : le_requirement == kMandatory || br_requirement == kMandatory ? kMandatory + : le_requirement == kOptional || br_requirement == kOptional ? kOptional + : kExcluded; - if (command_requirement == kMandatory && !command_supported) { - return false; - } - if (command_requirement == kExcluded && command_supported) { - return false; - } - return true; - }; + if (command_requirement == kMandatory && !command_supported) { + return false; + } + if (command_requirement == kExcluded && command_supported) { + return false; + } + return true; + }; // C1: Mandatory if the LE Controller supports transmitting packets, otherwise // excluded. @@ -810,76 +736,65 @@ bool ControllerProperties::CheckSupportedCommands() const { auto c3 = mandatory; // C4: Mandatory if LE Feature (LE Encryption) is supported, otherwise // excluded. - auto c4 = - mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION)); + auto c4 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION)); // C6: Mandatory if LE Feature (Connection Parameters Request procedure) is // supported, otherwise excluded. - auto c6 = mandatory_or_excluded(SupportsLLFeature( - LLFeaturesBits::CONNECTION_PARAMETERS_REQUEST_PROCEDURE)); + auto c6 = mandatory_or_excluded( + SupportsLLFeature(LLFeaturesBits::CONNECTION_PARAMETERS_REQUEST_PROCEDURE)); // C7: Mandatory if LE Feature (LE Encryption) and LE Feature (LE Ping) are // supported, otherwise excluded. - auto c7 = - mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION) && - SupportsLLFeature(LLFeaturesBits::LE_PING)); + auto c7 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION) && + SupportsLLFeature(LLFeaturesBits::LE_PING)); // C8: Mandatory if LE Feature (LE Data Packet Length Extension) is supported, // otherwise optional. - auto c8 = mandatory_or_optional( - SupportsLLFeature(LLFeaturesBits::LE_DATA_PACKET_LENGTH_EXTENSION)); + auto c8 = + mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::LE_DATA_PACKET_LENGTH_EXTENSION)); // C9: Mandatory if LE Feature (LL Privacy) is supported, otherwise excluded. - auto c9 = - mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LL_PRIVACY)); + auto c9 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LL_PRIVACY)); // C10: Optional if LE Feature (LL Privacy) is supported, otherwise excluded. - auto c10 = - optional_or_excluded(SupportsLLFeature(LLFeaturesBits::LL_PRIVACY)); + auto c10 = optional_or_excluded(SupportsLLFeature(LLFeaturesBits::LL_PRIVACY)); // C11: Mandatory if LE Feature (LE 2M PHY) or LE Feature (LE Coded PHY) is // supported, otherwise optional. - auto c11 = - mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) || - SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY)); + auto c11 = mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) || + SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY)); // C12: Mandatory if LE Feature (LE 2M PHY) or LE Feature (LE Coded PHY) or // LE Feature (Stable Modulation Index - Transmitter) is supported, otherwise // optional if the LE Controller supports transmitting packets, otherwise // excluded. auto c12 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) || - SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY) || - SupportsLLFeature(LLFeaturesBits::STABLE_MODULATION_INDEX_TRANSMITTER)); + SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) || + SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY) || + SupportsLLFeature(LLFeaturesBits::STABLE_MODULATION_INDEX_TRANSMITTER)); // C13: Mandatory if LE Feature (LE 2M PHY) or LE Feature (LE Coded PHY) or LE // Feature (Stable Modulation Index - Receiver) is supported, otherwise // optional if the LE Controller supports receiving packets, otherwise // excluded. auto c13 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) || - SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY) || - SupportsLLFeature(LLFeaturesBits::STABLE_MODULATION_INDEX_RECEIVER)); + SupportsLLFeature(LLFeaturesBits::LE_2M_PHY) || + SupportsLLFeature(LLFeaturesBits::LE_CODED_PHY) || + SupportsLLFeature(LLFeaturesBits::STABLE_MODULATION_INDEX_RECEIVER)); // C15: Mandatory if LE Controller supports transmitting scannable // advertisements, otherwise excluded. auto c15 = mandatory; // C16: Mandatory if LE Feature (Periodic Advertising) is supported and the LE // Controller supports both Scanning State and Synchronization State, // otherwise excluded. - auto c16 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); + auto c16 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); // C17: Mandatory if LE Feature (Extended Advertising) is supported and the LE // Controller supports Advertising State, otherwise excluded. - auto c17 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); + auto c17 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); // C18: Mandatory if LE Feature (Periodic Advertising) is supported and the LE // Controller supports Advertising State, otherwise excluded. - auto c18 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); + auto c18 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); // C19: Mandatory if LE Feature (Extended Advertising) is supported and the LE // Controller supports Scanning State, otherwise excluded. - auto c19 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); + auto c19 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); // C20: Mandatory if LE Feature (Extended Advertising) is supported and the LE // Controller supports Initiating State, otherwise excluded. - auto c20 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); + auto c20 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_EXTENDED_ADVERTISING)); // C21: Mandatory if LE Feature (Periodic Advertising) is supported and the LE // Controller supports Synchronization State, otherwise excluded. - auto c21 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); + auto c21 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); // C22: Mandatory if the LE Controller supports sending Transmit Power in // advertisements or if LE Feature (LE Power Control Request) is supported, // otherwise optional. @@ -894,62 +809,57 @@ bool ControllerProperties::CheckSupportedCommands() const { // // C25: Mandatory if LE Feature // (Connection CTE Request) is supported, otherwise excluded. - auto c25 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST)); + auto c25 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST)); // C26: Mandatory if LE Feature (Connection CTE Response) is supported, // otherwise excluded. - auto c26 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE)); + auto c26 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE)); // C27: Mandatory if LE Feature (Connectionless CTE Transmitter) is supported, // otherwise excluded. - auto c27 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER)); + auto c27 = + mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER)); // C28: Mandatory if LE Feature (Connectionless CTE Receiver) is supported, // otherwise excluded. - auto c28 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER)); + auto c28 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER)); // C29: Mandatory if LE Feature (Connection CTE Response) or LE Feature // (Connectionless CTE Transmitter) is supported, otherwise optional if the LE // Controller supports transmitting packets, otherwise excluded. - auto c29 = mandatory_or_optional( - SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE) || - SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER)); + auto c29 = + mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE) || + SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER)); // C30: Mandatory if LE Feature (Connection CTE Request) or LE Feature // (Connectionless CTE Receiver) is supported, otherwise optional if the LE // Controller supports receiving packets, otherwise excluded. - auto c30 = mandatory_or_optional( - SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST) || - SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER)); + auto c30 = mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST) || + SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER)); // C31: Mandatory if LE Feature (Connection CTE Request) or LE Feature // (Connection CTE Response) or LE Feature (Connectionless CTE Transmitter) or // LE Feature (Connectionless CTE Receiver) is supported, otherwise excluded. - auto c31 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST) || - SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE) || - SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER) || - SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER)); + auto c31 = + mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_REQUEST) || + SupportsLLFeature(LLFeaturesBits::CONNECTION_CTE_RESPONSE) || + SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_TRANSMITTER) || + SupportsLLFeature(LLFeaturesBits::CONNECTIONLESS_CTE_RECEIVER)); // C32: Mandatory if LE Feature (Periodic Advertising Sync Transfer – // Recipient) is supported, otherwise optional if LE Feature (Periodic // Advertising) is supported and the LE Controller supports Synchronization // State, otherwise excluded. auto c32 = mandatory_or_optional_or_excluded( - SupportsLLFeature( - LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT), - SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); + SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT), + SupportsLLFeature(LLFeaturesBits::LE_PERIODIC_ADVERTISING)); // C33: Mandatory if LE Feature (Periodic Advertising Sync Transfer – Sender) // is supported and the LE Controller supports Scanning State, otherwise // excluded. - auto c33 = mandatory_or_excluded(SupportsLLFeature( - LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER)); + auto c33 = mandatory_or_excluded( + SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER)); // C34: Mandatory if LE Feature (Periodic Advertising Sync Transfer – Sender) // is supported and the LE Controller supports Advertising State, otherwise // excluded. - auto c34 = mandatory_or_excluded(SupportsLLFeature( - LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER)); + auto c34 = mandatory_or_excluded( + SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER)); // C35: Mandatory if LE Feature (Periodic Advertising Sync Transfer – // Recipient) is supported, otherwise excluded. - auto c35 = mandatory_or_excluded(SupportsLLFeature( - LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT)); + auto c35 = mandatory_or_excluded( + SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT)); // C36: Mandatory if the LE Controller supports Central role or supports both // Peripheral role and LE Feature (Channel Classification), otherwise optional // if LE Feature (Extended Advertising) is supported and the LE Controller @@ -958,8 +868,7 @@ bool ControllerProperties::CheckSupportedCommands() const { auto c36 = mandatory; // C37: Mandatory if the LE Controller can change its sleep clock accuracy, // otherwise excluded. - auto c37 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES)); + auto c37 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES)); // C38: Mandatory if LE Feature (Connected Isochronous Stream - Central) or // LE Feature (Connected Isochronous Stream - Peripheral) is supported, // otherwise excluded. @@ -967,85 +876,73 @@ bool ControllerProperties::CheckSupportedCommands() const { // C39: Mandatory if LE Feature (Connected Isochronous // Stream - Central) is supported, otherwise excluded. auto c39 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL)); + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL)); // C40: Mandatory if LE Feature (Connected Isochronous Stream - Peripheral) is // supported, otherwise excluded. - auto c40 = mandatory_or_excluded(SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL)); + auto c40 = mandatory_or_excluded( + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL)); // C41: Mandatory if LE Feature (Isochronous Broadcaster) is supported, // otherwise excluded. - auto c41 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER)); + auto c41 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER)); // C42: Mandatory if LE Feature (Synchronized Receiver role) is supported, // otherwise excluded. - auto c42 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); + auto c42 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); // C44: Mandatory if LE Feature (Sleep Clock Accuracy Updates) and either LE // Feature (Connected Isochronous Stream - Central) or LE Feature (Connected // Isochronous Stream - Peripheral) are supported, otherwise optional if LE // Feature (Sleep Clock Accuracy Updates) is supported, otherwise excluded. auto c44 = mandatory_or_optional_or_excluded( - SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES) && - (SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || - SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL)), - SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES)); + SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES) && + (SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL)), + SupportsLLFeature(LLFeaturesBits::SLEEP_CLOCK_ACCURACY_UPDATES)); // C45: Mandatory if LE Feature (Connected Isochronous Stream - Central), or // LE Feature (Connected Isochronous Stream - Peripheral), or // LE Feature (Isochronous Broadcaster) is supported, otherwise excluded. auto c45 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || - SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || - SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER)); + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || + SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER)); // C46: Mandatory if LE Feature (Connected Isochronous Stream - Central), or // LE Feature (Connected Isochronous Stream - Peripheral), or // LE Feature (Synchronized Receiver role) is supported, otherwise excluded. auto c46 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || - SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || - SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || + SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); // C47: Mandatory if LE Feature (Connected Isochronous Stream - Central), or // LE Feature (Connected Isochronous Stream - Peripheral), or // LE Feature (Isochronous Broadcaster), or // LE Feature (Synchronized Receiver role) is supported, otherwise excluded. auto c47 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || - SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || - SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER) || - SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || + SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER) || + SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); // C49: Mandatory if LE Feature (Connected Isochronous Stream - Central) or // LE Feature (Connected Isochronous Stream - Peripheral) or // LE Feature (Connection Subrating) is supported, otherwise optional. auto c49 = mandatory_or_optional( - SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || - SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || - SupportsLLFeature(LLFeaturesBits::CONNECTION_SUBRATING)); + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTION_SUBRATING)); // C50: Optional if LE Feature (Connected Isochronous Stream - Central), or // LE Feature (Connected Isochronous Stream - Peripheral), or // LE Feature (Synchronized Receiver role) is supported, otherwise excluded. auto c50 = optional_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || - SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || - SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || + SupportsLLFeature(LLFeaturesBits::SYNCHRONIZED_RECEIVER)); // C51: Mandatory if LE Feature (LE Power Control Request) is supported, // otherwise excluded. - auto c51 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_POWER_CONTROL_REQUEST)); + auto c51 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_POWER_CONTROL_REQUEST)); // C52: Mandatory if LE Feature (LE Path Loss Monitoring) is supported, // otherwise excluded. - auto c52 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::LE_PATH_LOSS_MONITORING)); + auto c52 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_PATH_LOSS_MONITORING)); // C53: Mandatory if LE Feature (LE Power Control Request) is supported, // otherwise optional if the LE Controller supports transmitting packets, // otherwise excluded. - auto c53 = mandatory_or_optional( - SupportsLLFeature(LLFeaturesBits::LE_POWER_CONTROL_REQUEST)); + auto c53 = mandatory_or_optional(SupportsLLFeature(LLFeaturesBits::LE_POWER_CONTROL_REQUEST)); // C54: Mandatory if LE Feature (Synchronized Receiver) is supported, // otherwise optional. // @@ -1055,32 +952,27 @@ bool ControllerProperties::CheckSupportedCommands() const { // otherwise optional if the LE Controller supports Connection State, // otherwise excluded. auto c55 = mandatory_or_optional( - SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || - SupportsLLFeature( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || - SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER)); + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL) || + SupportsLLFeature(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL) || + SupportsLLFeature(LLFeaturesBits::ISOCHRONOUS_BROADCASTER)); // C56: Optional if LE Feature (LE Encryption) is supported, otherwise // excluded. // // C57: Mandatory if LE Feature (Connection Subrating) is supported, // otherwise excluded. - auto c57 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CONNECTION_SUBRATING)); + auto c57 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CONNECTION_SUBRATING)); // C58: Mandatory if LE Feature (Channel Classification) is supported, // otherwise excluded. - auto c58 = mandatory_or_excluded( - SupportsLLFeature(LLFeaturesBits::CHANNEL_CLASSIFICATION)); + auto c58 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::CHANNEL_CLASSIFICATION)); // C59: Mandatory if the LE Controller supports Central role, otherwise // excluded. auto c59 = mandatory; // C60: Mandatory if the LE Controller supports Central role and LE Feature // (LE Encryption), otherwise excluded. - auto c60 = - mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION)); + auto c60 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION)); // C61: Mandatory if the LE Controller supports Peripheral role and LE Feature // (LE Encryption), otherwise excluded. - auto c61 = - mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION)); + auto c61 = mandatory_or_excluded(SupportsLLFeature(LLFeaturesBits::LE_ENCRYPTION)); // C62: Mandatory if the LE Controller supports Central role or supports both // Peripheral role and LE Feature (Connection Parameters Request Procedure), // otherwise excluded. @@ -1093,9 +985,8 @@ bool ControllerProperties::CheckSupportedCommands() const { auto c64 = optional; // C94: Mandatory if the LE Create Connection or LE Extended Create Connection // command is supported, otherwise excluded. - auto c94 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::LE_CREATE_CONNECTION) || - SupportsCommand(OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION)); + auto c94 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::LE_CREATE_CONNECTION) || + SupportsCommand(OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V1)); // C95: Mandatory if the LE Request Peer SCA command is supported, otherwise // excluded. // @@ -1108,8 +999,7 @@ bool ControllerProperties::CheckSupportedCommands() const { auto c98 = mandatory; // C99: Mandatory if LE Generate DHKey command [v2] is supported, otherwise // optional. - auto c99 = - mandatory_or_optional(SupportsCommand(OpCodeIndex::LE_GENERATE_DHKEY_V2)); + auto c99 = mandatory_or_optional(SupportsCommand(OpCodeIndex::LE_GENERATE_DHKEY_V2)); // C101: Mandatory if the Authentication Requested command is supported, // otherwise excluded. // @@ -1118,8 +1008,7 @@ bool ControllerProperties::CheckSupportedCommands() const { // // C103: Mandatory if the Periodic // Inquiry Mode command is supported, otherwise excluded. - auto c103 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::PERIODIC_INQUIRY_MODE)); + auto c103 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::PERIODIC_INQUIRY_MODE)); // C104: Mandatory if the Read Clock Offset command is supported, otherwise // excluded. // @@ -1128,71 +1017,58 @@ bool ControllerProperties::CheckSupportedCommands() const { // // C106: Mandatory if the Remote Name Request // command is supported, otherwise excluded. - auto c106 = - mandatory_or_excluded(SupportsCommand(OpCodeIndex::REMOTE_NAME_REQUEST)); + auto c106 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::REMOTE_NAME_REQUEST)); // C107: Mandatory if the Set Controller To Host Flow Control command is // supported, otherwise excluded. - auto c107 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL)); + auto c107 = + mandatory_or_excluded(SupportsCommand(OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL)); // C108: Mandatory if the Set MWS_PATTERN Configuration command is supported, // otherwise optional. - auto c108 = mandatory_or_optional( - SupportsCommand(OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION)); + auto c108 = mandatory_or_optional(SupportsCommand(OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION)); // C109: Mandatory if the Set MWS Signaling command is supported, otherwise // excluded. - auto c109 = - mandatory_or_excluded(SupportsCommand(OpCodeIndex::SET_MWS_SIGNALING)); + auto c109 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::SET_MWS_SIGNALING)); // C110: Mandatory if the Set Triggered Clock Capture command is supported, // otherwise excluded. // // C111: Mandatory if the Write Authentication Enable // command is supported, otherwise excluded. - auto c111 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_AUTHENTICATION_ENABLE)); + auto c111 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_AUTHENTICATION_ENABLE)); // C112: Mandatory if the Write Default Erroneous Data Reporting command is // supported, otherwise excluded. auto c112 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING)); + SupportsCommand(OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING)); // C113: Mandatory if the Write Extended Inquiry Length command is supported, // otherwise excluded. - auto c113 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH)); + auto c113 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH)); // C114: Mandatory if the Write Extended Page Timeout command is supported, // otherwise excluded. - auto c114 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT)); + auto c114 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT)); // C115: Mandatory if the Write Inquiry Mode command is supported, otherwise // excluded. - auto c115 = - mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_INQUIRY_MODE)); + auto c115 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_INQUIRY_MODE)); // C116: Mandatory if the Write LE Host Support command is supported, // otherwise excluded. - auto c116 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_LE_HOST_SUPPORT)); + auto c116 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_LE_HOST_SUPPORT)); // C117: Mandatory if the Write Link Supervision Timeout command is supported, // otherwise excluded. - auto c117 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT)); + auto c117 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT)); // C118: Mandatory if the Write Num Broadcast Retransmissions command is // supported, otherwise excluded. - auto c118 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS)); + auto c118 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS)); // C119: Mandatory if the Write Page Scan Type command is supported, otherwise // excluded. - auto c119 = - mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_PAGE_SCAN_TYPE)); + auto c119 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_PAGE_SCAN_TYPE)); // C120: Mandatory if the Write PIN Type command is supported, otherwise // excluded. - auto c120 = - mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_PIN_TYPE)); + auto c120 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_PIN_TYPE)); // C121: Mandatory if the Write Stored Link Key command is supported, // otherwise excluded. - auto c121 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_STORED_LINK_KEY)); + auto c121 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_STORED_LINK_KEY)); // C122: Mandatory if the Write Synchronous Flow Control Enable command is // supported, otherwise excluded. auto c122 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE)); + SupportsCommand(OpCodeIndex::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE)); // C123: Mandatory if BR/EDR test mode is supported, otherwise excluded. auto c123 = mandatory; // C124: Mandatory if Data block based flow control is supported, otherwise @@ -1214,55 +1090,48 @@ bool ControllerProperties::CheckSupportedCommands() const { // C133: Mandatory if HV2, HV3, or multi-slot or EDR ACL packets are // supported, otherwise excluded. auto c133 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::HV2_PACKETS) || - SupportsLMPFeature(LMPFeaturesPage0Bits::HV3_PACKETS) || - SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE) || - SupportsLMPFeature( - LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE) || - SupportsLMPFeature( - LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS)); + SupportsLMPFeature(LMPFeaturesPage0Bits::HV2_PACKETS) || + SupportsLMPFeature(LMPFeaturesPage0Bits::HV3_PACKETS) || + SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_2_MB_S_MODE) || + SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_DATA_RATE_ACL_3_MB_S_MODE) || + SupportsLMPFeature(LMPFeaturesPage0Bits::LMP_3_SLOT_ENHANCED_DATA_RATE_ACL_PACKETS)); // C134: Mandatory if SCO or eSCO is supported, otherwise excluded. - auto c134 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) || - SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)); + auto c134 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) || + SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)); // C135: Optional if SCO or eSCO is supported, otherwise excluded. - auto c135 = optional_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) || - SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)); + auto c135 = optional_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SCO_LINK) || + SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)); // C136: Optional if Slot Availability Mask is supported, otherwise excluded. - auto c136 = optional_or_excluded( - SupportsLMPFeature(LMPFeaturesPage2Bits::SLOT_AVAILABILITY_MASK)); + auto c136 = + optional_or_excluded(SupportsLMPFeature(LMPFeaturesPage2Bits::SLOT_AVAILABILITY_MASK)); // C138: Mandatory if Secure Connections (Controller) is supported, otherwise // optional if eSCO is supported, otherwise excluded. auto c138 = mandatory_or_optional_or_excluded( - SupportsLMPFeature( - LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT), - SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)); + SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT), + SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_SCO_LINK)); // C139: Mandatory if the Controller is AFH capable in either role, otherwise // excluded. - auto c139 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL) || - SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL)); + auto c139 = + mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL) || + SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_PERIPHERAL)); // C140: Mandatory if the Controller supports AFH classification in either // role or is an AFH capable Central, otherwise excluded. auto c140 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL) || - SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_PERIPHERAL) || - SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL)); + SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_CENTRAL) || + SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CLASSIFICATION_PERIPHERAL) || + SupportsLMPFeature(LMPFeaturesPage0Bits::AFH_CAPABLE_CENTRAL)); // C141: Mandatory if Role Switch, Hold mode, or Sniff mode is supported, // otherwise excluded. - auto c141 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::ROLE_SWITCH) || - SupportsLMPFeature(LMPFeaturesPage0Bits::HOLD_MODE) || - SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_MODE)); + auto c141 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::ROLE_SWITCH) || + SupportsLMPFeature(LMPFeaturesPage0Bits::HOLD_MODE) || + SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_MODE)); // C142: Mandatory if Secure Connections (Host) is supported, otherwise // excluded. auto c142 = mandatory; // C143: Mandatory if Secure Connections (both Host and Controller) is // supported, otherwise excluded. - auto c143 = mandatory_or_excluded(SupportsLMPFeature( - LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT)); + auto c143 = mandatory_or_excluded( + SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT)); // C144: Mandatory if Hold Mode or Sniff Mode is supported, otherwise // excluded. // @@ -1284,91 +1153,75 @@ bool ControllerProperties::CheckSupportedCommands() const { // C151: Mandatory if Secure Connections (Controller) and Ping are supported, // otherwise excluded. auto c151 = mandatory_or_excluded( - SupportsLMPFeature( - LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT) && - SupportsLMPFeature(LMPFeaturesPage2Bits::PING)); + SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT) && + SupportsLMPFeature(LMPFeaturesPage2Bits::PING)); // C152: Mandatory if Power Control is supported, otherwise optional. - auto c152 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::POWER_CONTROL)); + auto c152 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::POWER_CONTROL)); // C153: Mandatory if LE supported in the Controller, otherwise optional. - auto c153 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER)); + auto c153 = + mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::LE_SUPPORTED_CONTROLLER)); // C154: Mandatory if Interlaced Page Scan is supported, otherwise optional. - auto c154 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN)); + auto c154 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::INTERLACED_PAGE_SCAN)); // C155: Mandatory if the Write Authenticated Payload Timeout command is // supported, otherwise excluded. - auto c155 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT)); + auto c155 = + mandatory_or_excluded(SupportsCommand(OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT)); // C156: Mandatory if the Read Local Supported Codecs command [v2] is // supported, otherwise excluded. - auto c156 = mandatory_or_excluded( - SupportsCommand(OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2)); + auto c156 = mandatory_or_excluded(SupportsCommand(OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2)); // C157: Mandatory if the Read Local Supported Codecs command [v2] is // supported, otherwise optional. - auto c157 = mandatory_or_optional( - SupportsCommand(OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2)); + auto c157 = mandatory_or_optional(SupportsCommand(OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2)); // C158: Mandatory if the Set Min Encryption Key Size command is supported, // otherwise optional. // // C201: Mandatory if Connectionless Peripheral Broadcast - Transmitter is // supported, otherwise excluded. auto c201 = mandatory_or_excluded(SupportsLMPFeature( - LMPFeaturesPage2Bits:: - CONNECTIONLESS_PERIPHERAL_BROADCAST_TRANSMITTER_OPERATION)); + LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_TRANSMITTER_OPERATION)); // C202: Mandatory if Connectionless Peripheral Broadcast - Receiver is // supported, otherwise excluded. auto c202 = mandatory_or_excluded(SupportsLMPFeature( - LMPFeaturesPage2Bits:: - CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVER_OPERATION)); + LMPFeaturesPage2Bits::CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVER_OPERATION)); // C203: Mandatory if Synchronization Train is supported, otherwise excluded. - auto c203 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_TRAIN)); + auto c203 = + mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_TRAIN)); // C204: Mandatory if Synchronization Scan is supported, otherwise excluded. - auto c204 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_SCAN)); + auto c204 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage2Bits::SYNCHRONIZATION_SCAN)); // C205: Mandatory if Extended Inquiry Response is supported, otherwise // excluded. auto c205 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE)); + SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_INQUIRY_RESPONSE)); // C212: Mandatory if Role Switch is supported, otherwise excluded. - auto c212 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::ROLE_SWITCH)); + auto c212 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::ROLE_SWITCH)); // C213: Mandatory if Hold mode is supported, otherwise excluded. - auto c213 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::HOLD_MODE)); + auto c213 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::HOLD_MODE)); // C214: Mandatory if Sniff mode is supported, otherwise excluded. - auto c214 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_MODE)); + auto c214 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_MODE)); // C215: Mandatory if Broadcast Encryption is supported, otherwise excluded. - auto c215 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::BROADCAST_ENCRYPTION)); + auto c215 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::BROADCAST_ENCRYPTION)); // C217: Mandatory if BR/EDR Enhanced Power Control is supported, otherwise // excluded. - auto c217 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL)); + auto c217 = + mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::ENHANCED_POWER_CONTROL)); // C218: Mandatory if Secure Connections (Controller) is supported, otherwise // excluded. - auto c218 = mandatory_or_excluded(SupportsLMPFeature( - LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT)); + auto c218 = mandatory_or_excluded( + SupportsLMPFeature(LMPFeaturesPage2Bits::SECURE_CONNECTIONS_CONTROLLER_SUPPORT)); // C219: Mandatory if Slot Availability Mask is supported, otherwise excluded. // C220: Mandatory if LMP Extended Features mask is supported, otherwise // excluded. - auto c220 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_FEATURES)); + auto c220 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::EXTENDED_FEATURES)); // C221: Mandatory if Sniff subrating is supported, otherwise excluded. - auto c221 = mandatory_or_excluded( - SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_SUBRATING)); + auto c221 = mandatory_or_excluded(SupportsLMPFeature(LMPFeaturesPage0Bits::SNIFF_SUBRATING)); -#define check_command_(op_code, br_requirement, le_requirement) \ - { \ - bool command_supported = \ - SupportsCommand(bluetooth::hci::OpCodeIndex::op_code); \ - if (!check_command_requirement(br_supported, br_requirement, le_supported, \ - le_requirement, command_supported)) { \ - INFO(#op_code " command validation failed (" #br_requirement \ - "," #le_requirement ")"); \ - } \ +#define check_command_(op_code, br_requirement, le_requirement) \ + { \ + bool command_supported = SupportsCommand(bluetooth::hci::OpCodeIndex::op_code); \ + if (!check_command_requirement(br_supported, br_requirement, le_supported, le_requirement, \ + command_supported)) { \ + INFO(#op_code " command validation failed (" #br_requirement "," #le_requirement ")"); \ + } \ } // Table 3.1: Alphabetical list of commands and events (Sheet 1 of 49) @@ -1384,7 +1237,7 @@ bool ControllerProperties::CheckSupportedCommands() const { check_command_(DELETE_RESERVED_LT_ADDR, c201, excluded); check_command_(DELETE_STORED_LINK_KEY, c121, excluded); check_command_(DISCONNECT, mandatory, c3); - check_command_(ENABLE_DEVICE_UNDER_TEST_MODE, c123, excluded); + check_command_(ENABLE_IMPLEMENTATION_UNDER_TEST_MODE, c123, excluded); // Table 3.1: Alphabetical list of commands and events (Sheet 5 of 49) check_command_(ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, c135, excluded); check_command_(ENHANCED_FLUSH, mandatory, excluded); @@ -1429,7 +1282,7 @@ bool ControllerProperties::CheckSupportedCommands() const { check_command_(LE_ENCRYPT, excluded, c4); // Table 3.1: Alphabetical list of commands and events (Sheet 12 of 49) check_command_(LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL, excluded, c51); - check_command_(LE_EXTENDED_CREATE_CONNECTION, excluded, c20); + check_command_(LE_EXTENDED_CREATE_CONNECTION_V1, excluded, c20); check_command_(LE_GENERATE_DHKEY_V1, excluded, c99); check_command_(LE_GENERATE_DHKEY_V2, excluded, optional); check_command_(LE_ISO_READ_TEST_COUNTERS, excluded, c46); @@ -1458,14 +1311,14 @@ bool ControllerProperties::CheckSupportedCommands() const { check_command_(LE_READ_ISO_TX_SYNC, excluded, c45); check_command_(LE_READ_LOCAL_RESOLVABLE_ADDRESS, excluded, c10); // Table 3.1: Alphabetical list of commands and events (Sheet 16 of 49) - check_command_(LE_READ_LOCAL_SUPPORTED_FEATURES, excluded, mandatory); + check_command_(LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0, excluded, mandatory); check_command_(LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, excluded, c17); check_command_(LE_READ_MAXIMUM_DATA_LENGTH, excluded, c8); check_command_(LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, excluded, c17); check_command_(LE_READ_PEER_RESOLVABLE_ADDRESS, excluded, c10); check_command_(LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, excluded, c21); check_command_(LE_READ_PHY, excluded, c11); - check_command_(LE_READ_REMOTE_FEATURES, excluded, c3); + check_command_(LE_READ_REMOTE_FEATURES_PAGE_0, excluded, c3); // Table 3.1: Alphabetical list of commands and events (Sheet 17 of 49) check_command_(LE_READ_REMOTE_TRANSMIT_POWER_LEVEL, excluded, c51); check_command_(LE_READ_RESOLVING_LIST_SIZE, excluded, c9); @@ -1478,8 +1331,7 @@ bool ControllerProperties::CheckSupportedCommands() const { check_command_(LE_RECEIVER_TEST_V3, excluded, c30); // Table 3.1: Alphabetical list of commands and events (Sheet 18 of 49) check_command_(LE_REJECT_CIS_REQUEST, excluded, c40); - check_command_(LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, - excluded, c6); + check_command_(LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, excluded, c6); check_command_(LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, excluded, c6); check_command_(LE_REMOVE_ADVERTISING_SET, excluded, c17); check_command_(LE_REMOVE_CIG, excluded, c39); @@ -1505,29 +1357,27 @@ bool ControllerProperties::CheckSupportedCommands() const { check_command_(LE_SET_DATA_LENGTH, excluded, c8); // Table 3.1: Alphabetical list of commands and events (Sheet 21 of 49) check_command_(LE_SET_DATA_RELATED_ADDRESS_CHANGES, excluded, c10); - check_command_(LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, - excluded, c35); + check_command_(LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, excluded, c35); check_command_(LE_SET_DEFAULT_PHY, excluded, c11); check_command_(LE_SET_DEFAULT_SUBRATE, excluded, c57); check_command_(LE_SET_EVENT_MASK, excluded, mandatory); check_command_(LE_SET_EXTENDED_ADVERTISING_DATA, excluded, c17); check_command_(LE_SET_EXTENDED_ADVERTISING_ENABLE, excluded, c17); - check_command_(LE_SET_EXTENDED_ADVERTISING_PARAMETERS, excluded, c17); + check_command_(LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1, excluded, c17); check_command_(LE_SET_EXTENDED_SCAN_ENABLE, excluded, c19); // Table 3.1: Alphabetical list of commands and events (Sheet 22 of 49) check_command_(LE_SET_EXTENDED_SCAN_PARAMETERS, excluded, c19); check_command_(LE_SET_EXTENDED_SCAN_RESPONSE_DATA, excluded, c17); check_command_(LE_SET_HOST_CHANNEL_CLASSIFICATION, excluded, c36); - check_command_(LE_SET_HOST_FEATURE, excluded, c49); + check_command_(LE_SET_HOST_FEATURE_V1, excluded, c49); check_command_(LE_SET_PATH_LOSS_REPORTING_ENABLE, excluded, c52); check_command_(LE_SET_PATH_LOSS_REPORTING_PARAMETERS, excluded, c52); check_command_(LE_SET_PERIODIC_ADVERTISING_DATA, excluded, c18); check_command_(LE_SET_PERIODIC_ADVERTISING_ENABLE, excluded, c18); - check_command_(LE_SET_PERIODIC_ADVERTISING_PARAMETERS, excluded, c18); + check_command_(LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1, excluded, c18); // Table 3.1: Alphabetical list of commands and events (Sheet 23 of 49) check_command_(LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, excluded, c32); - check_command_(LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, excluded, - c35); + check_command_(LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, excluded, c35); check_command_(LE_SET_PHY, excluded, c11); check_command_(LE_SET_PRIVACY_MODE, excluded, c9); check_command_(LE_SET_RANDOM_ADDRESS, excluded, c1); @@ -1649,8 +1499,7 @@ bool ControllerProperties::CheckSupportedCommands() const { // Table 3.1: Alphabetical list of commands and events (Sheet 39 of 49) check_command_(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST, c201, excluded); check_command_(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA, c201, excluded); - check_command_(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, c202, - excluded); + check_command_(SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, c202, excluded); check_command_(SET_CONTROLLER_TO_HOST_FLOW_CONTROL, optional, c96); check_command_(SET_ECOSYSTEM_BASE_INTERVAL, optional, optional); check_command_(SET_EVENT_FILTER, c148, excluded); @@ -1727,88 +1576,81 @@ bool ControllerProperties::CheckSupportedCommands() const { } ControllerProperties::ControllerProperties() - : supported_commands(std::move(SupportedCommands())), + : supported_commands(SupportedCommands()), lmp_features({Page0LmpFeatures(), 0, Page2LmpFeatures()}), le_features(LlFeatures()) { if (!CheckSupportedFeatures()) { - INFO( - "Warning: initial LMP and/or LE are not consistent. Please make sure" - " that the features are correct w.r.t. the rules described" - " in Vol 2, Part C 3.5 Feature requirements"); + INFO("Warning: initial LMP and/or LE are not consistent. Please make sure" + " that the features are correct w.r.t. the rules described" + " in Vol 2, Part C 3.5 Feature requirements"); } if (!CheckSupportedCommands()) { - INFO( - "Warning: initial supported commands are not consistent. Please make" - " sure that the supported commands are correct w.r.t. the rules" - " described in Vol 4, Part E § 3 Overview of commands and events"); + INFO("Warning: initial supported commands are not consistent. Please make" + " sure that the supported commands are correct w.r.t. the rules" + " described in Vol 4, Part E § 3 Overview of commands and events"); } } // Commands enabled by the LE Extended Advertising feature bit. static std::vector le_extended_advertising_commands_ = { - OpCodeIndex::LE_CLEAR_ADVERTISING_SETS, - OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION, - OpCodeIndex::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, - OpCodeIndex::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, - OpCodeIndex::LE_RECEIVER_TEST_V2, - OpCodeIndex::LE_REMOVE_ADVERTISING_SET, - OpCodeIndex::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, - OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_ENABLE, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS, - OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE, - OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS, - OpCodeIndex::LE_SET_EXTENDED_SCAN_RESPONSE_DATA, + OpCodeIndex::LE_CLEAR_ADVERTISING_SETS, + OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V1, + OpCodeIndex::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, + OpCodeIndex::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, + OpCodeIndex::LE_RECEIVER_TEST_V2, + OpCodeIndex::LE_REMOVE_ADVERTISING_SET, + OpCodeIndex::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, + OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_ENABLE, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1, + OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE, + OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS, + OpCodeIndex::LE_SET_EXTENDED_SCAN_RESPONSE_DATA, }; // Commands enabled by the LE Periodic Advertising feature bit. static std::vector le_periodic_advertising_commands_ = { - OpCodeIndex::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, - OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST, - OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, - OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC, - OpCodeIndex::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC, - OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, - OpCodeIndex::LE_RECEIVER_TEST_V2, - OpCodeIndex::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, - OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_ENABLE, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS, + OpCodeIndex::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, + OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST, + OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, + OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC, + OpCodeIndex::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC, + OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, + OpCodeIndex::LE_RECEIVER_TEST_V2, + OpCodeIndex::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, + OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_ENABLE, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1, }; // Commands enabled by the LL Privacy feature bit. static std::vector ll_privacy_commands_ = { - OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST, - OpCodeIndex::LE_CLEAR_RESOLVING_LIST, - OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS, - OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS, - OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE, - OpCodeIndex::LE_RECEIVER_TEST_V2, - OpCodeIndex::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, - OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE, - OpCodeIndex::LE_SET_PRIVACY_MODE, - OpCodeIndex::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, + OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST, + OpCodeIndex::LE_CLEAR_RESOLVING_LIST, + OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS, + OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS, + OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE, + OpCodeIndex::LE_RECEIVER_TEST_V2, + OpCodeIndex::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, + OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE, + OpCodeIndex::LE_SET_PRIVACY_MODE, + OpCodeIndex::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, }; // Commands enabled by the LL Connected Isochronous Stream feature bit. // Central and Peripheral support bits are enabled together. static std::vector ll_connected_isochronous_stream_commands_ = { - OpCodeIndex::LE_SET_CIG_PARAMETERS, - OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST, - OpCodeIndex::LE_CREATE_CIS, - OpCodeIndex::LE_REMOVE_CIG, - OpCodeIndex::LE_ACCEPT_CIS_REQUEST, - OpCodeIndex::LE_REJECT_CIS_REQUEST, - OpCodeIndex::LE_SETUP_ISO_DATA_PATH, - OpCodeIndex::LE_REMOVE_ISO_DATA_PATH, - OpCodeIndex::LE_REQUEST_PEER_SCA, + OpCodeIndex::LE_SET_CIG_PARAMETERS, OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST, + OpCodeIndex::LE_CREATE_CIS, OpCodeIndex::LE_REMOVE_CIG, + OpCodeIndex::LE_ACCEPT_CIS_REQUEST, OpCodeIndex::LE_REJECT_CIS_REQUEST, + OpCodeIndex::LE_SETUP_ISO_DATA_PATH, OpCodeIndex::LE_REMOVE_ISO_DATA_PATH, + OpCodeIndex::LE_REQUEST_PEER_SCA, }; -static void SetLLFeatureBit(uint64_t& le_features, LLFeaturesBits bit, - bool set) { +static void SetLLFeatureBit(uint64_t& le_features, LLFeaturesBits bit, bool set) { if (set) { le_features |= static_cast(bit); } else { @@ -1817,8 +1659,7 @@ static void SetLLFeatureBit(uint64_t& le_features, LLFeaturesBits bit, } static void SetSupportedCommandBits(std::array& supported_commands, - std::vector const& commands, - bool set) { + std::vector const& commands, bool set) { for (auto command : commands) { int index = static_cast(command); if (set) { @@ -1829,10 +1670,9 @@ static void SetSupportedCommandBits(std::array& supported_commands, } } -ControllerProperties::ControllerProperties( - rootcanal::configuration::Controller const& config) +ControllerProperties::ControllerProperties(rootcanal::configuration::Controller const& config) : strict(!config.has_strict() || config.strict()), - supported_commands(std::move(SupportedCommands())), + supported_commands(SupportedCommands()), lmp_features({Page0LmpFeatures(), 0, Page2LmpFeatures()}), le_features(LlFeatures()) { using namespace rootcanal::configuration; @@ -1853,14 +1693,13 @@ ControllerProperties::ControllerProperties( lmp_subversion = 0x5ad2; company_identifier = 0x7e8; supported_commands = std::array{ - 0x20, 0x00, 0x80, 0x00, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0x00, 0x04, - 0x00, 0x00, 0x00, 0x28, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x04, 0x00, 0x00, 0xf7, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x30, - 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1f, 0xe0, 0xf7, 0xff, 0xff, - 0xff, 0xc1, 0xe3, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x00, 0x80, 0x00, 0x00, 0xc0, 0x00, 0x0c, 0x00, 0x00, 0x04, 0x00, 0x00, + 0x00, 0x28, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0xf7, + 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x30, 0xf0, 0xff, 0xff, 0xff, 0xff, 0xff, + 0x1f, 0xe0, 0xf7, 0xff, 0xff, 0xff, 0xc1, 0xe3, 0x03, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - lmp_features = std::array { 0x6000000000, 0x0, 0x0 }; + lmp_features = std::array{0x6000000000, 0x0, 0x0}; le_features = 0x19beff017fff; le_acl_data_packet_length = 512; total_num_le_acl_data_packets = 4; @@ -1884,15 +1723,14 @@ ControllerProperties::ControllerProperties( lmp_version = bluetooth::hci::LmpVersion::V_4_2; lmp_subversion = 0x30e8; company_identifier = 0xa; - supported_commands = std::array { - 0xff, 0xff, 0xff, 0x03, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, - 0xff, 0xf3, 0x0f, 0xe8, 0xfe, 0x3f, 0xf7, 0x83, 0xff, 0x1c, 0x00, - 0x04, 0x00, 0x61, 0xf7, 0xff, 0xff, 0x7f, 0x00, 0xc0, 0xff, 0xff, - 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + supported_commands = std::array{ + 0xff, 0xff, 0xff, 0x03, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf3, + 0x0f, 0xe8, 0xfe, 0x3f, 0xf7, 0x83, 0xff, 0x1c, 0x00, 0x04, 0x00, 0x61, 0xf7, + 0xff, 0xff, 0x7f, 0x00, 0xc0, 0xff, 0xff, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; - lmp_features = std::array { 0x875b1fd87e8fffff, 0x0, 0x30f }; + lmp_features = std::array{0x875b1fd87e8fffff, 0x0, 0x30f}; acl_data_packet_length = 310; total_num_acl_data_packets = 10; sco_data_packet_length = 64; @@ -1905,6 +1743,40 @@ ControllerProperties::ControllerProperties( le_supported_states = 0x3ffffffffff; break; + case ControllerPreset::INTEL_BE200: + // Configuration extracted with the helper script controller_info.py + supports_csr_vendor_command = true; + br_supported = true; + le_supported = true; + hci_version = bluetooth::hci::HciVersion::V_5_4; + hci_subversion = 0x4363; + lmp_version = bluetooth::hci::LmpVersion::V_5_4; + lmp_subversion = 0x4363; + company_identifier = 0x2; + supported_commands = std::array{ + 0xbf, 0xff, 0xfb, 0x03, 0xcc, 0xff, 0x0f, 0xff, 0xbf, 0xff, 0xfc, 0x1f, 0xf2, + 0x0f, 0xe8, 0xfe, 0x3f, 0xf7, 0x8f, 0xff, 0x1c, 0x00, 0x04, 0x00, 0x61, 0xf7, + 0xff, 0xff, 0x7f, 0x38, 0x00, 0x00, 0xfe, 0xf0, 0xff, 0xff, 0xff, 0xe3, 0x80, + 0x07, 0x00, 0xe8, 0x1f, 0xfc, 0xff, 0xff, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }; + lmp_features = std::array{0x877bffdbfe0ffebf, 0x0, 0x300}; + acl_data_packet_length = 1021; + total_num_acl_data_packets = 4; + sco_data_packet_length = 96; + total_num_sco_data_packets = 6; + num_supported_iac = 2; + le_features = 0x80059ff; + le_acl_data_packet_length = 251; + total_num_le_acl_data_packets = 3; + le_filter_accept_list_size = 25; + le_resolving_list_size = 25; + le_supported_states = 0x3ffffffffff; + le_max_advertising_data_length = 160; + le_num_supported_advertising_sets = 12; + le_periodic_advertiser_list_size = 12; + break; + default: break; } @@ -1916,40 +1788,31 @@ ControllerProperties::ControllerProperties( if (features.has_le_extended_advertising()) { SetLLFeatureBit(le_features, LLFeaturesBits::LE_EXTENDED_ADVERTISING, features.le_extended_advertising()); - SetSupportedCommandBits(supported_commands, - le_extended_advertising_commands_, + SetSupportedCommandBits(supported_commands, le_extended_advertising_commands_, features.le_extended_advertising()); } if (features.has_le_periodic_advertising()) { SetLLFeatureBit(le_features, LLFeaturesBits::LE_PERIODIC_ADVERTISING, features.le_periodic_advertising()); - SetSupportedCommandBits(supported_commands, - le_periodic_advertising_commands_, + SetSupportedCommandBits(supported_commands, le_periodic_advertising_commands_, features.le_periodic_advertising()); } if (features.has_ll_privacy()) { - SetLLFeatureBit(le_features, LLFeaturesBits::LL_PRIVACY, - features.ll_privacy()); - SetSupportedCommandBits(supported_commands, ll_privacy_commands_, - features.ll_privacy()); + SetLLFeatureBit(le_features, LLFeaturesBits::LL_PRIVACY, features.ll_privacy()); + SetSupportedCommandBits(supported_commands, ll_privacy_commands_, features.ll_privacy()); } if (features.has_le_2m_phy()) { - SetLLFeatureBit(le_features, LLFeaturesBits::LE_2M_PHY, - features.le_2m_phy()); + SetLLFeatureBit(le_features, LLFeaturesBits::LE_2M_PHY, features.le_2m_phy()); } if (features.has_le_coded_phy()) { - SetLLFeatureBit(le_features, LLFeaturesBits::LE_CODED_PHY, - features.le_coded_phy()); + SetLLFeatureBit(le_features, LLFeaturesBits::LE_CODED_PHY, features.le_coded_phy()); } if (features.has_le_connected_isochronous_stream()) { - SetLLFeatureBit(le_features, - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL, + SetLLFeatureBit(le_features, LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_CENTRAL, features.le_connected_isochronous_stream()); - SetLLFeatureBit(le_features, - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL, + SetLLFeatureBit(le_features, LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL, features.le_connected_isochronous_stream()); - SetSupportedCommandBits(supported_commands, - ll_connected_isochronous_stream_commands_, + SetSupportedCommandBits(supported_commands, ll_connected_isochronous_stream_commands_, features.le_connected_isochronous_stream()); } } @@ -1957,12 +1820,10 @@ ControllerProperties::ControllerProperties( // Apply selected quirks. if (config.has_quirks()) { if (config.quirks().has_has_default_random_address()) { - quirks.has_default_random_address = - config.quirks().has_default_random_address(); + quirks.has_default_random_address = config.quirks().has_default_random_address(); } if (config.quirks().has_hardware_error_before_reset()) { - quirks.hardware_error_before_reset = - config.quirks().hardware_error_before_reset(); + quirks.hardware_error_before_reset = config.quirks().hardware_error_before_reset(); } // TODO(b/270606199): support send_acl_data_before_connection_complete } @@ -1979,17 +1840,15 @@ ControllerProperties::ControllerProperties( } if (!CheckSupportedFeatures()) { - INFO( - "Warning: LMP and/or LE features are not consistent. Please make sure" - " that the features are correct w.r.t. the rules described" - " in Vol 2, Part C 3.5 Feature requirements"); + INFO("Warning: LMP and/or LE features are not consistent. Please make sure" + " that the features are correct w.r.t. the rules described" + " in Vol 2, Part C 3.5 Feature requirements"); } if (!CheckSupportedCommands()) { - INFO( - "Warning: supported commands are not consistent. Please make" - " sure that the supported commands are correct w.r.t. the rules" - " described in Vol 4, Part E § 3 Overview of commands and events"); + INFO("Warning: supported commands are not consistent. Please make" + " sure that the supported commands are correct w.r.t. the rules" + " described in Vol 4, Part E § 3 Overview of commands and events"); } } diff --git a/model/controller/controller_properties.h b/model/controller/controller_properties.h index 0a153f1..7066441 100644 --- a/model/controller/controller_properties.h +++ b/model/controller/controller_properties.h @@ -57,7 +57,7 @@ struct ControllerQuirks { // and the capabilities of the Link Manager and Baseband in the BR/EDR // Controller. The Host device cannot modify any of these parameters. struct ControllerProperties { - public: +public: ControllerProperties(); ControllerProperties(rootcanal::configuration::Controller const&); ControllerProperties(ControllerProperties const&) = default; @@ -112,7 +112,9 @@ struct ControllerProperties { uint64_t le_features{0}; // Buffer Size (Vol 4, Part E § 7.4.5). - uint16_t acl_data_packet_length{1024}; + // Note: The blueZ HCI user socket limits the ACL Data Packet length to 1023 + // bytes (see HCI_MAX_FRAME_SIZE). + uint16_t acl_data_packet_length{1023}; uint8_t sco_data_packet_length{255}; uint16_t total_num_acl_data_packets{10}; uint16_t total_num_sco_data_packets{10}; @@ -181,8 +183,7 @@ struct ControllerProperties { bool SupportsCommand(bluetooth::hci::OpCodeIndex op_code) const { int index = static_cast(op_code); - return (supported_commands[index / 10] & (UINT64_C(1) << (index % 10))) != - 0; + return (supported_commands[index / 10] & (UINT64_C(1) << (index % 10))) != 0; } /// Return a bit mask with all supported PHYs diff --git a/model/controller/dual_mode_controller.cc b/model/controller/dual_mode_controller.cc index f0ceab7..7b953ed 100644 --- a/model/controller/dual_mode_controller.cc +++ b/model/controller/dual_mode_controller.cc @@ -16,6 +16,8 @@ #include "model/controller/dual_mode_controller.h" +#include +#include #include #include @@ -49,15 +51,15 @@ constexpr uint16_t kLeMaximumDataLength = 64; constexpr uint16_t kLeMaximumDataTime = 0x148; constexpr uint8_t kTransmitPowerLevel = -20; -constexpr bool kLeApcfTransportDiscoveryDataFilterSupported = true; +constexpr bool kLeApcfTransportDiscoveryDataFilterSupported = false; constexpr bool kLeApcfAdTypeFilterSupported = true; -#define CHECK_PACKET_VIEW(view) \ - do { \ - if (!CheckPacketView(view, fmt::format("{}:{} - {}() invalid packet", \ - __FILE__, __LINE__, __func__))) { \ - return; \ - } \ +#define CHECK_PACKET_VIEW(view) \ + do { \ + if (!CheckPacketView( \ + view, fmt::format("{}:{} - {}() invalid packet", __FILE__, __LINE__, __func__))) { \ + return; \ + } \ } while (0) void DualModeController::SetProperties(ControllerProperties properties) { @@ -66,13 +68,10 @@ void DualModeController::SetProperties(ControllerProperties properties) { } // Device methods. -std::string DualModeController::GetTypeString() const { - return "Simulated Bluetooth Controller"; -} +std::string DualModeController::GetTypeString() const { return "Simulated Bluetooth Controller"; } -void DualModeController::ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView incoming, Phy::Type /*type*/, - int8_t rssi) { +void DualModeController::ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView incoming, + Phy::Type /*type*/, int8_t rssi) { link_layer_controller_.IncomingPacket(incoming, rssi); } @@ -84,11 +83,10 @@ void DualModeController::Close() { } void DualModeController::SendCommandCompleteUnknownOpCodeEvent( - bluetooth::hci::OpCode op_code) const { + bluetooth::hci::OpCode op_code) const { send_event_(bluetooth::hci::CommandCompleteBuilder::Create( - kNumCommandPackets, op_code, - std::vector{ - static_cast(ErrorCode::UNKNOWN_HCI_COMMAND)})); + kNumCommandPackets, op_code, + std::vector{static_cast(ErrorCode::UNKNOWN_HCI_COMMAND)})); } DualModeController::DualModeController(ControllerProperties properties) @@ -99,15 +97,12 @@ DualModeController::DualModeController(ControllerProperties properties) // Default invalid packet handler will abort the controller // when receiving an invalid packet. - invalid_packet_handler_ = - [](uint32_t, InvalidPacketReason, std::string message, - std::vector const&) { FATAL("{}", message); }; + invalid_packet_handler_ = [](uint32_t, InvalidPacketReason, std::string message, + std::vector const&) { FATAL("{}", message); }; link_layer_controller_.RegisterRemoteChannel( - [this](std::shared_ptr packet, - Phy::Type phy_type, int8_t tx_power) { - this->SendLinkLayerPacket(packet, phy_type, tx_power); - }); + [this](std::shared_ptr packet, Phy::Type phy_type, + int8_t tx_power) { this->SendLinkLayerPacket(packet, phy_type, tx_power); }); } void DualModeController::ForwardToLm(CommandView command) { @@ -120,8 +115,7 @@ void DualModeController::ForwardToLl(CommandView command) { link_layer_controller_.ForwardToLl(command); } -void DualModeController::HandleAcl( - std::shared_ptr> packet) { +void DualModeController::HandleAcl(std::shared_ptr> packet) { auto acl_packet = bluetooth::hci::AclView::Create(pdl::packet::slice(packet)); CHECK_PACKET_VIEW(acl_packet); @@ -129,33 +123,31 @@ void DualModeController::HandleAcl( uint16_t handle = acl_packet.GetHandle(); std::vector payload(acl_packet.GetPayload()); - send_acl_(bluetooth::hci::AclBuilder::Create( - handle, acl_packet.GetPacketBoundaryFlag(), - acl_packet.GetBroadcastFlag(), std::move(payload))); + send_acl_(bluetooth::hci::AclBuilder::Create(handle, acl_packet.GetPacketBoundaryFlag(), + acl_packet.GetBroadcastFlag(), + std::move(payload))); std::vector completed_packets; bluetooth::hci::CompletedPackets cp; cp.connection_handle_ = handle; cp.host_num_of_completed_packets_ = 1; completed_packets.push_back(cp); - send_event_(bluetooth::hci::NumberOfCompletedPacketsBuilder::Create( - completed_packets)); + send_event_(bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(completed_packets)); return; } link_layer_controller_.SendAclToRemote(acl_packet); } -void DualModeController::HandleSco( - std::shared_ptr> packet) { +void DualModeController::HandleSco(std::shared_ptr> packet) { auto sco_packet = bluetooth::hci::ScoView::Create(pdl::packet::slice(packet)); CHECK_PACKET_VIEW(sco_packet); if (loopback_mode_ == LoopbackMode::ENABLE_LOCAL) { uint16_t handle = sco_packet.GetHandle(); - send_sco_(bluetooth::hci::ScoBuilder::Create( - handle, sco_packet.GetPacketStatusFlag(), sco_packet.GetData())); + send_sco_(bluetooth::hci::ScoBuilder::Create(handle, sco_packet.GetPacketStatusFlag(), + sco_packet.GetData())); std::vector completed_packets; bluetooth::hci::CompletedPackets cp; @@ -163,8 +155,7 @@ void DualModeController::HandleSco( cp.host_num_of_completed_packets_ = 1; completed_packets.push_back(cp); if (link_layer_controller_.GetScoFlowControlEnable()) { - send_event_(bluetooth::hci::NumberOfCompletedPacketsBuilder::Create( - completed_packets)); + send_event_(bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(completed_packets)); } return; } @@ -172,55 +163,46 @@ void DualModeController::HandleSco( link_layer_controller_.SendScoToRemote(sco_packet); } -void DualModeController::HandleIso( - std::shared_ptr> packet) { +void DualModeController::HandleIso(std::shared_ptr> packet) { auto iso = bluetooth::hci::IsoView::Create(pdl::packet::slice(packet)); CHECK_PACKET_VIEW(iso); link_layer_controller_.HandleIso(iso); } -void DualModeController::HandleCommand( - std::shared_ptr> packet) { - auto command_packet = - bluetooth::hci::CommandView::Create(pdl::packet::slice(packet)); +void DualModeController::HandleCommand(std::shared_ptr> packet) { + auto command_packet = bluetooth::hci::CommandView::Create(pdl::packet::slice(packet)); CHECK_PACKET_VIEW(command_packet); OpCode op_code = command_packet.GetOpCode(); const bool is_vendor_command = (static_cast(op_code) >> 10) == 0x3f; - const bool is_known_command = - hci_command_op_code_to_index_.count(op_code) > 0; + const bool is_known_command = hci_command_op_code_to_index_.count(op_code) > 0; const bool is_implemented_command = hci_command_handlers_.count(op_code) > 0; // HCI Read Local Supported Commands is supported by default. // Vendor commands are supported when implemented. - bool is_supported_command = - (op_code == OpCode::READ_LOCAL_SUPPORTED_COMMANDS) || - (is_vendor_command && is_implemented_command); + bool is_supported_command = (op_code == OpCode::READ_LOCAL_SUPPORTED_COMMANDS) || + (is_vendor_command && is_implemented_command); // For other commands, query the Support Commands bit mask in // the controller properties. if (!is_supported_command && is_known_command) { int index = static_cast(hci_command_op_code_to_index_.at(op_code)); - is_supported_command = (properties_.supported_commands[index / 10] & - (1U << (index % 10))) != 0; + is_supported_command = (properties_.supported_commands[index / 10] & (1U << (index % 10))) != 0; } // Loopback mode, the commands are sent back to the host. - if (loopback_mode_ == LoopbackMode::ENABLE_LOCAL && - op_code != OpCode::RESET && + if (loopback_mode_ == LoopbackMode::ENABLE_LOCAL && op_code != OpCode::RESET && op_code != OpCode::SET_CONTROLLER_TO_HOST_FLOW_CONTROL && - op_code != OpCode::HOST_BUFFER_SIZE && - op_code != OpCode::HOST_NUMBER_OF_COMPLETED_PACKETS && - op_code != OpCode::READ_BUFFER_SIZE && - op_code != OpCode::READ_LOOPBACK_MODE && + op_code != OpCode::HOST_BUFFER_SIZE && op_code != OpCode::HOST_NUMBER_OF_COMPLETED_PACKETS && + op_code != OpCode::READ_BUFFER_SIZE && op_code != OpCode::READ_LOOPBACK_MODE && op_code != OpCode::WRITE_LOOPBACK_MODE) { send_event_(bluetooth::hci::LoopbackCommandBuilder::Create( - std::vector(packet->begin(), packet->end()))); + std::vector(packet->begin(), packet->end()))); } // Quirk to reset the host stack when a command is received before the Hci // Reset command. - else if (properties_.quirks.hardware_error_before_reset && - !controller_reset_ && op_code != OpCode::RESET) { + else if (properties_.quirks.hardware_error_before_reset && !controller_reset_ && + op_code != OpCode::RESET) { WARNING(id_, "Received command {} before HCI Reset; sending the Hardware" " Error event", @@ -248,33 +230,30 @@ void DualModeController::HandleCommand( else { SendCommandCompleteUnknownOpCodeEvent(op_code); uint16_t raw_op_code = static_cast(op_code); - INFO(id_, "Unknown command, opcode: 0x{:04x}, OGF: 0x{:02x}, OCF: 0x{:03x}", - raw_op_code, (raw_op_code & 0xFC00) >> 10, raw_op_code & 0x03FF); + INFO(id_, "Unknown command, opcode: 0x{:04x}, OGF: 0x{:02x}, OCF: 0x{:03x}", raw_op_code, + (raw_op_code & 0xFC00) >> 10, raw_op_code & 0x03FF); } } void DualModeController::RegisterInvalidPacketHandler( - const std::function const&)>& handler) { + const std::function const&)>& handler) { INFO(id_, "updating the invalid packet handler"); invalid_packet_handler_ = handler; } void DualModeController::RegisterEventChannel( - const std::function>)>& - send_event) { - send_event_ = - [send_event](std::shared_ptr event) { - auto bytes = std::make_shared>(); - event->Serialize(*bytes); - send_event(bytes); - }; + const std::function>)>& send_event) { + send_event_ = [send_event](std::shared_ptr event) { + auto bytes = std::make_shared>(); + event->Serialize(*bytes); + send_event(bytes); + }; link_layer_controller_.RegisterEventChannel(send_event_); } void DualModeController::RegisterAclChannel( - const std::function>)>& - send_acl) { + const std::function>)>& send_acl) { send_acl_ = [send_acl](std::shared_ptr acl_data) { auto bytes = std::make_shared>(); acl_data->Serialize(*bytes); @@ -284,8 +263,7 @@ void DualModeController::RegisterAclChannel( } void DualModeController::RegisterScoChannel( - const std::function>)>& - send_sco) { + const std::function>)>& send_sco) { send_sco_ = [send_sco](std::shared_ptr sco_data) { auto bytes = std::make_shared>(); sco_data->Serialize(*bytes); @@ -295,8 +273,7 @@ void DualModeController::RegisterScoChannel( } void DualModeController::RegisterIsoChannel( - const std::function>)>& - send_iso) { + const std::function>)>& send_iso) { send_iso_ = [send_iso](std::shared_ptr iso_data) { auto bytes = std::make_shared>(); iso_data->Serialize(*bytes); @@ -315,8 +292,7 @@ void DualModeController::Reset(CommandView command) { loopback_mode_ = LoopbackMode::NO_LOOPBACK; controller_reset_ = true; - send_event_(bluetooth::hci::ResetCompleteBuilder::Create(kNumCommandPackets, - ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::ResetCompleteBuilder::Create(kNumCommandPackets, ErrorCode::SUCCESS)); } void DualModeController::ReadBufferSize(CommandView command) { @@ -326,33 +302,30 @@ void DualModeController::ReadBufferSize(CommandView command) { DEBUG(id_, "<< Read Buffer Size"); send_event_(bluetooth::hci::ReadBufferSizeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - properties_.acl_data_packet_length, properties_.sco_data_packet_length, - properties_.total_num_acl_data_packets, - properties_.total_num_sco_data_packets)); + kNumCommandPackets, ErrorCode::SUCCESS, properties_.acl_data_packet_length, + properties_.sco_data_packet_length, properties_.total_num_acl_data_packets, + properties_.total_num_sco_data_packets)); } void DualModeController::ReadFailedContactCounter(CommandView command) { - auto command_view = - bluetooth::hci::ReadFailedContactCounterView::Create(command); + auto command_view = bluetooth::hci::ReadFailedContactCounterView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); uint16_t failed_contact_counter = 0; ErrorCode status = link_layer_controller_.HasAclConnection(connection_handle) - ? ErrorCode::SUCCESS - : ErrorCode::UNKNOWN_CONNECTION; + ? ErrorCode::SUCCESS + : ErrorCode::UNKNOWN_CONNECTION; DEBUG(id_, "<< Read Failed Contact Counter"); DEBUG(id_, " connection_handle=0x{:x}", connection_handle); send_event_(bluetooth::hci::ReadFailedContactCounterCompleteBuilder::Create( - kNumCommandPackets, status, connection_handle, failed_contact_counter)); + kNumCommandPackets, status, connection_handle, failed_contact_counter)); } void DualModeController::ResetFailedContactCounter(CommandView command) { - auto command_view = - bluetooth::hci::ReadFailedContactCounterView::Create(command); + auto command_view = bluetooth::hci::ReadFailedContactCounterView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t connection_handle = command_view.GetConnectionHandle(); @@ -360,11 +333,11 @@ void DualModeController::ResetFailedContactCounter(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", connection_handle); ErrorCode status = link_layer_controller_.HasAclConnection(connection_handle) - ? ErrorCode::SUCCESS - : ErrorCode::UNKNOWN_CONNECTION; + ? ErrorCode::SUCCESS + : ErrorCode::UNKNOWN_CONNECTION; send_event_(bluetooth::hci::ResetFailedContactCounterCompleteBuilder::Create( - kNumCommandPackets, status, connection_handle)); + kNumCommandPackets, status, connection_handle)); } void DualModeController::ReadRssi(CommandView command) { @@ -378,22 +351,20 @@ void DualModeController::ReadRssi(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", connection_handle); ErrorCode status = link_layer_controller_.ReadRssi(connection_handle, &rssi); - send_event_(bluetooth::hci::ReadRssiCompleteBuilder::Create( - kNumCommandPackets, status, connection_handle, rssi)); + send_event_(bluetooth::hci::ReadRssiCompleteBuilder::Create(kNumCommandPackets, status, + connection_handle, rssi)); } void DualModeController::ReadEncryptionKeySize(CommandView command) { - auto command_view = - bluetooth::hci::ReadEncryptionKeySizeView::Create(command); + auto command_view = bluetooth::hci::ReadEncryptionKeySizeView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Encryption Key Size"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); send_event_(bluetooth::hci::ReadEncryptionKeySizeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - command_view.GetConnectionHandle(), - link_layer_controller_.GetEncryptionKeySize())); + kNumCommandPackets, ErrorCode::SUCCESS, command_view.GetConnectionHandle(), + link_layer_controller_.GetEncryptionKeySize())); } void DualModeController::HostBufferSize(CommandView command) { @@ -402,13 +373,12 @@ void DualModeController::HostBufferSize(CommandView command) { DEBUG(id_, "<< Host Buffer Size"); - send_event_(bluetooth::hci::HostBufferSizeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::HostBufferSizeCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadLocalVersionInformation(CommandView command) { - auto command_view = - bluetooth::hci::ReadLocalVersionInformationView::Create(command); + auto command_view = bluetooth::hci::ReadLocalVersionInformationView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Version Information"); @@ -420,25 +390,23 @@ void DualModeController::ReadLocalVersionInformation(CommandView command) { local_version_information.lmp_subversion_ = properties_.lmp_subversion; local_version_information.manufacturer_name_ = properties_.company_identifier; - send_event_( - bluetooth::hci::ReadLocalVersionInformationCompleteBuilder::Create( + send_event_(bluetooth::hci::ReadLocalVersionInformationCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, local_version_information)); } void DualModeController::ReadRemoteVersionInformation(CommandView command) { - auto command_view = - bluetooth::hci::ReadRemoteVersionInformationView::Create(command); + auto command_view = bluetooth::hci::ReadRemoteVersionInformationView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Remote Version Information"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); auto status = link_layer_controller_.SendCommandToRemoteByHandle( - OpCode::READ_REMOTE_VERSION_INFORMATION, command.bytes(), - command_view.GetConnectionHandle()); + OpCode::READ_REMOTE_VERSION_INFORMATION, command.bytes(), + command_view.GetConnectionHandle()); send_event_(bluetooth::hci::ReadRemoteVersionInformationStatusBuilder::Create( - status, kNumCommandPackets)); + status, kNumCommandPackets)); } void DualModeController::ReadBdAddr(CommandView command) { @@ -447,49 +415,43 @@ void DualModeController::ReadBdAddr(CommandView command) { DEBUG(id_, "<< Read BD_ADDR"); - send_event_(bluetooth::hci::ReadBdAddrCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, GetAddress())); + send_event_(bluetooth::hci::ReadBdAddrCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS, GetAddress())); } void DualModeController::ReadLocalSupportedCommands(CommandView command) { - auto command_view = - bluetooth::hci::ReadLocalSupportedCommandsView::Create(command); + auto command_view = bluetooth::hci::ReadLocalSupportedCommandsView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Supported Commands"); send_event_(bluetooth::hci::ReadLocalSupportedCommandsCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, properties_.supported_commands)); + kNumCommandPackets, ErrorCode::SUCCESS, properties_.supported_commands)); } void DualModeController::ReadLocalSupportedFeatures(CommandView command) { - auto command_view = - bluetooth::hci::ReadLocalSupportedFeaturesView::Create(command); + auto command_view = bluetooth::hci::ReadLocalSupportedFeaturesView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Supported Features"); send_event_(bluetooth::hci::ReadLocalSupportedFeaturesCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - link_layer_controller_.GetLmpFeatures())); + kNumCommandPackets, ErrorCode::SUCCESS, link_layer_controller_.GetLmpFeatures())); } void DualModeController::ReadLocalSupportedCodecsV1(CommandView command) { - auto command_view = - bluetooth::hci::ReadLocalSupportedCodecsV1View::Create(command); + auto command_view = bluetooth::hci::ReadLocalSupportedCodecsV1View::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Local Supported Codecs V1"); send_event_(bluetooth::hci::ReadLocalSupportedCodecsV1CompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - properties_.supported_standard_codecs, - properties_.supported_vendor_specific_codecs)); + kNumCommandPackets, ErrorCode::SUCCESS, properties_.supported_standard_codecs, + properties_.supported_vendor_specific_codecs)); } void DualModeController::ReadLocalExtendedFeatures(CommandView command) { - auto command_view = - bluetooth::hci::ReadLocalExtendedFeaturesView::Create(command); + auto command_view = bluetooth::hci::ReadLocalExtendedFeaturesView::Create(command); CHECK_PACKET_VIEW(command_view); uint8_t page_number = command_view.GetPageNumber(); @@ -497,14 +459,13 @@ void DualModeController::ReadLocalExtendedFeatures(CommandView command) { DEBUG(id_, " page_number={}", page_number); send_event_(bluetooth::hci::ReadLocalExtendedFeaturesCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, page_number, - link_layer_controller_.GetMaxLmpFeaturesPageNumber(), - link_layer_controller_.GetLmpFeatures(page_number))); + kNumCommandPackets, ErrorCode::SUCCESS, page_number, + link_layer_controller_.GetMaxLmpFeaturesPageNumber(), + link_layer_controller_.GetLmpFeatures(page_number))); } void DualModeController::ReadRemoteExtendedFeatures(CommandView command) { - auto command_view = - bluetooth::hci::ReadRemoteExtendedFeaturesView::Create(command); + auto command_view = bluetooth::hci::ReadRemoteExtendedFeaturesView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Remote Extended Features"); @@ -512,11 +473,11 @@ void DualModeController::ReadRemoteExtendedFeatures(CommandView command) { DEBUG(id_, " page_number={}", command_view.GetPageNumber()); auto status = link_layer_controller_.SendCommandToRemoteByHandle( - OpCode::READ_REMOTE_EXTENDED_FEATURES, command_view.bytes(), - command_view.GetConnectionHandle()); + OpCode::READ_REMOTE_EXTENDED_FEATURES, command_view.bytes(), + command_view.GetConnectionHandle()); - send_event_(bluetooth::hci::ReadRemoteExtendedFeaturesStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::ReadRemoteExtendedFeaturesStatusBuilder::Create(status, + kNumCommandPackets)); } void DualModeController::SwitchRole(CommandView command) { @@ -527,27 +488,24 @@ void DualModeController::SwitchRole(CommandView command) { DEBUG(id_, " bd_addr={}", command_view.GetBdAddr()); DEBUG(id_, " role={}", bluetooth::hci::RoleText(command_view.GetRole())); - auto status = link_layer_controller_.SwitchRole(command_view.GetBdAddr(), - command_view.GetRole()); + auto status = link_layer_controller_.SwitchRole(command_view.GetBdAddr(), command_view.GetRole()); - send_event_(bluetooth::hci::SwitchRoleStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::SwitchRoleStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::ReadRemoteSupportedFeatures(CommandView command) { - auto command_view = - bluetooth::hci::ReadRemoteSupportedFeaturesView::Create(command); + auto command_view = bluetooth::hci::ReadRemoteSupportedFeaturesView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Remote Supported Features"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); auto status = link_layer_controller_.SendCommandToRemoteByHandle( - OpCode::READ_REMOTE_SUPPORTED_FEATURES, command_view.bytes(), - command_view.GetConnectionHandle()); + OpCode::READ_REMOTE_SUPPORTED_FEATURES, command_view.bytes(), + command_view.GetConnectionHandle()); - send_event_(bluetooth::hci::ReadRemoteSupportedFeaturesStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::ReadRemoteSupportedFeaturesStatusBuilder::Create(status, + kNumCommandPackets)); } void DualModeController::ReadClockOffset(CommandView command) { @@ -559,11 +517,10 @@ void DualModeController::ReadClockOffset(CommandView command) { uint16_t handle = command_view.GetConnectionHandle(); - auto status = link_layer_controller_.SendCommandToRemoteByHandle( - OpCode::READ_CLOCK_OFFSET, command_view.bytes(), handle); + auto status = link_layer_controller_.SendCommandToRemoteByHandle(OpCode::READ_CLOCK_OFFSET, + command_view.bytes(), handle); - send_event_(bluetooth::hci::ReadClockOffsetStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::ReadClockOffsetStatusBuilder::Create(status, kNumCommandPackets)); } // Deprecated command, removed in v4.2. @@ -577,16 +534,13 @@ void DualModeController::AddScoConnection(CommandView command) { DEBUG(id_, " packet_type=0x{:x}", command_view.GetPacketType()); auto status = link_layer_controller_.AddScoConnection( - command_view.GetConnectionHandle(), command_view.GetPacketType(), - ScoDatapath::NORMAL); + command_view.GetConnectionHandle(), command_view.GetPacketType(), ScoDatapath::NORMAL); - send_event_(bluetooth::hci::AddScoConnectionStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::AddScoConnectionStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::SetupSynchronousConnection(CommandView command) { - auto command_view = - bluetooth::hci::SetupSynchronousConnectionView::Create(command); + auto command_view = bluetooth::hci::SetupSynchronousConnectionView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Setup Synchronous Connection"); @@ -594,19 +548,18 @@ void DualModeController::SetupSynchronousConnection(CommandView command) { DEBUG(id_, " packet_type=0x{:x}", command_view.GetPacketType()); auto status = link_layer_controller_.SetupSynchronousConnection( - command_view.GetConnectionHandle(), command_view.GetTransmitBandwidth(), - command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), - command_view.GetVoiceSetting(), - static_cast(command_view.GetRetransmissionEffort()), - command_view.GetPacketType(), ScoDatapath::NORMAL); + command_view.GetConnectionHandle(), command_view.GetTransmitBandwidth(), + command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), + command_view.GetVoiceSetting(), + static_cast(command_view.GetRetransmissionEffort()), + command_view.GetPacketType(), ScoDatapath::NORMAL); - send_event_(bluetooth::hci::SetupSynchronousConnectionStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::SetupSynchronousConnectionStatusBuilder::Create(status, + kNumCommandPackets)); } void DualModeController::AcceptSynchronousConnection(CommandView command) { - auto command_view = - bluetooth::hci::AcceptSynchronousConnectionView::Create(command); + auto command_view = bluetooth::hci::AcceptSynchronousConnectionView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Accept Synchronous Connection"); @@ -614,20 +567,18 @@ void DualModeController::AcceptSynchronousConnection(CommandView command) { DEBUG(id_, " packet_type=0x{:x}", command_view.GetPacketType()); auto status = link_layer_controller_.AcceptSynchronousConnection( - command_view.GetBdAddr(), command_view.GetTransmitBandwidth(), - command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), - command_view.GetVoiceSetting(), - static_cast(command_view.GetRetransmissionEffort()), - command_view.GetPacketType()); + command_view.GetBdAddr(), command_view.GetTransmitBandwidth(), + command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), + command_view.GetVoiceSetting(), + static_cast(command_view.GetRetransmissionEffort()), + command_view.GetPacketType()); - send_event_(bluetooth::hci::AcceptSynchronousConnectionStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::AcceptSynchronousConnectionStatusBuilder::Create(status, + kNumCommandPackets)); } -void DualModeController::EnhancedSetupSynchronousConnection( - CommandView command) { - auto command_view = - bluetooth::hci::EnhancedSetupSynchronousConnectionView::Create(command); +void DualModeController::EnhancedSetupSynchronousConnection(CommandView command) { + auto command_view = bluetooth::hci::EnhancedSetupSynchronousConnectionView::Create(command); auto status = ErrorCode::SUCCESS; CHECK_PACKET_VIEW(command_view); @@ -639,11 +590,10 @@ void DualModeController::EnhancedSetupSynchronousConnection( // to be equal. auto transmit_coding_format = command_view.GetTransmitCodingFormat(); auto receive_coding_format = command_view.GetReceiveCodingFormat(); - if (transmit_coding_format.coding_format_ != - receive_coding_format.coding_format_ || + if (transmit_coding_format.coding_format_ != receive_coding_format.coding_format_ || transmit_coding_format.company_id_ != receive_coding_format.company_id_ || transmit_coding_format.vendor_specific_codec_id_ != - receive_coding_format.vendor_specific_codec_id_) { + receive_coding_format.vendor_specific_codec_id_) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Transmit_Coding_Format " "({}) and Receive_Coding_Format ({}) as they are not equal", @@ -655,13 +605,11 @@ void DualModeController::EnhancedSetupSynchronousConnection( // to be equal, or shall set one of them to be zero and the other non-zero. auto input_bandwidth = command_view.GetInputBandwidth(); auto output_bandwidth = command_view.GetOutputBandwidth(); - if (input_bandwidth != output_bandwidth && input_bandwidth != 0 && - output_bandwidth != 0) { - INFO( - id_, - "EnhancedSetupSynchronousConnection: rejected Input_Bandwidth ({})" - " and Output_Bandwidth ({}) as they are not equal and different from 0", - input_bandwidth, output_bandwidth); + if (input_bandwidth != output_bandwidth && input_bandwidth != 0 && output_bandwidth != 0) { + INFO(id_, + "EnhancedSetupSynchronousConnection: rejected Input_Bandwidth ({})" + " and Output_Bandwidth ({}) as they are not equal and different from 0", + input_bandwidth, output_bandwidth); status = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -669,11 +617,10 @@ void DualModeController::EnhancedSetupSynchronousConnection( // to be equal. auto input_coding_format = command_view.GetInputCodingFormat(); auto output_coding_format = command_view.GetOutputCodingFormat(); - if (input_coding_format.coding_format_ != - output_coding_format.coding_format_ || + if (input_coding_format.coding_format_ != output_coding_format.coding_format_ || input_coding_format.company_id_ != output_coding_format.company_id_ || input_coding_format.vendor_specific_codec_id_ != - output_coding_format.vendor_specific_codec_id_) { + output_coding_format.vendor_specific_codec_id_) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Input_Coding_Format ({})" " and Output_Coding_Format ({}) as they are not equal", @@ -701,10 +648,8 @@ void DualModeController::EnhancedSetupSynchronousConnection( // Controller shall not modify the data sent to the remote device. auto transmit_bandwidth = command_view.GetTransmitBandwidth(); auto receive_bandwidth = command_view.GetReceiveBandwidth(); - if (transmit_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && - input_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + if (transmit_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + input_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && transmit_bandwidth != input_bandwidth) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Transmit_Bandwidth ({})" @@ -718,8 +663,7 @@ void DualModeController::EnhancedSetupSynchronousConnection( } if ((transmit_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT) != - (input_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { + (input_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Transmit_Coding_Format " "({}) and Input_Coding_Format ({}) as they are incompatible", @@ -731,10 +675,8 @@ void DualModeController::EnhancedSetupSynchronousConnection( // be “transparent” or neither shall be. If both are “transparent”, the // Receive_Bandwidth and the Output_Bandwidth shall be the same and the // Controller shall not modify the data sent to the Host. - if (receive_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && - output_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + if (receive_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + output_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && receive_bandwidth != output_bandwidth) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Receive_Bandwidth ({})" @@ -748,8 +690,7 @@ void DualModeController::EnhancedSetupSynchronousConnection( } if ((receive_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT) != - (output_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { + (output_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Receive_Coding_Format " "({}) and Output_Coding_Format ({}) as they are incompatible", @@ -759,22 +700,18 @@ void DualModeController::EnhancedSetupSynchronousConnection( if (status == ErrorCode::SUCCESS) { status = link_layer_controller_.SetupSynchronousConnection( - command_view.GetConnectionHandle(), transmit_bandwidth, - receive_bandwidth, command_view.GetMaxLatency(), - link_layer_controller_.GetVoiceSetting(), - static_cast(command_view.GetRetransmissionEffort()), - command_view.GetPacketType(), datapath); + command_view.GetConnectionHandle(), transmit_bandwidth, receive_bandwidth, + command_view.GetMaxLatency(), link_layer_controller_.GetVoiceSetting(), + static_cast(command_view.GetRetransmissionEffort()), + command_view.GetPacketType(), datapath); } - send_event_( - bluetooth::hci::EnhancedSetupSynchronousConnectionStatusBuilder::Create( + send_event_(bluetooth::hci::EnhancedSetupSynchronousConnectionStatusBuilder::Create( status, kNumCommandPackets)); } -void DualModeController::EnhancedAcceptSynchronousConnection( - CommandView command) { - auto command_view = - bluetooth::hci::EnhancedAcceptSynchronousConnectionView::Create(command); +void DualModeController::EnhancedAcceptSynchronousConnection(CommandView command) { + auto command_view = bluetooth::hci::EnhancedAcceptSynchronousConnectionView::Create(command); auto status = ErrorCode::SUCCESS; CHECK_PACKET_VIEW(command_view); @@ -786,11 +723,10 @@ void DualModeController::EnhancedAcceptSynchronousConnection( // to be equal. auto transmit_coding_format = command_view.GetTransmitCodingFormat(); auto receive_coding_format = command_view.GetReceiveCodingFormat(); - if (transmit_coding_format.coding_format_ != - receive_coding_format.coding_format_ || + if (transmit_coding_format.coding_format_ != receive_coding_format.coding_format_ || transmit_coding_format.company_id_ != receive_coding_format.company_id_ || transmit_coding_format.vendor_specific_codec_id_ != - receive_coding_format.vendor_specific_codec_id_) { + receive_coding_format.vendor_specific_codec_id_) { INFO(id_, "EnhancedAcceptSynchronousConnection: rejected Transmit_Coding_Format " "({})" @@ -803,13 +739,11 @@ void DualModeController::EnhancedAcceptSynchronousConnection( // to be equal, or shall set one of them to be zero and the other non-zero. auto input_bandwidth = command_view.GetInputBandwidth(); auto output_bandwidth = command_view.GetOutputBandwidth(); - if (input_bandwidth != output_bandwidth && input_bandwidth != 0 && - output_bandwidth != 0) { - INFO( - id_, - "EnhancedAcceptSynchronousConnection: rejected Input_Bandwidth ({})" - " and Output_Bandwidth ({}) as they are not equal and different from 0", - input_bandwidth, output_bandwidth); + if (input_bandwidth != output_bandwidth && input_bandwidth != 0 && output_bandwidth != 0) { + INFO(id_, + "EnhancedAcceptSynchronousConnection: rejected Input_Bandwidth ({})" + " and Output_Bandwidth ({}) as they are not equal and different from 0", + input_bandwidth, output_bandwidth); status = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -817,16 +751,14 @@ void DualModeController::EnhancedAcceptSynchronousConnection( // to be equal. auto input_coding_format = command_view.GetInputCodingFormat(); auto output_coding_format = command_view.GetOutputCodingFormat(); - if (input_coding_format.coding_format_ != - output_coding_format.coding_format_ || + if (input_coding_format.coding_format_ != output_coding_format.coding_format_ || input_coding_format.company_id_ != output_coding_format.company_id_ || input_coding_format.vendor_specific_codec_id_ != - output_coding_format.vendor_specific_codec_id_) { - INFO( - id_, - "EnhancedAcceptSynchronousConnection: rejected Input_Coding_Format ({})" - " and Output_Coding_Format ({}) as they are not equal", - input_coding_format.ToString(), output_coding_format.ToString()); + output_coding_format.vendor_specific_codec_id_) { + INFO(id_, + "EnhancedAcceptSynchronousConnection: rejected Input_Coding_Format ({})" + " and Output_Coding_Format ({}) as they are not equal", + input_coding_format.ToString(), output_coding_format.ToString()); status = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -848,10 +780,8 @@ void DualModeController::EnhancedAcceptSynchronousConnection( // Controller shall not modify the data sent to the remote device. auto transmit_bandwidth = command_view.GetTransmitBandwidth(); auto receive_bandwidth = command_view.GetReceiveBandwidth(); - if (transmit_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && - input_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + if (transmit_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + input_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && transmit_bandwidth != input_bandwidth) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Transmit_Bandwidth ({})" @@ -865,8 +795,7 @@ void DualModeController::EnhancedAcceptSynchronousConnection( } if ((transmit_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT) != - (input_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { + (input_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Transmit_Coding_Format " "({}) and Input_Coding_Format ({}) as they are incompatible", @@ -878,10 +807,8 @@ void DualModeController::EnhancedAcceptSynchronousConnection( // be “transparent” or neither shall be. If both are “transparent”, the // Receive_Bandwidth and the Output_Bandwidth shall be the same and the // Controller shall not modify the data sent to the Host. - if (receive_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && - output_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + if (receive_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && + output_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT && receive_bandwidth != output_bandwidth) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Receive_Bandwidth ({})" @@ -895,8 +822,7 @@ void DualModeController::EnhancedAcceptSynchronousConnection( } if ((receive_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT) != - (output_coding_format.coding_format_ == - bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { + (output_coding_format.coding_format_ == bluetooth::hci::ScoCodingFormatValues::TRANSPARENT)) { INFO(id_, "EnhancedSetupSynchronousConnection: rejected Receive_Coding_Format " "({}) and Output_Coding_Format ({}) as they are incompatible", @@ -906,47 +832,40 @@ void DualModeController::EnhancedAcceptSynchronousConnection( if (status == ErrorCode::SUCCESS) { status = link_layer_controller_.AcceptSynchronousConnection( - command_view.GetBdAddr(), transmit_bandwidth, receive_bandwidth, - command_view.GetMaxLatency(), link_layer_controller_.GetVoiceSetting(), - static_cast(command_view.GetRetransmissionEffort()), - command_view.GetPacketType()); + command_view.GetBdAddr(), transmit_bandwidth, receive_bandwidth, + command_view.GetMaxLatency(), link_layer_controller_.GetVoiceSetting(), + static_cast(command_view.GetRetransmissionEffort()), + command_view.GetPacketType()); } - send_event_( - bluetooth::hci::EnhancedAcceptSynchronousConnectionStatusBuilder::Create( + send_event_(bluetooth::hci::EnhancedAcceptSynchronousConnectionStatusBuilder::Create( status, kNumCommandPackets)); } void DualModeController::RejectSynchronousConnection(CommandView command) { - auto command_view = - bluetooth::hci::RejectSynchronousConnectionView::Create(command); + auto command_view = bluetooth::hci::RejectSynchronousConnectionView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Reject Synchronous Connection"); DEBUG(id_, " bd_addr={}", command_view.GetBdAddr()); - DEBUG(id_, " reason={}", - bluetooth::hci::RejectConnectionReasonText(command_view.GetReason())); + DEBUG(id_, " reason={}", bluetooth::hci::RejectConnectionReasonText(command_view.GetReason())); 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)); + send_event_(bluetooth::hci::RejectSynchronousConnectionStatusBuilder::Create(status, + kNumCommandPackets)); } -void DualModeController::ReadInquiryResponseTransmitPowerLevel( - CommandView command) { - auto command_view = - bluetooth::hci::ReadInquiryResponseTransmitPowerLevelView::Create( - command); +void DualModeController::ReadInquiryResponseTransmitPowerLevel(CommandView command) { + auto command_view = bluetooth::hci::ReadInquiryResponseTransmitPowerLevelView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Inquiry Response Transmit Power Level"); uint8_t tx_power = 20; // maximum - send_event_( - bluetooth::hci::ReadInquiryResponseTransmitPowerLevelCompleteBuilder:: - Create(kNumCommandPackets, ErrorCode::SUCCESS, tx_power)); + send_event_(bluetooth::hci::ReadInquiryResponseTransmitPowerLevelCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS, tx_power)); } void DualModeController::EnhancedFlush(CommandView command) { @@ -957,14 +876,13 @@ void DualModeController::EnhancedFlush(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); auto handle = command_view.GetConnectionHandle(); - send_event_(bluetooth::hci::EnhancedFlushStatusBuilder::Create( - ErrorCode::SUCCESS, kNumCommandPackets)); + send_event_(bluetooth::hci::EnhancedFlushStatusBuilder::Create(ErrorCode::SUCCESS, + kNumCommandPackets)); // TODO: When adding a queue of ACL packets. // Send the Enhanced Flush Complete event after discarding // all L2CAP packets identified by the Packet Type. - if (link_layer_controller_.IsEventUnmasked( - bluetooth::hci::EventCode::ENHANCED_FLUSH_COMPLETE)) { + if (link_layer_controller_.IsEventUnmasked(bluetooth::hci::EventCode::ENHANCED_FLUSH_COMPLETE)) { send_event_(bluetooth::hci::EnhancedFlushCompleteBuilder::Create(handle)); } } @@ -977,8 +895,8 @@ void DualModeController::SetEventMaskPage2(CommandView command) { DEBUG(id_, " event_mask_page_2=0x{:x}", command_view.GetEventMaskPage2()); link_layer_controller_.SetEventMaskPage2(command_view.GetEventMaskPage2()); - send_event_(bluetooth::hci::SetEventMaskPage2CompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::SetEventMaskPage2CompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadLocalOobData(CommandView command) { @@ -990,8 +908,7 @@ void DualModeController::ReadLocalOobData(CommandView command) { } void DualModeController::ReadLocalOobExtendedData(CommandView command) { - auto command_view = - bluetooth::hci::ReadLocalOobExtendedDataView::Create(command); + auto command_view = bluetooth::hci::ReadLocalOobExtendedDataView::Create(command); DEBUG(id_, "<< Read Local Oob Extended Data"); @@ -999,24 +916,21 @@ void DualModeController::ReadLocalOobExtendedData(CommandView command) { } void DualModeController::WriteSimplePairingMode(CommandView command) { - auto command_view = - bluetooth::hci::WriteSimplePairingModeView::Create(command); + auto command_view = bluetooth::hci::WriteSimplePairingModeView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Simple Pairing Mode"); DEBUG(id_, " simple_pairing_mode={}", command_view.GetSimplePairingMode() == bluetooth::hci::Enable::ENABLED); - auto enabled = - command_view.GetSimplePairingMode() == bluetooth::hci::Enable::ENABLED; + auto enabled = command_view.GetSimplePairingMode() == bluetooth::hci::Enable::ENABLED; link_layer_controller_.SetSecureSimplePairingSupport(enabled); - send_event_(bluetooth::hci::WriteSimplePairingModeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteSimplePairingModeCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ChangeConnectionPacketType(CommandView command) { - auto command_view = - bluetooth::hci::ChangeConnectionPacketTypeView::Create(command); + auto command_view = bluetooth::hci::ChangeConnectionPacketTypeView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Change Connection Packet Type"); @@ -1026,10 +940,9 @@ void DualModeController::ChangeConnectionPacketType(CommandView command) { uint16_t handle = command_view.GetConnectionHandle(); uint16_t packet_type = static_cast(command_view.GetPacketType()); - auto status = - link_layer_controller_.ChangeConnectionPacketType(handle, packet_type); - send_event_(bluetooth::hci::ChangeConnectionPacketTypeStatusBuilder::Create( - status, kNumCommandPackets)); + auto status = link_layer_controller_.ChangeConnectionPacketType(handle, packet_type); + send_event_(bluetooth::hci::ChangeConnectionPacketTypeStatusBuilder::Create(status, + kNumCommandPackets)); } void DualModeController::WriteLeHostSupport(CommandView command) { @@ -1040,29 +953,23 @@ void DualModeController::WriteLeHostSupport(CommandView command) { DEBUG(id_, " le_supported_host={}", command_view.GetLeSupportedHost() == bluetooth::hci::Enable::ENABLED); - auto le_support = - command_view.GetLeSupportedHost() == bluetooth::hci::Enable::ENABLED; + auto le_support = command_view.GetLeSupportedHost() == bluetooth::hci::Enable::ENABLED; link_layer_controller_.SetLeHostSupport(le_support); - send_event_(bluetooth::hci::WriteLeHostSupportCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteLeHostSupportCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } -void DualModeController::WriteSecureConnectionsHostSupport( - CommandView command) { - auto command_view = - bluetooth::hci::WriteSecureConnectionsHostSupportView::Create(command); +void DualModeController::WriteSecureConnectionsHostSupport(CommandView command) { + auto command_view = bluetooth::hci::WriteSecureConnectionsHostSupportView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Secure Connections Host Support"); DEBUG(id_, " secure_connections_host_support={}", - command_view.GetSecureConnectionsHostSupport() == - bluetooth::hci::Enable::ENABLED); + command_view.GetSecureConnectionsHostSupport() == bluetooth::hci::Enable::ENABLED); link_layer_controller_.SetSecureConnectionsSupport( - command_view.GetSecureConnectionsHostSupport() == - bluetooth::hci::Enable::ENABLED); - send_event_( - bluetooth::hci::WriteSecureConnectionsHostSupportCompleteBuilder::Create( + command_view.GetSecureConnectionsHostSupport() == bluetooth::hci::Enable::ENABLED); + send_event_(bluetooth::hci::WriteSecureConnectionsHostSupportCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS)); } @@ -1074,8 +981,8 @@ void DualModeController::SetEventMask(CommandView command) { DEBUG(id_, " event_mask=0x{:x}", command_view.GetEventMask()); link_layer_controller_.SetEventMask(command_view.GetEventMask()); - send_event_(bluetooth::hci::SetEventMaskCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::SetEventMaskCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadInquiryMode(CommandView command) { @@ -1084,10 +991,9 @@ void DualModeController::ReadInquiryMode(CommandView command) { DEBUG(id_, "<< Read Inquiry Mode"); - bluetooth::hci::InquiryMode inquiry_mode = - bluetooth::hci::InquiryMode::STANDARD; + bluetooth::hci::InquiryMode inquiry_mode = bluetooth::hci::InquiryMode::STANDARD; send_event_(bluetooth::hci::ReadInquiryModeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, inquiry_mode)); + kNumCommandPackets, ErrorCode::SUCCESS, inquiry_mode)); } void DualModeController::WriteInquiryMode(CommandView command) { @@ -1095,13 +1001,11 @@ void DualModeController::WriteInquiryMode(CommandView command) { CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Inquiry Mode"); - DEBUG(id_, " inquiry_mode={}", - bluetooth::hci::InquiryModeText(command_view.GetInquiryMode())); + DEBUG(id_, " inquiry_mode={}", bluetooth::hci::InquiryModeText(command_view.GetInquiryMode())); - link_layer_controller_.SetInquiryMode( - static_cast(command_view.GetInquiryMode())); - send_event_(bluetooth::hci::WriteInquiryModeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + link_layer_controller_.SetInquiryMode(static_cast(command_view.GetInquiryMode())); + send_event_(bluetooth::hci::WriteInquiryModeCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadPageScanType(CommandView command) { @@ -1110,10 +1014,9 @@ void DualModeController::ReadPageScanType(CommandView command) { DEBUG(id_, "<< Read Page Scan Type"); - bluetooth::hci::PageScanType page_scan_type = - bluetooth::hci::PageScanType::STANDARD; + bluetooth::hci::PageScanType page_scan_type = bluetooth::hci::PageScanType::STANDARD; send_event_(bluetooth::hci::ReadPageScanTypeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, page_scan_type)); + kNumCommandPackets, ErrorCode::SUCCESS, page_scan_type)); } void DualModeController::WritePageScanType(CommandView command) { @@ -1124,8 +1027,8 @@ void DualModeController::WritePageScanType(CommandView command) { DEBUG(id_, " page_scan_type={}", bluetooth::hci::PageScanTypeText(command_view.GetPageScanType())); - send_event_(bluetooth::hci::WritePageScanTypeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WritePageScanTypeCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadInquiryScanType(CommandView command) { @@ -1134,10 +1037,9 @@ void DualModeController::ReadInquiryScanType(CommandView command) { DEBUG(id_, "<< Read Inquiry Scan Type"); - bluetooth::hci::InquiryScanType inquiry_scan_type = - bluetooth::hci::InquiryScanType::STANDARD; + bluetooth::hci::InquiryScanType inquiry_scan_type = bluetooth::hci::InquiryScanType::STANDARD; send_event_(bluetooth::hci::ReadInquiryScanTypeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, inquiry_scan_type)); + kNumCommandPackets, ErrorCode::SUCCESS, inquiry_scan_type)); } void DualModeController::WriteInquiryScanType(CommandView command) { @@ -1148,13 +1050,12 @@ void DualModeController::WriteInquiryScanType(CommandView command) { DEBUG(id_, " inquiry_scan_type={}", bluetooth::hci::InquiryScanTypeText(command_view.GetInquiryScanType())); - send_event_(bluetooth::hci::WriteInquiryScanTypeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteInquiryScanTypeCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ChangeConnectionLinkKey(CommandView command) { - auto command_view = - bluetooth::hci::ChangeConnectionLinkKeyView::Create(command); + auto command_view = bluetooth::hci::ChangeConnectionLinkKeyView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Change Connection Link Key"); @@ -1163,8 +1064,8 @@ void DualModeController::ChangeConnectionLinkKey(CommandView command) { uint16_t handle = command_view.GetConnectionHandle(); auto status = link_layer_controller_.ChangeConnectionLinkKey(handle); - send_event_(bluetooth::hci::ChangeConnectionLinkKeyStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_( + bluetooth::hci::ChangeConnectionLinkKeyStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::CentralLinkKey(CommandView command) { @@ -1172,43 +1073,37 @@ void DualModeController::CentralLinkKey(CommandView command) { CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Central Link Key"); - DEBUG(id_, " key_flag={}", - bluetooth::hci::KeyFlagText(command_view.GetKeyFlag())); + DEBUG(id_, " key_flag={}", bluetooth::hci::KeyFlagText(command_view.GetKeyFlag())); uint8_t key_flag = static_cast(command_view.GetKeyFlag()); auto status = link_layer_controller_.CentralLinkKey(key_flag); - send_event_(bluetooth::hci::CentralLinkKeyStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::CentralLinkKeyStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::WriteAuthenticationEnable(CommandView command) { - auto command_view = - bluetooth::hci::WriteAuthenticationEnableView::Create(command); + auto command_view = bluetooth::hci::WriteAuthenticationEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Authentication Enable"); DEBUG(id_, " authentication_enable={}", - bluetooth::hci::AuthenticationEnableText( - command_view.GetAuthenticationEnable())); + bluetooth::hci::AuthenticationEnableText(command_view.GetAuthenticationEnable())); - link_layer_controller_.SetAuthenticationEnable( - command_view.GetAuthenticationEnable()); - send_event_(bluetooth::hci::WriteAuthenticationEnableCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + link_layer_controller_.SetAuthenticationEnable(command_view.GetAuthenticationEnable()); + send_event_(bluetooth::hci::WriteAuthenticationEnableCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadAuthenticationEnable(CommandView command) { - auto command_view = - bluetooth::hci::ReadAuthenticationEnableView::Create(command); + auto command_view = bluetooth::hci::ReadAuthenticationEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Authentication Enable"); send_event_(bluetooth::hci::ReadAuthenticationEnableCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - static_cast( - link_layer_controller_.GetAuthenticationEnable()))); + kNumCommandPackets, ErrorCode::SUCCESS, + static_cast( + link_layer_controller_.GetAuthenticationEnable()))); } void DualModeController::ReadClassOfDevice(CommandView command) { @@ -1218,8 +1113,7 @@ void DualModeController::ReadClassOfDevice(CommandView command) { DEBUG(id_, "<< Read Class of Device"); send_event_(bluetooth::hci::ReadClassOfDeviceCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - link_layer_controller_.GetClassOfDevice())); + kNumCommandPackets, ErrorCode::SUCCESS, link_layer_controller_.GetClassOfDevice())); } void DualModeController::WriteClassOfDevice(CommandView command) { @@ -1230,8 +1124,8 @@ void DualModeController::WriteClassOfDevice(CommandView command) { DEBUG(id_, " class_of_device=0x{:x}", command_view.GetClassOfDevice()); link_layer_controller_.SetClassOfDevice(command_view.GetClassOfDevice()); - send_event_(bluetooth::hci::WriteClassOfDeviceCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteClassOfDeviceCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadPageTimeout(CommandView command) { @@ -1242,7 +1136,7 @@ void DualModeController::ReadPageTimeout(CommandView command) { uint16_t page_timeout = link_layer_controller_.GetPageTimeout(); send_event_(bluetooth::hci::ReadPageTimeoutCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, page_timeout)); + kNumCommandPackets, ErrorCode::SUCCESS, page_timeout)); } void DualModeController::WritePageTimeout(CommandView command) { @@ -1253,8 +1147,8 @@ void DualModeController::WritePageTimeout(CommandView command) { DEBUG(id_, " page_timeout={}", command_view.GetPageTimeout()); link_layer_controller_.SetPageTimeout(command_view.GetPageTimeout()); - send_event_(bluetooth::hci::WritePageTimeoutCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WritePageTimeoutCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::HoldMode(CommandView command) { @@ -1267,11 +1161,10 @@ void DualModeController::HoldMode(CommandView command) { DEBUG(id_, "<< Hold Mode"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); - auto status = link_layer_controller_.HoldMode(handle, hold_mode_max_interval, - hold_mode_min_interval); + auto status = + link_layer_controller_.HoldMode(handle, hold_mode_max_interval, hold_mode_min_interval); - send_event_(bluetooth::hci::HoldModeStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::HoldModeStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::SniffMode(CommandView command) { @@ -1286,12 +1179,10 @@ void DualModeController::SniffMode(CommandView command) { DEBUG(id_, "<< Sniff Mode"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); - auto status = link_layer_controller_.SniffMode(handle, sniff_max_interval, - sniff_min_interval, + auto status = link_layer_controller_.SniffMode(handle, sniff_max_interval, sniff_min_interval, sniff_attempt, sniff_timeout); - send_event_(bluetooth::hci::SniffModeStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::SniffModeStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::ExitSniffMode(CommandView command) { @@ -1301,11 +1192,9 @@ void DualModeController::ExitSniffMode(CommandView command) { DEBUG(id_, "<< Exit Sniff Mode"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); - auto status = - link_layer_controller_.ExitSniffMode(command_view.GetConnectionHandle()); + auto status = link_layer_controller_.ExitSniffMode(command_view.GetConnectionHandle()); - send_event_(bluetooth::hci::ExitSniffModeStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::ExitSniffModeStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::QosSetup(CommandView command) { @@ -1321,12 +1210,10 @@ void DualModeController::QosSetup(CommandView command) { DEBUG(id_, "<< Qos Setup"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); - auto status = - link_layer_controller_.QosSetup(handle, service_type, token_rate, - peak_bandwidth, latency, delay_variation); + auto status = link_layer_controller_.QosSetup(handle, service_type, token_rate, peak_bandwidth, + latency, delay_variation); - send_event_(bluetooth::hci::QosSetupStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::QosSetupStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::RoleDiscovery(CommandView command) { @@ -1340,36 +1227,31 @@ void DualModeController::RoleDiscovery(CommandView command) { auto role = bluetooth::hci::Role::CENTRAL; auto status = link_layer_controller_.RoleDiscovery(handle, &role); - send_event_(bluetooth::hci::RoleDiscoveryCompleteBuilder::Create( - kNumCommandPackets, status, handle, role)); + send_event_(bluetooth::hci::RoleDiscoveryCompleteBuilder::Create(kNumCommandPackets, status, + handle, role)); } void DualModeController::ReadDefaultLinkPolicySettings(CommandView command) { - auto command_view = - bluetooth::hci::ReadDefaultLinkPolicySettingsView::Create(command); + auto command_view = bluetooth::hci::ReadDefaultLinkPolicySettingsView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Default Link Policy Settings"); uint16_t settings = link_layer_controller_.ReadDefaultLinkPolicySettings(); - send_event_( - bluetooth::hci::ReadDefaultLinkPolicySettingsCompleteBuilder::Create( + send_event_(bluetooth::hci::ReadDefaultLinkPolicySettingsCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, settings)); } void DualModeController::WriteDefaultLinkPolicySettings(CommandView command) { - auto command_view = - bluetooth::hci::WriteDefaultLinkPolicySettingsView::Create(command); + auto command_view = bluetooth::hci::WriteDefaultLinkPolicySettingsView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Default Link Policy Settings"); - DEBUG(id_, " default_link_policy_settings=0x{:x}", - command_view.GetDefaultLinkPolicySettings()); + DEBUG(id_, " default_link_policy_settings=0x{:x}", command_view.GetDefaultLinkPolicySettings()); ErrorCode status = link_layer_controller_.WriteDefaultLinkPolicySettings( - command_view.GetDefaultLinkPolicySettings()); - send_event_( - bluetooth::hci::WriteDefaultLinkPolicySettingsCompleteBuilder::Create( + command_view.GetDefaultLinkPolicySettings()); + send_event_(bluetooth::hci::WriteDefaultLinkPolicySettingsCompleteBuilder::Create( kNumCommandPackets, status)); } @@ -1382,15 +1264,14 @@ void DualModeController::SniffSubrating(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", connection_handle); send_event_(bluetooth::hci::SniffSubratingCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, connection_handle)); + kNumCommandPackets, ErrorCode::SUCCESS, connection_handle)); } void DualModeController::FlowSpecification(CommandView command) { auto command_view = bluetooth::hci::FlowSpecificationView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); - uint8_t flow_direction = - static_cast(command_view.GetFlowDirection()); + uint8_t flow_direction = static_cast(command_view.GetFlowDirection()); uint8_t service_type = static_cast(command_view.GetServiceType()); uint32_t token_rate = command_view.GetTokenRate(); uint32_t token_bucket_size = command_view.GetTokenBucketSize(); @@ -1400,17 +1281,15 @@ void DualModeController::FlowSpecification(CommandView command) { DEBUG(id_, "<< Flow Specification"); DEBUG(id_, " connection_handle=0x{:x}", handle); - auto status = link_layer_controller_.FlowSpecification( - handle, flow_direction, service_type, token_rate, token_bucket_size, - peak_bandwidth, access_latency); + auto status = link_layer_controller_.FlowSpecification(handle, flow_direction, service_type, + token_rate, token_bucket_size, + peak_bandwidth, access_latency); - send_event_(bluetooth::hci::FlowSpecificationStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::FlowSpecificationStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::ReadLinkPolicySettings(CommandView command) { - auto command_view = - bluetooth::hci::ReadLinkPolicySettingsView::Create(command); + auto command_view = bluetooth::hci::ReadLinkPolicySettingsView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); @@ -1418,16 +1297,14 @@ void DualModeController::ReadLinkPolicySettings(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", handle); uint16_t settings = 0; - auto status = - link_layer_controller_.ReadLinkPolicySettings(handle, &settings); + auto status = link_layer_controller_.ReadLinkPolicySettings(handle, &settings); send_event_(bluetooth::hci::ReadLinkPolicySettingsCompleteBuilder::Create( - kNumCommandPackets, status, handle, settings)); + kNumCommandPackets, status, handle, settings)); } void DualModeController::WriteLinkPolicySettings(CommandView command) { - auto command_view = - bluetooth::hci::WriteLinkPolicySettingsView::Create(command); + auto command_view = bluetooth::hci::WriteLinkPolicySettingsView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint16_t settings = command_view.GetLinkPolicySettings(); @@ -1436,16 +1313,14 @@ void DualModeController::WriteLinkPolicySettings(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", handle); DEBUG(id_, " link_policy_settings=0x{:x}", settings); - auto status = - link_layer_controller_.WriteLinkPolicySettings(handle, settings); + auto status = link_layer_controller_.WriteLinkPolicySettings(handle, settings); - send_event_(bluetooth::hci::WriteLinkPolicySettingsCompleteBuilder::Create( - kNumCommandPackets, status, handle)); + send_event_(bluetooth::hci::WriteLinkPolicySettingsCompleteBuilder::Create(kNumCommandPackets, + status, handle)); } void DualModeController::WriteLinkSupervisionTimeout(CommandView command) { - auto command_view = - bluetooth::hci::WriteLinkSupervisionTimeoutView::Create(command); + auto command_view = bluetooth::hci::WriteLinkSupervisionTimeoutView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); uint16_t timeout = command_view.GetLinkSupervisionTimeout(); @@ -1454,11 +1329,9 @@ void DualModeController::WriteLinkSupervisionTimeout(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", handle); DEBUG(id_, " link_supervision_timeout={}", timeout); - auto status = - link_layer_controller_.WriteLinkSupervisionTimeout(handle, timeout); - send_event_( - bluetooth::hci::WriteLinkSupervisionTimeoutCompleteBuilder::Create( - kNumCommandPackets, status, handle)); + auto status = link_layer_controller_.WriteLinkSupervisionTimeout(handle, timeout); + send_event_(bluetooth::hci::WriteLinkSupervisionTimeoutCompleteBuilder::Create(kNumCommandPackets, + status, handle)); } void DualModeController::ReadLocalName(CommandView command) { @@ -1468,8 +1341,7 @@ void DualModeController::ReadLocalName(CommandView command) { DEBUG(id_, "<< Read Local Name"); send_event_(bluetooth::hci::ReadLocalNameCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - link_layer_controller_.GetLocalName())); + kNumCommandPackets, ErrorCode::SUCCESS, link_layer_controller_.GetLocalName())); } void DualModeController::WriteLocalName(CommandView command) { @@ -1479,21 +1351,18 @@ void DualModeController::WriteLocalName(CommandView command) { DEBUG(id_, "<< Write Local Name"); link_layer_controller_.SetLocalName(command_view.GetLocalName()); - send_event_(bluetooth::hci::WriteLocalNameCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteLocalNameCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::WriteExtendedInquiryResponse(CommandView command) { - auto command_view = - bluetooth::hci::WriteExtendedInquiryResponseView::Create(command); + auto command_view = bluetooth::hci::WriteExtendedInquiryResponseView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Extended Inquiry Response"); - link_layer_controller_.SetExtendedInquiryResponse( - command_view.GetExtendedInquiryResponse()); - send_event_( - bluetooth::hci::WriteExtendedInquiryResponseCompleteBuilder::Create( + link_layer_controller_.SetExtendedInquiryResponse(command_view.GetExtendedInquiryResponse()); + send_event_(bluetooth::hci::WriteExtendedInquiryResponseCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS)); } @@ -1505,11 +1374,11 @@ void DualModeController::RefreshEncryptionKey(CommandView command) { DEBUG(id_, "<< Refresh Encryption Key"); DEBUG(id_, " connection_handle=0x{:x}", handle); - send_event_(bluetooth::hci::RefreshEncryptionKeyStatusBuilder::Create( - ErrorCode::SUCCESS, kNumCommandPackets)); + send_event_(bluetooth::hci::RefreshEncryptionKeyStatusBuilder::Create(ErrorCode::SUCCESS, + kNumCommandPackets)); // TODO: Support this in the link layer - send_event_(bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create( - ErrorCode::SUCCESS, handle)); + send_event_( + bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create(ErrorCode::SUCCESS, handle)); } void DualModeController::ReadVoiceSetting(CommandView command) { @@ -1519,8 +1388,7 @@ void DualModeController::ReadVoiceSetting(CommandView command) { DEBUG(id_, "<< Read Voice Setting"); send_event_(bluetooth::hci::ReadVoiceSettingCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - link_layer_controller_.GetVoiceSetting())); + kNumCommandPackets, ErrorCode::SUCCESS, link_layer_controller_.GetVoiceSetting())); } void DualModeController::WriteVoiceSetting(CommandView command) { @@ -1532,19 +1400,18 @@ void DualModeController::WriteVoiceSetting(CommandView command) { link_layer_controller_.SetVoiceSetting(command_view.GetVoiceSetting()); - send_event_(bluetooth::hci::WriteVoiceSettingCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteVoiceSettingCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadNumberOfSupportedIac(CommandView command) { - auto command_view = - bluetooth::hci::ReadNumberOfSupportedIacView::Create(command); + auto command_view = bluetooth::hci::ReadNumberOfSupportedIacView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Number of Supported Iac"); send_event_(bluetooth::hci::ReadNumberOfSupportedIacCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, properties_.num_supported_iac)); + kNumCommandPackets, ErrorCode::SUCCESS, properties_.num_supported_iac)); } void DualModeController::ReadCurrentIacLap(CommandView command) { @@ -1554,8 +1421,7 @@ void DualModeController::ReadCurrentIacLap(CommandView command) { DEBUG(id_, "<< Read Current Iac Lap"); send_event_(bluetooth::hci::ReadCurrentIacLapCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - link_layer_controller_.ReadCurrentIacLap())); + kNumCommandPackets, ErrorCode::SUCCESS, link_layer_controller_.ReadCurrentIacLap())); } void DualModeController::WriteCurrentIacLap(CommandView command) { @@ -1565,8 +1431,8 @@ void DualModeController::WriteCurrentIacLap(CommandView command) { DEBUG(id_, "<< Write Current Iac Lap"); link_layer_controller_.WriteCurrentIacLap(command_view.GetLapsToWrite()); - send_event_(bluetooth::hci::WriteCurrentIacLapCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteCurrentIacLapCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadPageScanActivity(CommandView command) { @@ -1578,23 +1444,21 @@ void DualModeController::ReadPageScanActivity(CommandView command) { uint16_t interval = 0x1000; uint16_t window = 0x0012; send_event_(bluetooth::hci::ReadPageScanActivityCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, interval, window)); + kNumCommandPackets, ErrorCode::SUCCESS, interval, window)); } void DualModeController::WritePageScanActivity(CommandView command) { - auto command_view = - bluetooth::hci::WritePageScanActivityView::Create(command); + auto command_view = bluetooth::hci::WritePageScanActivityView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Page Scan Activity"); - send_event_(bluetooth::hci::WritePageScanActivityCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WritePageScanActivityCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadInquiryScanActivity(CommandView command) { - auto command_view = - bluetooth::hci::ReadInquiryScanActivityView::Create(command); + auto command_view = bluetooth::hci::ReadInquiryScanActivityView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Inquiry Scan Activity"); @@ -1602,18 +1466,17 @@ void DualModeController::ReadInquiryScanActivity(CommandView command) { uint16_t interval = 0x1000; uint16_t window = 0x0012; send_event_(bluetooth::hci::ReadInquiryScanActivityCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, interval, window)); + kNumCommandPackets, ErrorCode::SUCCESS, interval, window)); } void DualModeController::WriteInquiryScanActivity(CommandView command) { - auto command_view = - bluetooth::hci::WriteInquiryScanActivityView::Create(command); + auto command_view = bluetooth::hci::WriteInquiryScanActivityView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Inquiry Scan Activity"); - send_event_(bluetooth::hci::WriteInquiryScanActivityCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteInquiryScanActivityCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadScanEnable(CommandView command) { @@ -1626,34 +1489,31 @@ void DualModeController::ReadScanEnable(CommandView command) { bool page_scan = link_layer_controller_.GetPageScanEnable(); bluetooth::hci::ScanEnable scan_enable = - inquiry_scan && page_scan - ? bluetooth::hci::ScanEnable::INQUIRY_AND_PAGE_SCAN - : inquiry_scan ? bluetooth::hci::ScanEnable::INQUIRY_SCAN_ONLY - : page_scan ? bluetooth::hci::ScanEnable::PAGE_SCAN_ONLY - : bluetooth::hci::ScanEnable::NO_SCANS; + inquiry_scan && page_scan ? bluetooth::hci::ScanEnable::INQUIRY_AND_PAGE_SCAN + : inquiry_scan ? bluetooth::hci::ScanEnable::INQUIRY_SCAN_ONLY + : page_scan ? bluetooth::hci::ScanEnable::PAGE_SCAN_ONLY + : bluetooth::hci::ScanEnable::NO_SCANS; send_event_(bluetooth::hci::ReadScanEnableCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, scan_enable)); + kNumCommandPackets, ErrorCode::SUCCESS, scan_enable)); } void DualModeController::WriteScanEnable(CommandView command) { auto command_view = bluetooth::hci::WriteScanEnableView::Create(command); CHECK_PACKET_VIEW(command_view); bluetooth::hci::ScanEnable scan_enable = command_view.GetScanEnable(); - bool inquiry_scan = - scan_enable == bluetooth::hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || - scan_enable == bluetooth::hci::ScanEnable::INQUIRY_SCAN_ONLY; - bool page_scan = - scan_enable == bluetooth::hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || - scan_enable == bluetooth::hci::ScanEnable::PAGE_SCAN_ONLY; + bool inquiry_scan = scan_enable == bluetooth::hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || + scan_enable == bluetooth::hci::ScanEnable::INQUIRY_SCAN_ONLY; + bool page_scan = scan_enable == bluetooth::hci::ScanEnable::INQUIRY_AND_PAGE_SCAN || + scan_enable == bluetooth::hci::ScanEnable::PAGE_SCAN_ONLY; DEBUG(id_, "<< Write Scan Enable"); DEBUG(id_, " scan_enable={}", bluetooth::hci::ScanEnableText(scan_enable)); link_layer_controller_.SetInquiryScanEnable(inquiry_scan); link_layer_controller_.SetPageScanEnable(page_scan); - send_event_(bluetooth::hci::WriteScanEnableCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::WriteScanEnableCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadTransmitPowerLevel(CommandView command) { @@ -1665,11 +1525,11 @@ void DualModeController::ReadTransmitPowerLevel(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", connection_handle); ErrorCode status = link_layer_controller_.HasAclConnection(connection_handle) - ? ErrorCode::SUCCESS - : ErrorCode::UNKNOWN_CONNECTION; + ? ErrorCode::SUCCESS + : ErrorCode::UNKNOWN_CONNECTION; send_event_(bluetooth::hci::ReadTransmitPowerLevelCompleteBuilder::Create( - kNumCommandPackets, status, connection_handle, kTransmitPowerLevel)); + kNumCommandPackets, status, connection_handle, kTransmitPowerLevel)); } void DualModeController::ReadEnhancedTransmitPowerLevel(CommandView command) { @@ -1681,17 +1541,16 @@ void DualModeController::ReadEnhancedTransmitPowerLevel(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", connection_handle); ErrorCode status = link_layer_controller_.HasAclConnection(connection_handle) - ? ErrorCode::SUCCESS - : ErrorCode::UNKNOWN_CONNECTION; + ? ErrorCode::SUCCESS + : ErrorCode::UNKNOWN_CONNECTION; send_event_(bluetooth::hci::ReadEnhancedTransmitPowerLevelCompleteBuilder::Create( - kNumCommandPackets, status, connection_handle, kTransmitPowerLevel, - kTransmitPowerLevel, kTransmitPowerLevel)); + kNumCommandPackets, status, connection_handle, kTransmitPowerLevel, kTransmitPowerLevel, + kTransmitPowerLevel)); } void DualModeController::ReadSynchronousFlowControlEnable(CommandView command) { - auto command_view = - bluetooth::hci::ReadSynchronousFlowControlEnableView::Create(command); + auto command_view = bluetooth::hci::ReadSynchronousFlowControlEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Synchronous Flow Control Enable"); @@ -1700,15 +1559,12 @@ void DualModeController::ReadSynchronousFlowControlEnable(CommandView command) { if (link_layer_controller_.GetScoFlowControlEnable()) { enabled = bluetooth::hci::Enable::ENABLED; } - send_event_( - bluetooth::hci::ReadSynchronousFlowControlEnableCompleteBuilder::Create( + send_event_(bluetooth::hci::ReadSynchronousFlowControlEnableCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, enabled)); } -void DualModeController::WriteSynchronousFlowControlEnable( - CommandView command) { - auto command_view = - bluetooth::hci::WriteSynchronousFlowControlEnableView::Create(command); +void DualModeController::WriteSynchronousFlowControlEnable(CommandView command) { + auto command_view = bluetooth::hci::WriteSynchronousFlowControlEnableView::Create(command); CHECK_PACKET_VIEW(command_view); auto enabled = command_view.GetEnable() == bluetooth::hci::Enable::ENABLED; @@ -1716,8 +1572,7 @@ void DualModeController::WriteSynchronousFlowControlEnable( DEBUG(id_, " enable={}", enabled); link_layer_controller_.SetScoFlowControlEnable(enabled); - send_event_( - bluetooth::hci::WriteSynchronousFlowControlEnableCompleteBuilder::Create( + send_event_(bluetooth::hci::WriteSynchronousFlowControlEnableCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS)); } @@ -1726,17 +1581,14 @@ void DualModeController::SetEventFilter(CommandView command) { CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Set Event Filter"); - DEBUG(id_, " filter_type={}", - bluetooth::hci::FilterTypeText(command_view.GetFilterType())); + DEBUG(id_, " filter_type={}", bluetooth::hci::FilterTypeText(command_view.GetFilterType())); -#if 0 if (command_view.GetFilterType() != bluetooth::hci::FilterType::CLEAR_ALL_FILTERS) { FATAL("unsupported event filter type"); } -#endif - send_event_(bluetooth::hci::SetEventFilterCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::SetEventFilterCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::Inquiry(CommandView command) { @@ -1751,15 +1603,14 @@ void DualModeController::Inquiry(CommandView command) { if (max_responses > 0xff || length < 1 || length > 0x30) { send_event_(bluetooth::hci::InquiryStatusBuilder::Create( - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS, kNumCommandPackets)); + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS, kNumCommandPackets)); return; } link_layer_controller_.SetInquiryLAP(command_view.GetLap().lap_); 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) { @@ -1769,45 +1620,40 @@ void DualModeController::InquiryCancel(CommandView command) { DEBUG(id_, "<< Inquiry Cancel"); link_layer_controller_.InquiryCancel(); - send_event_(bluetooth::hci::InquiryCancelCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::InquiryCancelCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::AcceptConnectionRequest(CommandView command) { - auto command_view = - bluetooth::hci::AcceptConnectionRequestView::Create(command); + auto command_view = bluetooth::hci::AcceptConnectionRequestView::Create(command); CHECK_PACKET_VIEW(command_view); Address bd_addr = command_view.GetBdAddr(); bool try_role_switch = - command_view.GetRole() == - bluetooth::hci::AcceptConnectionRequestRole::BECOME_CENTRAL; + command_view.GetRole() == bluetooth::hci::AcceptConnectionRequestRole::BECOME_CENTRAL; DEBUG(id_, "<< Accept Connection Request"); DEBUG(id_, " bd_addr={}", bd_addr); DEBUG(id_, " try_role_switch={}", try_role_switch); - auto status = - link_layer_controller_.AcceptConnectionRequest(bd_addr, try_role_switch); - send_event_(bluetooth::hci::AcceptConnectionRequestStatusBuilder::Create( - status, kNumCommandPackets)); + auto status = link_layer_controller_.AcceptConnectionRequest(bd_addr, try_role_switch); + send_event_( + bluetooth::hci::AcceptConnectionRequestStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::RejectConnectionRequest(CommandView command) { - auto command_view = - bluetooth::hci::RejectConnectionRequestView::Create(command); + auto command_view = bluetooth::hci::RejectConnectionRequestView::Create(command); CHECK_PACKET_VIEW(command_view); Address bd_addr = command_view.GetBdAddr(); auto reason = command_view.GetReason(); DEBUG(id_, "<< Reject Connection Request"); DEBUG(id_, " bd_addr={}", bd_addr); - DEBUG(id_, " reason={}", - bluetooth::hci::RejectConnectionReasonText(reason)); + DEBUG(id_, " reason={}", bluetooth::hci::RejectConnectionReasonText(reason)); - auto status = link_layer_controller_.RejectConnectionRequest( - bd_addr, static_cast(reason)); - send_event_(bluetooth::hci::RejectConnectionRequestStatusBuilder::Create( - status, kNumCommandPackets)); + auto status = + link_layer_controller_.RejectConnectionRequest(bd_addr, static_cast(reason)); + send_event_( + bluetooth::hci::RejectConnectionRequestStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::DeleteStoredLinkKey(CommandView command) { @@ -1816,8 +1662,8 @@ void DualModeController::DeleteStoredLinkKey(CommandView command) { DEBUG(id_, "<< Delete Stored Link Key"); - send_event_(bluetooth::hci::DeleteStoredLinkKeyCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, 0)); + send_event_(bluetooth::hci::DeleteStoredLinkKeyCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS, 0)); } void DualModeController::RemoteNameRequest(CommandView command) { @@ -1829,10 +1675,9 @@ void DualModeController::RemoteNameRequest(CommandView command) { DEBUG(id_, " bd_addr={}", bd_addr); auto status = link_layer_controller_.SendCommandToRemoteByAddress( - OpCode::REMOTE_NAME_REQUEST, command_view.bytes(), GetAddress(), bd_addr); + OpCode::REMOTE_NAME_REQUEST, command_view.bytes(), GetAddress(), bd_addr); - send_event_(bluetooth::hci::RemoteNameRequestStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::RemoteNameRequestStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::LeSetEventMask(CommandView command) { @@ -1843,8 +1688,8 @@ void DualModeController::LeSetEventMask(CommandView command) { DEBUG(id_, " le_event_mask=0x{:x}", command_view.GetLeEventMask()); link_layer_controller_.SetLeEventMask(command_view.GetLeEventMask()); - send_event_(bluetooth::hci::LeSetEventMaskCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::LeSetEventMaskCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::LeRequestPeerSca(CommandView command) { @@ -1868,19 +1713,18 @@ void DualModeController::LeRequestPeerSca(CommandView command) { // TODO if (link_layer_controller_.HasAclConnection(connection_handle)) { - send_event_(bluetooth::hci::LeRequestPeerScaStatusBuilder::Create( - ErrorCode::SUCCESS, kNumCommandPackets)); + send_event_(bluetooth::hci::LeRequestPeerScaStatusBuilder::Create(ErrorCode::SUCCESS, + kNumCommandPackets)); send_event_(bluetooth::hci::LeRequestPeerScaCompleteBuilder::Create( - ErrorCode::SUCCESS, connection_handle, - bluetooth::hci::ClockAccuracy::PPM_500)); + ErrorCode::SUCCESS, connection_handle, bluetooth::hci::ClockAccuracy::PPM_500)); } else { - send_event_(bluetooth::hci::LeRequestPeerScaStatusBuilder::Create( - ErrorCode::UNKNOWN_CONNECTION, kNumCommandPackets)); + send_event_(bluetooth::hci::LeRequestPeerScaStatusBuilder::Create(ErrorCode::UNKNOWN_CONNECTION, + kNumCommandPackets)); } } -void DualModeController::LeSetHostFeature(CommandView command) { - auto command_view = bluetooth::hci::LeSetHostFeatureView::Create(command); +void DualModeController::LeSetHostFeatureV1(CommandView command) { + auto command_view = bluetooth::hci::LeSetHostFeatureV1View::Create(command); CHECK_PACKET_VIEW(command_view); uint8_t bit_number = static_cast(command_view.GetBitNumber()); uint8_t bit_value = static_cast(command_view.GetBitValue()); @@ -1889,10 +1733,9 @@ void DualModeController::LeSetHostFeature(CommandView command) { DEBUG(id_, " bit_number={}", bit_number); DEBUG(id_, " bit_value={}", bit_value); - ErrorCode status = - link_layer_controller_.LeSetHostFeature(bit_number, bit_value); - send_event_(bluetooth::hci::LeSetHostFeatureCompleteBuilder::Create( - kNumCommandPackets, status)); + ErrorCode status = link_layer_controller_.LeSetHostFeature(bit_number, bit_value); + send_event_( + bluetooth::hci::LeSetHostFeatureV1CompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeReadBufferSizeV1(CommandView command) { @@ -1903,11 +1746,10 @@ void DualModeController::LeReadBufferSizeV1(CommandView command) { bluetooth::hci::LeBufferSize le_buffer_size; le_buffer_size.le_data_packet_length_ = properties_.le_acl_data_packet_length; - le_buffer_size.total_num_le_packets_ = - properties_.total_num_le_acl_data_packets; + le_buffer_size.total_num_le_packets_ = properties_.total_num_le_acl_data_packets; send_event_(bluetooth::hci::LeReadBufferSizeV1CompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, le_buffer_size)); + kNumCommandPackets, ErrorCode::SUCCESS, le_buffer_size)); } void DualModeController::LeReadBufferSizeV2(CommandView command) { @@ -1918,61 +1760,49 @@ void DualModeController::LeReadBufferSizeV2(CommandView command) { bluetooth::hci::LeBufferSize le_buffer_size; le_buffer_size.le_data_packet_length_ = properties_.le_acl_data_packet_length; - le_buffer_size.total_num_le_packets_ = - properties_.total_num_le_acl_data_packets; + le_buffer_size.total_num_le_packets_ = properties_.total_num_le_acl_data_packets; bluetooth::hci::LeBufferSize iso_buffer_size; iso_buffer_size.le_data_packet_length_ = properties_.iso_data_packet_length; - iso_buffer_size.total_num_le_packets_ = - properties_.total_num_iso_data_packets; + iso_buffer_size.total_num_le_packets_ = properties_.total_num_iso_data_packets; send_event_(bluetooth::hci::LeReadBufferSizeV2CompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, le_buffer_size, iso_buffer_size)); + kNumCommandPackets, ErrorCode::SUCCESS, le_buffer_size, iso_buffer_size)); } void DualModeController::LeSetAddressResolutionEnable(CommandView command) { - auto command_view = - bluetooth::hci::LeSetAddressResolutionEnableView::Create(command); + auto command_view = bluetooth::hci::LeSetAddressResolutionEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Address Resolution Enable"); DEBUG(id_, " address_resolution_enable={}", - command_view.GetAddressResolutionEnable() == - bluetooth::hci::Enable::ENABLED); + command_view.GetAddressResolutionEnable() == bluetooth::hci::Enable::ENABLED); ErrorCode status = link_layer_controller_.LeSetAddressResolutionEnable( - command_view.GetAddressResolutionEnable() == - bluetooth::hci::Enable::ENABLED); - send_event_( - bluetooth::hci::LeSetAddressResolutionEnableCompleteBuilder::Create( + command_view.GetAddressResolutionEnable() == bluetooth::hci::Enable::ENABLED); + send_event_(bluetooth::hci::LeSetAddressResolutionEnableCompleteBuilder::Create( kNumCommandPackets, status)); } -void DualModeController::LeSetResolvablePrivateAddressTimeout( - CommandView command) { - auto command_view = - bluetooth::hci::LeSetResolvablePrivateAddressTimeoutView::Create(command); +void DualModeController::LeSetResolvablePrivateAddressTimeout(CommandView command) { + auto command_view = bluetooth::hci::LeSetResolvablePrivateAddressTimeoutView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Resolvable Private Address Timeout"); ErrorCode status = - link_layer_controller_.LeSetResolvablePrivateAddressTimeout( - command_view.GetRpaTimeout()); - send_event_( - bluetooth::hci::LeSetResolvablePrivateAddressTimeoutCompleteBuilder:: - Create(kNumCommandPackets, status)); + link_layer_controller_.LeSetResolvablePrivateAddressTimeout(command_view.GetRpaTimeout()); + send_event_(bluetooth::hci::LeSetResolvablePrivateAddressTimeoutCompleteBuilder::Create( + kNumCommandPackets, status)); } -void DualModeController::LeReadLocalSupportedFeatures(CommandView command) { - auto command_view = - bluetooth::hci::LeReadLocalSupportedFeaturesView::Create(command); +void DualModeController::LeReadLocalSupportedFeaturesPage0(CommandView command) { + auto command_view = bluetooth::hci::LeReadLocalSupportedFeaturesPage0View::Create(command); CHECK_PACKET_VIEW(command_view); - DEBUG(id_, "<< LE Read Local Supported Features"); + DEBUG(id_, "<< LE Read Local Supported Features Page 0"); uint64_t le_features = link_layer_controller_.GetLeSupportedFeatures(); - send_event_( - bluetooth::hci::LeReadLocalSupportedFeaturesCompleteBuilder::Create( + send_event_(bluetooth::hci::LeReadLocalSupportedFeaturesPage0CompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, le_features)); } @@ -1983,43 +1813,35 @@ void DualModeController::LeSetRandomAddress(CommandView command) { DEBUG(id_, "<< LE Set Random Address"); DEBUG(id_, " random_address={}", command_view.GetRandomAddress()); - ErrorCode status = link_layer_controller_.LeSetRandomAddress( - command_view.GetRandomAddress()); - send_event_(bluetooth::hci::LeSetRandomAddressCompleteBuilder::Create( - kNumCommandPackets, status)); + ErrorCode status = link_layer_controller_.LeSetRandomAddress(command_view.GetRandomAddress()); + send_event_( + bluetooth::hci::LeSetRandomAddressCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeSetAdvertisingParameters(CommandView command) { - auto command_view = - bluetooth::hci::LeSetAdvertisingParametersView::Create(command); + auto command_view = bluetooth::hci::LeSetAdvertisingParametersView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Advertising Parameters"); ErrorCode status = link_layer_controller_.LeSetAdvertisingParameters( - command_view.GetAdvertisingIntervalMin(), - command_view.GetAdvertisingIntervalMax(), - command_view.GetAdvertisingType(), command_view.GetOwnAddressType(), - command_view.GetPeerAddressType(), command_view.GetPeerAddress(), - command_view.GetAdvertisingChannelMap(), - command_view.GetAdvertisingFilterPolicy()); - send_event_(bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create( - kNumCommandPackets, status)); -} - -void DualModeController::LeReadAdvertisingPhysicalChannelTxPower( - CommandView command) { - auto command_view = - bluetooth::hci::LeReadAdvertisingPhysicalChannelTxPowerView::Create( - command); + command_view.GetAdvertisingIntervalMin(), command_view.GetAdvertisingIntervalMax(), + command_view.GetAdvertisingType(), command_view.GetOwnAddressType(), + command_view.GetPeerAddressType(), command_view.GetPeerAddress(), + command_view.GetAdvertisingChannelMap(), command_view.GetAdvertisingFilterPolicy()); + send_event_(bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create(kNumCommandPackets, + status)); +} + +void DualModeController::LeReadAdvertisingPhysicalChannelTxPower(CommandView command) { + auto command_view = bluetooth::hci::LeReadAdvertisingPhysicalChannelTxPowerView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Physical Channel Tx Power"); - send_event_( - bluetooth::hci::LeReadAdvertisingPhysicalChannelTxPowerCompleteBuilder:: - Create(kNumCommandPackets, ErrorCode::SUCCESS, - properties_.le_advertising_physical_channel_tx_power)); + send_event_(bluetooth::hci::LeReadAdvertisingPhysicalChannelTxPowerCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS, + properties_.le_advertising_physical_channel_tx_power)); } void DualModeController::LeSetAdvertisingData(CommandView command) { @@ -2028,28 +1850,25 @@ void DualModeController::LeSetAdvertisingData(CommandView command) { DEBUG(id_, "<< LE Set Advertising Data"); - ErrorCode status = link_layer_controller_.LeSetAdvertisingData( - command_view.GetAdvertisingData()); - send_event_(bluetooth::hci::LeSetAdvertisingDataCompleteBuilder::Create( - kNumCommandPackets, status)); + ErrorCode status = link_layer_controller_.LeSetAdvertisingData(command_view.GetAdvertisingData()); + send_event_( + bluetooth::hci::LeSetAdvertisingDataCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeSetScanResponseData(CommandView command) { - auto command_view = - bluetooth::hci::LeSetScanResponseDataView::Create(command); + auto command_view = bluetooth::hci::LeSetScanResponseDataView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Scan Response Data"); - ErrorCode status = link_layer_controller_.LeSetScanResponseData( - command_view.GetAdvertisingData()); - send_event_(bluetooth::hci::LeSetScanResponseDataCompleteBuilder::Create( - kNumCommandPackets, status)); + ErrorCode status = + link_layer_controller_.LeSetScanResponseData(command_view.GetAdvertisingData()); + send_event_( + bluetooth::hci::LeSetScanResponseDataCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeSetAdvertisingEnable(CommandView command) { - auto command_view = - bluetooth::hci::LeSetAdvertisingEnableView::Create(command); + auto command_view = bluetooth::hci::LeSetAdvertisingEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Advertising Enable"); @@ -2057,9 +1876,9 @@ void DualModeController::LeSetAdvertisingEnable(CommandView command) { command_view.GetAdvertisingEnable() == bluetooth::hci::Enable::ENABLED); ErrorCode status = link_layer_controller_.LeSetAdvertisingEnable( - command_view.GetAdvertisingEnable() == bluetooth::hci::Enable::ENABLED); - send_event_(bluetooth::hci::LeSetAdvertisingEnableCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetAdvertisingEnable() == bluetooth::hci::Enable::ENABLED); + send_event_(bluetooth::hci::LeSetAdvertisingEnableCompleteBuilder::Create(kNumCommandPackets, + status)); } void DualModeController::LeSetScanParameters(CommandView command) { @@ -2069,11 +1888,11 @@ void DualModeController::LeSetScanParameters(CommandView command) { DEBUG(id_, "<< LE Set Scan Parameters"); ErrorCode status = link_layer_controller_.LeSetScanParameters( - command_view.GetLeScanType(), command_view.GetLeScanInterval(), - command_view.GetLeScanWindow(), command_view.GetOwnAddressType(), - command_view.GetScanningFilterPolicy()); - send_event_(bluetooth::hci::LeSetScanParametersCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetLeScanType(), command_view.GetLeScanInterval(), + command_view.GetLeScanWindow(), command_view.GetOwnAddressType(), + command_view.GetScanningFilterPolicy()); + send_event_( + bluetooth::hci::LeSetScanParametersCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeSetScanEnable(CommandView command) { @@ -2085,10 +1904,9 @@ void DualModeController::LeSetScanEnable(CommandView command) { command_view.GetLeScanEnable() == bluetooth::hci::Enable::ENABLED); ErrorCode status = link_layer_controller_.LeSetScanEnable( - command_view.GetLeScanEnable() == bluetooth::hci::Enable::ENABLED, - command_view.GetFilterDuplicates() == bluetooth::hci::Enable::ENABLED); - send_event_(bluetooth::hci::LeSetScanEnableCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetLeScanEnable() == bluetooth::hci::Enable::ENABLED, + command_view.GetFilterDuplicates() == bluetooth::hci::Enable::ENABLED); + send_event_(bluetooth::hci::LeSetScanEnableCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeCreateConnection(CommandView command) { @@ -2102,34 +1920,31 @@ void DualModeController::LeCreateConnection(CommandView command) { DEBUG(id_, " own_address_type={}", bluetooth::hci::OwnAddressTypeText(command_view.GetOwnAddressType())); DEBUG(id_, " initiator_filter_policy={}", - bluetooth::hci::InitiatorFilterPolicyText( - command_view.GetInitiatorFilterPolicy())); + bluetooth::hci::InitiatorFilterPolicyText(command_view.GetInitiatorFilterPolicy())); ErrorCode status = link_layer_controller_.LeCreateConnection( - command_view.GetLeScanInterval(), command_view.GetLeScanWindow(), - command_view.GetInitiatorFilterPolicy(), - AddressWithType{ - command_view.GetPeerAddress(), - command_view.GetPeerAddressType(), - }, - command_view.GetOwnAddressType(), command_view.GetConnectionIntervalMin(), - command_view.GetConnectionIntervalMax(), command_view.GetMaxLatency(), - command_view.GetSupervisionTimeout(), command_view.GetMinCeLength(), - command_view.GetMaxCeLength()); - send_event_(bluetooth::hci::LeCreateConnectionStatusBuilder::Create( - status, kNumCommandPackets)); + command_view.GetLeScanInterval(), command_view.GetLeScanWindow(), + command_view.GetInitiatorFilterPolicy(), + AddressWithType{ + command_view.GetPeerAddress(), + command_view.GetPeerAddressType(), + }, + command_view.GetOwnAddressType(), command_view.GetConnectionIntervalMin(), + command_view.GetConnectionIntervalMax(), command_view.GetMaxLatency(), + command_view.GetSupervisionTimeout(), command_view.GetMinCeLength(), + command_view.GetMaxCeLength()); + send_event_(bluetooth::hci::LeCreateConnectionStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::LeCreateConnectionCancel(CommandView command) { - auto command_view = - bluetooth::hci::LeCreateConnectionCancelView::Create(command); + auto command_view = bluetooth::hci::LeCreateConnectionCancelView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Create Connection Cancel"); ErrorCode status = link_layer_controller_.LeCreateConnectionCancel(); - send_event_(bluetooth::hci::LeCreateConnectionCancelCompleteBuilder::Create( - kNumCommandPackets, status)); + send_event_(bluetooth::hci::LeCreateConnectionCancelCompleteBuilder::Create(kNumCommandPackets, + status)); } void DualModeController::LeConnectionUpdate(CommandView command) { @@ -2140,13 +1955,11 @@ void DualModeController::LeConnectionUpdate(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); ErrorCode status = link_layer_controller_.LeConnectionUpdate( - command_view.GetConnectionHandle(), - command_view.GetConnectionIntervalMin(), - command_view.GetConnectionIntervalMax(), command_view.GetMaxLatency(), - command_view.GetSupervisionTimeout()); + command_view.GetConnectionHandle(), command_view.GetConnectionIntervalMin(), + command_view.GetConnectionIntervalMax(), command_view.GetMaxLatency(), + command_view.GetSupervisionTimeout()); - send_event_(bluetooth::hci::LeConnectionUpdateStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::LeConnectionUpdateStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::CreateConnection(CommandView command) { @@ -2154,31 +1967,27 @@ void DualModeController::CreateConnection(CommandView command) { CHECK_PACKET_VIEW(command_view); Address bd_addr = command_view.GetBdAddr(); uint16_t packet_type = command_view.GetPacketType(); - uint8_t page_scan_mode = - static_cast(command_view.GetPageScanRepetitionMode()); - uint16_t clock_offset = (command_view.GetClockOffsetValid() == - bluetooth::hci::ClockOffsetValid::VALID - ? command_view.GetClockOffset() - : 0); - uint8_t allow_role_switch = - static_cast(command_view.GetAllowRoleSwitch()); + uint8_t page_scan_mode = static_cast(command_view.GetPageScanRepetitionMode()); + uint16_t clock_offset = + (command_view.GetClockOffsetValid() == bluetooth::hci::ClockOffsetValid::VALID + ? command_view.GetClockOffset() + : 0); + uint8_t allow_role_switch = static_cast(command_view.GetAllowRoleSwitch()); DEBUG(id_, "<< Create Connection"); DEBUG(id_, " bd_addr={}", bd_addr); DEBUG(id_, " allow_role_switch={}", command_view.GetAllowRoleSwitch() == - bluetooth::hci::CreateConnectionRoleSwitch::ALLOW_ROLE_SWITCH); + bluetooth::hci::CreateConnectionRoleSwitch::ALLOW_ROLE_SWITCH); - auto status = link_layer_controller_.CreateConnection( - bd_addr, packet_type, page_scan_mode, clock_offset, allow_role_switch); + auto status = link_layer_controller_.CreateConnection(bd_addr, packet_type, page_scan_mode, + clock_offset, allow_role_switch); - send_event_(bluetooth::hci::CreateConnectionStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::CreateConnectionStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::CreateConnectionCancel(CommandView command) { - auto command_view = - bluetooth::hci::CreateConnectionCancelView::Create(command); + auto command_view = bluetooth::hci::CreateConnectionCancelView::Create(command); CHECK_PACKET_VIEW(command_view); Address address = command_view.GetBdAddr(); @@ -2187,8 +1996,8 @@ void DualModeController::CreateConnectionCancel(CommandView command) { auto status = link_layer_controller_.CreateConnectionCancel(address); - send_event_(bluetooth::hci::CreateConnectionCancelCompleteBuilder::Create( - kNumCommandPackets, status, address)); + send_event_(bluetooth::hci::CreateConnectionCancelCompleteBuilder::Create(kNumCommandPackets, + status, address)); } void DualModeController::Disconnect(CommandView command) { @@ -2199,76 +2008,64 @@ void DualModeController::Disconnect(CommandView command) { DEBUG(id_, "<< Disconnect"); DEBUG(id_, " connection_handle=0x{:x}", connection_handle); - if (connection_handle >= kCisHandleRangeStart && - connection_handle < kCisHandleRangeEnd) { + if (connection_handle >= kCisHandleRangeStart && connection_handle < kCisHandleRangeEnd) { link_layer_controller_.ForwardToLl(command); } else { - auto status = link_layer_controller_.Disconnect( - connection_handle, ErrorCode(command_view.GetReason())); + auto status = link_layer_controller_.Disconnect(connection_handle, + ErrorCode(command_view.GetReason())); - send_event_(bluetooth::hci::DisconnectStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::DisconnectStatusBuilder::Create(status, kNumCommandPackets)); } } void DualModeController::LeReadFilterAcceptListSize(CommandView command) { - auto command_view = - bluetooth::hci::LeReadFilterAcceptListSizeView::Create(command); + auto command_view = bluetooth::hci::LeReadFilterAcceptListSizeView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Filter Accept List Size"); send_event_(bluetooth::hci::LeReadFilterAcceptListSizeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - properties_.le_filter_accept_list_size)); + kNumCommandPackets, ErrorCode::SUCCESS, properties_.le_filter_accept_list_size)); } void DualModeController::LeClearFilterAcceptList(CommandView command) { - auto command_view = - bluetooth::hci::LeClearFilterAcceptListView::Create(command); + auto command_view = bluetooth::hci::LeClearFilterAcceptListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Clear Filter Accept List"); ErrorCode status = link_layer_controller_.LeClearFilterAcceptList(); - send_event_(bluetooth::hci::LeClearFilterAcceptListCompleteBuilder::Create( - kNumCommandPackets, status)); + send_event_(bluetooth::hci::LeClearFilterAcceptListCompleteBuilder::Create(kNumCommandPackets, + status)); } void DualModeController::LeAddDeviceToFilterAcceptList(CommandView command) { - auto command_view = - bluetooth::hci::LeAddDeviceToFilterAcceptListView::Create(command); + auto command_view = bluetooth::hci::LeAddDeviceToFilterAcceptListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Add Device To Filter Accept List"); DEBUG(id_, " address={}", command_view.GetAddress()); DEBUG(id_, " address_type={}", - bluetooth::hci::FilterAcceptListAddressTypeText( - command_view.GetAddressType())); + bluetooth::hci::FilterAcceptListAddressTypeText(command_view.GetAddressType())); ErrorCode status = link_layer_controller_.LeAddDeviceToFilterAcceptList( - command_view.GetAddressType(), command_view.GetAddress()); - send_event_( - bluetooth::hci::LeAddDeviceToFilterAcceptListCompleteBuilder::Create( + command_view.GetAddressType(), command_view.GetAddress()); + send_event_(bluetooth::hci::LeAddDeviceToFilterAcceptListCompleteBuilder::Create( kNumCommandPackets, status)); } -void DualModeController::LeRemoveDeviceFromFilterAcceptList( - CommandView command) { - auto command_view = - bluetooth::hci::LeRemoveDeviceFromFilterAcceptListView::Create(command); +void DualModeController::LeRemoveDeviceFromFilterAcceptList(CommandView command) { + auto command_view = bluetooth::hci::LeRemoveDeviceFromFilterAcceptListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Device From Filter Accept List"); DEBUG(id_, " address={}", command_view.GetAddress()); DEBUG(id_, " address_type={}", - bluetooth::hci::FilterAcceptListAddressTypeText( - command_view.GetAddressType())); + bluetooth::hci::FilterAcceptListAddressTypeText(command_view.GetAddressType())); ErrorCode status = link_layer_controller_.LeRemoveDeviceFromFilterAcceptList( - command_view.GetAddressType(), command_view.GetAddress()); - send_event_( - bluetooth::hci::LeRemoveDeviceFromFilterAcceptListCompleteBuilder::Create( + command_view.GetAddressType(), command_view.GetAddress()); + send_event_(bluetooth::hci::LeRemoveDeviceFromFilterAcceptListCompleteBuilder::Create( kNumCommandPackets, status)); } @@ -2279,67 +2076,56 @@ void DualModeController::LeClearResolvingList(CommandView command) { DEBUG(id_, "<< LE Clear Resolving List"); ErrorCode status = link_layer_controller_.LeClearResolvingList(); - send_event_(bluetooth::hci::LeClearResolvingListCompleteBuilder::Create( - kNumCommandPackets, status)); + send_event_( + bluetooth::hci::LeClearResolvingListCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeReadResolvingListSize(CommandView command) { - auto command_view = - bluetooth::hci::LeReadResolvingListSizeView::Create(command); + auto command_view = bluetooth::hci::LeReadResolvingListSizeView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Resolving List Size"); send_event_(bluetooth::hci::LeReadResolvingListSizeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - properties_.le_resolving_list_size)); + kNumCommandPackets, ErrorCode::SUCCESS, properties_.le_resolving_list_size)); } void DualModeController::LeReadPeerResolvableAddress(CommandView command) { - auto command_view = - bluetooth::hci::LeReadPeerResolvableAddressView::Create(command); + auto command_view = bluetooth::hci::LeReadPeerResolvableAddressView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Peer Resolvable Address"); - DEBUG(id_, " peer_identity_address={}", - command_view.GetPeerIdentityAddress()); + DEBUG(id_, " peer_identity_address={}", command_view.GetPeerIdentityAddress()); DEBUG(id_, " peer_identity_address_type={}", - bluetooth::hci::PeerAddressTypeText( - command_view.GetPeerIdentityAddressType())); + bluetooth::hci::PeerAddressTypeText(command_view.GetPeerIdentityAddressType())); Address peer_resolvable_address; ErrorCode status = link_layer_controller_.LeReadPeerResolvableAddress( - command_view.GetPeerIdentityAddressType(), - command_view.GetPeerIdentityAddress(), &peer_resolvable_address); - send_event_( - bluetooth::hci::LeReadPeerResolvableAddressCompleteBuilder::Create( + command_view.GetPeerIdentityAddressType(), command_view.GetPeerIdentityAddress(), + &peer_resolvable_address); + send_event_(bluetooth::hci::LeReadPeerResolvableAddressCompleteBuilder::Create( kNumCommandPackets, status, peer_resolvable_address)); } void DualModeController::LeReadLocalResolvableAddress(CommandView command) { - auto command_view = - bluetooth::hci::LeReadLocalResolvableAddressView::Create(command); + auto command_view = bluetooth::hci::LeReadLocalResolvableAddressView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Local Resolvable Address"); - DEBUG(id_, " peer_identity_address={}", - command_view.GetPeerIdentityAddress()); + DEBUG(id_, " peer_identity_address={}", command_view.GetPeerIdentityAddress()); DEBUG(id_, " peer_identity_address_type={}", - bluetooth::hci::PeerAddressTypeText( - command_view.GetPeerIdentityAddressType())); + bluetooth::hci::PeerAddressTypeText(command_view.GetPeerIdentityAddressType())); Address local_resolvable_address; ErrorCode status = link_layer_controller_.LeReadLocalResolvableAddress( - command_view.GetPeerIdentityAddressType(), - command_view.GetPeerIdentityAddress(), &local_resolvable_address); - send_event_( - bluetooth::hci::LeReadLocalResolvableAddressCompleteBuilder::Create( + command_view.GetPeerIdentityAddressType(), command_view.GetPeerIdentityAddress(), + &local_resolvable_address); + send_event_(bluetooth::hci::LeReadLocalResolvableAddressCompleteBuilder::Create( kNumCommandPackets, status, local_resolvable_address)); } void DualModeController::LeReadMaximumDataLength(CommandView command) { - auto command_view = - bluetooth::hci::LeReadMaximumDataLengthView::Create(command); + auto command_view = bluetooth::hci::LeReadMaximumDataLengthView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Maximum Data Length"); @@ -2350,7 +2136,7 @@ void DualModeController::LeReadMaximumDataLength(CommandView command) { data_length.supported_max_tx_octets_ = kLeMaximumDataLength + 10; data_length.supported_max_tx_time_ = kLeMaximumDataTime + 10; send_event_(bluetooth::hci::LeReadMaximumDataLengthCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, data_length)); + kNumCommandPackets, ErrorCode::SUCCESS, data_length)); } void DualModeController::LeReadPhy(CommandView command) { @@ -2363,10 +2149,9 @@ void DualModeController::LeReadPhy(CommandView command) { bluetooth::hci::PhyType tx_phy{}; bluetooth::hci::PhyType rx_phy{}; - ErrorCode status = - link_layer_controller_.LeReadPhy(connection_handle, &tx_phy, &rx_phy); - send_event_(bluetooth::hci::LeReadPhyCompleteBuilder::Create( - kNumCommandPackets, status, connection_handle, tx_phy, rx_phy)); + ErrorCode status = link_layer_controller_.LeReadPhy(connection_handle, &tx_phy, &rx_phy); + send_event_(bluetooth::hci::LeReadPhyCompleteBuilder::Create(kNumCommandPackets, status, + connection_handle, tx_phy, rx_phy)); } void DualModeController::LeSetDefaultPhy(CommandView command) { @@ -2376,11 +2161,10 @@ void DualModeController::LeSetDefaultPhy(CommandView command) { DEBUG(id_, "<< LE Set Default Phy"); ErrorCode status = link_layer_controller_.LeSetDefaultPhy( - command_view.GetAllPhysNoTransmitPreference(), - command_view.GetAllPhysNoReceivePreference(), command_view.GetTxPhys(), - command_view.GetRxPhys()); - send_event_(bluetooth::hci::LeSetDefaultPhyCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetAllPhysNoTransmitPreference(), + command_view.GetAllPhysNoReceivePreference(), command_view.GetTxPhys(), + command_view.GetRxPhys()); + send_event_(bluetooth::hci::LeSetDefaultPhyCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeSetPhy(CommandView command) { @@ -2391,32 +2175,26 @@ void DualModeController::LeSetPhy(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); ErrorCode status = link_layer_controller_.LeSetPhy( - command_view.GetConnectionHandle(), - command_view.GetAllPhysNoTransmitPreference(), - command_view.GetAllPhysNoReceivePreference(), command_view.GetTxPhys(), - command_view.GetRxPhys(), command_view.GetPhyOptions()); - send_event_(bluetooth::hci::LeSetPhyStatusBuilder::Create( - status, kNumCommandPackets)); + command_view.GetConnectionHandle(), command_view.GetAllPhysNoTransmitPreference(), + command_view.GetAllPhysNoReceivePreference(), command_view.GetTxPhys(), + command_view.GetRxPhys(), command_view.GetPhyOptions()); + send_event_(bluetooth::hci::LeSetPhyStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::LeReadSuggestedDefaultDataLength(CommandView command) { - auto command_view = - bluetooth::hci::LeReadSuggestedDefaultDataLengthView::Create(command); + auto command_view = bluetooth::hci::LeReadSuggestedDefaultDataLengthView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Suggested Default Data Length"); - send_event_( - bluetooth::hci::LeReadSuggestedDefaultDataLengthCompleteBuilder::Create( + send_event_(bluetooth::hci::LeReadSuggestedDefaultDataLengthCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, link_layer_controller_.GetLeSuggestedMaxTxOctets(), link_layer_controller_.GetLeSuggestedMaxTxTime())); } -void DualModeController::LeWriteSuggestedDefaultDataLength( - CommandView command) { - auto command_view = - bluetooth::hci::LeWriteSuggestedDefaultDataLengthView::Create(command); +void DualModeController::LeWriteSuggestedDefaultDataLength(CommandView command) { + auto command_view = bluetooth::hci::LeWriteSuggestedDefaultDataLengthView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Write Suggested Default Data Length"); @@ -2424,97 +2202,133 @@ void DualModeController::LeWriteSuggestedDefaultDataLength( uint16_t max_tx_octets = command_view.GetTxOctets(); uint16_t max_tx_time = command_view.GetTxTime(); ErrorCode status = ErrorCode::SUCCESS; - if (max_tx_octets > 0xFB || max_tx_octets < 0x1B || max_tx_time < 0x148 || - max_tx_time > 0x4290) { + if (max_tx_octets > 0xFB || max_tx_octets < 0x1B || max_tx_time < 0x148 || max_tx_time > 0x4290) { status = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } else { link_layer_controller_.SetLeSuggestedMaxTxOctets(max_tx_octets); link_layer_controller_.SetLeSuggestedMaxTxTime(max_tx_time); } - send_event_( - bluetooth::hci::LeWriteSuggestedDefaultDataLengthCompleteBuilder::Create( + send_event_(bluetooth::hci::LeWriteSuggestedDefaultDataLengthCompleteBuilder::Create( kNumCommandPackets, status)); } +static ErrorCode generateP256Key(std::array& key_x_coordinate, + std::array& key_y_coordinate) { + auto ec_key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1); + if (!ec_key) { + WARNING("EC_KEY_new_by_curve_name(NID_X9_62_prime256v1) failed"); + return ErrorCode::UNSPECIFIED_ERROR; + } + + if (!EC_KEY_generate_key(ec_key)) { + WARNING("EC_KEY_generate_key failed"); + EC_KEY_free(ec_key); + return ErrorCode::UNSPECIFIED_ERROR; + } + + uint8_t* out_buf = nullptr; + auto size = EC_KEY_key2buf(ec_key, POINT_CONVERSION_UNCOMPRESSED, &out_buf, nullptr); + if (!out_buf) { + WARNING("EC_KEY_key2buf failed"); + EC_KEY_free(ec_key); + return ErrorCode::UNSPECIFIED_ERROR; + } + + const size_t expected_size = key_x_coordinate.size() + key_y_coordinate.size() + 1; + if (size != expected_size) { + WARNING("unexpected size {}", size); + OPENSSL_free(out_buf); + EC_KEY_free(ec_key); + return ErrorCode::UNSPECIFIED_ERROR; + } + + memcpy(key_x_coordinate.data(), out_buf + 1, key_x_coordinate.size()); + memcpy(key_y_coordinate.data(), out_buf + 1 + key_x_coordinate.size(), key_y_coordinate.size()); + + // OPENSSL_free(out_buf); // <-- this call fails with error invalid pointer + EC_KEY_free(ec_key); + return ErrorCode::SUCCESS; +} + +void DualModeController::LeReadLocalP256PublicKey(CommandView command) { + auto command_view = bluetooth::hci::LeReadLocalP256PublicKeyView::Create(command); + CHECK_PACKET_VIEW(command_view); + + DEBUG(id_, "<< LE Read Local P-256 Public Key"); + + send_event_(bluetooth::hci::LeReadLocalP256PublicKeyStatusBuilder::Create(ErrorCode::SUCCESS, + kNumCommandPackets)); + + std::array key_x_coordinate = {}; + std::array key_y_coordinate = {}; + ErrorCode status = generateP256Key(key_x_coordinate, key_y_coordinate); + + send_event_(bluetooth::hci::LeReadLocalP256PublicKeyCompleteBuilder::Create( + status, key_x_coordinate, key_y_coordinate)); +} + void DualModeController::LeAddDeviceToResolvingList(CommandView command) { - auto command_view = - bluetooth::hci::LeAddDeviceToResolvingListView::Create(command); + auto command_view = bluetooth::hci::LeAddDeviceToResolvingListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Add Device to Resolving List"); - DEBUG(id_, " peer_identity_address={}", - command_view.GetPeerIdentityAddress()); + DEBUG(id_, " peer_identity_address={}", command_view.GetPeerIdentityAddress()); DEBUG(id_, " peer_identity_address_type={}", - bluetooth::hci::PeerAddressTypeText( - command_view.GetPeerIdentityAddressType())); + bluetooth::hci::PeerAddressTypeText(command_view.GetPeerIdentityAddressType())); ErrorCode status = link_layer_controller_.LeAddDeviceToResolvingList( - command_view.GetPeerIdentityAddressType(), - command_view.GetPeerIdentityAddress(), command_view.GetPeerIrk(), - command_view.GetLocalIrk()); - send_event_(bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetPeerIdentityAddressType(), command_view.GetPeerIdentityAddress(), + command_view.GetPeerIrk(), command_view.GetLocalIrk()); + send_event_(bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create(kNumCommandPackets, + status)); } void DualModeController::LeRemoveDeviceFromResolvingList(CommandView command) { - auto command_view = - bluetooth::hci::LeRemoveDeviceFromResolvingListView::Create(command); + auto command_view = bluetooth::hci::LeRemoveDeviceFromResolvingListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Device from Resolving List"); - DEBUG(id_, " peer_identity_address={}", - command_view.GetPeerIdentityAddress()); + DEBUG(id_, " peer_identity_address={}", command_view.GetPeerIdentityAddress()); DEBUG(id_, " peer_identity_address_type={}", - bluetooth::hci::PeerAddressTypeText( - command_view.GetPeerIdentityAddressType())); + bluetooth::hci::PeerAddressTypeText(command_view.GetPeerIdentityAddressType())); ErrorCode status = link_layer_controller_.LeRemoveDeviceFromResolvingList( - command_view.GetPeerIdentityAddressType(), - command_view.GetPeerIdentityAddress()); - send_event_( - bluetooth::hci::LeRemoveDeviceFromResolvingListCompleteBuilder::Create( + command_view.GetPeerIdentityAddressType(), command_view.GetPeerIdentityAddress()); + send_event_(bluetooth::hci::LeRemoveDeviceFromResolvingListCompleteBuilder::Create( kNumCommandPackets, status)); } -void DualModeController::LeSetPeriodicAdvertisingParameters( - CommandView command) { - auto command_view = - bluetooth::hci::LeSetPeriodicAdvertisingParametersView::Create(command); +void DualModeController::LeSetPeriodicAdvertisingParametersV1(CommandView command) { + auto command_view = bluetooth::hci::LeSetPeriodicAdvertisingParametersV1View::Create(command); CHECK_PACKET_VIEW(command_view); - DEBUG(id_, "<< LE Set Periodic Advertising Parameters"); + DEBUG(id_, "<< LE Set Periodic Advertising Parameters V1"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); ErrorCode status = link_layer_controller_.LeSetPeriodicAdvertisingParameters( - command_view.GetAdvertisingHandle(), - command_view.GetPeriodicAdvertisingIntervalMin(), - command_view.GetPeriodicAdvertisingIntervalMax(), - command_view.GetIncludeTxPower()); - send_event_( - bluetooth::hci::LeSetPeriodicAdvertisingParametersCompleteBuilder::Create( + command_view.GetAdvertisingHandle(), command_view.GetPeriodicAdvertisingIntervalMin(), + command_view.GetPeriodicAdvertisingIntervalMax(), command_view.GetIncludeTxPower()); + send_event_(bluetooth::hci::LeSetPeriodicAdvertisingParametersV1CompleteBuilder::Create( kNumCommandPackets, status)); } void DualModeController::LeSetPeriodicAdvertisingData(CommandView command) { - auto command_view = - bluetooth::hci::LeSetPeriodicAdvertisingDataView::Create(command); + auto command_view = bluetooth::hci::LeSetPeriodicAdvertisingDataView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Periodic Advertising Data"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); ErrorCode status = link_layer_controller_.LeSetPeriodicAdvertisingData( - command_view.GetAdvertisingHandle(), command_view.GetOperation(), - command_view.GetAdvertisingData()); - send_event_( - bluetooth::hci::LeSetPeriodicAdvertisingDataCompleteBuilder::Create( + command_view.GetAdvertisingHandle(), command_view.GetOperation(), + command_view.GetAdvertisingData()); + send_event_(bluetooth::hci::LeSetPeriodicAdvertisingDataCompleteBuilder::Create( kNumCommandPackets, status)); } void DualModeController::LeSetPeriodicAdvertisingEnable(CommandView command) { - auto command_view = - bluetooth::hci::LeSetPeriodicAdvertisingEnableView::Create(command); + auto command_view = bluetooth::hci::LeSetPeriodicAdvertisingEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Periodic Advertising Enable"); @@ -2522,179 +2336,143 @@ void DualModeController::LeSetPeriodicAdvertisingEnable(CommandView command) { DEBUG(id_, " enable={}", command_view.GetEnable() != 0); ErrorCode status = link_layer_controller_.LeSetPeriodicAdvertisingEnable( - command_view.GetEnable(), command_view.GetIncludeAdi(), - command_view.GetAdvertisingHandle()); - send_event_( - bluetooth::hci::LeSetPeriodicAdvertisingEnableCompleteBuilder::Create( + command_view.GetEnable(), command_view.GetIncludeAdi(), + command_view.GetAdvertisingHandle()); + send_event_(bluetooth::hci::LeSetPeriodicAdvertisingEnableCompleteBuilder::Create( kNumCommandPackets, status)); } void DualModeController::LePeriodicAdvertisingCreateSync(CommandView command) { - auto command_view = - bluetooth::hci::LePeriodicAdvertisingCreateSyncView::Create(command); + auto command_view = bluetooth::hci::LePeriodicAdvertisingCreateSyncView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Periodic Advertising Create Sync"); DEBUG(id_, " advertiser_address={}", command_view.GetAdvertiserAddress()); DEBUG(id_, " advertiser_address_type={}", - bluetooth::hci::AdvertiserAddressTypeText( - command_view.GetAdvertiserAddressType())); + bluetooth::hci::AdvertiserAddressTypeText(command_view.GetAdvertiserAddressType())); ErrorCode status = link_layer_controller_.LePeriodicAdvertisingCreateSync( - command_view.GetOptions(), command_view.GetAdvertisingSid(), - command_view.GetAdvertiserAddressType(), - command_view.GetAdvertiserAddress(), command_view.GetSkip(), - command_view.GetSyncTimeout(), command_view.GetSyncCteType()); - send_event_( - bluetooth::hci::LePeriodicAdvertisingCreateSyncStatusBuilder::Create( + command_view.GetOptions(), command_view.GetAdvertisingSid(), + command_view.GetAdvertiserAddressType(), command_view.GetAdvertiserAddress(), + command_view.GetSkip(), command_view.GetSyncTimeout(), command_view.GetSyncCteType()); + send_event_(bluetooth::hci::LePeriodicAdvertisingCreateSyncStatusBuilder::Create( status, kNumCommandPackets)); } -void DualModeController::LePeriodicAdvertisingCreateSyncCancel( - CommandView command) { - auto command_view = - bluetooth::hci::LePeriodicAdvertisingCreateSyncCancelView::Create( - command); +void DualModeController::LePeriodicAdvertisingCreateSyncCancel(CommandView command) { + auto command_view = bluetooth::hci::LePeriodicAdvertisingCreateSyncCancelView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Periodic Advertising Create Sync Cancel"); - ErrorCode status = - link_layer_controller_.LePeriodicAdvertisingCreateSyncCancel(); - send_event_( - bluetooth::hci::LePeriodicAdvertisingCreateSyncCancelCompleteBuilder:: - Create(kNumCommandPackets, status)); + ErrorCode status = link_layer_controller_.LePeriodicAdvertisingCreateSyncCancel(); + send_event_(bluetooth::hci::LePeriodicAdvertisingCreateSyncCancelCompleteBuilder::Create( + kNumCommandPackets, status)); } -void DualModeController::LePeriodicAdvertisingTerminateSync( - CommandView command) { - auto command_view = - bluetooth::hci::LePeriodicAdvertisingTerminateSyncView::Create(command); +void DualModeController::LePeriodicAdvertisingTerminateSync(CommandView command) { + auto command_view = bluetooth::hci::LePeriodicAdvertisingTerminateSyncView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Periodic Advertising Terminate Sync"); DEBUG(id_, " sync_handle=0x{:x}", command_view.GetSyncHandle()); - ErrorCode status = link_layer_controller_.LePeriodicAdvertisingTerminateSync( - command_view.GetSyncHandle()); - send_event_( - bluetooth::hci::LePeriodicAdvertisingTerminateSyncCompleteBuilder::Create( + ErrorCode status = + link_layer_controller_.LePeriodicAdvertisingTerminateSync(command_view.GetSyncHandle()); + send_event_(bluetooth::hci::LePeriodicAdvertisingTerminateSyncCompleteBuilder::Create( kNumCommandPackets, status)); } -void DualModeController::LeAddDeviceToPeriodicAdvertiserList( - CommandView command) { - auto command_view = - bluetooth::hci::LeAddDeviceToPeriodicAdvertiserListView::Create(command); +void DualModeController::LeAddDeviceToPeriodicAdvertiserList(CommandView command) { + auto command_view = bluetooth::hci::LeAddDeviceToPeriodicAdvertiserListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Add Device to Periodic Advertiser List"); DEBUG(id_, " advertiser_address={}", command_view.GetAdvertiserAddress()); DEBUG(id_, " advertiser_address_type={}", - bluetooth::hci::AdvertiserAddressTypeText( - command_view.GetAdvertiserAddressType())); + bluetooth::hci::AdvertiserAddressTypeText(command_view.GetAdvertiserAddressType())); ErrorCode status = link_layer_controller_.LeAddDeviceToPeriodicAdvertiserList( - command_view.GetAdvertiserAddressType(), - command_view.GetAdvertiserAddress(), command_view.GetAdvertisingSid()); - send_event_( - bluetooth::hci::LeAddDeviceToPeriodicAdvertiserListCompleteBuilder:: - Create(kNumCommandPackets, status)); + command_view.GetAdvertiserAddressType(), command_view.GetAdvertiserAddress(), + command_view.GetAdvertisingSid()); + send_event_(bluetooth::hci::LeAddDeviceToPeriodicAdvertiserListCompleteBuilder::Create( + kNumCommandPackets, status)); } -void DualModeController::LeRemoveDeviceFromPeriodicAdvertiserList( - CommandView command) { - auto command_view = - bluetooth::hci::LeRemoveDeviceFromPeriodicAdvertiserListView::Create( - command); +void DualModeController::LeRemoveDeviceFromPeriodicAdvertiserList(CommandView command) { + auto command_view = bluetooth::hci::LeRemoveDeviceFromPeriodicAdvertiserListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Device from Periodic Advertiser List"); DEBUG(id_, " advertiser_address={}", command_view.GetAdvertiserAddress()); DEBUG(id_, " advertiser_address_type={}", - bluetooth::hci::AdvertiserAddressTypeText( - command_view.GetAdvertiserAddressType())); + bluetooth::hci::AdvertiserAddressTypeText(command_view.GetAdvertiserAddressType())); - ErrorCode status = - link_layer_controller_.LeRemoveDeviceFromPeriodicAdvertiserList( - command_view.GetAdvertiserAddressType(), - command_view.GetAdvertiserAddress(), + ErrorCode status = link_layer_controller_.LeRemoveDeviceFromPeriodicAdvertiserList( + command_view.GetAdvertiserAddressType(), command_view.GetAdvertiserAddress(), command_view.GetAdvertisingSid()); - send_event_( - bluetooth::hci::LeRemoveDeviceFromPeriodicAdvertiserListCompleteBuilder:: - Create(kNumCommandPackets, status)); + send_event_(bluetooth::hci::LeRemoveDeviceFromPeriodicAdvertiserListCompleteBuilder::Create( + kNumCommandPackets, status)); } void DualModeController::LeClearPeriodicAdvertiserList(CommandView command) { - auto command_view = - bluetooth::hci::LeClearPeriodicAdvertiserListView::Create(command); + auto command_view = bluetooth::hci::LeClearPeriodicAdvertiserListView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Clear Periodic Advertiser List"); ErrorCode status = link_layer_controller_.LeClearPeriodicAdvertiserList(); - send_event_( - bluetooth::hci::LeClearPeriodicAdvertiserListCompleteBuilder::Create( + send_event_(bluetooth::hci::LeClearPeriodicAdvertiserListCompleteBuilder::Create( kNumCommandPackets, status)); } void DualModeController::LeReadPeriodicAdvertiserListSize(CommandView command) { - auto command_view = - bluetooth::hci::LeReadPeriodicAdvertiserListSizeView::Create(command); + auto command_view = bluetooth::hci::LeReadPeriodicAdvertiserListSizeView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Periodic Advertiser List Size"); - send_event_( - bluetooth::hci::LeReadPeriodicAdvertiserListSizeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - properties_.le_periodic_advertiser_list_size)); + send_event_(bluetooth::hci::LeReadPeriodicAdvertiserListSizeCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS, properties_.le_periodic_advertiser_list_size)); } void DualModeController::LeSetExtendedScanParameters(CommandView command) { - auto command_view = - bluetooth::hci::LeSetExtendedScanParametersView::Create(command); + auto command_view = bluetooth::hci::LeSetExtendedScanParametersView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Scan Parameters"); ErrorCode status = link_layer_controller_.LeSetExtendedScanParameters( - command_view.GetOwnAddressType(), command_view.GetScanningFilterPolicy(), - command_view.GetScanningPhys(), command_view.GetScanningPhyParameters()); - send_event_( - bluetooth::hci::LeSetExtendedScanParametersCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetOwnAddressType(), command_view.GetScanningFilterPolicy(), + command_view.GetScanningPhys(), command_view.GetScanningPhyParameters()); + send_event_(bluetooth::hci::LeSetExtendedScanParametersCompleteBuilder::Create(kNumCommandPackets, + status)); } void DualModeController::LeSetExtendedScanEnable(CommandView command) { - auto command_view = - bluetooth::hci::LeSetExtendedScanEnableView::Create(command); + auto command_view = bluetooth::hci::LeSetExtendedScanEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Scan Enable"); - DEBUG(id_, " enable={}", - command_view.GetEnable() == bluetooth::hci::Enable::ENABLED); + DEBUG(id_, " enable={}", command_view.GetEnable() == bluetooth::hci::Enable::ENABLED); ErrorCode status = link_layer_controller_.LeSetExtendedScanEnable( - command_view.GetEnable() == bluetooth::hci::Enable::ENABLED, - command_view.GetFilterDuplicates(), command_view.GetDuration(), - command_view.GetPeriod()); - send_event_(bluetooth::hci::LeSetExtendedScanEnableCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetEnable() == bluetooth::hci::Enable::ENABLED, + command_view.GetFilterDuplicates(), command_view.GetDuration(), command_view.GetPeriod()); + send_event_(bluetooth::hci::LeSetExtendedScanEnableCompleteBuilder::Create(kNumCommandPackets, + status)); } -void DualModeController::LeExtendedCreateConnection(CommandView command) { - auto command_view = - bluetooth::hci::LeExtendedCreateConnectionView::Create(command); +void DualModeController::LeExtendedCreateConnectionV1(CommandView command) { + auto command_view = bluetooth::hci::LeExtendedCreateConnectionV1View::Create(command); CHECK_PACKET_VIEW(command_view); - DEBUG(id_, "<< LE Extended Create Connection"); + DEBUG(id_, "<< LE Extended Create Connection V1"); DEBUG(id_, " peer_address={}", command_view.GetPeerAddress()); DEBUG(id_, " peer_address_type={}", bluetooth::hci::PeerAddressTypeText(command_view.GetPeerAddressType())); DEBUG(id_, " initiator_filter_policy={}", - bluetooth::hci::InitiatorFilterPolicyText( - command_view.GetInitiatorFilterPolicy())); + bluetooth::hci::InitiatorFilterPolicyText(command_view.GetInitiatorFilterPolicy())); AddressType peer_address_type; switch (command_view.GetPeerAddressType()) { @@ -2708,15 +2486,14 @@ void DualModeController::LeExtendedCreateConnection(CommandView command) { } ErrorCode status = link_layer_controller_.LeExtendedCreateConnection( - command_view.GetInitiatorFilterPolicy(), command_view.GetOwnAddressType(), - AddressWithType{ - command_view.GetPeerAddress(), - peer_address_type, - }, - command_view.GetInitiatingPhys(), - command_view.GetInitiatingPhyParameters()); - send_event_(bluetooth::hci::LeExtendedCreateConnectionStatusBuilder::Create( - status, kNumCommandPackets)); + command_view.GetInitiatorFilterPolicy(), command_view.GetOwnAddressType(), + AddressWithType{ + command_view.GetPeerAddress(), + peer_address_type, + }, + command_view.GetInitiatingPhys(), command_view.GetInitiatingPhyParameters()); + send_event_(bluetooth::hci::LeExtendedCreateConnectionV1StatusBuilder::Create( + status, kNumCommandPackets)); } void DualModeController::LeSetPrivacyMode(CommandView command) { @@ -2724,34 +2501,30 @@ void DualModeController::LeSetPrivacyMode(CommandView command) { CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Privacy Mode"); - DEBUG(id_, " peer_identity_address={}", - command_view.GetPeerIdentityAddress()); + DEBUG(id_, " peer_identity_address={}", command_view.GetPeerIdentityAddress()); DEBUG(id_, " peer_identity_address_type={}", - bluetooth::hci::PeerAddressTypeText( - command_view.GetPeerIdentityAddressType())); - DEBUG(id_, " privacy_mode={}", - bluetooth::hci::PrivacyModeText(command_view.GetPrivacyMode())); + bluetooth::hci::PeerAddressTypeText(command_view.GetPeerIdentityAddressType())); + DEBUG(id_, " privacy_mode={}", bluetooth::hci::PrivacyModeText(command_view.GetPrivacyMode())); ErrorCode status = link_layer_controller_.LeSetPrivacyMode( - command_view.GetPeerIdentityAddressType(), - command_view.GetPeerIdentityAddress(), command_view.GetPrivacyMode()); - send_event_(bluetooth::hci::LeSetPrivacyModeCompleteBuilder::Create( - kNumCommandPackets, status)); + command_view.GetPeerIdentityAddressType(), command_view.GetPeerIdentityAddress(), + command_view.GetPrivacyMode()); + send_event_(bluetooth::hci::LeSetPrivacyModeCompleteBuilder::Create(kNumCommandPackets, status)); } -void DualModeController::LeReadRemoteFeatures(CommandView command) { - auto command_view = bluetooth::hci::LeReadRemoteFeaturesView::Create(command); +void DualModeController::LeReadRemoteFeaturesPage0(CommandView command) { + auto command_view = bluetooth::hci::LeReadRemoteFeaturesPage0View::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); - DEBUG(id_, "<< LE Read Remote Features"); + DEBUG(id_, "<< LE Read Remote Features Page 0"); DEBUG(id_, " connection_handle=0x{:x}", handle); auto status = link_layer_controller_.SendCommandToRemoteByHandle( - OpCode::LE_READ_REMOTE_FEATURES, command_view.bytes(), handle); + OpCode::LE_READ_REMOTE_FEATURES_PAGE_0, command_view.bytes(), handle); - send_event_(bluetooth::hci::LeReadRemoteFeaturesStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::LeReadRemoteFeaturesPage0StatusBuilder::Create(status, + kNumCommandPackets)); } void DualModeController::LeEncrypt(CommandView command) { @@ -2760,11 +2533,11 @@ void DualModeController::LeEncrypt(CommandView command) { DEBUG(id_, "<< LE Encrypt"); - auto encrypted_data = rootcanal::crypto::aes_128( - command_view.GetKey(), command_view.GetPlaintextData()); + auto encrypted_data = + rootcanal::crypto::aes_128(command_view.GetKey(), command_view.GetPlaintextData()); - send_event_(bluetooth::hci::LeEncryptCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, encrypted_data)); + send_event_(bluetooth::hci::LeEncryptCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS, encrypted_data)); } void DualModeController::LeRand(CommandView command) { @@ -2773,64 +2546,52 @@ void DualModeController::LeRand(CommandView command) { DEBUG(id_, "<< LE Rand"); - send_event_(bluetooth::hci::LeRandCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, random_generator_())); + send_event_(bluetooth::hci::LeRandCompleteBuilder::Create(kNumCommandPackets, ErrorCode::SUCCESS, + random_generator_())); } void DualModeController::LeReadSupportedStates(CommandView command) { - auto command_view = - bluetooth::hci::LeReadSupportedStatesView::Create(command); + auto command_view = bluetooth::hci::LeReadSupportedStatesView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Supported States"); send_event_(bluetooth::hci::LeReadSupportedStatesCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, properties_.le_supported_states)); + kNumCommandPackets, ErrorCode::SUCCESS, properties_.le_supported_states)); } -void DualModeController::LeRemoteConnectionParameterRequestReply( - CommandView command) { - auto command_view = - bluetooth::hci::LeRemoteConnectionParameterRequestReplyView::Create( - command); +void DualModeController::LeRemoteConnectionParameterRequestReply(CommandView command) { + auto command_view = bluetooth::hci::LeRemoteConnectionParameterRequestReplyView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remote Connection Parameters Request Reply"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); auto status = link_layer_controller_.LeRemoteConnectionParameterRequestReply( - command_view.GetConnectionHandle(), command_view.GetIntervalMin(), - command_view.GetIntervalMax(), command_view.GetTimeout(), - command_view.GetLatency(), command_view.GetMinimumCeLength(), - command_view.GetMaximumCeLength()); - send_event_( - bluetooth::hci::LeRemoteConnectionParameterRequestReplyCompleteBuilder:: - Create(kNumCommandPackets, status, - command_view.GetConnectionHandle())); + command_view.GetConnectionHandle(), command_view.GetIntervalMin(), + command_view.GetIntervalMax(), command_view.GetTimeout(), command_view.GetLatency(), + command_view.GetMinimumCeLength(), command_view.GetMaximumCeLength()); + send_event_(bluetooth::hci::LeRemoteConnectionParameterRequestReplyCompleteBuilder::Create( + kNumCommandPackets, status, command_view.GetConnectionHandle())); } -void DualModeController::LeRemoteConnectionParameterRequestNegativeReply( - CommandView command) { - auto command_view = bluetooth::hci:: - LeRemoteConnectionParameterRequestNegativeReplyView::Create(command); +void DualModeController::LeRemoteConnectionParameterRequestNegativeReply(CommandView command) { + auto command_view = + bluetooth::hci::LeRemoteConnectionParameterRequestNegativeReplyView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remote Connection Parameters Request Negative Reply"); DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); - auto status = - link_layer_controller_.LeRemoteConnectionParameterRequestNegativeReply( + auto status = link_layer_controller_.LeRemoteConnectionParameterRequestNegativeReply( command_view.GetConnectionHandle(), command_view.GetReason()); send_event_( - bluetooth::hci:: - LeRemoteConnectionParameterRequestNegativeReplyCompleteBuilder:: - Create(kNumCommandPackets, status, - command_view.GetConnectionHandle())); + bluetooth::hci::LeRemoteConnectionParameterRequestNegativeReplyCompleteBuilder::Create( + kNumCommandPackets, status, command_view.GetConnectionHandle())); } void DualModeController::LeGetVendorCapabilities(CommandView command) { - auto command_view = - bluetooth::hci::LeGetVendorCapabilitiesView::Create(command); + auto command_view = bluetooth::hci::LeGetVendorCapabilitiesView::Create(command); CHECK_PACKET_VIEW(command_view); if (!properties_.supports_le_get_vendor_capabilities_command) { @@ -2843,20 +2604,17 @@ void DualModeController::LeGetVendorCapabilities(CommandView command) { bluetooth::hci::VendorCapabilities_V_0_98 vendor_capabilities; vendor_capabilities.total_scan_results_storage_ = 0; vendor_capabilities.max_irk_list_sz_ = 16; - vendor_capabilities.filtering_support_ = - properties_.supports_le_apcf_vendor_command; + vendor_capabilities.filtering_support_ = properties_.supports_le_apcf_vendor_command; vendor_capabilities.max_filter_ = properties_.le_apcf_filter_list_size; vendor_capabilities.activity_energy_info_support_ = 0; - vendor_capabilities.total_num_of_advt_tracked_ = - properties_.le_apcf_num_of_tracked_advertisers; + vendor_capabilities.total_num_of_advt_tracked_ = properties_.le_apcf_num_of_tracked_advertisers; vendor_capabilities.extended_scan_support_ = 0; vendor_capabilities.debug_logging_supported_ = 0; vendor_capabilities.a2dp_source_offload_capability_mask_ = 0; vendor_capabilities.bluetooth_quality_report_support_ = 0; send_event_(bluetooth::hci::LeGetVendorCapabilitiesCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - vendor_capabilities.SerializeToBytes())); + kNumCommandPackets, ErrorCode::SUCCESS, vendor_capabilities.SerializeToBytes())); } void DualModeController::LeBatchScan(CommandView command) { @@ -2876,29 +2634,24 @@ void DualModeController::LeApcf(CommandView command) { switch (command_view.GetApcfOpcode()) { case bluetooth::hci::ApcfOpcode::ENABLE: { - auto subcommand_view = - bluetooth::hci::LeApcfEnableView::Create(command_view); + auto subcommand_view = bluetooth::hci::LeApcfEnableView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Enable"); - DEBUG(id_, " enable={}", - bluetooth::hci::EnableText(subcommand_view.GetApcfEnable())); + DEBUG(id_, " enable={}", bluetooth::hci::EnableText(subcommand_view.GetApcfEnable())); - ErrorCode status = link_layer_controller_.LeApcfEnable( - subcommand_view.GetApcfEnable() == bluetooth::hci::Enable::ENABLED); + ErrorCode status = link_layer_controller_.LeApcfEnable(subcommand_view.GetApcfEnable() == + bluetooth::hci::Enable::ENABLED); send_event_(bluetooth::hci::LeApcfEnableCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfEnable())); + kNumCommandPackets, status, subcommand_view.GetApcfEnable())); break; } case bluetooth::hci::ApcfOpcode::SET_FILTERING_PARAMETERS: { - auto subcommand_view = - bluetooth::hci::LeApcfSetFilteringParametersView::Create( - command_view); + auto subcommand_view = bluetooth::hci::LeApcfSetFilteringParametersView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Set Filtering Parameters"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); ErrorCode status = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; uint8_t apcf_available_spaces = 0; @@ -2906,40 +2659,32 @@ void DualModeController::LeApcf(CommandView command) { switch (subcommand_view.GetApcfAction()) { case bluetooth::hci::ApcfAction::ADD: { auto subsubcommand_view = - bluetooth::hci::LeApcfAddFilteringParametersView::Create( - subcommand_view); + bluetooth::hci::LeApcfAddFilteringParametersView::Create(subcommand_view); CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfAddFilteringParameters( - subsubcommand_view.GetApcfFilterIndex(), - subsubcommand_view.GetApcfFeatureSelection(), - subsubcommand_view.GetApcfListLogicType(), - subsubcommand_view.GetApcfFilterLogicType(), - subsubcommand_view.GetRssiHighThresh(), - subsubcommand_view.GetDeliveryMode(), - subsubcommand_view.GetOnfoundTimeout(), - subsubcommand_view.GetOnfoundTimeoutCnt(), - subsubcommand_view.GetRssiLowThresh(), - subsubcommand_view.GetOnlostTimeout(), - subsubcommand_view.GetNumOfTrackingEntries(), - &apcf_available_spaces); + subsubcommand_view.GetApcfFilterIndex(), + subsubcommand_view.GetApcfFeatureSelection(), + subsubcommand_view.GetApcfListLogicType(), + subsubcommand_view.GetApcfFilterLogicType(), + subsubcommand_view.GetRssiHighThresh(), subsubcommand_view.GetDeliveryMode(), + subsubcommand_view.GetOnfoundTimeout(), subsubcommand_view.GetOnfoundTimeoutCnt(), + subsubcommand_view.GetRssiLowThresh(), subsubcommand_view.GetOnlostTimeout(), + subsubcommand_view.GetNumOfTrackingEntries(), &apcf_available_spaces); break; } case bluetooth::hci::ApcfAction::DELETE: { auto subsubcommand_view = - bluetooth::hci::LeApcfDeleteFilteringParametersView::Create( - subcommand_view); + bluetooth::hci::LeApcfDeleteFilteringParametersView::Create(subcommand_view); CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfDeleteFilteringParameters( - subsubcommand_view.GetApcfFilterIndex(), &apcf_available_spaces); + subsubcommand_view.GetApcfFilterIndex(), &apcf_available_spaces); break; } case bluetooth::hci::ApcfAction::CLEAR: { auto subsubcommand_view = - bluetooth::hci::LeApcfClearFilteringParametersView::Create( - subcommand_view); + bluetooth::hci::LeApcfClearFilteringParametersView::Create(subcommand_view); CHECK_PACKET_VIEW(subcommand_view); - status = link_layer_controller_.LeApcfClearFilteringParameters( - &apcf_available_spaces); + status = link_layer_controller_.LeApcfClearFilteringParameters(&apcf_available_spaces); break; } default: @@ -2948,20 +2693,16 @@ void DualModeController::LeApcf(CommandView command) { break; } - send_event_( - bluetooth::hci::LeApcfSetFilteringParametersCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + send_event_(bluetooth::hci::LeApcfSetFilteringParametersCompleteBuilder::Create( + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } case bluetooth::hci::ApcfOpcode::BROADCASTER_ADDRESS: { - auto subcommand_view = - bluetooth::hci::LeApcfBroadcasterAddressView::Create(command_view); + auto subcommand_view = bluetooth::hci::LeApcfBroadcasterAddressView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Broadcaster Address"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); ErrorCode status = ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; uint8_t apcf_available_spaces = 0; @@ -2969,40 +2710,32 @@ void DualModeController::LeApcf(CommandView command) { switch (subcommand_view.GetApcfAction()) { case bluetooth::hci::ApcfAction::ADD: { auto subsubcommand_view = - bluetooth::hci::LeApcfAddBroadcasterAddressView::Create( - subcommand_view); + bluetooth::hci::LeApcfAddBroadcasterAddressView::Create(subcommand_view); CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfBroadcasterAddress( - bluetooth::hci::ApcfAction::ADD, - subsubcommand_view.GetApcfFilterIndex(), - subsubcommand_view.GetApcfBroadcasterAddress(), - subsubcommand_view.GetApcfApplicationAddressType(), - &apcf_available_spaces); + bluetooth::hci::ApcfAction::ADD, subsubcommand_view.GetApcfFilterIndex(), + subsubcommand_view.GetApcfBroadcasterAddress(), + subsubcommand_view.GetApcfApplicationAddressType(), &apcf_available_spaces); break; } case bluetooth::hci::ApcfAction::DELETE: { auto subsubcommand_view = - bluetooth::hci::LeApcfDeleteBroadcasterAddressView::Create( - subcommand_view); + bluetooth::hci::LeApcfDeleteBroadcasterAddressView::Create(subcommand_view); CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfBroadcasterAddress( - bluetooth::hci::ApcfAction::DELETE, - subsubcommand_view.GetApcfFilterIndex(), - subsubcommand_view.GetApcfBroadcasterAddress(), - subsubcommand_view.GetApcfApplicationAddressType(), - &apcf_available_spaces); + bluetooth::hci::ApcfAction::DELETE, subsubcommand_view.GetApcfFilterIndex(), + subsubcommand_view.GetApcfBroadcasterAddress(), + subsubcommand_view.GetApcfApplicationAddressType(), &apcf_available_spaces); break; } case bluetooth::hci::ApcfAction::CLEAR: { auto subsubcommand_view = - bluetooth::hci::LeApcfClearBroadcasterAddressView::Create( - subcommand_view); + bluetooth::hci::LeApcfClearBroadcasterAddressView::Create(subcommand_view); CHECK_PACKET_VIEW(subcommand_view); status = link_layer_controller_.LeApcfBroadcasterAddress( - bluetooth::hci::ApcfAction::CLEAR, - subsubcommand_view.GetApcfFilterIndex(), Address(), - bluetooth::hci::ApcfApplicationAddressType::NOT_APPLICABLE, - &apcf_available_spaces); + bluetooth::hci::ApcfAction::CLEAR, subsubcommand_view.GetApcfFilterIndex(), + Address(), bluetooth::hci::ApcfApplicationAddressType::NOT_APPLICABLE, + &apcf_available_spaces); break; } default: @@ -3011,178 +2744,160 @@ void DualModeController::LeApcf(CommandView command) { break; } - send_event_( - bluetooth::hci::LeApcfBroadcasterAddressCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + send_event_(bluetooth::hci::LeApcfBroadcasterAddressCompleteBuilder::Create( + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } case bluetooth::hci::ApcfOpcode::SERVICE_UUID: { - auto subcommand_view = - bluetooth::hci::LeApcfServiceUuidView::Create(command_view); + auto subcommand_view = bluetooth::hci::LeApcfServiceUuidView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Service UUID"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); uint8_t apcf_available_spaces = 0; ErrorCode status = link_layer_controller_.LeApcfServiceUuid( - subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), - subcommand_view.GetAcpfUuidData(), &apcf_available_spaces); + subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), + subcommand_view.GetAcpfUuidData(), &apcf_available_spaces); send_event_(bluetooth::hci::LeApcfServiceUuidCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } case bluetooth::hci::ApcfOpcode::SERVICE_SOLICITATION_UUID: { auto subcommand_view = - bluetooth::hci::LeApcfServiceSolicitationUuidView::Create( - command_view); + bluetooth::hci::LeApcfServiceSolicitationUuidView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Service Solicitation UUID"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); uint8_t apcf_available_spaces = 0; ErrorCode status = link_layer_controller_.LeApcfServiceSolicitationUuid( - subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), - subcommand_view.GetAcpfUuidData(), &apcf_available_spaces); - send_event_( - bluetooth::hci::LeApcfServiceSolicitationUuidCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), + subcommand_view.GetAcpfUuidData(), &apcf_available_spaces); + send_event_(bluetooth::hci::LeApcfServiceSolicitationUuidCompleteBuilder::Create( + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } case bluetooth::hci::ApcfOpcode::LOCAL_NAME: { - auto subcommand_view = - bluetooth::hci::LeApcfLocalNameView::Create(command_view); + auto subcommand_view = bluetooth::hci::LeApcfLocalNameView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Local Name"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); uint8_t apcf_available_spaces = 0; ErrorCode status = link_layer_controller_.LeApcfLocalName( - subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), - subcommand_view.GetApcfLocalName(), &apcf_available_spaces); + subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), + subcommand_view.GetApcfLocalName(), &apcf_available_spaces); send_event_(bluetooth::hci::LeApcfLocalNameCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } case bluetooth::hci::ApcfOpcode::MANUFACTURER_DATA: { - auto subcommand_view = - bluetooth::hci::LeApcfManufacturerDataView::Create(command_view); + auto subcommand_view = bluetooth::hci::LeApcfManufacturerDataView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Manufacturer Data"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); uint8_t apcf_available_spaces = 0; ErrorCode status = link_layer_controller_.LeApcfManufacturerData( - subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), - subcommand_view.GetApcfManufacturerData(), &apcf_available_spaces); + subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), + subcommand_view.GetApcfManufacturerData(), &apcf_available_spaces); send_event_(bluetooth::hci::LeApcfManufacturerDataCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } case bluetooth::hci::ApcfOpcode::SERVICE_DATA: { - auto subcommand_view = - bluetooth::hci::LeApcfServiceDataView::Create(command_view); + auto subcommand_view = bluetooth::hci::LeApcfServiceDataView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Service Data"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); uint8_t apcf_available_spaces = 0; ErrorCode status = link_layer_controller_.LeApcfServiceData( - subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), - subcommand_view.GetApcfServiceData(), &apcf_available_spaces); + subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), + subcommand_view.GetApcfServiceData(), &apcf_available_spaces); send_event_(bluetooth::hci::LeApcfServiceDataCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } - case bluetooth::hci::ApcfOpcode::AD_TYPE_FILTER: { + case bluetooth::hci::ApcfOpcode::TRANSPORT_DISCOVERY_SERVICE: { auto subcommand_view = - bluetooth::hci::LeApcfAdTypeFilterView::Create(command_view); + bluetooth::hci::LeApcfTransportDiscoveryServiceView::Create(command_view); + CHECK_PACKET_VIEW(subcommand_view); + + DEBUG(id_, "<< LE APCF Transport Discovery Service"); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + + send_event_(bluetooth::hci::LeApcfTransportDiscoveryServiceCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::INVALID_HCI_COMMAND_PARAMETERS, + subcommand_view.GetApcfAction(), 0)); + break; + } + case bluetooth::hci::ApcfOpcode::AD_TYPE_FILTER: { + auto subcommand_view = bluetooth::hci::LeApcfAdTypeFilterView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF AD Type Filter"); - DEBUG(id_, " action={}", - bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); + DEBUG(id_, " action={}", bluetooth::hci::ApcfActionText(subcommand_view.GetApcfAction())); uint8_t apcf_available_spaces = 0; ErrorCode status = link_layer_controller_.LeApcfAdTypeFilter( - subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), - subcommand_view.GetApcfAdType(), subcommand_view.GetApcfAdData(), - subcommand_view.GetApcfAdDataMask(), &apcf_available_spaces); + subcommand_view.GetApcfAction(), subcommand_view.GetApcfFilterIndex(), + subcommand_view.GetApcfAdType(), subcommand_view.GetApcfAdData(), + subcommand_view.GetApcfAdDataMask(), &apcf_available_spaces); send_event_(bluetooth::hci::LeApcfAdTypeFilterCompleteBuilder::Create( - kNumCommandPackets, status, subcommand_view.GetApcfAction(), - apcf_available_spaces)); + kNumCommandPackets, status, subcommand_view.GetApcfAction(), apcf_available_spaces)); break; } case bluetooth::hci::ApcfOpcode::READ_EXTENDED_FEATURES: { - auto subcommand_view = - bluetooth::hci::LeApcfReadExtendedFeaturesView::Create(command_view); + auto subcommand_view = bluetooth::hci::LeApcfReadExtendedFeaturesView::Create(command_view); CHECK_PACKET_VIEW(subcommand_view); DEBUG(id_, "<< LE APCF Read Extended Features"); - send_event_( - bluetooth::hci::LeApcfReadExtendedFeaturesCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - kLeApcfTransportDiscoveryDataFilterSupported, + send_event_(bluetooth::hci::LeApcfReadExtendedFeaturesCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS, kLeApcfTransportDiscoveryDataFilterSupported, kLeApcfAdTypeFilterSupported)); break; } default: - ERROR(id_, "unknown APCF opcode {:#x}", - static_cast(command_view.GetApcfOpcode())); + ERROR(id_, "unknown APCF opcode {:#x}", static_cast(command_view.GetApcfOpcode())); send_event_(bluetooth::hci::LeApcfCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::INVALID_HCI_COMMAND_PARAMETERS, - command_view.GetApcfOpcode(), std::vector{})); - - invalid_packet_handler_( - id_, InvalidPacketReason::kUnsupported, - fmt::format("unsupported APCF opcode {:#x}", - static_cast(command_view.GetApcfOpcode())), - command_view.bytes().bytes()); + kNumCommandPackets, ErrorCode::INVALID_HCI_COMMAND_PARAMETERS, + command_view.GetApcfOpcode(), std::vector{})); + + invalid_packet_handler_(id_, InvalidPacketReason::kUnsupported, + fmt::format("unsupported APCF opcode {:#x}", + static_cast(command_view.GetApcfOpcode())), + command_view.bytes().bytes()); } } -void DualModeController::LeGetControllerActivityEnergyInfo( - CommandView command) { - auto command_view = - bluetooth::hci::LeGetControllerActivityEnergyInfoView::Create(command); +void DualModeController::LeGetControllerActivityEnergyInfo(CommandView command) { + auto command_view = bluetooth::hci::LeGetControllerActivityEnergyInfoView::Create(command); CHECK_PACKET_VIEW(command_view); - SendCommandCompleteUnknownOpCodeEvent( - OpCode::LE_GET_CONTROLLER_ACTIVITY_ENERGY_INFO); + SendCommandCompleteUnknownOpCodeEvent(OpCode::LE_GET_CONTROLLER_ACTIVITY_ENERGY_INFO); } void DualModeController::LeExSetScanParameters(CommandView command) { - auto command_view = - bluetooth::hci::LeExSetScanParametersView::Create(command); + auto command_view = bluetooth::hci::LeExSetScanParametersView::Create(command); CHECK_PACKET_VIEW(command_view); SendCommandCompleteUnknownOpCodeEvent(OpCode::LE_EX_SET_SCAN_PARAMETERS); } void DualModeController::GetControllerDebugInfo(CommandView command) { - auto command_view = - bluetooth::hci::GetControllerDebugInfoView::Create(command); + auto command_view = bluetooth::hci::GetControllerDebugInfoView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Get Controller Debug Info"); - send_event_(bluetooth::hci::GetControllerDebugInfoCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::GetControllerDebugInfoCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } // CSR vendor command. @@ -3235,10 +2950,9 @@ void DualModeController::CsrVendorCommand(CommandView command) { varid = (uint16_t)parameters[7] | ((uint16_t)parameters[8] << 8); length = 2 * (length - 5); - if (parameters.size() < (11 + length) || - (varid == CsrVarid::CSR_VARID_PS && length < 6)) { - INFO(id_, "Invalid CSR vendor command parameter length {}, expected {}", - parameters.size(), 11 + length); + if (parameters.size() < (11 + length) || (varid == CsrVarid::CSR_VARID_PS && length < 6)) { + INFO(id_, "Invalid CSR vendor command parameter length {}, expected {}", parameters.size(), + 11 + length); goto complete; } @@ -3246,21 +2960,18 @@ void DualModeController::CsrVendorCommand(CommandView command) { // Subcommand to read or write PSKEY of the selected identifier // instead of VARID. uint16_t pskey = (uint16_t)parameters[11] | ((uint16_t)parameters[12] << 8); - uint16_t length = - (uint16_t)parameters[13] | ((uint16_t)parameters[14] << 8); + uint16_t length = (uint16_t)parameters[13] | ((uint16_t)parameters[14] << 8); length = 2 * length; if (parameters.size() < (17 + length)) { - INFO(id_, "Invalid CSR vendor command parameter length {}, expected {}", - parameters.size(), 17 + length); + INFO(id_, "Invalid CSR vendor command parameter length {}, expected {}", parameters.size(), + 17 + length); goto complete; } - std::vector value(parameters.begin() + 17, - parameters.begin() + 17 + length); + std::vector value(parameters.begin() + 17, parameters.begin() + 17 + length); - INFO(id_, "CSR vendor command type={:04x} length={:04x} pskey={:04x}", type, - length, pskey); + INFO(id_, "CSR vendor command type={:04x} length={:04x} pskey={:04x}", type, length, pskey); if (type == 0) { CsrReadPskey(static_cast(pskey), value); @@ -3271,11 +2982,9 @@ void DualModeController::CsrVendorCommand(CommandView command) { } else { // Subcommand to read or write VARID of the selected identifier. - std::vector value(parameters.begin() + 11, - parameters.begin() + 11 + length); + std::vector value(parameters.begin() + 11, parameters.begin() + 11 + length); - INFO(id_, "CSR vendor command type={:04x} length={:04x} varid={:04x}", type, - length, varid); + INFO(id_, "CSR vendor command type={:04x} length={:04x} varid={:04x}", type, length, varid); if (type == 0) { CsrReadVarid(static_cast(varid), value); @@ -3289,12 +2998,11 @@ void DualModeController::CsrVendorCommand(CommandView command) { // Overwrite the command type. parameters[1] = 0x1; parameters[2] = 0x0; - send_event_(bluetooth::hci::EventBuilder::Create( - bluetooth::hci::EventCode::VENDOR_SPECIFIC, std::move(parameters))); + send_event_(bluetooth::hci::EventBuilder::Create(bluetooth::hci::EventCode::VENDOR_SPECIFIC, + std::move(parameters))); } -void DualModeController::CsrReadVarid(CsrVarid varid, - std::vector& value) const { +void DualModeController::CsrReadVarid(CsrVarid varid, std::vector& value) const { switch (varid) { case CsrVarid::CSR_VARID_BUILDID: // Return the extact Build ID returned by the official PTS dongle. @@ -3304,20 +3012,17 @@ void DualModeController::CsrReadVarid(CsrVarid varid, break; default: - INFO(id_, "Unsupported read of CSR varid 0x{:04x}", - static_cast(varid)); + INFO(id_, "Unsupported read of CSR varid 0x{:04x}", static_cast(varid)); break; } } -void DualModeController::CsrWriteVarid( - CsrVarid varid, std::vector const& /*value*/) const { - INFO(id_, "Unsupported write of CSR varid 0x{:04x}", - static_cast(varid)); +void DualModeController::CsrWriteVarid(CsrVarid varid, + std::vector const& /*value*/) const { + INFO(id_, "Unsupported write of CSR varid 0x{:04x}", static_cast(varid)); } -void DualModeController::CsrReadPskey(CsrPskey pskey, - std::vector& value) const { +void DualModeController::CsrReadPskey(CsrPskey pskey, std::vector& value) const { switch (pskey) { case CsrPskey::CSR_PSKEY_ENC_KEY_LMIN: ASSERT(!value.empty()); @@ -3337,35 +3042,30 @@ void DualModeController::CsrReadPskey(CsrPskey pskey, break; default: - INFO(id_, "Unsupported read of CSR pskey 0x{:04x}", - static_cast(pskey)); + INFO(id_, "Unsupported read of CSR pskey 0x{:04x}", static_cast(pskey)); break; } } -void DualModeController::CsrWritePskey(CsrPskey pskey, - std::vector const& value) { +void DualModeController::CsrWritePskey(CsrPskey pskey, std::vector const& value) { switch (pskey) { case CsrPskey::CSR_PSKEY_LOCAL_SUPPORTED_FEATURES: ASSERT(value.size() >= 8); INFO(id_, "CSR Vendor updating the Local Supported Features"); - properties_.lmp_features[0] = - ((uint64_t)value[0] << 0) | ((uint64_t)value[1] << 8) | - ((uint64_t)value[2] << 16) | ((uint64_t)value[3] << 24) | - ((uint64_t)value[4] << 32) | ((uint64_t)value[5] << 40) | - ((uint64_t)value[6] << 48) | ((uint64_t)value[7] << 56); + properties_.lmp_features[0] = ((uint64_t)value[0] << 0) | ((uint64_t)value[1] << 8) | + ((uint64_t)value[2] << 16) | ((uint64_t)value[3] << 24) | + ((uint64_t)value[4] << 32) | ((uint64_t)value[5] << 40) | + ((uint64_t)value[6] << 48) | ((uint64_t)value[7] << 56); break; default: - INFO(id_, "Unsupported write of CSR pskey 0x{:04x}", - static_cast(pskey)); + INFO(id_, "Unsupported write of CSR pskey 0x{:04x}", static_cast(pskey)); break; } } void DualModeController::LeSetAdvertisingSetRandomAddress(CommandView command) { - auto command_view = - bluetooth::hci::LeSetAdvertisingSetRandomAddressView::Create(command); + auto command_view = bluetooth::hci::LeSetAdvertisingSetRandomAddressView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Advertising Set Random Address"); @@ -3373,147 +3073,120 @@ void DualModeController::LeSetAdvertisingSetRandomAddress(CommandView command) { DEBUG(id_, " random_address={}", command_view.GetRandomAddress()); ErrorCode status = link_layer_controller_.LeSetAdvertisingSetRandomAddress( - command_view.GetAdvertisingHandle(), command_view.GetRandomAddress()); - send_event_( - bluetooth::hci::LeSetAdvertisingSetRandomAddressCompleteBuilder::Create( + command_view.GetAdvertisingHandle(), command_view.GetRandomAddress()); + send_event_(bluetooth::hci::LeSetAdvertisingSetRandomAddressCompleteBuilder::Create( kNumCommandPackets, status)); } -void DualModeController::LeSetExtendedAdvertisingParameters( - CommandView command) { - auto command_view = - bluetooth::hci::LeSetExtendedAdvertisingParametersView::Create(command); +void DualModeController::LeSetExtendedAdvertisingParametersV1(CommandView command) { + auto command_view = bluetooth::hci::LeSetExtendedAdvertisingParametersV1View::Create(command); CHECK_PACKET_VIEW(command_view); - DEBUG(id_, "<< LE Set Extended Advertising Parameters"); + DEBUG(id_, "<< LE Set Extended Advertising Parameters V1"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); ErrorCode status = link_layer_controller_.LeSetExtendedAdvertisingParameters( - command_view.GetAdvertisingHandle(), - command_view.GetAdvertisingEventProperties(), - command_view.GetPrimaryAdvertisingIntervalMin(), - command_view.GetPrimaryAdvertisingIntervalMax(), - command_view.GetPrimaryAdvertisingChannelMap(), - command_view.GetOwnAddressType(), command_view.GetPeerAddressType(), - command_view.GetPeerAddress(), command_view.GetAdvertisingFilterPolicy(), - command_view.GetAdvertisingTxPower(), - command_view.GetPrimaryAdvertisingPhy(), - command_view.GetSecondaryAdvertisingMaxSkip(), - command_view.GetSecondaryAdvertisingPhy(), - command_view.GetAdvertisingSid(), - command_view.GetScanRequestNotificationEnable() == Enable::ENABLED); + command_view.GetAdvertisingHandle(), command_view.GetAdvertisingEventProperties(), + command_view.GetPrimaryAdvertisingIntervalMin(), + command_view.GetPrimaryAdvertisingIntervalMax(), + command_view.GetPrimaryAdvertisingChannelMap(), command_view.GetOwnAddressType(), + command_view.GetPeerAddressType(), command_view.GetPeerAddress(), + command_view.GetAdvertisingFilterPolicy(), command_view.GetAdvertisingTxPower(), + command_view.GetPrimaryAdvertisingPhy(), command_view.GetSecondaryAdvertisingMaxSkip(), + command_view.GetSecondaryAdvertisingPhy(), command_view.GetAdvertisingSid(), + command_view.GetScanRequestNotificationEnable() == Enable::ENABLED); // The selected TX power is always the requested TX power // at the moment. - send_event_( - bluetooth::hci::LeSetExtendedAdvertisingParametersCompleteBuilder::Create( + send_event_(bluetooth::hci::LeSetExtendedAdvertisingParametersV1CompleteBuilder::Create( kNumCommandPackets, status, command_view.GetAdvertisingTxPower())); } void DualModeController::LeSetExtendedAdvertisingData(CommandView command) { - auto command_view = - bluetooth::hci::LeSetExtendedAdvertisingDataView::Create(command); + auto command_view = bluetooth::hci::LeSetExtendedAdvertisingDataView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Advertising Data"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); ErrorCode status = link_layer_controller_.LeSetExtendedAdvertisingData( - command_view.GetAdvertisingHandle(), command_view.GetOperation(), - command_view.GetFragmentPreference(), command_view.GetAdvertisingData()); - send_event_( - bluetooth::hci::LeSetExtendedAdvertisingDataCompleteBuilder::Create( + command_view.GetAdvertisingHandle(), command_view.GetOperation(), + command_view.GetFragmentPreference(), command_view.GetAdvertisingData()); + send_event_(bluetooth::hci::LeSetExtendedAdvertisingDataCompleteBuilder::Create( kNumCommandPackets, status)); } void DualModeController::LeSetExtendedScanResponseData(CommandView command) { - auto command_view = - bluetooth::hci::LeSetExtendedScanResponseDataView::Create(command); + auto command_view = bluetooth::hci::LeSetExtendedScanResponseDataView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Scan Response Data"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); ErrorCode status = link_layer_controller_.LeSetExtendedScanResponseData( - command_view.GetAdvertisingHandle(), command_view.GetOperation(), - command_view.GetFragmentPreference(), command_view.GetScanResponseData()); - send_event_( - bluetooth::hci::LeSetExtendedScanResponseDataCompleteBuilder::Create( + command_view.GetAdvertisingHandle(), command_view.GetOperation(), + command_view.GetFragmentPreference(), command_view.GetScanResponseData()); + send_event_(bluetooth::hci::LeSetExtendedScanResponseDataCompleteBuilder::Create( kNumCommandPackets, status)); } void DualModeController::LeSetExtendedAdvertisingEnable(CommandView command) { - auto command_view = - bluetooth::hci::LeSetExtendedAdvertisingEnableView::Create(command); + auto command_view = bluetooth::hci::LeSetExtendedAdvertisingEnableView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Advertising Enable"); - DEBUG(id_, " enable={}", - command_view.GetEnable() == bluetooth::hci::Enable::ENABLED); + DEBUG(id_, " enable={}", command_view.GetEnable() == bluetooth::hci::Enable::ENABLED); for (auto const& set : command_view.GetEnabledSets()) { DEBUG(id_, " advertising_handle={}", set.advertising_handle_); } ErrorCode status = link_layer_controller_.LeSetExtendedAdvertisingEnable( - command_view.GetEnable() == bluetooth::hci::Enable::ENABLED, - command_view.GetEnabledSets()); - send_event_( - bluetooth::hci::LeSetExtendedAdvertisingEnableCompleteBuilder::Create( + command_view.GetEnable() == bluetooth::hci::Enable::ENABLED, + command_view.GetEnabledSets()); + send_event_(bluetooth::hci::LeSetExtendedAdvertisingEnableCompleteBuilder::Create( kNumCommandPackets, status)); } -void DualModeController::LeReadMaximumAdvertisingDataLength( - CommandView command) { - auto command_view = - bluetooth::hci::LeReadMaximumAdvertisingDataLengthView::Create(command); +void DualModeController::LeReadMaximumAdvertisingDataLength(CommandView command) { + auto command_view = bluetooth::hci::LeReadMaximumAdvertisingDataLengthView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Maximum Advertising Data Length"); - send_event_( - bluetooth::hci::LeReadMaximumAdvertisingDataLengthCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, - properties_.le_max_advertising_data_length)); + send_event_(bluetooth::hci::LeReadMaximumAdvertisingDataLengthCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS, properties_.le_max_advertising_data_length)); } -void DualModeController::LeReadNumberOfSupportedAdvertisingSets( - CommandView command) { - auto command_view = - bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsView::Create( - command); +void DualModeController::LeReadNumberOfSupportedAdvertisingSets(CommandView command) { + auto command_view = bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Number of Supported Advertising Sets"); - send_event_( - bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsCompleteBuilder:: - Create(kNumCommandPackets, ErrorCode::SUCCESS, - properties_.le_num_supported_advertising_sets)); + send_event_(bluetooth::hci::LeReadNumberOfSupportedAdvertisingSetsCompleteBuilder::Create( + kNumCommandPackets, ErrorCode::SUCCESS, properties_.le_num_supported_advertising_sets)); } void DualModeController::LeRemoveAdvertisingSet(CommandView command) { - auto command_view = - bluetooth::hci::LeRemoveAdvertisingSetView::Create(command); + auto command_view = bluetooth::hci::LeRemoveAdvertisingSetView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Remove Advertising Set"); DEBUG(id_, " advertising_handle={}", command_view.GetAdvertisingHandle()); - auto status = link_layer_controller_.LeRemoveAdvertisingSet( - command_view.GetAdvertisingHandle()); - send_event_(bluetooth::hci::LeRemoveAdvertisingSetCompleteBuilder::Create( - kNumCommandPackets, status)); + auto status = link_layer_controller_.LeRemoveAdvertisingSet(command_view.GetAdvertisingHandle()); + send_event_(bluetooth::hci::LeRemoveAdvertisingSetCompleteBuilder::Create(kNumCommandPackets, + status)); } void DualModeController::LeClearAdvertisingSets(CommandView command) { - auto command_view = - bluetooth::hci::LeClearAdvertisingSetsView::Create(command); + auto command_view = bluetooth::hci::LeClearAdvertisingSetsView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Clear Advertising Sets"); auto status = link_layer_controller_.LeClearAdvertisingSets(); - send_event_(bluetooth::hci::LeClearAdvertisingSetsCompleteBuilder::Create( - kNumCommandPackets, status)); + send_event_(bluetooth::hci::LeClearAdvertisingSetsCompleteBuilder::Create(kNumCommandPackets, + status)); } void DualModeController::LeStartEncryption(CommandView command) { @@ -3524,72 +3197,61 @@ void DualModeController::LeStartEncryption(CommandView command) { DEBUG(id_, " connection_handle=0x{:x}", command_view.GetConnectionHandle()); ErrorCode status = link_layer_controller_.LeEnableEncryption( - command_view.GetConnectionHandle(), command_view.GetRand(), - command_view.GetEdiv(), command_view.GetLtk()); + command_view.GetConnectionHandle(), command_view.GetRand(), command_view.GetEdiv(), + command_view.GetLtk()); - send_event_(bluetooth::hci::LeStartEncryptionStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_(bluetooth::hci::LeStartEncryptionStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::LeLongTermKeyRequestReply(CommandView command) { - auto command_view = - bluetooth::hci::LeLongTermKeyRequestReplyView::Create(command); + auto command_view = bluetooth::hci::LeLongTermKeyRequestReplyView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< LE Long Term Key Request Reply"); DEBUG(id_, " connection_handle=0x{:x}", handle); - ErrorCode status = link_layer_controller_.LeLongTermKeyRequestReply( - handle, command_view.GetLongTermKey()); + ErrorCode status = + link_layer_controller_.LeLongTermKeyRequestReply(handle, command_view.GetLongTermKey()); - send_event_(bluetooth::hci::LeLongTermKeyRequestReplyCompleteBuilder::Create( - kNumCommandPackets, status, handle)); + send_event_(bluetooth::hci::LeLongTermKeyRequestReplyCompleteBuilder::Create(kNumCommandPackets, + status, handle)); } -void DualModeController::LeLongTermKeyRequestNegativeReply( - CommandView command) { - auto command_view = - bluetooth::hci::LeLongTermKeyRequestNegativeReplyView::Create(command); +void DualModeController::LeLongTermKeyRequestNegativeReply(CommandView command) { + auto command_view = bluetooth::hci::LeLongTermKeyRequestNegativeReplyView::Create(command); CHECK_PACKET_VIEW(command_view); uint16_t handle = command_view.GetConnectionHandle(); DEBUG(id_, "<< LE Long Term Key Request Negative Reply"); DEBUG(id_, " connection_handle=0x{:x}", handle); - ErrorCode status = - link_layer_controller_.LeLongTermKeyRequestNegativeReply(handle); + ErrorCode status = link_layer_controller_.LeLongTermKeyRequestNegativeReply(handle); - send_event_( - bluetooth::hci::LeLongTermKeyRequestNegativeReplyCompleteBuilder::Create( + send_event_(bluetooth::hci::LeLongTermKeyRequestNegativeReplyCompleteBuilder::Create( kNumCommandPackets, status, handle)); } void DualModeController::ReadConnectionAcceptTimeout(CommandView command) { - auto command_view = - bluetooth::hci::ReadConnectionAcceptTimeoutView::Create(command); + auto command_view = bluetooth::hci::ReadConnectionAcceptTimeoutView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Read Connection Accept Timeout"); - send_event_( - bluetooth::hci::ReadConnectionAcceptTimeoutCompleteBuilder::Create( + send_event_(bluetooth::hci::ReadConnectionAcceptTimeoutCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, link_layer_controller_.GetConnectionAcceptTimeout())); } void DualModeController::WriteConnectionAcceptTimeout(CommandView command) { - auto command_view = - bluetooth::hci::WriteConnectionAcceptTimeoutView::Create(command); + auto command_view = bluetooth::hci::WriteConnectionAcceptTimeoutView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< Write Connection Accept Timeout"); - link_layer_controller_.SetConnectionAcceptTimeout( - command_view.GetConnAcceptTimeout()); + link_layer_controller_.SetConnectionAcceptTimeout(command_view.GetConnAcceptTimeout()); - send_event_( - bluetooth::hci::WriteConnectionAcceptTimeoutCompleteBuilder::Create( + send_event_(bluetooth::hci::WriteConnectionAcceptTimeoutCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS)); } @@ -3600,7 +3262,7 @@ void DualModeController::ReadLoopbackMode(CommandView command) { DEBUG(id_, "<< Read Loopback Mode"); send_event_(bluetooth::hci::ReadLoopbackModeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS, loopback_mode_)); + kNumCommandPackets, ErrorCode::SUCCESS, loopback_mode_)); } void DualModeController::WriteLoopbackMode(CommandView command) { @@ -3615,82 +3277,65 @@ void DualModeController::WriteLoopbackMode(CommandView command) { // ACL channel uint16_t acl_handle = 0x123; send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, acl_handle, GetAddress(), - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + ErrorCode::SUCCESS, acl_handle, GetAddress(), bluetooth::hci::LinkType::ACL, + bluetooth::hci::Enable::DISABLED)); // SCO channel uint16_t sco_handle = 0x345; send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, sco_handle, GetAddress(), - bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED)); - send_event_(bluetooth::hci::WriteLoopbackModeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + ErrorCode::SUCCESS, sco_handle, GetAddress(), bluetooth::hci::LinkType::SCO, + bluetooth::hci::Enable::DISABLED)); + send_event_(bluetooth::hci::WriteLoopbackModeCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); +} + +void DualModeController::IntelDdcConfigWrite(CommandView /*command*/) { + send_event_(bluetooth::hci::CommandCompleteBuilder::Create(kNumCommandPackets, OpCode::INTEL_DDC_CONFIG_WRITE, + std::vector { static_cast(ErrorCode::SUCCESS) })); } // Note: the list does not contain all defined opcodes. // Notable exceptions: // - Vendor commands // - Read Local Supported Commands command -const std::unordered_map - DualModeController::hci_command_op_code_to_index_{ +const std::unordered_map DualModeController::hci_command_op_code_to_index_{ // LINK_CONTROL {OpCode::INQUIRY, OpCodeIndex::INQUIRY}, {OpCode::INQUIRY_CANCEL, OpCodeIndex::INQUIRY_CANCEL}, {OpCode::PERIODIC_INQUIRY_MODE, OpCodeIndex::PERIODIC_INQUIRY_MODE}, - {OpCode::EXIT_PERIODIC_INQUIRY_MODE, - OpCodeIndex::EXIT_PERIODIC_INQUIRY_MODE}, + {OpCode::EXIT_PERIODIC_INQUIRY_MODE, OpCodeIndex::EXIT_PERIODIC_INQUIRY_MODE}, {OpCode::CREATE_CONNECTION, OpCodeIndex::CREATE_CONNECTION}, {OpCode::DISCONNECT, OpCodeIndex::DISCONNECT}, {OpCode::ADD_SCO_CONNECTION, OpCodeIndex::ADD_SCO_CONNECTION}, - {OpCode::CREATE_CONNECTION_CANCEL, - OpCodeIndex::CREATE_CONNECTION_CANCEL}, - {OpCode::ACCEPT_CONNECTION_REQUEST, - OpCodeIndex::ACCEPT_CONNECTION_REQUEST}, - {OpCode::REJECT_CONNECTION_REQUEST, - OpCodeIndex::REJECT_CONNECTION_REQUEST}, + {OpCode::CREATE_CONNECTION_CANCEL, OpCodeIndex::CREATE_CONNECTION_CANCEL}, + {OpCode::ACCEPT_CONNECTION_REQUEST, OpCodeIndex::ACCEPT_CONNECTION_REQUEST}, + {OpCode::REJECT_CONNECTION_REQUEST, OpCodeIndex::REJECT_CONNECTION_REQUEST}, {OpCode::LINK_KEY_REQUEST_REPLY, OpCodeIndex::LINK_KEY_REQUEST_REPLY}, - {OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::LINK_KEY_REQUEST_NEGATIVE_REPLY}, + {OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY, OpCodeIndex::LINK_KEY_REQUEST_NEGATIVE_REPLY}, {OpCode::PIN_CODE_REQUEST_REPLY, OpCodeIndex::PIN_CODE_REQUEST_REPLY}, - {OpCode::PIN_CODE_REQUEST_NEGATIVE_REPLY, - OpCodeIndex::PIN_CODE_REQUEST_NEGATIVE_REPLY}, - {OpCode::CHANGE_CONNECTION_PACKET_TYPE, - OpCodeIndex::CHANGE_CONNECTION_PACKET_TYPE}, - {OpCode::AUTHENTICATION_REQUESTED, - OpCodeIndex::AUTHENTICATION_REQUESTED}, - {OpCode::SET_CONNECTION_ENCRYPTION, - OpCodeIndex::SET_CONNECTION_ENCRYPTION}, - {OpCode::CHANGE_CONNECTION_LINK_KEY, - OpCodeIndex::CHANGE_CONNECTION_LINK_KEY}, + {OpCode::PIN_CODE_REQUEST_NEGATIVE_REPLY, OpCodeIndex::PIN_CODE_REQUEST_NEGATIVE_REPLY}, + {OpCode::CHANGE_CONNECTION_PACKET_TYPE, OpCodeIndex::CHANGE_CONNECTION_PACKET_TYPE}, + {OpCode::AUTHENTICATION_REQUESTED, OpCodeIndex::AUTHENTICATION_REQUESTED}, + {OpCode::SET_CONNECTION_ENCRYPTION, OpCodeIndex::SET_CONNECTION_ENCRYPTION}, + {OpCode::CHANGE_CONNECTION_LINK_KEY, OpCodeIndex::CHANGE_CONNECTION_LINK_KEY}, {OpCode::CENTRAL_LINK_KEY, OpCodeIndex::CENTRAL_LINK_KEY}, {OpCode::REMOTE_NAME_REQUEST, OpCodeIndex::REMOTE_NAME_REQUEST}, - {OpCode::REMOTE_NAME_REQUEST_CANCEL, - OpCodeIndex::REMOTE_NAME_REQUEST_CANCEL}, - {OpCode::READ_REMOTE_SUPPORTED_FEATURES, - OpCodeIndex::READ_REMOTE_SUPPORTED_FEATURES}, - {OpCode::READ_REMOTE_EXTENDED_FEATURES, - OpCodeIndex::READ_REMOTE_EXTENDED_FEATURES}, - {OpCode::READ_REMOTE_VERSION_INFORMATION, - OpCodeIndex::READ_REMOTE_VERSION_INFORMATION}, + {OpCode::REMOTE_NAME_REQUEST_CANCEL, OpCodeIndex::REMOTE_NAME_REQUEST_CANCEL}, + {OpCode::READ_REMOTE_SUPPORTED_FEATURES, OpCodeIndex::READ_REMOTE_SUPPORTED_FEATURES}, + {OpCode::READ_REMOTE_EXTENDED_FEATURES, OpCodeIndex::READ_REMOTE_EXTENDED_FEATURES}, + {OpCode::READ_REMOTE_VERSION_INFORMATION, OpCodeIndex::READ_REMOTE_VERSION_INFORMATION}, {OpCode::READ_CLOCK_OFFSET, OpCodeIndex::READ_CLOCK_OFFSET}, {OpCode::READ_LMP_HANDLE, OpCodeIndex::READ_LMP_HANDLE}, - {OpCode::SETUP_SYNCHRONOUS_CONNECTION, - OpCodeIndex::SETUP_SYNCHRONOUS_CONNECTION}, - {OpCode::ACCEPT_SYNCHRONOUS_CONNECTION, - OpCodeIndex::ACCEPT_SYNCHRONOUS_CONNECTION}, - {OpCode::REJECT_SYNCHRONOUS_CONNECTION, - OpCodeIndex::REJECT_SYNCHRONOUS_CONNECTION}, - {OpCode::IO_CAPABILITY_REQUEST_REPLY, - OpCodeIndex::IO_CAPABILITY_REQUEST_REPLY}, - {OpCode::USER_CONFIRMATION_REQUEST_REPLY, - OpCodeIndex::USER_CONFIRMATION_REQUEST_REPLY}, + {OpCode::SETUP_SYNCHRONOUS_CONNECTION, OpCodeIndex::SETUP_SYNCHRONOUS_CONNECTION}, + {OpCode::ACCEPT_SYNCHRONOUS_CONNECTION, OpCodeIndex::ACCEPT_SYNCHRONOUS_CONNECTION}, + {OpCode::REJECT_SYNCHRONOUS_CONNECTION, OpCodeIndex::REJECT_SYNCHRONOUS_CONNECTION}, + {OpCode::IO_CAPABILITY_REQUEST_REPLY, OpCodeIndex::IO_CAPABILITY_REQUEST_REPLY}, + {OpCode::USER_CONFIRMATION_REQUEST_REPLY, OpCodeIndex::USER_CONFIRMATION_REQUEST_REPLY}, {OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, OpCodeIndex::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY}, - {OpCode::USER_PASSKEY_REQUEST_REPLY, - OpCodeIndex::USER_PASSKEY_REQUEST_REPLY}, + {OpCode::USER_PASSKEY_REQUEST_REPLY, OpCodeIndex::USER_PASSKEY_REQUEST_REPLY}, {OpCode::USER_PASSKEY_REQUEST_NEGATIVE_REPLY, OpCodeIndex::USER_PASSKEY_REQUEST_NEGATIVE_REPLY}, - {OpCode::REMOTE_OOB_DATA_REQUEST_REPLY, - OpCodeIndex::REMOTE_OOB_DATA_REQUEST_REPLY}, + {OpCode::REMOTE_OOB_DATA_REQUEST_REPLY, OpCodeIndex::REMOTE_OOB_DATA_REQUEST_REPLY}, {OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, OpCodeIndex::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY}, {OpCode::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, @@ -3705,10 +3350,8 @@ const std::unordered_map OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST}, {OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE}, - {OpCode::START_SYNCHRONIZATION_TRAIN, - OpCodeIndex::START_SYNCHRONIZATION_TRAIN}, - {OpCode::RECEIVE_SYNCHRONIZATION_TRAIN, - OpCodeIndex::RECEIVE_SYNCHRONIZATION_TRAIN}, + {OpCode::START_SYNCHRONIZATION_TRAIN, OpCodeIndex::START_SYNCHRONIZATION_TRAIN}, + {OpCode::RECEIVE_SYNCHRONIZATION_TRAIN, OpCodeIndex::RECEIVE_SYNCHRONIZATION_TRAIN}, {OpCode::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY, OpCodeIndex::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY}, @@ -3719,12 +3362,9 @@ const std::unordered_map {OpCode::QOS_SETUP, OpCodeIndex::QOS_SETUP}, {OpCode::ROLE_DISCOVERY, OpCodeIndex::ROLE_DISCOVERY}, {OpCode::SWITCH_ROLE, OpCodeIndex::SWITCH_ROLE}, - {OpCode::READ_LINK_POLICY_SETTINGS, - OpCodeIndex::READ_LINK_POLICY_SETTINGS}, - {OpCode::WRITE_LINK_POLICY_SETTINGS, - OpCodeIndex::WRITE_LINK_POLICY_SETTINGS}, - {OpCode::READ_DEFAULT_LINK_POLICY_SETTINGS, - OpCodeIndex::READ_DEFAULT_LINK_POLICY_SETTINGS}, + {OpCode::READ_LINK_POLICY_SETTINGS, OpCodeIndex::READ_LINK_POLICY_SETTINGS}, + {OpCode::WRITE_LINK_POLICY_SETTINGS, OpCodeIndex::WRITE_LINK_POLICY_SETTINGS}, + {OpCode::READ_DEFAULT_LINK_POLICY_SETTINGS, OpCodeIndex::READ_DEFAULT_LINK_POLICY_SETTINGS}, {OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS, OpCodeIndex::WRITE_DEFAULT_LINK_POLICY_SETTINGS}, {OpCode::FLOW_SPECIFICATION, OpCodeIndex::FLOW_SPECIFICATION}, @@ -3742,42 +3382,29 @@ const std::unordered_map {OpCode::DELETE_STORED_LINK_KEY, OpCodeIndex::DELETE_STORED_LINK_KEY}, {OpCode::WRITE_LOCAL_NAME, OpCodeIndex::WRITE_LOCAL_NAME}, {OpCode::READ_LOCAL_NAME, OpCodeIndex::READ_LOCAL_NAME}, - {OpCode::READ_CONNECTION_ACCEPT_TIMEOUT, - OpCodeIndex::READ_CONNECTION_ACCEPT_TIMEOUT}, - {OpCode::WRITE_CONNECTION_ACCEPT_TIMEOUT, - OpCodeIndex::WRITE_CONNECTION_ACCEPT_TIMEOUT}, + {OpCode::READ_CONNECTION_ACCEPT_TIMEOUT, OpCodeIndex::READ_CONNECTION_ACCEPT_TIMEOUT}, + {OpCode::WRITE_CONNECTION_ACCEPT_TIMEOUT, OpCodeIndex::WRITE_CONNECTION_ACCEPT_TIMEOUT}, {OpCode::READ_PAGE_TIMEOUT, OpCodeIndex::READ_PAGE_TIMEOUT}, {OpCode::WRITE_PAGE_TIMEOUT, OpCodeIndex::WRITE_PAGE_TIMEOUT}, {OpCode::READ_SCAN_ENABLE, OpCodeIndex::READ_SCAN_ENABLE}, {OpCode::WRITE_SCAN_ENABLE, OpCodeIndex::WRITE_SCAN_ENABLE}, {OpCode::READ_PAGE_SCAN_ACTIVITY, OpCodeIndex::READ_PAGE_SCAN_ACTIVITY}, - {OpCode::WRITE_PAGE_SCAN_ACTIVITY, - OpCodeIndex::WRITE_PAGE_SCAN_ACTIVITY}, - {OpCode::READ_INQUIRY_SCAN_ACTIVITY, - OpCodeIndex::READ_INQUIRY_SCAN_ACTIVITY}, - {OpCode::WRITE_INQUIRY_SCAN_ACTIVITY, - OpCodeIndex::WRITE_INQUIRY_SCAN_ACTIVITY}, - {OpCode::READ_AUTHENTICATION_ENABLE, - OpCodeIndex::READ_AUTHENTICATION_ENABLE}, - {OpCode::WRITE_AUTHENTICATION_ENABLE, - OpCodeIndex::WRITE_AUTHENTICATION_ENABLE}, + {OpCode::WRITE_PAGE_SCAN_ACTIVITY, OpCodeIndex::WRITE_PAGE_SCAN_ACTIVITY}, + {OpCode::READ_INQUIRY_SCAN_ACTIVITY, OpCodeIndex::READ_INQUIRY_SCAN_ACTIVITY}, + {OpCode::WRITE_INQUIRY_SCAN_ACTIVITY, OpCodeIndex::WRITE_INQUIRY_SCAN_ACTIVITY}, + {OpCode::READ_AUTHENTICATION_ENABLE, OpCodeIndex::READ_AUTHENTICATION_ENABLE}, + {OpCode::WRITE_AUTHENTICATION_ENABLE, OpCodeIndex::WRITE_AUTHENTICATION_ENABLE}, {OpCode::READ_CLASS_OF_DEVICE, OpCodeIndex::READ_CLASS_OF_DEVICE}, {OpCode::WRITE_CLASS_OF_DEVICE, OpCodeIndex::WRITE_CLASS_OF_DEVICE}, {OpCode::READ_VOICE_SETTING, OpCodeIndex::READ_VOICE_SETTING}, {OpCode::WRITE_VOICE_SETTING, OpCodeIndex::WRITE_VOICE_SETTING}, - {OpCode::READ_AUTOMATIC_FLUSH_TIMEOUT, - OpCodeIndex::READ_AUTOMATIC_FLUSH_TIMEOUT}, - {OpCode::WRITE_AUTOMATIC_FLUSH_TIMEOUT, - OpCodeIndex::WRITE_AUTOMATIC_FLUSH_TIMEOUT}, - {OpCode::READ_NUM_BROADCAST_RETRANSMITS, - OpCodeIndex::READ_NUM_BROADCAST_RETRANSMITS}, - {OpCode::WRITE_NUM_BROADCAST_RETRANSMITS, - OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS}, + {OpCode::READ_AUTOMATIC_FLUSH_TIMEOUT, OpCodeIndex::READ_AUTOMATIC_FLUSH_TIMEOUT}, + {OpCode::WRITE_AUTOMATIC_FLUSH_TIMEOUT, OpCodeIndex::WRITE_AUTOMATIC_FLUSH_TIMEOUT}, + {OpCode::READ_NUM_BROADCAST_RETRANSMITS, OpCodeIndex::READ_NUM_BROADCAST_RETRANSMITS}, + {OpCode::WRITE_NUM_BROADCAST_RETRANSMITS, OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS}, {OpCode::READ_HOLD_MODE_ACTIVITY, OpCodeIndex::READ_HOLD_MODE_ACTIVITY}, - {OpCode::WRITE_HOLD_MODE_ACTIVITY, - OpCodeIndex::WRITE_HOLD_MODE_ACTIVITY}, - {OpCode::READ_TRANSMIT_POWER_LEVEL, - OpCodeIndex::READ_TRANSMIT_POWER_LEVEL}, + {OpCode::WRITE_HOLD_MODE_ACTIVITY, OpCodeIndex::WRITE_HOLD_MODE_ACTIVITY}, + {OpCode::READ_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_TRANSMIT_POWER_LEVEL}, {OpCode::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, OpCodeIndex::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE}, {OpCode::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, @@ -3785,14 +3412,10 @@ const std::unordered_map {OpCode::SET_CONTROLLER_TO_HOST_FLOW_CONTROL, OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL}, {OpCode::HOST_BUFFER_SIZE, OpCodeIndex::HOST_BUFFER_SIZE}, - {OpCode::HOST_NUMBER_OF_COMPLETED_PACKETS, - OpCodeIndex::HOST_NUMBER_OF_COMPLETED_PACKETS}, - {OpCode::READ_LINK_SUPERVISION_TIMEOUT, - OpCodeIndex::READ_LINK_SUPERVISION_TIMEOUT}, - {OpCode::WRITE_LINK_SUPERVISION_TIMEOUT, - OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT}, - {OpCode::READ_NUMBER_OF_SUPPORTED_IAC, - OpCodeIndex::READ_NUMBER_OF_SUPPORTED_IAC}, + {OpCode::HOST_NUMBER_OF_COMPLETED_PACKETS, OpCodeIndex::HOST_NUMBER_OF_COMPLETED_PACKETS}, + {OpCode::READ_LINK_SUPERVISION_TIMEOUT, OpCodeIndex::READ_LINK_SUPERVISION_TIMEOUT}, + {OpCode::WRITE_LINK_SUPERVISION_TIMEOUT, OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT}, + {OpCode::READ_NUMBER_OF_SUPPORTED_IAC, OpCodeIndex::READ_NUMBER_OF_SUPPORTED_IAC}, {OpCode::READ_CURRENT_IAC_LAP, OpCodeIndex::READ_CURRENT_IAC_LAP}, {OpCode::WRITE_CURRENT_IAC_LAP, OpCodeIndex::WRITE_CURRENT_IAC_LAP}, {OpCode::SET_AFH_HOST_CHANNEL_CLASSIFICATION, @@ -3803,19 +3426,13 @@ const std::unordered_map {OpCode::WRITE_INQUIRY_MODE, OpCodeIndex::WRITE_INQUIRY_MODE}, {OpCode::READ_PAGE_SCAN_TYPE, OpCodeIndex::READ_PAGE_SCAN_TYPE}, {OpCode::WRITE_PAGE_SCAN_TYPE, OpCodeIndex::WRITE_PAGE_SCAN_TYPE}, - {OpCode::READ_AFH_CHANNEL_ASSESSMENT_MODE, - OpCodeIndex::READ_AFH_CHANNEL_ASSESSMENT_MODE}, - {OpCode::WRITE_AFH_CHANNEL_ASSESSMENT_MODE, - OpCodeIndex::WRITE_AFH_CHANNEL_ASSESSMENT_MODE}, - {OpCode::READ_EXTENDED_INQUIRY_RESPONSE, - OpCodeIndex::READ_EXTENDED_INQUIRY_RESPONSE}, - {OpCode::WRITE_EXTENDED_INQUIRY_RESPONSE, - OpCodeIndex::WRITE_EXTENDED_INQUIRY_RESPONSE}, + {OpCode::READ_AFH_CHANNEL_ASSESSMENT_MODE, OpCodeIndex::READ_AFH_CHANNEL_ASSESSMENT_MODE}, + {OpCode::WRITE_AFH_CHANNEL_ASSESSMENT_MODE, OpCodeIndex::WRITE_AFH_CHANNEL_ASSESSMENT_MODE}, + {OpCode::READ_EXTENDED_INQUIRY_RESPONSE, OpCodeIndex::READ_EXTENDED_INQUIRY_RESPONSE}, + {OpCode::WRITE_EXTENDED_INQUIRY_RESPONSE, OpCodeIndex::WRITE_EXTENDED_INQUIRY_RESPONSE}, {OpCode::REFRESH_ENCRYPTION_KEY, OpCodeIndex::REFRESH_ENCRYPTION_KEY}, - {OpCode::READ_SIMPLE_PAIRING_MODE, - OpCodeIndex::READ_SIMPLE_PAIRING_MODE}, - {OpCode::WRITE_SIMPLE_PAIRING_MODE, - OpCodeIndex::WRITE_SIMPLE_PAIRING_MODE}, + {OpCode::READ_SIMPLE_PAIRING_MODE, OpCodeIndex::READ_SIMPLE_PAIRING_MODE}, + {OpCode::WRITE_SIMPLE_PAIRING_MODE, OpCodeIndex::WRITE_SIMPLE_PAIRING_MODE}, {OpCode::READ_LOCAL_OOB_DATA, OpCodeIndex::READ_LOCAL_OOB_DATA}, {OpCode::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL}, @@ -3826,8 +3443,7 @@ const std::unordered_map {OpCode::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING}, {OpCode::ENHANCED_FLUSH, OpCodeIndex::ENHANCED_FLUSH}, - {OpCode::SEND_KEYPRESS_NOTIFICATION, - OpCodeIndex::SEND_KEYPRESS_NOTIFICATION}, + {OpCode::SEND_KEYPRESS_NOTIFICATION, OpCodeIndex::SEND_KEYPRESS_NOTIFICATION}, {OpCode::SET_EVENT_MASK_PAGE_2, OpCodeIndex::SET_EVENT_MASK_PAGE_2}, {OpCode::READ_FLOW_CONTROL_MODE, OpCodeIndex::READ_FLOW_CONTROL_MODE}, {OpCode::WRITE_FLOW_CONTROL_MODE, OpCodeIndex::WRITE_FLOW_CONTROL_MODE}, @@ -3835,16 +3451,12 @@ const std::unordered_map OpCodeIndex::READ_ENHANCED_TRANSMIT_POWER_LEVEL}, {OpCode::READ_LE_HOST_SUPPORT, OpCodeIndex::READ_LE_HOST_SUPPORT}, {OpCode::WRITE_LE_HOST_SUPPORT, OpCodeIndex::WRITE_LE_HOST_SUPPORT}, - {OpCode::SET_MWS_CHANNEL_PARAMETERS, - OpCodeIndex::SET_MWS_CHANNEL_PARAMETERS}, - {OpCode::SET_EXTERNAL_FRAME_CONFIGURATION, - OpCodeIndex::SET_EXTERNAL_FRAME_CONFIGURATION}, + {OpCode::SET_MWS_CHANNEL_PARAMETERS, OpCodeIndex::SET_MWS_CHANNEL_PARAMETERS}, + {OpCode::SET_EXTERNAL_FRAME_CONFIGURATION, OpCodeIndex::SET_EXTERNAL_FRAME_CONFIGURATION}, {OpCode::SET_MWS_SIGNALING, OpCodeIndex::SET_MWS_SIGNALING}, {OpCode::SET_MWS_TRANSPORT_LAYER, OpCodeIndex::SET_MWS_TRANSPORT_LAYER}, - {OpCode::SET_MWS_SCAN_FREQUENCY_TABLE, - OpCodeIndex::SET_MWS_SCAN_FREQUENCY_TABLE}, - {OpCode::SET_MWS_PATTERN_CONFIGURATION, - OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION}, + {OpCode::SET_MWS_SCAN_FREQUENCY_TABLE, OpCodeIndex::SET_MWS_SCAN_FREQUENCY_TABLE}, + {OpCode::SET_MWS_PATTERN_CONFIGURATION, OpCodeIndex::SET_MWS_PATTERN_CONFIGURATION}, {OpCode::SET_RESERVED_LT_ADDR, OpCodeIndex::SET_RESERVED_LT_ADDR}, {OpCode::DELETE_RESERVED_LT_ADDR, OpCodeIndex::DELETE_RESERVED_LT_ADDR}, {OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA, @@ -3861,93 +3473,69 @@ const std::unordered_map OpCodeIndex::READ_AUTHENTICATED_PAYLOAD_TIMEOUT}, {OpCode::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT, OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT}, - {OpCode::READ_LOCAL_OOB_EXTENDED_DATA, - OpCodeIndex::READ_LOCAL_OOB_EXTENDED_DATA}, - {OpCode::READ_EXTENDED_PAGE_TIMEOUT, - OpCodeIndex::READ_EXTENDED_PAGE_TIMEOUT}, - {OpCode::WRITE_EXTENDED_PAGE_TIMEOUT, - OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT}, - {OpCode::READ_EXTENDED_INQUIRY_LENGTH, - OpCodeIndex::READ_EXTENDED_INQUIRY_LENGTH}, - {OpCode::WRITE_EXTENDED_INQUIRY_LENGTH, - OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH}, - {OpCode::SET_ECOSYSTEM_BASE_INTERVAL, - OpCodeIndex::SET_ECOSYSTEM_BASE_INTERVAL}, + {OpCode::READ_LOCAL_OOB_EXTENDED_DATA, OpCodeIndex::READ_LOCAL_OOB_EXTENDED_DATA}, + {OpCode::READ_EXTENDED_PAGE_TIMEOUT, OpCodeIndex::READ_EXTENDED_PAGE_TIMEOUT}, + {OpCode::WRITE_EXTENDED_PAGE_TIMEOUT, OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT}, + {OpCode::READ_EXTENDED_INQUIRY_LENGTH, OpCodeIndex::READ_EXTENDED_INQUIRY_LENGTH}, + {OpCode::WRITE_EXTENDED_INQUIRY_LENGTH, OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH}, + {OpCode::SET_ECOSYSTEM_BASE_INTERVAL, OpCodeIndex::SET_ECOSYSTEM_BASE_INTERVAL}, {OpCode::CONFIGURE_DATA_PATH, OpCodeIndex::CONFIGURE_DATA_PATH}, - {OpCode::SET_MIN_ENCRYPTION_KEY_SIZE, - OpCodeIndex::SET_MIN_ENCRYPTION_KEY_SIZE}, + {OpCode::SET_MIN_ENCRYPTION_KEY_SIZE, OpCodeIndex::SET_MIN_ENCRYPTION_KEY_SIZE}, // INFORMATIONAL_PARAMETERS - {OpCode::READ_LOCAL_VERSION_INFORMATION, - OpCodeIndex::READ_LOCAL_VERSION_INFORMATION}, - {OpCode::READ_LOCAL_SUPPORTED_FEATURES, - OpCodeIndex::READ_LOCAL_SUPPORTED_FEATURES}, - {OpCode::READ_LOCAL_EXTENDED_FEATURES, - OpCodeIndex::READ_LOCAL_EXTENDED_FEATURES}, + {OpCode::READ_LOCAL_VERSION_INFORMATION, OpCodeIndex::READ_LOCAL_VERSION_INFORMATION}, + {OpCode::READ_LOCAL_SUPPORTED_FEATURES, OpCodeIndex::READ_LOCAL_SUPPORTED_FEATURES}, + {OpCode::READ_LOCAL_EXTENDED_FEATURES, OpCodeIndex::READ_LOCAL_EXTENDED_FEATURES}, {OpCode::READ_BUFFER_SIZE, OpCodeIndex::READ_BUFFER_SIZE}, {OpCode::READ_BD_ADDR, OpCodeIndex::READ_BD_ADDR}, {OpCode::READ_DATA_BLOCK_SIZE, OpCodeIndex::READ_DATA_BLOCK_SIZE}, - {OpCode::READ_LOCAL_SUPPORTED_CODECS_V1, - OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V1}, - {OpCode::READ_LOCAL_SIMPLE_PAIRING_OPTIONS, - OpCodeIndex::READ_LOCAL_SIMPLE_PAIRING_OPTIONS}, - {OpCode::READ_LOCAL_SUPPORTED_CODECS_V2, - OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2}, + {OpCode::READ_LOCAL_SUPPORTED_CODECS_V1, OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V1}, + {OpCode::READ_LOCAL_SIMPLE_PAIRING_OPTIONS, OpCodeIndex::READ_LOCAL_SIMPLE_PAIRING_OPTIONS}, + {OpCode::READ_LOCAL_SUPPORTED_CODECS_V2, OpCodeIndex::READ_LOCAL_SUPPORTED_CODECS_V2}, {OpCode::READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES, OpCodeIndex::READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES}, {OpCode::READ_LOCAL_SUPPORTED_CONTROLLER_DELAY, OpCodeIndex::READ_LOCAL_SUPPORTED_CONTROLLER_DELAY}, // STATUS_PARAMETERS - {OpCode::READ_FAILED_CONTACT_COUNTER, - OpCodeIndex::READ_FAILED_CONTACT_COUNTER}, - {OpCode::RESET_FAILED_CONTACT_COUNTER, - OpCodeIndex::RESET_FAILED_CONTACT_COUNTER}, + {OpCode::READ_FAILED_CONTACT_COUNTER, OpCodeIndex::READ_FAILED_CONTACT_COUNTER}, + {OpCode::RESET_FAILED_CONTACT_COUNTER, OpCodeIndex::RESET_FAILED_CONTACT_COUNTER}, {OpCode::READ_LINK_QUALITY, OpCodeIndex::READ_LINK_QUALITY}, {OpCode::READ_RSSI, OpCodeIndex::READ_RSSI}, {OpCode::READ_AFH_CHANNEL_MAP, OpCodeIndex::READ_AFH_CHANNEL_MAP}, {OpCode::READ_CLOCK, OpCodeIndex::READ_CLOCK}, - {OpCode::READ_ENCRYPTION_KEY_SIZE, - OpCodeIndex::READ_ENCRYPTION_KEY_SIZE}, + {OpCode::READ_ENCRYPTION_KEY_SIZE, OpCodeIndex::READ_ENCRYPTION_KEY_SIZE}, {OpCode::GET_MWS_TRANSPORT_LAYER_CONFIGURATION, OpCodeIndex::GET_MWS_TRANSPORT_LAYER_CONFIGURATION}, - {OpCode::SET_TRIGGERED_CLOCK_CAPTURE, - OpCodeIndex::SET_TRIGGERED_CLOCK_CAPTURE}, + {OpCode::SET_TRIGGERED_CLOCK_CAPTURE, OpCodeIndex::SET_TRIGGERED_CLOCK_CAPTURE}, // TESTING {OpCode::READ_LOOPBACK_MODE, OpCodeIndex::READ_LOOPBACK_MODE}, {OpCode::WRITE_LOOPBACK_MODE, OpCodeIndex::WRITE_LOOPBACK_MODE}, - {OpCode::ENABLE_DEVICE_UNDER_TEST_MODE, - OpCodeIndex::ENABLE_DEVICE_UNDER_TEST_MODE}, - {OpCode::WRITE_SIMPLE_PAIRING_DEBUG_MODE, - OpCodeIndex::WRITE_SIMPLE_PAIRING_DEBUG_MODE}, + {OpCode::ENABLE_IMPLEMENTATION_UNDER_TEST_MODE, + OpCodeIndex::ENABLE_IMPLEMENTATION_UNDER_TEST_MODE}, + {OpCode::WRITE_SIMPLE_PAIRING_DEBUG_MODE, OpCodeIndex::WRITE_SIMPLE_PAIRING_DEBUG_MODE}, {OpCode::WRITE_SECURE_CONNECTIONS_TEST_MODE, OpCodeIndex::WRITE_SECURE_CONNECTIONS_TEST_MODE}, // LE_CONTROLLER {OpCode::LE_SET_EVENT_MASK, OpCodeIndex::LE_SET_EVENT_MASK}, {OpCode::LE_READ_BUFFER_SIZE_V1, OpCodeIndex::LE_READ_BUFFER_SIZE_V1}, - {OpCode::LE_READ_LOCAL_SUPPORTED_FEATURES, - OpCodeIndex::LE_READ_LOCAL_SUPPORTED_FEATURES}, + {OpCode::LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0, + OpCodeIndex::LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0}, {OpCode::LE_SET_RANDOM_ADDRESS, OpCodeIndex::LE_SET_RANDOM_ADDRESS}, - {OpCode::LE_SET_ADVERTISING_PARAMETERS, - OpCodeIndex::LE_SET_ADVERTISING_PARAMETERS}, + {OpCode::LE_SET_ADVERTISING_PARAMETERS, OpCodeIndex::LE_SET_ADVERTISING_PARAMETERS}, {OpCode::LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER, OpCodeIndex::LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER}, {OpCode::LE_SET_ADVERTISING_DATA, OpCodeIndex::LE_SET_ADVERTISING_DATA}, - {OpCode::LE_SET_SCAN_RESPONSE_DATA, - OpCodeIndex::LE_SET_SCAN_RESPONSE_DATA}, - {OpCode::LE_SET_ADVERTISING_ENABLE, - OpCodeIndex::LE_SET_ADVERTISING_ENABLE}, + {OpCode::LE_SET_SCAN_RESPONSE_DATA, OpCodeIndex::LE_SET_SCAN_RESPONSE_DATA}, + {OpCode::LE_SET_ADVERTISING_ENABLE, OpCodeIndex::LE_SET_ADVERTISING_ENABLE}, {OpCode::LE_SET_SCAN_PARAMETERS, OpCodeIndex::LE_SET_SCAN_PARAMETERS}, {OpCode::LE_SET_SCAN_ENABLE, OpCodeIndex::LE_SET_SCAN_ENABLE}, {OpCode::LE_CREATE_CONNECTION, OpCodeIndex::LE_CREATE_CONNECTION}, - {OpCode::LE_CREATE_CONNECTION_CANCEL, - OpCodeIndex::LE_CREATE_CONNECTION_CANCEL}, - {OpCode::LE_READ_FILTER_ACCEPT_LIST_SIZE, - OpCodeIndex::LE_READ_FILTER_ACCEPT_LIST_SIZE}, - {OpCode::LE_CLEAR_FILTER_ACCEPT_LIST, - OpCodeIndex::LE_CLEAR_FILTER_ACCEPT_LIST}, + {OpCode::LE_CREATE_CONNECTION_CANCEL, OpCodeIndex::LE_CREATE_CONNECTION_CANCEL}, + {OpCode::LE_READ_FILTER_ACCEPT_LIST_SIZE, OpCodeIndex::LE_READ_FILTER_ACCEPT_LIST_SIZE}, + {OpCode::LE_CLEAR_FILTER_ACCEPT_LIST, OpCodeIndex::LE_CLEAR_FILTER_ACCEPT_LIST}, {OpCode::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST, OpCodeIndex::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST}, {OpCode::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, @@ -3956,16 +3544,14 @@ const std::unordered_map {OpCode::LE_SET_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::LE_SET_HOST_CHANNEL_CLASSIFICATION}, {OpCode::LE_READ_CHANNEL_MAP, OpCodeIndex::LE_READ_CHANNEL_MAP}, - {OpCode::LE_READ_REMOTE_FEATURES, OpCodeIndex::LE_READ_REMOTE_FEATURES}, + {OpCode::LE_READ_REMOTE_FEATURES_PAGE_0, OpCodeIndex::LE_READ_REMOTE_FEATURES_PAGE_0}, {OpCode::LE_ENCRYPT, OpCodeIndex::LE_ENCRYPT}, {OpCode::LE_RAND, OpCodeIndex::LE_RAND}, {OpCode::LE_START_ENCRYPTION, OpCodeIndex::LE_START_ENCRYPTION}, - {OpCode::LE_LONG_TERM_KEY_REQUEST_REPLY, - OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_REPLY}, + {OpCode::LE_LONG_TERM_KEY_REQUEST_REPLY, OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_REPLY}, {OpCode::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY, OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY}, - {OpCode::LE_READ_SUPPORTED_STATES, - OpCodeIndex::LE_READ_SUPPORTED_STATES}, + {OpCode::LE_READ_SUPPORTED_STATES, OpCodeIndex::LE_READ_SUPPORTED_STATES}, {OpCode::LE_RECEIVER_TEST_V1, OpCodeIndex::LE_RECEIVER_TEST_V1}, {OpCode::LE_TRANSMITTER_TEST_V1, OpCodeIndex::LE_TRANSMITTER_TEST_V1}, {OpCode::LE_TEST_END, OpCodeIndex::LE_TEST_END}, @@ -3978,26 +3564,19 @@ const std::unordered_map OpCodeIndex::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH}, {OpCode::LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, OpCodeIndex::LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH}, - {OpCode::LE_READ_LOCAL_P_256_PUBLIC_KEY, - OpCodeIndex::LE_READ_LOCAL_P_256_PUBLIC_KEY}, + {OpCode::LE_READ_LOCAL_P_256_PUBLIC_KEY, OpCodeIndex::LE_READ_LOCAL_P_256_PUBLIC_KEY}, {OpCode::LE_GENERATE_DHKEY_V1, OpCodeIndex::LE_GENERATE_DHKEY_V1}, - {OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST, - OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST}, + {OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST, OpCodeIndex::LE_ADD_DEVICE_TO_RESOLVING_LIST}, {OpCode::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, OpCodeIndex::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST}, {OpCode::LE_CLEAR_RESOLVING_LIST, OpCodeIndex::LE_CLEAR_RESOLVING_LIST}, - {OpCode::LE_READ_RESOLVING_LIST_SIZE, - OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE}, - {OpCode::LE_READ_PEER_RESOLVABLE_ADDRESS, - OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS}, - {OpCode::LE_READ_LOCAL_RESOLVABLE_ADDRESS, - OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS}, - {OpCode::LE_SET_ADDRESS_RESOLUTION_ENABLE, - OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE}, + {OpCode::LE_READ_RESOLVING_LIST_SIZE, OpCodeIndex::LE_READ_RESOLVING_LIST_SIZE}, + {OpCode::LE_READ_PEER_RESOLVABLE_ADDRESS, OpCodeIndex::LE_READ_PEER_RESOLVABLE_ADDRESS}, + {OpCode::LE_READ_LOCAL_RESOLVABLE_ADDRESS, OpCodeIndex::LE_READ_LOCAL_RESOLVABLE_ADDRESS}, + {OpCode::LE_SET_ADDRESS_RESOLUTION_ENABLE, OpCodeIndex::LE_SET_ADDRESS_RESOLUTION_ENABLE}, {OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, OpCodeIndex::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT}, - {OpCode::LE_READ_MAXIMUM_DATA_LENGTH, - OpCodeIndex::LE_READ_MAXIMUM_DATA_LENGTH}, + {OpCode::LE_READ_MAXIMUM_DATA_LENGTH, OpCodeIndex::LE_READ_MAXIMUM_DATA_LENGTH}, {OpCode::LE_READ_PHY, OpCodeIndex::LE_READ_PHY}, {OpCode::LE_SET_DEFAULT_PHY, OpCodeIndex::LE_SET_DEFAULT_PHY}, {OpCode::LE_SET_PHY, OpCodeIndex::LE_SET_PHY}, @@ -4005,10 +3584,9 @@ const std::unordered_map {OpCode::LE_TRANSMITTER_TEST_V2, OpCodeIndex::LE_TRANSMITTER_TEST_V2}, {OpCode::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, OpCodeIndex::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS}, - {OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS}, - {OpCode::LE_SET_EXTENDED_ADVERTISING_DATA, - OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA}, + {OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1}, + {OpCode::LE_SET_EXTENDED_ADVERTISING_DATA, OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_DATA}, {OpCode::LE_SET_EXTENDED_SCAN_RESPONSE_DATA, OpCodeIndex::LE_SET_EXTENDED_SCAN_RESPONSE_DATA}, {OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE, @@ -4017,22 +3595,16 @@ const std::unordered_map OpCodeIndex::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH}, {OpCode::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, OpCodeIndex::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS}, - {OpCode::LE_REMOVE_ADVERTISING_SET, - OpCodeIndex::LE_REMOVE_ADVERTISING_SET}, - {OpCode::LE_CLEAR_ADVERTISING_SETS, - OpCodeIndex::LE_CLEAR_ADVERTISING_SETS}, - {OpCode::LE_SET_PERIODIC_ADVERTISING_PARAMETERS, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS}, - {OpCode::LE_SET_PERIODIC_ADVERTISING_DATA, - OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA}, + {OpCode::LE_REMOVE_ADVERTISING_SET, OpCodeIndex::LE_REMOVE_ADVERTISING_SET}, + {OpCode::LE_CLEAR_ADVERTISING_SETS, OpCodeIndex::LE_CLEAR_ADVERTISING_SETS}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_DATA, OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_DATA}, {OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE, OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_ENABLE}, - {OpCode::LE_SET_EXTENDED_SCAN_PARAMETERS, - OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS}, - {OpCode::LE_SET_EXTENDED_SCAN_ENABLE, - OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE}, - {OpCode::LE_EXTENDED_CREATE_CONNECTION, - OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION}, + {OpCode::LE_SET_EXTENDED_SCAN_PARAMETERS, OpCodeIndex::LE_SET_EXTENDED_SCAN_PARAMETERS}, + {OpCode::LE_SET_EXTENDED_SCAN_ENABLE, OpCodeIndex::LE_SET_EXTENDED_SCAN_ENABLE}, + {OpCode::LE_EXTENDED_CREATE_CONNECTION_V1, OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V1}, {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC, OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC}, {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, @@ -4043,8 +3615,7 @@ const std::unordered_map OpCodeIndex::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST}, {OpCode::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, OpCodeIndex::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST}, - {OpCode::LE_CLEAR_PERIODIC_ADVERTISER_LIST, - OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST}, + {OpCode::LE_CLEAR_PERIODIC_ADVERTISER_LIST, OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST}, {OpCode::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE}, {OpCode::LE_READ_TRANSMIT_POWER, OpCodeIndex::LE_READ_TRANSMIT_POWER}, @@ -4065,12 +3636,9 @@ const std::unordered_map OpCodeIndex::LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS}, {OpCode::LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS, OpCodeIndex::LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS}, - {OpCode::LE_CONNECTION_CTE_REQUEST_ENABLE, - OpCodeIndex::LE_CONNECTION_CTE_REQUEST_ENABLE}, - {OpCode::LE_CONNECTION_CTE_RESPONSE_ENABLE, - OpCodeIndex::LE_CONNECTION_CTE_RESPONSE_ENABLE}, - {OpCode::LE_READ_ANTENNA_INFORMATION, - OpCodeIndex::LE_READ_ANTENNA_INFORMATION}, + {OpCode::LE_CONNECTION_CTE_REQUEST_ENABLE, OpCodeIndex::LE_CONNECTION_CTE_REQUEST_ENABLE}, + {OpCode::LE_CONNECTION_CTE_RESPONSE_ENABLE, OpCodeIndex::LE_CONNECTION_CTE_RESPONSE_ENABLE}, + {OpCode::LE_READ_ANTENNA_INFORMATION, OpCodeIndex::LE_READ_ANTENNA_INFORMATION}, {OpCode::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE}, {OpCode::LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, @@ -4080,16 +3648,13 @@ const std::unordered_map {OpCode::LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS}, {OpCode::LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, - OpCodeIndex:: - LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS}, + OpCodeIndex::LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS}, {OpCode::LE_GENERATE_DHKEY_V2, OpCodeIndex::LE_GENERATE_DHKEY_V2}, - {OpCode::LE_MODIFY_SLEEP_CLOCK_ACCURACY, - OpCodeIndex::LE_MODIFY_SLEEP_CLOCK_ACCURACY}, + {OpCode::LE_MODIFY_SLEEP_CLOCK_ACCURACY, OpCodeIndex::LE_MODIFY_SLEEP_CLOCK_ACCURACY}, {OpCode::LE_READ_BUFFER_SIZE_V2, OpCodeIndex::LE_READ_BUFFER_SIZE_V2}, {OpCode::LE_READ_ISO_TX_SYNC, OpCodeIndex::LE_READ_ISO_TX_SYNC}, {OpCode::LE_SET_CIG_PARAMETERS, OpCodeIndex::LE_SET_CIG_PARAMETERS}, - {OpCode::LE_SET_CIG_PARAMETERS_TEST, - OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST}, + {OpCode::LE_SET_CIG_PARAMETERS_TEST, OpCodeIndex::LE_SET_CIG_PARAMETERS_TEST}, {OpCode::LE_CREATE_CIS, OpCodeIndex::LE_CREATE_CIS}, {OpCode::LE_REMOVE_CIG, OpCodeIndex::LE_REMOVE_CIG}, {OpCode::LE_ACCEPT_CIS_REQUEST, OpCodeIndex::LE_ACCEPT_CIS_REQUEST}, @@ -4104,20 +3669,17 @@ const std::unordered_map {OpCode::LE_REMOVE_ISO_DATA_PATH, OpCodeIndex::LE_REMOVE_ISO_DATA_PATH}, {OpCode::LE_ISO_TRANSMIT_TEST, OpCodeIndex::LE_ISO_TRANSMIT_TEST}, {OpCode::LE_ISO_RECEIVE_TEST, OpCodeIndex::LE_ISO_RECEIVE_TEST}, - {OpCode::LE_ISO_READ_TEST_COUNTERS, - OpCodeIndex::LE_ISO_READ_TEST_COUNTERS}, + {OpCode::LE_ISO_READ_TEST_COUNTERS, OpCodeIndex::LE_ISO_READ_TEST_COUNTERS}, {OpCode::LE_ISO_TEST_END, OpCodeIndex::LE_ISO_TEST_END}, - {OpCode::LE_SET_HOST_FEATURE, OpCodeIndex::LE_SET_HOST_FEATURE}, - {OpCode::LE_READ_ISO_LINK_QUALITY, - OpCodeIndex::LE_READ_ISO_LINK_QUALITY}, + {OpCode::LE_SET_HOST_FEATURE_V1, OpCodeIndex::LE_SET_HOST_FEATURE_V1}, + {OpCode::LE_READ_ISO_LINK_QUALITY, OpCodeIndex::LE_READ_ISO_LINK_QUALITY}, {OpCode::LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL, OpCodeIndex::LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL}, {OpCode::LE_READ_REMOTE_TRANSMIT_POWER_LEVEL, OpCodeIndex::LE_READ_REMOTE_TRANSMIT_POWER_LEVEL}, {OpCode::LE_SET_PATH_LOSS_REPORTING_PARAMETERS, OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_PARAMETERS}, - {OpCode::LE_SET_PATH_LOSS_REPORTING_ENABLE, - OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_ENABLE}, + {OpCode::LE_SET_PATH_LOSS_REPORTING_ENABLE, OpCodeIndex::LE_SET_PATH_LOSS_REPORTING_ENABLE}, {OpCode::LE_SET_TRANSMIT_POWER_REPORTING_ENABLE, OpCodeIndex::LE_SET_TRANSMIT_POWER_REPORTING_ENABLE}, {OpCode::LE_TRANSMITTER_TEST_V4, OpCodeIndex::LE_TRANSMITTER_TEST_V4}, @@ -4125,548 +3687,598 @@ const std::unordered_map OpCodeIndex::LE_SET_DATA_RELATED_ADDRESS_CHANGES}, {OpCode::LE_SET_DEFAULT_SUBRATE, OpCodeIndex::LE_SET_DEFAULT_SUBRATE}, {OpCode::LE_SUBRATE_REQUEST, OpCodeIndex::LE_SUBRATE_REQUEST}, - }; + {OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V2, + OpCodeIndex::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V2}, + {OpCode::LE_SET_DECISION_DATA, OpCodeIndex::LE_SET_DECISION_DATA}, + {OpCode::LE_SET_DECISION_INSTRUCTIONS, OpCodeIndex::LE_SET_DECISION_INSTRUCTIONS}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_SUBEVENT_DATA, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_SUBEVENT_DATA}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_RESPONSE_DATA, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_RESPONSE_DATA}, + {OpCode::LE_SET_PERIODIC_SYNC_SUBEVENT, OpCodeIndex::LE_SET_PERIODIC_SYNC_SUBEVENT}, + {OpCode::LE_EXTENDED_CREATE_CONNECTION_V2, OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION_V2}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V2, + OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V2}, + {OpCode::LE_READ_ALL_LOCAL_SUPPORTED_FEATURES, + OpCodeIndex::LE_READ_ALL_LOCAL_SUPPORTED_FEATURES}, + {OpCode::LE_READ_ALL_REMOTE_FEATURES, OpCodeIndex::LE_READ_ALL_REMOTE_FEATURES}, + {OpCode::LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES, + OpCodeIndex::LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES}, + {OpCode::LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES, + OpCodeIndex::LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES}, + {OpCode::LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES, + OpCodeIndex::LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES}, + {OpCode::LE_CS_SECURITY_ENABLE, OpCodeIndex::LE_CS_SECURITY_ENABLE}, + {OpCode::LE_CS_SET_DEFAULT_SETTINGS, OpCodeIndex::LE_CS_SET_DEFAULT_SETTINGS}, + {OpCode::LE_CS_READ_REMOTE_FAE_TABLE, OpCodeIndex::LE_CS_READ_REMOTE_FAE_TABLE}, + {OpCode::LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE, + OpCodeIndex::LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE}, + {OpCode::LE_CS_CREATE_CONFIG, OpCodeIndex::LE_CS_CREATE_CONFIG}, + {OpCode::LE_CS_REMOVE_CONFIG, OpCodeIndex::LE_CS_REMOVE_CONFIG}, + {OpCode::LE_CS_SET_CHANNEL_CLASSIFICATION, OpCodeIndex::LE_CS_SET_CHANNEL_CLASSIFICATION}, + {OpCode::LE_CS_SET_PROCEDURE_PARAMETERS, OpCodeIndex::LE_CS_SET_PROCEDURE_PARAMETERS}, + {OpCode::LE_CS_PROCEDURE_ENABLE, OpCodeIndex::LE_CS_PROCEDURE_ENABLE}, + {OpCode::LE_CS_TEST, OpCodeIndex::LE_CS_TEST}, + {OpCode::LE_CS_TEST_END, OpCodeIndex::LE_CS_TEST_END}, + {OpCode::LE_ADD_DEVICE_TO_MONITORED_ADVERTISERS_LIST, + OpCodeIndex::LE_ADD_DEVICE_TO_MONITORED_ADVERTISERS_LIST}, + {OpCode::LE_REMOVE_DEVICE_FROM_MONITORED_ADVERTISERS_LIST, + OpCodeIndex::LE_REMOVE_DEVICE_FROM_MONITORED_ADVERTISERS_LIST}, + {OpCode::LE_CLEAR_MONITORED_ADVERTISERS_LIST, + OpCodeIndex::LE_CLEAR_MONITORED_ADVERTISERS_LIST}, + {OpCode::LE_READ_MONITORED_ADVERTISERS_LIST_SIZE, + OpCodeIndex::LE_READ_MONITORED_ADVERTISERS_LIST_SIZE}, + {OpCode::LE_ENABLE_MONITORING_ADVERTISERS, OpCodeIndex::LE_ENABLE_MONITORING_ADVERTISERS}, + {OpCode::LE_FRAME_SPACE_UPDATE, OpCodeIndex::LE_FRAME_SPACE_UPDATE}, +}; const std::unordered_map - DualModeController::hci_command_handlers_{ - // LINK_CONTROL - {OpCode::INQUIRY, &DualModeController::Inquiry}, - {OpCode::INQUIRY_CANCEL, &DualModeController::InquiryCancel}, - //{OpCode::PERIODIC_INQUIRY_MODE, - //&DualModeController::PeriodicInquiryMode}, - //{OpCode::EXIT_PERIODIC_INQUIRY_MODE, - //&DualModeController::ExitPeriodicInquiryMode}, - {OpCode::CREATE_CONNECTION, &DualModeController::CreateConnection}, - {OpCode::DISCONNECT, &DualModeController::Disconnect}, - {OpCode::ADD_SCO_CONNECTION, &DualModeController::AddScoConnection}, - {OpCode::CREATE_CONNECTION_CANCEL, - &DualModeController::CreateConnectionCancel}, - {OpCode::ACCEPT_CONNECTION_REQUEST, - &DualModeController::AcceptConnectionRequest}, - {OpCode::REJECT_CONNECTION_REQUEST, - &DualModeController::RejectConnectionRequest}, - {OpCode::LINK_KEY_REQUEST_REPLY, &DualModeController::ForwardToLm}, - {OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::PIN_CODE_REQUEST_REPLY, &DualModeController::ForwardToLm}, - {OpCode::PIN_CODE_REQUEST_NEGATIVE_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::CHANGE_CONNECTION_PACKET_TYPE, - &DualModeController::ChangeConnectionPacketType}, - {OpCode::AUTHENTICATION_REQUESTED, &DualModeController::ForwardToLm}, - {OpCode::SET_CONNECTION_ENCRYPTION, &DualModeController::ForwardToLm}, - {OpCode::CHANGE_CONNECTION_LINK_KEY, - &DualModeController::ChangeConnectionLinkKey}, - {OpCode::CENTRAL_LINK_KEY, &DualModeController::CentralLinkKey}, - {OpCode::REMOTE_NAME_REQUEST, &DualModeController::RemoteNameRequest}, - //{OpCode::REMOTE_NAME_REQUEST_CANCEL, - //&DualModeController::RemoteNameRequestCancel}, - {OpCode::READ_REMOTE_SUPPORTED_FEATURES, - &DualModeController::ReadRemoteSupportedFeatures}, - {OpCode::READ_REMOTE_EXTENDED_FEATURES, - &DualModeController::ReadRemoteExtendedFeatures}, - {OpCode::READ_REMOTE_VERSION_INFORMATION, - &DualModeController::ReadRemoteVersionInformation}, - {OpCode::READ_CLOCK_OFFSET, &DualModeController::ReadClockOffset}, - //{OpCode::READ_LMP_HANDLE, &DualModeController::ReadLmpHandle}, - {OpCode::SETUP_SYNCHRONOUS_CONNECTION, - &DualModeController::SetupSynchronousConnection}, - {OpCode::ACCEPT_SYNCHRONOUS_CONNECTION, - &DualModeController::AcceptSynchronousConnection}, - {OpCode::REJECT_SYNCHRONOUS_CONNECTION, - &DualModeController::RejectSynchronousConnection}, - {OpCode::IO_CAPABILITY_REQUEST_REPLY, &DualModeController::ForwardToLm}, - {OpCode::USER_CONFIRMATION_REQUEST_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::USER_PASSKEY_REQUEST_REPLY, &DualModeController::ForwardToLm}, - {OpCode::USER_PASSKEY_REQUEST_NEGATIVE_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::REMOTE_OOB_DATA_REQUEST_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, - &DualModeController::ForwardToLm}, - {OpCode::ENHANCED_SETUP_SYNCHRONOUS_CONNECTION, - &DualModeController::EnhancedSetupSynchronousConnection}, - {OpCode::ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, - &DualModeController::EnhancedAcceptSynchronousConnection}, - //{OpCode::TRUNCATED_PAGE, &DualModeController::TruncatedPage}, - //{OpCode::TRUNCATED_PAGE_CANCEL, - //&DualModeController::TruncatedPageCancel}, - //{OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST, - //&DualModeController::SetConnectionlessPeripheralBroadcast}, - //{OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, - //&DualModeController::SetConnectionlessPeripheralBroadcastReceive}, - //{OpCode::START_SYNCHRONIZATION_TRAIN, - //&DualModeController::StartSynchronizationTrain}, - //{OpCode::RECEIVE_SYNCHRONIZATION_TRAIN, - //&DualModeController::ReceiveSynchronizationTrain}, - {OpCode::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY, - &DualModeController::ForwardToLm}, - - // LINK_POLICY - {OpCode::HOLD_MODE, &DualModeController::HoldMode}, - {OpCode::SNIFF_MODE, &DualModeController::SniffMode}, - {OpCode::EXIT_SNIFF_MODE, &DualModeController::ExitSniffMode}, - {OpCode::QOS_SETUP, &DualModeController::QosSetup}, - {OpCode::ROLE_DISCOVERY, &DualModeController::RoleDiscovery}, - {OpCode::SWITCH_ROLE, &DualModeController::SwitchRole}, - {OpCode::READ_LINK_POLICY_SETTINGS, - &DualModeController::ReadLinkPolicySettings}, - {OpCode::WRITE_LINK_POLICY_SETTINGS, - &DualModeController::WriteLinkPolicySettings}, - {OpCode::READ_DEFAULT_LINK_POLICY_SETTINGS, - &DualModeController::ReadDefaultLinkPolicySettings}, - {OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS, - &DualModeController::WriteDefaultLinkPolicySettings}, - {OpCode::FLOW_SPECIFICATION, &DualModeController::FlowSpecification}, - {OpCode::SNIFF_SUBRATING, &DualModeController::SniffSubrating}, - - // CONTROLLER_AND_BASEBAND - {OpCode::SET_EVENT_MASK, &DualModeController::SetEventMask}, - {OpCode::RESET, &DualModeController::Reset}, - {OpCode::SET_EVENT_FILTER, &DualModeController::SetEventFilter}, - //{OpCode::FLUSH, &DualModeController::Flush}, - //{OpCode::READ_PIN_TYPE, &DualModeController::ReadPinType}, - //{OpCode::WRITE_PIN_TYPE, &DualModeController::WritePinType}, - //{OpCode::READ_STORED_LINK_KEY, - //&DualModeController::ReadStoredLinkKey}, - //{OpCode::WRITE_STORED_LINK_KEY, - //&DualModeController::WriteStoredLinkKey}, - {OpCode::DELETE_STORED_LINK_KEY, - &DualModeController::DeleteStoredLinkKey}, - {OpCode::WRITE_LOCAL_NAME, &DualModeController::WriteLocalName}, - {OpCode::READ_LOCAL_NAME, &DualModeController::ReadLocalName}, - {OpCode::READ_CONNECTION_ACCEPT_TIMEOUT, - &DualModeController::ReadConnectionAcceptTimeout}, - {OpCode::WRITE_CONNECTION_ACCEPT_TIMEOUT, - &DualModeController::WriteConnectionAcceptTimeout}, - {OpCode::READ_PAGE_TIMEOUT, &DualModeController::ReadPageTimeout}, - {OpCode::WRITE_PAGE_TIMEOUT, &DualModeController::WritePageTimeout}, - {OpCode::READ_SCAN_ENABLE, &DualModeController::ReadScanEnable}, - {OpCode::WRITE_SCAN_ENABLE, &DualModeController::WriteScanEnable}, - {OpCode::READ_PAGE_SCAN_ACTIVITY, - &DualModeController::ReadPageScanActivity}, - {OpCode::WRITE_PAGE_SCAN_ACTIVITY, - &DualModeController::WritePageScanActivity}, - {OpCode::READ_INQUIRY_SCAN_ACTIVITY, - &DualModeController::ReadInquiryScanActivity}, - {OpCode::WRITE_INQUIRY_SCAN_ACTIVITY, - &DualModeController::WriteInquiryScanActivity}, - {OpCode::READ_AUTHENTICATION_ENABLE, - &DualModeController::ReadAuthenticationEnable}, - {OpCode::WRITE_AUTHENTICATION_ENABLE, - &DualModeController::WriteAuthenticationEnable}, - {OpCode::READ_CLASS_OF_DEVICE, &DualModeController::ReadClassOfDevice}, - {OpCode::WRITE_CLASS_OF_DEVICE, - &DualModeController::WriteClassOfDevice}, - {OpCode::READ_VOICE_SETTING, &DualModeController::ReadVoiceSetting}, - {OpCode::WRITE_VOICE_SETTING, &DualModeController::WriteVoiceSetting}, - //{OpCode::READ_AUTOMATIC_FLUSH_TIMEOUT, - //&DualModeController::ReadAutomaticFlushTimeout}, - //{OpCode::WRITE_AUTOMATIC_FLUSH_TIMEOUT, - //&DualModeController::WriteAutomaticFlushTimeout}, - //{OpCode::READ_NUM_BROADCAST_RETRANSMITS, - //&DualModeController::ReadNumBroadcastRetransmits}, - //{OpCode::WRITE_NUM_BROADCAST_RETRANSMITS, - //&DualModeController::WriteNumBroadcastRetransmits}, - //{OpCode::READ_HOLD_MODE_ACTIVITY, - //&DualModeController::ReadHoldModeActivity}, - //{OpCode::WRITE_HOLD_MODE_ACTIVITY, - //&DualModeController::WriteHoldModeActivity}, - {OpCode::READ_TRANSMIT_POWER_LEVEL, - &DualModeController::ReadTransmitPowerLevel}, - {OpCode::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, - &DualModeController::ReadSynchronousFlowControlEnable}, - {OpCode::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, - &DualModeController::WriteSynchronousFlowControlEnable}, - //{OpCode::SET_CONTROLLER_TO_HOST_FLOW_CONTROL, - //&DualModeController::SetControllerToHostFlowControl}, - {OpCode::HOST_BUFFER_SIZE, &DualModeController::HostBufferSize}, - //{OpCode::HOST_NUMBER_OF_COMPLETED_PACKETS, - //&DualModeController::HostNumberOfCompletedPackets}, - //{OpCode::READ_LINK_SUPERVISION_TIMEOUT, - //&DualModeController::ReadLinkSupervisionTimeout}, - {OpCode::WRITE_LINK_SUPERVISION_TIMEOUT, - &DualModeController::WriteLinkSupervisionTimeout}, - {OpCode::READ_NUMBER_OF_SUPPORTED_IAC, - &DualModeController::ReadNumberOfSupportedIac}, - {OpCode::READ_CURRENT_IAC_LAP, &DualModeController::ReadCurrentIacLap}, - {OpCode::WRITE_CURRENT_IAC_LAP, - &DualModeController::WriteCurrentIacLap}, - //{OpCode::SET_AFH_HOST_CHANNEL_CLASSIFICATION, - //&DualModeController::SetAfhHostChannelClassification}, - {OpCode::READ_INQUIRY_SCAN_TYPE, - &DualModeController::ReadInquiryScanType}, - {OpCode::WRITE_INQUIRY_SCAN_TYPE, - &DualModeController::WriteInquiryScanType}, - {OpCode::READ_INQUIRY_MODE, &DualModeController::ReadInquiryMode}, - {OpCode::WRITE_INQUIRY_MODE, &DualModeController::WriteInquiryMode}, - {OpCode::READ_PAGE_SCAN_TYPE, &DualModeController::ReadPageScanType}, - {OpCode::WRITE_PAGE_SCAN_TYPE, &DualModeController::WritePageScanType}, - //{OpCode::READ_AFH_CHANNEL_ASSESSMENT_MODE, - //&DualModeController::ReadAfhChannelAssessmentMode}, - //{OpCode::WRITE_AFH_CHANNEL_ASSESSMENT_MODE, - //&DualModeController::WriteAfhChannelAssessmentMode}, - //{OpCode::READ_EXTENDED_INQUIRY_RESPONSE, - //&DualModeController::ReadExtendedInquiryResponse}, - {OpCode::WRITE_EXTENDED_INQUIRY_RESPONSE, - &DualModeController::WriteExtendedInquiryResponse}, - {OpCode::REFRESH_ENCRYPTION_KEY, - &DualModeController::RefreshEncryptionKey}, - //{OpCode::READ_SIMPLE_PAIRING_MODE, - //&DualModeController::ReadSimplePairingMode}, - {OpCode::WRITE_SIMPLE_PAIRING_MODE, - &DualModeController::WriteSimplePairingMode}, - {OpCode::READ_LOCAL_OOB_DATA, &DualModeController::ReadLocalOobData}, - {OpCode::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL, - &DualModeController::ReadInquiryResponseTransmitPowerLevel}, - //{OpCode::WRITE_INQUIRY_TRANSMIT_POWER_LEVEL, - //&DualModeController::WriteInquiryTransmitPowerLevel}, - //{OpCode::READ_DEFAULT_ERRONEOUS_DATA_REPORTING, - //&DualModeController::ReadDefaultErroneousDataReporting}, - //{OpCode::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, - //&DualModeController::WriteDefaultErroneousDataReporting}, - {OpCode::ENHANCED_FLUSH, &DualModeController::EnhancedFlush}, - {OpCode::SEND_KEYPRESS_NOTIFICATION, &DualModeController::ForwardToLm}, - {OpCode::SET_EVENT_MASK_PAGE_2, &DualModeController::SetEventMaskPage2}, - //{OpCode::READ_FLOW_CONTROL_MODE, - //&DualModeController::ReadFlowControlMode}, - //{OpCode::WRITE_FLOW_CONTROL_MODE, - //&DualModeController::WriteFlowControlMode}, - {OpCode::READ_ENHANCED_TRANSMIT_POWER_LEVEL, - &DualModeController::ReadEnhancedTransmitPowerLevel}, - //{OpCode::READ_LE_HOST_SUPPORT, - //&DualModeController::ReadLeHostSupport}, - {OpCode::WRITE_LE_HOST_SUPPORT, - &DualModeController::WriteLeHostSupport}, - //{OpCode::SET_MWS_CHANNEL_PARAMETERS, - //&DualModeController::SetMwsChannelParameters}, - //{OpCode::SET_EXTERNAL_FRAME_CONFIGURATION, - //&DualModeController::SetExternalFrameConfiguration}, - //{OpCode::SET_MWS_SIGNALING, &DualModeController::SetMwsSignaling}, - //{OpCode::SET_MWS_TRANSPORT_LAYER, - //&DualModeController::SetMwsTransportLayer}, - //{OpCode::SET_MWS_SCAN_FREQUENCY_TABLE, - //&DualModeController::SetMwsScanFrequencyTable}, - //{OpCode::SET_MWS_PATTERN_CONFIGURATION, - //&DualModeController::SetMwsPatternConfiguration}, - //{OpCode::SET_RESERVED_LT_ADDR, - //&DualModeController::SetReservedLtAddr}, - //{OpCode::DELETE_RESERVED_LT_ADDR, - //&DualModeController::DeleteReservedLtAddr}, - //{OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA, - //&DualModeController::SetConnectionlessPeripheralBroadcastData}, - //{OpCode::READ_SYNCHRONIZATION_TRAIN_PARAMETERS, - //&DualModeController::ReadSynchronizationTrainParameters}, - //{OpCode::WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS, - //&DualModeController::WriteSynchronizationTrainParameters}, - //{OpCode::READ_SECURE_CONNECTIONS_HOST_SUPPORT, - //&DualModeController::ReadSecureConnectionsHostSupport}, - {OpCode::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, - &DualModeController::WriteSecureConnectionsHostSupport}, - //{OpCode::READ_AUTHENTICATED_PAYLOAD_TIMEOUT, - //&DualModeController::ReadAuthenticatedPayloadTimeout}, - //{OpCode::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT, - //&DualModeController::WriteAuthenticatedPayloadTimeout}, - {OpCode::READ_LOCAL_OOB_EXTENDED_DATA, - &DualModeController::ReadLocalOobExtendedData}, - //{OpCode::READ_EXTENDED_PAGE_TIMEOUT, - //&DualModeController::ReadExtendedPageTimeout}, - //{OpCode::WRITE_EXTENDED_PAGE_TIMEOUT, - //&DualModeController::WriteExtendedPageTimeout}, - //{OpCode::READ_EXTENDED_INQUIRY_LENGTH, - //&DualModeController::ReadExtendedInquiryLength}, - //{OpCode::WRITE_EXTENDED_INQUIRY_LENGTH, - //&DualModeController::WriteExtendedInquiryLength}, - //{OpCode::SET_ECOSYSTEM_BASE_INTERVAL, - //&DualModeController::SetEcosystemBaseInterval}, - //{OpCode::CONFIGURE_DATA_PATH, &DualModeController::ConfigureDataPath}, - //{OpCode::SET_MIN_ENCRYPTION_KEY_SIZE, - //&DualModeController::SetMinEncryptionKeySize}, - - // INFORMATIONAL_PARAMETERS - {OpCode::READ_LOCAL_VERSION_INFORMATION, - &DualModeController::ReadLocalVersionInformation}, - {OpCode::READ_LOCAL_SUPPORTED_COMMANDS, - &DualModeController::ReadLocalSupportedCommands}, - {OpCode::READ_LOCAL_SUPPORTED_FEATURES, - &DualModeController::ReadLocalSupportedFeatures}, - {OpCode::READ_LOCAL_EXTENDED_FEATURES, - &DualModeController::ReadLocalExtendedFeatures}, - {OpCode::READ_BUFFER_SIZE, &DualModeController::ReadBufferSize}, - {OpCode::READ_BD_ADDR, &DualModeController::ReadBdAddr}, - //{OpCode::READ_DATA_BLOCK_SIZE, - //&DualModeController::ReadDataBlockSize}, - {OpCode::READ_LOCAL_SUPPORTED_CODECS_V1, - &DualModeController::ReadLocalSupportedCodecsV1}, - //{OpCode::READ_LOCAL_SIMPLE_PAIRING_OPTIONS, - //&DualModeController::ReadLocalSimplePairingOptions}, - //{OpCode::READ_LOCAL_SUPPORTED_CODECS_V2, - //&DualModeController::ReadLocalSupportedCodecsV2}, - //{OpCode::READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES, - //&DualModeController::ReadLocalSupportedCodecCapabilities}, - //{OpCode::READ_LOCAL_SUPPORTED_CONTROLLER_DELAY, - //&DualModeController::ReadLocalSupportedControllerDelay}, - - // STATUS_PARAMETERS - {OpCode::READ_FAILED_CONTACT_COUNTER, - &DualModeController::ReadFailedContactCounter}, - {OpCode::RESET_FAILED_CONTACT_COUNTER, - &DualModeController::ResetFailedContactCounter}, - //{OpCode::READ_LINK_QUALITY, &DualModeController::ReadLinkQuality}, - {OpCode::READ_RSSI, &DualModeController::ReadRssi}, - //{OpCode::READ_AFH_CHANNEL_MAP, - //&DualModeController::ReadAfhChannelMap}, - //{OpCode::READ_CLOCK, &DualModeController::ReadClock}, - {OpCode::READ_ENCRYPTION_KEY_SIZE, - &DualModeController::ReadEncryptionKeySize}, - //{OpCode::GET_MWS_TRANSPORT_LAYER_CONFIGURATION, - //&DualModeController::GetMwsTransportLayerConfiguration}, - //{OpCode::SET_TRIGGERED_CLOCK_CAPTURE, - //&DualModeController::SetTriggeredClockCapture}, - - // TESTING - {OpCode::READ_LOOPBACK_MODE, &DualModeController::ReadLoopbackMode}, - {OpCode::WRITE_LOOPBACK_MODE, &DualModeController::WriteLoopbackMode}, - //{OpCode::ENABLE_DEVICE_UNDER_TEST_MODE, - //&DualModeController::EnableDeviceUnderTestMode}, - //{OpCode::WRITE_SIMPLE_PAIRING_DEBUG_MODE, - //&DualModeController::WriteSimplePairingDebugMode}, - //{OpCode::WRITE_SECURE_CONNECTIONS_TEST_MODE, - //&DualModeController::WriteSecureConnectionsTestMode}, - - // LE_CONTROLLER - {OpCode::LE_SET_EVENT_MASK, &DualModeController::LeSetEventMask}, - {OpCode::LE_READ_BUFFER_SIZE_V1, - &DualModeController::LeReadBufferSizeV1}, - {OpCode::LE_READ_LOCAL_SUPPORTED_FEATURES, - &DualModeController::LeReadLocalSupportedFeatures}, - {OpCode::LE_SET_RANDOM_ADDRESS, - &DualModeController::LeSetRandomAddress}, - {OpCode::LE_SET_ADVERTISING_PARAMETERS, - &DualModeController::LeSetAdvertisingParameters}, - {OpCode::LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER, - &DualModeController::LeReadAdvertisingPhysicalChannelTxPower}, - {OpCode::LE_SET_ADVERTISING_DATA, - &DualModeController::LeSetAdvertisingData}, - {OpCode::LE_SET_SCAN_RESPONSE_DATA, - &DualModeController::LeSetScanResponseData}, - {OpCode::LE_SET_ADVERTISING_ENABLE, - &DualModeController::LeSetAdvertisingEnable}, - {OpCode::LE_SET_SCAN_PARAMETERS, - &DualModeController::LeSetScanParameters}, - {OpCode::LE_SET_SCAN_ENABLE, &DualModeController::LeSetScanEnable}, - {OpCode::LE_CREATE_CONNECTION, &DualModeController::LeCreateConnection}, - {OpCode::LE_CREATE_CONNECTION_CANCEL, - &DualModeController::LeCreateConnectionCancel}, - {OpCode::LE_READ_FILTER_ACCEPT_LIST_SIZE, - &DualModeController::LeReadFilterAcceptListSize}, - {OpCode::LE_CLEAR_FILTER_ACCEPT_LIST, - &DualModeController::LeClearFilterAcceptList}, - {OpCode::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST, - &DualModeController::LeAddDeviceToFilterAcceptList}, - {OpCode::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, - &DualModeController::LeRemoveDeviceFromFilterAcceptList}, - {OpCode::LE_CONNECTION_UPDATE, &DualModeController::LeConnectionUpdate}, - //{OpCode::LE_SET_HOST_CHANNEL_CLASSIFICATION, - //&DualModeController::LeSetHostChannelClassification}, - //{OpCode::LE_READ_CHANNEL_MAP, &DualModeController::LeReadChannelMap}, - {OpCode::LE_READ_REMOTE_FEATURES, - &DualModeController::LeReadRemoteFeatures}, - {OpCode::LE_ENCRYPT, &DualModeController::LeEncrypt}, - {OpCode::LE_RAND, &DualModeController::LeRand}, - {OpCode::LE_START_ENCRYPTION, &DualModeController::LeStartEncryption}, - {OpCode::LE_LONG_TERM_KEY_REQUEST_REPLY, - &DualModeController::LeLongTermKeyRequestReply}, - {OpCode::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY, - &DualModeController::LeLongTermKeyRequestNegativeReply}, - {OpCode::LE_READ_SUPPORTED_STATES, - &DualModeController::LeReadSupportedStates}, - //{OpCode::LE_RECEIVER_TEST_V1, &DualModeController::LeReceiverTestV1}, - //{OpCode::LE_TRANSMITTER_TEST_V1, - //&DualModeController::LeTransmitterTestV1}, - //{OpCode::LE_TEST_END, &DualModeController::LeTestEnd}, - {OpCode::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, - &DualModeController::LeRemoteConnectionParameterRequestReply}, - {OpCode::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, - &DualModeController::LeRemoteConnectionParameterRequestNegativeReply}, - //{OpCode::LE_SET_DATA_LENGTH, &DualModeController::LeSetDataLength}, - {OpCode::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, - &DualModeController::LeReadSuggestedDefaultDataLength}, - {OpCode::LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, - &DualModeController::LeWriteSuggestedDefaultDataLength}, - //{OpCode::LE_READ_LOCAL_P_256_PUBLIC_KEY, - //&DualModeController::LeReadLocalP256PublicKey}, - //{OpCode::LE_GENERATE_DHKEY_V1, - //&DualModeController::LeGenerateDhkeyV1}, - {OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST, - &DualModeController::LeAddDeviceToResolvingList}, - {OpCode::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, - &DualModeController::LeRemoveDeviceFromResolvingList}, - {OpCode::LE_CLEAR_RESOLVING_LIST, - &DualModeController::LeClearResolvingList}, - {OpCode::LE_READ_RESOLVING_LIST_SIZE, - &DualModeController::LeReadResolvingListSize}, - {OpCode::LE_READ_PEER_RESOLVABLE_ADDRESS, - &DualModeController::LeReadPeerResolvableAddress}, - {OpCode::LE_READ_LOCAL_RESOLVABLE_ADDRESS, - &DualModeController::LeReadLocalResolvableAddress}, - {OpCode::LE_SET_ADDRESS_RESOLUTION_ENABLE, - &DualModeController::LeSetAddressResolutionEnable}, - {OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, - &DualModeController::LeSetResolvablePrivateAddressTimeout}, - {OpCode::LE_READ_MAXIMUM_DATA_LENGTH, - &DualModeController::LeReadMaximumDataLength}, - {OpCode::LE_READ_PHY, &DualModeController::LeReadPhy}, - {OpCode::LE_SET_DEFAULT_PHY, &DualModeController::LeSetDefaultPhy}, - {OpCode::LE_SET_PHY, &DualModeController::LeSetPhy}, - //{OpCode::LE_RECEIVER_TEST_V2, &DualModeController::LeReceiverTestV2}, - //{OpCode::LE_TRANSMITTER_TEST_V2, - //&DualModeController::LeTransmitterTestV2}, - {OpCode::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, - &DualModeController::LeSetAdvertisingSetRandomAddress}, - {OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS, - &DualModeController::LeSetExtendedAdvertisingParameters}, - {OpCode::LE_SET_EXTENDED_ADVERTISING_DATA, - &DualModeController::LeSetExtendedAdvertisingData}, - {OpCode::LE_SET_EXTENDED_SCAN_RESPONSE_DATA, - &DualModeController::LeSetExtendedScanResponseData}, - {OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE, - &DualModeController::LeSetExtendedAdvertisingEnable}, - {OpCode::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, - &DualModeController::LeReadMaximumAdvertisingDataLength}, - {OpCode::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, - &DualModeController::LeReadNumberOfSupportedAdvertisingSets}, - {OpCode::LE_REMOVE_ADVERTISING_SET, - &DualModeController::LeRemoveAdvertisingSet}, - {OpCode::LE_CLEAR_ADVERTISING_SETS, - &DualModeController::LeClearAdvertisingSets}, - {OpCode::LE_SET_PERIODIC_ADVERTISING_PARAMETERS, - &DualModeController::LeSetPeriodicAdvertisingParameters}, - {OpCode::LE_SET_PERIODIC_ADVERTISING_DATA, - &DualModeController::LeSetPeriodicAdvertisingData}, - {OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE, - &DualModeController::LeSetPeriodicAdvertisingEnable}, - {OpCode::LE_SET_EXTENDED_SCAN_PARAMETERS, - &DualModeController::LeSetExtendedScanParameters}, - {OpCode::LE_SET_EXTENDED_SCAN_ENABLE, - &DualModeController::LeSetExtendedScanEnable}, - {OpCode::LE_EXTENDED_CREATE_CONNECTION, - &DualModeController::LeExtendedCreateConnection}, - {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC, - &DualModeController::LePeriodicAdvertisingCreateSync}, - {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, - &DualModeController::LePeriodicAdvertisingCreateSyncCancel}, - {OpCode::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC, - &DualModeController::LePeriodicAdvertisingTerminateSync}, - {OpCode::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, - &DualModeController::LeAddDeviceToPeriodicAdvertiserList}, - {OpCode::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, - &DualModeController::LeRemoveDeviceFromPeriodicAdvertiserList}, - {OpCode::LE_CLEAR_PERIODIC_ADVERTISER_LIST, - &DualModeController::LeClearPeriodicAdvertiserList}, - {OpCode::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, - &DualModeController::LeReadPeriodicAdvertiserListSize}, - //{OpCode::LE_READ_TRANSMIT_POWER, - //&DualModeController::LeReadTransmitPower}, - //{OpCode::LE_READ_RF_PATH_COMPENSATION_POWER, - //&DualModeController::LeReadRfPathCompensationPower}, - //{OpCode::LE_WRITE_RF_PATH_COMPENSATION_POWER, - //&DualModeController::LeWriteRfPathCompensationPower}, - {OpCode::LE_SET_PRIVACY_MODE, &DualModeController::LeSetPrivacyMode}, - //{OpCode::LE_RECEIVER_TEST_V3, &DualModeController::LeReceiverTestV3}, - //{OpCode::LE_TRANSMITTER_TEST_V3, - //&DualModeController::LeTransmitterTestV3}, - //{OpCode::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS, - //&DualModeController::LeSetConnectionlessCteTransmitParameters}, - //{OpCode::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_ENABLE, - //&DualModeController::LeSetConnectionlessCteTransmitEnable}, - //{OpCode::LE_SET_CONNECTIONLESS_IQ_SAMPLING_ENABLE, - //&DualModeController::LeSetConnectionlessIqSamplingEnable}, - //{OpCode::LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS, - //&DualModeController::LeSetConnectionCteReceiveParameters}, - //{OpCode::LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS, - //&DualModeController::LeSetConnectionCteTransmitParameters}, - //{OpCode::LE_CONNECTION_CTE_REQUEST_ENABLE, - //&DualModeController::LeConnectionCteRequestEnable}, - //{OpCode::LE_CONNECTION_CTE_RESPONSE_ENABLE, - //&DualModeController::LeConnectionCteResponseEnable}, - //{OpCode::LE_READ_ANTENNA_INFORMATION, - //&DualModeController::LeReadAntennaInformation}, - //{OpCode::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, - //&DualModeController::LeSetPeriodicAdvertisingReceiveEnable}, - //{OpCode::LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, - //&DualModeController::LePeriodicAdvertisingSyncTransfer}, - //{OpCode::LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, - //&DualModeController::LePeriodicAdvertisingSetInfoTransfer}, - //{OpCode::LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, - //&DualModeController::LeSetPeriodicAdvertisingSyncTransferParameters}, - //{OpCode::LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, - //&DualModeController::LeSetDefaultPeriodicAdvertisingSyncTransferParameters}, - //{OpCode::LE_GENERATE_DHKEY_V2, - //&DualModeController::LeGenerateDhkeyV2}, - //{OpCode::LE_MODIFY_SLEEP_CLOCK_ACCURACY, - //&DualModeController::LeModifySleepClockAccuracy}, - {OpCode::LE_READ_BUFFER_SIZE_V2, - &DualModeController::LeReadBufferSizeV2}, - //{OpCode::LE_READ_ISO_TX_SYNC, &DualModeController::LeReadIsoTxSync}, - {OpCode::LE_SET_CIG_PARAMETERS, &DualModeController::ForwardToLl}, - {OpCode::LE_SET_CIG_PARAMETERS_TEST, &DualModeController::ForwardToLl}, - {OpCode::LE_CREATE_CIS, &DualModeController::ForwardToLl}, - {OpCode::LE_REMOVE_CIG, &DualModeController::ForwardToLl}, - {OpCode::LE_ACCEPT_CIS_REQUEST, &DualModeController::ForwardToLl}, - {OpCode::LE_REJECT_CIS_REQUEST, &DualModeController::ForwardToLl}, - //{OpCode::LE_CREATE_BIG, &DualModeController::LeCreateBig}, - //{OpCode::LE_CREATE_BIG_TEST, &DualModeController::LeCreateBigTest}, - //{OpCode::LE_TERMINATE_BIG, &DualModeController::LeTerminateBig}, - //{OpCode::LE_BIG_CREATE_SYNC, &DualModeController::LeBigCreateSync}, - //{OpCode::LE_BIG_TERMINATE_SYNC, - //&DualModeController::LeBigTerminateSync}, - {OpCode::LE_REQUEST_PEER_SCA, &DualModeController::LeRequestPeerSca}, - {OpCode::LE_SETUP_ISO_DATA_PATH, &DualModeController::ForwardToLl}, - {OpCode::LE_REMOVE_ISO_DATA_PATH, &DualModeController::ForwardToLl}, - //{OpCode::LE_ISO_TRANSMIT_TEST, - //&DualModeController::LeIsoTransmitTest}, - //{OpCode::LE_ISO_RECEIVE_TEST, &DualModeController::LeIsoReceiveTest}, - //{OpCode::LE_ISO_READ_TEST_COUNTERS, - //&DualModeController::LeIsoReadTestCounters}, - //{OpCode::LE_ISO_TEST_END, &DualModeController::LeIsoTestEnd}, - {OpCode::LE_SET_HOST_FEATURE, &DualModeController::LeSetHostFeature}, - //{OpCode::LE_READ_ISO_LINK_QUALITY, - //&DualModeController::LeReadIsoLinkQuality}, - //{OpCode::LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL, - //&DualModeController::LeEnhancedReadTransmitPowerLevel}, - //{OpCode::LE_READ_REMOTE_TRANSMIT_POWER_LEVEL, - //&DualModeController::LeReadRemoteTransmitPowerLevel}, - //{OpCode::LE_SET_PATH_LOSS_REPORTING_PARAMETERS, - //&DualModeController::LeSetPathLossReportingParameters}, - //{OpCode::LE_SET_PATH_LOSS_REPORTING_ENABLE, - //&DualModeController::LeSetPathLossReportingEnable}, - //{OpCode::LE_SET_TRANSMIT_POWER_REPORTING_ENABLE, - //&DualModeController::LeSetTransmitPowerReportingEnable}, - //{OpCode::LE_TRANSMITTER_TEST_V4, - //&DualModeController::LeTransmitterTestV4}, - //{OpCode::LE_SET_DATA_RELATED_ADDRESS_CHANGES, - //&DualModeController::LeSetDataRelatedAddressChanges}, - //{OpCode::LE_SET_DEFAULT_SUBRATE, - //&DualModeController::LeSetDefaultSubrate}, - //{OpCode::LE_SUBRATE_REQUEST, &DualModeController::LeSubrateRequest}, - - // VENDOR - {OpCode(CSR_VENDOR), &DualModeController::CsrVendorCommand}, - {OpCode::LE_GET_VENDOR_CAPABILITIES, - &DualModeController::LeGetVendorCapabilities}, - {OpCode::LE_BATCH_SCAN, &DualModeController::LeBatchScan}, - {OpCode::LE_APCF, &DualModeController::LeApcf}, - {OpCode::LE_GET_CONTROLLER_ACTIVITY_ENERGY_INFO, - &DualModeController::LeGetControllerActivityEnergyInfo}, - {OpCode::LE_EX_SET_SCAN_PARAMETERS, - &DualModeController::LeExSetScanParameters}, - {OpCode::GET_CONTROLLER_DEBUG_INFO, - &DualModeController::GetControllerDebugInfo}}; + DualModeController::hci_command_handlers_{ + // LINK_CONTROL + {OpCode::INQUIRY, &DualModeController::Inquiry}, + {OpCode::INQUIRY_CANCEL, &DualModeController::InquiryCancel}, + //{OpCode::PERIODIC_INQUIRY_MODE, + //&DualModeController::PeriodicInquiryMode}, + //{OpCode::EXIT_PERIODIC_INQUIRY_MODE, + //&DualModeController::ExitPeriodicInquiryMode}, + {OpCode::CREATE_CONNECTION, &DualModeController::CreateConnection}, + {OpCode::DISCONNECT, &DualModeController::Disconnect}, + {OpCode::ADD_SCO_CONNECTION, &DualModeController::AddScoConnection}, + {OpCode::CREATE_CONNECTION_CANCEL, &DualModeController::CreateConnectionCancel}, + {OpCode::ACCEPT_CONNECTION_REQUEST, &DualModeController::AcceptConnectionRequest}, + {OpCode::REJECT_CONNECTION_REQUEST, &DualModeController::RejectConnectionRequest}, + {OpCode::LINK_KEY_REQUEST_REPLY, &DualModeController::ForwardToLm}, + {OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY, &DualModeController::ForwardToLm}, + {OpCode::PIN_CODE_REQUEST_REPLY, &DualModeController::ForwardToLm}, + {OpCode::PIN_CODE_REQUEST_NEGATIVE_REPLY, &DualModeController::ForwardToLm}, + {OpCode::CHANGE_CONNECTION_PACKET_TYPE, + &DualModeController::ChangeConnectionPacketType}, + {OpCode::AUTHENTICATION_REQUESTED, &DualModeController::ForwardToLm}, + {OpCode::SET_CONNECTION_ENCRYPTION, &DualModeController::ForwardToLm}, + {OpCode::CHANGE_CONNECTION_LINK_KEY, &DualModeController::ChangeConnectionLinkKey}, + {OpCode::CENTRAL_LINK_KEY, &DualModeController::CentralLinkKey}, + {OpCode::REMOTE_NAME_REQUEST, &DualModeController::RemoteNameRequest}, + //{OpCode::REMOTE_NAME_REQUEST_CANCEL, + //&DualModeController::RemoteNameRequestCancel}, + {OpCode::READ_REMOTE_SUPPORTED_FEATURES, + &DualModeController::ReadRemoteSupportedFeatures}, + {OpCode::READ_REMOTE_EXTENDED_FEATURES, + &DualModeController::ReadRemoteExtendedFeatures}, + {OpCode::READ_REMOTE_VERSION_INFORMATION, + &DualModeController::ReadRemoteVersionInformation}, + {OpCode::READ_CLOCK_OFFSET, &DualModeController::ReadClockOffset}, + //{OpCode::READ_LMP_HANDLE, &DualModeController::ReadLmpHandle}, + {OpCode::SETUP_SYNCHRONOUS_CONNECTION, + &DualModeController::SetupSynchronousConnection}, + {OpCode::ACCEPT_SYNCHRONOUS_CONNECTION, + &DualModeController::AcceptSynchronousConnection}, + {OpCode::REJECT_SYNCHRONOUS_CONNECTION, + &DualModeController::RejectSynchronousConnection}, + {OpCode::IO_CAPABILITY_REQUEST_REPLY, &DualModeController::ForwardToLm}, + {OpCode::USER_CONFIRMATION_REQUEST_REPLY, &DualModeController::ForwardToLm}, + {OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, + &DualModeController::ForwardToLm}, + {OpCode::USER_PASSKEY_REQUEST_REPLY, &DualModeController::ForwardToLm}, + {OpCode::USER_PASSKEY_REQUEST_NEGATIVE_REPLY, &DualModeController::ForwardToLm}, + {OpCode::REMOTE_OOB_DATA_REQUEST_REPLY, &DualModeController::ForwardToLm}, + {OpCode::REMOTE_OOB_DATA_REQUEST_NEGATIVE_REPLY, &DualModeController::ForwardToLm}, + {OpCode::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, &DualModeController::ForwardToLm}, + {OpCode::ENHANCED_SETUP_SYNCHRONOUS_CONNECTION, + &DualModeController::EnhancedSetupSynchronousConnection}, + {OpCode::ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION, + &DualModeController::EnhancedAcceptSynchronousConnection}, + //{OpCode::TRUNCATED_PAGE, &DualModeController::TruncatedPage}, + //{OpCode::TRUNCATED_PAGE_CANCEL, + //&DualModeController::TruncatedPageCancel}, + //{OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST, + //&DualModeController::SetConnectionlessPeripheralBroadcast}, + //{OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_RECEIVE, + //&DualModeController::SetConnectionlessPeripheralBroadcastReceive}, + //{OpCode::START_SYNCHRONIZATION_TRAIN, + //&DualModeController::StartSynchronizationTrain}, + //{OpCode::RECEIVE_SYNCHRONIZATION_TRAIN, + //&DualModeController::ReceiveSynchronizationTrain}, + {OpCode::REMOTE_OOB_EXTENDED_DATA_REQUEST_REPLY, &DualModeController::ForwardToLm}, + + // LINK_POLICY + {OpCode::HOLD_MODE, &DualModeController::HoldMode}, + {OpCode::SNIFF_MODE, &DualModeController::SniffMode}, + {OpCode::EXIT_SNIFF_MODE, &DualModeController::ExitSniffMode}, + {OpCode::QOS_SETUP, &DualModeController::QosSetup}, + {OpCode::ROLE_DISCOVERY, &DualModeController::RoleDiscovery}, + {OpCode::SWITCH_ROLE, &DualModeController::SwitchRole}, + {OpCode::READ_LINK_POLICY_SETTINGS, &DualModeController::ReadLinkPolicySettings}, + {OpCode::WRITE_LINK_POLICY_SETTINGS, &DualModeController::WriteLinkPolicySettings}, + {OpCode::READ_DEFAULT_LINK_POLICY_SETTINGS, + &DualModeController::ReadDefaultLinkPolicySettings}, + {OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS, + &DualModeController::WriteDefaultLinkPolicySettings}, + {OpCode::FLOW_SPECIFICATION, &DualModeController::FlowSpecification}, + {OpCode::SNIFF_SUBRATING, &DualModeController::SniffSubrating}, + + // CONTROLLER_AND_BASEBAND + {OpCode::SET_EVENT_MASK, &DualModeController::SetEventMask}, + {OpCode::RESET, &DualModeController::Reset}, + {OpCode::SET_EVENT_FILTER, &DualModeController::SetEventFilter}, + //{OpCode::FLUSH, &DualModeController::Flush}, + //{OpCode::READ_PIN_TYPE, &DualModeController::ReadPinType}, + //{OpCode::WRITE_PIN_TYPE, &DualModeController::WritePinType}, + //{OpCode::READ_STORED_LINK_KEY, + //&DualModeController::ReadStoredLinkKey}, + //{OpCode::WRITE_STORED_LINK_KEY, + //&DualModeController::WriteStoredLinkKey}, + {OpCode::DELETE_STORED_LINK_KEY, &DualModeController::DeleteStoredLinkKey}, + {OpCode::WRITE_LOCAL_NAME, &DualModeController::WriteLocalName}, + {OpCode::READ_LOCAL_NAME, &DualModeController::ReadLocalName}, + {OpCode::READ_CONNECTION_ACCEPT_TIMEOUT, + &DualModeController::ReadConnectionAcceptTimeout}, + {OpCode::WRITE_CONNECTION_ACCEPT_TIMEOUT, + &DualModeController::WriteConnectionAcceptTimeout}, + {OpCode::READ_PAGE_TIMEOUT, &DualModeController::ReadPageTimeout}, + {OpCode::WRITE_PAGE_TIMEOUT, &DualModeController::WritePageTimeout}, + {OpCode::READ_SCAN_ENABLE, &DualModeController::ReadScanEnable}, + {OpCode::WRITE_SCAN_ENABLE, &DualModeController::WriteScanEnable}, + {OpCode::READ_PAGE_SCAN_ACTIVITY, &DualModeController::ReadPageScanActivity}, + {OpCode::WRITE_PAGE_SCAN_ACTIVITY, &DualModeController::WritePageScanActivity}, + {OpCode::READ_INQUIRY_SCAN_ACTIVITY, &DualModeController::ReadInquiryScanActivity}, + {OpCode::WRITE_INQUIRY_SCAN_ACTIVITY, + &DualModeController::WriteInquiryScanActivity}, + {OpCode::READ_AUTHENTICATION_ENABLE, &DualModeController::ReadAuthenticationEnable}, + {OpCode::WRITE_AUTHENTICATION_ENABLE, + &DualModeController::WriteAuthenticationEnable}, + {OpCode::READ_CLASS_OF_DEVICE, &DualModeController::ReadClassOfDevice}, + {OpCode::WRITE_CLASS_OF_DEVICE, &DualModeController::WriteClassOfDevice}, + {OpCode::READ_VOICE_SETTING, &DualModeController::ReadVoiceSetting}, + {OpCode::WRITE_VOICE_SETTING, &DualModeController::WriteVoiceSetting}, + //{OpCode::READ_AUTOMATIC_FLUSH_TIMEOUT, + //&DualModeController::ReadAutomaticFlushTimeout}, + //{OpCode::WRITE_AUTOMATIC_FLUSH_TIMEOUT, + //&DualModeController::WriteAutomaticFlushTimeout}, + //{OpCode::READ_NUM_BROADCAST_RETRANSMITS, + //&DualModeController::ReadNumBroadcastRetransmits}, + //{OpCode::WRITE_NUM_BROADCAST_RETRANSMITS, + //&DualModeController::WriteNumBroadcastRetransmits}, + //{OpCode::READ_HOLD_MODE_ACTIVITY, + //&DualModeController::ReadHoldModeActivity}, + //{OpCode::WRITE_HOLD_MODE_ACTIVITY, + //&DualModeController::WriteHoldModeActivity}, + {OpCode::READ_TRANSMIT_POWER_LEVEL, &DualModeController::ReadTransmitPowerLevel}, + {OpCode::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE, + &DualModeController::ReadSynchronousFlowControlEnable}, + {OpCode::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE, + &DualModeController::WriteSynchronousFlowControlEnable}, + //{OpCode::SET_CONTROLLER_TO_HOST_FLOW_CONTROL, + //&DualModeController::SetControllerToHostFlowControl}, + {OpCode::HOST_BUFFER_SIZE, &DualModeController::HostBufferSize}, + //{OpCode::HOST_NUMBER_OF_COMPLETED_PACKETS, + //&DualModeController::HostNumberOfCompletedPackets}, + //{OpCode::READ_LINK_SUPERVISION_TIMEOUT, + //&DualModeController::ReadLinkSupervisionTimeout}, + {OpCode::WRITE_LINK_SUPERVISION_TIMEOUT, + &DualModeController::WriteLinkSupervisionTimeout}, + {OpCode::READ_NUMBER_OF_SUPPORTED_IAC, + &DualModeController::ReadNumberOfSupportedIac}, + {OpCode::READ_CURRENT_IAC_LAP, &DualModeController::ReadCurrentIacLap}, + {OpCode::WRITE_CURRENT_IAC_LAP, &DualModeController::WriteCurrentIacLap}, + //{OpCode::SET_AFH_HOST_CHANNEL_CLASSIFICATION, + //&DualModeController::SetAfhHostChannelClassification}, + {OpCode::READ_INQUIRY_SCAN_TYPE, &DualModeController::ReadInquiryScanType}, + {OpCode::WRITE_INQUIRY_SCAN_TYPE, &DualModeController::WriteInquiryScanType}, + {OpCode::READ_INQUIRY_MODE, &DualModeController::ReadInquiryMode}, + {OpCode::WRITE_INQUIRY_MODE, &DualModeController::WriteInquiryMode}, + {OpCode::READ_PAGE_SCAN_TYPE, &DualModeController::ReadPageScanType}, + {OpCode::WRITE_PAGE_SCAN_TYPE, &DualModeController::WritePageScanType}, + //{OpCode::READ_AFH_CHANNEL_ASSESSMENT_MODE, + //&DualModeController::ReadAfhChannelAssessmentMode}, + //{OpCode::WRITE_AFH_CHANNEL_ASSESSMENT_MODE, + //&DualModeController::WriteAfhChannelAssessmentMode}, + //{OpCode::READ_EXTENDED_INQUIRY_RESPONSE, + //&DualModeController::ReadExtendedInquiryResponse}, + {OpCode::WRITE_EXTENDED_INQUIRY_RESPONSE, + &DualModeController::WriteExtendedInquiryResponse}, + {OpCode::REFRESH_ENCRYPTION_KEY, &DualModeController::RefreshEncryptionKey}, + //{OpCode::READ_SIMPLE_PAIRING_MODE, + //&DualModeController::ReadSimplePairingMode}, + {OpCode::WRITE_SIMPLE_PAIRING_MODE, &DualModeController::WriteSimplePairingMode}, + {OpCode::READ_LOCAL_OOB_DATA, &DualModeController::ReadLocalOobData}, + {OpCode::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL, + &DualModeController::ReadInquiryResponseTransmitPowerLevel}, + //{OpCode::WRITE_INQUIRY_TRANSMIT_POWER_LEVEL, + //&DualModeController::WriteInquiryTransmitPowerLevel}, + //{OpCode::READ_DEFAULT_ERRONEOUS_DATA_REPORTING, + //&DualModeController::ReadDefaultErroneousDataReporting}, + //{OpCode::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING, + //&DualModeController::WriteDefaultErroneousDataReporting}, + {OpCode::ENHANCED_FLUSH, &DualModeController::EnhancedFlush}, + {OpCode::SEND_KEYPRESS_NOTIFICATION, &DualModeController::ForwardToLm}, + {OpCode::SET_EVENT_MASK_PAGE_2, &DualModeController::SetEventMaskPage2}, + //{OpCode::READ_FLOW_CONTROL_MODE, + //&DualModeController::ReadFlowControlMode}, + //{OpCode::WRITE_FLOW_CONTROL_MODE, + //&DualModeController::WriteFlowControlMode}, + {OpCode::READ_ENHANCED_TRANSMIT_POWER_LEVEL, + &DualModeController::ReadEnhancedTransmitPowerLevel}, + //{OpCode::READ_LE_HOST_SUPPORT, + //&DualModeController::ReadLeHostSupport}, + {OpCode::WRITE_LE_HOST_SUPPORT, &DualModeController::WriteLeHostSupport}, + //{OpCode::SET_MWS_CHANNEL_PARAMETERS, + //&DualModeController::SetMwsChannelParameters}, + //{OpCode::SET_EXTERNAL_FRAME_CONFIGURATION, + //&DualModeController::SetExternalFrameConfiguration}, + //{OpCode::SET_MWS_SIGNALING, &DualModeController::SetMwsSignaling}, + //{OpCode::SET_MWS_TRANSPORT_LAYER, + //&DualModeController::SetMwsTransportLayer}, + //{OpCode::SET_MWS_SCAN_FREQUENCY_TABLE, + //&DualModeController::SetMwsScanFrequencyTable}, + //{OpCode::SET_MWS_PATTERN_CONFIGURATION, + //&DualModeController::SetMwsPatternConfiguration}, + //{OpCode::SET_RESERVED_LT_ADDR, + //&DualModeController::SetReservedLtAddr}, + //{OpCode::DELETE_RESERVED_LT_ADDR, + //&DualModeController::DeleteReservedLtAddr}, + //{OpCode::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA, + //&DualModeController::SetConnectionlessPeripheralBroadcastData}, + //{OpCode::READ_SYNCHRONIZATION_TRAIN_PARAMETERS, + //&DualModeController::ReadSynchronizationTrainParameters}, + //{OpCode::WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS, + //&DualModeController::WriteSynchronizationTrainParameters}, + //{OpCode::READ_SECURE_CONNECTIONS_HOST_SUPPORT, + //&DualModeController::ReadSecureConnectionsHostSupport}, + {OpCode::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, + &DualModeController::WriteSecureConnectionsHostSupport}, + //{OpCode::READ_AUTHENTICATED_PAYLOAD_TIMEOUT, + //&DualModeController::ReadAuthenticatedPayloadTimeout}, + //{OpCode::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT, + //&DualModeController::WriteAuthenticatedPayloadTimeout}, + {OpCode::READ_LOCAL_OOB_EXTENDED_DATA, + &DualModeController::ReadLocalOobExtendedData}, + //{OpCode::READ_EXTENDED_PAGE_TIMEOUT, + //&DualModeController::ReadExtendedPageTimeout}, + //{OpCode::WRITE_EXTENDED_PAGE_TIMEOUT, + //&DualModeController::WriteExtendedPageTimeout}, + //{OpCode::READ_EXTENDED_INQUIRY_LENGTH, + //&DualModeController::ReadExtendedInquiryLength}, + //{OpCode::WRITE_EXTENDED_INQUIRY_LENGTH, + //&DualModeController::WriteExtendedInquiryLength}, + //{OpCode::SET_ECOSYSTEM_BASE_INTERVAL, + //&DualModeController::SetEcosystemBaseInterval}, + //{OpCode::CONFIGURE_DATA_PATH, &DualModeController::ConfigureDataPath}, + //{OpCode::SET_MIN_ENCRYPTION_KEY_SIZE, + //&DualModeController::SetMinEncryptionKeySize}, + + // INFORMATIONAL_PARAMETERS + {OpCode::READ_LOCAL_VERSION_INFORMATION, + &DualModeController::ReadLocalVersionInformation}, + {OpCode::READ_LOCAL_SUPPORTED_COMMANDS, + &DualModeController::ReadLocalSupportedCommands}, + {OpCode::READ_LOCAL_SUPPORTED_FEATURES, + &DualModeController::ReadLocalSupportedFeatures}, + {OpCode::READ_LOCAL_EXTENDED_FEATURES, + &DualModeController::ReadLocalExtendedFeatures}, + {OpCode::READ_BUFFER_SIZE, &DualModeController::ReadBufferSize}, + {OpCode::READ_BD_ADDR, &DualModeController::ReadBdAddr}, + //{OpCode::READ_DATA_BLOCK_SIZE, + //&DualModeController::ReadDataBlockSize}, + {OpCode::READ_LOCAL_SUPPORTED_CODECS_V1, + &DualModeController::ReadLocalSupportedCodecsV1}, + //{OpCode::READ_LOCAL_SIMPLE_PAIRING_OPTIONS, + //&DualModeController::ReadLocalSimplePairingOptions}, + //{OpCode::READ_LOCAL_SUPPORTED_CODECS_V2, + //&DualModeController::ReadLocalSupportedCodecsV2}, + //{OpCode::READ_LOCAL_SUPPORTED_CODEC_CAPABILITIES, + //&DualModeController::ReadLocalSupportedCodecCapabilities}, + //{OpCode::READ_LOCAL_SUPPORTED_CONTROLLER_DELAY, + //&DualModeController::ReadLocalSupportedControllerDelay}, + + // STATUS_PARAMETERS + {OpCode::READ_FAILED_CONTACT_COUNTER, + &DualModeController::ReadFailedContactCounter}, + {OpCode::RESET_FAILED_CONTACT_COUNTER, + &DualModeController::ResetFailedContactCounter}, + //{OpCode::READ_LINK_QUALITY, &DualModeController::ReadLinkQuality}, + {OpCode::READ_RSSI, &DualModeController::ReadRssi}, + //{OpCode::READ_AFH_CHANNEL_MAP, + //&DualModeController::ReadAfhChannelMap}, + //{OpCode::READ_CLOCK, &DualModeController::ReadClock}, + {OpCode::READ_ENCRYPTION_KEY_SIZE, &DualModeController::ReadEncryptionKeySize}, + //{OpCode::GET_MWS_TRANSPORT_LAYER_CONFIGURATION, + //&DualModeController::GetMwsTransportLayerConfiguration}, + //{OpCode::SET_TRIGGERED_CLOCK_CAPTURE, + //&DualModeController::SetTriggeredClockCapture}, + + // TESTING + {OpCode::READ_LOOPBACK_MODE, &DualModeController::ReadLoopbackMode}, + {OpCode::WRITE_LOOPBACK_MODE, &DualModeController::WriteLoopbackMode}, + //{OpCode::ENABLE_DEVICE_UNDER_TEST_MODE, + //&DualModeController::EnableDeviceUnderTestMode}, + //{OpCode::WRITE_SIMPLE_PAIRING_DEBUG_MODE, + //&DualModeController::WriteSimplePairingDebugMode}, + //{OpCode::WRITE_SECURE_CONNECTIONS_TEST_MODE, + //&DualModeController::WriteSecureConnectionsTestMode}, + + // LE_CONTROLLER + {OpCode::LE_SET_EVENT_MASK, &DualModeController::LeSetEventMask}, + {OpCode::LE_READ_BUFFER_SIZE_V1, &DualModeController::LeReadBufferSizeV1}, + {OpCode::LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0, + &DualModeController::LeReadLocalSupportedFeaturesPage0}, + {OpCode::LE_SET_RANDOM_ADDRESS, &DualModeController::LeSetRandomAddress}, + {OpCode::LE_SET_ADVERTISING_PARAMETERS, + &DualModeController::LeSetAdvertisingParameters}, + {OpCode::LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER, + &DualModeController::LeReadAdvertisingPhysicalChannelTxPower}, + {OpCode::LE_SET_ADVERTISING_DATA, &DualModeController::LeSetAdvertisingData}, + {OpCode::LE_SET_SCAN_RESPONSE_DATA, &DualModeController::LeSetScanResponseData}, + {OpCode::LE_SET_ADVERTISING_ENABLE, &DualModeController::LeSetAdvertisingEnable}, + {OpCode::LE_SET_SCAN_PARAMETERS, &DualModeController::LeSetScanParameters}, + {OpCode::LE_SET_SCAN_ENABLE, &DualModeController::LeSetScanEnable}, + {OpCode::LE_CREATE_CONNECTION, &DualModeController::LeCreateConnection}, + {OpCode::LE_CREATE_CONNECTION_CANCEL, + &DualModeController::LeCreateConnectionCancel}, + {OpCode::LE_READ_FILTER_ACCEPT_LIST_SIZE, + &DualModeController::LeReadFilterAcceptListSize}, + {OpCode::LE_CLEAR_FILTER_ACCEPT_LIST, &DualModeController::LeClearFilterAcceptList}, + {OpCode::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST, + &DualModeController::LeAddDeviceToFilterAcceptList}, + {OpCode::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, + &DualModeController::LeRemoveDeviceFromFilterAcceptList}, + {OpCode::LE_CONNECTION_UPDATE, &DualModeController::LeConnectionUpdate}, + //{OpCode::LE_SET_HOST_CHANNEL_CLASSIFICATION, + //&DualModeController::LeSetHostChannelClassification}, + //{OpCode::LE_READ_CHANNEL_MAP, &DualModeController::LeReadChannelMap}, + {OpCode::LE_READ_REMOTE_FEATURES_PAGE_0, + &DualModeController::LeReadRemoteFeaturesPage0}, + {OpCode::LE_ENCRYPT, &DualModeController::LeEncrypt}, + {OpCode::LE_RAND, &DualModeController::LeRand}, + {OpCode::LE_START_ENCRYPTION, &DualModeController::LeStartEncryption}, + {OpCode::LE_LONG_TERM_KEY_REQUEST_REPLY, + &DualModeController::LeLongTermKeyRequestReply}, + {OpCode::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY, + &DualModeController::LeLongTermKeyRequestNegativeReply}, + {OpCode::LE_READ_SUPPORTED_STATES, &DualModeController::LeReadSupportedStates}, + //{OpCode::LE_RECEIVER_TEST_V1, &DualModeController::LeReceiverTestV1}, + //{OpCode::LE_TRANSMITTER_TEST_V1, + //&DualModeController::LeTransmitterTestV1}, + //{OpCode::LE_TEST_END, &DualModeController::LeTestEnd}, + {OpCode::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY, + &DualModeController::LeRemoteConnectionParameterRequestReply}, + {OpCode::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY, + &DualModeController::LeRemoteConnectionParameterRequestNegativeReply}, + //{OpCode::LE_SET_DATA_LENGTH, &DualModeController::LeSetDataLength}, + {OpCode::LE_READ_SUGGESTED_DEFAULT_DATA_LENGTH, + &DualModeController::LeReadSuggestedDefaultDataLength}, + {OpCode::LE_WRITE_SUGGESTED_DEFAULT_DATA_LENGTH, + &DualModeController::LeWriteSuggestedDefaultDataLength}, + {OpCode::LE_READ_LOCAL_P_256_PUBLIC_KEY, + &DualModeController::LeReadLocalP256PublicKey}, + //{OpCode::LE_GENERATE_DHKEY_V1, + //&DualModeController::LeGenerateDhkeyV1}, + {OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST, + &DualModeController::LeAddDeviceToResolvingList}, + {OpCode::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, + &DualModeController::LeRemoveDeviceFromResolvingList}, + {OpCode::LE_CLEAR_RESOLVING_LIST, &DualModeController::LeClearResolvingList}, + {OpCode::LE_READ_RESOLVING_LIST_SIZE, &DualModeController::LeReadResolvingListSize}, + {OpCode::LE_READ_PEER_RESOLVABLE_ADDRESS, + &DualModeController::LeReadPeerResolvableAddress}, + {OpCode::LE_READ_LOCAL_RESOLVABLE_ADDRESS, + &DualModeController::LeReadLocalResolvableAddress}, + {OpCode::LE_SET_ADDRESS_RESOLUTION_ENABLE, + &DualModeController::LeSetAddressResolutionEnable}, + {OpCode::LE_SET_RESOLVABLE_PRIVATE_ADDRESS_TIMEOUT, + &DualModeController::LeSetResolvablePrivateAddressTimeout}, + {OpCode::LE_READ_MAXIMUM_DATA_LENGTH, &DualModeController::LeReadMaximumDataLength}, + {OpCode::LE_READ_PHY, &DualModeController::LeReadPhy}, + {OpCode::LE_SET_DEFAULT_PHY, &DualModeController::LeSetDefaultPhy}, + {OpCode::LE_SET_PHY, &DualModeController::LeSetPhy}, + //{OpCode::LE_RECEIVER_TEST_V2, &DualModeController::LeReceiverTestV2}, + //{OpCode::LE_TRANSMITTER_TEST_V2, + //&DualModeController::LeTransmitterTestV2}, + {OpCode::LE_SET_ADVERTISING_SET_RANDOM_ADDRESS, + &DualModeController::LeSetAdvertisingSetRandomAddress}, + {OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1, + &DualModeController::LeSetExtendedAdvertisingParametersV1}, + {OpCode::LE_SET_EXTENDED_ADVERTISING_DATA, + &DualModeController::LeSetExtendedAdvertisingData}, + {OpCode::LE_SET_EXTENDED_SCAN_RESPONSE_DATA, + &DualModeController::LeSetExtendedScanResponseData}, + {OpCode::LE_SET_EXTENDED_ADVERTISING_ENABLE, + &DualModeController::LeSetExtendedAdvertisingEnable}, + {OpCode::LE_READ_MAXIMUM_ADVERTISING_DATA_LENGTH, + &DualModeController::LeReadMaximumAdvertisingDataLength}, + {OpCode::LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS, + &DualModeController::LeReadNumberOfSupportedAdvertisingSets}, + {OpCode::LE_REMOVE_ADVERTISING_SET, &DualModeController::LeRemoveAdvertisingSet}, + {OpCode::LE_CLEAR_ADVERTISING_SETS, &DualModeController::LeClearAdvertisingSets}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1, + &DualModeController::LeSetPeriodicAdvertisingParametersV1}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_DATA, + &DualModeController::LeSetPeriodicAdvertisingData}, + {OpCode::LE_SET_PERIODIC_ADVERTISING_ENABLE, + &DualModeController::LeSetPeriodicAdvertisingEnable}, + {OpCode::LE_SET_EXTENDED_SCAN_PARAMETERS, + &DualModeController::LeSetExtendedScanParameters}, + {OpCode::LE_SET_EXTENDED_SCAN_ENABLE, &DualModeController::LeSetExtendedScanEnable}, + {OpCode::LE_EXTENDED_CREATE_CONNECTION_V1, + &DualModeController::LeExtendedCreateConnectionV1}, + {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC, + &DualModeController::LePeriodicAdvertisingCreateSync}, + {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, + &DualModeController::LePeriodicAdvertisingCreateSyncCancel}, + {OpCode::LE_PERIODIC_ADVERTISING_TERMINATE_SYNC, + &DualModeController::LePeriodicAdvertisingTerminateSync}, + {OpCode::LE_ADD_DEVICE_TO_PERIODIC_ADVERTISER_LIST, + &DualModeController::LeAddDeviceToPeriodicAdvertiserList}, + {OpCode::LE_REMOVE_DEVICE_FROM_PERIODIC_ADVERTISER_LIST, + &DualModeController::LeRemoveDeviceFromPeriodicAdvertiserList}, + {OpCode::LE_CLEAR_PERIODIC_ADVERTISER_LIST, + &DualModeController::LeClearPeriodicAdvertiserList}, + {OpCode::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE, + &DualModeController::LeReadPeriodicAdvertiserListSize}, + //{OpCode::LE_READ_TRANSMIT_POWER, + //&DualModeController::LeReadTransmitPower}, + //{OpCode::LE_READ_RF_PATH_COMPENSATION_POWER, + //&DualModeController::LeReadRfPathCompensationPower}, + //{OpCode::LE_WRITE_RF_PATH_COMPENSATION_POWER, + //&DualModeController::LeWriteRfPathCompensationPower}, + {OpCode::LE_SET_PRIVACY_MODE, &DualModeController::LeSetPrivacyMode}, + //{OpCode::LE_RECEIVER_TEST_V3, &DualModeController::LeReceiverTestV3}, + //{OpCode::LE_TRANSMITTER_TEST_V3, + //&DualModeController::LeTransmitterTestV3}, + //{OpCode::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS, + //&DualModeController::LeSetConnectionlessCteTransmitParameters}, + //{OpCode::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_ENABLE, + //&DualModeController::LeSetConnectionlessCteTransmitEnable}, + //{OpCode::LE_SET_CONNECTIONLESS_IQ_SAMPLING_ENABLE, + //&DualModeController::LeSetConnectionlessIqSamplingEnable}, + //{OpCode::LE_SET_CONNECTION_CTE_RECEIVE_PARAMETERS, + //&DualModeController::LeSetConnectionCteReceiveParameters}, + //{OpCode::LE_SET_CONNECTION_CTE_TRANSMIT_PARAMETERS, + //&DualModeController::LeSetConnectionCteTransmitParameters}, + //{OpCode::LE_CONNECTION_CTE_REQUEST_ENABLE, + //&DualModeController::LeConnectionCteRequestEnable}, + //{OpCode::LE_CONNECTION_CTE_RESPONSE_ENABLE, + //&DualModeController::LeConnectionCteResponseEnable}, + //{OpCode::LE_READ_ANTENNA_INFORMATION, + //&DualModeController::LeReadAntennaInformation}, + //{OpCode::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE, + //&DualModeController::LeSetPeriodicAdvertisingReceiveEnable}, + //{OpCode::LE_PERIODIC_ADVERTISING_SYNC_TRANSFER, + //&DualModeController::LePeriodicAdvertisingSyncTransfer}, + //{OpCode::LE_PERIODIC_ADVERTISING_SET_INFO_TRANSFER, + //&DualModeController::LePeriodicAdvertisingSetInfoTransfer}, + //{OpCode::LE_SET_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, + //&DualModeController::LeSetPeriodicAdvertisingSyncTransferParameters}, + //{OpCode::LE_SET_DEFAULT_PERIODIC_ADVERTISING_SYNC_TRANSFER_PARAMETERS, + //&DualModeController::LeSetDefaultPeriodicAdvertisingSyncTransferParameters}, + //{OpCode::LE_GENERATE_DHKEY_V2, + //&DualModeController::LeGenerateDhkeyV2}, + //{OpCode::LE_MODIFY_SLEEP_CLOCK_ACCURACY, + //&DualModeController::LeModifySleepClockAccuracy}, + {OpCode::LE_READ_BUFFER_SIZE_V2, &DualModeController::LeReadBufferSizeV2}, + //{OpCode::LE_READ_ISO_TX_SYNC, &DualModeController::LeReadIsoTxSync}, + {OpCode::LE_SET_CIG_PARAMETERS, &DualModeController::ForwardToLl}, + {OpCode::LE_SET_CIG_PARAMETERS_TEST, &DualModeController::ForwardToLl}, + {OpCode::LE_CREATE_CIS, &DualModeController::ForwardToLl}, + {OpCode::LE_REMOVE_CIG, &DualModeController::ForwardToLl}, + {OpCode::LE_ACCEPT_CIS_REQUEST, &DualModeController::ForwardToLl}, + {OpCode::LE_REJECT_CIS_REQUEST, &DualModeController::ForwardToLl}, + //{OpCode::LE_CREATE_BIG, &DualModeController::LeCreateBig}, + //{OpCode::LE_CREATE_BIG_TEST, &DualModeController::LeCreateBigTest}, + //{OpCode::LE_TERMINATE_BIG, &DualModeController::LeTerminateBig}, + //{OpCode::LE_BIG_CREATE_SYNC, &DualModeController::LeBigCreateSync}, + //{OpCode::LE_BIG_TERMINATE_SYNC, + //&DualModeController::LeBigTerminateSync}, + {OpCode::LE_REQUEST_PEER_SCA, &DualModeController::LeRequestPeerSca}, + {OpCode::LE_SETUP_ISO_DATA_PATH, &DualModeController::ForwardToLl}, + {OpCode::LE_REMOVE_ISO_DATA_PATH, &DualModeController::ForwardToLl}, + //{OpCode::LE_ISO_TRANSMIT_TEST, + //&DualModeController::LeIsoTransmitTest}, + //{OpCode::LE_ISO_RECEIVE_TEST, &DualModeController::LeIsoReceiveTest}, + //{OpCode::LE_ISO_READ_TEST_COUNTERS, + //&DualModeController::LeIsoReadTestCounters}, + //{OpCode::LE_ISO_TEST_END, &DualModeController::LeIsoTestEnd}, + {OpCode::LE_SET_HOST_FEATURE_V1, &DualModeController::LeSetHostFeatureV1}, + //{OpCode::LE_READ_ISO_LINK_QUALITY, + //&DualModeController::LeReadIsoLinkQuality}, + //{OpCode::LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL, + //&DualModeController::LeEnhancedReadTransmitPowerLevel}, + //{OpCode::LE_READ_REMOTE_TRANSMIT_POWER_LEVEL, + //&DualModeController::LeReadRemoteTransmitPowerLevel}, + //{OpCode::LE_SET_PATH_LOSS_REPORTING_PARAMETERS, + //&DualModeController::LeSetPathLossReportingParameters}, + //{OpCode::LE_SET_PATH_LOSS_REPORTING_ENABLE, + //&DualModeController::LeSetPathLossReportingEnable}, + //{OpCode::LE_SET_TRANSMIT_POWER_REPORTING_ENABLE, + //&DualModeController::LeSetTransmitPowerReportingEnable}, + //{OpCode::LE_TRANSMITTER_TEST_V4, + //&DualModeController::LeTransmitterTestV4}, + //{OpCode::LE_SET_DATA_RELATED_ADDRESS_CHANGES, + //&DualModeController::LeSetDataRelatedAddressChanges}, + //{OpCode::LE_SET_DEFAULT_SUBRATE, + //&DualModeController::LeSetDefaultSubrate}, + //{OpCode::LE_SUBRATE_REQUEST, &DualModeController::LeSubrateRequest}, + //{OpCode::LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V2, + //&DualModeController::LeSetExtendedAdvertisingParametersV2}, + //{OpCode::LE_SET_DECISION_DATA, &DualModeController::LeSetDecisionData}, + //{OpCode::LE_SET_DECISION_INSTRUCTIONS, + //&DualModeController::LeSetDecisionInstructions}, + //{OpCode::LE_SET_PERIODIC_ADVERTISING_SUBEVENT_DATA, + //&DualModeController::LeSetPeriodicAdvertisingSubeventData}, + //{OpCode::LE_SET_PERIODIC_ADVERTISING_RESPONSE_DATA, + //&DualModeController::LeSetPeriodicAdvertisingResponseData}, + //{OpCode::LE_SET_PERIODIC_SYNC_SUBEVENT, + //&DualModeController::LeSetPeriodicSyncSubevent}, + //{OpCode::LE_EXTENDED_CREATE_CONNECTION_V2, + //&DualModeController::LeExtendedCreateConnectionV2}, + //{OpCode::LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V2, + //&DualModeController::LeSetPeriodicAdvertisingParametersV2}, + //{OpCode::LE_READ_ALL_LOCAL_SUPPORTED_FEATURES, + //&DualModeController::LeReadAllLocalSupportedFeatures}, + //{OpCode::LE_READ_ALL_REMOTE_FEATURES, + //&DualModeController::LeReadAllRemoteFeatures}, + //{OpCode::LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES, + //&DualModeController::LeCsReadLocalSupportedCapabilities}, + //{OpCode::LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES, + //&DualModeController::LeCsReadRemoteSupportedCapabilities}, + //{OpCode::LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES, + //&DualModeController::LeCsWriteCachedRemoteSupportedCapabilities}, + //{OpCode::LE_CS_SECURITY_ENABLE, &DualModeController::LeCsSecurityEnable}, + //{OpCode::LE_CS_SET_DEFAULT_SETTINGS, &DualModeController::LeCsSetDefaultSettings}, + //{OpCode::LE_CS_READ_REMOTE_FAE_TABLE, + //&DualModeController::LeCsReadRemoteFaeTable}, + //{OpCode::LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE, + //&DualModeController::LeCsWriteCachedRemoteFaeTable}, + //{OpCode::LE_CS_CREATE_CONFIG, &DualModeController::LeCsCreateConfig}, + //{OpCode::LE_CS_REMOVE_CONFIG, &DualModeController::LeCsRemoveConfig}, + //{OpCode::LE_CS_SET_CHANNEL_CLASSIFICATION, + //&DualModeController::LeCsSetChannelClassification}, + //{OpCode::LE_CS_SET_PROCEDURE_PARAMETERS, + //&DualModeController::LeCsSetProcedureParameters}, + //{OpCode::LE_CS_PROCEDURE_ENABLE, &DualModeController::LeCsProcedureEnable}, + //{OpCode::LE_CS_TEST, &DualModeController::LeCsTest}, + //{OpCode::LE_CS_TEST_END, &DualModeController::LeCsTestEnd}, + //{OpCode::LE_ADD_DEVICE_TO_MONITORED_ADVERTISERS_LIST, + //&DualModeController::LeAddDeviceToMonitoredAdvertisersList}, + //{OpCode::LE_REMOVE_DEVICE_FROM_MONITORED_ADVERTISERS_LIST, + //&DualModeController::LeRemoveDeviceFromMonitoredAdvertisersList}, + //{OpCode::LE_CLEAR_MONITORED_ADVERTISERS_LIST, + //&DualModeController::LeClearMonitoredAdvertisersList}, + //{OpCode::LE_READ_MONITORED_ADVERTISERS_LIST_SIZE, + //&DualModeController::LeReadMonitoredAdvertisersListSize}, + //{OpCode::LE_ENABLE_MONITORED_ADVERTISERS, + //&DualModeController::LeEnableMonitoredAdvertisers}, + //{OpCode::LE_FRAME_SPACE_UPDATE, &DualModeController::LeFrameSpaceUpdate}, + + // VENDOR + {OpCode(CSR_VENDOR), &DualModeController::CsrVendorCommand}, + {OpCode::LE_GET_VENDOR_CAPABILITIES, &DualModeController::LeGetVendorCapabilities}, + {OpCode::LE_BATCH_SCAN, &DualModeController::LeBatchScan}, + {OpCode::LE_APCF, &DualModeController::LeApcf}, + {OpCode::LE_GET_CONTROLLER_ACTIVITY_ENERGY_INFO, + &DualModeController::LeGetControllerActivityEnergyInfo}, + {OpCode::LE_EX_SET_SCAN_PARAMETERS, &DualModeController::LeExSetScanParameters}, + {OpCode::GET_CONTROLLER_DEBUG_INFO, &DualModeController::GetControllerDebugInfo}, + {OpCode::INTEL_DDC_CONFIG_WRITE, &DualModeController::IntelDdcConfigWrite}, + }; } // namespace rootcanal diff --git a/model/controller/dual_mode_controller.h b/model/controller/dual_mode_controller.h index f3b0ce1..c5574bd 100644 --- a/model/controller/dual_mode_controller.h +++ b/model/controller/dual_mode_controller.h @@ -59,7 +59,7 @@ enum InvalidPacketReason { // corresponding Bluetooth command in the Core Specification with the prefix // "Hci" to distinguish it as a controller command. class DualModeController : public Device { - public: +public: DualModeController(ControllerProperties properties = ControllerProperties()); DualModeController(DualModeController&&) = delete; DualModeController(const DualModeController&) = delete; @@ -73,8 +73,8 @@ class DualModeController : public Device { // Device methods. std::string GetTypeString() const override; - void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView incoming, - Phy::Type type, int8_t rssi) override; + void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView incoming, Phy::Type type, + int8_t rssi) override; void Tick() override; void Close() override; @@ -89,25 +89,21 @@ class DualModeController : public Device { /// to an external tracker. Packets are rejected if they failed to /// be parsed, or run into an unimplemented part of the controller. void RegisterInvalidPacketHandler( - const std::function const&)>& handler); + const std::function const&)>& handler); // Set the callbacks for sending packets to the HCI. void RegisterEventChannel( - const std::function>)>& - send_event); + const std::function>)>& send_event); void RegisterAclChannel( - const std::function>)>& - send_acl); + const std::function>)>& send_acl); void RegisterScoChannel( - const std::function>)>& - send_sco); + const std::function>)>& send_sco); void RegisterIsoChannel( - const std::function>)>& - send_iso); + const std::function>)>& send_iso); // Controller commands. For error codes, see the Bluetooth Core Specification, // Version 4.2, Volume 2, Part D (page 370). @@ -398,7 +394,7 @@ class DualModeController : public Device { void LeReadBufferSizeV2(CommandView command); // 7.8.3 - void LeReadLocalSupportedFeatures(CommandView command); + void LeReadLocalSupportedFeaturesPage0(CommandView command); // 7.8.4 void LeSetRandomAddress(CommandView command); @@ -428,7 +424,7 @@ class DualModeController : public Device { void LeConnectionUpdate(CommandView command); // 7.8.21 - void LeReadRemoteFeatures(CommandView command); + void LeReadRemoteFeaturesPage0(CommandView command); // 7.8.22 void LeEncrypt(CommandView command); @@ -454,6 +450,9 @@ class DualModeController : public Device { void LeReadSuggestedDefaultDataLength(CommandView command); void LeWriteSuggestedDefaultDataLength(CommandView command); + // 7.8.36 + void LeReadLocalP256PublicKey(CommandView command); + // 7.8.38 - 7.8.41 void LeAddDeviceToResolvingList(CommandView command); void LeRemoveDeviceFromResolvingList(CommandView command); @@ -478,7 +477,7 @@ class DualModeController : public Device { // 7.8.52 - 7.8.60 void LeSetAdvertisingSetRandomAddress(CommandView command); - void LeSetExtendedAdvertisingParameters(CommandView command); + void LeSetExtendedAdvertisingParametersV1(CommandView command); void LeSetExtendedAdvertisingData(CommandView command); void LeSetExtendedScanResponseData(CommandView command); void LeSetExtendedAdvertisingEnable(CommandView command); @@ -488,7 +487,7 @@ class DualModeController : public Device { void LeClearAdvertisingSets(CommandView command); // 7.8.61 - 7.8.63 - void LeSetPeriodicAdvertisingParameters(CommandView command); + void LeSetPeriodicAdvertisingParametersV1(CommandView command); void LeSetPeriodicAdvertisingData(CommandView command); void LeSetPeriodicAdvertisingEnable(CommandView command); @@ -508,7 +507,7 @@ class DualModeController : public Device { void LeSetExtendedScanEnable(CommandView command); // 7.8.66 - void LeExtendedCreateConnection(CommandView command); + void LeExtendedCreateConnectionV1(CommandView command); // 7.8.77 void LeSetPrivacyMode(CommandView command); @@ -517,7 +516,7 @@ class DualModeController : public Device { void LeRequestPeerSca(CommandView command); // 7.8.115 - void LeSetHostFeature(CommandView command); + void LeSetHostFeatureV1(CommandView command); // Vendor-specific Commands void LeGetVendorCapabilities(CommandView command); @@ -526,6 +525,7 @@ class DualModeController : public Device { void LeGetControllerActivityEnergyInfo(CommandView command); void LeExSetScanParameters(CommandView command); void GetControllerDebugInfo(CommandView command); + void IntelDdcConfigWrite(CommandView command); // CSR vendor command. // Implement the command specific to the CSR controller @@ -540,18 +540,17 @@ class DualModeController : public Device { void ForwardToLm(CommandView command); void ForwardToLl(CommandView command); - protected: +protected: // Controller configuration. ControllerProperties properties_; // Link Layer state. LinkLayerController link_layer_controller_{address_, properties_, id_}; - private: +private: // Send a HCI_Command_Complete event for the specified op_code with // the error code UNKNOWN_OPCODE. - void SendCommandCompleteUnknownOpCodeEvent( - bluetooth::hci::OpCode op_code) const; + void SendCommandCompleteUnknownOpCodeEvent(bluetooth::hci::OpCode op_code) const; // Validate that a received packet is correctly formatted. // If the packet failed to be parsed, the function sends a @@ -566,22 +565,19 @@ class DualModeController : public Device { // Send a hardware error to reset the host, and report the packet // for tracing. send_event_(bluetooth::hci::HardwareErrorBuilder::Create(0x43)); - invalid_packet_handler_(id_, InvalidPacketReason::kParseError, reason, - view.bytes().bytes()); + invalid_packet_handler_(id_, InvalidPacketReason::kParseError, reason, view.bytes().bytes()); return false; } // Callbacks to send packets back to the HCI. std::function)> send_acl_; - std::function)> - send_event_; + std::function)> send_event_; std::function)> send_sco_; std::function)> send_iso_; // Report invalid packets received on this controller instance. - std::function const&)> - invalid_packet_handler_; + std::function const&)> + invalid_packet_handler_; // Loopback mode (Vol 4, Part E § 7.6.1). // The local loopback mode is used to pass the android Vendor Test Suite @@ -597,15 +593,13 @@ class DualModeController : public Device { // Map command opcodes to the corresponding bit index in the // supported command mask. - static const std::unordered_map - hci_command_op_code_to_index_; + static const std::unordered_map hci_command_op_code_to_index_; // Map all implemented opcodes to the function implementing the handler // for the associated command. The map should be a subset of the // supported_command field in the properties_ object. Commands // that are supported but not implemented will raise a fatal assert. - using CommandHandler = - std::function; + using CommandHandler = std::function; static const std::unordered_map hci_command_handlers_; }; diff --git a/model/controller/ffi.cc b/model/controller/ffi.cc index 4c6efad..6d8fd1c 100644 --- a/model/controller/ffi.cc +++ b/model/controller/ffi.cc @@ -38,50 +38,42 @@ enum Idc { extern "C" { __attribute__((visibility("default"))) void* ffi_controller_new( - uint8_t const address[6], - void (*send_hci)(int idc, uint8_t const* data, size_t data_len), - void (*send_ll)(uint8_t const* data, size_t data_len, int phy, - int tx_power)) { + uint8_t const address[6], void (*send_hci)(int idc, uint8_t const* data, size_t data_len), + void (*send_ll)(uint8_t const* data, size_t data_len, int phy, int tx_power)) { DualModeController* controller = new DualModeController(); - controller->SetAddress(Address({address[0], address[1], address[2], - address[3], address[4], address[5]})); - controller->RegisterEventChannel( - [=](std::shared_ptr> data) { - send_hci(hci::Idc::EVT, data->data(), data->size()); - }); - controller->RegisterAclChannel( - [=](std::shared_ptr> data) { - send_hci(hci::Idc::ACL, data->data(), data->size()); - }); - controller->RegisterScoChannel( - [=](std::shared_ptr> data) { - send_hci(hci::Idc::SCO, data->data(), data->size()); - }); - controller->RegisterIsoChannel( - [=](std::shared_ptr> data) { - send_hci(hci::Idc::ISO, data->data(), data->size()); - }); + controller->SetAddress( + Address({address[0], address[1], address[2], address[3], address[4], address[5]})); + controller->RegisterEventChannel([=](std::shared_ptr> data) { + send_hci(hci::Idc::EVT, data->data(), data->size()); + }); + controller->RegisterAclChannel([=](std::shared_ptr> data) { + send_hci(hci::Idc::ACL, data->data(), data->size()); + }); + controller->RegisterScoChannel([=](std::shared_ptr> data) { + send_hci(hci::Idc::SCO, data->data(), data->size()); + }); + controller->RegisterIsoChannel([=](std::shared_ptr> data) { + send_hci(hci::Idc::ISO, data->data(), data->size()); + }); controller->RegisterLinkLayerChannel( - [=](std::vector const& data, Phy::Type phy, int8_t tx_power) { - send_ll(data.data(), data.size(), static_cast(phy), tx_power); - }); + [=](std::vector const& data, Phy::Type phy, int8_t tx_power) { + send_ll(data.data(), data.size(), static_cast(phy), tx_power); + }); return controller; } -__attribute__((visibility("default"))) void ffi_controller_delete( - void* controller_) { - DualModeController* controller = - reinterpret_cast(controller_); +__attribute__((visibility("default"))) void ffi_controller_delete(void* controller_) { + DualModeController* controller = reinterpret_cast(controller_); delete controller; } -__attribute__((visibility("default"))) void ffi_controller_receive_hci( - void* controller_, int idc, uint8_t const* data, size_t data_len) { - DualModeController* controller = - reinterpret_cast(controller_); +__attribute__((visibility("default"))) void ffi_controller_receive_hci(void* controller_, int idc, + uint8_t const* data, + size_t data_len) { + DualModeController* controller = reinterpret_cast(controller_); std::shared_ptr> bytes = - std::make_shared>(data, data + data_len); + std::make_shared>(data, data + data_len); switch (idc) { case hci::Idc::CMD: @@ -97,21 +89,20 @@ __attribute__((visibility("default"))) void ffi_controller_receive_hci( controller->HandleIso(bytes); break; default: - std::cerr << "Dropping HCI packet with unknown type " << (int)idc - << std::endl; + std::cerr << "Dropping HCI packet with unknown type " << (int)idc << std::endl; break; } } -__attribute__((visibility("default"))) void ffi_controller_receive_ll( - void* controller_, uint8_t const* data, size_t data_len, int phy, - int rssi) { - DualModeController* controller = - reinterpret_cast(controller_); +__attribute__((visibility("default"))) void ffi_controller_receive_ll(void* controller_, + uint8_t const* data, + size_t data_len, int phy, + int rssi) { + DualModeController* controller = reinterpret_cast(controller_); std::shared_ptr> bytes = - std::make_shared>(data, data + data_len); + std::make_shared>(data, data + data_len); model::packets::LinkLayerPacketView packet = - model::packets::LinkLayerPacketView::Create(pdl::packet::slice(bytes)); + model::packets::LinkLayerPacketView::Create(pdl::packet::slice(bytes)); if (!packet.IsValid()) { std::cerr << "Dropping malformed LL packet" << std::endl; return; @@ -119,15 +110,13 @@ __attribute__((visibility("default"))) void ffi_controller_receive_ll( controller->ReceiveLinkLayerPacket(packet, Phy::Type(phy), rssi); } -__attribute__((visibility("default"))) void ffi_controller_tick( - void* controller_) { - DualModeController* controller = - reinterpret_cast(controller_); +__attribute__((visibility("default"))) void ffi_controller_tick(void* controller_) { + DualModeController* controller = reinterpret_cast(controller_); controller->Tick(); } -__attribute__((visibility("default"))) void ffi_generate_rpa( - uint8_t const irk_[16], uint8_t rpa[6]) { +__attribute__((visibility("default"))) void ffi_generate_rpa(uint8_t const irk_[16], + uint8_t rpa[6]) { std::array irk; memcpy(irk.data(), irk_, LinkLayerController::kIrkSize); Address address = LinkLayerController::generate_rpa(irk); diff --git a/model/controller/ffi.h b/model/controller/ffi.h index 8b6033b..8b1d9d2 100644 --- a/model/controller/ffi.h +++ b/model/controller/ffi.h @@ -20,15 +20,13 @@ extern "C" { void* ffi_controller_new(uint8_t const address[6], - void (*send_hci)(int idc, uint8_t const* data, - size_t data_len), - void (*send_ll)(uint8_t const* data, size_t data_len, - int phy, int tx_power)); + void (*send_hci)(int idc, uint8_t const* data, size_t data_len), + void (*send_ll)(uint8_t const* data, size_t data_len, int phy, + int tx_power)); void ffi_controller_delete(void* controller); -void ffi_controller_receive_hci(void* controller, int idc, uint8_t const* data, - size_t data_len); -void ffi_controller_receive_ll(void* controller, uint8_t const* data, - size_t data_len, int phy, int rssi); +void ffi_controller_receive_hci(void* controller, int idc, uint8_t const* data, size_t data_len); +void ffi_controller_receive_ll(void* controller, uint8_t const* data, size_t data_len, int phy, + int rssi); void ffi_controller_tick(void* controller); void ffi_generate_rpa(uint8_t const irk[16], uint8_t rpa[6]); diff --git a/model/controller/le_advertiser.cc b/model/controller/le_advertiser.cc index 0f5cfab..cd9ae56 100644 --- a/model/controller/le_advertiser.cc +++ b/model/controller/le_advertiser.cc @@ -62,11 +62,10 @@ const uint16_t max_extended_advertising_pdu_size = 1650; // HCI command LE_Set_Advertising_Parameters (Vol 4, Part E § 7.8.5). ErrorCode LinkLayerController::LeSetAdvertisingParameters( - uint16_t advertising_interval_min, uint16_t advertising_interval_max, - AdvertisingType advertising_type, OwnAddressType own_address_type, - PeerAddressType peer_address_type, Address peer_address, - uint8_t advertising_channel_map, - AdvertisingFilterPolicy advertising_filter_policy) { + uint16_t advertising_interval_min, uint16_t advertising_interval_max, + AdvertisingType advertising_type, OwnAddressType own_address_type, + PeerAddressType peer_address_type, Address peer_address, uint8_t advertising_channel_map, + AdvertisingFilterPolicy advertising_filter_policy) { // Legacy advertising commands are disallowed when extended advertising // commands were used since the last reset. if (!SelectLegacyAdvertising()) { @@ -131,9 +130,9 @@ ErrorCode LinkLayerController::LeSetAdvertisingParameters( } legacy_advertiser_.advertising_interval = - advertising_type == AdvertisingType::ADV_DIRECT_IND_HIGH - ? std::chrono::duration_cast(adv_direct_ind_high_interval) - : slots(advertising_interval_min); + advertising_type == AdvertisingType::ADV_DIRECT_IND_HIGH + ? std::chrono::duration_cast(adv_direct_ind_high_interval) + : slots(advertising_interval_min); legacy_advertiser_.advertising_type = advertising_type; legacy_advertiser_.own_address_type = own_address_type; legacy_advertiser_.peer_address_type = peer_address_type; @@ -144,8 +143,7 @@ ErrorCode LinkLayerController::LeSetAdvertisingParameters( } // HCI command LE_Set_Advertising_Data (Vol 4, Part E § 7.8.7). -ErrorCode LinkLayerController::LeSetAdvertisingData( - const std::vector& advertising_data) { +ErrorCode LinkLayerController::LeSetAdvertisingData(const std::vector& advertising_data) { // Legacy advertising commands are disallowed when extended advertising // commands were used since the last reset. if (!SelectLegacyAdvertising()) { @@ -161,7 +159,7 @@ ErrorCode LinkLayerController::LeSetAdvertisingData( // HCI command LE_Set_Scan_Response_Data (Vol 4, Part E § 7.8.8). ErrorCode LinkLayerController::LeSetScanResponseData( - const std::vector& scan_response_data) { + const std::vector& scan_response_data) { // Legacy advertising commands are disallowed when extended advertising // commands were used since the last reset. if (!SelectLegacyAdvertising()) { @@ -191,13 +189,12 @@ ErrorCode LinkLayerController::LeSetAdvertisingEnable(bool advertising_enable) { return ErrorCode::SUCCESS; } - AddressWithType peer_address = PeerDeviceAddress( - legacy_advertiser_.peer_address, legacy_advertiser_.peer_address_type); + AddressWithType peer_address = + PeerDeviceAddress(legacy_advertiser_.peer_address, legacy_advertiser_.peer_address_type); AddressWithType public_address{address_, AddressType::PUBLIC_DEVICE_ADDRESS}; - AddressWithType random_address{random_address_, - AddressType::RANDOM_DEVICE_ADDRESS}; + AddressWithType random_address{random_address_, AddressType::RANDOM_DEVICE_ADDRESS}; std::optional resolvable_address = - GenerateResolvablePrivateAddress(peer_address, IrkSelection::Local); + GenerateResolvablePrivateAddress(peer_address, IrkSelection::Local); // TODO: additional checks would apply in the case of a LE only Controller // with no configured public device address. @@ -223,8 +220,7 @@ ErrorCode LinkLayerController::LeSetAdvertisingEnable(bool advertising_enable) { break; case OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS: - legacy_advertiser_.advertising_address = - resolvable_address.value_or(public_address); + legacy_advertiser_.advertising_address = resolvable_address.value_or(public_address); break; case OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS: @@ -250,14 +246,13 @@ ErrorCode LinkLayerController::LeSetAdvertisingEnable(bool advertising_enable) { legacy_advertiser_.timeout = {}; legacy_advertiser_.target_address = - AddressWithType{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; switch (legacy_advertiser_.advertising_type) { case AdvertisingType::ADV_DIRECT_IND_HIGH: // The Link Layer shall exit the Advertising state no later than 1.28 s // after the Advertising state was entered. - legacy_advertiser_.timeout = - std::chrono::steady_clock::now() + adv_direct_ind_high_timeout; + legacy_advertiser_.timeout = std::chrono::steady_clock::now() + adv_direct_ind_high_timeout; [[fallthrough]]; case AdvertisingType::ADV_DIRECT_IND_LOW: { @@ -271,9 +266,8 @@ ErrorCode LinkLayerController::LeSetAdvertisingEnable(bool advertising_enable) { // (TargetA field) shall use the Identity Address when entering the // Advertising State and using connectable directed events. std::optional peer_resolvable_address = - GenerateResolvablePrivateAddress(peer_address, IrkSelection::Peer); - legacy_advertiser_.target_address = - peer_resolvable_address.value_or(peer_address); + GenerateResolvablePrivateAddress(peer_address, IrkSelection::Peer); + legacy_advertiser_.target_address = peer_resolvable_address.value_or(peer_address); break; } default: @@ -281,8 +275,8 @@ ErrorCode LinkLayerController::LeSetAdvertisingEnable(bool advertising_enable) { } legacy_advertiser_.advertising_enable = true; - legacy_advertiser_.next_event = std::chrono::steady_clock::now() + - legacy_advertiser_.advertising_interval; + legacy_advertiser_.next_event = + std::chrono::steady_clock::now() + legacy_advertiser_.advertising_interval; return ErrorCode::SUCCESS; } @@ -291,8 +285,8 @@ ErrorCode LinkLayerController::LeSetAdvertisingEnable(bool advertising_enable) { // ============================================================================= // HCI command LE_Set_Advertising_Set_Random_Address (Vol 4, Part E § 7.8.52). -ErrorCode LinkLayerController::LeSetAdvertisingSetRandomAddress( - uint8_t advertising_handle, Address random_address) { +ErrorCode LinkLayerController::LeSetAdvertisingSetRandomAddress(uint8_t advertising_handle, + Address random_address) { // If the advertising set corresponding to the Advertising_Handle parameter // does not exist, then the Controller shall return the error code // Unknown Advertising Identifier (0x42). @@ -320,16 +314,14 @@ ErrorCode LinkLayerController::LeSetAdvertisingSetRandomAddress( // HCI command LE_Set_Extended_Advertising_Parameters (Vol 4, Part E § 7.8.53). ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( - uint8_t advertising_handle, - AdvertisingEventProperties advertising_event_properties, - uint16_t primary_advertising_interval_min, - uint16_t primary_advertising_interval_max, - uint8_t primary_advertising_channel_map, OwnAddressType own_address_type, - PeerAddressType peer_address_type, Address peer_address, - AdvertisingFilterPolicy advertising_filter_policy, - uint8_t advertising_tx_power, PrimaryPhyType primary_advertising_phy, - uint8_t secondary_max_skip, SecondaryPhyType secondary_advertising_phy, - uint8_t advertising_sid, bool scan_request_notification_enable) { + uint8_t advertising_handle, AdvertisingEventProperties advertising_event_properties, + uint16_t primary_advertising_interval_min, uint16_t primary_advertising_interval_max, + uint8_t primary_advertising_channel_map, OwnAddressType own_address_type, + PeerAddressType peer_address_type, Address peer_address, + AdvertisingFilterPolicy advertising_filter_policy, uint8_t advertising_tx_power, + PrimaryPhyType primary_advertising_phy, uint8_t secondary_max_skip, + SecondaryPhyType secondary_advertising_phy, uint8_t advertising_sid, + bool scan_request_notification_enable) { // Extended advertising commands are disallowed when legacy advertising // commands were used since the last reset. if (!SelectExtendedAdvertising()) { @@ -344,12 +336,10 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( bool connectable_advertising = advertising_event_properties.connectable_; bool scannable_advertising = advertising_event_properties.scannable_; bool directed_advertising = advertising_event_properties.directed_; - bool high_duty_cycle_advertising = - advertising_event_properties.high_duty_cycle_; + bool high_duty_cycle_advertising = advertising_event_properties.high_duty_cycle_; bool anonymous_advertising = advertising_event_properties.anonymous_; uint16_t raw_advertising_event_properties = - ExtendedAdvertiser::GetRawAdvertisingEventProperties( - advertising_event_properties); + ExtendedAdvertiser::GetRawAdvertisingEventProperties(advertising_event_properties); // Clear reserved bits. primary_advertising_channel_map &= 0x7; @@ -361,8 +351,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( // TODO(c++20) unordered_map<>::contains if (extended_advertisers_.count(advertising_handle) == 0) { - if (extended_advertisers_.size() >= - properties_.le_num_supported_advertising_sets) { + if (extended_advertisers_.size() >= properties_.le_num_supported_advertising_sets) { INFO(id_, "no advertising set defined with handle {:02x} and" " cannot allocate any more advertisers", @@ -385,19 +374,15 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( // shall be one of those specified in Table 7.2. if (legacy_advertising && (raw_advertising_event_properties & ~0x10) != - static_cast(LegacyAdvertisingEventProperties::ADV_IND) && + static_cast(LegacyAdvertisingEventProperties::ADV_IND) && (raw_advertising_event_properties & ~0x10) != - static_cast( - LegacyAdvertisingEventProperties::ADV_DIRECT_IND_LOW) && + static_cast(LegacyAdvertisingEventProperties::ADV_DIRECT_IND_LOW) && (raw_advertising_event_properties & ~0x10) != - static_cast( - LegacyAdvertisingEventProperties::ADV_DIRECT_IND_HIGH) && + static_cast(LegacyAdvertisingEventProperties::ADV_DIRECT_IND_HIGH) && (raw_advertising_event_properties & ~0x10) != - static_cast( - LegacyAdvertisingEventProperties::ADV_SCAN_IND) && + static_cast(LegacyAdvertisingEventProperties::ADV_SCAN_IND) && (raw_advertising_event_properties & ~0x10) != - static_cast( - LegacyAdvertisingEventProperties::ADV_NONCONN_IND)) { + static_cast(LegacyAdvertisingEventProperties::ADV_NONCONN_IND)) { INFO(id_, "advertising_event_properties (0x{:02x}) is legacy but does not" " match valid legacy advertising event types", @@ -405,9 +390,8 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } - bool can_have_advertising_data = - (legacy_advertising && !directed_advertising) || - (extended_advertising && !scannable_advertising); + bool can_have_advertising_data = (legacy_advertising && !directed_advertising) || + (extended_advertising && !scannable_advertising); // If the Advertising_Event_Properties parameter [..] specifies a type that // does not support advertising data when the advertising set already @@ -436,8 +420,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( // exceed 31 octets. if (legacy_advertising && (advertiser.advertising_data.size() > max_legacy_advertising_pdu_size || - advertiser.scan_response_data.size() > - max_legacy_advertising_pdu_size)) { + advertiser.scan_response_data.size() > max_legacy_advertising_pdu_size)) { INFO(id_, "advertising_event_properties (0x{:02x}) is legacy and the" " advertising data or scan response data exceeds the capacity" @@ -448,8 +431,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( // If extended advertising PDU types are being used (bit 4 = 0) then: // The advertisement shall not be both connectable and scannable. - if (extended_advertising && connectable_advertising && - scannable_advertising) { + if (extended_advertising && connectable_advertising && scannable_advertising) { INFO(id_, "advertising_event_properties (0x{:02x}) is extended and may not" " be connectable and scannable at the same time", @@ -473,8 +455,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( // outside the advertising interval range supported by the Controller, then // the Controller shall return the error code Unsupported Feature or // Parameter Value (0x11). - if (primary_advertising_interval_min < 0x20 || - primary_advertising_interval_max < 0x20) { + if (primary_advertising_interval_min < 0x20 || primary_advertising_interval_max < 0x20) { INFO(id_, "primary_advertising_interval_min (0x{:04x}) and/or" " primary_advertising_interval_max (0x{:04x}) are outside the range" @@ -508,8 +489,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( INFO(id_, "advertising_event_properties (0x{:04x}) is legacy but" " primary_advertising_phy ({:02x}) is not LE 1M", - raw_advertising_event_properties, - static_cast(primary_advertising_phy)); + raw_advertising_event_properties, static_cast(primary_advertising_phy)); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -530,9 +510,8 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( // the specified advertising set and connectable, scannable, legacy, // or anonymous advertising is specified, the Controller shall return the // error code Invalid HCI Command Parameters (0x12). - if (advertiser.periodic_advertising_enable && - (connectable_advertising || scannable_advertising || legacy_advertising || - anonymous_advertising)) { + if (advertiser.periodic_advertising_enable && (connectable_advertising || scannable_advertising || + legacy_advertising || anonymous_advertising)) { INFO(id_, "periodic advertising is enabled for the specified advertising set" " and advertising_event_properties (0x{:02x}) is either" @@ -565,8 +544,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( // coding shall be assumed. if (extended_advertising && (advertiser.advertising_data.size() > max_extended_advertising_pdu_size || - advertiser.scan_response_data.size() > - max_extended_advertising_pdu_size)) { + advertiser.scan_response_data.size() > max_extended_advertising_pdu_size)) { INFO(id_, "the advertising data contained in the set is larger than the" " available PDU capacity"); @@ -574,8 +552,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( } advertiser.advertising_event_properties = advertising_event_properties; - advertiser.primary_advertising_interval = - slots(primary_advertising_interval_min); + advertiser.primary_advertising_interval = slots(primary_advertising_interval_min); advertiser.primary_advertising_channel_map = primary_advertising_channel_map; advertiser.own_address_type = own_address_type; advertiser.peer_address_type = peer_address_type; @@ -586,19 +563,16 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingParameters( advertiser.secondary_max_skip = secondary_max_skip; advertiser.secondary_advertising_phy = secondary_advertising_phy; advertiser.advertising_sid = advertising_sid; - advertiser.scan_request_notification_enable = - scan_request_notification_enable; + advertiser.scan_request_notification_enable = scan_request_notification_enable; - extended_advertisers_.insert_or_assign(advertising_handle, - std::move(advertiser)); + extended_advertisers_.insert_or_assign(advertising_handle, std::move(advertiser)); return ErrorCode::SUCCESS; } // HCI command LE_Set_Extended_Advertising_Data (Vol 4, Part E § 7.8.54). ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( - uint8_t advertising_handle, Operation operation, - FragmentPreference fragment_preference, - const std::vector& advertising_data) { + uint8_t advertising_handle, Operation operation, FragmentPreference fragment_preference, + const std::vector& advertising_data) { // Extended advertising commands are disallowed when legacy advertising // commands were used since the last reset. if (!SelectExtendedAdvertising()) { @@ -623,15 +597,13 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( ExtendedAdvertiser& advertiser = extended_advertisers_[advertising_handle]; const AdvertisingEventProperties& advertising_event_properties = - advertiser.advertising_event_properties; + advertiser.advertising_event_properties; uint16_t raw_advertising_event_properties = - ExtendedAdvertiser::GetRawAdvertisingEventProperties( - advertising_event_properties); + ExtendedAdvertiser::GetRawAdvertisingEventProperties(advertising_event_properties); - bool can_have_advertising_data = (advertising_event_properties.legacy_ && - !advertising_event_properties.directed_) || - (!advertising_event_properties.legacy_ && - !advertising_event_properties.scannable_); + bool can_have_advertising_data = + (advertising_event_properties.legacy_ && !advertising_event_properties.directed_) || + (!advertising_event_properties.legacy_ && !advertising_event_properties.scannable_); // If the advertising set specifies a type that does not support // advertising data, the Controller shall return the error code @@ -680,8 +652,8 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( // If Operation is not 0x03 or 0x04 and Advertising_Data_Length is zero, // the Controller shall return the error code Invalid HCI // Command Parameters (0x12). - if (operation != Operation::COMPLETE_ADVERTISEMENT && - operation != Operation::UNCHANGED_DATA && advertising_data.empty()) { + if (operation != Operation::COMPLETE_ADVERTISEMENT && operation != Operation::UNCHANGED_DATA && + advertising_data.empty()) { INFO(id_, "operation ({:02x}) is not Complete_Advertisement or Unchanged_Data" " but the advertising data is empty", @@ -692,8 +664,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( // If advertising is currently enabled for the specified advertising set and // Operation does not have the value 0x03 or 0x04, the Controller shall // return the error code Command Disallowed (0x0C). - if (advertiser.advertising_enable && - operation != Operation::COMPLETE_ADVERTISEMENT && + if (advertiser.advertising_enable && operation != Operation::COMPLETE_ADVERTISEMENT && operation != Operation::UNCHANGED_DATA) { INFO(id_, "operation ({:02x}) is used but advertising is enabled for the" @@ -705,8 +676,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( switch (operation) { case Operation::INTERMEDIATE_FRAGMENT: advertiser.advertising_data.insert(advertiser.advertising_data.end(), - advertising_data.begin(), - advertising_data.end()); + advertising_data.begin(), advertising_data.end()); advertiser.partial_advertising_data = true; break; @@ -717,8 +687,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( case Operation::LAST_FRAGMENT: advertiser.advertising_data.insert(advertiser.advertising_data.end(), - advertising_data.begin(), - advertising_data.end()); + advertising_data.begin(), advertising_data.end()); advertiser.partial_advertising_data = false; break; @@ -741,13 +710,11 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( // or the amount of memory currently available, all the data // shall be discarded and the Controller shall return the error code Memory // Capacity Exceeded (0x07). - if (advertiser.advertising_data.size() > - properties_.le_max_advertising_data_length) { + if (advertiser.advertising_data.size() > properties_.le_max_advertising_data_length) { INFO(id_, "the combined length {} of the advertising data exceeds the" " advertising set capacity {}", - advertiser.advertising_data.size(), - properties_.le_max_advertising_data_length); + advertiser.advertising_data.size(), properties_.le_max_advertising_data_length); advertiser.advertising_data.clear(); advertiser.partial_advertising_data = false; return ErrorCode::MEMORY_CAPACITY_EXCEEDED; @@ -761,8 +728,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( // the error code Packet Too Long (0x45). If advertising on the // LE Coded PHY, the S=8 coding shall be assumed. size_t max_advertising_data_length = - ExtendedAdvertiser::GetMaxAdvertisingDataLength( - advertising_event_properties); + ExtendedAdvertiser::GetMaxAdvertisingDataLength(advertising_event_properties); if (advertiser.advertising_enable && advertiser.advertising_data.size() > max_advertising_data_length) { INFO(id_, @@ -778,9 +744,8 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingData( // HCI command LE_Set_Extended_Scan_Response_Data (Vol 4, Part E § 7.8.55). ErrorCode LinkLayerController::LeSetExtendedScanResponseData( - uint8_t advertising_handle, Operation operation, - FragmentPreference fragment_preference, - const std::vector& scan_response_data) { + uint8_t advertising_handle, Operation operation, FragmentPreference fragment_preference, + const std::vector& scan_response_data) { // Extended advertising commands are disallowed when legacy advertising // commands were used since the last reset. if (!SelectExtendedAdvertising()) { @@ -805,10 +770,9 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( ExtendedAdvertiser& advertiser = extended_advertisers_[advertising_handle]; const AdvertisingEventProperties& advertising_event_properties = - advertiser.advertising_event_properties; + advertiser.advertising_event_properties; uint16_t raw_advertising_event_properties = - ExtendedAdvertiser::GetRawAdvertisingEventProperties( - advertising_event_properties); + ExtendedAdvertiser::GetRawAdvertisingEventProperties(advertising_event_properties); // If the advertising set is non-scannable and the Host uses this // command other than to discard existing data, the Controller shall @@ -825,8 +789,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( // either Operation is not 0x03 or the Scan_Response_Data_Length // parameter exceeds 31 octets, the Controller shall // return the error code Invalid HCI Command Parameters (0x12). - if (advertising_event_properties.scannable_ && - advertising_event_properties.legacy_ && + if (advertising_event_properties.scannable_ && advertising_event_properties.legacy_ && (operation != Operation::COMPLETE_ADVERTISEMENT || scan_response_data.size() > max_legacy_advertising_pdu_size)) { INFO(id_, @@ -840,8 +803,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( // If Operation is not 0x03 and Scan_Response_Data_Length is zero, the // Controller shall return the error code // Invalid HCI Command Parameters (0x12). - if (operation != Operation::COMPLETE_ADVERTISEMENT && - scan_response_data.empty()) { + if (operation != Operation::COMPLETE_ADVERTISEMENT && scan_response_data.empty()) { INFO(id_, "operation ({:02x}) is not Complete_Advertisement but the" " scan response data is empty", @@ -852,8 +814,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( // If advertising is currently enabled for the specified advertising set and // Operation does not have the value 0x03, the Controller shall // return the error code Command Disallowed (0x0C). - if (advertiser.advertising_enable && - operation != Operation::COMPLETE_ADVERTISEMENT) { + if (advertiser.advertising_enable && operation != Operation::COMPLETE_ADVERTISEMENT) { INFO(id_, "operation ({:02x}) is used but advertising is enabled for the" " specified advertising set", @@ -865,8 +826,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( // advertising is currently enabled for the specified advertising set, // and Scan_Response_Data_Length is zero, the Controller shall return // the error code Command Disallowed (0x0C). - if (advertiser.advertising_enable && - advertising_event_properties.scannable_ && + if (advertiser.advertising_enable && advertising_event_properties.scannable_ && !advertising_event_properties.legacy_ && scan_response_data.empty()) { INFO(id_, "advertising_event_properties ({:02x}) is scannable extended," @@ -879,8 +839,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( switch (operation) { case Operation::INTERMEDIATE_FRAGMENT: advertiser.scan_response_data.insert(advertiser.scan_response_data.end(), - scan_response_data.begin(), - scan_response_data.end()); + scan_response_data.begin(), scan_response_data.end()); advertiser.partial_scan_response_data = true; break; @@ -891,8 +850,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( case Operation::LAST_FRAGMENT: advertiser.scan_response_data.insert(advertiser.scan_response_data.end(), - scan_response_data.begin(), - scan_response_data.end()); + scan_response_data.begin(), scan_response_data.end()); advertiser.partial_scan_response_data = false; break; @@ -918,8 +876,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( // or the amount of memory currently available, all the data shall be // discarded and the Controller shall return the error code // Memory Capacity Exceeded (0x07). - if (advertiser.scan_response_data.size() > - properties_.le_max_advertising_data_length) { + if (advertiser.scan_response_data.size() > properties_.le_max_advertising_data_length) { INFO(id_, "the combined length of the scan response data exceeds the" " advertising set capacity"); @@ -936,8 +893,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( // discarded and the Controller shall return the error code // Packet Too Long (0x45). If advertising on the LE Coded PHY, // the S=8 coding shall be assumed. - if (advertiser.scan_response_data.size() > - max_extended_advertising_pdu_size) { + if (advertiser.scan_response_data.size() > max_extended_advertising_pdu_size) { INFO(id_, "the scan response data contained in the set is larger than the" " available PDU capacity"); @@ -951,7 +907,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanResponseData( // HCI command LE_Set_Extended_Advertising_Enable (Vol 4, Part E § 7.8.56). ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( - bool enable, const std::vector& sets) { + bool enable, const std::vector& sets) { // Extended advertising commands are disallowed when legacy advertising // commands were used since the last reset. if (!SelectExtendedAdvertising()) { @@ -968,18 +924,15 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // Advertising_Handle[i] arrayed parameter, then the Controller shall return // the error code Invalid HCI Command Parameters (0x12). if (used_advertising_handles[set.advertising_handle_]) { - INFO(id_, "advertising handle {:02x} is added more than once", - set.advertising_handle_); + INFO(id_, "advertising handle {:02x} is added more than once", set.advertising_handle_); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } // If the advertising set corresponding to the Advertising_Handle[i] // parameter does not exist, then the Controller shall return the error code // Unknown Advertising Identifier (0x42). - if (extended_advertisers_.find(set.advertising_handle_) == - extended_advertisers_.end()) { - INFO(id_, "advertising handle {:02x} is not defined", - set.advertising_handle_); + if (extended_advertisers_.find(set.advertising_handle_) == extended_advertisers_.end()) { + INFO(id_, "advertising handle {:02x} is not defined", set.advertising_handle_); return ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER; } @@ -1013,25 +966,21 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // Validate the advertising parameters before enabling any set. for (auto& set : sets) { - ExtendedAdvertiser& advertiser = - extended_advertisers_[set.advertising_handle_]; + ExtendedAdvertiser& advertiser = extended_advertisers_[set.advertising_handle_]; const AdvertisingEventProperties& advertising_event_properties = - advertiser.advertising_event_properties; + advertiser.advertising_event_properties; bool extended_advertising = !advertising_event_properties.legacy_; bool connectable_advertising = advertising_event_properties.connectable_; bool scannable_advertising = advertising_event_properties.scannable_; bool directed_advertising = advertising_event_properties.directed_; - bool high_duty_cycle_advertising = - advertising_event_properties.high_duty_cycle_; + bool high_duty_cycle_advertising = advertising_event_properties.high_duty_cycle_; // If the advertising is high duty cycle connectable directed advertising, // then Duration[i] shall be less than or equal to 1.28 seconds and shall // not be equal to 0. - std::chrono::milliseconds duration = - std::chrono::milliseconds(set.duration_ * 10); - if (connectable_advertising && directed_advertising && - high_duty_cycle_advertising && + std::chrono::milliseconds duration = std::chrono::milliseconds(set.duration_ * 10); + if (connectable_advertising && directed_advertising && high_duty_cycle_advertising && (set.duration_ == 0 || duration > adv_direct_ind_high_timeout)) { INFO(id_, "extended advertising is high duty cycle connectable directed" @@ -1042,8 +991,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // If the advertising set contains partial advertising data or partial // scan response data, the Controller shall return the error code // Command Disallowed (0x0C). - if (advertiser.partial_advertising_data || - advertiser.partial_scan_response_data) { + if (advertiser.partial_advertising_data || advertiser.partial_scan_response_data) { INFO(id_, "advertising set contains partial advertising" " or scan response data"); @@ -1053,8 +1001,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // If the advertising set uses scannable extended advertising PDUs and no // scan response data is currently provided, the Controller shall return the // error code Command Disallowed (0x0C). - if (extended_advertising && scannable_advertising && - advertiser.scan_response_data.empty()) { + if (extended_advertising && scannable_advertising && advertiser.scan_response_data.empty()) { INFO(id_, "advertising set uses scannable extended advertising PDUs" " but no scan response data is provided"); @@ -1067,8 +1014,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // Invalid HCI Command Parameters (0x12). if (extended_advertising && connectable_advertising && advertiser.advertising_data.size() > - ExtendedAdvertiser::GetMaxAdvertisingDataLength( - advertising_event_properties)) { + ExtendedAdvertiser::GetMaxAdvertisingDataLength(advertising_event_properties)) { INFO(id_, "advertising set uses connectable extended advertising PDUs" " but the advertising data does not fit in AUX_ADV_IND PDUs"); @@ -1081,25 +1027,22 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // advertising segment consistent with the chosen advertising interval, // the Controller shall return the error code Packet Too Long (0x45). // If advertising on the LE Coded PHY, the S=8 coding shall be assumed. - if (extended_advertising && (advertiser.advertising_data.size() > - max_extended_advertising_pdu_size || - advertiser.scan_response_data.size() > - max_extended_advertising_pdu_size)) { + if (extended_advertising && + (advertiser.advertising_data.size() > max_extended_advertising_pdu_size || + advertiser.scan_response_data.size() > max_extended_advertising_pdu_size)) { INFO(id_, "advertising set uses extended advertising PDUs" " but the advertising data does not fit in advertising PDUs"); return ErrorCode::PACKET_TOO_LONG; } - AddressWithType peer_address = PeerDeviceAddress( - advertiser.peer_address, advertiser.peer_address_type); - AddressWithType public_address{address_, - AddressType::PUBLIC_DEVICE_ADDRESS}; - AddressWithType random_address{ - advertiser.random_address.value_or(Address::kEmpty), - AddressType::RANDOM_DEVICE_ADDRESS}; + AddressWithType peer_address = + PeerDeviceAddress(advertiser.peer_address, advertiser.peer_address_type); + AddressWithType public_address{address_, AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType random_address{advertiser.random_address.value_or(Address::kEmpty), + AddressType::RANDOM_DEVICE_ADDRESS}; std::optional resolvable_address = - GenerateResolvablePrivateAddress(peer_address, IrkSelection::Local); + GenerateResolvablePrivateAddress(peer_address, IrkSelection::Local); // TODO: additional checks would apply in the case of a LE only Controller // with no configured public device address. @@ -1116,18 +1059,16 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // command, the Controller shall return the error code // Invalid HCI Command Parameters (0x12). if (random_address.GetAddress() == Address::kEmpty) { - INFO( - id_, - "own_address_type is Random_Device_Address but the Random_Address" - " has not been initialized"); + INFO(id_, + "own_address_type is Random_Device_Address but the Random_Address" + " has not been initialized"); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } advertiser.advertising_address = random_address; break; case OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS: - advertiser.advertising_address = - resolvable_address.value_or(public_address); + advertiser.advertising_address = resolvable_address.value_or(public_address); break; case OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS: @@ -1159,23 +1100,19 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( // Address when entering the Advertising State and using connectable // directed events. if (advertiser.IsDirected()) { - advertiser.target_address = - GenerateResolvablePrivateAddress(peer_address, IrkSelection::Peer) - .value_or(peer_address); + advertiser.target_address = GenerateResolvablePrivateAddress(peer_address, IrkSelection::Peer) + .value_or(peer_address); } } for (auto& set : sets) { - ExtendedAdvertiser& advertiser = - extended_advertisers_[set.advertising_handle_]; + ExtendedAdvertiser& advertiser = extended_advertisers_[set.advertising_handle_]; - advertiser.max_extended_advertising_events = - set.max_extended_advertising_events_; + advertiser.max_extended_advertising_events = set.max_extended_advertising_events_; advertiser.num_completed_extended_advertising_events = 0; advertiser.Enable(); if (set.duration_ > 0) { - std::chrono::milliseconds duration = - std::chrono::milliseconds(set.duration_ * 10); + std::chrono::milliseconds duration = std::chrono::milliseconds(set.duration_ * 10); advertiser.timeout = std::chrono::steady_clock::now() + duration; } else { advertiser.timeout.reset(); @@ -1186,8 +1123,7 @@ ErrorCode LinkLayerController::LeSetExtendedAdvertisingEnable( } // HCI command LE_Remove_Advertising_Set (Vol 4, Part E § 7.8.59). -ErrorCode LinkLayerController::LeRemoveAdvertisingSet( - uint8_t advertising_handle) { +ErrorCode LinkLayerController::LeRemoveAdvertisingSet(uint8_t advertising_handle) { // If the advertising set corresponding to the Advertising_Handle parameter // does not exist, then the Controller shall return the error code // Unknown Advertising Identifier (0x42). @@ -1228,7 +1164,7 @@ ErrorCode LinkLayerController::LeClearAdvertisingSets() { } uint16_t ExtendedAdvertiser::GetMaxAdvertisingDataLength( - const AdvertisingEventProperties& properties) { + const AdvertisingEventProperties& properties) { // The PDU AdvData size is defined in the following sections: // - Vol 6, Part B § 2.3.1.1 ADV_IND // - Vol 6, Part B § 2.3.1.2 ADV_DIRECT_IND @@ -1263,7 +1199,7 @@ uint16_t ExtendedAdvertiser::GetMaxAdvertisingDataLength( max_advertising_data_length -= 6; // AdvA max_advertising_data_length -= 2; // ADI max_advertising_data_length -= 6 * properties.directed_; // TargetA - max_advertising_data_length -= 1 * properties.tx_power_; // TxPower + max_advertising_data_length -= 1 * properties.include_tx_power_; // TxPower // TODO(pedantic): configure the ACAD field in order to leave the least // amount of AdvData space to the user (191). } @@ -1272,7 +1208,7 @@ uint16_t ExtendedAdvertiser::GetMaxAdvertisingDataLength( } uint16_t ExtendedAdvertiser::GetMaxScanResponseDataLength( - const AdvertisingEventProperties& properties) { + const AdvertisingEventProperties& properties) { // The PDU AdvData size is defined in the following sections: // - Vol 6, Part B § 2.3.2.2 SCAN_RSP // - Vol 6, Part B § 2.3.2.3 AUX_SCAN_RSP @@ -1296,7 +1232,7 @@ uint16_t ExtendedAdvertiser::GetMaxScanResponseDataLength( } uint16_t ExtendedAdvertiser::GetRawAdvertisingEventProperties( - const AdvertisingEventProperties& properties) { + const AdvertisingEventProperties& properties) { uint16_t mask = 0; if (properties.connectable_) { mask |= 0x1; @@ -1316,7 +1252,7 @@ uint16_t ExtendedAdvertiser::GetRawAdvertisingEventProperties( if (properties.anonymous_) { mask |= 0x20; } - if (properties.tx_power_) { + if (properties.include_tx_power_) { mask |= 0x40; } return mask; @@ -1328,8 +1264,8 @@ uint16_t ExtendedAdvertiser::GetRawAdvertisingEventProperties( // HCI LE Set Periodic Advertising Parameters command (Vol 4, Part E § 7.8.61). ErrorCode LinkLayerController::LeSetPeriodicAdvertisingParameters( - uint8_t advertising_handle, uint16_t periodic_advertising_interval_min, - uint16_t periodic_advertising_interval_max, bool /*include_tx_power*/) { + uint8_t advertising_handle, uint16_t periodic_advertising_interval_min, + uint16_t periodic_advertising_interval_max, bool /*include_tx_power*/) { // The Advertising_Handle parameter identifies the advertising set whose // periodic advertising parameters are being configured. If the corresponding // advertising set does not already exist, then the Controller shall return @@ -1345,8 +1281,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingParameters( // The Periodic_Advertising_Interval_Min parameter shall be less than or // equal to the Periodic_Advertising_Interval_Max parameter. - if (periodic_advertising_interval_min < 0x6 || - periodic_advertising_interval_max < 0x6 || + if (periodic_advertising_interval_min < 0x6 || periodic_advertising_interval_max < 0x6 || periodic_advertising_interval_max < periodic_advertising_interval_min) { INFO(id_, "invalid periodic advertising interval range {:04x} - {:04x}", periodic_advertising_interval_min, periodic_advertising_interval_max); @@ -1390,7 +1325,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingParameters( // code Packet Too Long (0x45). if (advertiser.periodic_advertising_data.size() > ExtendedAdvertiser::GetMaxPeriodicAdvertisingDataLength( - slots(periodic_advertising_interval_max))) { + slots(periodic_advertising_interval_max))) { INFO(id_, "the length of the periodic advertising data exceeds the maximum" " that the controller can transmit within the maximum periodic" @@ -1398,15 +1333,14 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingParameters( return ErrorCode::PACKET_TOO_LONG; } - advertiser.periodic_advertising_interval = - slots(periodic_advertising_interval_max); + advertiser.periodic_advertising_interval = slots(periodic_advertising_interval_max); return ErrorCode::SUCCESS; } // HCI LE Set Periodic Advertising Data command (Vol 4, Part E § 7.8.62). ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( - uint8_t advertising_handle, bluetooth::hci::Operation operation, - const std::vector& advertising_data) { + uint8_t advertising_handle, bluetooth::hci::Operation operation, + const std::vector& advertising_data) { // If the advertising set corresponding to the Advertising_Handle parameter // does not exist, then the Controller shall return the error code // Unknown Advertising Identifier (0x42). @@ -1430,8 +1364,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( // If periodic advertising is currently enabled for the specified advertising // set and Operation does not have the value 0x03 or 0x04, then the Controller // shall return the error code Command Disallowed (0x0C). - if (advertiser.periodic_advertising_enable && - operation != Operation::COMPLETE_ADVERTISEMENT && + if (advertiser.periodic_advertising_enable && operation != Operation::COMPLETE_ADVERTISEMENT && operation != Operation::UNCHANGED_DATA) { INFO(id_, "periodic advertising is enabled and the operation is not" @@ -1442,8 +1375,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( // If Operation is not 0x03 or 0x04 and Advertising_Data_Length is zero, // then the Controller shall return the error code // Invalid HCI Command Parameters (0x12). - if (advertising_data.empty() && - operation != Operation::COMPLETE_ADVERTISEMENT && + if (advertising_data.empty() && operation != Operation::COMPLETE_ADVERTISEMENT && operation != Operation::UNCHANGED_DATA) { INFO(id_, "periodic advertising data is empty is enabled and the operation" @@ -1458,22 +1390,19 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( // then the Controller shall return the error code // Invalid HCI Command Parameters (0x12). if (operation == Operation::UNCHANGED_DATA && - (!advertiser.periodic_advertising_enable || - advertiser.periodic_advertising_data.empty() || + (!advertiser.periodic_advertising_enable || advertiser.periodic_advertising_data.empty() || !advertising_data.empty())) { - INFO( - id_, - "Unchanged_Data operation is used but periodic advertising is disabled;" - " or the periodic advertising set contains no data;" - " or the advertising data is not empty"); + INFO(id_, + "Unchanged_Data operation is used but periodic advertising is disabled;" + " or the periodic advertising set contains no data;" + " or the advertising data is not empty"); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } switch (operation) { case Operation::INTERMEDIATE_FRAGMENT: - advertiser.periodic_advertising_data.insert( - advertiser.periodic_advertising_data.end(), advertising_data.begin(), - advertising_data.end()); + advertiser.periodic_advertising_data.insert(advertiser.periodic_advertising_data.end(), + advertising_data.begin(), advertising_data.end()); advertiser.partial_periodic_advertising_data = true; break; @@ -1483,9 +1412,8 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( break; case Operation::LAST_FRAGMENT: - advertiser.periodic_advertising_data.insert( - advertiser.periodic_advertising_data.end(), advertising_data.begin(), - advertising_data.end()); + advertiser.periodic_advertising_data.insert(advertiser.periodic_advertising_data.end(), + advertising_data.begin(), advertising_data.end()); advertiser.partial_periodic_advertising_data = false; break; @@ -1506,8 +1434,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( // set identified by the Advertising_Handle parameter or the amount of memory // currently available, all the data shall be discarded and the Controller // shall return the error code Memory Capacity Exceeded (0x07). - if (advertiser.periodic_advertising_data.size() > - properties_.le_max_advertising_data_length) { + if (advertiser.periodic_advertising_data.size() > properties_.le_max_advertising_data_length) { INFO(id_, "the length of the combined periodic advertising data exceeds" " the maximum advertising data length"); @@ -1522,7 +1449,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( // Controller shall return the error code Packet Too Long (0x45). if (advertiser.periodic_advertising_data.size() > ExtendedAdvertiser::GetMaxPeriodicAdvertisingDataLength( - advertiser.periodic_advertising_interval)) { + advertiser.periodic_advertising_interval)) { INFO(id_, "the length of the combined periodic advertising data exceeds" " the maximum that the controller can transmit within the current" @@ -1536,8 +1463,8 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingData( } // HCI LE Set Periodic Advertising Enable command (Vol 4, Part E § 7.8.63). -ErrorCode LinkLayerController::LeSetPeriodicAdvertisingEnable( - bool enable, bool include_adi, uint8_t advertising_handle) { +ErrorCode LinkLayerController::LeSetPeriodicAdvertisingEnable(bool enable, bool include_adi, + uint8_t advertising_handle) { // If the advertising set corresponding to the Advertising_Handle parameter // does not exist, the Controller shall return the error code Unknown // Advertising Identifier (0x42). @@ -1579,7 +1506,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingEnable( // error code Packet Too Long (0x45). if (advertiser.periodic_advertising_data.size() > ExtendedAdvertiser::GetMaxPeriodicAdvertisingDataLength( - advertiser.periodic_advertising_interval)) { + advertiser.periodic_advertising_interval)) { INFO(id_, "the length of the combined periodic advertising data exceeds" " the maximum that the controller can transmit within the current" @@ -1606,8 +1533,8 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingEnable( // Periodic Advertising ADI Support feature, the Controller shall return an // error which should use the error code Unsupported Feature or // Parameter Value (0x11). - if (include_adi && !properties_.SupportsLLFeature( - LLFeaturesBits::PERIODIC_ADVERTISING_ADI_SUPPORT)) { + if (include_adi && + !properties_.SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_ADI_SUPPORT)) { INFO(id_, "include ADI is true but the controller does not support the" " Periodic Advertising ADI Supported feature", @@ -1620,7 +1547,7 @@ ErrorCode LinkLayerController::LeSetPeriodicAdvertisingEnable( } uint16_t ExtendedAdvertiser::GetMaxPeriodicAdvertisingDataLength( - slots /*periodic_advertising_interval*/) { + slots /*periodic_advertising_interval*/) { // TODO: evaluate the maximum length of the advertising PDU that can // be physically sent in the advertising interval. return max_extended_advertising_pdu_size; @@ -1657,17 +1584,16 @@ void LinkLayerController::LeAdvertising() { // is unmasked. #if 0 if (IsLeEventUnmasked(SubeventCode::ENHANCED_CONNECTION_COMPLETE)) { - send_event_(bluetooth::hci::LeEnhancedConnectionCompleteBuilder::Create( + send_event_(bluetooth::hci::LeEnhancedConnectionCompleteV1Builder::Create( ErrorCode::ADVERTISING_TIMEOUT, 0, Role::CENTRAL, AddressType::PUBLIC_DEVICE_ADDRESS, Address(), Address(), Address(), 0, 0, 0, ClockAccuracy::PPM_500)); } else #endif - if (IsLeEventUnmasked(SubeventCode::CONNECTION_COMPLETE)) { + if (IsLeEventUnmasked(SubeventCode::LE_CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::LeConnectionCompleteBuilder::Create( - ErrorCode::ADVERTISING_TIMEOUT, 0, Role::CENTRAL, - AddressType::PUBLIC_DEVICE_ADDRESS, Address(), 0, 0, 0, - ClockAccuracy::PPM_500)); + ErrorCode::ADVERTISING_TIMEOUT, 0, Role::CENTRAL, AddressType::PUBLIC_DEVICE_ADDRESS, + Address(), 0, 0, 0, ClockAccuracy::PPM_500)); } } @@ -1676,8 +1602,7 @@ void LinkLayerController::LeAdvertising() { // Generate Link Layer Advertising events when advertising is enabled // and a full interval has passed since the last event. if (legacy_advertiser_.IsEnabled() && now >= legacy_advertiser_.next_event) { - legacy_advertiser_.next_event = - now + legacy_advertiser_.advertising_interval; + legacy_advertiser_.next_event = now + legacy_advertiser_.advertising_interval; model::packets::LegacyAdvertisingType type; bool attach_advertising_data = true; switch (legacy_advertiser_.advertising_type) { @@ -1697,18 +1622,17 @@ void LinkLayerController::LeAdvertising() { break; } - SendLeLinkLayerPacket( - model::packets::LeLegacyAdvertisingPduBuilder::Create( - legacy_advertiser_.advertising_address.GetAddress(), - legacy_advertiser_.target_address.GetAddress(), - static_cast( - legacy_advertiser_.advertising_address.GetAddressType()), - static_cast( - legacy_advertiser_.target_address.GetAddressType()), - type, - attach_advertising_data ? legacy_advertiser_.advertising_data - : std::vector{}), - properties_.le_advertising_physical_channel_tx_power); + SendLeLinkLayerPacket(model::packets::LeLegacyAdvertisingPduBuilder::Create( + legacy_advertiser_.advertising_address.GetAddress(), + legacy_advertiser_.target_address.GetAddress(), + static_cast( + legacy_advertiser_.advertising_address.GetAddressType()), + static_cast( + legacy_advertiser_.target_address.GetAddressType()), + type, + attach_advertising_data ? legacy_advertiser_.advertising_data + : std::vector{}), + properties_.le_advertising_physical_channel_tx_power); } for (auto& [_, advertiser] : extended_advertisers_) { @@ -1730,44 +1654,43 @@ void LinkLayerController::LeAdvertising() { advertiser.Disable(); bool high_duty_cycle_connectable_directed_advertising = - advertiser.advertising_event_properties.directed_ && - advertiser.advertising_event_properties.connectable_ && - advertiser.advertising_event_properties.high_duty_cycle_; + advertiser.advertising_event_properties.directed_ && + advertiser.advertising_event_properties.connectable_ && + advertiser.advertising_event_properties.high_duty_cycle_; // Note: HCI_LE_Connection_Complete is not sent if the // HCI_LE_Enhanced_Connection_Complete event (see Section 7.7.65.10) // is unmasked. if (high_duty_cycle_connectable_directed_advertising && - IsLeEventUnmasked(SubeventCode::ENHANCED_CONNECTION_COMPLETE)) { - send_event_(bluetooth::hci::LeEnhancedConnectionCompleteBuilder::Create( - ErrorCode::ADVERTISING_TIMEOUT, 0, Role::CENTRAL, - AddressType::PUBLIC_DEVICE_ADDRESS, Address(), Address(), Address(), - 0, 0, 0, ClockAccuracy::PPM_500)); + IsLeEventUnmasked(SubeventCode::LE_ENHANCED_CONNECTION_COMPLETE_V1)) { + send_event_(bluetooth::hci::LeEnhancedConnectionCompleteV1Builder::Create( + ErrorCode::ADVERTISING_TIMEOUT, 0, Role::CENTRAL, + AddressType::PUBLIC_DEVICE_ADDRESS, Address(), Address(), Address(), 0, 0, 0, + ClockAccuracy::PPM_500)); } else if (high_duty_cycle_connectable_directed_advertising && - IsLeEventUnmasked(SubeventCode::CONNECTION_COMPLETE)) { + IsLeEventUnmasked(SubeventCode::LE_CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::LeConnectionCompleteBuilder::Create( - ErrorCode::ADVERTISING_TIMEOUT, 0, Role::CENTRAL, - AddressType::PUBLIC_DEVICE_ADDRESS, Address(), 0, 0, 0, - ClockAccuracy::PPM_500)); + ErrorCode::ADVERTISING_TIMEOUT, 0, Role::CENTRAL, + AddressType::PUBLIC_DEVICE_ADDRESS, Address(), 0, 0, 0, ClockAccuracy::PPM_500)); } - if (IsLeEventUnmasked(SubeventCode::ADVERTISING_SET_TERMINATED)) { + if (IsLeEventUnmasked(SubeventCode::LE_ADVERTISING_SET_TERMINATED)) { // The parameter Num_Completed_Extended_Advertising_Events is set // only when Max_Extended_Advertising_Events was configured as // non-zero in the advertising parameters. uint8_t num_completed_extended_advertising_events = - advertiser.max_extended_advertising_events != 0 - ? advertiser.num_completed_extended_advertising_events - : 0; + advertiser.max_extended_advertising_events != 0 + ? advertiser.num_completed_extended_advertising_events + : 0; send_event_(bluetooth::hci::LeAdvertisingSetTerminatedBuilder::Create( - ErrorCode::ADVERTISING_TIMEOUT, advertiser.advertising_handle, 0, - num_completed_extended_advertising_events)); + ErrorCode::ADVERTISING_TIMEOUT, advertiser.advertising_handle, 0, + num_completed_extended_advertising_events)); } } if (advertiser.IsEnabled() && advertiser.max_extended_advertising_events && advertiser.num_completed_extended_advertising_events >= - advertiser.max_extended_advertising_events) { + advertiser.max_extended_advertising_events) { // If the Max_Extended_Advertising_Events[i] parameter is set to a value // other than 0x00, an HCI_LE_Advertising_Set_Terminated event shall be // generated when the maximum number of extended advertising events has @@ -1775,10 +1698,10 @@ void LinkLayerController::LeAdvertising() { INFO(id_, "Max Extended Advertising count reached"); advertiser.Disable(); - if (IsLeEventUnmasked(SubeventCode::ADVERTISING_SET_TERMINATED)) { + if (IsLeEventUnmasked(SubeventCode::LE_ADVERTISING_SET_TERMINATED)) { send_event_(bluetooth::hci::LeAdvertisingSetTerminatedBuilder::Create( - ErrorCode::ADVERTISING_TIMEOUT, advertiser.advertising_handle, 0, - advertiser.num_completed_extended_advertising_events)); + ErrorCode::ADVERTISING_TIMEOUT, advertiser.advertising_handle, 0, + advertiser.num_completed_extended_advertising_events)); } } @@ -1793,10 +1716,10 @@ void LinkLayerController::LeAdvertising() { if (advertiser.advertising_event_properties.legacy_) { model::packets::LegacyAdvertisingType type; uint16_t raw_advertising_event_properties = - ExtendedAdvertiser::GetRawAdvertisingEventProperties( - advertiser.advertising_event_properties); - switch (static_cast( - raw_advertising_event_properties & 0xf)) { + ExtendedAdvertiser::GetRawAdvertisingEventProperties( + advertiser.advertising_event_properties); + switch (static_cast(raw_advertising_event_properties & + 0xf)) { case LegacyAdvertisingEventProperties::ADV_IND: type = model::packets::LegacyAdvertisingType::ADV_IND; break; @@ -1811,43 +1734,39 @@ void LinkLayerController::LeAdvertising() { type = model::packets::LegacyAdvertisingType::ADV_NONCONN_IND; break; default: - FATAL( - id_, - "unexpected raw advertising event properties;" - " please check the extended advertising parameter validation"); + FATAL(id_, + "unexpected raw advertising event properties;" + " please check the extended advertising parameter validation"); break; } - SendLeLinkLayerPacket( - model::packets::LeLegacyAdvertisingPduBuilder::Create( - advertiser.advertising_address.GetAddress(), - advertiser.target_address.GetAddress(), - static_cast( - advertiser.advertising_address.GetAddressType()), - static_cast( - advertiser.target_address.GetAddressType()), - type, advertiser.advertising_data), - advertiser.advertising_tx_power); + SendLeLinkLayerPacket(model::packets::LeLegacyAdvertisingPduBuilder::Create( + advertiser.advertising_address.GetAddress(), + advertiser.target_address.GetAddress(), + static_cast( + advertiser.advertising_address.GetAddressType()), + static_cast( + advertiser.target_address.GetAddressType()), + type, advertiser.advertising_data), + advertiser.advertising_tx_power); } else { SendLeLinkLayerPacket( - model::packets::LeExtendedAdvertisingPduBuilder::Create( - advertiser.advertising_address.GetAddress(), - advertiser.target_address.GetAddress(), - static_cast( - advertiser.advertising_address.GetAddressType()), - static_cast( - advertiser.target_address.GetAddressType()), - advertiser.advertising_event_properties.connectable_, - advertiser.advertising_event_properties.scannable_, - advertiser.advertising_event_properties.directed_, - advertiser.advertising_sid, advertiser.advertising_tx_power, - static_cast( - advertiser.primary_advertising_phy), - static_cast( - advertiser.secondary_advertising_phy), - advertiser.periodic_advertising_interval.count(), - advertiser.advertising_data), - advertiser.advertising_tx_power); + model::packets::LeExtendedAdvertisingPduBuilder::Create( + advertiser.advertising_address.GetAddress(), + advertiser.target_address.GetAddress(), + static_cast( + advertiser.advertising_address.GetAddressType()), + static_cast( + advertiser.target_address.GetAddressType()), + advertiser.advertising_event_properties.connectable_, + advertiser.advertising_event_properties.scannable_, + advertiser.advertising_event_properties.directed_, + advertiser.advertising_sid, advertiser.advertising_tx_power, + static_cast(advertiser.primary_advertising_phy), + static_cast(advertiser.secondary_advertising_phy), + advertiser.periodic_advertising_interval.count(), + advertiser.advertising_data), + advertiser.advertising_tx_power); } } @@ -1855,19 +1774,16 @@ void LinkLayerController::LeAdvertising() { // Generate Link Layer Advertising events when advertising is enabled // and a full interval has passed since the last event. - if (advertiser.IsPeriodicEnabled() && - now >= advertiser.next_periodic_event) { - advertiser.next_periodic_event += - advertiser.periodic_advertising_interval; - SendLeLinkLayerPacket( - model::packets::LePeriodicAdvertisingPduBuilder::Create( - advertiser.advertising_address.GetAddress(), Address(), - static_cast( - advertiser.advertising_address.GetAddressType()), - advertiser.advertising_sid, advertiser.advertising_tx_power, - advertiser.periodic_advertising_interval.count(), - advertiser.periodic_advertising_data), - advertiser.advertising_tx_power); + if (advertiser.IsPeriodicEnabled() && now >= advertiser.next_periodic_event) { + advertiser.next_periodic_event += advertiser.periodic_advertising_interval; + SendLeLinkLayerPacket(model::packets::LePeriodicAdvertisingPduBuilder::Create( + advertiser.advertising_address.GetAddress(), Address(), + static_cast( + advertiser.advertising_address.GetAddressType()), + advertiser.advertising_sid, advertiser.advertising_tx_power, + advertiser.periodic_advertising_interval.count(), + advertiser.periodic_advertising_data), + advertiser.advertising_tx_power); } } } diff --git a/model/controller/le_advertiser.h b/model/controller/le_advertiser.h index cef6516..f365370 100644 --- a/model/controller/le_advertiser.h +++ b/model/controller/le_advertiser.h @@ -29,8 +29,7 @@ namespace rootcanal { // Duration type for slots (increments of 625us). -using slots = - std::chrono::duration>; +using slots = std::chrono::duration>; // User defined literal for slots, e.g. `0x800_slots` slots operator"" _slots(unsigned long long count); @@ -39,7 +38,7 @@ using namespace bluetooth::hci; // Advertising interface common to legacy and extended advertisers. class Advertiser { - public: +public: Advertiser() = default; ~Advertiser() = default; @@ -51,10 +50,8 @@ class Advertiser { // HCI properties. bool advertising_enable{false}; - AddressWithType advertising_address{Address::kEmpty, - AddressType::PUBLIC_DEVICE_ADDRESS}; - AddressWithType target_address{Address::kEmpty, - AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType advertising_address{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType target_address{Address::kEmpty, AddressType::PUBLIC_DEVICE_ADDRESS}; // Time keeping. std::chrono::steady_clock::time_point next_event{}; @@ -64,7 +61,7 @@ class Advertiser { // Implement the unique legacy advertising instance. // For extended advertising check the ExtendedAdvertiser class. class LegacyAdvertiser : public Advertiser { - public: +public: LegacyAdvertiser() = default; ~LegacyAdvertiser() = default; @@ -91,12 +88,10 @@ class LegacyAdvertiser : public Advertiser { slots advertising_interval{0x0800}; AdvertisingType advertising_type{AdvertisingType::ADV_IND}; OwnAddressType own_address_type{OwnAddressType::PUBLIC_DEVICE_ADDRESS}; - PeerAddressType peer_address_type{ - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS}; + PeerAddressType peer_address_type{PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS}; Address peer_address{}; uint8_t advertising_channel_map{0x07}; - AdvertisingFilterPolicy advertising_filter_policy{ - AdvertisingFilterPolicy::ALL_DEVICES}; + AdvertisingFilterPolicy advertising_filter_policy{AdvertisingFilterPolicy::ALL_DEVICES}; std::vector advertising_data{}; std::vector scan_response_data{}; }; @@ -105,9 +100,8 @@ class LegacyAdvertiser : public Advertiser { // The configuration is set by the extended advertising commands; // for the legacy advertiser check the LegacyAdvertiser class. class ExtendedAdvertiser : public Advertiser { - public: - ExtendedAdvertiser(uint8_t advertising_handle = 0) - : advertising_handle(advertising_handle) {} +public: + ExtendedAdvertiser(uint8_t advertising_handle = 0) : advertising_handle(advertising_handle) {} ~ExtendedAdvertiser() = default; void Enable() { @@ -130,9 +124,7 @@ class ExtendedAdvertiser : public Advertiser { bool IsPeriodicEnabled() const { return periodic_advertising_enable_latch; } bool IsScannable() const { return advertising_event_properties.scannable_; } - bool IsConnectable() const { - return advertising_event_properties.connectable_; - } + bool IsConnectable() const { return advertising_event_properties.connectable_; } bool IsDirected() const { return advertising_event_properties.directed_; } @@ -192,23 +184,19 @@ class ExtendedAdvertiser : public Advertiser { // Compute the maximum advertising data payload size for the selected // advertising event properties. The advertising data is not present if // 0 is returned. - static uint16_t GetMaxAdvertisingDataLength( - const AdvertisingEventProperties& properties); + static uint16_t GetMaxAdvertisingDataLength(const AdvertisingEventProperties& properties); // Compute the maximum scan response data payload size for the selected // advertising event properties. The scan response data is not present if // 0 is returned. - static uint16_t GetMaxScanResponseDataLength( - const AdvertisingEventProperties& properties); + static uint16_t GetMaxScanResponseDataLength(const AdvertisingEventProperties& properties); // Reconstitute the raw Advertising_Event_Properties bitmask. - static uint16_t GetRawAdvertisingEventProperties( - const AdvertisingEventProperties& properties); + static uint16_t GetRawAdvertisingEventProperties(const AdvertisingEventProperties& properties); // Compute the maximum periodic advertising data payload size for the // selected periodic advertising interval. - static uint16_t GetMaxPeriodicAdvertisingDataLength( - slots periodic_advertising_interval); + static uint16_t GetMaxPeriodicAdvertisingDataLength(slots periodic_advertising_interval); }; } // namespace rootcanal diff --git a/model/controller/link_layer_controller.cc b/model/controller/link_layer_controller.cc index e37a313..04416e8 100644 --- a/model/controller/link_layer_controller.cc +++ b/model/controller/link_layer_controller.cc @@ -64,8 +64,7 @@ constexpr milliseconds kPageInterval(1000); const Address& LinkLayerController::GetAddress() const { return address_; } -AddressWithType PeerDeviceAddress(Address address, - PeerAddressType peer_address_type) { +AddressWithType PeerDeviceAddress(Address address, PeerAddressType peer_address_type) { switch (peer_address_type) { case PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS: return AddressWithType(address, AddressType::PUBLIC_DEVICE_ADDRESS); @@ -74,8 +73,7 @@ AddressWithType PeerDeviceAddress(Address address, } } -AddressWithType PeerIdentityAddress(Address address, - PeerAddressType peer_address_type) { +AddressWithType PeerIdentityAddress(Address address, PeerAddressType peer_address_type) { switch (peer_address_type) { case PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS: return AddressWithType(address, AddressType::PUBLIC_IDENTITY_ADDRESS); @@ -85,14 +83,21 @@ AddressWithType PeerIdentityAddress(Address address, } bool LinkLayerController::IsEventUnmasked(EventCode event) const { - uint64_t bit = UINT64_C(1) << (static_cast(event) - 1); - return (event_mask_ & bit) != 0; + uint8_t evt = static_cast(event); + + if (evt <= 64) { + uint64_t bit = UINT64_C(1) << (evt - 1); + return (event_mask_ & bit) != 0; + } else { + evt -= 64; + uint64_t bit = UINT64_C(1) << (evt - 1); + return (event_mask_page_2_ & bit) != 0; + } } bool LinkLayerController::IsLeEventUnmasked(SubeventCode subevent) const { uint64_t bit = UINT64_C(1) << (static_cast(subevent) - 1); - return IsEventUnmasked(EventCode::LE_META_EVENT) && - (le_event_mask_ & bit) != 0; + return IsEventUnmasked(EventCode::LE_META_EVENT) && (le_event_mask_ & bit) != 0; } bool LinkLayerController::FilterAcceptListBusy() { @@ -101,14 +106,13 @@ bool LinkLayerController::FilterAcceptListBusy() { // advertising is enabled, if (legacy_advertiser_.IsEnabled() && legacy_advertiser_.advertising_filter_policy != - bluetooth::hci::AdvertisingFilterPolicy::ALL_DEVICES) { + bluetooth::hci::AdvertisingFilterPolicy::ALL_DEVICES) { return true; } for (auto const& [_, advertiser] : extended_advertisers_) { - if (advertiser.IsEnabled() && - advertiser.advertising_filter_policy != - bluetooth::hci::AdvertisingFilterPolicy::ALL_DEVICES) { + if (advertiser.IsEnabled() && advertiser.advertising_filter_policy != + bluetooth::hci::AdvertisingFilterPolicy::ALL_DEVICES) { return true; } } @@ -117,10 +121,9 @@ bool LinkLayerController::FilterAcceptListBusy() { // is enabled, if (scanner_.IsEnabled() && (scanner_.scan_filter_policy == - bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY || - scanner_.scan_filter_policy == - bluetooth::hci::LeScanningFilterPolicy:: - FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY)) { + bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY || + scanner_.scan_filter_policy == bluetooth::hci::LeScanningFilterPolicy:: + FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY)) { return true; } @@ -129,15 +132,15 @@ bool LinkLayerController::FilterAcceptListBusy() { // command is pending. if (initiator_.IsEnabled() && initiator_.initiator_filter_policy == - bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST) { + bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST_WITH_PEER_ADDRESS) { return true; } return false; } -bool LinkLayerController::LeFilterAcceptListContainsDevice( - FilterAcceptListAddressType address_type, Address address) { +bool LinkLayerController::LeFilterAcceptListContainsDevice(FilterAcceptListAddressType address_type, + Address address) { for (auto const& entry : le_filter_accept_list_) { if (entry.address_type == address_type && (address_type == FilterAcceptListAddressType::ANONYMOUS_ADVERTISERS || @@ -150,8 +153,8 @@ bool LinkLayerController::LeFilterAcceptListContainsDevice( } bool LinkLayerController::LePeriodicAdvertiserListContainsDevice( - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint8_t advertising_sid) { + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint8_t advertising_sid) { for (auto const& entry : le_periodic_advertiser_list_) { if (entry.advertiser_address_type == advertiser_address_type && entry.advertiser_address == advertiser_address && @@ -163,8 +166,7 @@ bool LinkLayerController::LePeriodicAdvertiserListContainsDevice( return false; } -bool LinkLayerController::LeFilterAcceptListContainsDevice( - AddressWithType address) { +bool LinkLayerController::LeFilterAcceptListContainsDevice(AddressWithType address) { FilterAcceptListAddressType address_type; switch (address.GetAddressType()) { case AddressType::PUBLIC_DEVICE_ADDRESS: @@ -207,8 +209,7 @@ bool LinkLayerController::ResolvingListBusy() { return false; } -std::optional LinkLayerController::ResolvePrivateAddress( - AddressWithType address) { +std::optional LinkLayerController::ResolvePrivateAddress(AddressWithType address) { if (!address.IsRpa()) { return address; } @@ -223,23 +224,20 @@ std::optional LinkLayerController::ResolvePrivateAddress( // with the returned identity address. entry.peer_resolvable_address = address.GetAddress(); - return PeerDeviceAddress(entry.peer_identity_address, - entry.peer_identity_address_type); + return PeerDeviceAddress(entry.peer_identity_address, entry.peer_identity_address_type); } } return {}; } -bool LinkLayerController::ResolveTargetA(AddressWithType target_a, - AddressWithType adv_a) { +bool LinkLayerController::ResolveTargetA(AddressWithType target_a, AddressWithType adv_a) { if (!le_resolving_list_enabled_) { return false; } for (auto const& entry : le_resolving_list_) { - if (adv_a == PeerDeviceAddress(entry.peer_identity_address, - entry.peer_identity_address_type) && + if (adv_a == PeerDeviceAddress(entry.peer_identity_address, entry.peer_identity_address_type) && target_a.IsRpaThatMatchesIrk(entry.local_irk)) { return true; } @@ -248,8 +246,7 @@ bool LinkLayerController::ResolveTargetA(AddressWithType target_a, return false; } -bool LinkLayerController::ValidateTargetA(AddressWithType target_a, - AddressWithType adv_a) { +bool LinkLayerController::ValidateTargetA(AddressWithType target_a, AddressWithType adv_a) { if (IsLocalPublicOrRandomAddress(target_a)) { return true; } @@ -259,14 +256,13 @@ bool LinkLayerController::ValidateTargetA(AddressWithType target_a, return false; } -std::optional -LinkLayerController::GenerateResolvablePrivateAddress(AddressWithType address, - IrkSelection irk) { +std::optional LinkLayerController::GenerateResolvablePrivateAddress( + AddressWithType address, IrkSelection irk) { for (auto& entry : le_resolving_list_) { if (address.GetAddress() == entry.peer_identity_address && address.ToPeerAddressType() == entry.peer_identity_address_type) { std::array const& used_irk = - irk == IrkSelection::Local ? entry.local_irk : entry.peer_irk; + irk == IrkSelection::Local ? entry.local_irk : entry.peer_irk; Address local_resolvable_address = generate_rpa(used_irk); // Update the local resolvable address used for the peer @@ -275,8 +271,7 @@ LinkLayerController::GenerateResolvablePrivateAddress(AddressWithType address, entry.local_resolvable_address = local_resolvable_address; } - return AddressWithType{local_resolvable_address, - AddressType::RANDOM_DEVICE_ADDRESS}; + return AddressWithType{local_resolvable_address, AddressType::RANDOM_DEVICE_ADDRESS}; } } @@ -288,8 +283,7 @@ LinkLayerController::GenerateResolvablePrivateAddress(AddressWithType address, // ============================================================================= // HCI Read Rssi command (Vol 4, Part E § 7.5.4). -ErrorCode LinkLayerController::ReadRssi(uint16_t connection_handle, - int8_t* rssi) { +ErrorCode LinkLayerController::ReadRssi(uint16_t connection_handle, int8_t* rssi) { // Not documented: If the connection handle is not found, the Controller // shall return the error code Unknown Connection Identifier (0x02). if (!connections_.HasHandle(connection_handle)) { @@ -310,8 +304,7 @@ ErrorCode LinkLayerController::LeSetRandomAddress(Address random_address) { // If the Host issues this command when any of advertising (created using // legacy advertising commands), scanning, or initiating are enabled, // the Controller shall return the error code Command Disallowed (0x0C). - if (legacy_advertiser_.IsEnabled() || scanner_.IsEnabled() || - initiator_.IsEnabled()) { + if (legacy_advertiser_.IsEnabled() || scanner_.IsEnabled() || initiator_.IsEnabled()) { INFO(id_, "advertising, scanning or initiating are currently active"); return ErrorCode::COMMAND_DISALLOWED; } @@ -326,8 +319,7 @@ ErrorCode LinkLayerController::LeSetRandomAddress(Address random_address) { } // HCI LE Set Host Feature command (Vol 4, Part E § 7.8.45). -ErrorCode LinkLayerController::LeSetResolvablePrivateAddressTimeout( - uint16_t rpa_timeout) { +ErrorCode LinkLayerController::LeSetResolvablePrivateAddressTimeout(uint16_t rpa_timeout) { // Note: no documented status code for this case. if (rpa_timeout < 0x1 || rpa_timeout > 0x0e10) { INFO(id_, @@ -352,17 +344,16 @@ ErrorCode LinkLayerController::LeReadPhy(uint16_t connection_handle, return ErrorCode::UNKNOWN_CONNECTION; } - AclConnection const& connection = - connections_.GetAclConnection(connection_handle); + AclConnection const& connection = connections_.GetAclConnection(connection_handle); *tx_phy = connection.GetTxPhy(); *rx_phy = connection.GetRxPhy(); return ErrorCode::SUCCESS; } // HCI LE Set Default Phy command (Vol 4, Part E § 7.8.48). -ErrorCode LinkLayerController::LeSetDefaultPhy( - bool all_phys_no_transmit_preference, bool all_phys_no_receive_preference, - uint8_t tx_phys, uint8_t rx_phys) { +ErrorCode LinkLayerController::LeSetDefaultPhy(bool all_phys_no_transmit_preference, + bool all_phys_no_receive_preference, uint8_t tx_phys, + uint8_t rx_phys) { uint8_t supported_phys = properties_.LeSupportedPhys(); // If the All_PHYs parameter specifies that the Host has no preference, @@ -406,10 +397,11 @@ ErrorCode LinkLayerController::LeSetDefaultPhy( } // HCI LE Set Phy command (Vol 4, Part E § 7.8.49). -ErrorCode LinkLayerController::LeSetPhy( - uint16_t connection_handle, bool all_phys_no_transmit_preference, - bool all_phys_no_receive_preference, uint8_t tx_phys, uint8_t rx_phys, - bluetooth::hci::PhyOptions /*phy_options*/) { +ErrorCode LinkLayerController::LeSetPhy(uint16_t connection_handle, + bool all_phys_no_transmit_preference, + bool all_phys_no_receive_preference, uint8_t tx_phys, + uint8_t rx_phys, + bluetooth::hci::PhyOptions /*phy_options*/) { uint8_t supported_phys = properties_.LeSupportedPhys(); // Note: no documented status code for this case. @@ -446,13 +438,11 @@ ErrorCode LinkLayerController::LeSetPhy( // future use, the Controller shall return the error code Unsupported Feature // or Parameter Value (0x11). if ((tx_phys & ~supported_phys) != 0) { - INFO(id_, "TX_PhyS ({:x}) configures unsupported or reserved bits", - tx_phys); + INFO(id_, "TX_PhyS ({:x}) configures unsupported or reserved bits", tx_phys); return ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; } if ((rx_phys & ~supported_phys) != 0) { - INFO(id_, "RX_PhyS ({:x}) configures unsupported or reserved bits", - rx_phys); + INFO(id_, "RX_PhyS ({:x}) configures unsupported or reserved bits", rx_phys); return ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; } @@ -460,9 +450,8 @@ ErrorCode LinkLayerController::LeSetPhy( // or both PHY changes or when the Controller determines that neither PHY // will change immediately. SendLeLinkLayerPacket(model::packets::LlPhyReqBuilder::Create( - connections_.GetOwnAddress(connection_handle).GetAddress(), - connections_.GetAddress(connection_handle).GetAddress(), tx_phys, - rx_phys)); + connections_.GetOwnAddress(connection_handle).GetAddress(), + connections_.GetAddress(connection_handle).GetAddress(), tx_phys, rx_phys)); connections_.GetAclConnection(connection_handle).InitiatePhyUpdate(); requested_tx_phys_ = tx_phys; @@ -471,8 +460,7 @@ ErrorCode LinkLayerController::LeSetPhy( } // Helper to pick one phy in enabled phys. -static bluetooth::hci::PhyType select_phy(uint8_t phys, - bluetooth::hci::PhyType current) { +static bluetooth::hci::PhyType select_phy(uint8_t phys, bluetooth::hci::PhyType current) { return (phys & 0x4) ? bluetooth::hci::PhyType::LE_CODED : (phys & 0x2) ? bluetooth::hci::PhyType::LE_2M : (phys & 0x1) ? bluetooth::hci::PhyType::LE_1M @@ -481,20 +469,17 @@ static bluetooth::hci::PhyType select_phy(uint8_t phys, // Helper to generate the LL_PHY_UPDATE_IND mask for the selected phy. // The mask is non zero only if the phy has changed. -static uint8_t indicate_phy(bluetooth::hci::PhyType selected, - bluetooth::hci::PhyType current) { +static uint8_t indicate_phy(bluetooth::hci::PhyType selected, bluetooth::hci::PhyType current) { return selected == current ? 0x0 : selected == bluetooth::hci::PhyType::LE_CODED ? 0x4 : selected == bluetooth::hci::PhyType::LE_2M ? 0x2 : 0x1; } -void LinkLayerController::IncomingLlPhyReq( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingLlPhyReq(model::packets::LinkLayerPacketView incoming) { auto phy_req = model::packets::LlPhyReqView::Create(incoming); ASSERT(phy_req.IsValid()); - uint16_t connection_handle = - connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); + uint16_t connection_handle = connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); if (connection_handle == kReservedHandle) { INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), @@ -508,8 +493,8 @@ void LinkLayerController::IncomingLlPhyReq( // Peripheral receives the request: respond with local phy preferences // in LL_PHY_RSP pdu. SendLeLinkLayerPacket(model::packets::LlPhyRspBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - default_tx_phys_, default_rx_phys_)); + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), default_tx_phys_, + default_rx_phys_)); } else { // Central receives the request: respond with LL_PHY_UPDATE_IND and // the selected phys. @@ -519,10 +504,8 @@ void LinkLayerController::IncomingLlPhyReq( uint8_t rx_phys = phy_req.GetTxPhys() & default_rx_phys_; // Select valid TX and RX phys from preferences. - bluetooth::hci::PhyType phy_c_to_p = - select_phy(tx_phys, connection.GetTxPhy()); - bluetooth::hci::PhyType phy_p_to_c = - select_phy(rx_phys, connection.GetRxPhy()); + bluetooth::hci::PhyType phy_c_to_p = select_phy(tx_phys, connection.GetTxPhy()); + bluetooth::hci::PhyType phy_p_to_c = select_phy(rx_phys, connection.GetRxPhy()); // Send LL_PHY_UPDATE_IND to notify selected phys. // @@ -532,17 +515,16 @@ void LinkLayerController::IncomingLlPhyReq( // PHY shall be set to 1 and the remaining bits to 0; if a PHY is remaining // unchanged, then the corresponding field shall be set to the value 0. SendLeLinkLayerPacket(model::packets::LlPhyUpdateIndBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - indicate_phy(phy_c_to_p, connection.GetTxPhy()), - indicate_phy(phy_p_to_c, connection.GetRxPhy()), 0)); + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), + indicate_phy(phy_c_to_p, connection.GetTxPhy()), + indicate_phy(phy_p_to_c, connection.GetRxPhy()), 0)); // Notify the host when the phy selection has changed // (responder in this case). - if ((phy_c_to_p != connection.GetTxPhy() || - phy_p_to_c != connection.GetRxPhy()) && - IsLeEventUnmasked(SubeventCode::PHY_UPDATE_COMPLETE)) { + if ((phy_c_to_p != connection.GetTxPhy() || phy_p_to_c != connection.GetRxPhy()) && + IsLeEventUnmasked(SubeventCode::LE_PHY_UPDATE_COMPLETE)) { send_event_(bluetooth::hci::LePhyUpdateCompleteBuilder::Create( - ErrorCode::SUCCESS, connection_handle, phy_c_to_p, phy_p_to_c)); + ErrorCode::SUCCESS, connection_handle, phy_c_to_p, phy_p_to_c)); } // Update local state. @@ -551,12 +533,10 @@ void LinkLayerController::IncomingLlPhyReq( } } -void LinkLayerController::IncomingLlPhyRsp( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingLlPhyRsp(model::packets::LinkLayerPacketView incoming) { auto phy_rsp = model::packets::LlPhyRspView::Create(incoming); ASSERT(phy_rsp.IsValid()); - uint16_t connection_handle = - connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); + uint16_t connection_handle = connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); if (connection_handle == kReservedHandle) { INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), @@ -572,10 +552,8 @@ void LinkLayerController::IncomingLlPhyRsp( uint8_t rx_phys = phy_rsp.GetTxPhys() & requested_rx_phys_; // Select valid TX and RX phys from preferences. - bluetooth::hci::PhyType phy_c_to_p = - select_phy(tx_phys, connection.GetTxPhy()); - bluetooth::hci::PhyType phy_p_to_c = - select_phy(rx_phys, connection.GetRxPhy()); + bluetooth::hci::PhyType phy_c_to_p = select_phy(tx_phys, connection.GetTxPhy()); + bluetooth::hci::PhyType phy_p_to_c = select_phy(rx_phys, connection.GetRxPhy()); // Send LL_PHY_UPDATE_IND to notify selected phys. // @@ -585,15 +563,15 @@ void LinkLayerController::IncomingLlPhyRsp( // PHY shall be set to 1 and the remaining bits to 0; if a PHY is remaining // unchanged, then the corresponding field shall be set to the value 0. SendLeLinkLayerPacket(model::packets::LlPhyUpdateIndBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - indicate_phy(phy_c_to_p, connection.GetTxPhy()), - indicate_phy(phy_p_to_c, connection.GetRxPhy()), 0)); + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), + indicate_phy(phy_c_to_p, connection.GetTxPhy()), + indicate_phy(phy_p_to_c, connection.GetRxPhy()), 0)); // Always notify the host, even if the phy selection has not changed // (initiator in this case). - if (IsLeEventUnmasked(SubeventCode::PHY_UPDATE_COMPLETE)) { + if (IsLeEventUnmasked(SubeventCode::LE_PHY_UPDATE_COMPLETE)) { send_event_(bluetooth::hci::LePhyUpdateCompleteBuilder::Create( - ErrorCode::SUCCESS, connection_handle, phy_c_to_p, phy_p_to_c)); + ErrorCode::SUCCESS, connection_handle, phy_c_to_p, phy_p_to_c)); } // Update local state. @@ -602,12 +580,10 @@ void LinkLayerController::IncomingLlPhyRsp( connection.SetRxPhy(phy_p_to_c); } -void LinkLayerController::IncomingLlPhyUpdateInd( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingLlPhyUpdateInd(model::packets::LinkLayerPacketView incoming) { auto phy_update_ind = model::packets::LlPhyUpdateIndView::Create(incoming); ASSERT(phy_update_ind.IsValid()); - uint16_t connection_handle = - connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); + uint16_t connection_handle = connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); if (connection_handle == kReservedHandle) { INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), @@ -618,19 +594,17 @@ void LinkLayerController::IncomingLlPhyUpdateInd( AclConnection& connection = connections_.GetAclConnection(connection_handle); ASSERT(connection.GetRole() == bluetooth::hci::Role::PERIPHERAL); - bluetooth::hci::PhyType tx_phy = - select_phy(phy_update_ind.GetPhyPToC(), connection.GetTxPhy()); - bluetooth::hci::PhyType rx_phy = - select_phy(phy_update_ind.GetPhyCToP(), connection.GetRxPhy()); + bluetooth::hci::PhyType tx_phy = select_phy(phy_update_ind.GetPhyPToC(), connection.GetTxPhy()); + bluetooth::hci::PhyType rx_phy = select_phy(phy_update_ind.GetPhyCToP(), connection.GetRxPhy()); // Update local state, and notify the host. // The notification is sent only when the local host is initiator // of the Phy update procedure or the phy selection has changed. - if (IsLeEventUnmasked(SubeventCode::PHY_UPDATE_COMPLETE) && + if (IsLeEventUnmasked(SubeventCode::LE_PHY_UPDATE_COMPLETE) && (tx_phy != connection.GetTxPhy() || rx_phy != connection.GetRxPhy() || connection.InitiatedPhyUpdate())) { send_event_(bluetooth::hci::LePhyUpdateCompleteBuilder::Create( - ErrorCode::SUCCESS, connection_handle, tx_phy, rx_phy)); + ErrorCode::SUCCESS, connection_handle, tx_phy, rx_phy)); } connection.PhyUpdateComplete(); @@ -639,8 +613,7 @@ void LinkLayerController::IncomingLlPhyUpdateInd( } // HCI LE Set Host Feature command (Vol 4, Part E § 7.8.115). -ErrorCode LinkLayerController::LeSetHostFeature(uint8_t bit_number, - uint8_t bit_value) { +ErrorCode LinkLayerController::LeSetHostFeature(uint8_t bit_number, uint8_t bit_value) { if (bit_number >= 64 || bit_value > 1) { return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -660,12 +633,9 @@ ErrorCode LinkLayerController::LeSetHostFeature(uint8_t bit_number, uint64_t bit_mask = UINT64_C(1) << bit_number; if (bit_mask == - static_cast( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_HOST_SUPPORT)) { + static_cast(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_HOST_SUPPORT)) { connected_isochronous_stream_host_support_ = bit_value != 0; - } else if (bit_mask == - static_cast( - LLFeaturesBits::CONNECTION_SUBRATING_HOST_SUPPORT)) { + } else if (bit_mask == static_cast(LLFeaturesBits::CONNECTION_SUBRATING_HOST_SUPPORT)) { connection_subrating_host_support_ = bit_value != 0; } // If Bit_Number specifies a feature bit that is not controlled by the Host, @@ -690,9 +660,8 @@ ErrorCode LinkLayerController::LeSetHostFeature(uint8_t bit_number, // HCI command LE_Add_Device_To_Resolving_List (Vol 4, Part E § 7.8.38). ErrorCode LinkLayerController::LeAddDeviceToResolvingList( - PeerAddressType peer_identity_address_type, Address peer_identity_address, - std::array peer_irk, - std::array local_irk) { + PeerAddressType peer_identity_address_type, Address peer_identity_address, + std::array peer_irk, std::array local_irk) { // This command shall not be used when address resolution is enabled in the // Controller and: // • Advertising (other than periodic advertising) is enabled, @@ -738,7 +707,7 @@ ErrorCode LinkLayerController::LeAddDeviceToResolvingList( // HCI command LE_Remove_Device_From_Resolving_List (Vol 4, Part E § 7.8.39). ErrorCode LinkLayerController::LeRemoveDeviceFromResolvingList( - PeerAddressType peer_identity_address_type, Address peer_identity_address) { + PeerAddressType peer_identity_address_type, Address peer_identity_address) { // This command shall not be used when address resolution is enabled in the // Controller and: // • Advertising (other than periodic advertising) is enabled, @@ -752,8 +721,7 @@ ErrorCode LinkLayerController::LeRemoveDeviceFromResolvingList( return ErrorCode::COMMAND_DISALLOWED; } - for (auto it = le_resolving_list_.begin(); it != le_resolving_list_.end(); - it++) { + for (auto it = le_resolving_list_.begin(); it != le_resolving_list_.end(); it++) { if (it->peer_identity_address_type == peer_identity_address_type && it->peer_identity_address == peer_identity_address) { le_resolving_list_.erase(it); @@ -789,8 +757,8 @@ ErrorCode LinkLayerController::LeClearResolvingList() { // HCI command LE_Read_Peer_Resolvable_Address (Vol 4, Part E § 7.8.42). ErrorCode LinkLayerController::LeReadPeerResolvableAddress( - PeerAddressType peer_identity_address_type, Address peer_identity_address, - Address* peer_resolvable_address) { + PeerAddressType peer_identity_address_type, Address peer_identity_address, + Address* peer_resolvable_address) { for (auto const& entry : le_resolving_list_) { if (entry.peer_identity_address_type == peer_identity_address_type && entry.peer_identity_address == peer_identity_address && @@ -813,8 +781,8 @@ ErrorCode LinkLayerController::LeReadPeerResolvableAddress( // HCI command LE_Read_Local_Resolvable_Address (Vol 4, Part E § 7.8.43). ErrorCode LinkLayerController::LeReadLocalResolvableAddress( - PeerAddressType peer_identity_address_type, Address peer_identity_address, - Address* local_resolvable_address) { + PeerAddressType peer_identity_address_type, Address peer_identity_address, + Address* local_resolvable_address) { for (auto const& entry : le_resolving_list_) { if (entry.peer_identity_address_type == peer_identity_address_type && entry.peer_identity_address == peer_identity_address && @@ -854,9 +822,9 @@ ErrorCode LinkLayerController::LeSetAddressResolutionEnable(bool enable) { } // HCI command LE_Set_Privacy_Mode (Vol 4, Part E § 7.8.77). -ErrorCode LinkLayerController::LeSetPrivacyMode( - PeerAddressType peer_identity_address_type, Address peer_identity_address, - bluetooth::hci::PrivacyMode privacy_mode) { +ErrorCode LinkLayerController::LeSetPrivacyMode(PeerAddressType peer_identity_address_type, + Address peer_identity_address, + bluetooth::hci::PrivacyMode privacy_mode) { // This command shall not be used when address resolution is enabled in the // Controller and: // • Advertising (other than periodic advertising) is enabled, @@ -911,7 +879,7 @@ ErrorCode LinkLayerController::LeClearFilterAcceptList() { // HCI command LE_Add_Device_To_Filter_Accept_List (Vol 4, Part E § 7.8.16). ErrorCode LinkLayerController::LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType address_type, Address address) { + FilterAcceptListAddressType address_type, Address address) { // This command shall not be used when: // • any advertising filter policy uses the Filter Accept List and // advertising is enabled, @@ -935,15 +903,14 @@ ErrorCode LinkLayerController::LeAddDeviceToFilterAcceptList( return ErrorCode::MEMORY_CAPACITY_EXCEEDED; } - le_filter_accept_list_.emplace_back( - FilterAcceptListEntry{address_type, address}); + le_filter_accept_list_.emplace_back(FilterAcceptListEntry{address_type, address}); return ErrorCode::SUCCESS; } // HCI command LE_Remove_Device_From_Filter_Accept_List (Vol 4, Part E // § 7.8.17). ErrorCode LinkLayerController::LeRemoveDeviceFromFilterAcceptList( - FilterAcceptListAddressType address_type, Address address) { + FilterAcceptListAddressType address_type, Address address) { // This command shall not be used when: // • any advertising filter policy uses the Filter Accept List and // advertising is enabled, @@ -959,8 +926,7 @@ ErrorCode LinkLayerController::LeRemoveDeviceFromFilterAcceptList( return ErrorCode::COMMAND_DISALLOWED; } - for (auto it = le_filter_accept_list_.begin(); - it != le_filter_accept_list_.end(); it++) { + for (auto it = le_filter_accept_list_.begin(); it != le_filter_accept_list_.end(); it++) { // Address shall be ignored when Address_Type is set to 0xFF. if (it->address_type == address_type && (address_type == FilterAcceptListAddressType::ANONYMOUS_ADVERTISERS || @@ -982,22 +948,20 @@ ErrorCode LinkLayerController::LeRemoveDeviceFromFilterAcceptList( // HCI LE Add Device To Periodic Advertiser List command (Vol 4, Part E // § 7.8.70). ErrorCode LinkLayerController::LeAddDeviceToPeriodicAdvertiserList( - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint8_t advertising_sid) { + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint8_t advertising_sid) { // If the Host issues this command when an HCI_LE_Periodic_Advertising_- // Create_Sync command is pending, the Controller shall return the error code // Command Disallowed (0x0C). if (synchronizing_.has_value()) { - INFO(id_, - "LE Periodic Advertising Create Sync command is currently pending"); + INFO(id_, "LE Periodic Advertising Create Sync command is currently pending"); return ErrorCode::COMMAND_DISALLOWED; } // When a Controller cannot add an entry to the Periodic Advertiser list // because the list is full, the Controller shall return the error code Memory // Capacity Exceeded (0x07). - if (le_periodic_advertiser_list_.size() >= - properties_.le_periodic_advertiser_list_size) { + if (le_periodic_advertiser_list_.size() >= properties_.le_periodic_advertiser_list_size) { INFO(id_, "periodic advertiser list is full"); return ErrorCode::MEMORY_CAPACITY_EXCEEDED; } @@ -1014,29 +978,27 @@ ErrorCode LinkLayerController::LeAddDeviceToPeriodicAdvertiserList( } le_periodic_advertiser_list_.emplace_back(PeriodicAdvertiserListEntry{ - advertiser_address_type, advertiser_address, advertising_sid}); + advertiser_address_type, advertiser_address, advertising_sid}); return ErrorCode::SUCCESS; } // HCI LE Remove Device From Periodic Advertiser List command // (Vol 4, Part E § 7.8.71). ErrorCode LinkLayerController::LeRemoveDeviceFromPeriodicAdvertiserList( - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint8_t advertising_sid) { + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint8_t advertising_sid) { // If this command is used when an HCI_LE_Periodic_Advertising_Create_Sync // command is pending, the Controller shall return the error code Command // Disallowed (0x0C). if (synchronizing_.has_value()) { - INFO(id_, - "LE Periodic Advertising Create Sync command is currently pending"); + INFO(id_, "LE Periodic Advertising Create Sync command is currently pending"); return ErrorCode::COMMAND_DISALLOWED; } - for (auto it = le_periodic_advertiser_list_.begin(); - it != le_periodic_advertiser_list_.end(); it++) { + for (auto it = le_periodic_advertiser_list_.begin(); it != le_periodic_advertiser_list_.end(); + it++) { if (it->advertiser_address_type == advertiser_address_type && - it->advertiser_address == advertiser_address && - it->advertising_sid == advertising_sid) { + it->advertiser_address == advertiser_address && it->advertising_sid == advertising_sid) { le_periodic_advertiser_list_.erase(it); return ErrorCode::SUCCESS; } @@ -1055,8 +1017,7 @@ ErrorCode LinkLayerController::LeClearPeriodicAdvertiserList() { // command is pending, the Controller shall return the error code Command // Disallowed (0x0C). if (synchronizing_.has_value()) { - INFO(id_, - "LE Periodic Advertising Create Sync command is currently pending"); + INFO(id_, "LE Periodic Advertising Create Sync command is currently pending"); return ErrorCode::COMMAND_DISALLOWED; } @@ -1070,16 +1031,14 @@ ErrorCode LinkLayerController::LeClearPeriodicAdvertiserList() { // HCI LE Periodic Advertising Create Sync command (Vol 4, Part E § 7.8.67). ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSync( - bluetooth::hci::PeriodicAdvertisingOptions options, uint8_t advertising_sid, - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint16_t /*skip*/, uint16_t sync_timeout, - uint8_t sync_cte_type) { + bluetooth::hci::PeriodicAdvertisingOptions options, uint8_t advertising_sid, + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint16_t /*skip*/, uint16_t sync_timeout, uint8_t sync_cte_type) { // If the Host issues this command when another HCI_LE_Periodic_Advertising_- // Create_Sync command is pending, the Controller shall return the error code // Command Disallowed (0x0C). if (synchronizing_.has_value()) { - INFO(id_, - "LE Periodic Advertising Create Sync command is currently pending"); + INFO(id_, "LE Periodic Advertising Create Sync command is currently pending"); return ErrorCode::COMMAND_DISALLOWED; } @@ -1087,8 +1046,7 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSync( // to 1, the Controller shall return the error code Command Disallowed (0x0C). uint8_t sync_cte_type_mask = 0x1f; if ((sync_cte_type & sync_cte_type_mask) == sync_cte_type_mask) { - INFO(id_, - "Sync_CTE_Type is configured to ignore all types of advertisement"); + INFO(id_, "Sync_CTE_Type is configured to ignore all types of advertisement"); return ErrorCode::COMMAND_DISALLOWED; } @@ -1099,17 +1057,15 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSync( // Connection Already Exists (0x0B). bool has_synchronized_train = false; for (auto& [_, sync] : synchronized_) { - has_synchronized_train |= - sync.advertiser_address_type == advertiser_address_type && - sync.advertiser_address == advertiser_address && - sync.advertising_sid == advertising_sid; + has_synchronized_train |= sync.advertiser_address_type == advertiser_address_type && + sync.advertiser_address == advertiser_address && + sync.advertising_sid == advertising_sid; } if (!options.use_periodic_advertiser_list_ && has_synchronized_train) { INFO(id_, "the controller is already synchronized on the periodic advertising" " train from {}[{}] - SID=0x{:x}", - advertiser_address, - bluetooth::hci::AdvertiserAddressTypeText(advertiser_address_type), + advertiser_address, bluetooth::hci::AdvertiserAddressTypeText(advertiser_address_type), advertising_sid); return ErrorCode::CONNECTION_ALREADY_EXISTS; } @@ -1124,8 +1080,7 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSync( // Controller shall return an error which should use the error code // Unsupported Feature or Parameter Value (0x11). if (!options.disable_reporting_ && options.enable_duplicate_filtering_ && - !properties_.SupportsLLFeature( - LLFeaturesBits::PERIODIC_ADVERTISING_ADI_SUPPORT)) { + !properties_.SupportsLLFeature(LLFeaturesBits::PERIODIC_ADVERTISING_ADI_SUPPORT)) { INFO(id_, "reporting and duplicate filtering are enabled in the options," " but the controller does not support the Periodic Advertising ADI" @@ -1139,8 +1094,7 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSync( // / Synchronization Timeout (0x3E). if (options.disable_reporting_ && !properties_.SupportsCommand( - bluetooth::hci::OpCodeIndex:: - LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE)) { + bluetooth::hci::OpCodeIndex::LE_SET_PERIODIC_ADVERTISING_RECEIVE_ENABLE)) { INFO(id_, "reporting is disabled in the options, but the controller does not" " support the HCI_LE_Set_Periodic_Advertising_Receive_Enable command"); @@ -1148,11 +1102,11 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSync( } synchronizing_ = Synchronizing{ - .options = options, - .advertiser_address_type = advertiser_address_type, - .advertiser_address = advertiser_address, - .advertising_sid = advertising_sid, - .sync_timeout = 10ms * sync_timeout, + .options = options, + .advertiser_address_type = advertiser_address_type, + .advertiser_address = advertiser_address, + .advertising_sid = advertising_sid, + .sync_timeout = 10ms * sync_timeout, }; return ErrorCode::SUCCESS; } @@ -1172,13 +1126,11 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSyncCancel() { // successful, the Controller sends an HCI_LE_Periodic_Advertising_Sync_- // Established event to the Host with the error code Operation Cancelled // by Host (0x44). - if (IsLeEventUnmasked(SubeventCode::PERIODIC_ADVERTISING_SYNC_ESTABLISHED)) { + if (IsLeEventUnmasked(SubeventCode::LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_V1)) { ScheduleTask(0ms, [this] { - send_event_( - bluetooth::hci::LePeriodicAdvertisingSyncEstablishedBuilder::Create( - ErrorCode::OPERATION_CANCELLED_BY_HOST, 0, 0, - AddressType::PUBLIC_DEVICE_ADDRESS, Address::kEmpty, - bluetooth::hci::SecondaryPhyType::NO_PACKETS, 0, + send_event_(bluetooth::hci::LePeriodicAdvertisingSyncEstablishedV1Builder::Create( + ErrorCode::OPERATION_CANCELLED_BY_HOST, 0, 0, AddressType::PUBLIC_DEVICE_ADDRESS, + Address::kEmpty, bluetooth::hci::SecondaryPhyType::NO_PACKETS, 0, bluetooth::hci::ClockAccuracy::PPM_500)); }); } @@ -1189,8 +1141,7 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSyncCancel() { // HCI LE Periodic Advertising Terminate Sync command (Vol 4, Part E // § 7.8.69). -ErrorCode LinkLayerController::LePeriodicAdvertisingTerminateSync( - uint16_t sync_handle) { +ErrorCode LinkLayerController::LePeriodicAdvertisingTerminateSync(uint16_t sync_handle) { // If the periodic advertising train corresponding to the Sync_Handle // parameter does not exist, then the Controller shall return the error // code Unknown Advertising Identifier (0x42). @@ -1209,9 +1160,9 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingTerminateSync( // HCI command LE_Set_Scan_Parameters (Vol 4, Part E § 7.8.10). ErrorCode LinkLayerController::LeSetScanParameters( - bluetooth::hci::LeScanType scan_type, uint16_t scan_interval, - uint16_t scan_window, bluetooth::hci::OwnAddressType own_address_type, - bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy) { + bluetooth::hci::LeScanType scan_type, uint16_t scan_interval, uint16_t scan_window, + bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy) { // Legacy advertising commands are disallowed when extended advertising // commands were used since the last reset. if (!SelectLegacyAdvertising()) { @@ -1231,8 +1182,7 @@ ErrorCode LinkLayerController::LeSetScanParameters( // Note: no explicit error code stated for invalid interval and window // values but assuming Unsupported Feature or Parameter Value (0x11) // error code based on similar advertising command. - if (scan_interval < 0x4 || scan_interval > 0x4000 || scan_window < 0x4 || - scan_window > 0x4000) { + if (scan_interval < 0x4 || scan_interval > 0x4000 || scan_window < 0x4 || scan_window > 0x4000) { INFO(id_, "le_scan_interval (0x{:04x}) and/or" " le_scan_window (0x{:04x}) are outside the range" @@ -1244,9 +1194,8 @@ ErrorCode LinkLayerController::LeSetScanParameters( // The LE_Scan_Window parameter shall always be set to a value smaller // or equal to the value set for the LE_Scan_Interval parameter. if (scan_window > scan_interval) { - INFO(id_, - "le_scan_window (0x{:04x}) is larger than le_scan_interval (0x{:04x})", - scan_window, scan_interval); + INFO(id_, "le_scan_window (0x{:04x}) is larger than le_scan_interval (0x{:04x})", scan_window, + scan_interval); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -1261,8 +1210,7 @@ ErrorCode LinkLayerController::LeSetScanParameters( } // HCI command LE_Set_Scan_Enable (Vol 4, Part E § 7.8.11). -ErrorCode LinkLayerController::LeSetScanEnable(bool enable, - bool filter_duplicates) { +ErrorCode LinkLayerController::LeSetScanEnable(bool enable, bool filter_duplicates) { // Legacy advertising commands are disallowed when extended advertising // commands were used since the last reset. if (!SelectLegacyAdvertising()) { @@ -1288,10 +1236,8 @@ ErrorCode LinkLayerController::LeSetScanEnable(bool enable, // has not been initialized using the HCI_LE_Set_Random_Address command, // the Controller shall return the error code // Invalid HCI Command Parameters (0x12). - if ((scanner_.own_address_type == - bluetooth::hci::OwnAddressType::RANDOM_DEVICE_ADDRESS || - scanner_.own_address_type == - bluetooth::hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS) && + if ((scanner_.own_address_type == bluetooth::hci::OwnAddressType::RANDOM_DEVICE_ADDRESS || + scanner_.own_address_type == bluetooth::hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS) && random_address_ == Address::kEmpty) { INFO(id_, "own_address_type is Random_Device_Address or" @@ -1306,9 +1252,8 @@ ErrorCode LinkLayerController::LeSetScanEnable(bool enable, scanner_.periodical_timeout = {}; scanner_.pending_scan_request = {}; scanner_.pending_scan_request_timeout = {}; - scanner_.filter_duplicates = filter_duplicates - ? bluetooth::hci::FilterDuplicates::ENABLED - : bluetooth::hci::FilterDuplicates::DISABLED; + scanner_.filter_duplicates = filter_duplicates ? bluetooth::hci::FilterDuplicates::ENABLED + : bluetooth::hci::FilterDuplicates::DISABLED; return ErrorCode::SUCCESS; } @@ -1318,11 +1263,9 @@ ErrorCode LinkLayerController::LeSetScanEnable(bool enable, // HCI command LE_Set_Extended_Scan_Parameters (Vol 4, Part E § 7.8.64). ErrorCode LinkLayerController::LeSetExtendedScanParameters( - bluetooth::hci::OwnAddressType own_address_type, - bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy, - uint8_t scanning_phys, - std::vector - scanning_phy_parameters) { + bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy, uint8_t scanning_phys, + std::vector scanning_phy_parameters) { uint8_t supported_phys = properties_.LeSupportedPhys(); // Extended advertising commands are disallowed when legacy advertising @@ -1353,8 +1296,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanParameters( } // TODO(c++20) std::popcount - if (__builtin_popcount(scanning_phys) != - int(scanning_phy_parameters.size())) { + if (__builtin_popcount(scanning_phys) != int(scanning_phy_parameters.size())) { INFO(id_, "scanning_phy_parameters ({})" " does not match scanning_phys ({:02x})", @@ -1400,20 +1342,20 @@ ErrorCode LinkLayerController::LeSetExtendedScanParameters( if (scanning_phys & 0x1) { scanner_.le_1m_phy = Scanner::PhyParameters{ - .enabled = true, - .scan_type = scanning_phy_parameters[offset].le_scan_type_, - .scan_interval = scanning_phy_parameters[offset].le_scan_interval_, - .scan_window = scanning_phy_parameters[offset].le_scan_window_, + .enabled = true, + .scan_type = scanning_phy_parameters[offset].le_scan_type_, + .scan_interval = scanning_phy_parameters[offset].le_scan_interval_, + .scan_window = scanning_phy_parameters[offset].le_scan_window_, }; offset++; } if (scanning_phys & 0x4) { scanner_.le_coded_phy = Scanner::PhyParameters{ - .enabled = true, - .scan_type = scanning_phy_parameters[offset].le_scan_type_, - .scan_interval = scanning_phy_parameters[offset].le_scan_interval_, - .scan_window = scanning_phy_parameters[offset].le_scan_window_, + .enabled = true, + .scan_type = scanning_phy_parameters[offset].le_scan_type_, + .scan_interval = scanning_phy_parameters[offset].le_scan_interval_, + .scan_window = scanning_phy_parameters[offset].le_scan_window_, }; offset++; } @@ -1423,8 +1365,8 @@ ErrorCode LinkLayerController::LeSetExtendedScanParameters( // HCI command LE_Set_Extended_Scan_Enable (Vol 4, Part E § 7.8.65). ErrorCode LinkLayerController::LeSetExtendedScanEnable( - bool enable, bluetooth::hci::FilterDuplicates filter_duplicates, - uint16_t duration, uint16_t period) { + bool enable, bluetooth::hci::FilterDuplicates filter_duplicates, uint16_t duration, + uint16_t period) { // Extended advertising commands are disallowed when legacy advertising // commands were used since the last reset. if (!SelectExtendedAdvertising()) { @@ -1450,8 +1392,7 @@ ErrorCode LinkLayerController::LeSetExtendedScanEnable( // If Filter_Duplicates is set to 0x02 and either Period or Duration to zero, // the Controller shall return the error code // Invalid HCI Command Parameters (0x12). - if (filter_duplicates == - bluetooth::hci::FilterDuplicates::RESET_EACH_PERIOD && + if (filter_duplicates == bluetooth::hci::FilterDuplicates::RESET_EACH_PERIOD && (period == 0 || duration == 0)) { INFO(id_, "filter_duplicates is Reset_Each_Period but either" @@ -1478,10 +1419,8 @@ ErrorCode LinkLayerController::LeSetExtendedScanEnable( // has not been initialized using the HCI_LE_Set_Random_Address command, // the Controller shall return the error code // Invalid HCI Command Parameters (0x12). - if ((scanner_.own_address_type == - bluetooth::hci::OwnAddressType::RANDOM_DEVICE_ADDRESS || - scanner_.own_address_type == - bluetooth::hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS) && + if ((scanner_.own_address_type == bluetooth::hci::OwnAddressType::RANDOM_DEVICE_ADDRESS || + scanner_.own_address_type == bluetooth::hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS) && random_address_ == Address::kEmpty) { INFO(id_, "own_address_type is Random_Device_Address or" @@ -1520,13 +1459,11 @@ ErrorCode LinkLayerController::LeSetExtendedScanEnable( // HCI LE Create Connection command (Vol 4, Part E § 7.8.12). ErrorCode LinkLayerController::LeCreateConnection( - uint16_t scan_interval, uint16_t scan_window, - bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, - AddressWithType peer_address, - bluetooth::hci::OwnAddressType own_address_type, - uint16_t connection_interval_min, uint16_t connection_interval_max, - uint16_t max_latency, uint16_t supervision_timeout, uint16_t min_ce_length, - uint16_t max_ce_length) { + uint16_t scan_interval, uint16_t scan_window, + bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, AddressWithType peer_address, + bluetooth::hci::OwnAddressType own_address_type, uint16_t connection_interval_min, + uint16_t connection_interval_max, uint16_t max_latency, uint16_t supervision_timeout, + uint16_t min_ce_length, uint16_t max_ce_length) { // Legacy advertising commands are disallowed when extended advertising // commands were used since the last reset. if (!SelectLegacyAdvertising()) { @@ -1547,8 +1484,7 @@ ErrorCode LinkLayerController::LeCreateConnection( // Note: no explicit error code stated for invalid interval and window // values but assuming Unsupported Feature or Parameter Value (0x11) // error code based on similar advertising command. - if (scan_interval < 0x4 || scan_interval > 0x4000 || scan_window < 0x4 || - scan_window > 0x4000) { + if (scan_interval < 0x4 || scan_interval > 0x4000 || scan_window < 0x4 || scan_window > 0x4000) { INFO(id_, "scan_interval (0x{:04x}) and/or " "scan_window (0x{:04x}) are outside the range" @@ -1560,8 +1496,8 @@ ErrorCode LinkLayerController::LeCreateConnection( // The LE_Scan_Window parameter shall be set to a value smaller or equal to // the value set for the LE_Scan_Interval parameter. if (scan_interval < scan_window) { - INFO(id_, "scan_window (0x{:04x}) is larger than scan_interval (0x{:04x})", - scan_window, scan_interval); + INFO(id_, "scan_window (0x{:04x}) is larger than scan_interval (0x{:04x})", scan_window, + scan_interval); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -1613,14 +1549,13 @@ ErrorCode LinkLayerController::LeCreateConnection( // The Supervision_Timeout in milliseconds shall be larger than // (1 + Max_Latency) * Connection_Interval_Max * 2, where // Connection_Interval_Max is given in milliseconds. - milliseconds min_supervision_timeout = duration_cast( - (1 + max_latency) * slots(2 * connection_interval_max) * 2); + milliseconds min_supervision_timeout = + duration_cast((1 + max_latency) * slots(2 * connection_interval_max) * 2); if (supervision_timeout * 10ms < min_supervision_timeout) { INFO(id_, "supervision_timeout ({} ms) is smaller that the minimal supervision " "timeout allowed by connection_interval_max and max_latency ({} ms)", - supervision_timeout * 10, - static_cast(min_supervision_timeout / 1ms)); + supervision_timeout * 10, static_cast(min_supervision_timeout / 1ms)); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -1690,19 +1625,17 @@ ErrorCode LinkLayerController::LeCreateConnectionCancel() { // Connection Complete or an HCI_LE_Enhanced_Connection_Complete event // shall be generated. In either case, the event shall be sent with the error // code Unknown Connection Identifier (0x02). - if (IsLeEventUnmasked(SubeventCode::ENHANCED_CONNECTION_COMPLETE)) { + if (IsLeEventUnmasked(SubeventCode::LE_ENHANCED_CONNECTION_COMPLETE_V1)) { ScheduleTask(0ms, [this] { - send_event_(bluetooth::hci::LeEnhancedConnectionCompleteBuilder::Create( - ErrorCode::UNKNOWN_CONNECTION, 0, Role::CENTRAL, - AddressType::PUBLIC_DEVICE_ADDRESS, Address(), Address(), Address(), - 0, 0, 0, bluetooth::hci::ClockAccuracy::PPM_500)); + send_event_(bluetooth::hci::LeEnhancedConnectionCompleteV1Builder::Create( + ErrorCode::UNKNOWN_CONNECTION, 0, Role::CENTRAL, AddressType::PUBLIC_DEVICE_ADDRESS, + Address(), Address(), Address(), 0, 0, 0, bluetooth::hci::ClockAccuracy::PPM_500)); }); - } else if (IsLeEventUnmasked(SubeventCode::CONNECTION_COMPLETE)) { + } else if (IsLeEventUnmasked(SubeventCode::LE_CONNECTION_COMPLETE)) { ScheduleTask(0ms, [this] { send_event_(bluetooth::hci::LeConnectionCompleteBuilder::Create( - ErrorCode::UNKNOWN_CONNECTION, 0, Role::CENTRAL, - AddressType::PUBLIC_DEVICE_ADDRESS, Address(), 0, 0, 0, - bluetooth::hci::ClockAccuracy::PPM_500)); + ErrorCode::UNKNOWN_CONNECTION, 0, Role::CENTRAL, AddressType::PUBLIC_DEVICE_ADDRESS, + Address(), 0, 0, 0, bluetooth::hci::ClockAccuracy::PPM_500)); }); } @@ -1716,11 +1649,10 @@ ErrorCode LinkLayerController::LeCreateConnectionCancel() { // HCI LE Extended Create Connection command (Vol 4, Part E § 7.8.66). ErrorCode LinkLayerController::LeExtendedCreateConnection( - bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, - bluetooth::hci::OwnAddressType own_address_type, - AddressWithType peer_address, uint8_t initiating_phys, - std::vector - initiating_phy_parameters) { + bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, + bluetooth::hci::OwnAddressType own_address_type, AddressWithType peer_address, + uint8_t initiating_phys, + std::vector initiating_phy_parameters) { // Extended advertising commands are disallowed when legacy advertising // commands were used since the last reset. if (!SelectExtendedAdvertising()) { @@ -1750,8 +1682,7 @@ ErrorCode LinkLayerController::LeExtendedCreateConnection( } // TODO(c++20) std::popcount - if (__builtin_popcount(initiating_phys) != - int(initiating_phy_parameters.size())) { + if (__builtin_popcount(initiating_phys) != int(initiating_phy_parameters.size())) { INFO(id_, "initiating_phy_parameters ({})" " does not match initiating_phys ({:02x})", @@ -1785,8 +1716,7 @@ ErrorCode LinkLayerController::LeExtendedCreateConnection( // The LE_Scan_Window parameter shall be set to a value smaller or equal to // the value set for the LE_Scan_Interval parameter. if (parameter.scan_interval_ < parameter.scan_window_) { - INFO(id_, - "scan_window (0x{:04x}) is larger than scan_interval (0x{:04x})", + INFO(id_, "scan_window (0x{:04x}) is larger than scan_interval (0x{:04x})", parameter.scan_window_, parameter.scan_interval_); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -1794,28 +1724,23 @@ ErrorCode LinkLayerController::LeExtendedCreateConnection( // Note: no explicit error code stated for invalid connection interval // values but assuming Unsupported Feature or Parameter Value (0x11) // error code based on similar advertising command. - if (parameter.connection_interval_min_ < 0x6 || - parameter.connection_interval_min_ > 0x0c80 || - parameter.connection_interval_max_ < 0x6 || - parameter.connection_interval_max_ > 0x0c80) { + if (parameter.connection_interval_min_ < 0x6 || parameter.connection_interval_min_ > 0x0c80 || + parameter.connection_interval_max_ < 0x6 || parameter.connection_interval_max_ > 0x0c80) { INFO(id_, "connection_interval_min (0x{:04x}) and/or " "connection_interval_max (0x{:04x}) are outside the range" " of supported values (0x6 - 0x0c80)", - parameter.connection_interval_min_, - parameter.connection_interval_max_); + parameter.connection_interval_min_, parameter.connection_interval_max_); return ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE; } // The Connection_Interval_Min parameter shall not be greater than the // Connection_Interval_Max parameter. - if (parameter.connection_interval_max_ < - parameter.connection_interval_min_) { + if (parameter.connection_interval_max_ < parameter.connection_interval_min_) { INFO(id_, "connection_interval_min (0x{:04x}) is larger than" " connection_interval_max (0x{:04x})", - parameter.connection_interval_min_, - parameter.connection_interval_max_); + parameter.connection_interval_min_, parameter.connection_interval_max_); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -1833,8 +1758,7 @@ ErrorCode LinkLayerController::LeExtendedCreateConnection( // Note: no explicit error code stated for invalid supervision timeout // values but assuming Unsupported Feature or Parameter Value (0x11) // error code based on similar advertising command. - if (parameter.supervision_timeout_ < 0xa || - parameter.supervision_timeout_ > 0x0c80) { + if (parameter.supervision_timeout_ < 0xa || parameter.supervision_timeout_ > 0x0c80) { INFO(id_, "supervision_timeout (0x{:04x}) is outside the range" " of supported values (0xa - 0x0c80)", @@ -1846,15 +1770,13 @@ ErrorCode LinkLayerController::LeExtendedCreateConnection( // (1 + Max_Latency) * Connection_Interval_Max * 2, where // Connection_Interval_Max is given in milliseconds. milliseconds min_supervision_timeout = duration_cast( - (1 + parameter.max_latency_) * - slots(2 * parameter.connection_interval_max_) * 2); + (1 + parameter.max_latency_) * slots(2 * parameter.connection_interval_max_) * 2); if (parameter.supervision_timeout_ * 10ms < min_supervision_timeout) { - INFO( - id_, - "supervision_timeout ({} ms) is smaller that the minimal supervision " - "timeout allowed by connection_interval_max and max_latency ({} ms)", - parameter.supervision_timeout_ * 10, - static_cast(min_supervision_timeout / 1ms)); + INFO(id_, + "supervision_timeout ({} ms) is smaller that the minimal supervision " + "timeout allowed by connection_interval_max and max_latency ({} ms)", + parameter.supervision_timeout_ * 10, + static_cast(min_supervision_timeout / 1ms)); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } } @@ -1904,54 +1826,45 @@ ErrorCode LinkLayerController::LeExtendedCreateConnection( if (initiating_phys & 0x1) { initiator_.le_1m_phy = Initiator::PhyParameters{ - .enabled = true, - .scan_interval = initiating_phy_parameters[offset].scan_interval_, - .scan_window = initiating_phy_parameters[offset].scan_window_, - .connection_interval_min = - initiating_phy_parameters[offset].connection_interval_min_, - .connection_interval_max = - initiating_phy_parameters[offset].connection_interval_max_, - .max_latency = initiating_phy_parameters[offset].max_latency_, - .supervision_timeout = - initiating_phy_parameters[offset].supervision_timeout_, - .min_ce_length = initiating_phy_parameters[offset].min_ce_length_, - .max_ce_length = initiating_phy_parameters[offset].max_ce_length_, + .enabled = true, + .scan_interval = initiating_phy_parameters[offset].scan_interval_, + .scan_window = initiating_phy_parameters[offset].scan_window_, + .connection_interval_min = initiating_phy_parameters[offset].connection_interval_min_, + .connection_interval_max = initiating_phy_parameters[offset].connection_interval_max_, + .max_latency = initiating_phy_parameters[offset].max_latency_, + .supervision_timeout = initiating_phy_parameters[offset].supervision_timeout_, + .min_ce_length = initiating_phy_parameters[offset].min_ce_length_, + .max_ce_length = initiating_phy_parameters[offset].max_ce_length_, }; offset++; } if (initiating_phys & 0x2) { initiator_.le_2m_phy = Initiator::PhyParameters{ - .enabled = true, - .scan_interval = initiating_phy_parameters[offset].scan_interval_, - .scan_window = initiating_phy_parameters[offset].scan_window_, - .connection_interval_min = - initiating_phy_parameters[offset].connection_interval_min_, - .connection_interval_max = - initiating_phy_parameters[offset].connection_interval_max_, - .max_latency = initiating_phy_parameters[offset].max_latency_, - .supervision_timeout = - initiating_phy_parameters[offset].supervision_timeout_, - .min_ce_length = initiating_phy_parameters[offset].min_ce_length_, - .max_ce_length = initiating_phy_parameters[offset].max_ce_length_, + .enabled = true, + .scan_interval = initiating_phy_parameters[offset].scan_interval_, + .scan_window = initiating_phy_parameters[offset].scan_window_, + .connection_interval_min = initiating_phy_parameters[offset].connection_interval_min_, + .connection_interval_max = initiating_phy_parameters[offset].connection_interval_max_, + .max_latency = initiating_phy_parameters[offset].max_latency_, + .supervision_timeout = initiating_phy_parameters[offset].supervision_timeout_, + .min_ce_length = initiating_phy_parameters[offset].min_ce_length_, + .max_ce_length = initiating_phy_parameters[offset].max_ce_length_, }; offset++; } if (initiating_phys & 0x4) { initiator_.le_coded_phy = Initiator::PhyParameters{ - .enabled = true, - .scan_interval = initiating_phy_parameters[offset].scan_interval_, - .scan_window = initiating_phy_parameters[offset].scan_window_, - .connection_interval_min = - initiating_phy_parameters[offset].connection_interval_min_, - .connection_interval_max = - initiating_phy_parameters[offset].connection_interval_max_, - .max_latency = initiating_phy_parameters[offset].max_latency_, - .supervision_timeout = - initiating_phy_parameters[offset].supervision_timeout_, - .min_ce_length = initiating_phy_parameters[offset].min_ce_length_, - .max_ce_length = initiating_phy_parameters[offset].max_ce_length_, + .enabled = true, + .scan_interval = initiating_phy_parameters[offset].scan_interval_, + .scan_window = initiating_phy_parameters[offset].scan_window_, + .connection_interval_min = initiating_phy_parameters[offset].connection_interval_min_, + .connection_interval_max = initiating_phy_parameters[offset].connection_interval_max_, + .max_latency = initiating_phy_parameters[offset].max_latency_, + .supervision_timeout = initiating_phy_parameters[offset].supervision_timeout_, + .min_ce_length = initiating_phy_parameters[offset].min_ce_length_, + .max_ce_length = initiating_phy_parameters[offset].max_ce_length_, }; offset++; } @@ -1996,8 +1909,7 @@ void LinkLayerController::SetSecureConnectionsSupport(bool enable) { } } -void LinkLayerController::SetLocalName( - std::array const& local_name) { +void LinkLayerController::SetLocalName(std::array const& local_name) { std::copy(local_name.begin(), local_name.end(), local_name_.begin()); } @@ -2008,12 +1920,12 @@ void LinkLayerController::SetLocalName(std::vector const& local_name) { } void LinkLayerController::SetExtendedInquiryResponse( - std::array const& extended_inquiry_response) { + std::array const& extended_inquiry_response) { extended_inquiry_response_ = extended_inquiry_response; } void LinkLayerController::SetExtendedInquiryResponse( - std::vector const& extended_inquiry_response) { + std::vector const& extended_inquiry_response) { ASSERT(extended_inquiry_response.size() <= extended_inquiry_response_.size()); extended_inquiry_response_.fill(0); std::copy(extended_inquiry_response.begin(), extended_inquiry_response.end(), @@ -2021,8 +1933,7 @@ void LinkLayerController::SetExtendedInquiryResponse( } LinkLayerController::LinkLayerController(const Address& address, - const ControllerProperties& properties, - uint32_t id) + const ControllerProperties& properties, uint32_t id) : id_(id), address_(address), properties_(properties), @@ -2030,92 +1941,87 @@ LinkLayerController::LinkLayerController(const Address& address, ll_(nullptr, link_layer_destroy) { if (properties_.quirks.has_default_random_address) { WARNING(id_, "Configuring a default random address for this controller"); - random_address_ = Address { 0xba, 0xdb, 0xad, 0xba, 0xdb, 0xad }; + random_address_ = Address{0xba, 0xdb, 0xad, 0xba, 0xdb, 0xad}; } controller_ops_ = { - .user_pointer = this, - .get_handle = - [](void* user, const uint8_t(*address)[6]) { - auto controller = static_cast(user); - - return controller->connections_.GetHandleOnlyAddress( - Address(*address)); - }, - - .get_address = - [](void* user, uint16_t handle, uint8_t(*result)[6]) { - auto controller = static_cast(user); - - auto address_opt = controller->connections_.GetAddressSafe(handle); - Address address = address_opt.has_value() - ? address_opt.value().GetAddress() - : Address::kEmpty; - std::copy(address.data(), address.data() + 6, - reinterpret_cast(result)); - }, - - .get_extended_features = - [](void* user, uint8_t features_page) { - auto controller = static_cast(user); - return controller->GetLmpFeatures(features_page); - }, - - .get_le_features = - [](void* user) { - auto controller = static_cast(user); - return controller->GetLeSupportedFeatures(); - }, - - .get_le_event_mask = - [](void* user) { - auto controller = static_cast(user); - return controller->le_event_mask_; - }, - - .send_hci_event = - [](void* user, const uint8_t* data, uintptr_t len) { - auto controller = static_cast(user); - - auto event_code = static_cast(data[0]); - controller->send_event_(bluetooth::hci::EventBuilder::Create( - event_code, std::vector(data + 2, data + len))); - }, - - .send_lmp_packet = - [](void* user, const uint8_t(*to)[6], const uint8_t* data, - uintptr_t len) { - auto controller = static_cast(user); - - Address source = controller->GetAddress(); - Address dest(*to); - - controller->SendLinkLayerPacket(model::packets::LmpBuilder::Create( - source, dest, std::vector(data, data + len))); - }, - - .send_llcp_packet = - [](void* user, uint16_t acl_connection_handle, const uint8_t* data, - uintptr_t len) { - auto controller = static_cast(user); - - if (!controller->connections_.HasHandle(acl_connection_handle)) { - ERROR( - "Dropping LLCP packet sent for unknown connection handle " - "0x{:x}", - acl_connection_handle); - return; - } - - AclConnection const& connection = - controller->connections_.GetAclConnection( - acl_connection_handle); - Address source = connection.GetOwnAddress().GetAddress(); - Address destination = connection.GetAddress().GetAddress(); - - controller->SendLinkLayerPacket(model::packets::LlcpBuilder::Create( - source, destination, std::vector(data, data + len))); - }}; + .user_pointer = this, + .get_handle = + [](void* user, const uint8_t(*address)[6]) { + auto controller = static_cast(user); + + return controller->connections_.GetHandleOnlyAddress(Address(*address)); + }, + + .get_address = + [](void* user, uint16_t handle, uint8_t(*result)[6]) { + auto controller = static_cast(user); + + auto address_opt = controller->connections_.GetAddressSafe(handle); + Address address = address_opt.has_value() ? address_opt.value().GetAddress() + : Address::kEmpty; + std::copy(address.data(), address.data() + 6, + reinterpret_cast(result)); + }, + + .get_extended_features = + [](void* user, uint8_t features_page) { + auto controller = static_cast(user); + return controller->GetLmpFeatures(features_page); + }, + + .get_le_features = + [](void* user) { + auto controller = static_cast(user); + return controller->GetLeSupportedFeatures(); + }, + + .get_le_event_mask = + [](void* user) { + auto controller = static_cast(user); + return controller->le_event_mask_; + }, + + .send_hci_event = + [](void* user, const uint8_t* data, uintptr_t len) { + auto controller = static_cast(user); + + auto event_code = static_cast(data[0]); + controller->send_event_(bluetooth::hci::EventBuilder::Create( + event_code, std::vector(data + 2, data + len))); + }, + + .send_lmp_packet = + [](void* user, const uint8_t(*to)[6], const uint8_t* data, uintptr_t len) { + auto controller = static_cast(user); + + Address source = controller->GetAddress(); + Address dest(*to); + + controller->SendLinkLayerPacket(model::packets::LmpBuilder::Create( + source, dest, std::vector(data, data + len))); + }, + + .send_llcp_packet = + [](void* user, uint16_t acl_connection_handle, const uint8_t* data, + uintptr_t len) { + auto controller = static_cast(user); + + if (!controller->connections_.HasHandle(acl_connection_handle)) { + ERROR("Dropping LLCP packet sent for unknown connection handle " + "0x{:x}", + acl_connection_handle); + return; + } + + AclConnection const& connection = + controller->connections_.GetAclConnection(acl_connection_handle); + Address source = connection.GetOwnAddress().GetAddress(); + Address destination = connection.GetAddress().GetAddress(); + + controller->SendLinkLayerPacket(model::packets::LlcpBuilder::Create( + source, destination, std::vector(data, data + len))); + }}; lm_.reset(link_manager_create(controller_ops_)); ll_.reset(link_layer_create(controller_ops_)); @@ -2124,102 +2030,92 @@ LinkLayerController::LinkLayerController(const Address& address, LinkLayerController::~LinkLayerController() {} void LinkLayerController::SendLeLinkLayerPacket( - std::unique_ptr packet, - int8_t tx_power) { - std::shared_ptr shared_packet = - std::move(packet); + std::unique_ptr packet, int8_t tx_power) { + std::shared_ptr shared_packet = std::move(packet); ScheduleTask(kNoDelayMs, [this, shared_packet, tx_power]() { send_to_remote_(shared_packet, Phy::Type::LOW_ENERGY, tx_power); }); } void LinkLayerController::SendLinkLayerPacket( - std::unique_ptr packet, - int8_t tx_power) { - std::shared_ptr shared_packet = - std::move(packet); + std::unique_ptr packet, int8_t tx_power) { + std::shared_ptr shared_packet = std::move(packet); ScheduleTask(kNoDelayMs, [this, shared_packet, tx_power]() { send_to_remote_(shared_packet, Phy::Type::BR_EDR, tx_power); }); } -ErrorCode LinkLayerController::SendLeCommandToRemoteByAddress( - OpCode opcode, const Address& own_address, const Address& peer_address) { +ErrorCode LinkLayerController::SendLeCommandToRemoteByAddress(OpCode opcode, + const Address& own_address, + const Address& peer_address) { switch (opcode) { - case (OpCode::LE_READ_REMOTE_FEATURES): - SendLeLinkLayerPacket(model::packets::LeReadRemoteFeaturesBuilder::Create( - own_address, peer_address)); + case (OpCode::LE_READ_REMOTE_FEATURES_PAGE_0): + SendLeLinkLayerPacket( + model::packets::LeReadRemoteFeaturesBuilder::Create(own_address, peer_address)); break; default: - INFO(id_, "Dropping unhandled command 0x{:04x}", - static_cast(opcode)); + INFO(id_, "Dropping unhandled command 0x{:04x}", static_cast(opcode)); return ErrorCode::UNKNOWN_HCI_COMMAND; } return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::SendCommandToRemoteByAddress( - OpCode opcode, pdl::packet::slice args, const Address& own_address, - const Address& peer_address) { +ErrorCode LinkLayerController::SendCommandToRemoteByAddress(OpCode opcode, pdl::packet::slice args, + const Address& own_address, + const Address& peer_address) { switch (opcode) { case (OpCode::REMOTE_NAME_REQUEST): // LMP features get requested with remote name requests. - SendLinkLayerPacket(model::packets::ReadRemoteLmpFeaturesBuilder::Create( - own_address, peer_address)); - SendLinkLayerPacket(model::packets::RemoteNameRequestBuilder::Create( - own_address, peer_address)); + SendLinkLayerPacket( + model::packets::ReadRemoteLmpFeaturesBuilder::Create(own_address, peer_address)); + SendLinkLayerPacket( + model::packets::RemoteNameRequestBuilder::Create(own_address, peer_address)); break; case (OpCode::READ_REMOTE_SUPPORTED_FEATURES): - SendLinkLayerPacket( - model::packets::ReadRemoteSupportedFeaturesBuilder::Create( - own_address, peer_address)); + SendLinkLayerPacket(model::packets::ReadRemoteSupportedFeaturesBuilder::Create(own_address, + peer_address)); break; case (OpCode::READ_REMOTE_EXTENDED_FEATURES): { pdl::packet::slice page_number_slice = args.subrange(5, 1); uint8_t page_number = page_number_slice.read_le(); - SendLinkLayerPacket( - model::packets::ReadRemoteExtendedFeaturesBuilder::Create( + SendLinkLayerPacket(model::packets::ReadRemoteExtendedFeaturesBuilder::Create( own_address, peer_address, page_number)); } break; case (OpCode::READ_REMOTE_VERSION_INFORMATION): - SendLinkLayerPacket( - model::packets::ReadRemoteVersionInformationBuilder::Create( + SendLinkLayerPacket(model::packets::ReadRemoteVersionInformationBuilder::Create( own_address, peer_address)); break; case (OpCode::READ_CLOCK_OFFSET): - SendLinkLayerPacket(model::packets::ReadClockOffsetBuilder::Create( - own_address, peer_address)); + SendLinkLayerPacket( + model::packets::ReadClockOffsetBuilder::Create(own_address, peer_address)); break; default: - INFO(id_, "Dropping unhandled command 0x{:04x}", - static_cast(opcode)); + INFO(id_, "Dropping unhandled command 0x{:04x}", static_cast(opcode)); return ErrorCode::UNKNOWN_HCI_COMMAND; } return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::SendCommandToRemoteByHandle( - OpCode opcode, pdl::packet::slice args, uint16_t handle) { +ErrorCode LinkLayerController::SendCommandToRemoteByHandle(OpCode opcode, pdl::packet::slice args, + uint16_t handle) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } switch (opcode) { - case (OpCode::LE_READ_REMOTE_FEATURES): - return SendLeCommandToRemoteByAddress( - opcode, connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress()); + case (OpCode::LE_READ_REMOTE_FEATURES_PAGE_0): + return SendLeCommandToRemoteByAddress(opcode, connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress()); default: - return SendCommandToRemoteByAddress( - opcode, args, connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress()); + return SendCommandToRemoteByAddress(opcode, args, + connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress()); } } -ErrorCode LinkLayerController::SendAclToRemote( - bluetooth::hci::AclView acl_packet) { +ErrorCode LinkLayerController::SendAclToRemote(bluetooth::hci::AclView acl_packet) { uint16_t handle = acl_packet.GetHandle(); if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; @@ -2231,10 +2127,10 @@ ErrorCode LinkLayerController::SendAclToRemote( auto acl_packet_payload = acl_packet.GetPayload(); auto acl = model::packets::AclBuilder::Create( - my_address.GetAddress(), destination.GetAddress(), - static_cast(acl_packet.GetPacketBoundaryFlag()), - static_cast(acl_packet.GetBroadcastFlag()), - std::vector(acl_packet_payload.begin(), acl_packet_payload.end())); + my_address.GetAddress(), destination.GetAddress(), + static_cast(acl_packet.GetPacketBoundaryFlag()), + static_cast(acl_packet.GetBroadcastFlag()), + std::vector(acl_packet_payload.begin(), acl_packet_payload.end())); switch (phy) { case Phy::Type::BR_EDR: @@ -2247,13 +2143,12 @@ ErrorCode LinkLayerController::SendAclToRemote( ScheduleTask(kNoDelayMs, [this, handle]() { send_event_(bluetooth::hci::NumberOfCompletedPacketsBuilder::Create( - {bluetooth::hci::CompletedPackets(handle, 1)})); + {bluetooth::hci::CompletedPackets(handle, 1)})); }); return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::SendScoToRemote( - bluetooth::hci::ScoView sco_packet) { +ErrorCode LinkLayerController::SendScoToRemote(bluetooth::hci::ScoView sco_packet) { uint16_t handle = sco_packet.GetHandle(); if (!connections_.HasScoHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; @@ -2266,13 +2161,13 @@ ErrorCode LinkLayerController::SendScoToRemote( auto sco_data = sco_packet.GetData(); std::vector sco_data_bytes(sco_data.begin(), sco_data.end()); - SendLinkLayerPacket(model::packets::ScoBuilder::Create( - source, destination, std::move(sco_data_bytes))); + SendLinkLayerPacket( + model::packets::ScoBuilder::Create(source, destination, std::move(sco_data_bytes))); return ErrorCode::SUCCESS; } -void LinkLayerController::IncomingPacket( - model::packets::LinkLayerPacketView incoming, int8_t rssi) { +void LinkLayerController::IncomingPacket(model::packets::LinkLayerPacketView incoming, + int8_t rssi) { ASSERT(incoming.IsValid()); auto destination_address = incoming.GetDestinationAddress(); @@ -2293,8 +2188,7 @@ void LinkLayerController::IncomingPacket( } // Check public address - if (destination_address == address_ || - destination_address == random_address_) { + if (destination_address == address_ || destination_address == random_address_) { address_matches = true; } @@ -2307,8 +2201,7 @@ void LinkLayerController::IncomingPacket( auto source_address = incoming.GetSourceAddress(); auto handle = connections_.GetHandleOnlyAddress(source_address); if (handle != kReservedHandle) { - if (connections_.GetOwnAddress(handle).GetAddress() == - destination_address) { + if (connections_.GetOwnAddress(handle).GetAddress() == destination_address) { address_matches = true; // Update link timeout for valid ACL connections @@ -2318,9 +2211,8 @@ void LinkLayerController::IncomingPacket( // Drop packets not addressed to me if (!address_matches) { - INFO(id_, "{} | Dropping packet not addressed to me {}->{} (type 0x{:x})", - address_, source_address, destination_address, - static_cast(incoming.GetType())); + INFO(id_, "{} | Dropping packet not addressed to me {}->{} (type 0x{:x})", address_, + source_address, destination_address, static_cast(incoming.GetType())); return; } @@ -2473,27 +2365,24 @@ void LinkLayerController::IncomingPacket( } } -void LinkLayerController::IncomingAclPacket( - model::packets::LinkLayerPacketView incoming, int8_t rssi) { +void LinkLayerController::IncomingAclPacket(model::packets::LinkLayerPacketView incoming, + int8_t rssi) { auto acl = model::packets::AclView::Create(incoming); ASSERT(acl.IsValid()); auto acl_data = acl.GetData(); - auto packet_boundary_flag = - bluetooth::hci::PacketBoundaryFlag(acl.GetPacketBoundaryFlag()); + auto packet_boundary_flag = bluetooth::hci::PacketBoundaryFlag(acl.GetPacketBoundaryFlag()); auto broadcast_flag = bluetooth::hci::BroadcastFlag(acl.GetBroadcastFlag()); if (packet_boundary_flag == bluetooth::hci::PacketBoundaryFlag::FIRST_NON_AUTOMATICALLY_FLUSHABLE) { - packet_boundary_flag = - bluetooth::hci::PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE; + packet_boundary_flag = bluetooth::hci::PacketBoundaryFlag::FIRST_AUTOMATICALLY_FLUSHABLE; } - INFO(id_, "Acl Packet [{}] {} -> {}", acl_data.size(), - incoming.GetSourceAddress(), incoming.GetDestinationAddress()); + INFO(id_, "Acl Packet [{}] {} -> {}", acl_data.size(), incoming.GetSourceAddress(), + incoming.GetDestinationAddress()); - uint16_t connection_handle = - connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); + uint16_t connection_handle = connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); if (connection_handle == kReservedHandle) { INFO(id_, "Dropping packet since connection does not exist"); return; @@ -2512,20 +2401,17 @@ void LinkLayerController::IncomingAclPacket( std::vector fragment(acl_data.begin() + offset, acl_data.begin() + offset + fragment_size); - auto acl_packet = bluetooth::hci::AclBuilder::Create( - connection_handle, packet_boundary_flag, broadcast_flag, - std::move(fragment)); + auto acl_packet = bluetooth::hci::AclBuilder::Create(connection_handle, packet_boundary_flag, + broadcast_flag, std::move(fragment)); send_acl_(std::move(acl_packet)); - packet_boundary_flag = - bluetooth::hci::PacketBoundaryFlag::CONTINUING_FRAGMENT; + packet_boundary_flag = bluetooth::hci::PacketBoundaryFlag::CONTINUING_FRAGMENT; offset += fragment_size; } } -void LinkLayerController::IncomingScoPacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingScoPacket(model::packets::LinkLayerPacketView incoming) { Address source = incoming.GetSourceAddress(); uint16_t sco_handle = connections_.GetScoHandle(source); if (!connections_.HasScoHandle(sco_handle)) { @@ -2542,63 +2428,54 @@ void LinkLayerController::IncomingScoPacket( incoming.GetSourceAddress(), incoming.GetDestinationAddress()); send_sco_(bluetooth::hci::ScoBuilder::Create( - sco_handle, bluetooth::hci::PacketStatusFlag::CORRECTLY_RECEIVED, - sco_data_bytes)); + sco_handle, bluetooth::hci::PacketStatusFlag::CORRECTLY_RECEIVED, sco_data_bytes)); } -void LinkLayerController::IncomingRemoteNameRequest( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingRemoteNameRequest(model::packets::LinkLayerPacketView incoming) { auto view = model::packets::RemoteNameRequestView::Create(incoming); ASSERT(view.IsValid()); SendLinkLayerPacket(model::packets::RemoteNameRequestResponseBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - local_name_)); + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), local_name_)); } void LinkLayerController::IncomingRemoteNameRequestResponse( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { auto view = model::packets::RemoteNameRequestResponseView::Create(incoming); ASSERT(view.IsValid()); if (IsEventUnmasked(EventCode::REMOTE_NAME_REQUEST_COMPLETE)) { send_event_(bluetooth::hci::RemoteNameRequestCompleteBuilder::Create( - ErrorCode::SUCCESS, incoming.GetSourceAddress(), view.GetName())); + ErrorCode::SUCCESS, incoming.GetSourceAddress(), view.GetName())); } } void LinkLayerController::IncomingReadRemoteLmpFeatures( - model::packets::LinkLayerPacketView incoming) { - SendLinkLayerPacket( - model::packets::ReadRemoteLmpFeaturesResponseBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - host_supported_features_)); + model::packets::LinkLayerPacketView incoming) { + SendLinkLayerPacket(model::packets::ReadRemoteLmpFeaturesResponseBuilder::Create( + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), host_supported_features_)); } void LinkLayerController::IncomingReadRemoteLmpFeaturesResponse( - model::packets::LinkLayerPacketView incoming) { - auto view = - model::packets::ReadRemoteLmpFeaturesResponseView::Create(incoming); + model::packets::LinkLayerPacketView incoming) { + auto view = model::packets::ReadRemoteLmpFeaturesResponseView::Create(incoming); ASSERT(view.IsValid()); if (IsEventUnmasked(EventCode::REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION)) { - send_event_( - bluetooth::hci::RemoteHostSupportedFeaturesNotificationBuilder::Create( + send_event_(bluetooth::hci::RemoteHostSupportedFeaturesNotificationBuilder::Create( incoming.GetSourceAddress(), view.GetFeatures())); } } void LinkLayerController::IncomingReadRemoteSupportedFeatures( - model::packets::LinkLayerPacketView incoming) { - SendLinkLayerPacket( - model::packets::ReadRemoteSupportedFeaturesResponseBuilder::Create( + model::packets::LinkLayerPacketView incoming) { + SendLinkLayerPacket(model::packets::ReadRemoteSupportedFeaturesResponseBuilder::Create( incoming.GetDestinationAddress(), incoming.GetSourceAddress(), properties_.lmp_features[0])); } void LinkLayerController::IncomingReadRemoteSupportedFeaturesResponse( - model::packets::LinkLayerPacketView incoming) { - auto view = - model::packets::ReadRemoteSupportedFeaturesResponseView::Create(incoming); + model::packets::LinkLayerPacketView incoming) { + auto view = model::packets::ReadRemoteSupportedFeaturesResponseView::Create(incoming); ASSERT(view.IsValid()); Address source = incoming.GetSourceAddress(); uint16_t handle = connections_.GetHandleOnlyAddress(source); @@ -2607,14 +2484,13 @@ void LinkLayerController::IncomingReadRemoteSupportedFeaturesResponse( return; } if (IsEventUnmasked(EventCode::READ_REMOTE_SUPPORTED_FEATURES_COMPLETE)) { - send_event_( - bluetooth::hci::ReadRemoteSupportedFeaturesCompleteBuilder::Create( + send_event_(bluetooth::hci::ReadRemoteSupportedFeaturesCompleteBuilder::Create( ErrorCode::SUCCESS, handle, view.GetFeatures())); } } void LinkLayerController::IncomingReadRemoteExtendedFeatures( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { auto view = model::packets::ReadRemoteExtendedFeaturesView::Create(incoming); ASSERT(view.IsValid()); uint8_t page_number = view.GetPageNumber(); @@ -2622,17 +2498,14 @@ void LinkLayerController::IncomingReadRemoteExtendedFeatures( if (page_number >= properties_.lmp_features.size()) { error_code = static_cast(ErrorCode::INVALID_LMP_OR_LL_PARAMETERS); } - SendLinkLayerPacket( - model::packets::ReadRemoteExtendedFeaturesResponseBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - error_code, page_number, GetMaxLmpFeaturesPageNumber(), - GetLmpFeatures(page_number))); + SendLinkLayerPacket(model::packets::ReadRemoteExtendedFeaturesResponseBuilder::Create( + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), error_code, page_number, + GetMaxLmpFeaturesPageNumber(), GetLmpFeatures(page_number))); } void LinkLayerController::IncomingReadRemoteExtendedFeaturesResponse( - model::packets::LinkLayerPacketView incoming) { - auto view = - model::packets::ReadRemoteExtendedFeaturesResponseView::Create(incoming); + model::packets::LinkLayerPacketView incoming) { + auto view = model::packets::ReadRemoteExtendedFeaturesResponseView::Create(incoming); ASSERT(view.IsValid()); Address source = incoming.GetSourceAddress(); uint16_t handle = connections_.GetHandleOnlyAddress(source); @@ -2641,27 +2514,22 @@ void LinkLayerController::IncomingReadRemoteExtendedFeaturesResponse( return; } if (IsEventUnmasked(EventCode::READ_REMOTE_EXTENDED_FEATURES_COMPLETE)) { - send_event_( - bluetooth::hci::ReadRemoteExtendedFeaturesCompleteBuilder::Create( - static_cast(view.GetStatus()), handle, - view.GetPageNumber(), view.GetMaxPageNumber(), view.GetFeatures())); + send_event_(bluetooth::hci::ReadRemoteExtendedFeaturesCompleteBuilder::Create( + static_cast(view.GetStatus()), handle, view.GetPageNumber(), + view.GetMaxPageNumber(), view.GetFeatures())); } } -void LinkLayerController::IncomingReadRemoteVersion( - model::packets::LinkLayerPacketView incoming) { - SendLinkLayerPacket( - model::packets::ReadRemoteVersionInformationResponseBuilder::Create( +void LinkLayerController::IncomingReadRemoteVersion(model::packets::LinkLayerPacketView incoming) { + SendLinkLayerPacket(model::packets::ReadRemoteVersionInformationResponseBuilder::Create( incoming.GetDestinationAddress(), incoming.GetSourceAddress(), static_cast(properties_.lmp_version), - static_cast(properties_.lmp_subversion), - properties_.company_identifier)); + static_cast(properties_.lmp_subversion), properties_.company_identifier)); } void LinkLayerController::IncomingReadRemoteVersionResponse( - model::packets::LinkLayerPacketView incoming) { - auto view = model::packets::ReadRemoteVersionInformationResponseView::Create( - incoming); + model::packets::LinkLayerPacketView incoming) { + auto view = model::packets::ReadRemoteVersionInformationResponseView::Create(incoming); ASSERT(view.IsValid()); Address source = incoming.GetSourceAddress(); uint16_t handle = connections_.GetHandleOnlyAddress(source); @@ -2670,22 +2538,19 @@ void LinkLayerController::IncomingReadRemoteVersionResponse( return; } if (IsEventUnmasked(EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE)) { - send_event_( - bluetooth::hci::ReadRemoteVersionInformationCompleteBuilder::Create( - ErrorCode::SUCCESS, handle, view.GetLmpVersion(), - view.GetManufacturerName(), view.GetLmpSubversion())); + send_event_(bluetooth::hci::ReadRemoteVersionInformationCompleteBuilder::Create( + ErrorCode::SUCCESS, handle, view.GetLmpVersion(), view.GetManufacturerName(), + view.GetLmpSubversion())); } } -void LinkLayerController::IncomingReadClockOffset( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingReadClockOffset(model::packets::LinkLayerPacketView incoming) { SendLinkLayerPacket(model::packets::ReadClockOffsetResponseBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - GetClockOffset())); + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), GetClockOffset())); } void LinkLayerController::IncomingReadClockOffsetResponse( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { auto view = model::packets::ReadClockOffsetResponseView::Create(incoming); ASSERT(view.IsValid()); Address source = incoming.GetSourceAddress(); @@ -2695,13 +2560,12 @@ void LinkLayerController::IncomingReadClockOffsetResponse( return; } if (IsEventUnmasked(EventCode::READ_CLOCK_OFFSET_COMPLETE)) { - send_event_(bluetooth::hci::ReadClockOffsetCompleteBuilder::Create( - ErrorCode::SUCCESS, handle, view.GetOffset())); + send_event_(bluetooth::hci::ReadClockOffsetCompleteBuilder::Create(ErrorCode::SUCCESS, handle, + view.GetOffset())); } } -void LinkLayerController::IncomingDisconnectPacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingDisconnectPacket(model::packets::LinkLayerPacketView incoming) { INFO(id_, "Disconnect Packet"); auto disconnect = model::packets::DisconnectView::Create(incoming); ASSERT(disconnect.IsValid()); @@ -2714,22 +2578,20 @@ void LinkLayerController::IncomingDisconnectPacket( } auto is_br_edr = connections_.GetPhyType(handle) == Phy::Type::BR_EDR; ASSERT_LOG( - connections_.Disconnect( - handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }), - "GetHandle() returned invalid handle 0x{:x}", handle); + connections_.Disconnect(handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }), + "GetHandle() returned invalid handle 0x{:x}", handle); uint8_t reason = disconnect.GetReason(); SendDisconnectionCompleteEvent(handle, ErrorCode(reason)); if (is_br_edr) { - ASSERT(link_manager_remove_link( - lm_.get(), reinterpret_cast(peer.data()))); + ASSERT(link_manager_remove_link(lm_.get(), reinterpret_cast(peer.data()))); } else { ASSERT(link_layer_remove_link(ll_.get(), handle)); } } -void LinkLayerController::IncomingInquiryPacket( - model::packets::LinkLayerPacketView incoming, uint8_t rssi) { +void LinkLayerController::IncomingInquiryPacket(model::packets::LinkLayerPacketView incoming, + uint8_t rssi) { auto inquiry = model::packets::InquiryView::Create(incoming); ASSERT(inquiry.IsValid()); @@ -2746,49 +2608,40 @@ void LinkLayerController::IncomingInquiryPacket( switch (inquiry.GetInquiryType()) { case (model::packets::InquiryType::STANDARD): { SendLinkLayerPacket(model::packets::InquiryResponseBuilder::Create( - GetAddress(), peer, static_cast(GetPageScanRepetitionMode()), - class_of_device_, GetClockOffset())); + GetAddress(), peer, static_cast(GetPageScanRepetitionMode()), + class_of_device_, GetClockOffset())); } break; case (model::packets::InquiryType::RSSI): { - SendLinkLayerPacket( - model::packets::InquiryResponseWithRssiBuilder::Create( - GetAddress(), peer, - static_cast(GetPageScanRepetitionMode()), + SendLinkLayerPacket(model::packets::InquiryResponseWithRssiBuilder::Create( + GetAddress(), peer, static_cast(GetPageScanRepetitionMode()), class_of_device_, GetClockOffset(), rssi)); } break; case (model::packets::InquiryType::EXTENDED): { - SendLinkLayerPacket( - model::packets::ExtendedInquiryResponseBuilder::Create( - GetAddress(), peer, - static_cast(GetPageScanRepetitionMode()), - class_of_device_, GetClockOffset(), rssi, - extended_inquiry_response_)); + SendLinkLayerPacket(model::packets::ExtendedInquiryResponseBuilder::Create( + GetAddress(), peer, static_cast(GetPageScanRepetitionMode()), + class_of_device_, GetClockOffset(), rssi, extended_inquiry_response_)); } break; default: - WARNING(id_, "Unhandled Incoming Inquiry of type {}", - static_cast(inquiry.GetType())); + WARNING(id_, "Unhandled Incoming Inquiry of type {}", static_cast(inquiry.GetType())); return; } // TODO: Send an Inquiry Response Notification Event 7.7.74 } void LinkLayerController::IncomingInquiryResponsePacket( - model::packets::LinkLayerPacketView incoming) { - auto basic_inquiry_response = - model::packets::BasicInquiryResponseView::Create(incoming); + model::packets::LinkLayerPacketView incoming) { + auto basic_inquiry_response = model::packets::BasicInquiryResponseView::Create(incoming); ASSERT(basic_inquiry_response.IsValid()); std::vector eir; switch (basic_inquiry_response.GetInquiryType()) { case (model::packets::InquiryType::STANDARD): { // TODO: Support multiple inquiries in the same packet. - auto inquiry_response = - model::packets::InquiryResponseView::Create(basic_inquiry_response); + auto inquiry_response = model::packets::InquiryResponseView::Create(basic_inquiry_response); ASSERT(inquiry_response.IsValid()); auto page_scan_repetition_mode = - (bluetooth::hci::PageScanRepetitionMode) - inquiry_response.GetPageScanRepetitionMode(); + (bluetooth::hci::PageScanRepetitionMode)inquiry_response.GetPageScanRepetitionMode(); std::vector responses; responses.emplace_back(); @@ -2803,13 +2656,11 @@ void LinkLayerController::IncomingInquiryResponsePacket( case (model::packets::InquiryType::RSSI): { auto inquiry_response = - model::packets::InquiryResponseWithRssiView::Create( - basic_inquiry_response); + model::packets::InquiryResponseWithRssiView::Create(basic_inquiry_response); ASSERT(inquiry_response.IsValid()); auto page_scan_repetition_mode = - (bluetooth::hci::PageScanRepetitionMode) - inquiry_response.GetPageScanRepetitionMode(); + (bluetooth::hci::PageScanRepetitionMode)inquiry_response.GetPageScanRepetitionMode(); std::vector responses; responses.emplace_back(); @@ -2819,24 +2670,21 @@ void LinkLayerController::IncomingInquiryResponsePacket( responses.back().clock_offset_ = inquiry_response.GetClockOffset(); responses.back().rssi_ = inquiry_response.GetRssi(); if (IsEventUnmasked(EventCode::INQUIRY_RESULT_WITH_RSSI)) { - send_event_( - bluetooth::hci::InquiryResultWithRssiBuilder::Create(responses)); + send_event_(bluetooth::hci::InquiryResultWithRssiBuilder::Create(responses)); } } break; case (model::packets::InquiryType::EXTENDED): { auto inquiry_response = - model::packets::ExtendedInquiryResponseView::Create( - basic_inquiry_response); + model::packets::ExtendedInquiryResponseView::Create(basic_inquiry_response); ASSERT(inquiry_response.IsValid()); send_event_(bluetooth::hci::ExtendedInquiryResultBuilder::Create( - inquiry_response.GetSourceAddress(), - static_cast( - inquiry_response.GetPageScanRepetitionMode()), - inquiry_response.GetClassOfDevice(), - inquiry_response.GetClockOffset(), inquiry_response.GetRssi(), - inquiry_response.GetExtendedInquiryResponse())); + inquiry_response.GetSourceAddress(), + static_cast( + inquiry_response.GetPageScanRepetitionMode()), + inquiry_response.GetClassOfDevice(), inquiry_response.GetClockOffset(), + inquiry_response.GetRssi(), inquiry_response.GetExtendedInquiryResponse())); } break; default: @@ -2845,8 +2693,7 @@ void LinkLayerController::IncomingInquiryResponsePacket( } } -Address LinkLayerController::generate_rpa( - std::array irk) { +Address LinkLayerController::generate_rpa(std::array irk) { // most significant bit, bit7, bit6 is 01 to be resolvable random // Bits of the random part of prand shall not be all 1 or all 0 std::array prand; @@ -2868,8 +2715,7 @@ Address LinkLayerController::generate_rpa( rpa.address[5] = prand[2]; /* encrypt with IRK */ - rootcanal::crypto::Octet16 p = - rootcanal::crypto::aes_128(irk, prand.data(), 3); + rootcanal::crypto::Octet16 p = rootcanal::crypto::aes_128(irk, prand.data(), 3); /* set hash to be LSB of rpAddress */ rpa.address[0] = p[0]; @@ -2880,12 +2726,12 @@ Address LinkLayerController::generate_rpa( } bool LinkLayerController::irk_is_zero(std::array irk) { - return std::all_of(irk.begin(), irk.end(), [](uint8_t b) { return b == 0; }); + return std::all_of(irk.begin(), irk.end(), [](uint8_t b) { return b == 0; }); } // Handle legacy advertising PDUs while in the Scanning state. void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( - model::packets::LeLegacyAdvertisingPduView& pdu, uint8_t rssi) { + model::packets::LeLegacyAdvertisingPduView& pdu, uint8_t rssi) { if (!scanner_.IsEnabled()) { return; } @@ -2893,24 +2739,22 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( auto advertising_type = pdu.GetAdvertisingType(); std::vector advertising_data = pdu.GetAdvertisingData(); - AddressWithType advertising_address{ - pdu.GetSourceAddress(), - static_cast(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast(pdu.GetTargetAddressType())}; bool scannable_advertising = - advertising_type == model::packets::LegacyAdvertisingType::ADV_IND || - advertising_type == model::packets::LegacyAdvertisingType::ADV_SCAN_IND; + advertising_type == model::packets::LegacyAdvertisingType::ADV_IND || + advertising_type == model::packets::LegacyAdvertisingType::ADV_SCAN_IND; bool directed_advertising = - advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; + advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; bool connectable_advertising = - advertising_type == model::packets::LegacyAdvertisingType::ADV_IND || - advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; + advertising_type == model::packets::LegacyAdvertisingType::ADV_IND || + advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; // TODO: check originating PHY, compare against active scanning PHYs // (scanner_.le_1m_phy or scanner_.le_coded_phy). @@ -2921,7 +2765,7 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( // address. The scanner’s filter policy shall then determine if the scanner // responds with a scan request. AddressWithType resolved_advertising_address = - ResolvePrivateAddress(advertising_address).value_or(advertising_address); + ResolvePrivateAddress(advertising_address).value_or(advertising_address); if (resolved_advertising_address != advertising_address) { DEBUG(id_, "Resolved the advertising address {} to {}", advertising_address, @@ -2934,8 +2778,7 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( case bluetooth::hci::LeScanningFilterPolicy::CHECK_INITIATORS_IDENTITY: break; case bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY: - case bluetooth::hci::LeScanningFilterPolicy:: - FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: + case bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: if (!LeFilterAcceptListContainsDevice(resolved_advertising_address)) { DEBUG(id_, "Legacy advertising ignored by scanner because the advertising " @@ -2978,10 +2821,8 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( // • the TargetA field is identical to the scanner's device address, or // • the TargetA field is a resolvable private address. case bluetooth::hci::LeScanningFilterPolicy::CHECK_INITIATORS_IDENTITY: - case bluetooth::hci::LeScanningFilterPolicy:: - FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: - if (!IsLocalPublicOrRandomAddress(target_address) && - !target_address.IsRpa()) { + case bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: + if (!IsLocalPublicOrRandomAddress(target_address) && !target_address.IsRpa()) { DEBUG(id_, "Legacy advertising ignored by scanner because the directed " "address {} does not match the current device or is not a " @@ -2990,15 +2831,14 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( return; } should_send_directed_advertising_report = - target_address.IsRpa() && - !ResolveTargetA(target_address, resolved_advertising_address); + target_address.IsRpa() && + !ResolveTargetA(target_address, resolved_advertising_address); break; } } bool should_send_advertising_report = true; - if (scanner_.filter_duplicates != - bluetooth::hci::FilterDuplicates::DISABLED) { + if (scanner_.filter_duplicates != bluetooth::hci::FilterDuplicates::DISABLED) { if (scanner_.IsPacketInHistory(pdu.bytes())) { should_send_advertising_report = false; } else { @@ -3009,27 +2849,23 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( // Legacy scanning, directed advertising. if (LegacyAdvertising() && should_send_advertising_report && should_send_directed_advertising_report && - IsLeEventUnmasked(SubeventCode::DIRECTED_ADVERTISING_REPORT)) { + IsLeEventUnmasked(SubeventCode::LE_DIRECTED_ADVERTISING_REPORT)) { bluetooth::hci::LeDirectedAdvertisingResponse response; - response.event_type_ = - bluetooth::hci::DirectAdvertisingEventType::ADV_DIRECT_IND; - response.address_type_ = - static_cast( + response.event_type_ = bluetooth::hci::DirectAdvertisingEventType::ADV_DIRECT_IND; + response.address_type_ = static_cast( resolved_advertising_address.GetAddressType()); response.address_ = resolved_advertising_address.GetAddress(); - response.direct_address_type_ = - bluetooth::hci::DirectAddressType::RANDOM_DEVICE_ADDRESS; + response.direct_address_type_ = bluetooth::hci::DirectAddressType::RANDOM_DEVICE_ADDRESS; response.direct_address_ = target_address.GetAddress(); response.rssi_ = rssi; - send_event_( - bluetooth::hci::LeDirectedAdvertisingReportBuilder::Create({response})); + send_event_(bluetooth::hci::LeDirectedAdvertisingReportBuilder::Create({response})); } // Legacy scanning, un-directed advertising. if (LegacyAdvertising() && should_send_advertising_report && !should_send_directed_advertising_report && - IsLeEventUnmasked(SubeventCode::ADVERTISING_REPORT)) { + IsLeEventUnmasked(SubeventCode::LE_ADVERTISING_REPORT)) { bluetooth::hci::LeAdvertisingResponse response; response.address_type_ = resolved_advertising_address.GetAddressType(); response.address_ = resolved_advertising_address.GetAddress(); @@ -3041,16 +2877,13 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( response.event_type_ = bluetooth::hci::AdvertisingEventType::ADV_IND; break; case model::packets::LegacyAdvertisingType::ADV_DIRECT_IND: - response.event_type_ = - bluetooth::hci::AdvertisingEventType::ADV_DIRECT_IND; + response.event_type_ = bluetooth::hci::AdvertisingEventType::ADV_DIRECT_IND; break; case model::packets::LegacyAdvertisingType::ADV_SCAN_IND: - response.event_type_ = - bluetooth::hci::AdvertisingEventType::ADV_SCAN_IND; + response.event_type_ = bluetooth::hci::AdvertisingEventType::ADV_SCAN_IND; break; case model::packets::LegacyAdvertisingType::ADV_NONCONN_IND: - response.event_type_ = - bluetooth::hci::AdvertisingEventType::ADV_NONCONN_IND; + response.event_type_ = bluetooth::hci::AdvertisingEventType::ADV_NONCONN_IND; break; } @@ -3059,7 +2892,7 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( // Extended scanning. if (ExtendedAdvertising() && should_send_advertising_report && - IsLeEventUnmasked(SubeventCode::EXTENDED_ADVERTISING_REPORT)) { + IsLeEventUnmasked(SubeventCode::LE_EXTENDED_ADVERTISING_REPORT)) { bluetooth::hci::LeExtendedAdvertisingResponse response; response.connectable_ = connectable_advertising; response.scannable_ = scannable_advertising; @@ -3067,8 +2900,7 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( response.scan_response_ = false; response.legacy_ = true; response.data_status_ = bluetooth::hci::DataStatus::COMPLETE; - response.address_type_ = - static_cast( + response.address_type_ = static_cast( resolved_advertising_address.GetAddressType()); response.address_ = resolved_advertising_address.GetAddress(); response.primary_phy_ = bluetooth::hci::PrimaryPhyType::LE_1M; @@ -3079,26 +2911,23 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( response.periodic_advertising_interval_ = 0; // No periodic advertising. if (directed_advertising) { response.direct_address_type_ = - bluetooth::hci::DirectAdvertisingAddressType( - target_address.GetAddressType()); + bluetooth::hci::DirectAdvertisingAddressType(target_address.GetAddressType()); response.direct_address_ = target_address.GetAddress(); } else { response.direct_address_type_ = - bluetooth::hci::DirectAdvertisingAddressType::NO_ADDRESS_PROVIDED; + bluetooth::hci::DirectAdvertisingAddressType::NO_ADDRESS_PROVIDED; response.direct_address_ = Address::kEmpty; } response.advertising_data_ = advertising_data; - send_event_( - bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create({response})); + send_event_(bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create({response})); } // Did the user enable Active scanning ? - bool active_scanning = - (scanner_.le_1m_phy.enabled && - scanner_.le_1m_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE) || - (scanner_.le_coded_phy.enabled && - scanner_.le_coded_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE); + bool active_scanning = (scanner_.le_1m_phy.enabled && + scanner_.le_1m_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE) || + (scanner_.le_coded_phy.enabled && + scanner_.le_coded_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE); // Active scanning. // Note: only send SCAN requests in response to scannable advertising @@ -3128,13 +2957,10 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( // Scan requests with public or random device addresses must be ignored // when the peer has network privacy mode. - AddressWithType public_address{address_, - AddressType::PUBLIC_DEVICE_ADDRESS}; - AddressWithType random_address{random_address_, - AddressType::RANDOM_DEVICE_ADDRESS}; + AddressWithType public_address{address_, AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType random_address{random_address_, AddressType::RANDOM_DEVICE_ADDRESS}; std::optional resolvable_scanning_address = - GenerateResolvablePrivateAddress(resolved_advertising_address, - IrkSelection::Local); + GenerateResolvablePrivateAddress(resolved_advertising_address, IrkSelection::Local); // The ScanA field of the scanning PDU is generated using the // Resolving List’s Local IRK value and the Resolvable Private Address @@ -3169,8 +2995,7 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( scanner_.primary_scan_response_phy = model::packets::PhyType::LE_1M; scanner_.secondary_scan_response_phy = model::packets::PhyType::NO_PACKETS; scanner_.pending_scan_request = advertising_address; - scanner_.pending_scan_request_timeout = - std::chrono::steady_clock::now() + kScanRequestTimeout; + scanner_.pending_scan_request_timeout = std::chrono::steady_clock::now() + kScanRequestTimeout; INFO(id_, "Sending LE Scan request to advertising address {} with scanning " @@ -3181,26 +3006,24 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( // shall be the same as the advertiser’s device address (AdvA field) // received in the advertising PDU to which the scanner is responding. SendLeLinkLayerPacket(model::packets::LeScanBuilder::Create( - scanning_address.GetAddress(), advertising_address.GetAddress(), - static_cast( - scanning_address.GetAddressType()), - static_cast( - advertising_address.GetAddressType()))); + scanning_address.GetAddress(), advertising_address.GetAddress(), + static_cast(scanning_address.GetAddressType()), + static_cast(advertising_address.GetAddressType()))); } } void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( - model::packets::LeLegacyAdvertisingPduView& pdu) { + model::packets::LeLegacyAdvertisingPduView& pdu) { if (!initiator_.IsEnabled()) { return; } auto advertising_type = pdu.GetAdvertisingType(); bool connectable_advertising = - advertising_type == model::packets::LegacyAdvertisingType::ADV_IND || - advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; + advertising_type == model::packets::LegacyAdvertisingType::ADV_IND || + advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; bool directed_advertising = - advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; + advertising_type == model::packets::LegacyAdvertisingType::ADV_DIRECT_IND; // Connection. // Note: only send CONNECT requests in response to connectable advertising @@ -3218,16 +3041,14 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( return; } - AddressWithType advertising_address{ - pdu.GetSourceAddress(), - static_cast(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast(pdu.GetTargetAddressType())}; AddressWithType resolved_advertising_address = - ResolvePrivateAddress(advertising_address).value_or(advertising_address); + ResolvePrivateAddress(advertising_address).value_or(advertising_address); // Vol 6, Part B § 4.3.5 Initiator filter policy. switch (initiator_.initiator_filter_policy) { @@ -3240,7 +3061,7 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( return; } break; - case bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST: + case bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST_WITH_PEER_ADDRESS: if (!LeFilterAcceptListContainsDevice(resolved_advertising_address)) { DEBUG(id_, "Legacy advertising ignored by initiator because the " @@ -3249,6 +3070,12 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( return; } break; + case bluetooth::hci::InitiatorFilterPolicy::USE_DECISION_PDUS: + case bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST_WITH_DECISION_PDUS: + DEBUG(id_, + "Legacy advertising ignored by initiated because the " + "initiator filter policy is unsupported"); + return; } // When an initiator receives a directed connectable advertising event that @@ -3268,10 +3095,8 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( return; } if (!target_address.IsRpa() && - (initiator_.own_address_type == - OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS || - initiator_.own_address_type == - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS)) { + (initiator_.own_address_type == OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS || + initiator_.own_address_type == OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS)) { DEBUG(id_, "Directed legacy advertising ignored by initiator because the " "target address {} is static or public and the initiator is " @@ -3282,11 +3107,9 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( } AddressWithType public_address{address_, AddressType::PUBLIC_DEVICE_ADDRESS}; - AddressWithType random_address{random_address_, - AddressType::RANDOM_DEVICE_ADDRESS}; + AddressWithType random_address{random_address_, AddressType::RANDOM_DEVICE_ADDRESS}; std::optional resolvable_initiating_address = - GenerateResolvablePrivateAddress(resolved_advertising_address, - IrkSelection::Local); + GenerateResolvablePrivateAddress(resolved_advertising_address, IrkSelection::Local); // The Link Layer shall use resolvable private addresses for the initiator’s // device address (InitA field) when initiating connection establishment with @@ -3303,26 +3126,22 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( initiating_address = random_address; break; case bluetooth::hci::OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS: - initiating_address = - resolvable_initiating_address.value_or(public_address); + initiating_address = resolvable_initiating_address.value_or(public_address); break; case bluetooth::hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS: // The random address is checked in Le_Create_Connection or // Le_Extended_Create_Connection. ASSERT(random_address_ != Address::kEmpty); - initiating_address = - resolvable_initiating_address.value_or(random_address); + initiating_address = resolvable_initiating_address.value_or(random_address); break; } - if (!connections_.CreatePendingLeConnection( - advertising_address, - resolved_advertising_address != advertising_address - ? resolved_advertising_address - : AddressWithType{}, - initiating_address)) { - WARNING(id_, "CreatePendingLeConnection failed for connection to {}", - advertising_address); + if (!connections_.CreatePendingLeConnection(advertising_address, + resolved_advertising_address != advertising_address + ? resolved_advertising_address + : AddressWithType{}, + initiating_address)) { + WARNING(id_, "CreatePendingLeConnection failed for connection to {}", advertising_address); } initiator_.pending_connect_request = advertising_address; @@ -3336,20 +3155,17 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( // received in the advertising event PDU to which the initiator is // responding. SendLeLinkLayerPacket(model::packets::LeConnectBuilder::Create( - initiating_address.GetAddress(), advertising_address.GetAddress(), - static_cast( - initiating_address.GetAddressType()), - static_cast( - advertising_address.GetAddressType()), - // The connection is created with the highest allowed - // value for the connection interval and the latency. - initiator_.le_1m_phy.connection_interval_max, - initiator_.le_1m_phy.max_latency, - initiator_.le_1m_phy.supervision_timeout)); + initiating_address.GetAddress(), advertising_address.GetAddress(), + static_cast(initiating_address.GetAddressType()), + static_cast(advertising_address.GetAddressType()), + // The connection is created with the highest allowed + // value for the connection interval and the latency. + initiator_.le_1m_phy.connection_interval_max, initiator_.le_1m_phy.max_latency, + initiator_.le_1m_phy.supervision_timeout)); } void LinkLayerController::IncomingLeLegacyAdvertisingPdu( - model::packets::LinkLayerPacketView incoming, uint8_t rssi) { + model::packets::LinkLayerPacketView incoming, uint8_t rssi) { auto pdu = model::packets::LeLegacyAdvertisingPduView::Create(incoming); ASSERT(pdu.IsValid()); @@ -3359,7 +3175,7 @@ void LinkLayerController::IncomingLeLegacyAdvertisingPdu( // Handle legacy advertising PDUs while in the Scanning state. void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( - model::packets::LeExtendedAdvertisingPduView& pdu, uint8_t rssi) { + model::packets::LeExtendedAdvertisingPduView& pdu, uint8_t rssi) { if (!scanner_.IsEnabled()) { return; } @@ -3369,13 +3185,11 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( } std::vector advertising_data = pdu.GetAdvertisingData(); - AddressWithType advertising_address{ - pdu.GetSourceAddress(), - static_cast(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast(pdu.GetTargetAddressType())}; bool scannable_advertising = pdu.GetScannable(); bool connectable_advertising = pdu.GetConnectable(); @@ -3384,10 +3198,8 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( auto secondary_phy = pdu.GetSecondaryPhy(); // Check originating primary PHY, compare against active scanning PHYs. - if ((primary_phy == model::packets::PhyType::LE_1M && - !scanner_.le_1m_phy.enabled) || - (primary_phy == model::packets::PhyType::LE_CODED_S8 && - !scanner_.le_coded_phy.enabled)) { + if ((primary_phy == model::packets::PhyType::LE_1M && !scanner_.le_1m_phy.enabled) || + (primary_phy == model::packets::PhyType::LE_CODED_S8 && !scanner_.le_coded_phy.enabled)) { DEBUG(id_, "Extended adverising ignored because the scanner is not scanning on " "the primary phy type {}", @@ -3399,14 +3211,11 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( // supported features. The primary PHY is validated by the command // LE Set Extended Scan Parameters. if ((secondary_phy == model::packets::PhyType::LE_2M && - !properties_.SupportsLLFeature( - bluetooth::hci::LLFeaturesBits::LE_2M_PHY)) || + !properties_.SupportsLLFeature(bluetooth::hci::LLFeaturesBits::LE_2M_PHY)) || (secondary_phy == model::packets::PhyType::LE_CODED_S8 && - !properties_.SupportsLLFeature( - bluetooth::hci::LLFeaturesBits::LE_CODED_PHY)) || + !properties_.SupportsLLFeature(bluetooth::hci::LLFeaturesBits::LE_CODED_PHY)) || (secondary_phy == model::packets::PhyType::LE_CODED_S2 && - !properties_.SupportsLLFeature( - bluetooth::hci::LLFeaturesBits::LE_CODED_PHY))) { + !properties_.SupportsLLFeature(bluetooth::hci::LLFeaturesBits::LE_CODED_PHY))) { DEBUG(id_, "Extended adverising ignored because the scanner does not support " "the secondary phy type {}", @@ -3420,14 +3229,13 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( // address. The scanner’s filter policy shall then determine if the scanner // responds with a scan request. AddressWithType resolved_advertising_address = - ResolvePrivateAddress(advertising_address).value_or(advertising_address); + ResolvePrivateAddress(advertising_address).value_or(advertising_address); if (resolved_advertising_address != advertising_address) { DEBUG(id_, "Resolved the advertising address {} to {}", advertising_address, bluetooth::hci::AddressTypeText(advertising_address.GetAddressType()), resolved_advertising_address, - bluetooth::hci::AddressTypeText( - resolved_advertising_address.GetAddressType())); + bluetooth::hci::AddressTypeText(resolved_advertising_address.GetAddressType())); } // Vol 6, Part B § 4.3.3 Scanner filter policy @@ -3436,8 +3244,7 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( case bluetooth::hci::LeScanningFilterPolicy::CHECK_INITIATORS_IDENTITY: break; case bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY: - case bluetooth::hci::LeScanningFilterPolicy:: - FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: + case bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: if (!LeFilterAcceptListContainsDevice(resolved_advertising_address)) { DEBUG(id_, "Extended advertising ignored by scanner because the advertising " @@ -3471,10 +3278,8 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( // • the TargetA field is identical to the scanner's device address, or // • the TargetA field is a resolvable private address. case bluetooth::hci::LeScanningFilterPolicy::CHECK_INITIATORS_IDENTITY: - case bluetooth::hci::LeScanningFilterPolicy:: - FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: - if (!IsLocalPublicOrRandomAddress(target_address) && - !target_address.IsRpa()) { + case bluetooth::hci::LeScanningFilterPolicy::FILTER_ACCEPT_LIST_AND_INITIATORS_IDENTITY: + if (!IsLocalPublicOrRandomAddress(target_address) && !target_address.IsRpa()) { DEBUG(id_, "Extended advertising ignored by scanner because the directed " "address {} does not match the current device or is not a " @@ -3487,8 +3292,7 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( } bool should_send_advertising_report = true; - if (scanner_.filter_duplicates != - bluetooth::hci::FilterDuplicates::DISABLED) { + if (scanner_.filter_duplicates != bluetooth::hci::FilterDuplicates::DISABLED) { if (scanner_.IsPacketInHistory(pdu.bytes())) { should_send_advertising_report = false; } else { @@ -3497,7 +3301,7 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( } if (should_send_advertising_report && - IsLeEventUnmasked(SubeventCode::EXTENDED_ADVERTISING_REPORT)) { + IsLeEventUnmasked(SubeventCode::LE_EXTENDED_ADVERTISING_REPORT)) { bluetooth::hci::LeExtendedAdvertisingResponse response; response.connectable_ = connectable_advertising; response.scannable_ = scannable_advertising; @@ -3505,27 +3309,22 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( response.scan_response_ = false; response.legacy_ = false; response.data_status_ = bluetooth::hci::DataStatus::COMPLETE; - response.address_type_ = - static_cast( + response.address_type_ = static_cast( resolved_advertising_address.GetAddressType()); response.address_ = resolved_advertising_address.GetAddress(); - response.primary_phy_ = - static_cast(primary_phy); - response.secondary_phy_ = - static_cast(secondary_phy); + response.primary_phy_ = static_cast(primary_phy); + response.secondary_phy_ = static_cast(secondary_phy); response.advertising_sid_ = pdu.GetSid(); response.tx_power_ = pdu.GetTxPower(); response.rssi_ = rssi; - response.periodic_advertising_interval_ = - pdu.GetPeriodicAdvertisingInterval(); + response.periodic_advertising_interval_ = pdu.GetPeriodicAdvertisingInterval(); if (directed_advertising) { response.direct_address_type_ = - bluetooth::hci::DirectAdvertisingAddressType( - target_address.GetAddressType()); + bluetooth::hci::DirectAdvertisingAddressType(target_address.GetAddressType()); response.direct_address_ = target_address.GetAddress(); } else { response.direct_address_type_ = - bluetooth::hci::DirectAdvertisingAddressType::NO_ADDRESS_PROVIDED; + bluetooth::hci::DirectAdvertisingAddressType::NO_ADDRESS_PROVIDED; response.direct_address_ = Address::kEmpty; } response.advertising_data_ = advertising_data; @@ -3539,23 +3338,20 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( size_t remaining_size = advertising_data.size() - offset; size_t fragment_size = std::min(max_fragment_size, remaining_size); response.data_status_ = remaining_size <= max_fragment_size - ? bluetooth::hci::DataStatus::COMPLETE - : bluetooth::hci::DataStatus::CONTINUING; - response.advertising_data_ = - std::vector(advertising_data.begin() + offset, - advertising_data.begin() + offset + fragment_size); + ? bluetooth::hci::DataStatus::COMPLETE + : bluetooth::hci::DataStatus::CONTINUING; + response.advertising_data_ = std::vector(advertising_data.begin() + offset, + advertising_data.begin() + offset + fragment_size); offset += fragment_size; - send_event_(bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create( - {response})); + send_event_(bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create({response})); } while (offset < advertising_data.size()); } // Did the user enable Active scanning ? - bool active_scanning = - (scanner_.le_1m_phy.enabled && - scanner_.le_1m_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE) || - (scanner_.le_coded_phy.enabled && - scanner_.le_coded_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE); + bool active_scanning = (scanner_.le_1m_phy.enabled && + scanner_.le_1m_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE) || + (scanner_.le_coded_phy.enabled && + scanner_.le_coded_phy.scan_type == bluetooth::hci::LeScanType::ACTIVE); // Active scanning. // Note: only send SCAN requests in response to scannable advertising @@ -3585,13 +3381,10 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( // Scan requests with public or random device addresses must be ignored // when the peer has network privacy mode. - AddressWithType public_address{address_, - AddressType::PUBLIC_DEVICE_ADDRESS}; - AddressWithType random_address{random_address_, - AddressType::RANDOM_DEVICE_ADDRESS}; + AddressWithType public_address{address_, AddressType::PUBLIC_DEVICE_ADDRESS}; + AddressWithType random_address{random_address_, AddressType::RANDOM_DEVICE_ADDRESS}; std::optional resolvable_address = - GenerateResolvablePrivateAddress(resolved_advertising_address, - IrkSelection::Local); + GenerateResolvablePrivateAddress(resolved_advertising_address, IrkSelection::Local); // The ScanA field of the scanning PDU is generated using the // Resolving List’s Local IRK value and the Resolvable Private Address @@ -3637,16 +3430,14 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( // shall be the same as the advertiser’s device address (AdvA field) // received in the advertising PDU to which the scanner is responding. SendLeLinkLayerPacket(model::packets::LeScanBuilder::Create( - scanning_address.GetAddress(), advertising_address.GetAddress(), - static_cast( - scanning_address.GetAddressType()), - static_cast( - advertising_address.GetAddressType()))); + scanning_address.GetAddress(), advertising_address.GetAddress(), + static_cast(scanning_address.GetAddressType()), + static_cast(advertising_address.GetAddressType()))); } } void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( - model::packets::LeExtendedAdvertisingPduView& pdu) { + model::packets::LeExtendedAdvertisingPduView& pdu) { if (!initiator_.IsEnabled()) { return; } @@ -3665,23 +3456,20 @@ void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( return; } if (initiator_.pending_connect_request) { - DEBUG( - id_, - "Extended advertising ignored because an LE Connect request is already " - "pending"); + DEBUG(id_, + "Extended advertising ignored because an LE Connect request is already " + "pending"); return; } - AddressWithType advertising_address{ - pdu.GetSourceAddress(), - static_cast(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast(pdu.GetTargetAddressType())}; AddressWithType resolved_advertising_address = - ResolvePrivateAddress(advertising_address).value_or(advertising_address); + ResolvePrivateAddress(advertising_address).value_or(advertising_address); // Vol 6, Part B § 4.3.5 Initiator filter policy. switch (initiator_.initiator_filter_policy) { @@ -3694,7 +3482,7 @@ void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( return; } break; - case bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST: + case bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST_WITH_PEER_ADDRESS: if (!LeFilterAcceptListContainsDevice(resolved_advertising_address)) { DEBUG(id_, "Extended advertising ignored by initiator because the " @@ -3703,6 +3491,12 @@ void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( return; } break; + case bluetooth::hci::InitiatorFilterPolicy::USE_DECISION_PDUS: + case bluetooth::hci::InitiatorFilterPolicy::USE_FILTER_ACCEPT_LIST_WITH_DECISION_PDUS: + DEBUG(id_, + "Extended advertising ignored by initiator because the " + "initiator filter policy is not supported"); + return; } // When an initiator receives a directed connectable advertising event that @@ -3722,10 +3516,8 @@ void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( return; } if (!target_address.IsRpa() && - (initiator_.own_address_type == - OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS || - initiator_.own_address_type == - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS)) { + (initiator_.own_address_type == OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS || + initiator_.own_address_type == OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS)) { DEBUG(id_, "Directed extended advertising ignored by initiator because the " "target address {} is static or public and the initiator is " @@ -3736,11 +3528,9 @@ void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( } AddressWithType public_address{address_, AddressType::PUBLIC_DEVICE_ADDRESS}; - AddressWithType random_address{random_address_, - AddressType::RANDOM_DEVICE_ADDRESS}; + AddressWithType random_address{random_address_, AddressType::RANDOM_DEVICE_ADDRESS}; std::optional resolvable_initiating_address = - GenerateResolvablePrivateAddress(resolved_advertising_address, - IrkSelection::Local); + GenerateResolvablePrivateAddress(resolved_advertising_address, IrkSelection::Local); // The Link Layer shall use resolvable private addresses for the initiator’s // device address (InitA field) when initiating connection establishment with @@ -3757,26 +3547,22 @@ void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( initiating_address = random_address; break; case bluetooth::hci::OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS: - initiating_address = - resolvable_initiating_address.value_or(public_address); + initiating_address = resolvable_initiating_address.value_or(public_address); break; case bluetooth::hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS: // The random address is checked in Le_Create_Connection or // Le_Extended_Create_Connection. ASSERT(random_address_ != Address::kEmpty); - initiating_address = - resolvable_initiating_address.value_or(random_address); + initiating_address = resolvable_initiating_address.value_or(random_address); break; } - if (!connections_.CreatePendingLeConnection( - advertising_address, - resolved_advertising_address != advertising_address - ? resolved_advertising_address - : AddressWithType{}, - initiating_address)) { - WARNING(id_, "CreatePendingLeConnection failed for connection to {}", - advertising_address); + if (!connections_.CreatePendingLeConnection(advertising_address, + resolved_advertising_address != advertising_address + ? resolved_advertising_address + : AddressWithType{}, + initiating_address)) { + WARNING(id_, "CreatePendingLeConnection failed for connection to {}", advertising_address); } initiator_.pending_connect_request = advertising_address; @@ -3790,20 +3576,17 @@ void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( // received in the advertising event PDU to which the initiator is // responding. SendLeLinkLayerPacket(model::packets::LeConnectBuilder::Create( - initiating_address.GetAddress(), advertising_address.GetAddress(), - static_cast( - initiating_address.GetAddressType()), - static_cast( - advertising_address.GetAddressType()), - // The connection is created with the highest allowed value - // for the connection interval and the latency. - initiator_.le_1m_phy.connection_interval_max, - initiator_.le_1m_phy.max_latency, - initiator_.le_1m_phy.supervision_timeout)); + initiating_address.GetAddress(), advertising_address.GetAddress(), + static_cast(initiating_address.GetAddressType()), + static_cast(advertising_address.GetAddressType()), + // The connection is created with the highest allowed value + // for the connection interval and the latency. + initiator_.le_1m_phy.connection_interval_max, initiator_.le_1m_phy.max_latency, + initiator_.le_1m_phy.supervision_timeout)); } void LinkLayerController::IncomingLeExtendedAdvertisingPdu( - model::packets::LinkLayerPacketView incoming, uint8_t rssi) { + model::packets::LinkLayerPacketView incoming, uint8_t rssi) { auto pdu = model::packets::LeExtendedAdvertisingPduView::Create(incoming); ASSERT(pdu.IsValid()); @@ -3812,7 +3595,7 @@ void LinkLayerController::IncomingLeExtendedAdvertisingPdu( } void LinkLayerController::IncomingLePeriodicAdvertisingPdu( - model::packets::LinkLayerPacketView incoming, uint8_t rssi) { + model::packets::LinkLayerPacketView incoming, uint8_t rssi) { auto pdu = model::packets::LePeriodicAdvertisingPduView::Create(incoming); ASSERT(pdu.IsValid()); @@ -3826,9 +3609,8 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( return; } - AddressWithType advertiser_address{ - pdu.GetSourceAddress(), - static_cast(pdu.GetAdvertisingAddressType())}; + AddressWithType advertiser_address{pdu.GetSourceAddress(), + static_cast(pdu.GetAdvertisingAddressType())}; uint8_t advertising_sid = pdu.GetSid(); // When a scanner receives an advertising packet that contains a resolvable @@ -3837,20 +3619,20 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( // address. The scanner's periodic sync establishment filter policy shall // determine if the scanner processes the advertising packet. AddressWithType resolved_advertiser_address = - ResolvePrivateAddress(advertiser_address).value_or(advertiser_address); + ResolvePrivateAddress(advertiser_address).value_or(advertiser_address); bluetooth::hci::AdvertiserAddressType advertiser_address_type; switch (resolved_advertiser_address.GetAddressType()) { case AddressType::PUBLIC_DEVICE_ADDRESS: case AddressType::PUBLIC_IDENTITY_ADDRESS: default: - advertiser_address_type = bluetooth::hci::AdvertiserAddressType:: - PUBLIC_DEVICE_OR_IDENTITY_ADDRESS; + advertiser_address_type = + bluetooth::hci::AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS; break; case AddressType::RANDOM_DEVICE_ADDRESS: case AddressType::RANDOM_IDENTITY_ADDRESS: - advertiser_address_type = bluetooth::hci::AdvertiserAddressType:: - RANDOM_DEVICE_OR_IDENTITY_ADDRESS; + advertiser_address_type = + bluetooth::hci::AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS; break; } @@ -3861,24 +3643,21 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( bool matches_synchronizing = false; if (synchronizing_.has_value()) { matches_synchronizing = - synchronizing_->options.use_periodic_advertiser_list_ - ? LePeriodicAdvertiserListContainsDevice( - advertiser_address_type, - resolved_advertiser_address.GetAddress(), advertising_sid) - : synchronizing_->advertiser_address_type == - advertiser_address_type && - synchronizing_->advertiser_address == - resolved_advertiser_address.GetAddress() && - synchronizing_->advertising_sid == advertising_sid; + synchronizing_->options.use_periodic_advertiser_list_ + ? LePeriodicAdvertiserListContainsDevice( + advertiser_address_type, resolved_advertiser_address.GetAddress(), + advertising_sid) + : synchronizing_->advertiser_address_type == advertiser_address_type && + synchronizing_->advertiser_address == + resolved_advertiser_address.GetAddress() && + synchronizing_->advertising_sid == advertising_sid; } // If the periodic advertising event matches the synchronizing state, // create the synchronized train and report to the Host. if (matches_synchronizing) { - INFO(id_, "Established Sync with advertiser {}[{}] - SID 0x{:x}", - advertiser_address, - bluetooth::hci::AdvertiserAddressTypeText(advertiser_address_type), - advertising_sid); + INFO(id_, "Established Sync with advertiser {}[{}] - SID 0x{:x}", advertiser_address, + bluetooth::hci::AdvertiserAddressTypeText(advertiser_address_type), advertising_sid); // Use the first unused Sync_Handle. // Note: sync handles are allocated from a different number space // compared to connection handles. @@ -3887,30 +3666,25 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( } // Notify of the new Synchronized train. - if (IsLeEventUnmasked( - SubeventCode::PERIODIC_ADVERTISING_SYNC_ESTABLISHED)) { - send_event_( - bluetooth::hci::LePeriodicAdvertisingSyncEstablishedBuilder::Create( + if (IsLeEventUnmasked(SubeventCode::LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_V1)) { + send_event_(bluetooth::hci::LePeriodicAdvertisingSyncEstablishedV1Builder::Create( ErrorCode::SUCCESS, sync_handle, advertising_sid, resolved_advertiser_address.GetAddressType(), - resolved_advertiser_address.GetAddress(), - bluetooth::hci::SecondaryPhyType::LE_1M, - pdu.GetAdvertisingInterval(), - bluetooth::hci::ClockAccuracy::PPM_500)); + resolved_advertiser_address.GetAddress(), bluetooth::hci::SecondaryPhyType::LE_1M, + pdu.GetAdvertisingInterval(), bluetooth::hci::ClockAccuracy::PPM_500)); } // Update the synchronization state. synchronized_.insert( - {sync_handle, - Synchronized{ - .advertiser_address_type = advertiser_address_type, - .advertiser_address = resolved_advertiser_address.GetAddress(), - .advertising_sid = advertising_sid, - .sync_handle = sync_handle, - .sync_timeout = synchronizing_->sync_timeout, - .timeout = std::chrono::steady_clock::now() + - synchronizing_->sync_timeout, - }}); + {sync_handle, + Synchronized{ + .advertiser_address_type = advertiser_address_type, + .advertiser_address = resolved_advertiser_address.GetAddress(), + .advertising_sid = advertising_sid, + .sync_handle = sync_handle, + .sync_timeout = synchronizing_->sync_timeout, + .timeout = std::chrono::steady_clock::now() + synchronizing_->sync_timeout, + }}); // Quit synchronizing state. synchronizing_ = {}; @@ -3934,7 +3708,7 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( // and refresh the timeout for sync termination. The periodic // advertising event might need to be fragmented to fit the maximum // size of an HCI event. - if (IsLeEventUnmasked(SubeventCode::PERIODIC_ADVERTISING_REPORT)) { + if (IsLeEventUnmasked(SubeventCode::LE_PERIODIC_ADVERTISING_REPORT_V1)) { // Each extended advertising report can only pass 229 bytes of // advertising data (255 - 8 = size of report fields). std::vector advertising_data = pdu.GetAdvertisingData(); @@ -3944,18 +3718,15 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( size_t remaining_size = advertising_data.size() - offset; size_t fragment_size = std::min(max_fragment_size, remaining_size); - bluetooth::hci::DataStatus data_status = - remaining_size <= max_fragment_size - ? bluetooth::hci::DataStatus::COMPLETE - : bluetooth::hci::DataStatus::CONTINUING; - std::vector fragment_data( - advertising_data.begin() + offset, - advertising_data.begin() + offset + fragment_size); + bluetooth::hci::DataStatus data_status = remaining_size <= max_fragment_size + ? bluetooth::hci::DataStatus::COMPLETE + : bluetooth::hci::DataStatus::CONTINUING; + std::vector fragment_data(advertising_data.begin() + offset, + advertising_data.begin() + offset + fragment_size); offset += fragment_size; - send_event_(bluetooth::hci::LePeriodicAdvertisingReportBuilder::Create( - sync.sync_handle, pdu.GetTxPower(), rssi, - bluetooth::hci::CteType::NO_CONSTANT_TONE_EXTENSION, data_status, - fragment_data)); + send_event_(bluetooth::hci::LePeriodicAdvertisingReportV1Builder::Create( + sync.sync_handle, pdu.GetTxPower(), rssi, + bluetooth::hci::CteType::NO_CONSTANT_TONE_EXTENSION, data_status, fragment_data)); } while (offset < advertising_data.size()); } @@ -3965,7 +3736,7 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( } void LinkLayerController::IncomingScoConnectionRequest( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { Address address = incoming.GetSourceAddress(); auto request = model::packets::ScoConnectionRequestView::Create(incoming); ASSERT(request.IsValid()); @@ -3981,34 +3752,32 @@ void LinkLayerController::IncomingScoConnectionRequest( address); SendLinkLayerPacket(model::packets::ScoConnectionResponseBuilder::Create( - GetAddress(), address, - (uint8_t)ErrorCode::SYNCHRONOUS_CONNECTION_LIMIT_EXCEEDED, 0, 0, 0, 0, - 0, 0)); + GetAddress(), address, (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, - ScoDatapath::NORMAL); + connections_.CreateScoConnection(address, connection_parameters, + extended ? ScoState::SCO_STATE_SENT_ESCO_CONNECTION_REQUEST + : ScoState::SCO_STATE_SENT_SCO_CONNECTION_REQUEST, + ScoDatapath::NORMAL); // Send connection request event and wait for Accept or Reject command. send_event_(bluetooth::hci::ConnectionRequestBuilder::Create( - address, request.GetClassOfDevice(), - extended ? bluetooth::hci::ConnectionRequestLinkType::ESCO - : bluetooth::hci::ConnectionRequestLinkType::SCO)); + address, request.GetClassOfDevice(), + extended ? bluetooth::hci::ConnectionRequestLinkType::ESCO + : bluetooth::hci::ConnectionRequestLinkType::SCO)); } void LinkLayerController::IncomingScoConnectionResponse( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { Address address = incoming.GetSourceAddress(); auto response = model::packets::ScoConnectionResponseView::Create(incoming); ASSERT(response.IsValid()); @@ -4021,54 +3790,50 @@ 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, [this, address] { - return LinkLayerController::StartScoStream(address); - }); + connections_.AcceptPendingScoConnection(address, link_parameters, [this, address] { + return LinkLayerController::StartScoStream(address); + }); if (is_legacy) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, connections_.GetScoHandle(address), address, - bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED)); + ErrorCode::SUCCESS, connections_.GetScoHandle(address), address, + 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 ? response.GetTransmissionInterval() : 0, - extended ? response.GetRetransmissionWindow() : 0, - extended ? response.GetRxPacketLength() : 0, - extended ? response.GetTxPacketLength() : 0, - bluetooth::hci::ScoAirMode(response.GetAirMode()))); + ErrorCode::SUCCESS, connections_.GetScoHandle(address), address, + extended ? bluetooth::hci::ScoLinkType::ESCO : bluetooth::hci::ScoLinkType::SCO, + extended ? response.GetTransmissionInterval() : 0, + extended ? response.GetRetransmissionWindow() : 0, + extended ? response.GetRxPacketLength() : 0, + extended ? response.GetTxPacketLength() : 0, + bluetooth::hci::ScoAirMode(response.GetAirMode()))); } } else { connections_.CancelPendingScoConnection(address); if (is_legacy) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - status, 0, address, bluetooth::hci::LinkType::SCO, - bluetooth::hci::Enable::DISABLED)); + status, 0, address, bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED)); } else { ScoConnectionParameters connection_parameters = - connections_.GetScoConnectionParameters(address); + connections_.GetScoConnectionParameters(address); send_event_(bluetooth::hci::SynchronousConnectionCompleteBuilder::Create( - status, 0, address, - connection_parameters.IsExtended() ? bluetooth::hci::ScoLinkType::ESCO - : bluetooth::hci::ScoLinkType::SCO, - 0, 0, 0, 0, bluetooth::hci::ScoAirMode::TRANSPARENT)); + status, 0, address, + connection_parameters.IsExtended() ? bluetooth::hci::ScoLinkType::ESCO + : bluetooth::hci::ScoLinkType::SCO, + 0, 0, 0, 0, bluetooth::hci::ScoAirMode::TRANSPARENT)); } } } -void LinkLayerController::IncomingScoDisconnect( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingScoDisconnect(model::packets::LinkLayerPacketView incoming) { Address address = incoming.GetSourceAddress(); auto request = model::packets::ScoDisconnectView::Create(incoming); ASSERT(request.IsValid()); @@ -4081,27 +3846,23 @@ void LinkLayerController::IncomingScoDisconnect( static_cast(reason), incoming.GetSourceAddress()); if (handle != kReservedHandle) { - connections_.Disconnect( - handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); + connections_.Disconnect(handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); SendDisconnectionCompleteEvent(handle, ErrorCode(reason)); } } -void LinkLayerController::IncomingLmpPacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingLmpPacket(model::packets::LinkLayerPacketView incoming) { Address address = incoming.GetSourceAddress(); auto request = model::packets::LmpView::Create(incoming); ASSERT(request.IsValid()); auto payload = request.GetPayload(); auto packet = std::vector(payload.begin(), payload.end()); - ASSERT(link_manager_ingest_lmp( - lm_.get(), reinterpret_cast(address.data()), packet.data(), - packet.size())); + ASSERT(link_manager_ingest_lmp(lm_.get(), reinterpret_cast(address.data()), + packet.data(), packet.size())); } -void LinkLayerController::IncomingLlcpPacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingLlcpPacket(model::packets::LinkLayerPacketView incoming) { Address address = incoming.GetSourceAddress(); auto request = model::packets::LlcpView::Create(incoming); ASSERT(request.IsValid()); @@ -4114,12 +3875,10 @@ void LinkLayerController::IncomingLlcpPacket( return; } - ASSERT(link_layer_ingest_llcp(ll_.get(), acl_connection_handle, packet.data(), - packet.size())); + ASSERT(link_layer_ingest_llcp(ll_.get(), acl_connection_handle, packet.data(), packet.size())); } -void LinkLayerController::IncomingLeConnectedIsochronousPdu( - LinkLayerPacketView incoming) { +void LinkLayerController::IncomingLeConnectedIsochronousPdu(LinkLayerPacketView incoming) { auto pdu = model::packets::LeConnectedIsochronousPduView::Create(incoming); ASSERT(pdu.IsValid()); auto data = pdu.GetData(); @@ -4129,11 +3888,8 @@ void LinkLayerController::IncomingLeConnectedIsochronousPdu( uint16_t cis_connection_handle = 0; uint16_t iso_sdu_length = packet.size(); - if (!link_layer_get_cis_connection_handle(ll_.get(), cig_id, cis_id, - &cis_connection_handle)) { - INFO(id_, - "Dropping CIS pdu received on disconnected CIS cig_id={}, cis_id={}", - cig_id, cis_id); + if (!link_layer_get_cis_connection_handle(ll_.get(), cig_id, cis_id, &cis_connection_handle)) { + INFO(id_, "Dropping CIS pdu received on disconnected CIS cig_id={}, cis_id={}", cig_id, cis_id); return; } @@ -4142,27 +3898,23 @@ void LinkLayerController::IncomingLeConnectedIsochronousPdu( // iso_sdu_length size_t remaining_size = packet.size(); size_t offset = 0; - auto packet_boundary_flag = - remaining_size <= kMaxPayloadSize - ? bluetooth::hci::IsoPacketBoundaryFlag::COMPLETE_SDU - : bluetooth::hci::IsoPacketBoundaryFlag::FIRST_FRAGMENT; + auto packet_boundary_flag = remaining_size <= kMaxPayloadSize + ? bluetooth::hci::IsoPacketBoundaryFlag::COMPLETE_SDU + : bluetooth::hci::IsoPacketBoundaryFlag::FIRST_FRAGMENT; do { size_t fragment_size = std::min(kMaxPayloadSize, remaining_size); - std::vector fragment(packet.data() + offset, - packet.data() + offset + fragment_size); + std::vector fragment(packet.data() + offset, packet.data() + offset + fragment_size); send_iso_(bluetooth::hci::IsoWithoutTimestampBuilder::Create( - cis_connection_handle, packet_boundary_flag, pdu.GetSequenceNumber(), - iso_sdu_length, bluetooth::hci::IsoPacketStatusFlag::VALID, - std::move(fragment))); + cis_connection_handle, packet_boundary_flag, pdu.GetSequenceNumber(), iso_sdu_length, + bluetooth::hci::IsoPacketStatusFlag::VALID, std::move(fragment))); remaining_size -= fragment_size; offset += fragment_size; - packet_boundary_flag = - remaining_size <= kMaxPayloadSize - ? bluetooth::hci::IsoPacketBoundaryFlag::LAST_FRAGMENT - : bluetooth::hci::IsoPacketBoundaryFlag::CONTINUATION_FRAGMENT; + packet_boundary_flag = remaining_size <= kMaxPayloadSize + ? bluetooth::hci::IsoPacketBoundaryFlag::LAST_FRAGMENT + : bluetooth::hci::IsoPacketBoundaryFlag::CONTINUATION_FRAGMENT; } while (remaining_size > 0); } @@ -4185,8 +3937,7 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) { // The TS_Flag bit shall only be set if the PB_Flag field equals 0b00 or 0b10. if (ts_flag == bluetooth::hci::TimeStampFlag::PRESENT && - (pb_flag == - bluetooth::hci::IsoPacketBoundaryFlag::CONTINUATION_FRAGMENT || + (pb_flag == bluetooth::hci::IsoPacketBoundaryFlag::CONTINUATION_FRAGMENT || pb_flag == bluetooth::hci::IsoPacketBoundaryFlag::LAST_FRAGMENT)) { FATAL(id_, "Received ISO HCI packet with TS_Flag set, but no ISO Header is " @@ -4199,11 +3950,9 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) { uint16_t packet_sequence_number = 0; uint16_t max_sdu_length = 0; - if (!link_layer_get_cis_information(ll_.get(), cis_connection_handle, - &acl_connection_handle, &cig_id, &cis_id, - &max_sdu_length)) { - INFO(id_, "Ignoring CIS pdu received on disconnected CIS handle={}", - cis_connection_handle); + if (!link_layer_get_cis_information(ll_.get(), cis_connection_handle, &acl_connection_handle, + &cig_id, &cis_id, &max_sdu_length)) { + INFO(id_, "Ignoring CIS pdu received on disconnected CIS handle={}", cis_connection_handle); return; } @@ -4214,8 +3963,7 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) { switch (ts_flag) { case bluetooth::hci::TimeStampFlag::PRESENT: { - auto iso_with_timestamp = - bluetooth::hci::IsoWithTimestampView::Create(iso); + auto iso_with_timestamp = bluetooth::hci::IsoWithTimestampView::Create(iso); ASSERT(iso_with_timestamp.IsValid()); auto iso_payload = iso_with_timestamp.GetPayload(); iso_sdu_.insert(iso_sdu_.end(), iso_payload.begin(), iso_payload.end()); @@ -4224,8 +3972,7 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) { } default: case bluetooth::hci::TimeStampFlag::NOT_PRESENT: { - auto iso_without_timestamp = - bluetooth::hci::IsoWithoutTimestampView::Create(iso); + auto iso_without_timestamp = bluetooth::hci::IsoWithoutTimestampView::Create(iso); ASSERT(iso_without_timestamp.IsValid()); auto iso_payload = iso_without_timestamp.GetPayload(); iso_sdu_.insert(iso_sdu_.end(), iso_payload.begin(), iso_payload.end()); @@ -4239,27 +3986,23 @@ void LinkLayerController::HandleIso(bluetooth::hci::IsoView iso) { // Validate that the Host stack is not sending ISO SDUs that are larger // that what was configured for the CIS. if (iso_sdu_.size() > max_sdu_length) { - WARNING( - id_, - "attempted to send an SDU of length {} that exceeds the configure " - "Max_SDU_Length ({})", - iso_sdu_.size(), max_sdu_length); + WARNING(id_, + "attempted to send an SDU of length {} that exceeds the configure " + "Max_SDU_Length ({})", + iso_sdu_.size(), max_sdu_length); return; } - SendLeLinkLayerPacket( - model::packets::LeConnectedIsochronousPduBuilder::Create( - address_, - connections_.GetAddress(acl_connection_handle).GetAddress(), cig_id, - cis_id, packet_sequence_number, std::move(iso_sdu_))); + SendLeLinkLayerPacket(model::packets::LeConnectedIsochronousPduBuilder::Create( + address_, connections_.GetAddress(acl_connection_handle).GetAddress(), cig_id, cis_id, + packet_sequence_number, std::move(iso_sdu_))); } } uint16_t LinkLayerController::HandleLeConnection( - AddressWithType address, AddressWithType own_address, - bluetooth::hci::Role role, uint16_t connection_interval, - uint16_t connection_latency, uint16_t supervision_timeout, - bool send_le_channel_selection_algorithm_event) { + AddressWithType address, AddressWithType own_address, bluetooth::hci::Role role, + uint16_t connection_interval, uint16_t connection_latency, uint16_t supervision_timeout, + bool send_le_channel_selection_algorithm_event) { // Note: the HCI_LE_Connection_Complete event is not sent if the // HCI_LE_Enhanced_Connection_Complete event (see Section 7.7.65.10) is // unmasked. @@ -4270,9 +4013,8 @@ uint16_t LinkLayerController::HandleLeConnection( return kReservedHandle; } - if (IsLeEventUnmasked(SubeventCode::ENHANCED_CONNECTION_COMPLETE)) { - AddressWithType peer_resolved_address = - connections_.GetResolvedAddress(handle); + if (IsLeEventUnmasked(SubeventCode::LE_ENHANCED_CONNECTION_COMPLETE_V1)) { + AddressWithType peer_resolved_address = connections_.GetResolvedAddress(handle); Address peer_resolvable_private_address; Address connection_address = address.GetAddress(); AddressType peer_address_type = address.GetAddressType(); @@ -4282,38 +4024,36 @@ uint16_t LinkLayerController::HandleLeConnection( connection_address = peer_resolved_address.GetAddress(); } Address local_resolved_address = own_address.GetAddress(); - if (local_resolved_address == GetAddress() || - local_resolved_address == random_address_) { + if (local_resolved_address == GetAddress() || local_resolved_address == random_address_) { local_resolved_address = Address::kEmpty; } - send_event_(bluetooth::hci::LeEnhancedConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, handle, role, peer_address_type, connection_address, - local_resolved_address, peer_resolvable_private_address, - connection_interval, connection_latency, supervision_timeout, - static_cast(0x00))); - } else if (IsLeEventUnmasked(SubeventCode::CONNECTION_COMPLETE)) { + send_event_(bluetooth::hci::LeEnhancedConnectionCompleteV1Builder::Create( + ErrorCode::SUCCESS, handle, role, peer_address_type, connection_address, + local_resolved_address, peer_resolvable_private_address, connection_interval, + connection_latency, supervision_timeout, + static_cast(0x00))); + } else if (IsLeEventUnmasked(SubeventCode::LE_CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::LeConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, handle, role, address.GetAddressType(), - address.GetAddress(), connection_interval, connection_latency, - supervision_timeout, static_cast(0x00))); + ErrorCode::SUCCESS, handle, role, address.GetAddressType(), address.GetAddress(), + connection_interval, connection_latency, supervision_timeout, + static_cast(0x00))); } // Update the link layer with the new link. - ASSERT(link_layer_add_link( - ll_.get(), handle, - reinterpret_cast(address.GetAddress().data()), - static_cast(role))); + ASSERT(link_layer_add_link(ll_.get(), handle, + reinterpret_cast(address.GetAddress().data()), + static_cast(role))); // Note: the HCI_LE_Connection_Complete event is immediately followed by // an HCI_LE_Channel_Selection_Algorithm event if the connection is created // using the LE_Extended_Create_Connection command (see Section 7.7.8.66). if (send_le_channel_selection_algorithm_event && - IsLeEventUnmasked(SubeventCode::CHANNEL_SELECTION_ALGORITHM)) { + IsLeEventUnmasked(SubeventCode::LE_CHANNEL_SELECTION_ALGORITHM)) { // The selection channel algorithm probably will have no impact // on emulation. send_event_(bluetooth::hci::LeChannelSelectionAlgorithmBuilder::Create( - handle, bluetooth::hci::ChannelSelectionAlgorithm::ALGORITHM_1)); + handle, bluetooth::hci::ChannelSelectionAlgorithm::ALGORITHM_1)); } if (own_address.GetAddress() == initiator_.initiating_address) { @@ -4324,7 +4064,7 @@ uint16_t LinkLayerController::HandleLeConnection( // Handle CONNECT_IND PDUs for the legacy advertiser. bool LinkLayerController::ProcessIncomingLegacyConnectRequest( - model::packets::LeConnectView const& connect_ind) { + model::packets::LeConnectView const& connect_ind) { if (!legacy_advertiser_.IsEnabled()) { return false; } @@ -4336,13 +4076,13 @@ bool LinkLayerController::ProcessIncomingLegacyConnectRequest( } AddressWithType advertising_address{ - connect_ind.GetDestinationAddress(), - static_cast(connect_ind.GetAdvertisingAddressType()), + connect_ind.GetDestinationAddress(), + static_cast(connect_ind.GetAdvertisingAddressType()), }; AddressWithType initiating_address{ - connect_ind.GetSourceAddress(), - static_cast(connect_ind.GetInitiatingAddressType()), + connect_ind.GetSourceAddress(), + static_cast(connect_ind.GetInitiatingAddressType()), }; if (legacy_advertiser_.GetAdvertisingAddress() != advertising_address) { @@ -4359,7 +4099,7 @@ bool LinkLayerController::ProcessIncomingLegacyConnectRequest( // The advertising filter policy shall then determine if the // advertiser establishes a connection. AddressWithType resolved_initiating_address = - ResolvePrivateAddress(initiating_address).value_or(initiating_address); + ResolvePrivateAddress(initiating_address).value_or(initiating_address); if (resolved_initiating_address != initiating_address) { DEBUG(id_, "Resolved the initiating address {} to {}", initiating_address, @@ -4370,8 +4110,7 @@ bool LinkLayerController::ProcessIncomingLegacyConnectRequest( // advertising filter policy shall be ignored. if (legacy_advertiser_.IsDirected()) { if (resolved_initiating_address != - PeerDeviceAddress(legacy_advertiser_.peer_address, - legacy_advertiser_.peer_address_type)) { + PeerDeviceAddress(legacy_advertiser_.peer_address, legacy_advertiser_.peer_address_type)) { DEBUG(id_, "LE Connect request ignored by legacy advertiser because the " "initiating address {} does not match the target address {}[{}]", @@ -4404,30 +4143,27 @@ bool LinkLayerController::ProcessIncomingLegacyConnectRequest( "address {}", resolved_initiating_address); - if (!connections_.CreatePendingLeConnection( - initiating_address, - resolved_initiating_address != initiating_address - ? resolved_initiating_address - : AddressWithType{}, - advertising_address)) { + if (!connections_.CreatePendingLeConnection(initiating_address, + resolved_initiating_address != initiating_address + ? resolved_initiating_address + : AddressWithType{}, + advertising_address)) { WARNING(id_, "CreatePendingLeConnection failed for connection from {}", initiating_address.GetAddress()); return false; } - (void)HandleLeConnection( - initiating_address, advertising_address, bluetooth::hci::Role::PERIPHERAL, - connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), - connect_ind.GetConnSupervisionTimeout(), false); + (void)HandleLeConnection(initiating_address, advertising_address, + bluetooth::hci::Role::PERIPHERAL, connect_ind.GetConnInterval(), + connect_ind.GetConnPeripheralLatency(), + connect_ind.GetConnSupervisionTimeout(), false); SendLeLinkLayerPacket(model::packets::LeConnectCompleteBuilder::Create( - advertising_address.GetAddress(), initiating_address.GetAddress(), - static_cast( - initiating_address.GetAddressType()), - static_cast( - advertising_address.GetAddressType()), - connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), - connect_ind.GetConnSupervisionTimeout())); + advertising_address.GetAddress(), initiating_address.GetAddress(), + static_cast(initiating_address.GetAddressType()), + static_cast(advertising_address.GetAddressType()), + connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), + connect_ind.GetConnSupervisionTimeout())); legacy_advertiser_.Disable(); return true; @@ -4435,8 +4171,7 @@ bool LinkLayerController::ProcessIncomingLegacyConnectRequest( // Handle CONNECT_IND PDUs for the selected extended advertiser. bool LinkLayerController::ProcessIncomingExtendedConnectRequest( - ExtendedAdvertiser& advertiser, - model::packets::LeConnectView const& connect_ind) { + ExtendedAdvertiser& advertiser, model::packets::LeConnectView const& connect_ind) { if (!advertiser.IsEnabled()) { return false; } @@ -4449,21 +4184,20 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( } AddressWithType advertising_address{ - connect_ind.GetDestinationAddress(), - static_cast(connect_ind.GetAdvertisingAddressType()), + connect_ind.GetDestinationAddress(), + static_cast(connect_ind.GetAdvertisingAddressType()), }; AddressWithType initiating_address{ - connect_ind.GetSourceAddress(), - static_cast(connect_ind.GetInitiatingAddressType()), + connect_ind.GetSourceAddress(), + static_cast(connect_ind.GetInitiatingAddressType()), }; if (advertiser.GetAdvertisingAddress() != advertising_address) { DEBUG(id_, "LE Connect request ignored by extended advertiser {} because the " "advertising address {} does not match {}", - advertiser.advertising_handle, advertising_address, - advertiser.GetAdvertisingAddress()); + advertiser.advertising_handle, advertising_address, advertiser.GetAdvertisingAddress()); return false; } @@ -4473,7 +4207,7 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( // The advertising filter policy shall then determine if the // advertiser establishes a connection. AddressWithType resolved_initiating_address = - ResolvePrivateAddress(initiating_address).value_or(initiating_address); + ResolvePrivateAddress(initiating_address).value_or(initiating_address); if (resolved_initiating_address != initiating_address) { DEBUG(id_, "Resolved the initiating address {} to {}", initiating_address, @@ -4484,13 +4218,11 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( // advertising filter policy shall be ignored. if (advertiser.IsDirected()) { if (resolved_initiating_address != - PeerDeviceAddress(advertiser.peer_address, - advertiser.peer_address_type)) { + PeerDeviceAddress(advertiser.peer_address, advertiser.peer_address_type)) { DEBUG(id_, "LE Connect request ignored by extended advertiser {} because the " "initiating address {} does not match the target address {}[{}]", - advertiser.advertising_handle, resolved_initiating_address, - advertiser.peer_address, + advertiser.advertising_handle, resolved_initiating_address, advertiser.peer_address, PeerAddressTypeText(advertiser.peer_address_type)); return false; } @@ -4519,12 +4251,11 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( "address {}", advertiser.advertising_handle, resolved_initiating_address); - if (!connections_.CreatePendingLeConnection( - initiating_address, - resolved_initiating_address != initiating_address - ? resolved_initiating_address - : AddressWithType{}, - advertising_address)) { + if (!connections_.CreatePendingLeConnection(initiating_address, + resolved_initiating_address != initiating_address + ? resolved_initiating_address + : AddressWithType{}, + advertising_address)) { WARNING(id_, "CreatePendingLeConnection failed for connection from {}", initiating_address.GetAddress()); return false; @@ -4533,18 +4264,16 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( advertiser.Disable(); uint16_t connection_handle = HandleLeConnection( - initiating_address, advertising_address, bluetooth::hci::Role::PERIPHERAL, - connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), - connect_ind.GetConnSupervisionTimeout(), false); + initiating_address, advertising_address, bluetooth::hci::Role::PERIPHERAL, + connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), + connect_ind.GetConnSupervisionTimeout(), false); SendLeLinkLayerPacket(model::packets::LeConnectCompleteBuilder::Create( - advertising_address.GetAddress(), initiating_address.GetAddress(), - static_cast( - initiating_address.GetAddressType()), - static_cast( - advertising_address.GetAddressType()), - connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), - connect_ind.GetConnSupervisionTimeout())); + advertising_address.GetAddress(), initiating_address.GetAddress(), + static_cast(initiating_address.GetAddressType()), + static_cast(advertising_address.GetAddressType()), + connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), + connect_ind.GetConnSupervisionTimeout())); // If the advertising set is connectable and a connection gets created, an // HCI_LE_Connection_Complete or HCI_LE_Enhanced_Connection_Complete @@ -4552,19 +4281,17 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( // event with the Status parameter set to 0x00. The Controller should not send // any other events in between these two events - if (IsLeEventUnmasked(SubeventCode::ADVERTISING_SET_TERMINATED)) { + if (IsLeEventUnmasked(SubeventCode::LE_ADVERTISING_SET_TERMINATED)) { send_event_(bluetooth::hci::LeAdvertisingSetTerminatedBuilder::Create( - ErrorCode::SUCCESS, advertiser.advertising_handle, connection_handle, - advertiser.num_completed_extended_advertising_events)); + ErrorCode::SUCCESS, advertiser.advertising_handle, connection_handle, + advertiser.num_completed_extended_advertising_events)); } return true; } -void LinkLayerController::IncomingLeConnectPacket( - model::packets::LinkLayerPacketView incoming) { - model::packets::LeConnectView connect = - model::packets::LeConnectView::Create(incoming); +void LinkLayerController::IncomingLeConnectPacket(model::packets::LinkLayerPacketView incoming) { + model::packets::LeConnectView connect = model::packets::LeConnectView::Create(incoming); ASSERT(connect.IsValid()); if (ProcessIncomingLegacyConnectRequest(connect)) { @@ -4579,13 +4306,13 @@ void LinkLayerController::IncomingLeConnectPacket( } void LinkLayerController::IncomingLeConnectCompletePacket( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { auto complete = model::packets::LeConnectCompleteView::Create(incoming); ASSERT(complete.IsValid()); AddressWithType advertising_address{ - incoming.GetSourceAddress(), static_cast( - complete.GetAdvertisingAddressType())}; + incoming.GetSourceAddress(), + static_cast(complete.GetAdvertisingAddressType())}; INFO(id_, "Received LE Connect complete response with advertising address {}", advertising_address); @@ -4593,10 +4320,9 @@ void LinkLayerController::IncomingLeConnectCompletePacket( HandleLeConnection(advertising_address, AddressWithType(incoming.GetDestinationAddress(), static_cast( - complete.GetInitiatingAddressType())), + complete.GetInitiatingAddressType())), bluetooth::hci::Role::CENTRAL, complete.GetConnInterval(), - complete.GetConnPeripheralLatency(), - complete.GetConnSupervisionTimeout(), + complete.GetConnPeripheralLatency(), complete.GetConnSupervisionTimeout(), ExtendedAdvertising()); initiator_.pending_connect_request = {}; @@ -4604,63 +4330,55 @@ void LinkLayerController::IncomingLeConnectCompletePacket( } void LinkLayerController::IncomingLeConnectionParameterRequest( - model::packets::LinkLayerPacketView incoming) { - auto request = - model::packets::LeConnectionParameterRequestView::Create(incoming); + model::packets::LinkLayerPacketView incoming) { + auto request = model::packets::LeConnectionParameterRequestView::Create(incoming); ASSERT(request.IsValid()); Address peer = incoming.GetSourceAddress(); uint16_t handle = connections_.GetHandleOnlyAddress(peer); if (handle == kReservedHandle) { - INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), - peer); + INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), peer); return; } - if (IsLeEventUnmasked(SubeventCode::REMOTE_CONNECTION_PARAMETER_REQUEST)) { - send_event_( - bluetooth::hci::LeRemoteConnectionParameterRequestBuilder::Create( - handle, request.GetIntervalMin(), request.GetIntervalMax(), - request.GetLatency(), request.GetTimeout())); + if (IsLeEventUnmasked(SubeventCode::LE_REMOTE_CONNECTION_PARAMETER_REQUEST)) { + send_event_(bluetooth::hci::LeRemoteConnectionParameterRequestBuilder::Create( + handle, request.GetIntervalMin(), request.GetIntervalMax(), request.GetLatency(), + request.GetTimeout())); } else { // If the request is being indicated to the Host and the event to the Host // is masked, then the Link Layer shall issue an LL_REJECT_EXT_IND PDU with // the ErrorCode set to Unsupported Remote Feature (0x1A). - SendLeLinkLayerPacket( - model::packets::LeConnectionParameterUpdateBuilder::Create( + SendLeLinkLayerPacket(model::packets::LeConnectionParameterUpdateBuilder::Create( request.GetDestinationAddress(), request.GetSourceAddress(), - static_cast(ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE), - 0, 0, 0)); + static_cast(ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE), 0, 0, 0)); } } void LinkLayerController::IncomingLeConnectionParameterUpdate( - model::packets::LinkLayerPacketView incoming) { - auto update = - model::packets::LeConnectionParameterUpdateView::Create(incoming); + model::packets::LinkLayerPacketView incoming) { + auto update = model::packets::LeConnectionParameterUpdateView::Create(incoming); ASSERT(update.IsValid()); Address peer = incoming.GetSourceAddress(); uint16_t handle = connections_.GetHandleOnlyAddress(peer); if (handle == kReservedHandle) { - INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), - peer); + INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), peer); return; } - if (IsLeEventUnmasked(SubeventCode::CONNECTION_UPDATE_COMPLETE)) { + if (IsLeEventUnmasked(SubeventCode::LE_CONNECTION_UPDATE_COMPLETE)) { send_event_(bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create( - static_cast(update.GetStatus()), handle, - update.GetInterval(), update.GetLatency(), update.GetTimeout())); + static_cast(update.GetStatus()), handle, update.GetInterval(), + update.GetLatency(), update.GetTimeout())); } } void LinkLayerController::IncomingLeEncryptConnection( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { INFO(id_, "IncomingLeEncryptConnection"); Address peer = incoming.GetSourceAddress(); uint16_t handle = connections_.GetHandleOnlyAddress(peer); if (handle == kReservedHandle) { - INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), - peer); + INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), peer); return; } auto le_encrypt = model::packets::LeEncryptConnectionView::Create(incoming); @@ -4669,25 +4387,23 @@ void LinkLayerController::IncomingLeEncryptConnection( // TODO: Save keys to check if (IsEventUnmasked(EventCode::LE_META_EVENT)) { - send_event_(bluetooth::hci::LeLongTermKeyRequestBuilder::Create( - handle, le_encrypt.GetRand(), le_encrypt.GetEdiv())); + send_event_(bluetooth::hci::LeLongTermKeyRequestBuilder::Create(handle, le_encrypt.GetRand(), + le_encrypt.GetEdiv())); } } void LinkLayerController::IncomingLeEncryptConnectionResponse( - model::packets::LinkLayerPacketView incoming) { + model::packets::LinkLayerPacketView incoming) { INFO(id_, "IncomingLeEncryptConnectionResponse"); // TODO: Check keys - uint16_t handle = - connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); + uint16_t handle = connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); if (handle == kReservedHandle) { INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), incoming.GetSourceAddress()); return; } ErrorCode status = ErrorCode::SUCCESS; - auto response = - model::packets::LeEncryptConnectionResponseView::Create(incoming); + auto response = model::packets::LeEncryptConnectionResponseView::Create(incoming); ASSERT(response.IsValid()); bool success = true; @@ -4699,45 +4415,40 @@ void LinkLayerController::IncomingLeEncryptConnectionResponse( if (connections_.IsEncrypted(handle)) { if (IsEventUnmasked(EventCode::ENCRYPTION_KEY_REFRESH_COMPLETE)) { - send_event_(bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create( - status, handle)); + send_event_(bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create(status, handle)); } } else if (success) { connections_.Encrypt(handle); if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE)) { send_event_(bluetooth::hci::EncryptionChangeBuilder::Create( - status, handle, bluetooth::hci::EncryptionEnabled::ON)); + status, handle, bluetooth::hci::EncryptionEnabled::ON)); } } else { if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE)) { send_event_(bluetooth::hci::EncryptionChangeBuilder::Create( - status, handle, bluetooth::hci::EncryptionEnabled::OFF)); + status, handle, bluetooth::hci::EncryptionEnabled::OFF)); } } } void LinkLayerController::IncomingLeReadRemoteFeatures( - model::packets::LinkLayerPacketView incoming) { - uint16_t handle = - connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); + model::packets::LinkLayerPacketView incoming) { + uint16_t handle = connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); ErrorCode status = ErrorCode::SUCCESS; if (handle == kReservedHandle) { - WARNING(id_, "@{}: Unknown connection @{}", - incoming.GetDestinationAddress(), incoming.GetSourceAddress()); + WARNING(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), + incoming.GetSourceAddress()); } - SendLeLinkLayerPacket( - model::packets::LeReadRemoteFeaturesResponseBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress(), - GetLeSupportedFeatures(), static_cast(status))); + SendLeLinkLayerPacket(model::packets::LeReadRemoteFeaturesResponseBuilder::Create( + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), GetLeSupportedFeatures(), + static_cast(status))); } void LinkLayerController::IncomingLeReadRemoteFeaturesResponse( - model::packets::LinkLayerPacketView incoming) { - uint16_t handle = - connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); + model::packets::LinkLayerPacketView incoming) { + uint16_t handle = connections_.GetHandleOnlyAddress(incoming.GetSourceAddress()); ErrorCode status = ErrorCode::SUCCESS; - auto response = - model::packets::LeReadRemoteFeaturesResponseView::Create(incoming); + auto response = model::packets::LeReadRemoteFeaturesResponseView::Create(incoming); ASSERT(response.IsValid()); if (handle == kReservedHandle) { INFO(id_, "@{}: Unknown connection @{}", incoming.GetDestinationAddress(), @@ -4747,14 +4458,14 @@ void LinkLayerController::IncomingLeReadRemoteFeaturesResponse( status = static_cast(response.GetStatus()); } if (IsEventUnmasked(EventCode::LE_META_EVENT)) { - send_event_(bluetooth::hci::LeReadRemoteFeaturesCompleteBuilder::Create( - status, handle, response.GetFeatures())); + send_event_(bluetooth::hci::LeReadRemoteFeaturesPage0CompleteBuilder::Create( + status, handle, response.GetFeatures())); } } void LinkLayerController::ProcessIncomingLegacyScanRequest( - AddressWithType scanning_address, AddressWithType resolved_scanning_address, - AddressWithType advertising_address) { + AddressWithType scanning_address, AddressWithType resolved_scanning_address, + AddressWithType advertising_address) { // Check if the advertising addresses matches the legacy // advertising address. if (!legacy_advertiser_.IsEnabled()) { @@ -4768,11 +4479,10 @@ void LinkLayerController::ProcessIncomingLegacyScanRequest( } if (advertising_address != legacy_advertiser_.advertising_address) { - DEBUG( - id_, - "LE Scan request ignored by legacy advertiser because the advertising " - "address {} does not match {}", - advertising_address, legacy_advertiser_.GetAdvertisingAddress()); + DEBUG(id_, + "LE Scan request ignored by legacy advertiser because the advertising " + "address {} does not match {}", + advertising_address, legacy_advertiser_.GetAdvertisingAddress()); return; } @@ -4785,11 +4495,10 @@ void LinkLayerController::ProcessIncomingLegacyScanRequest( case bluetooth::hci::AdvertisingFilterPolicy::LISTED_SCAN: case bluetooth::hci::AdvertisingFilterPolicy::LISTED_SCAN_AND_CONNECT: if (!LeFilterAcceptListContainsDevice(resolved_scanning_address)) { - DEBUG( - id_, - "LE Scan request ignored by legacy advertiser because the scanning " - "address {} is not in the filter accept list", - resolved_scanning_address); + DEBUG(id_, + "LE Scan request ignored by legacy advertiser because the scanning " + "address {} is not in the filter accept list", + resolved_scanning_address); return; } break; @@ -4806,18 +4515,16 @@ void LinkLayerController::ProcessIncomingLegacyScanRequest( // the advertiser’s device address (AdvA field) in the SCAN_REQ PDU to // which it is responding. SendLeLinkLayerPacket( - model::packets::LeScanResponseBuilder::Create( - advertising_address.GetAddress(), scanning_address.GetAddress(), - static_cast( - advertising_address.GetAddressType()), - legacy_advertiser_.scan_response_data), - properties_.le_advertising_physical_channel_tx_power); + model::packets::LeScanResponseBuilder::Create( + advertising_address.GetAddress(), scanning_address.GetAddress(), + static_cast(advertising_address.GetAddressType()), + legacy_advertiser_.scan_response_data), + properties_.le_advertising_physical_channel_tx_power); } void LinkLayerController::ProcessIncomingExtendedScanRequest( - ExtendedAdvertiser const& advertiser, AddressWithType scanning_address, - AddressWithType resolved_scanning_address, - AddressWithType advertising_address) { + ExtendedAdvertiser const& advertiser, AddressWithType scanning_address, + AddressWithType resolved_scanning_address, AddressWithType advertising_address) { // Check if the advertising addresses matches the legacy // advertising address. if (!advertiser.IsEnabled()) { @@ -4835,8 +4542,7 @@ void LinkLayerController::ProcessIncomingExtendedScanRequest( DEBUG(id_, "LE Scan request ignored by extended advertiser {} because the " "advertising address {} does not match {}", - advertiser.advertising_handle, advertising_address, - advertiser.GetAdvertisingAddress()); + advertiser.advertising_handle, advertising_address, advertiser.GetAdvertisingAddress()); return; } @@ -4860,13 +4566,11 @@ void LinkLayerController::ProcessIncomingExtendedScanRequest( // Check if the scanner address is the target address in the case of // scannable directed event types. - if (advertiser.IsDirected() && - advertiser.target_address != resolved_scanning_address) { + if (advertiser.IsDirected() && advertiser.target_address != resolved_scanning_address) { DEBUG(id_, "LE Scan request ignored by extended advertiser {} because the " "scanning address {} does not match the target address {}", - advertiser.advertising_handle, resolved_scanning_address, - advertiser.GetTargetAddress()); + advertiser.advertising_handle, resolved_scanning_address, advertiser.GetTargetAddress()); return; } @@ -4881,26 +4585,23 @@ void LinkLayerController::ProcessIncomingExtendedScanRequest( // the advertiser’s device address (AdvA field) in the SCAN_REQ PDU to // which it is responding. SendLeLinkLayerPacket( - model::packets::LeScanResponseBuilder::Create( - advertising_address.GetAddress(), scanning_address.GetAddress(), - static_cast( - advertising_address.GetAddressType()), - advertiser.scan_response_data), - advertiser.advertising_tx_power); + model::packets::LeScanResponseBuilder::Create( + advertising_address.GetAddress(), scanning_address.GetAddress(), + static_cast(advertising_address.GetAddressType()), + advertiser.scan_response_data), + advertiser.advertising_tx_power); } -void LinkLayerController::IncomingLeScanPacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingLeScanPacket(model::packets::LinkLayerPacketView incoming) { auto scan_request = model::packets::LeScanView::Create(incoming); ASSERT(scan_request.IsValid()); - AddressWithType scanning_address{ - scan_request.GetSourceAddress(), - static_cast(scan_request.GetScanningAddressType())}; + AddressWithType scanning_address{scan_request.GetSourceAddress(), + static_cast(scan_request.GetScanningAddressType())}; AddressWithType advertising_address{ - scan_request.GetDestinationAddress(), - static_cast(scan_request.GetAdvertisingAddressType())}; + scan_request.GetDestinationAddress(), + static_cast(scan_request.GetAdvertisingAddressType())}; // Note: Vol 6, Part B § 6.2 Privacy in the Advertising State. // @@ -4910,7 +4611,7 @@ void LinkLayerController::IncomingLeScanPacket( // address. The advertising filter policy shall then determine if // the advertiser processes the scan request. AddressWithType resolved_scanning_address = - ResolvePrivateAddress(scanning_address).value_or(scanning_address); + ResolvePrivateAddress(scanning_address).value_or(scanning_address); if (resolved_scanning_address != scanning_address) { DEBUG(id_, "Resolved the scanning address {} to {}", scanning_address, @@ -4920,14 +4621,13 @@ void LinkLayerController::IncomingLeScanPacket( ProcessIncomingLegacyScanRequest(scanning_address, resolved_scanning_address, advertising_address); for (auto& [_, advertiser] : extended_advertisers_) { - ProcessIncomingExtendedScanRequest(advertiser, scanning_address, - resolved_scanning_address, + ProcessIncomingExtendedScanRequest(advertiser, scanning_address, resolved_scanning_address, advertising_address); } } -void LinkLayerController::IncomingLeScanResponsePacket( - model::packets::LinkLayerPacketView incoming, uint8_t rssi) { +void LinkLayerController::IncomingLeScanResponsePacket(model::packets::LinkLayerPacketView incoming, + uint8_t rssi) { auto scan_response = model::packets::LeScanResponseView::Create(incoming); ASSERT(scan_response.IsValid()); @@ -4943,8 +4643,8 @@ void LinkLayerController::IncomingLeScanResponsePacket( } AddressWithType advertising_address{ - scan_response.GetSourceAddress(), - static_cast(scan_response.GetAdvertisingAddressType())}; + scan_response.GetSourceAddress(), + static_cast(scan_response.GetAdvertisingAddressType())}; // If the advertiser processes the scan request, the advertiser’s device // address (AdvA field) in the scan response PDU shall be the same as the @@ -4959,21 +4659,19 @@ void LinkLayerController::IncomingLeScanResponsePacket( } AddressWithType resolved_advertising_address = - ResolvePrivateAddress(advertising_address).value_or(advertising_address); + ResolvePrivateAddress(advertising_address).value_or(advertising_address); if (advertising_address != resolved_advertising_address) { DEBUG(id_, "Resolved the advertising address {} to {}", advertising_address, resolved_advertising_address); } - INFO(id_, "Accepting LE Scan response from advertising address {}", - resolved_advertising_address); + INFO(id_, "Accepting LE Scan response from advertising address {}", resolved_advertising_address); scanner_.pending_scan_request = {}; bool should_send_advertising_report = true; - if (scanner_.filter_duplicates != - bluetooth::hci::FilterDuplicates::DISABLED) { + if (scanner_.filter_duplicates != bluetooth::hci::FilterDuplicates::DISABLED) { if (scanner_.IsPacketInHistory(incoming.bytes())) { should_send_advertising_report = false; } else { @@ -4982,7 +4680,7 @@ void LinkLayerController::IncomingLeScanResponsePacket( } if (LegacyAdvertising() && should_send_advertising_report && - IsLeEventUnmasked(SubeventCode::ADVERTISING_REPORT)) { + IsLeEventUnmasked(SubeventCode::LE_ADVERTISING_REPORT)) { bluetooth::hci::LeAdvertisingResponse response; response.event_type_ = bluetooth::hci::AdvertisingEventType::SCAN_RESPONSE; response.address_ = resolved_advertising_address.GetAddress(); @@ -4993,26 +4691,25 @@ void LinkLayerController::IncomingLeScanResponsePacket( } if (ExtendedAdvertising() && should_send_advertising_report && - IsLeEventUnmasked(SubeventCode::EXTENDED_ADVERTISING_REPORT)) { + IsLeEventUnmasked(SubeventCode::LE_EXTENDED_ADVERTISING_REPORT)) { bluetooth::hci::LeExtendedAdvertisingResponse response; response.address_ = resolved_advertising_address.GetAddress(); - response.address_type_ = - static_cast( + response.address_type_ = static_cast( resolved_advertising_address.GetAddressType()); response.connectable_ = scanner_.connectable_scan_response; response.scannable_ = true; response.legacy_ = !scanner_.extended_scan_response; response.scan_response_ = true; - response.primary_phy_ = static_cast( - scanner_.primary_scan_response_phy); - response.secondary_phy_ = static_cast( - scanner_.secondary_scan_response_phy); + response.primary_phy_ = + static_cast(scanner_.primary_scan_response_phy); + response.secondary_phy_ = + static_cast(scanner_.secondary_scan_response_phy); // TODO: SID should be set in scan response PDU response.advertising_sid_ = 0xFF; response.tx_power_ = 0x7F; response.rssi_ = rssi; response.direct_address_type_ = - bluetooth::hci::DirectAdvertisingAddressType::NO_ADDRESS_PROVIDED; + bluetooth::hci::DirectAdvertisingAddressType::NO_ADDRESS_PROVIDED; // Each extended advertising report can only pass 229 bytes of // advertising data (255 - size of report fields). @@ -5025,14 +4722,12 @@ void LinkLayerController::IncomingLeScanResponsePacket( size_t remaining_size = advertising_data.size() - offset; size_t fragment_size = std::min(max_fragment_size, remaining_size); response.data_status_ = remaining_size <= max_fragment_size - ? bluetooth::hci::DataStatus::COMPLETE - : bluetooth::hci::DataStatus::CONTINUING; - response.advertising_data_ = - std::vector(advertising_data.begin() + offset, - advertising_data.begin() + offset + fragment_size); + ? bluetooth::hci::DataStatus::COMPLETE + : bluetooth::hci::DataStatus::CONTINUING; + response.advertising_data_ = std::vector(advertising_data.begin() + offset, + advertising_data.begin() + offset + fragment_size); offset += fragment_size; - send_event_(bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create( - {response})); + send_event_(bluetooth::hci::LeExtendedAdvertisingReportBuilder::Create({response})); } while (offset < advertising_data.size()); } } @@ -5050,8 +4745,7 @@ void LinkLayerController::LeScanning() { // events with Advertising Timeout error code when the advertising // type is ADV_DIRECT_IND and the connection failed to be established. - if (scanner_.timeout.has_value() && - !scanner_.periodical_timeout.has_value() && + if (scanner_.timeout.has_value() && !scanner_.periodical_timeout.has_value() && now >= scanner_.timeout.value()) { // At the end of a single scan (Duration non-zero but Period zero), // an HCI_LE_Scan_Timeout event shall be generated. @@ -5059,7 +4753,7 @@ void LinkLayerController::LeScanning() { scanner_.scan_enable = false; scanner_.pending_scan_request = {}; scanner_.history.clear(); - if (IsLeEventUnmasked(SubeventCode::SCAN_TIMEOUT)) { + if (IsLeEventUnmasked(SubeventCode::LE_SCAN_TIMEOUT)) { send_event_(bluetooth::hci::LeScanTimeoutBuilder::Create()); } } @@ -5071,8 +4765,7 @@ void LinkLayerController::LeScanning() { } // End of period - if (!scanner_.timeout.has_value() && - scanner_.periodical_timeout.has_value() && + if (!scanner_.timeout.has_value() && scanner_.periodical_timeout.has_value() && now >= scanner_.periodical_timeout.value()) { if (scanner_.filter_duplicates == FilterDuplicates::RESET_EACH_PERIOD) { scanner_.history.clear(); @@ -5095,13 +4788,11 @@ void LinkLayerController::LeSynchronization() { std::vector removed_sync_handles; for (auto& [_, sync] : synchronized_) { if (sync.timeout > std::chrono::steady_clock::now()) { - INFO(id_, "Periodic advertising sync with handle 0x{:x} lost", - sync.sync_handle); + INFO(id_, "Periodic advertising sync with handle 0x{:x} lost", sync.sync_handle); removed_sync_handles.push_back(sync.sync_handle); } - if (IsLeEventUnmasked(SubeventCode::PERIODIC_ADVERTISING_SYNC_LOST)) { - send_event_(bluetooth::hci::LePeriodicAdvertisingSyncLostBuilder::Create( - sync.sync_handle)); + if (IsLeEventUnmasked(SubeventCode::LE_PERIODIC_ADVERTISING_SYNC_LOST)) { + send_event_(bluetooth::hci::LePeriodicAdvertisingSyncLostBuilder::Create(sync.sync_handle)); } } @@ -5110,8 +4801,7 @@ void LinkLayerController::LeSynchronization() { } } -void LinkLayerController::IncomingPagePacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingPagePacket(model::packets::LinkLayerPacketView incoming) { auto bd_addr = incoming.GetSourceAddress(); auto page = model::packets::PageView::Create(incoming); ASSERT(page.IsValid()); @@ -5123,9 +4813,9 @@ void LinkLayerController::IncomingPagePacket( if (!IsEventUnmasked(EventCode::CONNECTION_REQUEST)) { INFO(id_, "rejecting connection request from {} because the HCI_Connection_Request" - " event is masked by the Host", bd_addr); - SendLinkLayerPacket( - model::packets::PageRejectBuilder::Create( + " event is masked by the Host", + bd_addr); + SendLinkLayerPacket(model::packets::PageRejectBuilder::Create( GetAddress(), bd_addr, static_cast(ErrorCode::CONNECTION_TIMEOUT))); return; } @@ -5137,8 +4827,8 @@ void LinkLayerController::IncomingPagePacket( bool allow_role_switch = page.GetAllowRoleSwitch(); if (!connections_.CreatePendingConnection( - bd_addr, authentication_enable_ == AuthenticationEnable::REQUIRED, - allow_role_switch)) { + bd_addr, authentication_enable_ == AuthenticationEnable::REQUIRED, + allow_role_switch)) { // Will be triggered when multiple hosts are paging simultaneously; // only one connection will be accepted. WARNING(id_, "Failed to create a pending connection for {}", bd_addr); @@ -5146,12 +4836,10 @@ void LinkLayerController::IncomingPagePacket( } send_event_(bluetooth::hci::ConnectionRequestBuilder::Create( - bd_addr, page.GetClassOfDevice(), - bluetooth::hci::ConnectionRequestLinkType::ACL)); + bd_addr, page.GetClassOfDevice(), bluetooth::hci::ConnectionRequestLinkType::ACL)); } -void LinkLayerController::IncomingPageRejectPacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingPageRejectPacket(model::packets::LinkLayerPacketView incoming) { auto bd_addr = incoming.GetSourceAddress(); auto reject = model::packets::PageRejectView::Create(incoming); ASSERT(reject.IsValid()); @@ -5168,13 +4856,12 @@ void LinkLayerController::IncomingPageRejectPacket( if (IsEventUnmasked(EventCode::CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - static_cast(reject.GetReason()), 0, bd_addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + static_cast(reject.GetReason()), 0, bd_addr, bluetooth::hci::LinkType::ACL, + bluetooth::hci::Enable::DISABLED)); } } -void LinkLayerController::IncomingPageResponsePacket( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingPageResponsePacket(model::packets::LinkLayerPacketView incoming) { auto bd_addr = incoming.GetSourceAddress(); auto response = model::packets::PageResponseView::Create(incoming); ASSERT(response.IsValid()); @@ -5188,14 +4875,12 @@ void LinkLayerController::IncomingPageResponsePacket( INFO(id_, "Received Page Response packet from {}", bd_addr); - uint16_t connection_handle = - connections_.CreateConnection(bd_addr, GetAddress(), false); + uint16_t connection_handle = connections_.CreateConnection(bd_addr, GetAddress(), false); ASSERT(connection_handle != kReservedHandle); - bluetooth::hci::Role role = - page_->allow_role_switch && response.GetTryRoleSwitch() - ? bluetooth::hci::Role::PERIPHERAL - : bluetooth::hci::Role::CENTRAL; + bluetooth::hci::Role role = page_->allow_role_switch && response.GetTryRoleSwitch() + ? bluetooth::hci::Role::PERIPHERAL + : bluetooth::hci::Role::CENTRAL; AclConnection& connection = connections_.GetAclConnection(connection_handle); CheckExpiringConnection(connection_handle); @@ -5203,22 +4888,19 @@ void LinkLayerController::IncomingPageResponsePacket( connection.SetRole(role); page_ = {}; - ASSERT(link_manager_add_link( - lm_.get(), reinterpret_cast(bd_addr.data()))); + ASSERT(link_manager_add_link(lm_.get(), reinterpret_cast(bd_addr.data()))); // Role change event before connection complete generates an HCI Role Change // event on the initiator side if accepted; the event is sent before the // HCI Connection Complete event. - if (role == bluetooth::hci::Role::PERIPHERAL && - IsEventUnmasked(EventCode::ROLE_CHANGE)) { - send_event_(bluetooth::hci::RoleChangeBuilder::Create(ErrorCode::SUCCESS, - bd_addr, role)); + if (role == bluetooth::hci::Role::PERIPHERAL && IsEventUnmasked(EventCode::ROLE_CHANGE)) { + send_event_(bluetooth::hci::RoleChangeBuilder::Create(ErrorCode::SUCCESS, bd_addr, role)); } if (IsEventUnmasked(EventCode::CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, connection_handle, bd_addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + ErrorCode::SUCCESS, connection_handle, bd_addr, bluetooth::hci::LinkType::ACL, + bluetooth::hci::Enable::DISABLED)); } } @@ -5242,33 +4924,28 @@ void LinkLayerController::Close() { } void LinkLayerController::RegisterEventChannel( - const std::function)>& - send_event) { + const std::function)>& send_event) { send_event_ = send_event; } void LinkLayerController::RegisterAclChannel( - const std::function)>& - send_acl) { + const std::function)>& send_acl) { send_acl_ = send_acl; } void LinkLayerController::RegisterScoChannel( - const std::function)>& - send_sco) { + const std::function)>& send_sco) { send_sco_ = send_sco; } void LinkLayerController::RegisterIsoChannel( - const std::function)>& - send_iso) { + const std::function)>& send_iso) { send_iso_ = send_iso; } void LinkLayerController::RegisterRemoteChannel( - const std::function< - void(std::shared_ptr, Phy::Type, - int8_t)>& send_to_remote) { + const std::function, Phy::Type, + int8_t)>& send_to_remote) { send_to_remote_ = send_to_remote; } @@ -5282,13 +4959,11 @@ void LinkLayerController::ForwardToLl(bluetooth::hci::CommandView command) { ASSERT(link_layer_ingest_hci(ll_.get(), packet.data(), packet.size())); } -std::vector const& LinkLayerController::ReadCurrentIacLap() - const { +std::vector const& LinkLayerController::ReadCurrentIacLap() const { return current_iac_lap_list_; } -void LinkLayerController::WriteCurrentIacLap( - std::vector iac_lap) { +void LinkLayerController::WriteCurrentIacLap(std::vector iac_lap) { current_iac_lap_list_.swap(iac_lap); // If Num_Current_IAC is greater than Num_Supported_IAC then only the first @@ -5317,12 +4992,11 @@ ErrorCode LinkLayerController::AcceptConnectionRequest(const Address& bd_addr, uint16_t sco_handle = 0; ScoLinkParameters link_parameters = {}; ScoConnectionParameters connection_parameters = - connections_.GetScoConnectionParameters(bd_addr); + connections_.GetScoConnectionParameters(bd_addr); - if (!connections_.AcceptPendingScoConnection( - bd_addr, connection_parameters, [this, bd_addr] { - return LinkLayerController::StartScoStream(bd_addr); - })) { + if (!connections_.AcceptPendingScoConnection(bd_addr, connection_parameters, [this, bd_addr] { + return LinkLayerController::StartScoStream(bd_addr); + })) { connections_.CancelPendingScoConnection(bd_addr); status = ErrorCode::SCO_INTERVAL_REJECTED; // TODO: proper status code } else { @@ -5332,18 +5006,16 @@ ErrorCode LinkLayerController::AcceptConnectionRequest(const Address& bd_addr, // Send eSCO connection response to peer. SendLinkLayerPacket(model::packets::ScoConnectionResponseBuilder::Create( - 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.extended)); + 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.extended)); // Schedule HCI Connection Complete event. if (IsEventUnmasked(EventCode::CONNECTION_COMPLETE)) { ScheduleTask(kNoDelayMs, [this, status, sco_handle, bd_addr]() { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode(status), sco_handle, bd_addr, - bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED)); + ErrorCode(status), sco_handle, bd_addr, bluetooth::hci::LinkType::SCO, + bluetooth::hci::Enable::DISABLED)); }); } @@ -5354,42 +5026,37 @@ ErrorCode LinkLayerController::AcceptConnectionRequest(const Address& bd_addr, return ErrorCode::UNKNOWN_CONNECTION; } -void LinkLayerController::MakePeripheralConnection(const Address& bd_addr, - bool try_role_switch) { - uint16_t connection_handle = - connections_.CreateConnection(bd_addr, GetAddress()); +void LinkLayerController::MakePeripheralConnection(const Address& bd_addr, bool try_role_switch) { + uint16_t connection_handle = connections_.CreateConnection(bd_addr, GetAddress()); if (connection_handle == kReservedHandle) { INFO(id_, "CreateConnection failed"); return; } bluetooth::hci::Role role = - try_role_switch && connections_.IsRoleSwitchAllowedForPendingConnection() - ? bluetooth::hci::Role::CENTRAL - : bluetooth::hci::Role::PERIPHERAL; + try_role_switch && connections_.IsRoleSwitchAllowedForPendingConnection() + ? bluetooth::hci::Role::CENTRAL + : bluetooth::hci::Role::PERIPHERAL; AclConnection& connection = connections_.GetAclConnection(connection_handle); CheckExpiringConnection(connection_handle); connection.SetLinkPolicySettings(default_link_policy_settings_); connection.SetRole(role); - ASSERT(link_manager_add_link( - lm_.get(), reinterpret_cast(bd_addr.data()))); + ASSERT(link_manager_add_link(lm_.get(), reinterpret_cast(bd_addr.data()))); // Role change event before connection complete generates an HCI Role Change // event on the acceptor side if accepted; the event is sent before the // HCI Connection Complete event. - if (role == bluetooth::hci::Role::CENTRAL && - IsEventUnmasked(EventCode::ROLE_CHANGE)) { + if (role == bluetooth::hci::Role::CENTRAL && IsEventUnmasked(EventCode::ROLE_CHANGE)) { INFO(id_, "Role at connection setup accepted"); - send_event_(bluetooth::hci::RoleChangeBuilder::Create(ErrorCode::SUCCESS, - bd_addr, role)); + send_event_(bluetooth::hci::RoleChangeBuilder::Create(ErrorCode::SUCCESS, bd_addr, role)); } if (IsEventUnmasked(EventCode::CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, connection_handle, bd_addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + ErrorCode::SUCCESS, connection_handle, bd_addr, bluetooth::hci::LinkType::ACL, + bluetooth::hci::Enable::DISABLED)); } // If the current Host was initiating a connection to the same bd_addr, @@ -5405,39 +5072,33 @@ void LinkLayerController::MakePeripheralConnection(const Address& bd_addr, } INFO(id_, "Sending page response to {}", bd_addr.ToString()); - SendLinkLayerPacket(model::packets::PageResponseBuilder::Create( - GetAddress(), bd_addr, try_role_switch)); + SendLinkLayerPacket( + model::packets::PageResponseBuilder::Create(GetAddress(), bd_addr, try_role_switch)); } -ErrorCode LinkLayerController::RejectConnectionRequest(const Address& addr, - uint8_t reason) { +ErrorCode LinkLayerController::RejectConnectionRequest(const Address& addr, uint8_t reason) { if (!connections_.HasPendingConnection(addr)) { INFO(id_, "No pending connection for {}", addr); return ErrorCode::UNKNOWN_CONNECTION; } - ScheduleTask(kNoDelayMs, [this, addr, reason]() { - RejectPeripheralConnection(addr, reason); - }); + ScheduleTask(kNoDelayMs, [this, addr, reason]() { RejectPeripheralConnection(addr, reason); }); return ErrorCode::SUCCESS; } -void LinkLayerController::RejectPeripheralConnection(const Address& addr, - uint8_t reason) { +void LinkLayerController::RejectPeripheralConnection(const Address& addr, uint8_t reason) { INFO(id_, "Sending page reject to {} (reason 0x{:02x})", addr, reason); - SendLinkLayerPacket( - model::packets::PageRejectBuilder::Create(GetAddress(), addr, reason)); + SendLinkLayerPacket(model::packets::PageRejectBuilder::Create(GetAddress(), addr, reason)); if (IsEventUnmasked(EventCode::CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - static_cast(reason), 0xeff, addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + static_cast(reason), 0xeff, addr, bluetooth::hci::LinkType::ACL, + bluetooth::hci::Enable::DISABLED)); } } -ErrorCode LinkLayerController::CreateConnection(const Address& bd_addr, - uint16_t /* packet_type */, +ErrorCode LinkLayerController::CreateConnection(const Address& bd_addr, uint16_t /* packet_type */, uint8_t /* page_scan_mode */, uint16_t /* clock_offset */, uint8_t allow_role_switch) { @@ -5457,10 +5118,10 @@ ErrorCode LinkLayerController::CreateConnection(const Address& bd_addr, auto now = std::chrono::steady_clock::now(); page_ = Page{ - .bd_addr = bd_addr, - .allow_role_switch = allow_role_switch, - .next_page_event = now + kPageInterval, - .page_timeout = now + slots(page_timeout_), + .bd_addr = bd_addr, + .allow_role_switch = allow_role_switch, + .next_page_event = now + kPageInterval, + .page_timeout = now + slots(page_timeout_), }; return ErrorCode::SUCCESS; @@ -5485,8 +5146,8 @@ ErrorCode LinkLayerController::CreateConnectionCancel(const Address& bd_addr) { if (IsEventUnmasked(EventCode::CONNECTION_COMPLETE)) { ScheduleTask(kNoDelayMs, [this, bd_addr]() { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode::UNKNOWN_CONNECTION, 0, bd_addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + ErrorCode::UNKNOWN_CONNECTION, 0, bd_addr, bluetooth::hci::LinkType::ACL, + bluetooth::hci::Enable::DISABLED)); }); } @@ -5494,28 +5155,25 @@ ErrorCode LinkLayerController::CreateConnectionCancel(const Address& bd_addr) { return ErrorCode::SUCCESS; } -void LinkLayerController::SendDisconnectionCompleteEvent(uint16_t handle, - ErrorCode reason) { +void LinkLayerController::SendDisconnectionCompleteEvent(uint16_t handle, ErrorCode reason) { if (IsEventUnmasked(EventCode::DISCONNECTION_COMPLETE)) { ScheduleTask(kNoDelayMs, [this, handle, reason]() { - send_event_(bluetooth::hci::DisconnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, handle, reason)); + send_event_(bluetooth::hci::DisconnectionCompleteBuilder::Create(ErrorCode::SUCCESS, handle, + reason)); }); } } -ErrorCode LinkLayerController::Disconnect(uint16_t handle, - ErrorCode host_reason, +ErrorCode LinkLayerController::Disconnect(uint16_t handle, ErrorCode host_reason, ErrorCode controller_reason) { if (connections_.HasScoHandle(handle)) { const Address remote = connections_.GetScoAddress(handle); INFO(id_, "Disconnecting eSCO connection with {}", remote); SendLinkLayerPacket(model::packets::ScoDisconnectBuilder::Create( - GetAddress(), remote, static_cast(host_reason))); + GetAddress(), remote, static_cast(host_reason))); - connections_.Disconnect( - handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); + connections_.Disconnect(handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); SendDisconnectionCompleteEvent(handle, controller_reason); return ErrorCode::SUCCESS; } @@ -5533,47 +5191,42 @@ ErrorCode LinkLayerController::Disconnect(uint16_t handle, uint16_t sco_handle = connections_.GetScoHandle(remote.GetAddress()); if (sco_handle != kReservedHandle) { SendLinkLayerPacket(model::packets::ScoDisconnectBuilder::Create( - GetAddress(), remote.GetAddress(), - static_cast(host_reason))); + GetAddress(), remote.GetAddress(), static_cast(host_reason))); - connections_.Disconnect( - sco_handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); + connections_.Disconnect(sco_handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); SendDisconnectionCompleteEvent(sco_handle, controller_reason); } SendLinkLayerPacket(model::packets::DisconnectBuilder::Create( - GetAddress(), remote.GetAddress(), static_cast(host_reason))); + GetAddress(), remote.GetAddress(), static_cast(host_reason))); } else { INFO(id_, "Disconnecting LE connection with {}", remote); SendLeLinkLayerPacket(model::packets::DisconnectBuilder::Create( - connections_.GetOwnAddress(handle).GetAddress(), remote.GetAddress(), - static_cast(host_reason))); + connections_.GetOwnAddress(handle).GetAddress(), remote.GetAddress(), + static_cast(host_reason))); } - connections_.Disconnect( - handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); + connections_.Disconnect(handle, [this](TaskId task_id) { CancelScheduledTask(task_id); }); SendDisconnectionCompleteEvent(handle, controller_reason); if (is_br_edr) { - ASSERT(link_manager_remove_link( - lm_.get(), - reinterpret_cast(remote.GetAddress().data()))); + ASSERT(link_manager_remove_link(lm_.get(), + reinterpret_cast(remote.GetAddress().data()))); } else { ASSERT(link_layer_remove_link(ll_.get(), handle)); } return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::ChangeConnectionPacketType(uint16_t handle, - uint16_t types) { +ErrorCode LinkLayerController::ChangeConnectionPacketType(uint16_t handle, uint16_t types) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } ScheduleTask(kNoDelayMs, [this, handle, types]() { if (IsEventUnmasked(EventCode::CONNECTION_PACKET_TYPE_CHANGED)) { - send_event_(bluetooth::hci::ConnectionPacketTypeChangedBuilder::Create( - ErrorCode::SUCCESS, handle, types)); + send_event_(bluetooth::hci::ConnectionPacketTypeChangedBuilder::Create(ErrorCode::SUCCESS, + handle, types)); } }); @@ -5596,8 +5249,7 @@ ErrorCode LinkLayerController::CentralLinkKey(uint8_t /* key_flag */) { return ErrorCode::COMMAND_DISALLOWED; } -ErrorCode LinkLayerController::HoldMode(uint16_t handle, - uint16_t hold_mode_max_interval, +ErrorCode LinkLayerController::HoldMode(uint16_t handle, uint16_t hold_mode_max_interval, uint16_t hold_mode_min_interval) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; @@ -5611,17 +5263,15 @@ ErrorCode LinkLayerController::HoldMode(uint16_t handle, return ErrorCode::COMMAND_DISALLOWED; } -ErrorCode LinkLayerController::SniffMode(uint16_t handle, - uint16_t sniff_max_interval, - uint16_t sniff_min_interval, - uint16_t sniff_attempt, +ErrorCode LinkLayerController::SniffMode(uint16_t handle, uint16_t sniff_max_interval, + uint16_t sniff_min_interval, uint16_t sniff_attempt, uint16_t sniff_timeout) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } - if (sniff_max_interval < sniff_min_interval || sniff_attempt < 0x0001 || - sniff_attempt > 0x7FFF || sniff_timeout > 0x7FFF) { + if (sniff_max_interval < sniff_min_interval || sniff_attempt < 0x0001 || sniff_attempt > 0x7FFF || + sniff_timeout > 0x7FFF) { return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -5639,10 +5289,8 @@ ErrorCode LinkLayerController::ExitSniffMode(uint16_t handle) { } ErrorCode LinkLayerController::QosSetup(uint16_t handle, uint8_t service_type, - uint32_t /* token_rate */, - uint32_t /* peak_bandwidth */, - uint32_t /* latency */, - uint32_t /* delay_variation */) { + uint32_t /* token_rate */, uint32_t /* peak_bandwidth */, + uint32_t /* latency */, uint32_t /* delay_variation */) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -5655,8 +5303,7 @@ ErrorCode LinkLayerController::QosSetup(uint16_t handle, uint8_t service_type, return ErrorCode::COMMAND_DISALLOWED; } -ErrorCode LinkLayerController::RoleDiscovery(uint16_t handle, - bluetooth::hci::Role* role) { +ErrorCode LinkLayerController::RoleDiscovery(uint16_t handle, bluetooth::hci::Role* role) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -5665,8 +5312,7 @@ ErrorCode LinkLayerController::RoleDiscovery(uint16_t handle, return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::SwitchRole(Address bd_addr, - bluetooth::hci::Role role) { +ErrorCode LinkLayerController::SwitchRole(Address bd_addr, bluetooth::hci::Role role) { // The BD_ADDR command parameter indicates for which connection // the role switch is to be performed and shall specify a BR/EDR Controller // for which a connection already exists. @@ -5692,28 +5338,25 @@ ErrorCode LinkLayerController::SwitchRole(Address bd_addr, // BD_ADDR parameter is placed in Sniff mode, an attempt to perform a role // switch shall be rejected by the local device. if (connection.GetMode() == AclConnectionState::kSniffMode) { - INFO(id_, - "role switch rejected because the acl connection is in sniff mode"); + INFO(id_, "role switch rejected because the acl connection is in sniff mode"); return ErrorCode::COMMAND_DISALLOWED; } if (role != connection.GetRole()) { - SendLinkLayerPacket(model::packets::RoleSwitchRequestBuilder::Create( - GetAddress(), bd_addr)); + SendLinkLayerPacket(model::packets::RoleSwitchRequestBuilder::Create(GetAddress(), bd_addr)); } else if (IsEventUnmasked(EventCode::ROLE_CHANGE)) { // Note: the status is Success only if the role change procedure was // actually performed, otherwise the status is >0. ScheduleTask(kNoDelayMs, [this, bd_addr, role]() { - send_event_(bluetooth::hci::RoleChangeBuilder::Create( - ErrorCode::ROLE_SWITCH_FAILED, bd_addr, role)); + send_event_(bluetooth::hci::RoleChangeBuilder::Create(ErrorCode::ROLE_SWITCH_FAILED, bd_addr, + role)); }); } return ErrorCode::SUCCESS; } -void LinkLayerController::IncomingRoleSwitchRequest( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingRoleSwitchRequest(model::packets::LinkLayerPacketView incoming) { auto bd_addr = incoming.GetSourceAddress(); auto connection_handle = connections_.GetHandleOnlyAddress(bd_addr); auto switch_req = model::packets::RoleSwitchRequestView::Create(incoming); @@ -5729,31 +5372,28 @@ void LinkLayerController::IncomingRoleSwitchRequest( if (!connection.IsRoleSwitchEnabled()) { INFO(id_, "role switch disabled by local link policy settings"); SendLinkLayerPacket(model::packets::RoleSwitchResponseBuilder::Create( - GetAddress(), bd_addr, - static_cast(ErrorCode::ROLE_CHANGE_NOT_ALLOWED))); + GetAddress(), bd_addr, static_cast(ErrorCode::ROLE_CHANGE_NOT_ALLOWED))); } else { INFO(id_, "role switch request accepted by local device"); SendLinkLayerPacket(model::packets::RoleSwitchResponseBuilder::Create( - GetAddress(), bd_addr, static_cast(ErrorCode::SUCCESS))); + GetAddress(), bd_addr, static_cast(ErrorCode::SUCCESS))); - bluetooth::hci::Role new_role = - connection.GetRole() == bluetooth::hci::Role::CENTRAL - ? bluetooth::hci::Role::PERIPHERAL - : bluetooth::hci::Role::CENTRAL; + bluetooth::hci::Role new_role = connection.GetRole() == bluetooth::hci::Role::CENTRAL + ? bluetooth::hci::Role::PERIPHERAL + : bluetooth::hci::Role::CENTRAL; connection.SetRole(new_role); if (IsEventUnmasked(EventCode::ROLE_CHANGE)) { ScheduleTask(kNoDelayMs, [this, bd_addr, new_role]() { - send_event_(bluetooth::hci::RoleChangeBuilder::Create( - ErrorCode::SUCCESS, bd_addr, new_role)); + send_event_( + bluetooth::hci::RoleChangeBuilder::Create(ErrorCode::SUCCESS, bd_addr, new_role)); }); } } } -void LinkLayerController::IncomingRoleSwitchResponse( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingRoleSwitchResponse(model::packets::LinkLayerPacketView incoming) { auto bd_addr = incoming.GetSourceAddress(); auto connection_handle = connections_.GetHandleOnlyAddress(bd_addr); auto switch_rsp = model::packets::RoleSwitchResponseView::Create(incoming); @@ -5766,24 +5406,21 @@ void LinkLayerController::IncomingRoleSwitchResponse( AclConnection& connection = connections_.GetAclConnection(connection_handle); ErrorCode status = ErrorCode(switch_rsp.GetStatus()); - bluetooth::hci::Role new_role = - status != ErrorCode::SUCCESS ? connection.GetRole() - : connection.GetRole() == bluetooth::hci::Role::CENTRAL - ? bluetooth::hci::Role::PERIPHERAL - : bluetooth::hci::Role::CENTRAL; + bluetooth::hci::Role new_role = status != ErrorCode::SUCCESS ? connection.GetRole() + : connection.GetRole() == bluetooth::hci::Role::CENTRAL + ? bluetooth::hci::Role::PERIPHERAL + : bluetooth::hci::Role::CENTRAL; connection.SetRole(new_role); if (IsEventUnmasked(EventCode::ROLE_CHANGE)) { ScheduleTask(kNoDelayMs, [this, status, bd_addr, new_role]() { - send_event_( - bluetooth::hci::RoleChangeBuilder::Create(status, bd_addr, new_role)); + send_event_(bluetooth::hci::RoleChangeBuilder::Create(status, bd_addr, new_role)); }); } } -ErrorCode LinkLayerController::ReadLinkPolicySettings(uint16_t handle, - uint16_t* settings) { +ErrorCode LinkLayerController::ReadLinkPolicySettings(uint16_t handle, uint16_t* settings) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -5792,8 +5429,7 @@ ErrorCode LinkLayerController::ReadLinkPolicySettings(uint16_t handle, return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::WriteLinkPolicySettings(uint16_t handle, - uint16_t settings) { +ErrorCode LinkLayerController::WriteLinkPolicySettings(uint16_t handle, uint16_t settings) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -5804,8 +5440,7 @@ ErrorCode LinkLayerController::WriteLinkPolicySettings(uint16_t handle, return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::WriteDefaultLinkPolicySettings( - uint16_t settings) { +ErrorCode LinkLayerController::WriteDefaultLinkPolicySettings(uint16_t settings) { if (settings > 7 /* Sniff + Hold + Role switch */) { return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -5819,52 +5454,46 @@ uint16_t LinkLayerController::ReadDefaultLinkPolicySettings() const { } void LinkLayerController::ReadLocalOobData() { - std::array c_array( - {'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', '0', - static_cast((oob_id_ % 0x10000) >> 8), - static_cast(oob_id_ % 0x100)}); - - std::array r_array( - {'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', '0', - static_cast((oob_id_ % 0x10000) >> 8), - static_cast(oob_id_ % 0x100)}); - - send_event_(bluetooth::hci::ReadLocalOobDataCompleteBuilder::Create( - 1, ErrorCode::SUCCESS, c_array, r_array)); + std::array c_array({'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', + '0', static_cast((oob_id_ % 0x10000) >> 8), + static_cast(oob_id_ % 0x100)}); + + std::array r_array({'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', + '0', static_cast((oob_id_ % 0x10000) >> 8), + static_cast(oob_id_ % 0x100)}); + + send_event_(bluetooth::hci::ReadLocalOobDataCompleteBuilder::Create(1, ErrorCode::SUCCESS, + c_array, r_array)); oob_id_ += 1; } void LinkLayerController::ReadLocalOobExtendedData() { - std::array c_192_array( - {'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', '0', '0', - static_cast((oob_id_ % 0x10000) >> 8), - static_cast(oob_id_ % 0x100)}); - - std::array r_192_array( - {'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', '0', '0', - static_cast((oob_id_ % 0x10000) >> 8), - static_cast(oob_id_ % 0x100)}); - - std::array c_256_array( - {'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', '0', '0', - static_cast((oob_id_ % 0x10000) >> 8), - static_cast(oob_id_ % 0x100)}); - - std::array r_256_array( - {'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', '0', '0', - static_cast((oob_id_ % 0x10000) >> 8), - static_cast(oob_id_ % 0x100)}); + std::array c_192_array({'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', + '0', '0', static_cast((oob_id_ % 0x10000) >> 8), + static_cast(oob_id_ % 0x100)}); + + std::array r_192_array({'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', + '0', '0', static_cast((oob_id_ % 0x10000) >> 8), + static_cast(oob_id_ % 0x100)}); + + std::array c_256_array({'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', + '0', '0', static_cast((oob_id_ % 0x10000) >> 8), + static_cast(oob_id_ % 0x100)}); + + std::array r_256_array({'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', + '0', '0', static_cast((oob_id_ % 0x10000) >> 8), + static_cast(oob_id_ % 0x100)}); send_event_(bluetooth::hci::ReadLocalOobExtendedDataCompleteBuilder::Create( - 1, ErrorCode::SUCCESS, c_192_array, r_192_array, c_256_array, - r_256_array)); + 1, ErrorCode::SUCCESS, c_192_array, r_192_array, c_256_array, r_256_array)); oob_id_ += 1; } -ErrorCode LinkLayerController::FlowSpecification( - uint16_t handle, uint8_t flow_direction, uint8_t service_type, - uint32_t /* token_rate */, uint32_t /* token_bucket_size */, - uint32_t /* peak_bandwidth */, uint32_t /* access_latency */) { +ErrorCode LinkLayerController::FlowSpecification(uint16_t handle, uint8_t flow_direction, + uint8_t service_type, uint32_t /* token_rate */, + uint32_t /* token_bucket_size */, + uint32_t /* peak_bandwidth */, + uint32_t /* access_latency */) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -5877,25 +5506,25 @@ ErrorCode LinkLayerController::FlowSpecification( return ErrorCode::COMMAND_DISALLOWED; } -ErrorCode LinkLayerController::WriteLinkSupervisionTimeout( - uint16_t handle, uint16_t /* timeout */) { +ErrorCode LinkLayerController::WriteLinkSupervisionTimeout(uint16_t handle, + uint16_t /* timeout */) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } return ErrorCode::SUCCESS; } -void LinkLayerController::LeConnectionUpdateComplete( - uint16_t handle, uint16_t interval_min, uint16_t interval_max, - uint16_t latency, uint16_t supervision_timeout) { +void LinkLayerController::LeConnectionUpdateComplete(uint16_t handle, uint16_t interval_min, + uint16_t interval_max, uint16_t latency, + uint16_t supervision_timeout) { ErrorCode status = ErrorCode::SUCCESS; if (!connections_.HasHandle(handle)) { status = ErrorCode::UNKNOWN_CONNECTION; } if (interval_min < 6 || interval_max > 0xC80 || interval_min > interval_max || - interval_max < interval_min || latency > 0x1F3 || - supervision_timeout < 0xA || supervision_timeout > 0xC80 || + interval_max < interval_min || latency > 0x1F3 || supervision_timeout < 0xA || + supervision_timeout > 0xC80 || // The Supervision_Timeout in milliseconds (*10) shall be larger than (1 + // Connection_Latency) * Connection_Interval_Max (* 5/4) * 2 supervision_timeout <= ((((1 + latency) * interval_max * 10) / 4) / 10)) { @@ -5904,20 +5533,19 @@ void LinkLayerController::LeConnectionUpdateComplete( uint16_t interval = (interval_min + interval_max) / 2; SendLeLinkLayerPacket(LeConnectionParameterUpdateBuilder::Create( - connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress(), - static_cast(ErrorCode::SUCCESS), interval, latency, - supervision_timeout)); + connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress(), static_cast(ErrorCode::SUCCESS), + interval, latency, supervision_timeout)); - if (IsLeEventUnmasked(SubeventCode::CONNECTION_UPDATE_COMPLETE)) { + if (IsLeEventUnmasked(SubeventCode::LE_CONNECTION_UPDATE_COMPLETE)) { send_event_(bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create( - status, handle, interval, latency, supervision_timeout)); + status, handle, interval, latency, supervision_timeout)); } } -ErrorCode LinkLayerController::LeConnectionUpdate( - uint16_t handle, uint16_t interval_min, uint16_t interval_max, - uint16_t latency, uint16_t supervision_timeout) { +ErrorCode LinkLayerController::LeConnectionUpdate(uint16_t handle, uint16_t interval_min, + uint16_t interval_max, uint16_t latency, + uint16_t supervision_timeout) { if (!connections_.HasHandle(handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -5928,51 +5556,46 @@ ErrorCode LinkLayerController::LeConnectionUpdate( // As Central, it is allowed to directly send // LL_CONNECTION_PARAM_UPDATE_IND to update the parameters. SendLeLinkLayerPacket(LeConnectionParameterUpdateBuilder::Create( - connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress(), - static_cast(ErrorCode::SUCCESS), interval_max, latency, - supervision_timeout)); + connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress(), static_cast(ErrorCode::SUCCESS), + interval_max, latency, supervision_timeout)); - if (IsLeEventUnmasked(SubeventCode::CONNECTION_UPDATE_COMPLETE)) { + if (IsLeEventUnmasked(SubeventCode::LE_CONNECTION_UPDATE_COMPLETE)) { send_event_(bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create( - ErrorCode::SUCCESS, handle, interval_max, latency, - supervision_timeout)); + ErrorCode::SUCCESS, handle, interval_max, latency, supervision_timeout)); } } else { // Send LL_CONNECTION_PARAM_REQ and wait for LL_CONNECTION_PARAM_RSP // in return. SendLeLinkLayerPacket(LeConnectionParameterRequestBuilder::Create( - connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress(), interval_min, - interval_max, latency, supervision_timeout)); + connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress(), interval_min, interval_max, latency, + supervision_timeout)); } return ErrorCode::SUCCESS; } ErrorCode LinkLayerController::LeRemoteConnectionParameterRequestReply( - uint16_t connection_handle, uint16_t interval_min, uint16_t interval_max, - uint16_t timeout, uint16_t latency, uint16_t minimum_ce_length, - uint16_t maximum_ce_length) { + uint16_t connection_handle, uint16_t interval_min, uint16_t interval_max, uint16_t timeout, + uint16_t latency, uint16_t minimum_ce_length, uint16_t maximum_ce_length) { if (!connections_.HasHandle(connection_handle)) { return ErrorCode::UNKNOWN_CONNECTION; } - if ((interval_min > interval_max) || - (minimum_ce_length > maximum_ce_length)) { + if ((interval_min > interval_max) || (minimum_ce_length > maximum_ce_length)) { return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } - ScheduleTask(kNoDelayMs, [this, connection_handle, interval_min, interval_max, - latency, timeout]() { - LeConnectionUpdateComplete(connection_handle, interval_min, interval_max, - latency, timeout); + ScheduleTask(kNoDelayMs, [this, connection_handle, interval_min, interval_max, latency, + timeout]() { + LeConnectionUpdateComplete(connection_handle, interval_min, interval_max, latency, timeout); }); return ErrorCode::SUCCESS; } ErrorCode LinkLayerController::LeRemoteConnectionParameterRequestNegativeReply( - uint16_t connection_handle, bluetooth::hci::ErrorCode reason) { + uint16_t connection_handle, bluetooth::hci::ErrorCode reason) { if (!connections_.HasHandle(connection_handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -5981,36 +5604,34 @@ ErrorCode LinkLayerController::LeRemoteConnectionParameterRequestNegativeReply( uint16_t latency = 0; uint16_t timeout = 0; SendLeLinkLayerPacket(LeConnectionParameterUpdateBuilder::Create( - connections_.GetOwnAddress(connection_handle).GetAddress(), - connections_.GetAddress(connection_handle).GetAddress(), - static_cast(reason), interval, latency, timeout)); + connections_.GetOwnAddress(connection_handle).GetAddress(), + connections_.GetAddress(connection_handle).GetAddress(), static_cast(reason), + interval, latency, timeout)); return ErrorCode::SUCCESS; } -bool LinkLayerController::HasAclConnection() { - return !connections_.GetAclHandles().empty(); -} +bool LinkLayerController::HasAclConnection() { return !connections_.GetAclHandles().empty(); } bool LinkLayerController::HasAclConnection(uint16_t connection_handle) { return connections_.HasHandle(connection_handle); } -void LinkLayerController::HandleLeEnableEncryption( - uint16_t handle, std::array rand, uint16_t ediv, - std::array ltk) { +void LinkLayerController::HandleLeEnableEncryption(uint16_t handle, std::array rand, + uint16_t ediv, + std::array ltk) { // TODO: Check keys // TODO: Block ACL traffic or at least guard against it if (!connections_.HasHandle(handle)) { return; } SendLeLinkLayerPacket(model::packets::LeEncryptConnectionBuilder::Create( - connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress(), rand, ediv, ltk)); + connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress(), rand, ediv, ltk)); } -ErrorCode LinkLayerController::LeEnableEncryption( - uint16_t handle, std::array rand, uint16_t ediv, - std::array ltk) { +ErrorCode LinkLayerController::LeEnableEncryption(uint16_t handle, std::array rand, + uint16_t ediv, + std::array ltk) { if (!connections_.HasHandle(handle)) { INFO(id_, "Unknown handle 0x{:04x}", handle); return ErrorCode::UNKNOWN_CONNECTION; @@ -6022,8 +5643,8 @@ ErrorCode LinkLayerController::LeEnableEncryption( return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::LeLongTermKeyRequestReply( - uint16_t handle, std::array ltk) { +ErrorCode LinkLayerController::LeLongTermKeyRequestReply(uint16_t handle, + std::array ltk) { if (!connections_.HasHandle(handle)) { INFO(id_, "Unknown handle {:04x}", handle); return ErrorCode::UNKNOWN_CONNECTION; @@ -6032,37 +5653,37 @@ ErrorCode LinkLayerController::LeLongTermKeyRequestReply( // TODO: Check keys if (connections_.IsEncrypted(handle)) { if (IsEventUnmasked(EventCode::ENCRYPTION_KEY_REFRESH_COMPLETE)) { - send_event_(bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create( - ErrorCode::SUCCESS, handle)); + send_event_(bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create(ErrorCode::SUCCESS, + handle)); } } else { connections_.Encrypt(handle); - if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE)) { + if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE_V2)) { + send_event_(bluetooth::hci::EncryptionChangeV2Builder::Create( + ErrorCode::SUCCESS, handle, bluetooth::hci::EncryptionEnabled::ON, + 0x10 /* key_size */)); + } else if (IsEventUnmasked(EventCode::ENCRYPTION_CHANGE)) { send_event_(bluetooth::hci::EncryptionChangeBuilder::Create( - ErrorCode::SUCCESS, handle, bluetooth::hci::EncryptionEnabled::ON)); + ErrorCode::SUCCESS, handle, bluetooth::hci::EncryptionEnabled::ON)); } } - SendLeLinkLayerPacket( - model::packets::LeEncryptConnectionResponseBuilder::Create( + SendLeLinkLayerPacket(model::packets::LeEncryptConnectionResponseBuilder::Create( connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress(), - std::array(), uint16_t(), ltk)); + connections_.GetAddress(handle).GetAddress(), std::array(), uint16_t(), ltk)); return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::LeLongTermKeyRequestNegativeReply( - uint16_t handle) { +ErrorCode LinkLayerController::LeLongTermKeyRequestNegativeReply(uint16_t handle) { if (!connections_.HasHandle(handle)) { INFO(id_, "Unknown handle {:04x}", handle); return ErrorCode::UNKNOWN_CONNECTION; } - SendLeLinkLayerPacket( - model::packets::LeEncryptConnectionResponseBuilder::Create( + SendLeLinkLayerPacket(model::packets::LeEncryptConnectionResponseBuilder::Create( connections_.GetOwnAddress(handle).GetAddress(), - connections_.GetAddress(handle).GetAddress(), - std::array(), uint16_t(), std::array())); + connections_.GetAddress(handle).GetAddress(), std::array(), uint16_t(), + std::array())); return ErrorCode::SUCCESS; } @@ -6110,6 +5731,7 @@ void LinkLayerController::Reset() { legacy_advertiser_ = LegacyAdvertiser{}; extended_advertisers_.clear(); scanner_ = Scanner{}; + apcf_scanner_ = ApcfScanner{}; initiator_ = Initiator{}; synchronizing_ = {}; synchronized_ = {}; @@ -6141,12 +5763,11 @@ void LinkLayerController::Paging() { auto now = std::chrono::steady_clock::now(); if (page_.has_value() && now >= page_->page_timeout) { - INFO("page timeout triggered for connection with {}", - page_->bd_addr.ToString()); + INFO("page timeout triggered for connection with {}", page_->bd_addr.ToString()); send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - ErrorCode::PAGE_TIMEOUT, 0, page_->bd_addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + ErrorCode::PAGE_TIMEOUT, 0, page_->bd_addr, bluetooth::hci::LinkType::ACL, + bluetooth::hci::Enable::DISABLED)); page_ = {}; return; @@ -6158,16 +5779,14 @@ void LinkLayerController::Paging() { if (page_.has_value() && now >= page_->next_page_event && !connections_.HasPendingConnection(page_->bd_addr)) { SendLinkLayerPacket(model::packets::PageBuilder::Create( - GetAddress(), page_->bd_addr, class_of_device_, - page_->allow_role_switch)); + GetAddress(), page_->bd_addr, class_of_device_, page_->allow_role_switch)); page_->next_page_event = now + kPageInterval; } } void LinkLayerController::StartInquiry(milliseconds timeout) { - inquiry_timer_task_id_ = ScheduleTask(milliseconds(timeout), [this]() { - LinkLayerController::InquiryTimeout(); - }); + inquiry_timer_task_id_ = + ScheduleTask(milliseconds(timeout), [this]() { LinkLayerController::InquiryTimeout(); }); } void LinkLayerController::InquiryCancel() { @@ -6180,8 +5799,7 @@ void LinkLayerController::InquiryTimeout() { if (inquiry_timer_task_id_ != kInvalidTaskId) { inquiry_timer_task_id_ = kInvalidTaskId; if (IsEventUnmasked(EventCode::INQUIRY_COMPLETE)) { - send_event_( - bluetooth::hci::InquiryCompleteBuilder::Create(ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::InquiryCompleteBuilder::Create(ErrorCode::SUCCESS)); } } } @@ -6192,9 +5810,7 @@ void LinkLayerController::SetInquiryMode(uint8_t mode) { void LinkLayerController::SetInquiryLAP(uint64_t lap) { inquiry_lap_ = lap; } -void LinkLayerController::SetInquiryMaxResponses(uint8_t max) { - inquiry_max_responses_ = max; -} +void LinkLayerController::SetInquiryMaxResponses(uint8_t max) { inquiry_max_responses_ = max; } void LinkLayerController::Inquiry() { steady_clock::time_point now = steady_clock::now(); @@ -6202,25 +5818,18 @@ void LinkLayerController::Inquiry() { return; } - SendLinkLayerPacket(model::packets::InquiryBuilder::Create( - GetAddress(), Address::kEmpty, inquiry_mode_, inquiry_lap_)); + SendLinkLayerPacket(model::packets::InquiryBuilder::Create(GetAddress(), Address::kEmpty, + inquiry_mode_, inquiry_lap_)); last_inquiry_ = now; } -void LinkLayerController::SetInquiryScanEnable(bool enable) { - inquiry_scan_enable_ = enable; -} +void LinkLayerController::SetInquiryScanEnable(bool enable) { inquiry_scan_enable_ = enable; } -void LinkLayerController::SetPageScanEnable(bool enable) { - page_scan_enable_ = enable; -} +void LinkLayerController::SetPageScanEnable(bool enable) { page_scan_enable_ = enable; } -void LinkLayerController::SetPageTimeout(uint16_t page_timeout) { - page_timeout_ = page_timeout; -} +void LinkLayerController::SetPageTimeout(uint16_t page_timeout) { page_timeout_ = page_timeout; } -ErrorCode LinkLayerController::AddScoConnection(uint16_t connection_handle, - uint16_t packet_type, +ErrorCode LinkLayerController::AddScoConnection(uint16_t connection_handle, uint16_t packet_type, ScoDatapath datapath) { if (!connections_.HasHandle(connection_handle)) { return ErrorCode::UNKNOWN_CONNECTION; @@ -6235,39 +5844,32 @@ ErrorCode LinkLayerController::AddScoConnection(uint16_t connection_handle, // Save connection parameters. ScoConnectionParameters connection_parameters = { - 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)}; - connections_.CreateScoConnection( - connections_.GetAddress(connection_handle).GetAddress(), - connection_parameters, SCO_STATE_PENDING, datapath, true); + 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)}; + connections_.CreateScoConnection(connections_.GetAddress(connection_handle).GetAddress(), + connection_parameters, SCO_STATE_PENDING, datapath, true); // Send SCO connection request to peer. SendLinkLayerPacket(model::packets::ScoConnectionRequestBuilder::Create( - GetAddress(), bd_addr, connection_parameters.transmit_bandwidth, - connection_parameters.receive_bandwidth, - connection_parameters.max_latency, connection_parameters.voice_setting, - connection_parameters.retransmission_effort, - connection_parameters.packet_type, class_of_device_)); + GetAddress(), bd_addr, connection_parameters.transmit_bandwidth, + connection_parameters.receive_bandwidth, connection_parameters.max_latency, + connection_parameters.voice_setting, connection_parameters.retransmission_effort, + connection_parameters.packet_type, class_of_device_)); 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, - ScoDatapath datapath) { + 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, ScoDatapath datapath) { if (!connections_.HasHandle(connection_handle)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -6283,24 +5885,23 @@ ErrorCode LinkLayerController::SetupSynchronousConnection( INFO(id_, "Creating eSCO connection with {}", bd_addr); // Save connection parameters. - ScoConnectionParameters connection_parameters = { - transmit_bandwidth, receive_bandwidth, max_latency, - voice_setting, retransmission_effort, packet_types}; - connections_.CreateScoConnection( - connections_.GetAddress(connection_handle).GetAddress(), - connection_parameters, SCO_STATE_PENDING, datapath); + ScoConnectionParameters connection_parameters = {transmit_bandwidth, receive_bandwidth, + max_latency, voice_setting, + retransmission_effort, packet_types}; + connections_.CreateScoConnection(connections_.GetAddress(connection_handle).GetAddress(), + connection_parameters, SCO_STATE_PENDING, datapath); // Send eSCO connection request to peer. SendLinkLayerPacket(model::packets::ScoConnectionRequestBuilder::Create( - GetAddress(), bd_addr, transmit_bandwidth, receive_bandwidth, max_latency, - voice_setting, retransmission_effort, packet_types, class_of_device_)); + GetAddress(), bd_addr, transmit_bandwidth, receive_bandwidth, max_latency, voice_setting, + retransmission_effort, packet_types, class_of_device_)); 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, - uint16_t packet_types) { + 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) { INFO(id_, "Accepting eSCO connection request from {}", bd_addr); if (!connections_.HasPendingScoConnection(bd_addr)) { @@ -6311,14 +5912,13 @@ ErrorCode LinkLayerController::AcceptSynchronousConnection( ErrorCode status = ErrorCode::SUCCESS; uint16_t sco_handle = 0; ScoLinkParameters link_parameters = {}; - ScoConnectionParameters connection_parameters = { - transmit_bandwidth, receive_bandwidth, max_latency, - voice_setting, retransmission_effort, packet_types}; + ScoConnectionParameters connection_parameters = {transmit_bandwidth, receive_bandwidth, + max_latency, voice_setting, + retransmission_effort, packet_types}; - if (!connections_.AcceptPendingScoConnection( - bd_addr, connection_parameters, [this, bd_addr] { - return LinkLayerController::StartScoStream(bd_addr); - })) { + if (!connections_.AcceptPendingScoConnection(bd_addr, connection_parameters, [this, bd_addr] { + return LinkLayerController::StartScoStream(bd_addr); + })) { connections_.CancelPendingScoConnection(bd_addr); status = ErrorCode::STATUS_UNKNOWN; // TODO: proper status code } else { @@ -6328,31 +5928,27 @@ ErrorCode LinkLayerController::AcceptSynchronousConnection( // Send eSCO connection response to peer. SendLinkLayerPacket(model::packets::ScoConnectionResponseBuilder::Create( - 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.extended)); + 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.extended)); // Schedule HCI Synchronous Connection Complete event. - ScheduleTask(kNoDelayMs, [this, status, sco_handle, bd_addr, - link_parameters]() { + ScheduleTask(kNoDelayMs, [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))); + 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) { INFO(id_, "Rejecting eSCO connection request from {}", bd_addr); if (reason == (uint8_t)ErrorCode::SUCCESS) { @@ -6366,13 +5962,13 @@ ErrorCode LinkLayerController::RejectSynchronousConnection(Address bd_addr, // Send eSCO connection response to peer. SendLinkLayerPacket(model::packets::ScoConnectionResponseBuilder::Create( - GetAddress(), bd_addr, reason, 0, 0, 0, 0, 0, 0)); + GetAddress(), bd_addr, reason, 0, 0, 0, 0, 0, 0)); // Schedule HCI Synchronous Connection Complete event. ScheduleTask(kNoDelayMs, [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; @@ -6384,43 +5980,41 @@ void LinkLayerController::CheckExpiringConnection(uint16_t handle) { } if (connections_.HasLinkExpired(handle)) { - Disconnect(handle, ErrorCode::CONNECTION_TIMEOUT, - ErrorCode::CONNECTION_TIMEOUT); + Disconnect(handle, ErrorCode::CONNECTION_TIMEOUT, ErrorCode::CONNECTION_TIMEOUT); return; } if (connections_.IsLinkNearExpiring(handle)) { AddressWithType my_address = connections_.GetOwnAddress(handle); AddressWithType destination = connections_.GetAddress(handle); - SendLinkLayerPacket(model::packets::PingRequestBuilder::Create( - my_address.GetAddress(), destination.GetAddress())); - ScheduleTask(std::chrono::duration_cast( - connections_.TimeUntilLinkExpired(handle)), - [this, handle] { CheckExpiringConnection(handle); }); + SendLinkLayerPacket(model::packets::PingRequestBuilder::Create(my_address.GetAddress(), + destination.GetAddress())); + ScheduleTask( + std::chrono::duration_cast(connections_.TimeUntilLinkExpired(handle)), + [this, handle] { CheckExpiringConnection(handle); }); return; } - ScheduleTask(std::chrono::duration_cast( - connections_.TimeUntilLinkNearExpiring(handle)), - [this, handle] { CheckExpiringConnection(handle); }); + ScheduleTask( + std::chrono::duration_cast(connections_.TimeUntilLinkNearExpiring(handle)), + [this, handle] { CheckExpiringConnection(handle); }); } -void LinkLayerController::IncomingPingRequest( - model::packets::LinkLayerPacketView incoming) { +void LinkLayerController::IncomingPingRequest(model::packets::LinkLayerPacketView incoming) { auto view = model::packets::PingRequestView::Create(incoming); ASSERT(view.IsValid()); - SendLinkLayerPacket(model::packets::PingResponseBuilder::Create( - incoming.GetDestinationAddress(), incoming.GetSourceAddress())); + SendLinkLayerPacket(model::packets::PingResponseBuilder::Create(incoming.GetDestinationAddress(), + incoming.GetSourceAddress())); } TaskId LinkLayerController::StartScoStream(Address address) { - auto sco_builder = bluetooth::hci::ScoBuilder::Create( - connections_.GetScoHandle(address), PacketStatusFlag::CORRECTLY_RECEIVED, - {0, 0, 0, 0, 0}); + auto sco_builder = + bluetooth::hci::ScoBuilder::Create(connections_.GetScoHandle(address), + PacketStatusFlag::CORRECTLY_RECEIVED, {0, 0, 0, 0, 0}); auto sco_bytes = sco_builder->SerializeToBytes(); - auto sco_view = bluetooth::hci::ScoView::Create(pdl::packet::slice( - std::make_shared>(std::move(sco_bytes)))); + auto sco_view = bluetooth::hci::ScoView::Create( + pdl::packet::slice(std::make_shared>(std::move(sco_bytes)))); ASSERT(sco_view.IsValid()); return SchedulePeriodicTask(0ms, 20ms, [this, address, sco_view]() { @@ -6431,10 +6025,9 @@ TaskId LinkLayerController::StartScoStream(Address address) { TaskId LinkLayerController::NextTaskId() { TaskId task_id = task_counter_++; - while ( - task_id == kInvalidTaskId || - std::any_of(task_queue_.begin(), task_queue_.end(), - [=](Task const& task) { return task.task_id == task_id; })) { + while (task_id == kInvalidTaskId || + std::any_of(task_queue_.begin(), task_queue_.end(), + [=](Task const& task) { return task.task_id == task_id; })) { task_id = task_counter_++; } return task_id; @@ -6443,17 +6036,16 @@ TaskId LinkLayerController::NextTaskId() { TaskId LinkLayerController::ScheduleTask(std::chrono::milliseconds delay, TaskCallback task_callback) { TaskId task_id = NextTaskId(); - task_queue_.emplace(std::chrono::steady_clock::now() + delay, - std::move(task_callback), task_id); + task_queue_.emplace(std::chrono::steady_clock::now() + delay, std::move(task_callback), task_id); return task_id; } -TaskId LinkLayerController::SchedulePeriodicTask( - std::chrono::milliseconds delay, std::chrono::milliseconds period, - TaskCallback task_callback) { +TaskId LinkLayerController::SchedulePeriodicTask(std::chrono::milliseconds delay, + std::chrono::milliseconds period, + TaskCallback task_callback) { TaskId task_id = NextTaskId(); - task_queue_.emplace(std::chrono::steady_clock::now() + delay, period, - std::move(task_callback), task_id); + task_queue_.emplace(std::chrono::steady_clock::now() + delay, period, std::move(task_callback), + task_id); return task_id; } diff --git a/model/controller/link_layer_controller.h b/model/controller/link_layer_controller.h index 57e4cbf..75a8fd3 100644 --- a/model/controller/link_layer_controller.h +++ b/model/controller/link_layer_controller.h @@ -55,15 +55,13 @@ using ::bluetooth::hci::PageScanRepetitionMode; using rootcanal::apcf::ApcfScanner; // Create an address with type Public Device Address or Random Device Address. -AddressWithType PeerDeviceAddress(Address address, - PeerAddressType peer_address_type); +AddressWithType PeerDeviceAddress(Address address, PeerAddressType peer_address_type); // Create an address with type Public Identity Address or Random Identity // address. -AddressWithType PeerIdentityAddress(Address address, - PeerAddressType peer_address_type); +AddressWithType PeerIdentityAddress(Address address, PeerAddressType peer_address_type); class LinkLayerController { - public: +public: static constexpr size_t kIrkSize = 16; static constexpr size_t kLtkSize = 16; static constexpr size_t kLocalNameSize = 248; @@ -73,24 +71,20 @@ class LinkLayerController { const uint32_t id_; // Generate a resolvable private address using the specified IRK. - static Address generate_rpa( - std::array irk); + static Address generate_rpa(std::array irk); // Return true if the input IRK is all 0s. static bool irk_is_zero(std::array irk); - LinkLayerController(const Address& address, - const ControllerProperties& properties, uint32_t id = 0); + LinkLayerController(const Address& address, const ControllerProperties& properties, + uint32_t id = 0); ~LinkLayerController(); ErrorCode SendCommandToRemoteByAddress(OpCode opcode, pdl::packet::slice args, - const Address& own_address, - const Address& peer_address); - ErrorCode SendLeCommandToRemoteByAddress(OpCode opcode, - const Address& own_address, + const Address& own_address, const Address& peer_address); + ErrorCode SendLeCommandToRemoteByAddress(OpCode opcode, const Address& own_address, const Address& peer_address); - ErrorCode SendCommandToRemoteByHandle(OpCode opcode, pdl::packet::slice args, - uint16_t handle); + ErrorCode SendCommandToRemoteByHandle(OpCode opcode, pdl::packet::slice args, uint16_t handle); ErrorCode SendScoToRemote(bluetooth::hci::ScoView sco_packet); ErrorCode SendAclToRemote(bluetooth::hci::AclView acl_packet); @@ -106,17 +100,16 @@ class LinkLayerController { void RejectPeripheralConnection(const Address& addr, uint8_t reason); // HCI command Create Connection (Vol 4, Part E § 7.1.5). - ErrorCode CreateConnection(const Address& bd_addr, uint16_t packet_type, - uint8_t page_scan_mode, uint16_t clock_offset, - uint8_t allow_role_switch); + ErrorCode CreateConnection(const Address& bd_addr, uint16_t packet_type, uint8_t page_scan_mode, + uint16_t clock_offset, uint8_t allow_role_switch); // HCI command Disconnect (Vol 4, Part E § 7.1.6). // \p host_reason is taken from the Disconnect command, and sent over // to the remote as disconnect error. \p controller_reason is the code // used in the DisconnectionComplete event. - ErrorCode Disconnect(uint16_t handle, ErrorCode host_reason, - ErrorCode controller_reason = - ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST); + ErrorCode Disconnect( + uint16_t handle, ErrorCode host_reason, + ErrorCode controller_reason = ErrorCode::CONNECTION_TERMINATED_BY_LOCAL_HOST); // HCI command Create Connection Cancel (Vol 4, Part E § 7.1.7). ErrorCode CreateConnectionCancel(const Address& bd_addr); @@ -130,15 +123,13 @@ class LinkLayerController { static constexpr TaskId kInvalidTaskId = 0; /// Schedule a task to be executed \p delay ms in the future. - TaskId ScheduleTask(std::chrono::milliseconds delay, - TaskCallback task_callback); + TaskId ScheduleTask(std::chrono::milliseconds delay, TaskCallback task_callback); /// Schedule a task to be executed every \p period ms starting /// \p delay ms in the future. Note that the task will be executed /// at most once per \ref Tick() invocation, hence the period /// cannot be lower than the \ref Tick() period. - TaskId SchedulePeriodicTask(std::chrono::milliseconds delay, - std::chrono::milliseconds period, + TaskId SchedulePeriodicTask(std::chrono::milliseconds delay, std::chrono::milliseconds period, TaskCallback task_callback); /// Cancel the selected task. @@ -147,14 +138,13 @@ class LinkLayerController { // Execute tasks that are pending at the current time. void RunPendingTasks(); - private: +private: void SendDisconnectionCompleteEvent(uint16_t handle, ErrorCode reason); - public: +public: const Address& GetAddress() const; - void IncomingPacket(model::packets::LinkLayerPacketView incoming, - int8_t rssi); + void IncomingPacket(model::packets::LinkLayerPacketView incoming, int8_t rssi); void Tick(); @@ -162,25 +152,20 @@ class LinkLayerController { // Set the callbacks for sending packets to the HCI. void RegisterEventChannel( - const std::function)>& - send_event); + const std::function)>& send_event); void RegisterAclChannel( - const std::function)>& - send_acl); + const std::function)>& send_acl); void RegisterScoChannel( - const std::function)>& - send_sco); + const std::function)>& send_sco); void RegisterIsoChannel( - const std::function)>& - send_iso); + const std::function)>& send_iso); void RegisterRemoteChannel( - const std::function< - void(std::shared_ptr, - Phy::Type, int8_t)>& send_to_remote); + const std::function, + Phy::Type, int8_t)>& send_to_remote); void Reset(); @@ -189,35 +174,31 @@ class LinkLayerController { void LeScanning(); void LeSynchronization(); - void LeConnectionUpdateComplete(uint16_t handle, uint16_t interval_min, - uint16_t interval_max, uint16_t latency, - uint16_t supervision_timeout); - ErrorCode LeConnectionUpdate(uint16_t handle, uint16_t interval_min, - uint16_t interval_max, uint16_t latency, - uint16_t supervision_timeout); - ErrorCode LeRemoteConnectionParameterRequestReply( - uint16_t connection_handle, uint16_t interval_min, uint16_t interval_max, - uint16_t timeout, uint16_t latency, uint16_t minimum_ce_length, - uint16_t maximum_ce_length); - ErrorCode LeRemoteConnectionParameterRequestNegativeReply( - uint16_t connection_handle, bluetooth::hci::ErrorCode reason); + void LeConnectionUpdateComplete(uint16_t handle, uint16_t interval_min, uint16_t interval_max, + uint16_t latency, uint16_t supervision_timeout); + ErrorCode LeConnectionUpdate(uint16_t handle, uint16_t interval_min, uint16_t interval_max, + uint16_t latency, uint16_t supervision_timeout); + ErrorCode LeRemoteConnectionParameterRequestReply(uint16_t connection_handle, + uint16_t interval_min, uint16_t interval_max, + uint16_t timeout, uint16_t latency, + uint16_t minimum_ce_length, + uint16_t maximum_ce_length); + ErrorCode LeRemoteConnectionParameterRequestNegativeReply(uint16_t connection_handle, + bluetooth::hci::ErrorCode reason); uint16_t HandleLeConnection(AddressWithType addr, AddressWithType own_addr, - bluetooth::hci::Role role, - uint16_t connection_interval, - uint16_t connection_latency, - uint16_t supervision_timeout, + bluetooth::hci::Role role, uint16_t connection_interval, + uint16_t connection_latency, uint16_t supervision_timeout, bool send_le_channel_selection_algorithm_event); bool ResolvingListBusy(); bool FilterAcceptListBusy(); - bool LeFilterAcceptListContainsDevice( - FilterAcceptListAddressType address_type, Address address); + bool LeFilterAcceptListContainsDevice(FilterAcceptListAddressType address_type, Address address); bool LeFilterAcceptListContainsDevice(AddressWithType address); bool LePeriodicAdvertiserListContainsDevice( - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint8_t advertising_sid); + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint8_t advertising_sid); enum IrkSelection { Peer, // Use Peer IRK for RPA resolution or generation. @@ -244,8 +225,8 @@ class LinkLayerController { // If the address is not found in the resolving list none is returned. // `local` indicates whether to use the local (true) or peer (false) IRK when // generating the Resolvable Private Address. - std::optional GenerateResolvablePrivateAddress( - AddressWithType address, IrkSelection irk); + std::optional GenerateResolvablePrivateAddress(AddressWithType address, + IrkSelection irk); // Check if the selected address matches one of the controller's device // addresses (public or random static). @@ -260,16 +241,13 @@ class LinkLayerController { } } - void HandleLeEnableEncryption(uint16_t handle, std::array rand, - uint16_t ediv, + void HandleLeEnableEncryption(uint16_t handle, std::array rand, uint16_t ediv, std::array ltk); - ErrorCode LeEnableEncryption(uint16_t handle, std::array rand, - uint16_t ediv, + ErrorCode LeEnableEncryption(uint16_t handle, std::array rand, uint16_t ediv, std::array ltk); - ErrorCode LeLongTermKeyRequestReply(uint16_t handle, - std::array ltk); + ErrorCode LeLongTermKeyRequestReply(uint16_t handle, std::array ltk); ErrorCode LeLongTermKeyRequestNegativeReply(uint16_t handle); @@ -298,20 +276,17 @@ class LinkLayerController { ErrorCode CentralLinkKey(uint8_t key_flag); ErrorCode HoldMode(uint16_t handle, uint16_t hold_mode_max_interval, uint16_t hold_mode_min_interval); - ErrorCode SniffMode(uint16_t handle, uint16_t sniff_max_interval, - uint16_t sniff_min_interval, uint16_t sniff_attempt, - uint16_t sniff_timeout); + ErrorCode SniffMode(uint16_t handle, uint16_t sniff_max_interval, uint16_t sniff_min_interval, + uint16_t sniff_attempt, uint16_t sniff_timeout); ErrorCode ExitSniffMode(uint16_t handle); ErrorCode QosSetup(uint16_t handle, uint8_t service_type, uint32_t token_rate, - uint32_t peak_bandwidth, uint32_t latency, - uint32_t delay_variation); + uint32_t peak_bandwidth, uint32_t latency, uint32_t delay_variation); ErrorCode RoleDiscovery(uint16_t handle, bluetooth::hci::Role* role); ErrorCode SwitchRole(Address bd_addr, bluetooth::hci::Role role); ErrorCode ReadLinkPolicySettings(uint16_t handle, uint16_t* settings); ErrorCode WriteLinkPolicySettings(uint16_t handle, uint16_t settings); - ErrorCode FlowSpecification(uint16_t handle, uint8_t flow_direction, - uint8_t service_type, uint32_t token_rate, - uint32_t token_bucket_size, + ErrorCode FlowSpecification(uint16_t handle, uint8_t flow_direction, uint8_t service_type, + uint32_t token_rate, uint32_t token_bucket_size, uint32_t peak_bandwidth, uint32_t access_latency); ErrorCode WriteLinkSupervisionTimeout(uint16_t handle, uint16_t timeout); ErrorCode WriteDefaultLinkPolicySettings(uint16_t settings); @@ -323,15 +298,14 @@ class LinkLayerController { ErrorCode AddScoConnection(uint16_t connection_handle, uint16_t packet_type, ScoDatapath datapath); - 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, - ScoDatapath datapath); - 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 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, ScoDatapath datapath); + 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); // Returns true if any ACL connection exists. @@ -356,20 +330,17 @@ class LinkLayerController { ErrorCode LeSetResolvablePrivateAddressTimeout(uint16_t rpa_timeout); // HCI LE Read Phy command (Vol 4, Part E § 7.8.47). - ErrorCode LeReadPhy(uint16_t connection_handle, - bluetooth::hci::PhyType* tx_phy, + ErrorCode LeReadPhy(uint16_t connection_handle, bluetooth::hci::PhyType* tx_phy, bluetooth::hci::PhyType* rx_phy); // HCI LE Set Default Phy command (Vol 4, Part E § 7.8.48). ErrorCode LeSetDefaultPhy(bool all_phys_no_transmit_preference, - bool all_phys_no_receive_preference, - uint8_t tx_phys, uint8_t rx_phys); + bool all_phys_no_receive_preference, uint8_t tx_phys, uint8_t rx_phys); // HCI LE Set Phy command (Vol 4, Part E § 7.8.49). - ErrorCode LeSetPhy(uint16_t connection_handle, - bool all_phys_no_transmit_preference, - bool all_phys_no_receive_preference, uint8_t tx_phys, - uint8_t rx_phys, bluetooth::hci::PhyOptions phy_options); + ErrorCode LeSetPhy(uint16_t connection_handle, bool all_phys_no_transmit_preference, + bool all_phys_no_receive_preference, uint8_t tx_phys, uint8_t rx_phys, + bluetooth::hci::PhyOptions phy_options); // HCI LE Set Host Feature command (Vol 4, Part E § 7.8.115). ErrorCode LeSetHostFeature(uint8_t bit_number, uint8_t bit_value); @@ -380,39 +351,38 @@ class LinkLayerController { ErrorCode LeClearFilterAcceptList(); // HCI command LE_Add_Device_To_Filter_Accept_List (Vol 4, Part E § 7.8.16). - ErrorCode LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType address_type, Address address); + ErrorCode LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType address_type, + Address address); // HCI command LE_Remove_Device_From_Filter_Accept_List (Vol 4, Part E // § 7.8.17). - ErrorCode LeRemoveDeviceFromFilterAcceptList( - FilterAcceptListAddressType address_type, Address address); + ErrorCode LeRemoveDeviceFromFilterAcceptList(FilterAcceptListAddressType address_type, + Address address); // LE Address Resolving // HCI command LE_Add_Device_To_Resolving_List (Vol 4, Part E § 7.8.38). - ErrorCode LeAddDeviceToResolvingList( - PeerAddressType peer_identity_address_type, Address peer_identity_address, - std::array peer_irk, - std::array local_irk); + ErrorCode LeAddDeviceToResolvingList(PeerAddressType peer_identity_address_type, + Address peer_identity_address, + std::array peer_irk, + std::array local_irk); // HCI command LE_Remove_Device_From_Resolving_List (Vol 4, Part E § 7.8.39). - ErrorCode LeRemoveDeviceFromResolvingList( - PeerAddressType peer_identity_address_type, - Address peer_identity_address); + ErrorCode LeRemoveDeviceFromResolvingList(PeerAddressType peer_identity_address_type, + Address peer_identity_address); // HCI command LE_Clear_Resolving_List (Vol 4, Part E § 7.8.40). ErrorCode LeClearResolvingList(); // HCI command LE_Read_Peer_Resolvable_Address (Vol 4, Part E § 7.8.42). - ErrorCode LeReadPeerResolvableAddress( - PeerAddressType peer_identity_address_type, Address peer_identity_address, - Address* peer_resolvable_address); + ErrorCode LeReadPeerResolvableAddress(PeerAddressType peer_identity_address_type, + Address peer_identity_address, + Address* peer_resolvable_address); // HCI command LE_Read_Local_Resolvable_Address (Vol 4, Part E § 7.8.43). - ErrorCode LeReadLocalResolvableAddress( - PeerAddressType peer_identity_address_type, Address peer_identity_address, - Address* local_resolvable_address); + ErrorCode LeReadLocalResolvableAddress(PeerAddressType peer_identity_address_type, + Address peer_identity_address, + Address* local_resolvable_address); // HCI command LE_Set_Address_Resolution_Enable (Vol 4, Part E § 7.8.44). ErrorCode LeSetAddressResolutionEnable(bool enable); @@ -426,19 +396,18 @@ class LinkLayerController { // HCI command LE_Set_Advertising_Parameters (Vol 4, Part E § 7.8.5). ErrorCode LeSetAdvertisingParameters( - uint16_t advertising_interval_min, uint16_t advertising_interval_max, - bluetooth::hci::AdvertisingType advertising_type, - bluetooth::hci::OwnAddressType own_address_type, - bluetooth::hci::PeerAddressType peer_address_type, Address peer_address, - uint8_t advertising_channel_map, - bluetooth::hci::AdvertisingFilterPolicy advertising_filter_policy); + uint16_t advertising_interval_min, uint16_t advertising_interval_max, + bluetooth::hci::AdvertisingType advertising_type, + bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::PeerAddressType peer_address_type, Address peer_address, + uint8_t advertising_channel_map, + bluetooth::hci::AdvertisingFilterPolicy advertising_filter_policy); // HCI command LE_Set_Advertising_Data (Vol 4, Part E § 7.8.7). ErrorCode LeSetAdvertisingData(const std::vector& advertising_data); // HCI command LE_Set_Scan_Response_Data (Vol 4, Part E § 7.8.8). - ErrorCode LeSetScanResponseData( - const std::vector& scan_response_data); + ErrorCode LeSetScanResponseData(const std::vector& scan_response_data); // HCI command LE_Advertising_Enable (Vol 4, Part E § 7.8.9). ErrorCode LeSetAdvertisingEnable(bool advertising_enable); @@ -446,40 +415,34 @@ class LinkLayerController { // Extended Advertising // HCI command LE_Set_Advertising_Set_Random_Address (Vol 4, Part E § 7.8.52). - ErrorCode LeSetAdvertisingSetRandomAddress(uint8_t advertising_handle, - Address random_address); + ErrorCode LeSetAdvertisingSetRandomAddress(uint8_t advertising_handle, Address random_address); // HCI command LE_Set_Advertising_Parameters (Vol 4, Part E § 7.8.53). ErrorCode LeSetExtendedAdvertisingParameters( - uint8_t advertising_handle, - AdvertisingEventProperties advertising_event_properties, - uint16_t primary_advertising_interval_min, - uint16_t primary_advertising_interval_max, - uint8_t primary_advertising_channel_map, - bluetooth::hci::OwnAddressType own_address_type, - bluetooth::hci::PeerAddressType peer_address_type, Address peer_address, - bluetooth::hci::AdvertisingFilterPolicy advertising_filter_policy, - uint8_t advertising_tx_power, - bluetooth::hci::PrimaryPhyType primary_advertising_phy, - uint8_t secondary_max_skip, - bluetooth::hci::SecondaryPhyType secondary_advertising_phy, - uint8_t advertising_sid, bool scan_request_notification_enable); + uint8_t advertising_handle, AdvertisingEventProperties advertising_event_properties, + uint16_t primary_advertising_interval_min, uint16_t primary_advertising_interval_max, + uint8_t primary_advertising_channel_map, bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::PeerAddressType peer_address_type, Address peer_address, + bluetooth::hci::AdvertisingFilterPolicy advertising_filter_policy, + uint8_t advertising_tx_power, bluetooth::hci::PrimaryPhyType primary_advertising_phy, + uint8_t secondary_max_skip, bluetooth::hci::SecondaryPhyType secondary_advertising_phy, + uint8_t advertising_sid, bool scan_request_notification_enable); // HCI command LE_Set_Extended_Advertising_Data (Vol 4, Part E § 7.8.54). - ErrorCode LeSetExtendedAdvertisingData( - uint8_t advertising_handle, bluetooth::hci::Operation operation, - bluetooth::hci::FragmentPreference fragment_preference, - const std::vector& advertising_data); + ErrorCode LeSetExtendedAdvertisingData(uint8_t advertising_handle, + bluetooth::hci::Operation operation, + bluetooth::hci::FragmentPreference fragment_preference, + const std::vector& advertising_data); // HCI command LE_Set_Extended_Scan_Response_Data (Vol 4, Part E § 7.8.55). - ErrorCode LeSetExtendedScanResponseData( - uint8_t advertising_handle, bluetooth::hci::Operation operation, - bluetooth::hci::FragmentPreference fragment_preference, - const std::vector& scan_response_data); + ErrorCode LeSetExtendedScanResponseData(uint8_t advertising_handle, + bluetooth::hci::Operation operation, + bluetooth::hci::FragmentPreference fragment_preference, + const std::vector& scan_response_data); // HCI command LE_Set_Extended_Advertising_Enable (Vol 4, Part E § 7.8.56). - ErrorCode LeSetExtendedAdvertisingEnable( - bool enable, const std::vector& sets); + ErrorCode LeSetExtendedAdvertisingEnable(bool enable, + const std::vector& sets); // HCI command LE_Remove_Advertising_Set (Vol 4, Part E § 7.8.59). ErrorCode LeRemoveAdvertisingSet(uint8_t advertising_handle); @@ -490,10 +453,10 @@ class LinkLayerController { // Legacy Scanning // HCI command LE_Set_Scan_Parameters (Vol 4, Part E § 7.8.10). - ErrorCode LeSetScanParameters( - bluetooth::hci::LeScanType scan_type, uint16_t scan_interval, - uint16_t scan_window, bluetooth::hci::OwnAddressType own_address_type, - bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy); + ErrorCode LeSetScanParameters(bluetooth::hci::LeScanType scan_type, uint16_t scan_interval, + uint16_t scan_window, + bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy); // HCI command LE_Set_Scan_Enable (Vol 4, Part E § 7.8.11). ErrorCode LeSetScanEnable(bool enable, bool filter_duplicates); @@ -502,28 +465,24 @@ class LinkLayerController { // HCI command LE_Set_Extended_Scan_Parameters (Vol 4, Part E § 7.8.64). ErrorCode LeSetExtendedScanParameters( - bluetooth::hci::OwnAddressType own_address_type, - bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy, - uint8_t scanning_phys, - std::vector - scanning_phy_parameters); + bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy, uint8_t scanning_phys, + std::vector scanning_phy_parameters); // HCI command LE_Set_Extended_Scan_Enable (Vol 4, Part E § 7.8.65). - ErrorCode LeSetExtendedScanEnable( - bool enable, bluetooth::hci::FilterDuplicates filter_duplicates, - uint16_t duration, uint16_t period); + ErrorCode LeSetExtendedScanEnable(bool enable, bluetooth::hci::FilterDuplicates filter_duplicates, + uint16_t duration, uint16_t period); // Legacy Connection // HCI LE Create Connection command (Vol 4, Part E § 7.8.12). - ErrorCode LeCreateConnection( - uint16_t scan_interval, uint16_t scan_window, - bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, - AddressWithType peer_address, - bluetooth::hci::OwnAddressType own_address_type, - uint16_t connection_interval_min, uint16_t connection_interval_max, - uint16_t max_latency, uint16_t supervision_timeout, - uint16_t min_ce_length, uint16_t max_ce_length); + ErrorCode LeCreateConnection(uint16_t scan_interval, uint16_t scan_window, + bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, + AddressWithType peer_address, + bluetooth::hci::OwnAddressType own_address_type, + uint16_t connection_interval_min, uint16_t connection_interval_max, + uint16_t max_latency, uint16_t supervision_timeout, + uint16_t min_ce_length, uint16_t max_ce_length); // HCI LE Create Connection Cancel command (Vol 4, Part E § 7.8.12). ErrorCode LeCreateConnectionCancel(); @@ -532,24 +491,24 @@ class LinkLayerController { // HCI LE Extended Create Connection command (Vol 4, Part E § 7.8.66). ErrorCode LeExtendedCreateConnection( - bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, - bluetooth::hci::OwnAddressType own_address_type, - AddressWithType peer_address, uint8_t initiating_phys, - std::vector - initiating_phy_parameters); + bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, + bluetooth::hci::OwnAddressType own_address_type, AddressWithType peer_address, + uint8_t initiating_phys, + std::vector initiating_phy_parameters); // Periodic Advertising // HCI LE Set Periodic Advertising Parameters command (Vol 4, Part E // § 7.8.61). - ErrorCode LeSetPeriodicAdvertisingParameters( - uint8_t advertising_handle, uint16_t periodic_advertising_interval_min, - uint16_t periodic_advertising_interval_max, bool include_tx_power); + ErrorCode LeSetPeriodicAdvertisingParameters(uint8_t advertising_handle, + uint16_t periodic_advertising_interval_min, + uint16_t periodic_advertising_interval_max, + bool include_tx_power); // HCI LE Set Periodic Advertising Data command (Vol 4, Part E § 7.8.62). - ErrorCode LeSetPeriodicAdvertisingData( - uint8_t advertising_handle, bluetooth::hci::Operation operation, - const std::vector& advertising_data); + ErrorCode LeSetPeriodicAdvertisingData(uint8_t advertising_handle, + bluetooth::hci::Operation operation, + const std::vector& advertising_data); // HCI LE Set Periodic Advertising Enable command (Vol 4, Part E § 7.8.63). ErrorCode LeSetPeriodicAdvertisingEnable(bool enable, bool include_adi, @@ -559,11 +518,9 @@ class LinkLayerController { // HCI LE Periodic Advertising Create Sync command (Vol 4, Part E § 7.8.67). ErrorCode LePeriodicAdvertisingCreateSync( - bluetooth::hci::PeriodicAdvertisingOptions options, - uint8_t advertising_sid, - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint16_t skip, uint16_t sync_timeout, - uint8_t sync_cte_type); + bluetooth::hci::PeriodicAdvertisingOptions options, uint8_t advertising_sid, + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint16_t skip, uint16_t sync_timeout, uint8_t sync_cte_type); // HCI LE Periodic Advertising Create Sync Cancel command (Vol 4, Part E // § 7.8.68). @@ -578,14 +535,14 @@ class LinkLayerController { // HCI LE Add Device To Periodic Advertiser List command (Vol 4, Part E // § 7.8.70). ErrorCode LeAddDeviceToPeriodicAdvertiserList( - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint8_t advertising_sid); + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint8_t advertising_sid); // HCI LE Remove Device From Periodic Advertiser List command // (Vol 4, Part E § 7.8.71). ErrorCode LeRemoveDeviceFromPeriodicAdvertiserList( - bluetooth::hci::AdvertiserAddressType advertiser_address_type, - Address advertiser_address, uint8_t advertising_sid); + bluetooth::hci::AdvertiserAddressType advertiser_address_type, Address advertiser_address, + uint8_t advertising_sid); // HCI LE Clear Periodic Advertiser List command (Vol 4, Part E § 7.8.72). ErrorCode LeClearPeriodicAdvertiserList(); @@ -594,13 +551,14 @@ class LinkLayerController { ErrorCode LeApcfEnable(bool apcf_enable); - ErrorCode LeApcfAddFilteringParameters( - uint8_t apcf_filter_index, uint16_t apcf_feature_selection, - uint16_t apcf_list_logic_type, uint8_t apcf_filter_logic_type, - uint8_t rssi_high_thresh, bluetooth::hci::DeliveryMode delivery_mode, - uint16_t onfound_timeout, uint8_t onfound_timeout_cnt, - uint8_t rssi_low_thresh, uint16_t onlost_timeout, - uint16_t num_of_tracking_entries, uint8_t* apcf_available_spaces); + ErrorCode LeApcfAddFilteringParameters(uint8_t apcf_filter_index, uint16_t apcf_feature_selection, + uint16_t apcf_list_logic_type, + uint8_t apcf_filter_logic_type, uint8_t rssi_high_thresh, + bluetooth::hci::DeliveryMode delivery_mode, + uint16_t onfound_timeout, uint8_t onfound_timeout_cnt, + uint8_t rssi_low_thresh, uint16_t onlost_timeout, + uint16_t num_of_tracking_entries, + uint8_t* apcf_available_spaces); ErrorCode LeApcfDeleteFilteringParameters(uint8_t apcf_filter_index, uint8_t* apcf_available_spaces); @@ -608,145 +566,106 @@ class LinkLayerController { ErrorCode LeApcfClearFilteringParameters(uint8_t* apcf_available_spaces); ErrorCode LeApcfBroadcasterAddress( - bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, - bluetooth::hci::Address apcf_broadcaster_address, - bluetooth::hci::ApcfApplicationAddressType apcf_application_address_type, - uint8_t* apcf_available_spaces); - - ErrorCode LeApcfServiceUuid(bluetooth::hci::ApcfAction apcf_action, - uint8_t apcf_filter_index, - std::vector acpf_uuid_data, - uint8_t* apcf_available_spaces); + bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, + bluetooth::hci::Address apcf_broadcaster_address, + bluetooth::hci::ApcfApplicationAddressType apcf_application_address_type, + uint8_t* apcf_available_spaces); + + ErrorCode LeApcfServiceUuid(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector acpf_uuid_data, uint8_t* apcf_available_spaces); - ErrorCode LeApcfServiceSolicitationUuid( - bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, - std::vector acpf_uuid_data, uint8_t* apcf_available_spaces); + ErrorCode LeApcfServiceSolicitationUuid(bluetooth::hci::ApcfAction apcf_action, + uint8_t apcf_filter_index, + std::vector acpf_uuid_data, + uint8_t* apcf_available_spaces); - ErrorCode LeApcfLocalName(bluetooth::hci::ApcfAction apcf_action, - uint8_t apcf_filter_index, - std::vector apcf_local_name, - uint8_t* apcf_available_spaces); + ErrorCode LeApcfLocalName(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector apcf_local_name, uint8_t* apcf_available_spaces); ErrorCode LeApcfManufacturerData(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, std::vector apcf_manufacturer_data, uint8_t* apcf_available_spaces); - ErrorCode LeApcfServiceData(bluetooth::hci::ApcfAction apcf_action, - uint8_t apcf_filter_index, + ErrorCode LeApcfServiceData(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, std::vector apcf_service_data, uint8_t* apcf_available_spaces); - ErrorCode LeApcfAdTypeFilter(bluetooth::hci::ApcfAction apcf_action, - uint8_t apcf_filter_index, uint8_t ad_type, - std::vector apcf_ad_data, + ErrorCode LeApcfAdTypeFilter(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, + uint8_t ad_type, std::vector apcf_ad_data, std::vector apcf_ad_data_mask, uint8_t* apcf_available_spaces); - protected: - void SendLinkLayerPacket( - std::unique_ptr packet, - int8_t tx_power = 0); - void SendLeLinkLayerPacket( - std::unique_ptr packet, - int8_t tx_power = 0); +protected: + void SendLinkLayerPacket(std::unique_ptr packet, + int8_t tx_power = 0); + void SendLeLinkLayerPacket(std::unique_ptr packet, + int8_t tx_power = 0); - void IncomingAclPacket(model::packets::LinkLayerPacketView incoming, - int8_t rssi); + void IncomingAclPacket(model::packets::LinkLayerPacketView incoming, int8_t rssi); void IncomingScoPacket(model::packets::LinkLayerPacketView incoming); void IncomingDisconnectPacket(model::packets::LinkLayerPacketView incoming); void IncomingEncryptConnection(model::packets::LinkLayerPacketView incoming); - void IncomingEncryptConnectionResponse( - model::packets::LinkLayerPacketView incoming); - void IncomingInquiryPacket(model::packets::LinkLayerPacketView incoming, - uint8_t rssi); - void IncomingInquiryResponsePacket( - model::packets::LinkLayerPacketView incoming); + void IncomingEncryptConnectionResponse(model::packets::LinkLayerPacketView incoming); + void IncomingInquiryPacket(model::packets::LinkLayerPacketView incoming, uint8_t rssi); + void IncomingInquiryResponsePacket(model::packets::LinkLayerPacketView incoming); void IncomingLmpPacket(model::packets::LinkLayerPacketView incoming); void IncomingLlcpPacket(model::packets::LinkLayerPacketView incoming); - void IncomingLeConnectedIsochronousPdu( - model::packets::LinkLayerPacketView incoming); - - void ScanIncomingLeLegacyAdvertisingPdu( - model::packets::LeLegacyAdvertisingPduView& pdu, uint8_t rssi); - void ScanIncomingLeExtendedAdvertisingPdu( - model::packets::LeExtendedAdvertisingPduView& pdu, uint8_t rssi); - void ConnectIncomingLeLegacyAdvertisingPdu( - model::packets::LeLegacyAdvertisingPduView& pdu); - void ConnectIncomingLeExtendedAdvertisingPdu( - model::packets::LeExtendedAdvertisingPduView& pdu); - - void IncomingLeLegacyAdvertisingPdu( - model::packets::LinkLayerPacketView incoming, uint8_t rssi); - void IncomingLeExtendedAdvertisingPdu( - model::packets::LinkLayerPacketView incoming, uint8_t rssi); - void IncomingLePeriodicAdvertisingPdu( - model::packets::LinkLayerPacketView incoming, uint8_t rssi); + void IncomingLeConnectedIsochronousPdu(model::packets::LinkLayerPacketView incoming); + + void ScanIncomingLeLegacyAdvertisingPdu(model::packets::LeLegacyAdvertisingPduView& pdu, + uint8_t rssi); + void ScanIncomingLeExtendedAdvertisingPdu(model::packets::LeExtendedAdvertisingPduView& pdu, + uint8_t rssi); + void ConnectIncomingLeLegacyAdvertisingPdu(model::packets::LeLegacyAdvertisingPduView& pdu); + void ConnectIncomingLeExtendedAdvertisingPdu(model::packets::LeExtendedAdvertisingPduView& pdu); + + void IncomingLeLegacyAdvertisingPdu(model::packets::LinkLayerPacketView incoming, uint8_t rssi); + void IncomingLeExtendedAdvertisingPdu(model::packets::LinkLayerPacketView incoming, uint8_t rssi); + void IncomingLePeriodicAdvertisingPdu(model::packets::LinkLayerPacketView incoming, uint8_t rssi); void IncomingLeConnectPacket(model::packets::LinkLayerPacketView incoming); - void IncomingLeConnectCompletePacket( - model::packets::LinkLayerPacketView incoming); - void IncomingLeConnectionParameterRequest( - model::packets::LinkLayerPacketView incoming); - void IncomingLeConnectionParameterUpdate( - model::packets::LinkLayerPacketView incoming); - void IncomingLeEncryptConnection( - model::packets::LinkLayerPacketView incoming); - void IncomingLeEncryptConnectionResponse( - model::packets::LinkLayerPacketView incoming); - void IncomingLeReadRemoteFeatures( - model::packets::LinkLayerPacketView incoming); - void IncomingLeReadRemoteFeaturesResponse( - model::packets::LinkLayerPacketView incoming); - - void ProcessIncomingLegacyScanRequest( - AddressWithType scanning_address, - AddressWithType resolved_scanning_address, - AddressWithType advertising_address); - void ProcessIncomingExtendedScanRequest( - ExtendedAdvertiser const& advertiser, AddressWithType scanning_address, - AddressWithType resolved_scanning_address, - AddressWithType advertising_address); - - bool ProcessIncomingLegacyConnectRequest( - model::packets::LeConnectView const& connect_ind); - bool ProcessIncomingExtendedConnectRequest( - ExtendedAdvertiser& advertiser, - model::packets::LeConnectView const& connect_ind); + void IncomingLeConnectCompletePacket(model::packets::LinkLayerPacketView incoming); + void IncomingLeConnectionParameterRequest(model::packets::LinkLayerPacketView incoming); + void IncomingLeConnectionParameterUpdate(model::packets::LinkLayerPacketView incoming); + void IncomingLeEncryptConnection(model::packets::LinkLayerPacketView incoming); + void IncomingLeEncryptConnectionResponse(model::packets::LinkLayerPacketView incoming); + void IncomingLeReadRemoteFeatures(model::packets::LinkLayerPacketView incoming); + void IncomingLeReadRemoteFeaturesResponse(model::packets::LinkLayerPacketView incoming); + + void ProcessIncomingLegacyScanRequest(AddressWithType scanning_address, + AddressWithType resolved_scanning_address, + AddressWithType advertising_address); + void ProcessIncomingExtendedScanRequest(ExtendedAdvertiser const& advertiser, + AddressWithType scanning_address, + AddressWithType resolved_scanning_address, + AddressWithType advertising_address); + + bool ProcessIncomingLegacyConnectRequest(model::packets::LeConnectView const& connect_ind); + bool ProcessIncomingExtendedConnectRequest(ExtendedAdvertiser& advertiser, + model::packets::LeConnectView const& connect_ind); void IncomingLeScanPacket(model::packets::LinkLayerPacketView incoming); - void IncomingLeScanResponsePacket( - model::packets::LinkLayerPacketView incoming, uint8_t rssi); + void IncomingLeScanResponsePacket(model::packets::LinkLayerPacketView incoming, uint8_t rssi); void IncomingPagePacket(model::packets::LinkLayerPacketView incoming); void IncomingPageRejectPacket(model::packets::LinkLayerPacketView incoming); void IncomingPageResponsePacket(model::packets::LinkLayerPacketView incoming); - void IncomingReadRemoteLmpFeatures( - model::packets::LinkLayerPacketView incoming); - void IncomingReadRemoteLmpFeaturesResponse( - model::packets::LinkLayerPacketView incoming); - void IncomingReadRemoteSupportedFeatures( - model::packets::LinkLayerPacketView incoming); - void IncomingReadRemoteSupportedFeaturesResponse( - model::packets::LinkLayerPacketView incoming); - void IncomingReadRemoteExtendedFeatures( - model::packets::LinkLayerPacketView incoming); - void IncomingReadRemoteExtendedFeaturesResponse( - model::packets::LinkLayerPacketView incoming); + void IncomingReadRemoteLmpFeatures(model::packets::LinkLayerPacketView incoming); + void IncomingReadRemoteLmpFeaturesResponse(model::packets::LinkLayerPacketView incoming); + void IncomingReadRemoteSupportedFeatures(model::packets::LinkLayerPacketView incoming); + void IncomingReadRemoteSupportedFeaturesResponse(model::packets::LinkLayerPacketView incoming); + void IncomingReadRemoteExtendedFeatures(model::packets::LinkLayerPacketView incoming); + void IncomingReadRemoteExtendedFeaturesResponse(model::packets::LinkLayerPacketView incoming); void IncomingReadRemoteVersion(model::packets::LinkLayerPacketView incoming); - void IncomingReadRemoteVersionResponse( - model::packets::LinkLayerPacketView incoming); + void IncomingReadRemoteVersionResponse(model::packets::LinkLayerPacketView incoming); void IncomingReadClockOffset(model::packets::LinkLayerPacketView incoming); - void IncomingReadClockOffsetResponse( - model::packets::LinkLayerPacketView incoming); + void IncomingReadClockOffsetResponse(model::packets::LinkLayerPacketView incoming); void IncomingRemoteNameRequest(model::packets::LinkLayerPacketView incoming); - void IncomingRemoteNameRequestResponse( - model::packets::LinkLayerPacketView incoming); + void IncomingRemoteNameRequestResponse(model::packets::LinkLayerPacketView incoming); - void IncomingScoConnectionRequest( - model::packets::LinkLayerPacketView incoming); - void IncomingScoConnectionResponse( - model::packets::LinkLayerPacketView incoming); + void IncomingScoConnectionRequest(model::packets::LinkLayerPacketView incoming); + void IncomingScoConnectionResponse(model::packets::LinkLayerPacketView incoming); void IncomingScoDisconnect(model::packets::LinkLayerPacketView incoming); void IncomingPingRequest(model::packets::LinkLayerPacketView incoming); @@ -757,7 +676,7 @@ class LinkLayerController { void IncomingLlPhyRsp(model::packets::LinkLayerPacketView incoming); void IncomingLlPhyUpdateInd(model::packets::LinkLayerPacketView incoming); - public: +public: bool IsEventUnmasked(bluetooth::hci::EventCode event) const; bool IsLeEventUnmasked(bluetooth::hci::SubeventCode subevent) const; @@ -770,9 +689,7 @@ class LinkLayerController { // TODO // The Page Scan Repetition Mode should be specific to an ACL connection or // a paging session. - PageScanRepetitionMode GetPageScanRepetitionMode() const { - return page_scan_repetition_mode_; - } + PageScanRepetitionMode GetPageScanRepetitionMode() const { return page_scan_repetition_mode_; } // TODO // The Encryption Key Size should be specific to an ACL connection. @@ -780,72 +697,47 @@ class LinkLayerController { bool GetScoFlowControlEnable() const { return sco_flow_control_enable_; } - AuthenticationEnable GetAuthenticationEnable() { - return authentication_enable_; - } + AuthenticationEnable GetAuthenticationEnable() { return authentication_enable_; } - std::array const& GetLocalName() { - return local_name_; - } + std::array const& GetLocalName() { return local_name_; } uint64_t GetLeSupportedFeatures() const { return properties_.le_features | le_host_supported_features_; } - uint16_t GetConnectionAcceptTimeout() const { - return connection_accept_timeout_; - } + uint16_t GetConnectionAcceptTimeout() const { return connection_accept_timeout_; } uint16_t GetVoiceSetting() const { return voice_setting_; } uint32_t GetClassOfDevice() const { return class_of_device_; } - uint8_t GetMaxLmpFeaturesPageNumber() { - return properties_.lmp_features.size() - 1; - } + uint8_t GetMaxLmpFeaturesPageNumber() { return properties_.lmp_features.size() - 1; } uint64_t GetLmpFeatures(uint8_t page_number = 0) { - return page_number == 1 ? host_supported_features_ - : properties_.lmp_features[page_number]; + return page_number == 1 ? host_supported_features_ : properties_.lmp_features[page_number]; } void SetLocalName(std::vector const& local_name); void SetLocalName(std::array const& local_name); - void SetExtendedInquiryResponse( - std::array const& extended_inquiry_response); - void SetExtendedInquiryResponse( - std::vector const& extended_inquiry_response); + void SetExtendedInquiryResponse(std::array const& extended_inquiry_response); + void SetExtendedInquiryResponse(std::vector const& extended_inquiry_response); - void SetClassOfDevice(uint32_t class_of_device) { - class_of_device_ = class_of_device; - } + void SetClassOfDevice(uint32_t class_of_device) { class_of_device_ = class_of_device; } - void SetAuthenticationEnable(AuthenticationEnable enable) { - authentication_enable_ = enable; - } + void SetAuthenticationEnable(AuthenticationEnable enable) { authentication_enable_ = enable; } - void SetScoFlowControlEnable(bool enable) { - sco_flow_control_enable_ = enable; - } - void SetVoiceSetting(uint16_t voice_setting) { - voice_setting_ = voice_setting; - } + void SetScoFlowControlEnable(bool enable) { sco_flow_control_enable_ = enable; } + void SetVoiceSetting(uint16_t voice_setting) { voice_setting_ = voice_setting; } void SetEventMask(uint64_t event_mask) { event_mask_ = event_mask; } - void SetEventMaskPage2(uint64_t event_mask) { - event_mask_page_2_ = event_mask; - } - void SetLeEventMask(uint64_t le_event_mask) { - le_event_mask_ = le_event_mask; - } + void SetEventMaskPage2(uint64_t event_mask) { event_mask_page_2_ = event_mask; } + void SetLeEventMask(uint64_t le_event_mask) { le_event_mask_ = le_event_mask; } void SetLeHostSupport(bool enable); void SetSecureSimplePairingSupport(bool enable); void SetSecureConnectionsSupport(bool enable); - void SetConnectionAcceptTimeout(uint16_t timeout) { - connection_accept_timeout_ = timeout; - } + void SetConnectionAcceptTimeout(uint16_t timeout) { connection_accept_timeout_ = timeout; } bool LegacyAdvertising() const { return legacy_advertising_in_use_; } bool ExtendedAdvertising() const { return extended_advertising_in_use_; } @@ -866,21 +758,17 @@ class LinkLayerController { return true; } - uint16_t GetLeSuggestedMaxTxOctets() const { - return le_suggested_max_tx_octets_; - } + uint16_t GetLeSuggestedMaxTxOctets() const { return le_suggested_max_tx_octets_; } uint16_t GetLeSuggestedMaxTxTime() const { return le_suggested_max_tx_time_; } void SetLeSuggestedMaxTxOctets(uint16_t max_tx_octets) { le_suggested_max_tx_octets_ = max_tx_octets; } - void SetLeSuggestedMaxTxTime(uint16_t max_tx_time) { - le_suggested_max_tx_time_ = max_tx_time; - } + void SetLeSuggestedMaxTxTime(uint16_t max_tx_time) { le_suggested_max_tx_time_ = max_tx_time; } TaskId StartScoStream(Address address); - private: +private: const Address& address_; const ControllerProperties& properties_; @@ -929,8 +817,7 @@ class LinkLayerController { uint16_t voice_setting_{0x0060}; // Authentication Enable (Vol 4, Part E § 6.16). - AuthenticationEnable authentication_enable_{ - AuthenticationEnable::NOT_REQUIRED}; + AuthenticationEnable authentication_enable_{AuthenticationEnable::NOT_REQUIRED}; // Default Link Policy Settings (Vol 4, Part E § 6.18). uint8_t default_link_policy_settings_{0x0000}; @@ -942,8 +829,7 @@ class LinkLayerController { std::array local_name_{}; // Extended Inquiry Response (Vol 4, Part E § 6.24). - std::array - extended_inquiry_response_{}; + std::array extended_inquiry_response_{}; // Class of Device (Vol 4, Part E § 6.26). uint32_t class_of_device_{0}; @@ -978,15 +864,14 @@ class LinkLayerController { // Callbacks to send packets back to the HCI. std::function)> send_acl_; - std::function)> - send_event_; + std::function)> send_event_; std::function)> send_sco_; std::function)> send_iso_; // Callback to send packets to remote devices. - std::function, - Phy::Type phy_type, int8_t tx_power)> - send_to_remote_; + std::function, Phy::Type phy_type, + int8_t tx_power)> + send_to_remote_; uint32_t oob_id_{1}; uint32_t key_id_{1}; @@ -1074,8 +959,7 @@ class LinkLayerController { model::packets::PhyType primary_scan_response_phy; model::packets::PhyType secondary_scan_response_phy; std::optional pending_scan_request{}; - std::optional - pending_scan_request_timeout{}; + std::optional pending_scan_request_timeout{}; // Time keeping std::optional timeout; @@ -1087,14 +971,11 @@ class LinkLayerController { bool IsEnabled() const { return scan_enable; } bool IsPacketInHistory(pdl::packet::slice const& packet) const { - return std::any_of( - history.begin(), history.end(), - [packet](pdl::packet::slice const& a) { return a == packet; }); + return std::any_of(history.begin(), history.end(), + [packet](pdl::packet::slice const& a) { return a == packet; }); } - void AddPacketToHistory(pdl::packet::slice packet) { - history.push_back(packet); - } + void AddPacketToHistory(pdl::packet::slice packet) { history.push_back(packet); } }; // Legacy and extended scanning properties. @@ -1187,36 +1068,29 @@ class LinkLayerController { std::optional page_; std::chrono::steady_clock::time_point last_inquiry_; - model::packets::InquiryType inquiry_mode_{ - model::packets::InquiryType::STANDARD}; + model::packets::InquiryType inquiry_mode_{model::packets::InquiryType::STANDARD}; TaskId inquiry_timer_task_id_ = kInvalidTaskId; uint64_t inquiry_lap_{}; uint8_t inquiry_max_responses_{}; - public: +public: // Type of scheduled tasks. class Task { - public: - Task(std::chrono::steady_clock::time_point time, - std::chrono::milliseconds period, TaskCallback callback, - TaskId task_id) + public: + Task(std::chrono::steady_clock::time_point time, std::chrono::milliseconds period, + TaskCallback callback, TaskId task_id) : time(time), periodic(true), period(period), callback(std::move(callback)), task_id(task_id) {} - Task(std::chrono::steady_clock::time_point time, TaskCallback callback, - TaskId task_id) - : time(time), - periodic(false), - callback(std::move(callback)), - task_id(task_id) {} + Task(std::chrono::steady_clock::time_point time, TaskCallback callback, TaskId task_id) + : time(time), periodic(false), callback(std::move(callback)), task_id(task_id) {} // 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); } // These fields should no longer be public if the class ever becomes @@ -1228,7 +1102,7 @@ class LinkLayerController { TaskId task_id; }; - private: +private: // List currently pending tasks. std::set task_queue_{}; TaskId task_counter_{0}; diff --git a/model/controller/sco_connection.cc b/model/controller/sco_connection.cc index e0fb087..0ecacf3 100644 --- a/model/controller/sco_connection.cc +++ b/model/controller/sco_connection.cc @@ -41,14 +41,13 @@ bool ScoConnectionParameters::IsExtended() const { return ((packet_type ^ edr) & ~legacy) != 0; } -std::optional ScoConnectionParameters::GetLinkParameters() - const { +std::optional ScoConnectionParameters::GetLinkParameters() const { // 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. @@ -72,20 +71,16 @@ std::optional ScoConnectionParameters::GetLinkParameters() 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. @@ -112,14 +107,12 @@ std::optional ScoConnectionParameters::GetLinkParameters() continue; } - INFO("Testing combination {}/{} : {}/{}", tx.length, tx.slots, rx.length, - rx.slots); + INFO("Testing combination {}/{} : {}/{}", 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); @@ -127,22 +120,17 @@ std::optional 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; INFO("Retransmission window: {} 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) { @@ -162,26 +150,23 @@ std::optional ScoConnectionParameters::GetLinkParameters() // We got a valid configuration. // Evaluate the actual bandwidth usage. - double bandwidth_usage = - (double)transmission_window / (double)transmission_interval; + double bandwidth_usage = (double)transmission_window / (double)transmission_interval; if (bandwidth_usage <= best_bandwidth_usage) { INFO("Valid combination!"); - uint16_t tx_packet_length = - (transmit_bandwidth * transmission_interval + 1600 - 1) / 1600; - uint16_t rx_packet_length = - (receive_bandwidth * transmission_interval + 1600 - 1) / 1600; + uint16_t tx_packet_length = (transmit_bandwidth * transmission_interval + 1600 - 1) / 1600; + uint16_t rx_packet_length = (receive_bandwidth * transmission_interval + 1600 - 1) / 1600; uint8_t air_coding = voice_setting & 0x3; best_bandwidth_usage = bandwidth_usage; best_parameters = { - (uint8_t)transmission_interval, - (uint8_t)retransmission_window, - rx_packet_length, - tx_packet_length, - air_coding_to_air_mode[air_coding], - true, + (uint8_t)transmission_interval, + (uint8_t)retransmission_window, + rx_packet_length, + tx_packet_length, + air_coding_to_air_mode[air_coding], + true, }; } } @@ -194,10 +179,8 @@ std::optional 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) { WARNING("SCO Retransmission effort must be None or Don't care"); return {}; } @@ -221,26 +204,24 @@ std::optional ScoConnectionParameters::GetLinkParameters() } best_parameters = { - transmission_interval, - 0, - packet_length, - packet_length, - air_coding_to_air_mode[air_coding], - false, + 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) { WARNING("Transmit bandwidth requirements cannot be met"); return false; } - if (state_ == SCO_STATE_SENT_ESCO_CONNECTION_REQUEST && - peer.receive_bandwidth != 0xffff && + if (state_ == SCO_STATE_SENT_ESCO_CONNECTION_REQUEST && peer.receive_bandwidth != 0xffff && peer.receive_bandwidth != parameters_.transmit_bandwidth) { WARNING("Receive bandwidth requirements cannot be met"); return false; @@ -265,52 +246,40 @@ bool ScoConnection::NegotiateLinkParameters( return false; } - 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); + 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); 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 || + } else if (peer.retransmission_effort == (uint8_t)RetransmissionEffort::NO_RETRANSMISSION || parameters_.retransmission_effort == - (uint8_t)RetransmissionEffort::NO_RETRANSMISSION) { + (uint8_t)RetransmissionEffort::NO_RETRANSMISSION) { WARNING("Retransmission effort requirements cannot be met"); - WARNING("Remote retransmission effort: 0x{:02x}", - parameters_.retransmission_effort); - WARNING("Local retransmission effort: 0x{:02x}", - peer.retransmission_effort); + WARNING("Remote retransmission effort: 0x{:02x}", parameters_.retransmission_effort); + WARNING("Local retransmission effort: 0x{:02x}", peer.retransmission_effort); return false; } else { retransmission_effort = (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER; } 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()) { link_parameters_ = link_parameters.value(); INFO("Negotiated link parameters for SCO connection:"); - INFO(" Transmission interval: {} slots", - link_parameters_.transmission_interval); - INFO(" Retransmission window: {} slots", - link_parameters_.retransmission_window); + INFO(" Transmission interval: {} slots", link_parameters_.transmission_interval); + INFO(" Retransmission window: {} slots", link_parameters_.retransmission_window); INFO(" RX packet length: {} bytes", link_parameters_.rx_packet_length); INFO(" TX packet length: {} bytes", link_parameters_.tx_packet_length); INFO(" Air mode: {}", link_parameters_.air_mode); diff --git a/model/controller/sco_connection.h b/model/controller/sco_connection.h index decd842..b086642 100644 --- a/model/controller/sco_connection.h +++ b/model/controller/sco_connection.h @@ -82,9 +82,9 @@ enum ScoDatapath { }; class ScoConnection { - public: - ScoConnection(Address address, ScoConnectionParameters const& parameters, - ScoState state, ScoDatapath datapath, bool legacy) +public: + ScoConnection(Address address, ScoConnectionParameters const& parameters, ScoState state, + ScoDatapath datapath, bool legacy) : address_(address), parameters_(parameters), link_parameters_(), @@ -102,13 +102,9 @@ class ScoConnection { void StartStream(std::function startStream); void StopStream(std::function stopStream); - ScoConnectionParameters GetConnectionParameters() const { - return parameters_; - } + ScoConnectionParameters GetConnectionParameters() const { return parameters_; } ScoLinkParameters GetLinkParameters() const { return link_parameters_; } - void SetLinkParameters(ScoLinkParameters const& parameters) { - link_parameters_ = parameters; - } + void SetLinkParameters(ScoLinkParameters const& parameters) { link_parameters_ = parameters; } // Negotiate the connection parameters. // Update the local connection parameters with negotiated values. @@ -117,7 +113,7 @@ class ScoConnection { ScoDatapath GetDatapath() const { return datapath_; } - private: +private: Address address_; ScoConnectionParameters parameters_; ScoLinkParameters link_parameters_; diff --git a/model/controller/vendor_commands/le_apcf.cc b/model/controller/vendor_commands/le_apcf.cc index a28fcd7..e4a774e 100644 --- a/model/controller/vendor_commands/le_apcf.cc +++ b/model/controller/vendor_commands/le_apcf.cc @@ -28,50 +28,41 @@ namespace rootcanal::apcf { bool ApcfScanner::HasFilterIndex(uint8_t apcf_filter_index) const { - return std::any_of(std::begin(filters), std::end(filters), [&](auto it) { - return it.filter_index == apcf_filter_index; - }); + return std::any_of(std::begin(filters), std::end(filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }); } void ApcfScanner::ClearFilterIndex(uint8_t apcf_filter_index) { broadcaster_address_filters.erase( - std::remove_if( - std::begin(broadcaster_address_filters), - std::end(broadcaster_address_filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), - std::end(broadcaster_address_filters)); + std::remove_if(std::begin(broadcaster_address_filters), + std::end(broadcaster_address_filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), + std::end(broadcaster_address_filters)); service_uuid_filters.erase( - std::remove_if( - std::begin(service_uuid_filters), std::end(service_uuid_filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), - std::end(service_uuid_filters)); + std::remove_if(std::begin(service_uuid_filters), std::end(service_uuid_filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), + std::end(service_uuid_filters)); service_solicitation_uuid_filters.erase( - std::remove_if( - std::begin(service_solicitation_uuid_filters), - std::end(service_solicitation_uuid_filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), - std::end(service_solicitation_uuid_filters)); + std::remove_if(std::begin(service_solicitation_uuid_filters), + std::end(service_solicitation_uuid_filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), + std::end(service_solicitation_uuid_filters)); local_name_filters.erase( - std::remove_if( - std::begin(local_name_filters), std::end(local_name_filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), - std::end(local_name_filters)); + std::remove_if(std::begin(local_name_filters), std::end(local_name_filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), + std::end(local_name_filters)); manufacturer_data_filters.erase( - std::remove_if( - std::begin(manufacturer_data_filters), - std::end(manufacturer_data_filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), - std::end(manufacturer_data_filters)); + std::remove_if(std::begin(manufacturer_data_filters), std::end(manufacturer_data_filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), + std::end(manufacturer_data_filters)); service_data_filters.erase( - std::remove_if( - std::begin(service_data_filters), std::end(service_data_filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), - std::end(service_data_filters)); + std::remove_if(std::begin(service_data_filters), std::end(service_data_filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), + std::end(service_data_filters)); ad_type_filters.erase( - std::remove_if( - std::begin(ad_type_filters), std::end(ad_type_filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), - std::end(ad_type_filters)); + std::remove_if(std::begin(ad_type_filters), std::end(ad_type_filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), + std::end(ad_type_filters)); } void ApcfScanner::Clear() { @@ -86,10 +77,8 @@ void ApcfScanner::Clear() { } template -ErrorCode ApcfScanner::UpdateFilterList(std::vector& filter_list, - size_t max_filter_list_size, - bluetooth::hci::ApcfAction action, - T filter) { +ErrorCode ApcfScanner::UpdateFilterList(std::vector& filter_list, size_t max_filter_list_size, + bluetooth::hci::ApcfAction action, T filter) { if (!HasFilterIndex(filter.filter_index)) { return ErrorCode::UNKNOWN_CONNECTION; } @@ -105,19 +94,17 @@ ErrorCode ApcfScanner::UpdateFilterList(std::vector& filter_list, } case ApcfAction::DELETE: { // Delete will delete the specified data in the specified filter. - filter_list.erase( - std::remove_if(std::begin(filter_list), std::end(filter_list), - [&](auto it) { return it == filter; }), - std::end(filter_list)); + filter_list.erase(std::remove_if(std::begin(filter_list), std::end(filter_list), + [&](auto it) { return it == filter; }), + std::end(filter_list)); return ErrorCode::SUCCESS; } case ApcfAction::CLEAR: { // Clear will clear all data in the specified filter. filter_list.erase( - std::remove_if( - std::begin(filter_list), std::end(filter_list), - [&](auto it) { return it.filter_index == filter.filter_index; }), - std::end(filter_list)); + std::remove_if(std::begin(filter_list), std::end(filter_list), + [&](auto it) { return it.filter_index == filter.filter_index; }), + std::end(filter_list)); return ErrorCode::SUCCESS; } default: @@ -127,8 +114,7 @@ ErrorCode ApcfScanner::UpdateFilterList(std::vector& filter_list, return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } -bool operator==(BroadcasterAddressFilter const& lhs, - BroadcasterAddressFilter const& rhs) { +bool operator==(BroadcasterAddressFilter const& lhs, BroadcasterAddressFilter const& rhs) { return lhs.filter_index == rhs.filter_index && lhs.broadcaster_address == rhs.broadcaster_address && lhs.application_address_type == rhs.application_address_type; @@ -156,26 +142,24 @@ ErrorCode LinkLayerController::LeApcfEnable(bool apcf_enable) { } ErrorCode LinkLayerController::LeApcfAddFilteringParameters( - uint8_t apcf_filter_index, uint16_t apcf_feature_selection, - uint16_t apcf_list_logic_type, uint8_t apcf_filter_logic_type, - uint8_t rssi_high_thresh, bluetooth::hci::DeliveryMode delivery_mode, - uint16_t onfound_timeout, uint8_t onfound_timeout_cnt, - uint8_t rssi_low_thresh, uint16_t onlost_timeout, - uint16_t num_of_tracking_entries, uint8_t* apcf_available_spaces) { - *apcf_available_spaces = - properties_.le_apcf_filter_list_size - apcf_scanner_.filters.size(); - - if (apcf_scanner_.HasFilterIndex(apcf_filter_index)) { - INFO(id_, "apcf filter index {} already configured", apcf_filter_index); - return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; - } + uint8_t apcf_filter_index, uint16_t apcf_feature_selection, uint16_t apcf_list_logic_type, + uint8_t apcf_filter_logic_type, uint8_t rssi_high_thresh, + bluetooth::hci::DeliveryMode delivery_mode, uint16_t onfound_timeout, + uint8_t onfound_timeout_cnt, uint8_t rssi_low_thresh, uint16_t onlost_timeout, + uint16_t num_of_tracking_entries, uint8_t* apcf_available_spaces) { + *apcf_available_spaces = properties_.le_apcf_filter_list_size - apcf_scanner_.filters.size(); + + if (apcf_scanner_.HasFilterIndex(apcf_filter_index)) { + INFO(id_, "apcf filter index {} already configured", apcf_filter_index); + return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; + } - if (*apcf_available_spaces == 0) { - INFO(id_, "reached max number of apcf filters"); - return ErrorCode::MEMORY_CAPACITY_EXCEEDED; - } + if (*apcf_available_spaces == 0) { + INFO(id_, "reached max number of apcf filters"); + return ErrorCode::MEMORY_CAPACITY_EXCEEDED; + } - apcf_scanner_.filters.push_back(rootcanal::apcf::Filter{ + apcf_scanner_.filters.push_back(rootcanal::apcf::Filter{ .filter_index = apcf_filter_index, .feature_selection = apcf_feature_selection, .list_logic_type = apcf_list_logic_type, @@ -187,79 +171,74 @@ ErrorCode LinkLayerController::LeApcfAddFilteringParameters( .rssi_low_thresh = rssi_low_thresh, .onlost_timeout = onlost_timeout, .num_of_tracking_entries = num_of_tracking_entries, - }); + }); - *apcf_available_spaces -= 1; - return ErrorCode::SUCCESS; + *apcf_available_spaces -= 1; + return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::LeApcfDeleteFilteringParameters( - uint8_t apcf_filter_index, uint8_t* apcf_available_spaces) { - *apcf_available_spaces = - properties_.le_apcf_filter_list_size - apcf_scanner_.filters.size(); +ErrorCode LinkLayerController::LeApcfDeleteFilteringParameters(uint8_t apcf_filter_index, + uint8_t* apcf_available_spaces) { + *apcf_available_spaces = properties_.le_apcf_filter_list_size - apcf_scanner_.filters.size(); - if (!apcf_scanner_.HasFilterIndex(apcf_filter_index)) { - INFO(id_, "apcf filter index {} is not configured", apcf_filter_index); - return ErrorCode::UNKNOWN_CONNECTION; - } + if (!apcf_scanner_.HasFilterIndex(apcf_filter_index)) { + INFO(id_, "apcf filter index {} is not configured", apcf_filter_index); + return ErrorCode::UNKNOWN_CONNECTION; + } - apcf_scanner_.filters.erase( - std::remove_if( - std::begin(apcf_scanner_.filters), - std::end(apcf_scanner_.filters), - [&](auto it) { return it.filter_index == apcf_filter_index; }), + apcf_scanner_.filters.erase( + std::remove_if(std::begin(apcf_scanner_.filters), std::end(apcf_scanner_.filters), + [&](auto it) { return it.filter_index == apcf_filter_index; }), std::end(apcf_scanner_.filters)); - apcf_scanner_.ClearFilterIndex(apcf_filter_index); - *apcf_available_spaces += 1; - return ErrorCode::SUCCESS; + apcf_scanner_.ClearFilterIndex(apcf_filter_index); + *apcf_available_spaces += 1; + return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::LeApcfClearFilteringParameters( - uint8_t* apcf_available_spaces) { - apcf_scanner_.Clear(); - *apcf_available_spaces = properties_.le_apcf_filter_list_size; - return ErrorCode::SUCCESS; +ErrorCode LinkLayerController::LeApcfClearFilteringParameters(uint8_t* apcf_available_spaces) { + apcf_scanner_.Clear(); + *apcf_available_spaces = properties_.le_apcf_filter_list_size; + return ErrorCode::SUCCESS; } ErrorCode LinkLayerController::LeApcfBroadcasterAddress( - ApcfAction apcf_action, uint8_t apcf_filter_index, - bluetooth::hci::Address apcf_broadcaster_address, - bluetooth::hci::ApcfApplicationAddressType apcf_application_address_type, - uint8_t* apcf_available_spaces) { + ApcfAction apcf_action, uint8_t apcf_filter_index, + bluetooth::hci::Address apcf_broadcaster_address, + bluetooth::hci::ApcfApplicationAddressType apcf_application_address_type, + uint8_t* apcf_available_spaces) { ErrorCode status = apcf_scanner_.UpdateFilterList( - apcf_scanner_.broadcaster_address_filters, - properties_.le_apcf_broadcaster_address_filter_list_size, apcf_action, - rootcanal::apcf::BroadcasterAddressFilter{ - .filter_index = apcf_filter_index, - .broadcaster_address = apcf_broadcaster_address, - .application_address_type = apcf_application_address_type, - }); + apcf_scanner_.broadcaster_address_filters, + properties_.le_apcf_broadcaster_address_filter_list_size, apcf_action, + rootcanal::apcf::BroadcasterAddressFilter{ + .filter_index = apcf_filter_index, + .broadcaster_address = apcf_broadcaster_address, + .application_address_type = apcf_application_address_type, + }); - *apcf_available_spaces = - properties_.le_apcf_broadcaster_address_filter_list_size - - apcf_scanner_.broadcaster_address_filters.size(); + *apcf_available_spaces = properties_.le_apcf_broadcaster_address_filter_list_size - + apcf_scanner_.broadcaster_address_filters.size(); return status; } -ErrorCode LinkLayerController::LeApcfServiceUuid( - ApcfAction apcf_action, uint8_t apcf_filter_index, - std::vector apcf_uuid_data, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfServiceUuid(ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector apcf_uuid_data, + uint8_t* apcf_available_spaces) { size_t uuid_data_size = apcf_uuid_data.size() / 2; std::vector uuid_data(std::begin(apcf_uuid_data), std::begin(apcf_uuid_data) + uuid_data_size); - std::vector uuid_data_mask( - std::begin(apcf_uuid_data) + uuid_data_size, std::end(apcf_uuid_data)); + std::vector uuid_data_mask(std::begin(apcf_uuid_data) + uuid_data_size, + std::end(apcf_uuid_data)); ErrorCode status = apcf_scanner_.UpdateFilterList( - apcf_scanner_.service_uuid_filters, - properties_.le_apcf_service_uuid_filter_list_size, apcf_action, - rootcanal::apcf::GapDataFilter{ - .filter_index = apcf_filter_index, - .gap_data = uuid_data, - .gap_data_mask = uuid_data_mask, - }); + apcf_scanner_.service_uuid_filters, properties_.le_apcf_service_uuid_filter_list_size, + apcf_action, + rootcanal::apcf::GapDataFilter{ + .filter_index = apcf_filter_index, + .gap_data = uuid_data, + .gap_data_mask = uuid_data_mask, + }); *apcf_available_spaces = properties_.le_apcf_service_uuid_filter_list_size - apcf_scanner_.service_uuid_filters.size(); @@ -267,104 +246,99 @@ ErrorCode LinkLayerController::LeApcfServiceUuid( return status; } -ErrorCode LinkLayerController::LeApcfServiceSolicitationUuid( - ApcfAction apcf_action, uint8_t apcf_filter_index, - std::vector apcf_uuid_data, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfServiceSolicitationUuid(ApcfAction apcf_action, + uint8_t apcf_filter_index, + std::vector apcf_uuid_data, + uint8_t* apcf_available_spaces) { size_t uuid_data_size = apcf_uuid_data.size() / 2; std::vector uuid_data(std::begin(apcf_uuid_data), std::begin(apcf_uuid_data) + uuid_data_size); - std::vector uuid_data_mask( - std::begin(apcf_uuid_data) + uuid_data_size, std::end(apcf_uuid_data)); + std::vector uuid_data_mask(std::begin(apcf_uuid_data) + uuid_data_size, + std::end(apcf_uuid_data)); ErrorCode status = apcf_scanner_.UpdateFilterList( - apcf_scanner_.service_solicitation_uuid_filters, - properties_.le_apcf_service_solicitation_uuid_filter_list_size, - apcf_action, - rootcanal::apcf::GapDataFilter{ - .filter_index = apcf_filter_index, - .gap_data = uuid_data, - .gap_data_mask = uuid_data_mask, - }); + apcf_scanner_.service_solicitation_uuid_filters, + properties_.le_apcf_service_solicitation_uuid_filter_list_size, apcf_action, + rootcanal::apcf::GapDataFilter{ + .filter_index = apcf_filter_index, + .gap_data = uuid_data, + .gap_data_mask = uuid_data_mask, + }); - *apcf_available_spaces = - properties_.le_apcf_service_solicitation_uuid_filter_list_size - - apcf_scanner_.service_solicitation_uuid_filters.size(); + *apcf_available_spaces = properties_.le_apcf_service_solicitation_uuid_filter_list_size - + apcf_scanner_.service_solicitation_uuid_filters.size(); return status; } -ErrorCode LinkLayerController::LeApcfLocalName( - ApcfAction apcf_action, uint8_t apcf_filter_index, - std::vector apcf_local_name, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfLocalName(ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector apcf_local_name, + uint8_t* apcf_available_spaces) { size_t local_name_size = apcf_local_name.size() / 2; - std::vector local_name( - std::begin(apcf_local_name), - std::begin(apcf_local_name) + local_name_size); - std::vector local_name_mask( - std::begin(apcf_local_name) + local_name_size, std::end(apcf_local_name)); - - ErrorCode status = apcf_scanner_.UpdateFilterList( - apcf_scanner_.local_name_filters, - properties_.le_apcf_local_name_filter_list_size, apcf_action, - rootcanal::apcf::GapDataFilter{ - .filter_index = apcf_filter_index, - .gap_data = local_name, - .gap_data_mask = local_name_mask, - }); + std::vector local_name(std::begin(apcf_local_name), + std::begin(apcf_local_name) + local_name_size); + std::vector local_name_mask(std::begin(apcf_local_name) + local_name_size, + std::end(apcf_local_name)); + + ErrorCode status = apcf_scanner_.UpdateFilterList(apcf_scanner_.local_name_filters, + properties_.le_apcf_local_name_filter_list_size, + apcf_action, + rootcanal::apcf::GapDataFilter{ + .filter_index = apcf_filter_index, + .gap_data = local_name, + .gap_data_mask = local_name_mask, + }); - *apcf_available_spaces = properties_.le_apcf_local_name_filter_list_size - - apcf_scanner_.local_name_filters.size(); + *apcf_available_spaces = + properties_.le_apcf_local_name_filter_list_size - apcf_scanner_.local_name_filters.size(); return status; } -ErrorCode LinkLayerController::LeApcfManufacturerData( - ApcfAction apcf_action, uint8_t apcf_filter_index, - std::vector apcf_manufacturer_data, - uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfManufacturerData(ApcfAction apcf_action, + uint8_t apcf_filter_index, + std::vector apcf_manufacturer_data, + uint8_t* apcf_available_spaces) { size_t manufacturer_data_size = apcf_manufacturer_data.size() / 2; std::vector manufacturer_data( - std::begin(apcf_manufacturer_data), - std::begin(apcf_manufacturer_data) + manufacturer_data_size); + std::begin(apcf_manufacturer_data), + std::begin(apcf_manufacturer_data) + manufacturer_data_size); std::vector manufacturer_data_mask( - std::begin(apcf_manufacturer_data) + manufacturer_data_size, - std::end(apcf_manufacturer_data)); + std::begin(apcf_manufacturer_data) + manufacturer_data_size, + std::end(apcf_manufacturer_data)); ErrorCode status = apcf_scanner_.UpdateFilterList( - apcf_scanner_.manufacturer_data_filters, - properties_.le_apcf_manufacturer_data_filter_list_size, apcf_action, - rootcanal::apcf::GapDataFilter{ - .filter_index = apcf_filter_index, - .gap_data = manufacturer_data, - .gap_data_mask = manufacturer_data_mask, - }); + apcf_scanner_.manufacturer_data_filters, + properties_.le_apcf_manufacturer_data_filter_list_size, apcf_action, + rootcanal::apcf::GapDataFilter{ + .filter_index = apcf_filter_index, + .gap_data = manufacturer_data, + .gap_data_mask = manufacturer_data_mask, + }); - *apcf_available_spaces = - properties_.le_apcf_manufacturer_data_filter_list_size - - apcf_scanner_.manufacturer_data_filters.size(); + *apcf_available_spaces = properties_.le_apcf_manufacturer_data_filter_list_size - + apcf_scanner_.manufacturer_data_filters.size(); return status; } -ErrorCode LinkLayerController::LeApcfServiceData( - ApcfAction apcf_action, uint8_t apcf_filter_index, - std::vector apcf_service_data, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfServiceData(ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector apcf_service_data, + uint8_t* apcf_available_spaces) { size_t service_data_size = apcf_service_data.size() / 2; - std::vector service_data( - std::begin(apcf_service_data), - std::begin(apcf_service_data) + service_data_size); - std::vector service_data_mask( - std::begin(apcf_service_data) + service_data_size, - std::end(apcf_service_data)); + std::vector service_data(std::begin(apcf_service_data), + std::begin(apcf_service_data) + service_data_size); + std::vector service_data_mask(std::begin(apcf_service_data) + service_data_size, + std::end(apcf_service_data)); ErrorCode status = apcf_scanner_.UpdateFilterList( - apcf_scanner_.service_data_filters, - properties_.le_apcf_service_data_filter_list_size, apcf_action, - rootcanal::apcf::GapDataFilter{ - .filter_index = apcf_filter_index, - .gap_data = service_data, - .gap_data_mask = service_data_mask, - }); + apcf_scanner_.service_data_filters, properties_.le_apcf_service_data_filter_list_size, + apcf_action, + rootcanal::apcf::GapDataFilter{ + .filter_index = apcf_filter_index, + .gap_data = service_data, + .gap_data_mask = service_data_mask, + }); *apcf_available_spaces = properties_.le_apcf_service_data_filter_list_size - apcf_scanner_.service_data_filters.size(); @@ -372,22 +346,22 @@ ErrorCode LinkLayerController::LeApcfServiceData( return status; } -ErrorCode LinkLayerController::LeApcfAdTypeFilter( - ApcfAction apcf_action, uint8_t apcf_filter_index, uint8_t apcf_ad_type, - std::vector apcf_ad_data, std::vector apcf_ad_data_mask, - uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfAdTypeFilter(ApcfAction apcf_action, uint8_t apcf_filter_index, + uint8_t apcf_ad_type, + std::vector apcf_ad_data, + std::vector apcf_ad_data_mask, + uint8_t* apcf_available_spaces) { ErrorCode status = apcf_scanner_.UpdateFilterList( - apcf_scanner_.ad_type_filters, - properties_.le_apcf_ad_type_filter_list_size, apcf_action, - rootcanal::apcf::AdTypeFilter{ - .filter_index = apcf_filter_index, - .ad_type = apcf_ad_type, - .ad_data = std::move(apcf_ad_data), - .ad_data_mask = std::move(apcf_ad_data_mask), - }); + apcf_scanner_.ad_type_filters, properties_.le_apcf_ad_type_filter_list_size, apcf_action, + rootcanal::apcf::AdTypeFilter{ + .filter_index = apcf_filter_index, + .ad_type = apcf_ad_type, + .ad_data = std::move(apcf_ad_data), + .ad_data_mask = std::move(apcf_ad_data_mask), + }); - *apcf_available_spaces = properties_.le_apcf_ad_type_filter_list_size - - apcf_scanner_.ad_type_filters.size(); + *apcf_available_spaces = + properties_.le_apcf_ad_type_filter_list_size - apcf_scanner_.ad_type_filters.size(); return status; } diff --git a/model/controller/vendor_commands/le_apcf.h b/model/controller/vendor_commands/le_apcf.h index 5c6cce4..862ccfd 100644 --- a/model/controller/vendor_commands/le_apcf.h +++ b/model/controller/vendor_commands/le_apcf.h @@ -86,8 +86,7 @@ struct ApcfScanner { // Apply the requested modification to the selected // filter list. template - ErrorCode UpdateFilterList(std::vector& filter_list, - size_t max_filter_list_size, + ErrorCode UpdateFilterList(std::vector& filter_list, size_t max_filter_list_size, bluetooth::hci::ApcfAction action, T filter); }; diff --git a/model/devices/baseband_sniffer.cc b/model/devices/baseband_sniffer.cc index 3bd933f..2ab5501 100644 --- a/model/devices/baseband_sniffer.cc +++ b/model/devices/baseband_sniffer.cc @@ -41,8 +41,7 @@ BaseBandSniffer::BaseBandSniffer(const std::string& filename) { output_.flush(); } -void BaseBandSniffer::AppendRecord( - std::unique_ptr packet) { +void BaseBandSniffer::AppendRecord(std::unique_ptr packet) { std::vector bytes = packet->SerializeToBytes(); pcap::WriteRecordHeader(output_, bytes.size()); output_.write((char*)bytes.data(), bytes.size()); @@ -51,12 +50,10 @@ void BaseBandSniffer::AppendRecord( static uint8_t ReverseByte(uint8_t b) { static uint8_t lookup[16] = { - [0b0000] = 0b0000, [0b0001] = 0b1000, [0b0010] = 0b0100, - [0b0011] = 0b1100, [0b0100] = 0b0010, [0b0101] = 0b1010, - [0b0110] = 0b0110, [0b0111] = 0b1110, [0b1000] = 0b0001, - [0b1001] = 0b1001, [0b1010] = 0b0101, [0b1011] = 0b1101, - [0b1100] = 0b0011, [0b1101] = 0b1011, [0b1110] = 0b0111, - [0b1111] = 0b1111, + [0b0000] = 0b0000, [0b0001] = 0b1000, [0b0010] = 0b0100, [0b0011] = 0b1100, + [0b0100] = 0b0010, [0b0101] = 0b1010, [0b0110] = 0b0110, [0b0111] = 0b1110, + [0b1000] = 0b0001, [0b1001] = 0b1001, [0b1010] = 0b0101, [0b1011] = 0b1101, + [0b1100] = 0b0011, [0b1101] = 0b1011, [0b1110] = 0b0111, [0b1111] = 0b1111, }; return (lookup[b & 0xF] << 4) | lookup[b >> 4]; @@ -79,41 +76,38 @@ static uint8_t HeaderErrorCheck(uint8_t uap, uint32_t data) { return value; } -static uint32_t BuildBtPacketHeader(uint8_t uap, uint8_t lt_addr, - uint8_t packet_type, bool flow, bool arqn, - bool seqn) { +static uint32_t BuildBtPacketHeader(uint8_t uap, uint8_t lt_addr, uint8_t packet_type, bool flow, + bool arqn, bool seqn) { // See Bluetooth Core, Vol2, Part B, 6.4 - uint32_t header = (lt_addr & 0x7) | ((packet_type & 0xF) << 3) | (flow << 7) | - (arqn << 8) | (seqn << 9); + uint32_t header = + (lt_addr & 0x7) | ((packet_type & 0xF) << 3) | (flow << 7) | (arqn << 8) | (seqn << 9); header |= (HeaderErrorCheck(uap, header) << 10); return header; } -void BaseBandSniffer::ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView packet, Phy::Type /*type*/, - int8_t /*rssi*/) { +void BaseBandSniffer::ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, + Phy::Type /*type*/, int8_t /*rssi*/) { auto packet_type = packet.GetType(); auto address = packet.GetSourceAddress(); // Bluetooth Core, Vol2, Part B, 1.2, Figure 1.5 - uint32_t lap = - address.data()[0] | (address.data()[1] << 8) | (address.data()[2] << 16); + uint32_t lap = address.data()[0] | (address.data()[1] << 8) | (address.data()[2] << 16); uint8_t uap = address.data()[3]; uint16_t nap = address.data()[4] | (address.data()[5] << 8); // http://www.whiterocker.com/bt/LINKTYPE_BLUETOOTH_BREDR_BB.html uint16_t flags = - /* BT Packet Header and BR or EDR Payload are de-whitened */ 0x0001 | - /* BR or EDR Payload is decrypted */ 0x0008 | - /* Reference LAP is valid and led to this packet being captured */ - 0x0010 | - /* BR or EDR Payload is present and follows this field */ 0x0020 | - /* Reference UAP field is valid for HEC and CRC checking */ 0x0080 | - /* CRC portion of the BR or EDR Payload was checked */ 0x0400 | - /* CRC portion of the BR or EDR Payload passed its check */ 0x0800; + /* BT Packet Header and BR or EDR Payload are de-whitened */ 0x0001 | + /* BR or EDR Payload is decrypted */ 0x0008 | + /* Reference LAP is valid and led to this packet being captured */ + 0x0010 | + /* BR or EDR Payload is present and follows this field */ 0x0020 | + /* Reference UAP field is valid for HEC and CRC checking */ 0x0080 | + /* CRC portion of the BR or EDR Payload was checked */ 0x0400 | + /* CRC portion of the BR or EDR Payload passed its check */ 0x0800; uint8_t lt_addr = 0; @@ -134,22 +128,20 @@ void BaseBandSniffer::ReceiveLinkLayerPacket( uint8_t bt_packet_type = 0b0010; // FHS AppendRecord(bredr_bb::FHSAclPacketBuilder::Create( - rf_channel, signal_power, noise_power, access_code_offenses, - corrected_header_bits, corrected_payload_bits, lower_address_part, - reference_lap, reference_uap, - BuildBtPacketHeader(uap, lt_addr, bt_packet_type, true, true, true), - flags, - 0, // parity_bits - lap, - 0, // eir - 0, // sr - 0, // sp - uap, nap, page_view.GetClassOfDevice(), - 1, // lt_addr - 0, // clk - 0, // page_scan_mode - 0 // crc - )); + rf_channel, signal_power, noise_power, access_code_offenses, corrected_header_bits, + corrected_payload_bits, lower_address_part, reference_lap, reference_uap, + BuildBtPacketHeader(uap, lt_addr, bt_packet_type, true, true, true), flags, + 0, // parity_bits + lap, + 0, // eir + 0, // sr + 0, // sp + uap, nap, page_view.GetClassOfDevice(), + 1, // lt_addr + 0, // clk + 0, // page_scan_mode + 0 // crc + )); } else if (packet_type == model::packets::PacketType::LMP) { auto lmp_view = model::packets::LmpView::Create(packet); ASSERT(lmp_view.IsValid()); @@ -157,16 +149,14 @@ void BaseBandSniffer::ReceiveLinkLayerPacket( uint8_t bt_packet_type = 0b0011; // DM1 AppendRecord(bredr_bb::DM1AclPacketBuilder::Create( - rf_channel, signal_power, noise_power, access_code_offenses, - corrected_header_bits, corrected_payload_bits, lower_address_part, - reference_lap, reference_uap, - BuildBtPacketHeader(uap, lt_addr, bt_packet_type, true, true, true), - flags, - 0x3, // llid - 1, // flow - std::move(lmp_bytes), - 0 // crc - )); + rf_channel, signal_power, noise_power, access_code_offenses, corrected_header_bits, + corrected_payload_bits, lower_address_part, reference_lap, reference_uap, + BuildBtPacketHeader(uap, lt_addr, bt_packet_type, true, true, true), flags, + 0x3, // llid + 1, // flow + std::move(lmp_bytes), + 0 // crc + )); } } diff --git a/model/devices/baseband_sniffer.h b/model/devices/baseband_sniffer.h index c910b1e..9ed5bb1 100644 --- a/model/devices/baseband_sniffer.h +++ b/model/devices/baseband_sniffer.h @@ -35,7 +35,7 @@ namespace rootcanal { using ::bluetooth::hci::Address; class BaseBandSniffer : public Device { - public: +public: BaseBandSniffer(const std::string& filename); ~BaseBandSniffer() = default; @@ -44,15 +44,12 @@ class BaseBandSniffer : public Device { } // Return a string representation of the type of device. - virtual std::string GetTypeString() const override { - return "baseband_sniffer"; - } + virtual std::string GetTypeString() const override { return "baseband_sniffer"; } - virtual void ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView packet, Phy::Type type, - int8_t rssi) override; + virtual void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, Phy::Type type, + int8_t rssi) override; - private: +private: void AppendRecord(std::unique_ptr packet); std::ofstream output_; }; diff --git a/model/devices/beacon.cc b/model/devices/beacon.cc index d61d44b..37feff6 100644 --- a/model/devices/beacon.cc +++ b/model/devices/beacon.cc @@ -36,13 +36,11 @@ bool Beacon::registered_ = DeviceBoutique::Register("beacon", &Beacon::Create); Beacon::Beacon() : advertising_type_(LegacyAdvertisingType::ADV_NONCONN_IND), advertising_data_({ - 0x0F /* Length */, 0x09 /* TYPE_NAME_COMPLETE */, 'g', 'D', 'e', 'v', - 'i', 'c', 'e', '-', 'b', 'e', 'a', 'c', 'o', 'n', 0x02 /* Length */, - 0x01 /* TYPE_FLAG */, - 0x4 /* BREDR_NOT_SUPPORTED */ | 0x2 /* GENERAL_DISCOVERABLE */ + 0x0F /* Length */, 0x09 /* TYPE_NAME_COMPLETE */, 'g', 'D', 'e', 'v', 'i', 'c', 'e', + '-', 'b', 'e', 'a', 'c', 'o', 'n', 0x02 /* Length */, 0x01 /* TYPE_FLAG */, + 0x4 /* BREDR_NOT_SUPPORTED */ | 0x2 /* GENERAL_DISCOVERABLE */ }), - scan_response_data_( - {0x05 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'b', 'e', 'a', 'c'}), + scan_response_data_({0x05 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'b', 'e', 'a', 'c'}), advertising_interval_(1280ms) {} Beacon::Beacon(const std::vector& args) : Beacon() { @@ -59,27 +57,24 @@ void Beacon::Tick() { std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); if ((now - advertising_last_) >= advertising_interval_) { advertising_last_ = now; - SendLinkLayerPacket( - std::move(LeLegacyAdvertisingPduBuilder::Create( - address_, Address::kEmpty, AddressType::PUBLIC, AddressType::PUBLIC, - advertising_type_, - std::vector(advertising_data_.begin(), advertising_data_.end()))), - Phy::Type::LOW_ENERGY); + SendLinkLayerPacket(LeLegacyAdvertisingPduBuilder::Create( + address_, Address::kEmpty, AddressType::PUBLIC, AddressType::PUBLIC, + advertising_type_, + std::vector(advertising_data_.begin(), advertising_data_.end())), + Phy::Type::LOW_ENERGY); } } -void Beacon::ReceiveLinkLayerPacket(LinkLayerPacketView packet, - Phy::Type /*type*/, int8_t /*rssi*/) { - if (packet.GetDestinationAddress() == address_ && - packet.GetType() == PacketType::LE_SCAN && +void Beacon::ReceiveLinkLayerPacket(LinkLayerPacketView packet, Phy::Type /*type*/, + int8_t /*rssi*/) { + if (packet.GetDestinationAddress() == address_ && packet.GetType() == PacketType::LE_SCAN && (advertising_type_ == LegacyAdvertisingType::ADV_IND || advertising_type_ == LegacyAdvertisingType::ADV_SCAN_IND)) { SendLinkLayerPacket( - std::move(LeScanResponseBuilder::Create( - address_, packet.GetSourceAddress(), AddressType::PUBLIC, - std::vector(scan_response_data_.begin(), - scan_response_data_.end()))), - Phy::Type::LOW_ENERGY); + LeScanResponseBuilder::Create( + address_, packet.GetSourceAddress(), AddressType::PUBLIC, + std::vector(scan_response_data_.begin(), scan_response_data_.end())), + Phy::Type::LOW_ENERGY); } } diff --git a/model/devices/beacon.h b/model/devices/beacon.h index 6b33197..33bd7be 100644 --- a/model/devices/beacon.h +++ b/model/devices/beacon.h @@ -32,7 +32,7 @@ namespace rootcanal { // Simple device that advertises with non-connectable advertising in general // discoverable mode, and responds to LE scan requests. class Beacon : public Device { - public: +public: Beacon(); Beacon(const std::vector& args); virtual ~Beacon() = default; @@ -44,18 +44,17 @@ class Beacon : public Device { virtual std::string GetTypeString() const override { return "beacon"; } virtual void Tick() override; - virtual void ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView packet, Phy::Type type, - int8_t rssi) override; + virtual void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, Phy::Type type, + int8_t rssi) override; - protected: +protected: model::packets::LegacyAdvertisingType advertising_type_{}; std::array advertising_data_{}; std::array scan_response_data_{}; std::chrono::steady_clock::duration advertising_interval_{}; std::chrono::steady_clock::time_point advertising_last_{}; - private: +private: static bool registered_; }; diff --git a/model/devices/beacon_swarm.cc b/model/devices/beacon_swarm.cc index af4b755..b0013d9 100644 --- a/model/devices/beacon_swarm.cc +++ b/model/devices/beacon_swarm.cc @@ -29,42 +29,40 @@ namespace rootcanal { using namespace model::packets; using namespace std::chrono_literals; -bool BeaconSwarm::registered_ = - DeviceBoutique::Register("beacon_swarm", &BeaconSwarm::Create); +bool BeaconSwarm::registered_ = DeviceBoutique::Register("beacon_swarm", &BeaconSwarm::Create); BeaconSwarm::BeaconSwarm(const std::vector& args) : Beacon(args) { advertising_interval_ = 1280ms; advertising_type_ = LegacyAdvertisingType::ADV_NONCONN_IND; advertising_data_ = { - 0x15 /* Length */, - 0x09 /* TYPE_NAME_COMPLETE */, - 'g', - 'D', - 'e', - 'v', - 'i', - 'c', - 'e', - '-', - 'b', - 'e', - 'a', - 'c', - 'o', - 'n', - '_', - 's', - 'w', - 'a', - 'r', - 'm', - 0x02 /* Length */, - 0x01 /* TYPE_FLAG */, - 0x4 /* BREDR_NOT_SUPPORTED */ | 0x2 /* GENERAL_DISCOVERABLE */, + 0x15 /* Length */, + 0x09 /* TYPE_NAME_COMPLETE */, + 'g', + 'D', + 'e', + 'v', + 'i', + 'c', + 'e', + '-', + 'b', + 'e', + 'a', + 'c', + 'o', + 'n', + '_', + 's', + 'w', + 'a', + 'r', + 'm', + 0x02 /* Length */, + 0x01 /* TYPE_FLAG */, + 0x4 /* BREDR_NOT_SUPPORTED */ | 0x2 /* GENERAL_DISCOVERABLE */, }; - scan_response_data_ = { - 0x06 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'c', 'b', 'e', 'a', 'c'}; + scan_response_data_ = {0x06 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'c', 'b', 'e', 'a', 'c'}; } void BeaconSwarm::Tick() { diff --git a/model/devices/beacon_swarm.h b/model/devices/beacon_swarm.h index 69f6dd4..70fe492 100644 --- a/model/devices/beacon_swarm.h +++ b/model/devices/beacon_swarm.h @@ -27,7 +27,7 @@ namespace rootcanal { // Pretend to be a lot of beacons by changing the advertising address. class BeaconSwarm : public Beacon { - public: +public: BeaconSwarm(const std::vector& args); virtual ~BeaconSwarm() = default; @@ -40,7 +40,7 @@ class BeaconSwarm : public Beacon { virtual void Tick() override; - private: +private: static bool registered_; }; diff --git a/model/devices/device.cc b/model/devices/device.cc index 9fadf9e..59bfa7f 100644 --- a/model/devices/device.cc +++ b/model/devices/device.cc @@ -37,9 +37,7 @@ Device::Device() : id_(next_instance_id()) { ASSERT(Address::FromString("BB:BB:BB:BB:BB:AD", address_)); } -std::string Device::ToString() const { - return GetTypeString() + "@" + address_.ToString(); -} +std::string Device::ToString() const { return GetTypeString() + "@" + address_.ToString(); } void Device::Close() { if (close_callback_ != nullptr) { @@ -47,14 +45,13 @@ void Device::Close() { } } -void Device::SendLinkLayerPacket( - std::shared_ptr packet, - Phy::Type type, int8_t tx_power) { +void Device::SendLinkLayerPacket(std::shared_ptr packet, + Phy::Type type, int8_t tx_power) { SendLinkLayerPacket(packet->SerializeToBytes(), type, tx_power); } -void Device::SendLinkLayerPacket(std::vector const& packet, - Phy::Type type, int8_t tx_power) { +void Device::SendLinkLayerPacket(std::vector const& packet, Phy::Type type, + int8_t tx_power) { if (send_ll_ != nullptr) { send_ll_(packet, type, tx_power); } @@ -65,8 +62,7 @@ void Device::RegisterCloseCallback(std::function close_callback) { } void Device::RegisterLinkLayerChannel( - std::function const&, Phy::Type, int8_t)> - send_ll) { + std::function const&, Phy::Type, int8_t)> send_ll) { send_ll_ = send_ll; } diff --git a/model/devices/device.h b/model/devices/device.h index 3d5f258..96bccfc 100644 --- a/model/devices/device.h +++ b/model/devices/device.h @@ -33,7 +33,7 @@ using ::bluetooth::hci::Address; // Represent a Bluetooth Device // - Provide Get*() and Set*() functions for device attributes. class Device { - public: +public: // Unique device identifier. const uint32_t id_; @@ -55,24 +55,20 @@ class Device { virtual void Tick() {} virtual void Close(); - virtual void ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView /*packet*/, Phy::Type /*type*/, - int8_t /*rssi*/) {} + virtual void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView /*packet*/, + Phy::Type /*type*/, int8_t /*rssi*/) {} - void SendLinkLayerPacket( - std::shared_ptr packet, - Phy::Type type, int8_t tx_power = 0); + void SendLinkLayerPacket(std::shared_ptr packet, + Phy::Type type, int8_t tx_power = 0); - void SendLinkLayerPacket(std::vector const& packet, Phy::Type type, - int8_t tx_power = 0); + void SendLinkLayerPacket(std::vector const& packet, Phy::Type type, int8_t tx_power = 0); void RegisterLinkLayerChannel( - std::function const&, Phy::Type, int8_t)> - send_ll); + std::function const&, Phy::Type, int8_t)> send_ll); void RegisterCloseCallback(std::function close_callback); - protected: +protected: // Unique device address. Used as public device address for // Bluetooth activities. Address address_; diff --git a/model/devices/hci_device.cc b/model/devices/hci_device.cc index 9f0b30b..5597fd0 100644 --- a/model/devices/hci_device.cc +++ b/model/devices/hci_device.cc @@ -30,35 +30,34 @@ namespace rootcanal { HciDevice::HciDevice(std::shared_ptr transport, ControllerProperties const& properties) - : DualModeController(ControllerProperties(properties)), - transport_(transport) { + : DualModeController(ControllerProperties(properties)), transport_(transport) { link_layer_controller_.SetLocalName(std::vector({ - 'g', - 'D', - 'e', - 'v', - 'i', - 'c', - 'e', - '-', - 'H', - 'C', - 'I', + 'g', + 'D', + 'e', + 'v', + 'i', + 'c', + 'e', + '-', + 'H', + 'C', + 'I', })); link_layer_controller_.SetExtendedInquiryResponse(std::vector({ - 12, // Length - 9, // Type: Device Name - 'g', - 'D', - 'e', - 'v', - 'i', - 'c', - 'e', - '-', - 'h', - 'c', - 'i', + 12, // Length + 9, // Type: Device Name + 'g', + 'D', + 'e', + 'v', + 'i', + 'c', + 'e', + '-', + 'h', + 'c', + 'i', })); RegisterEventChannel([this](std::shared_ptr> packet) { @@ -75,30 +74,29 @@ HciDevice::HciDevice(std::shared_ptr transport, }); transport_->RegisterCallbacks( - [this](PacketType packet_type, - const std::shared_ptr> packet) { - switch (packet_type) { - case PacketType::COMMAND: - HandleCommand(packet); - break; - case PacketType::ACL: - HandleAcl(packet); - break; - case PacketType::SCO: - HandleSco(packet); - break; - case PacketType::ISO: - HandleIso(packet); - break; - default: - ASSERT(false); - break; - } - }, - [this]() { - INFO(id_, "HCI transport closed"); - Close(); - }); + [this](PacketType packet_type, const std::shared_ptr> packet) { + switch (packet_type) { + case PacketType::COMMAND: + HandleCommand(packet); + break; + case PacketType::ACL: + HandleAcl(packet); + break; + case PacketType::SCO: + HandleSco(packet); + break; + case PacketType::ISO: + HandleIso(packet); + break; + default: + ASSERT(false); + break; + } + }, + [this]() { + INFO(id_, "HCI transport closed"); + Close(); + }); } void HciDevice::Tick() { diff --git a/model/devices/hci_device.h b/model/devices/hci_device.h index 38be7fb..020e6af 100644 --- a/model/devices/hci_device.h +++ b/model/devices/hci_device.h @@ -26,14 +26,12 @@ namespace rootcanal { class HciDevice : public DualModeController { - public: - HciDevice(std::shared_ptr transport, - ControllerProperties const& properties); +public: + HciDevice(std::shared_ptr transport, ControllerProperties const& properties); ~HciDevice() = default; - static std::shared_ptr Create( - std::shared_ptr transport, - ControllerProperties const& properties) { + static std::shared_ptr Create(std::shared_ptr transport, + ControllerProperties const& properties) { return std::make_shared(transport, properties); } @@ -43,7 +41,7 @@ class HciDevice : public DualModeController { void Close() override; - private: +private: std::shared_ptr transport_; }; diff --git a/model/devices/link_layer_socket_device.cc b/model/devices/link_layer_socket_device.cc index e61badf..fad0fba 100644 --- a/model/devices/link_layer_socket_device.cc +++ b/model/devices/link_layer_socket_device.cc @@ -34,16 +34,15 @@ using std::vector; namespace rootcanal { -LinkLayerSocketDevice::LinkLayerSocketDevice( - std::shared_ptr socket_fd, Phy::Type phy_type) +LinkLayerSocketDevice::LinkLayerSocketDevice(std::shared_ptr socket_fd, + Phy::Type phy_type) : socket_(socket_fd), phy_type_(phy_type), size_bytes_(std::make_shared>(kSizeBytes)) {} void LinkLayerSocketDevice::Tick() { if (receiving_size_) { - ssize_t bytes_received = - socket_->Recv(size_bytes_->data() + offset_, kSizeBytes); + ssize_t bytes_received = socket_->Recv(size_bytes_->data() + offset_, kSizeBytes); if (bytes_received <= 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { // Nothing available yet. @@ -65,8 +64,7 @@ void LinkLayerSocketDevice::Tick() { offset_ = 0; receiving_size_ = false; } - ssize_t bytes_received = - socket_->Recv(received_->data() + offset_, bytes_left_); + ssize_t bytes_received = socket_->Recv(received_->data() + offset_, bytes_left_); if (bytes_received <= 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) { // Nothing available yet. @@ -95,9 +93,8 @@ void LinkLayerSocketDevice::Close() { Device::Close(); } -void LinkLayerSocketDevice::ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView packet, Phy::Type /*type*/, - int8_t /*rssi*/) { +void LinkLayerSocketDevice::ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, + Phy::Type /*type*/, int8_t /*rssi*/) { std::vector packet_bytes = packet.bytes().bytes(); std::vector size_bytes; pdl::packet::Builder::write_le(size_bytes, packet_bytes.size()); diff --git a/model/devices/link_layer_socket_device.h b/model/devices/link_layer_socket_device.h index b91263a..5d28e79 100644 --- a/model/devices/link_layer_socket_device.h +++ b/model/devices/link_layer_socket_device.h @@ -32,31 +32,27 @@ namespace rootcanal { using android::net::AsyncDataChannel; class LinkLayerSocketDevice : public Device { - public: - LinkLayerSocketDevice(std::shared_ptr socket_fd, - Phy::Type phy_type); +public: + LinkLayerSocketDevice(std::shared_ptr socket_fd, Phy::Type phy_type); LinkLayerSocketDevice(LinkLayerSocketDevice&& s) = default; virtual ~LinkLayerSocketDevice() = default; - static std::unique_ptr Create( - std::shared_ptr socket_fd, Phy::Type phy_type) { + static std::unique_ptr Create(std::shared_ptr socket_fd, + Phy::Type phy_type) { return std::make_unique(socket_fd, phy_type); } - virtual std::string GetTypeString() const override { - return "link_layer_socket_device"; - } + virtual std::string GetTypeString() const override { return "link_layer_socket_device"; } - virtual void ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView packet, Phy::Type type, - int8_t rssi) override; + virtual void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, Phy::Type type, + int8_t rssi) override; virtual void Tick() override; virtual void Close() override; static constexpr size_t kSizeBytes = sizeof(uint32_t); - private: +private: std::shared_ptr socket_; Phy::Type phy_type_; bool receiving_size_{true}; diff --git a/model/devices/scripted_beacon.cc b/model/devices/scripted_beacon.cc index 9095d11..1e9bb66 100644 --- a/model/devices/scripted_beacon.cc +++ b/model/devices/scripted_beacon.cc @@ -39,44 +39,43 @@ using namespace model::packets; using namespace std::chrono_literals; bool ScriptedBeacon::registered_ = - DeviceBoutique::Register("scripted_beacon", &ScriptedBeacon::Create); + DeviceBoutique::Register("scripted_beacon", &ScriptedBeacon::Create); ScriptedBeacon::ScriptedBeacon(const vector& args) : Beacon(args) { advertising_interval_ = 1280ms; advertising_type_ = LegacyAdvertisingType::ADV_SCAN_IND; advertising_data_ = { - 0x18 /* Length */, - 0x09 /* TYPE_NAME_CMPL */, - 'g', - 'D', - 'e', - 'v', - 'i', - 'c', - 'e', - '-', - 's', - 'c', - 'r', - 'i', - 'p', - 't', - 'e', - 'd', - '-', - 'b', - 'e', - 'a', - 'c', - 'o', - 'n', - 0x02 /* Length */, - 0x01 /* TYPE_FLAG */, - 0x4 /* BREDR_NOT_SPT */ | 0x2 /* GEN_DISC_FLAG */, + 0x18 /* Length */, + 0x09 /* TYPE_NAME_CMPL */, + 'g', + 'D', + 'e', + 'v', + 'i', + 'c', + 'e', + '-', + 's', + 'c', + 'r', + 'i', + 'p', + 't', + 'e', + 'd', + '-', + 'b', + 'e', + 'a', + 'c', + 'o', + 'n', + 0x02 /* Length */, + 0x01 /* TYPE_FLAG */, + 0x4 /* BREDR_NOT_SPT */ | 0x2 /* GEN_DISC_FLAG */, }; - scan_response_data_ = { - 0x05 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'g', 'b', 'e', 'a'}; + scan_response_data_ = {0x05 /* Length */, 0x08 /* TYPE_NAME_SHORT */, 'g', 'b', 'e', 'a'}; INFO("Scripted_beacon registered {}", registered_); @@ -85,9 +84,8 @@ ScriptedBeacon::ScriptedBeacon(const vector& args) : Beacon(args) { events_file_ = args[3]; set_state(PlaybackEvent::INITIALIZED); } else { - ERROR( - "Initialization failed, need playback and playback events file " - "arguments"); + ERROR("Initialization failed, need playback and playback events file " + "arguments"); } } @@ -95,8 +93,7 @@ bool has_time_elapsed(steady_clock::time_point time_point) { return steady_clock::now() > time_point; } -static void populate_event(PlaybackEvent* event, - PlaybackEvent::PlaybackEventType type) { +static void populate_event(PlaybackEvent* event, PlaybackEvent::PlaybackEventType type) { INFO("Adding event: {}", PlaybackEvent::PlaybackEventType_Name(type)); event->set_type(type); event->set_secs_since_epoch(system_clock::now().time_since_epoch().count()); @@ -108,8 +105,7 @@ 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()) { INFO("Events file not opened yet, for event: {}", PlaybackEvent::PlaybackEventType_Name(state)); @@ -127,16 +123,14 @@ void ScriptedBeacon::Tick() { Beacon::Tick(); break; case PlaybackEvent::SCANNED_ONCE: - next_check_time_ = - steady_clock::now() + steady_clock::duration(std::chrono::seconds(1)); + next_check_time_ = steady_clock::now() + steady_clock::duration(std::chrono::seconds(1)); set_state(PlaybackEvent::WAITING_FOR_FILE); break; case PlaybackEvent::WAITING_FOR_FILE: if (!has_time_elapsed(next_check_time_)) { return; } - next_check_time_ = - steady_clock::now() + steady_clock::duration(std::chrono::seconds(1)); + next_check_time_ = steady_clock::now() + steady_clock::duration(std::chrono::seconds(1)); if (access(config_file_.c_str(), F_OK) == -1) { return; } @@ -168,9 +162,8 @@ void ScriptedBeacon::Tick() { case PlaybackEvent::PLAYBACK_STARTED: { while (has_time_elapsed(next_ad_.ad_time)) { auto ad = model::packets::LeLegacyAdvertisingPduBuilder::Create( - next_ad_.address, Address::kEmpty /* Destination */, - AddressType::RANDOM, AddressType::PUBLIC, - LegacyAdvertisingType::ADV_NONCONN_IND, next_ad_.ad); + next_ad_.address, Address::kEmpty /* Destination */, AddressType::RANDOM, + AddressType::PUBLIC, LegacyAdvertisingType::ADV_NONCONN_IND, next_ad_.ad); SendLinkLayerPacket(std::move(ad), Phy::Type::LOW_ENERGY); if (packet_num_ < ble_ad_list_.advertisements().size()) { get_next_advertisement(); @@ -179,10 +172,9 @@ void ScriptedBeacon::Tick() { if (events_ostream_.is_open()) { events_ostream_.close(); } - INFO( - "Completed Ble advertisement playback from file: {} with {} " - "packets", - config_file_, packet_num_); + INFO("Completed Ble advertisement playback from file: {} with {} " + "packets", + config_file_, packet_num_); break; } } @@ -194,29 +186,24 @@ void ScriptedBeacon::Tick() { } } -void ScriptedBeacon::ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView packet, Phy::Type /*type*/, - int8_t /*rssi*/) { +void ScriptedBeacon::ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, + Phy::Type /*type*/, int8_t /*rssi*/) { if (current_state_ == PlaybackEvent::INITIALIZED) { - if (packet.GetDestinationAddress() == address_ && - packet.GetType() == PacketType::LE_SCAN) { + if (packet.GetDestinationAddress() == address_ && packet.GetType() == PacketType::LE_SCAN) { set_state(PlaybackEvent::SCANNED_ONCE); SendLinkLayerPacket( - std::move(model::packets::LeScanResponseBuilder::Create( - address_, packet.GetSourceAddress(), AddressType::PUBLIC, - std::vector(scan_response_data_.begin(), - scan_response_data_.end()))), - Phy::Type::LOW_ENERGY); + model::packets::LeScanResponseBuilder::Create( + address_, packet.GetSourceAddress(), AddressType::PUBLIC, + std::vector(scan_response_data_.begin(), scan_response_data_.end())), + Phy::Type::LOW_ENERGY); } } } void ScriptedBeacon::get_next_advertisement() { std::string payload = ble_ad_list_.advertisements(packet_num_).payload(); - std::string mac_address = - ble_ad_list_.advertisements(packet_num_).mac_address(); - uint32_t delay_before_send_ms = - ble_ad_list_.advertisements(packet_num_).delay_before_send_ms(); + std::string mac_address = ble_ad_list_.advertisements(packet_num_).mac_address(); + uint32_t delay_before_send_ms = ble_ad_list_.advertisements(packet_num_).delay_before_send_ms(); next_ad_.ad.assign(payload.begin(), payload.end()); if (Address::IsValidAddress(mac_address)) { // formatted string with colons like "12:34:56:78:9a:bc" @@ -228,8 +215,7 @@ void ScriptedBeacon::get_next_advertisement() { } else { Address::FromString("BA:D0:AD:BA:D0:AD", next_ad_.address); } - next_ad_.ad_time += - steady_clock::duration(std::chrono::milliseconds(delay_before_send_ms)); + next_ad_.ad_time += steady_clock::duration(std::chrono::milliseconds(delay_before_send_ms)); packet_num_++; } } // namespace rootcanal diff --git a/model/devices/scripted_beacon.h b/model/devices/scripted_beacon.h index 4d62ac6..05ad079 100644 --- a/model/devices/scripted_beacon.h +++ b/model/devices/scripted_beacon.h @@ -23,13 +23,12 @@ #include "model/devices/beacon.h" #include "model/devices/scripted_beacon_ble_payload.pb.h" -using android::bluetooth::rootcanal::model::devices::ScriptedBeaconBleAdProto:: - PlaybackEvent; +using android::bluetooth::rootcanal::model::devices::ScriptedBeaconBleAdProto::PlaybackEvent; namespace rootcanal { // Pretend to be a lot of beacons by advertising from a file. class ScriptedBeacon : public Beacon { - public: +public: ScriptedBeacon(const std::vector& args); virtual ~ScriptedBeacon() = default; @@ -38,19 +37,15 @@ class ScriptedBeacon : public Beacon { } // Return a string representation of the type of device. - virtual std::string GetTypeString() const override { - return "scripted_beacon"; - } + virtual std::string GetTypeString() const override { return "scripted_beacon"; } - virtual std::string ToString() const override { - return "scripted_beacon " + config_file_; - } + virtual std::string ToString() const override { return "scripted_beacon " + config_file_; } void Tick() override; - void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet_view, - Phy::Type type, int8_t rssi) override; + void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet_view, Phy::Type type, + int8_t rssi) override; - private: +private: static bool registered_; std::string config_file_{}; std::string events_file_{}; @@ -69,7 +64,7 @@ class ScriptedBeacon : public Beacon { int packet_num_{0}; PlaybackEvent::PlaybackEventType current_state_{PlaybackEvent::UNKNOWN}; std::chrono::steady_clock::time_point next_check_time_{}; - android::bluetooth::rootcanal::model::devices::ScriptedBeaconBleAdProto:: - BleAdvertisementList ble_ad_list_; + android::bluetooth::rootcanal::model::devices::ScriptedBeaconBleAdProto::BleAdvertisementList + ble_ad_list_; }; } // namespace rootcanal diff --git a/model/devices/sniffer.cc b/model/devices/sniffer.cc index 793b078..02f5766 100644 --- a/model/devices/sniffer.cc +++ b/model/devices/sniffer.cc @@ -28,8 +28,7 @@ namespace rootcanal { -bool Sniffer::registered_ = - DeviceBoutique::Register("sniffer", &Sniffer::Create); +bool Sniffer::registered_ = DeviceBoutique::Register("sniffer", &Sniffer::Create); Sniffer::Sniffer(const std::vector& args) { if (args.size() >= 2) { @@ -37,8 +36,8 @@ Sniffer::Sniffer(const std::vector& args) { } } -void Sniffer::ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, - Phy::Type /*type*/, int8_t /*rssi*/) { +void Sniffer::ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, Phy::Type /*type*/, + int8_t /*rssi*/) { Address source = packet.GetSourceAddress(); Address dest = packet.GetDestinationAddress(); model::packets::PacketType packet_type = packet.GetType(); @@ -49,8 +48,7 @@ void Sniffer::ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, return; } - INFO("{} {} -> {} (Type {})", - (match_source ? (match_dest ? "<->" : "<--") : "-->"), source, dest, + INFO("{} {} -> {} (Type {})", (match_source ? (match_dest ? "<->" : "<--") : "-->"), source, dest, model::packets::PacketTypeText(packet_type)); } diff --git a/model/devices/sniffer.h b/model/devices/sniffer.h index 60bee3e..1f04d29 100644 --- a/model/devices/sniffer.h +++ b/model/devices/sniffer.h @@ -26,7 +26,7 @@ namespace rootcanal { class Sniffer : public Device { - public: +public: Sniffer(const std::vector& args); ~Sniffer() = default; @@ -36,11 +36,10 @@ class Sniffer : public Device { virtual std::string GetTypeString() const override { return "sniffer"; } - virtual void ReceiveLinkLayerPacket( - model::packets::LinkLayerPacketView packet, Phy::Type type, - int8_t rssi) override; + virtual void ReceiveLinkLayerPacket(model::packets::LinkLayerPacketView packet, Phy::Type type, + int8_t rssi) override; - private: +private: static bool registered_; }; diff --git a/model/hci/h4_data_channel_packetizer.cc b/model/hci/h4_data_channel_packetizer.cc index 15e6f3d..aa8edbe 100644 --- a/model/hci/h4_data_channel_packetizer.cc +++ b/model/hci/h4_data_channel_packetizer.cc @@ -33,16 +33,14 @@ namespace rootcanal { H4DataChannelPacketizer::H4DataChannelPacketizer( - std::shared_ptr socket, PacketReadCallback command_cb, - PacketReadCallback event_cb, PacketReadCallback acl_cb, - PacketReadCallback sco_cb, PacketReadCallback iso_cb, - ClientDisconnectCallback disconnect_cb) + std::shared_ptr socket, PacketReadCallback command_cb, + PacketReadCallback event_cb, PacketReadCallback acl_cb, PacketReadCallback sco_cb, + PacketReadCallback iso_cb, ClientDisconnectCallback disconnect_cb) : uart_socket_(socket), h4_parser_(command_cb, event_cb, acl_cb, sco_cb, iso_cb, true), disconnect_cb_(std::move(disconnect_cb)) {} -size_t H4DataChannelPacketizer::Send(uint8_t type, const uint8_t* data, - size_t length) { +size_t H4DataChannelPacketizer::Send(uint8_t type, const uint8_t* data, size_t length) { ssize_t ret = uart_socket_->Send(&type, sizeof(type)); if (ret == -1) { ERROR("Error writing to UART ({})", strerror(errno)); @@ -56,15 +54,12 @@ size_t H4DataChannelPacketizer::Send(uint8_t type, const uint8_t* data, to_be_written += ret; if (to_be_written != length + sizeof(type)) { - ERROR("{} / {} bytes written - something went wrong...", to_be_written, - length + sizeof(type)); + ERROR("{} / {} bytes written - something went wrong...", to_be_written, length + sizeof(type)); } return to_be_written; } -void H4DataChannelPacketizer::OnDataReady( - std::shared_ptr socket) { - +void H4DataChannelPacketizer::OnDataReady(std::shared_ptr socket) { // Continue reading from the async data channel as long as bytes // are available to read. Otherwise this limits the number of HCI // packets parsed to one every 3 ticks. @@ -90,8 +85,7 @@ void H4DataChannelPacketizer::OnDataReady( disconnect_cb_(); return; } - FATAL("Read error in {}: {}", fmt::underlying(h4_parser_.CurrentState()), - strerror(errno)); + FATAL("Read error in {}: {}", fmt::underlying(h4_parser_.CurrentState()), strerror(errno)); } h4_parser_.Consume(buffer.data(), bytes_read); } diff --git a/model/hci/h4_data_channel_packetizer.h b/model/hci/h4_data_channel_packetizer.h index 272373c..f32b643 100644 --- a/model/hci/h4_data_channel_packetizer.h +++ b/model/hci/h4_data_channel_packetizer.h @@ -31,19 +31,17 @@ using android::net::AsyncDataChannel; // A socket based H4DataChannelPacketizer. Call OnDataReady whenever // data can be read from the socket. class H4DataChannelPacketizer { - public: - H4DataChannelPacketizer(std::shared_ptr socket, - PacketReadCallback command_cb, - PacketReadCallback event_cb, - PacketReadCallback acl_cb, PacketReadCallback sco_cb, - PacketReadCallback iso_cb, +public: + H4DataChannelPacketizer(std::shared_ptr socket, PacketReadCallback command_cb, + PacketReadCallback event_cb, PacketReadCallback acl_cb, + PacketReadCallback sco_cb, PacketReadCallback iso_cb, ClientDisconnectCallback disconnect_cb); size_t Send(uint8_t type, const uint8_t* data, size_t length); void OnDataReady(std::shared_ptr socket); - private: +private: std::shared_ptr uart_socket_; H4Parser h4_parser_; diff --git a/model/hci/h4_parser.cc b/model/hci/h4_parser.cc index b84ad1f..c3aa76d 100644 --- a/model/hci/h4_parser.cc +++ b/model/hci/h4_parser.cc @@ -34,17 +34,15 @@ void H4Parser::Reset() { packet_type_ = 0; } -size_t H4Parser::HciGetPacketLengthForType(PacketType type, - const uint8_t* preamble) { - static const size_t - packet_length_offset[static_cast(PacketType::ISO) + 1] = { +size_t H4Parser::HciGetPacketLengthForType(PacketType type, const uint8_t* preamble) { + static const size_t packet_length_offset[static_cast(PacketType::ISO) + 1] = { 0, H4Parser::COMMAND_LENGTH_OFFSET, H4Parser::ACL_LENGTH_OFFSET, H4Parser::SCO_LENGTH_OFFSET, H4Parser::EVENT_LENGTH_OFFSET, H4Parser::ISO_LENGTH_OFFSET, - }; + }; size_t offset = packet_length_offset[static_cast(type)]; size_t size = preamble[offset]; @@ -58,8 +56,8 @@ size_t H4Parser::HciGetPacketLengthForType(PacketType type, } H4Parser::H4Parser(PacketReadCallback command_cb, PacketReadCallback event_cb, - PacketReadCallback acl_cb, PacketReadCallback sco_cb, - PacketReadCallback iso_cb, bool enable_recovery_state) + PacketReadCallback acl_cb, PacketReadCallback sco_cb, PacketReadCallback iso_cb, + bool enable_recovery_state) : command_cb_(std::move(command_cb)), event_cb_(std::move(event_cb)), acl_cb_(std::move(acl_cb)), @@ -109,19 +107,17 @@ bool H4Parser::Consume(const uint8_t* buffer, int32_t bytes_read) { return false; } if ((uint32_t)bytes_read > BytesRequested()) { - FATAL("More bytes read ({}) than expected ({})!", bytes_read, - bytes_to_read); + FATAL("More bytes read ({}) than expected ({})!", bytes_read, bytes_to_read); } - static const size_t preamble_size[static_cast(PacketType::ISO) + 1] = - { + static const size_t preamble_size[static_cast(PacketType::ISO) + 1] = { 0, H4Parser::COMMAND_PREAMBLE_SIZE, H4Parser::ACL_PREAMBLE_SIZE, H4Parser::SCO_PREAMBLE_SIZE, H4Parser::EVENT_PREAMBLE_SIZE, H4Parser::ISO_PREAMBLE_SIZE, - }; + }; switch (state_) { case HCI_TYPE: // bytes_read >= 1 @@ -167,16 +163,13 @@ bool H4Parser::Consume(const uint8_t* buffer, int32_t bytes_read) { switch (state_) { case HCI_TYPE: hci_packet_type_ = static_cast(packet_type_); - if (hci_packet_type_ != PacketType::ACL && - hci_packet_type_ != PacketType::SCO && - hci_packet_type_ != PacketType::COMMAND && - hci_packet_type_ != PacketType::EVENT && + if (hci_packet_type_ != PacketType::ACL && hci_packet_type_ != PacketType::SCO && + hci_packet_type_ != PacketType::COMMAND && hci_packet_type_ != PacketType::EVENT && hci_packet_type_ != PacketType::ISO) { if (!enable_recovery_state_) { FATAL("Received invalid packet type 0x{:x}", packet_type_); } - ERROR("Received invalid packet type 0x{:x}, entering recovery state", - packet_type_); + ERROR("Received invalid packet type 0x{:x}, entering recovery state", packet_type_); state_ = HCI_RECOVERY; hci_packet_type_ = PacketType::COMMAND; bytes_wanted_ = 1; @@ -187,8 +180,7 @@ bool H4Parser::Consume(const uint8_t* buffer, int32_t bytes_read) { break; case HCI_PREAMBLE: if (bytes_wanted_ == 0) { - size_t payload_size = - HciGetPacketLengthForType(hci_packet_type_, packet_.data()); + size_t payload_size = HciGetPacketLengthForType(hci_packet_type_, packet_.data()); if (payload_size == 0) { OnPacketReady(); state_ = HCI_TYPE; diff --git a/model/hci/h4_parser.h b/model/hci/h4_parser.h index e7a6363..a10d0b2 100644 --- a/model/hci/h4_parser.h +++ b/model/hci/h4_parser.h @@ -44,12 +44,12 @@ using ClientDisconnectCallback = std::function; // The parser will invoke the proper callbacks once a packet has been parsed. // The parser keeps internal state and is not thread safe. class H4Parser { - public: +public: enum State { HCI_TYPE, HCI_PREAMBLE, HCI_PAYLOAD, HCI_RECOVERY }; - H4Parser(PacketReadCallback command_cb, PacketReadCallback event_cb, - PacketReadCallback acl_cb, PacketReadCallback sco_cb, - PacketReadCallback iso_cb, bool enable_recovery_state = false); + H4Parser(PacketReadCallback command_cb, PacketReadCallback event_cb, PacketReadCallback acl_cb, + PacketReadCallback sco_cb, PacketReadCallback iso_cb, + bool enable_recovery_state = false); // Consumes the given number of bytes, returns true on success. bool Consume(const uint8_t* buffer, int32_t bytes); @@ -60,12 +60,12 @@ class H4Parser { // Resets the parser to the empty, initial state. void Reset(); - State CurrentState() { return state_; }; + State CurrentState() { return state_; } void EnableRecovery() { enable_recovery_state_ = true; } void DisableRecovery() { enable_recovery_state_ = false; } - private: +private: void OnPacketReady(); // 2 bytes for opcode, 1 byte for parameter length (Volume 2, Part E, 5.4.1) @@ -94,8 +94,7 @@ class H4Parser { PacketReadCallback sco_cb_; PacketReadCallback iso_cb_; - static size_t HciGetPacketLengthForType(PacketType type, - const uint8_t* preamble); + static size_t HciGetPacketLengthForType(PacketType type, const uint8_t* preamble); PacketType hci_packet_type_{PacketType::UNKNOWN}; @@ -106,8 +105,7 @@ class H4Parser { bool enable_recovery_state_{false}; }; -inline std::ostream& operator<<(std::ostream& os, - H4Parser::State const& state_) { +inline std::ostream& operator<<(std::ostream& os, H4Parser::State const& state_) { switch (state_) { case H4Parser::State::HCI_TYPE: os << "HCI_TYPE"; diff --git a/model/hci/hci_sniffer.cc b/model/hci/hci_sniffer.cc index ea3e2cb..9a0509d 100644 --- a/model/hci/hci_sniffer.cc +++ b/model/hci/hci_sniffer.cc @@ -28,9 +28,7 @@ HciSniffer::HciSniffer(std::shared_ptr transport, SetOutputStream(outputStream); } -void HciSniffer::SetPcapFilter(std::shared_ptr filter) { - filter_ = filter; -} +void HciSniffer::SetPcapFilter(std::shared_ptr filter) { filter_ = filter; } void HciSniffer::SetOutputStream(std::shared_ptr outputStream) { output_ = outputStream; @@ -42,8 +40,7 @@ void HciSniffer::SetOutputStream(std::shared_ptr outputStream) { } } -void HciSniffer::AppendRecord(PacketDirection packet_direction, - PacketType packet_type, +void HciSniffer::AppendRecord(PacketDirection packet_direction, PacketType packet_type, const std::vector& packet) { if (output_ == nullptr) { return; @@ -62,8 +59,7 @@ void HciSniffer::AppendRecord(PacketDirection packet_direction, // Apply the PCAP filter when provided. if (filter_ != nullptr) { - std::vector filtered_packet = - filter_->FilterHciPacket(packet, idc); + std::vector filtered_packet = filter_->FilterHciPacket(packet, idc); output_->write((char*)filtered_packet.data(), filtered_packet.size()); } else { output_->write((char*)packet.data(), packet.size()); @@ -73,16 +69,14 @@ void HciSniffer::AppendRecord(PacketDirection packet_direction, output_->flush(); } -void HciSniffer::RegisterCallbacks(PacketCallback packet_callback, - CloseCallback close_callback) { +void HciSniffer::RegisterCallbacks(PacketCallback packet_callback, CloseCallback close_callback) { transport_->RegisterCallbacks( - [this, packet_callback]( - PacketType packet_type, - const std::shared_ptr> packet) { - AppendRecord(PacketDirection::HOST_TO_CONTROLLER, packet_type, *packet); - packet_callback(packet_type, packet); - }, - close_callback); + [this, packet_callback](PacketType packet_type, + const std::shared_ptr> packet) { + AppendRecord(PacketDirection::HOST_TO_CONTROLLER, packet_type, *packet); + packet_callback(packet_type, packet); + }, + close_callback); } void HciSniffer::Tick() { transport_->Tick(); } @@ -94,8 +88,7 @@ void HciSniffer::Close() { } } -void HciSniffer::Send(PacketType packet_type, - const std::vector& packet) { +void HciSniffer::Send(PacketType packet_type, const std::vector& packet) { AppendRecord(PacketDirection::CONTROLLER_TO_HOST, packet_type, packet); transport_->Send(packet_type, packet); } diff --git a/model/hci/hci_sniffer.h b/model/hci/hci_sniffer.h index 5ad47fb..79a2b9c 100644 --- a/model/hci/hci_sniffer.h +++ b/model/hci/hci_sniffer.h @@ -35,16 +35,15 @@ enum class PacketDirection : uint8_t { // A Hci Transport that logs all the in and out going // packets to a stream. class HciSniffer : public HciTransport { - public: +public: HciSniffer(std::shared_ptr transport, std::shared_ptr outputStream = nullptr, std::shared_ptr filter = nullptr); ~HciSniffer() = default; - static std::shared_ptr Create( - std::shared_ptr transport, - std::shared_ptr outputStream = nullptr, - std::shared_ptr /*filter*/ = nullptr) { + static std::shared_ptr Create(std::shared_ptr transport, + std::shared_ptr outputStream = nullptr, + std::shared_ptr /*filter*/ = nullptr) { return std::make_shared(transport, outputStream); } @@ -52,18 +51,15 @@ class HciSniffer : public HciTransport { void SetOutputStream(std::shared_ptr outputStream); void SetPcapFilter(std::shared_ptr filter); - void Send(PacketType packet_type, - const std::vector& packet) override; + void Send(PacketType packet_type, const std::vector& packet) override; - void RegisterCallbacks(PacketCallback packet_callback, - CloseCallback close_callback) override; + void RegisterCallbacks(PacketCallback packet_callback, CloseCallback close_callback) override; void Tick() override; void Close() override; - private: - void AppendRecord(PacketDirection direction, PacketType type, - const std::vector& packet); +private: + void AppendRecord(PacketDirection direction, PacketType type, const std::vector& packet); std::shared_ptr output_; std::shared_ptr transport_; diff --git a/model/hci/hci_socket_transport.cc b/model/hci/hci_socket_transport.cc index 0fc556e..d7127f5 100644 --- a/model/hci/hci_socket_transport.cc +++ b/model/hci/hci_socket_transport.cc @@ -27,40 +27,36 @@ void HciSocketTransport::RegisterCallbacks(PacketCallback packet_callback, CloseCallback close_callback) { // TODO: Avoid the copy here by using new buffer in H4DataChannel h4_ = H4DataChannelPacketizer( - socket_, - [packet_callback](const std::vector& raw_command) { - std::shared_ptr> packet_copy = - std::make_shared>(raw_command); - packet_callback(PacketType::COMMAND, packet_copy); - }, - [](const std::vector&) { - FATAL("Unexpected Event in HciSocketTransport!"); - }, - [packet_callback](const std::vector& raw_acl) { - std::shared_ptr> packet_copy = - std::make_shared>(raw_acl); - packet_callback(PacketType::ACL, packet_copy); - }, - [packet_callback](const std::vector& raw_sco) { - std::shared_ptr> packet_copy = - std::make_shared>(raw_sco); - packet_callback(PacketType::SCO, packet_copy); - }, - [packet_callback](const std::vector& raw_iso) { - std::shared_ptr> packet_copy = - std::make_shared>(raw_iso); - packet_callback(PacketType::ISO, packet_copy); - }, - close_callback); + socket_, + [packet_callback](const std::vector& raw_command) { + std::shared_ptr> packet_copy = + std::make_shared>(raw_command); + packet_callback(PacketType::COMMAND, packet_copy); + }, + [](const std::vector&) { FATAL("Unexpected Event in HciSocketTransport!"); }, + [packet_callback](const std::vector& raw_acl) { + std::shared_ptr> packet_copy = + std::make_shared>(raw_acl); + packet_callback(PacketType::ACL, packet_copy); + }, + [packet_callback](const std::vector& raw_sco) { + std::shared_ptr> packet_copy = + std::make_shared>(raw_sco); + packet_callback(PacketType::SCO, packet_copy); + }, + [packet_callback](const std::vector& raw_iso) { + std::shared_ptr> packet_copy = + std::make_shared>(raw_iso); + packet_callback(PacketType::ISO, packet_copy); + }, + close_callback); } void HciSocketTransport::Tick() { h4_.OnDataReady(socket_); } -void HciSocketTransport::Send(PacketType packet_type, - const std::vector& packet) { +void HciSocketTransport::Send(PacketType packet_type, const std::vector& packet) { if (!socket_ || !socket_->Connected()) { - INFO("Closed socket. Dropping packet of type {}", - fmt::underlying(packet_type)); + INFO("Closed socket. Dropping packet of type {}", fmt::underlying(packet_type)); return; } uint8_t type = static_cast(packet_type); diff --git a/model/hci/hci_socket_transport.h b/model/hci/hci_socket_transport.h index e6e4a35..660c42e 100644 --- a/model/hci/hci_socket_transport.h +++ b/model/hci/hci_socket_transport.h @@ -27,25 +27,22 @@ namespace rootcanal { using android::net::AsyncDataChannel; class HciSocketTransport : public HciTransport { - public: +public: HciSocketTransport(std::shared_ptr socket); ~HciSocketTransport() = default; - static std::shared_ptr Create( - std::shared_ptr socket) { + static std::shared_ptr Create(std::shared_ptr socket) { return std::make_shared(socket); } - void Send(PacketType packet_type, - const std::vector& packet) override; + void Send(PacketType packet_type, const std::vector& packet) override; - void RegisterCallbacks(PacketCallback packet_callback, - CloseCallback close_callback) override; + void RegisterCallbacks(PacketCallback packet_callback, CloseCallback close_callback) override; void Tick() override; void Close() override; - private: +private: std::shared_ptr socket_; H4DataChannelPacketizer h4_{socket_, [](const std::vector&) {}, diff --git a/model/hci/hci_transport.h b/model/hci/hci_transport.h index 5aa10f1..9f3662e 100644 --- a/model/hci/hci_transport.h +++ b/model/hci/hci_transport.h @@ -24,22 +24,19 @@ namespace rootcanal { -using PacketCallback = std::function>)>; +using PacketCallback = std::function>)>; using CloseCallback = std::function; class HciTransport { - public: +public: virtual ~HciTransport() = default; /// Send the input HCI packet with the selected H4 packet type. /// The packet data contains the H4 header but not the IDC byte. - virtual void Send(PacketType packet_type, - std::vector const& packet) = 0; + virtual void Send(PacketType packet_type, std::vector const& packet) = 0; /// Register the handler for received HCI packets. - virtual void RegisterCallbacks(PacketCallback packet_callback, - CloseCallback close_callback) = 0; + virtual void RegisterCallbacks(PacketCallback packet_callback, CloseCallback close_callback) = 0; virtual void Tick() = 0; virtual void Close() = 0; diff --git a/model/setup/async_manager.cc b/model/setup/async_manager.cc index caa92a0..2475212 100644 --- a/model/setup/async_manager.cc +++ b/model/setup/async_manager.cc @@ -16,26 +16,29 @@ #include "async_manager.h" +#include +#include +#include + #include #include #include -#include #include -#include #include -#include #include #include "log.h" #ifndef TEMP_FAILURE_RETRY /* Used to retry syscalls that can return EINTR. */ -#define TEMP_FAILURE_RETRY(exp) ({ \ +#define TEMP_FAILURE_RETRY(exp) \ + ({ \ __typeof__(exp) _rc; \ do { \ - _rc = (exp); \ + _rc = (exp); \ } while (_rc == -1 && errno == EINTR); \ - _rc; }) + _rc; \ + }) #endif // TEMP_FAILURE_RETRY namespace rootcanal { @@ -84,8 +87,7 @@ namespace rootcanal { // 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; } @@ -103,9 +105,9 @@ 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) { +public: + int WatchFdForNonBlockingReads(int file_descriptor, + const ReadCallback& on_read_fd_ready_callback) { // add file descriptor and callback { std::unique_lock guard(internal_mutex_); @@ -146,8 +148,7 @@ class AsyncManager::AsyncFdWatcher { if (std::this_thread::get_id() != thread_.get_id()) { thread_.join(); } else { - WARNING("{}: Starting thread stop from inside the reading thread itself", - __func__); + WARNING("{}: Starting thread stop from inside the reading thread itself", __func__); } { @@ -158,7 +159,7 @@ class AsyncManager::AsyncFdWatcher { return 0; } - private: +private: // Make sure to call this with at least one file descriptor ready to be // watched upon or the thread routine will return immediately int tryStartThread() { @@ -168,19 +169,16 @@ class AsyncManager::AsyncFdWatcher { // set up the communication channel int pipe_fds[2]; if (pipe(pipe_fds)) { - ERROR( - "{}: Unable to establish a communication channel to the reading " - "thread", - __func__); + ERROR("{}: Unable to establish a communication channel to the reading " + "thread", + __func__); return -1; } // configure the fds as non blocking. - if (fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK) || - fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK)) { - ERROR( - "{}: Unable to configure the communication channel to the reading " - "thread", - __func__); + if (fcntl(pipe_fds[0], F_SETFL, O_NONBLOCK) || fcntl(pipe_fds[1], F_SETFL, O_NONBLOCK)) { + ERROR("{}: Unable to configure the communication channel to the reading " + "thread", + __func__); return -1; } @@ -224,8 +222,7 @@ class AsyncManager::AsyncFdWatcher { bool consumeThreadNotifications(fd_set& read_fds) const { 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; @@ -256,10 +253,9 @@ class AsyncManager::AsyncFdWatcher { // wait until there is data available to read on some FD int retval = select(nfds + 1, &read_fds, NULL, NULL, NULL); if (retval <= 0) { // there was some error or a timeout - ERROR( - "{}: There was an error while waiting for data on the file " - "descriptors: {}", - __func__, strerror(errno)); + ERROR("{}: There was an error while waiting for data on the file " + "descriptors: {}", + __func__, strerror(errno)); continue; } @@ -287,21 +283,20 @@ class AsyncManager::AsyncFdWatcher { // Async task manager implementation class AsyncManager::AsyncTaskManager { - public: +public: AsyncUserId GetNextUserId() { return lastUserId_++; } AsyncTaskId ExecAsync(AsyncUserId user_id, std::chrono::milliseconds delay, const TaskCallback& callback) { - return scheduleTask(std::make_shared( - std::chrono::steady_clock::now() + delay, callback, user_id)); + return scheduleTask( + std::make_shared(std::chrono::steady_clock::now() + delay, callback, user_id)); } - AsyncTaskId ExecAsyncPeriodically(AsyncUserId user_id, - std::chrono::milliseconds delay, + AsyncTaskId ExecAsyncPeriodically(AsyncUserId user_id, std::chrono::milliseconds delay, std::chrono::milliseconds period, const TaskCallback& callback) { - return scheduleTask(std::make_shared( - std::chrono::steady_clock::now() + delay, period, callback, user_id)); + return scheduleTask(std::make_shared(std::chrono::steady_clock::now() + delay, period, + callback, user_id)); } bool CancelAsyncTask(AsyncTaskId async_task_id) { @@ -349,37 +344,29 @@ class AsyncManager::AsyncTaskManager { if (std::this_thread::get_id() != thread_.get_id()) { thread_.join(); } else { - WARNING("{}: Starting thread stop from inside the task thread itself", - __func__); + WARNING("{}: Starting thread stop from inside the task thread itself", __func__); } return 0; } - private: +private: // Holds the data for each task class Task { - public: - Task(std::chrono::steady_clock::time_point time, - std::chrono::milliseconds period, const TaskCallback& callback, - AsyncUserId user) + public: + Task(std::chrono::steady_clock::time_point time, std::chrono::milliseconds period, + const TaskCallback& callback, AsyncUserId user) : time(time), periodic(true), period(period), callback(callback), task_id(kInvalidTaskId), user_id(user) {} - Task(std::chrono::steady_clock::time_point time, - const TaskCallback& callback, AsyncUserId user) - : time(time), - periodic(false), - callback(callback), - task_id(kInvalidTaskId), - user_id(user) {} + Task(std::chrono::steady_clock::time_point time, const TaskCallback& callback, AsyncUserId user) + : time(time), periodic(false), callback(callback), task_id(kInvalidTaskId), user_id(user) {} // 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; } @@ -389,7 +376,7 @@ class AsyncManager::AsyncTaskManager { std::chrono::steady_clock::time_point time; bool periodic; std::chrono::milliseconds period{}; - std::mutex in_callback; // Taken when the callback is active + std::mutex in_callback; // Taken when the callback is active TaskCallback callback; AsyncTaskId task_id; AsyncUserId user_id; @@ -397,8 +384,7 @@ 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& t1, - const std::shared_ptr& t2) const { + bool operator()(const std::shared_ptr& t1, const std::shared_ptr& t2) const { return *t1 < *t2; } }; @@ -454,9 +440,7 @@ class AsyncManager::AsyncTaskManager { return task->task_id; } - bool isTaskIdInUse(const AsyncTaskId& task_id) const { - return tasks_by_id_.count(task_id) != 0; - } + bool isTaskIdInUse(const AsyncTaskId& task_id) const { return tasks_by_id_.count(task_id) != 0; } int tryStartThread() { // need the lock because of the running flag and the cond var @@ -514,8 +498,7 @@ class AsyncManager::AsyncTaskManager { // Make a copy of the time_point because wait_until takes a reference // to it and may read it after waiting, by which time the task may // have been freed (e.g. via CancelAsyncTask). - std::chrono::steady_clock::time_point time = - (*task_queue_.begin())->time; + std::chrono::steady_clock::time_point time = (*task_queue_.begin())->time; internal_cond_var_.wait_until(guard, time); } else { internal_cond_var_.wait(guard); @@ -539,8 +522,7 @@ class AsyncManager::AsyncTaskManager { // Async Manager Implementation: AsyncManager::AsyncManager() - : fdWatcher_p_(new AsyncFdWatcher()), - taskManager_p_(new AsyncTaskManager()) {} + : fdWatcher_p_(new AsyncFdWatcher()), taskManager_p_(new AsyncTaskManager()) {} AsyncManager::~AsyncManager() { // Make sure the threads are stopped before destroying the object. @@ -553,31 +535,27 @@ 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) { fdWatcher_p_->StopWatchingFileDescriptor(file_descriptor); } -AsyncUserId AsyncManager::GetNextUserId() { - return taskManager_p_->GetNextUserId(); -} +AsyncUserId AsyncManager::GetNextUserId() { return taskManager_p_->GetNextUserId(); } -AsyncTaskId AsyncManager::ExecAsync(AsyncUserId user_id, - std::chrono::milliseconds delay, +AsyncTaskId AsyncManager::ExecAsync(AsyncUserId user_id, std::chrono::milliseconds delay, const TaskCallback& callback) { return taskManager_p_->ExecAsync(user_id, delay, callback); } -AsyncTaskId AsyncManager::ExecAsyncPeriodically( - AsyncUserId user_id, std::chrono::milliseconds delay, - std::chrono::milliseconds period, const TaskCallback& callback) { - return taskManager_p_->ExecAsyncPeriodically(user_id, delay, period, - callback); +AsyncTaskId AsyncManager::ExecAsyncPeriodically(AsyncUserId user_id, + std::chrono::milliseconds delay, + std::chrono::milliseconds period, + const TaskCallback& callback) { + return taskManager_p_->ExecAsyncPeriodically(user_id, delay, period, callback); } bool AsyncManager::CancelAsyncTask(AsyncTaskId async_task_id) { diff --git a/model/setup/async_manager.h b/model/setup/async_manager.h index d1861d2..a8eaff0 100644 --- a/model/setup/async_manager.h +++ b/model/setup/async_manager.h @@ -63,7 +63,7 @@ constexpr uint16_t kInvalidTaskId = 0; // AsyncManager object from different threads are granted to *NOT* run // concurrently. class AsyncManager { - public: +public: // Starts watching a file descriptor in a separate thread. The // on_read_fd_ready_callback() will be asynchronously called when it is // guaranteed that a call to read() on the FD will not block. No promise is @@ -88,10 +88,8 @@ class AsyncManager { // is not positive the callback will be asynchronously called once for each // time in the past that it should have been called and then scheduled for // future times. - AsyncTaskId ExecAsyncPeriodically(AsyncUserId user_id, - std::chrono::milliseconds delay, - std::chrono::milliseconds period, - const TaskCallback& callback); + AsyncTaskId ExecAsyncPeriodically(AsyncUserId user_id, std::chrono::milliseconds delay, + std::chrono::milliseconds period, const TaskCallback& callback); // Cancels the/every future occurrence of the action specified by this id. // The following invariants will hold: @@ -122,7 +120,7 @@ class AsyncManager { ~AsyncManager(); - private: +private: // Implementation of the FD watching part of AsyncManager, extracted to its // own class for clarity purposes. class AsyncFdWatcher; diff --git a/model/setup/device_boutique.cc b/model/setup/device_boutique.cc index ad04cbe..7825862 100644 --- a/model/setup/device_boutique.cc +++ b/model/setup/device_boutique.cc @@ -22,27 +22,24 @@ using std::vector; namespace rootcanal { -std::unordered_map( - const vector&)>>& +std::unordered_map(const vector&)>>& DeviceBoutique::GetMap() { - static std::unordered_map( - const vector&)>> - impl; + static std::unordered_map(const vector&)>> + impl; return impl; } // Register a constructor for a device type. bool DeviceBoutique::Register( - const std::string& device_type, - const std::function(const vector&)> - method) { + const std::string& device_type, + const std::function(const vector&)> method) { INFO("Registering {}", device_type); GetMap()[device_type] = method; return true; } -std::shared_ptr DeviceBoutique::Create( - const vector& args) { +std::shared_ptr DeviceBoutique::Create(const vector& args) { ASSERT(!args.empty()); auto device = GetMap().find(args[0]); diff --git a/model/setup/device_boutique.h b/model/setup/device_boutique.h index 2f07404..fc57a24 100644 --- a/model/setup/device_boutique.h +++ b/model/setup/device_boutique.h @@ -28,22 +28,21 @@ namespace rootcanal { // Create customized devices from a centralized shop. class DeviceBoutique { - public: +public: DeviceBoutique(); virtual ~DeviceBoutique() = default; // Register a constructor for a device type. static bool Register( - std::string const& device_type, - std::function(const std::vector&)> - method); + std::string const& device_type, + std::function(const std::vector&)> method); // Call the function that matches arg[0] with args static std::shared_ptr Create(const std::vector& args); - private: - static std::unordered_map( - const std::vector&)>>& +private: + static std::unordered_map< + std::string, std::function(const std::vector&)>>& GetMap(); }; diff --git a/model/setup/phy_device.cc b/model/setup/phy_device.cc index 59f3d52..297c0ee 100644 --- a/model/setup/phy_device.cc +++ b/model/setup/phy_device.cc @@ -26,8 +26,7 @@ PhyDevice::PhyDevice(std::string type, std::shared_ptr device) : id(device->id_), type(std::move(type)), device_(std::move(device)) { using namespace std::placeholders; ASSERT(device_ != nullptr); - device_->RegisterLinkLayerChannel( - std::bind(&PhyDevice::Send, this, _1, _2, _3)); + device_->RegisterLinkLayerChannel(std::bind(&PhyDevice::Send, this, _1, _2, _3)); } void PhyDevice::Register(PhyLayer* phy) { phy_layers_.insert(phy); } @@ -36,25 +35,19 @@ void PhyDevice::Unregister(PhyLayer* phy) { phy_layers_.erase(phy); } void PhyDevice::Tick() { device_->Tick(); } -bluetooth::hci::Address PhyDevice::GetAddress() const { - return device_->GetAddress(); -} +bluetooth::hci::Address PhyDevice::GetAddress() const { return device_->GetAddress(); } -std::shared_ptr PhyDevice::GetDevice() const { - return device_; -} +std::shared_ptr PhyDevice::GetDevice() const { return device_; } void PhyDevice::SetAddress(bluetooth::hci::Address address) { device_->SetAddress(std::move(address)); } -void PhyDevice::Receive(std::vector const& packet, Phy::Type type, - int8_t rssi) { +void PhyDevice::Receive(std::vector const& packet, Phy::Type type, int8_t rssi) { std::shared_ptr> packet_copy = - std::make_shared>(packet); + std::make_shared>(packet); model::packets::LinkLayerPacketView packet_view = - model::packets::LinkLayerPacketView::Create( - pdl::packet::slice(packet_copy)); + model::packets::LinkLayerPacketView::Create(pdl::packet::slice(packet_copy)); if (packet_view.IsValid()) { device_->ReceiveLinkLayerPacket(std::move(packet_view), type, rssi); } else { @@ -62,8 +55,7 @@ void PhyDevice::Receive(std::vector const& packet, Phy::Type type, } } -void PhyDevice::Send(std::vector const& packet, Phy::Type type, - int8_t tx_power) { +void PhyDevice::Send(std::vector const& packet, Phy::Type type, int8_t tx_power) { for (auto const& phy : phy_layers_) { if (phy->type == type) { phy->Send(packet, tx_power, id); diff --git a/model/setup/phy_device.h b/model/setup/phy_device.h index af45dbe..1a989bf 100644 --- a/model/setup/phy_device.h +++ b/model/setup/phy_device.h @@ -28,11 +28,11 @@ class PhyLayer; class Device; class PhyDevice { - public: +public: using Identifier = uint32_t; PhyDevice(std::string type, std::shared_ptr device); - PhyDevice(PhyDevice &&) = delete; + PhyDevice(PhyDevice&&) = delete; ~PhyDevice() = default; void Register(PhyLayer* phy); @@ -40,8 +40,7 @@ class PhyDevice { void Tick(); void Receive(std::vector const& packet, Phy::Type type, int8_t rssi); - void Send(std::vector const& packet, Phy::Type type, - int8_t tx_power); + void Send(std::vector const& packet, Phy::Type type, int8_t tx_power); bluetooth::hci::Address GetAddress() const; std::shared_ptr GetDevice() const; @@ -52,7 +51,7 @@ class PhyDevice { const Identifier id; const std::string type; - private: +private: const std::shared_ptr device_; std::unordered_set phy_layers_; }; diff --git a/model/setup/phy_layer.cc b/model/setup/phy_layer.cc index 301979c..2e15f74 100644 --- a/model/setup/phy_layer.cc +++ b/model/setup/phy_layer.cc @@ -45,8 +45,7 @@ void PhyLayer::UnregisterAll() { } int8_t PhyLayer::ComputeRssi(PhyDevice::Identifier /*sender_id*/, - PhyDevice::Identifier /*receiver_id*/, - int8_t /*tx_power*/) { + PhyDevice::Identifier /*receiver_id*/, int8_t /*tx_power*/) { // Perform no RSSI computation by default. // Clients overriding this function should use the TX power and // positional information to derive correct device-to-device RSSI. @@ -60,8 +59,7 @@ void PhyLayer::Send(std::vector const& packet, int8_t tx_power, for (const auto& device : phy_devices_) { // Do not send the packet back to the sender. if (sender_id != device->id) { - device->Receive(packet, type, - ComputeRssi(sender_id, device->id, tx_power)); + device->Receive(packet, type, ComputeRssi(sender_id, device->id, tx_power)); } } } diff --git a/model/setup/phy_layer.h b/model/setup/phy_layer.h index 4c14f45..2c96db7 100644 --- a/model/setup/phy_layer.h +++ b/model/setup/phy_layer.h @@ -28,7 +28,7 @@ namespace rootcanal { using rootcanal::PhyDevice; class PhyLayer { - public: +public: using Identifier = uint32_t; PhyLayer(Identifier id, Phy::Type type); @@ -40,8 +40,7 @@ class PhyLayer { // Compute the RSSI for a packet sent from one device to the other // with the specified TX power. - virtual int8_t ComputeRssi(PhyDevice::Identifier sender_id, - PhyDevice::Identifier receiver_id, + virtual int8_t ComputeRssi(PhyDevice::Identifier sender_id, PhyDevice::Identifier receiver_id, int8_t tx_power); void Register(std::shared_ptr device); @@ -54,7 +53,7 @@ class PhyLayer { const Identifier id; const Phy::Type type; - protected: +protected: // List of devices currently connected to the phy. std::list> phy_devices_; }; diff --git a/model/setup/test_channel_transport.cc b/model/setup/test_channel_transport.cc index 6b04326..d59cbb5 100644 --- a/model/setup/test_channel_transport.cc +++ b/model/setup/test_channel_transport.cc @@ -48,16 +48,15 @@ void TestChannelTransport::OnCommandReady(AsyncDataChannel* socket, uint8_t command_name_size = 0; ssize_t bytes_read = socket->Recv(&command_name_size, 1); if (bytes_read != 1) { - INFO("Unexpected (command_name_size) bytes_read: {} != {}, {}", bytes_read, - 1, strerror(errno)); + INFO("Unexpected (command_name_size) bytes_read: {} != {}, {}", bytes_read, 1, strerror(errno)); socket->Close(); } vector command_name_raw; command_name_raw.resize(command_name_size); bytes_read = socket->Recv(command_name_raw.data(), command_name_size); if (bytes_read != command_name_size) { - INFO("Unexpected (command_name) bytes_read: {} != {}, {}", bytes_read, - command_name_size, strerror(errno)); + INFO("Unexpected (command_name) bytes_read: {} != {}, {}", bytes_read, command_name_size, + strerror(errno)); } std::string command_name(command_name_raw.begin(), command_name_raw.end()); @@ -71,23 +70,20 @@ void TestChannelTransport::OnCommandReady(AsyncDataChannel* socket, uint8_t num_args = 0; bytes_read = socket->Recv(&num_args, 1); if (bytes_read != 1) { - INFO("Unexpected (num_args) bytes_read: {} != {}, {}", bytes_read, 1, - strerror(errno)); + INFO("Unexpected (num_args) bytes_read: {} != {}, {}", bytes_read, 1, strerror(errno)); } vector args; for (uint8_t i = 0; i < num_args; ++i) { uint8_t arg_size = 0; bytes_read = socket->Recv(&arg_size, 1); if (bytes_read != 1) { - INFO("Unexpected (arg_size) bytes_read: {} != {}, {}", bytes_read, 1, - strerror(errno)); + INFO("Unexpected (arg_size) bytes_read: {} != {}, {}", bytes_read, 1, strerror(errno)); } vector arg; arg.resize(arg_size); bytes_read = socket->Recv(arg.data(), arg_size); if (bytes_read != arg_size) { - INFO("Unexpected (arg) bytes_read: {} != {}, {}", bytes_read, arg_size, - strerror(errno)); + INFO("Unexpected (arg) bytes_read: {} != {}, {}", bytes_read, arg_size, strerror(errno)); } args.push_back(std::string(arg.begin(), arg.end())); } @@ -95,33 +91,29 @@ void TestChannelTransport::OnCommandReady(AsyncDataChannel* socket, command_handler_(command_name, args); } -void TestChannelTransport::SendResponse( - std::shared_ptr socket, const std::string& response) { +void TestChannelTransport::SendResponse(std::shared_ptr socket, + const std::string& response) { size_t size = response.size(); // Cap to 64K if (size > 0xffff) { size = 0xffff; } - uint8_t size_buf[4] = {static_cast(size & 0xff), - static_cast((size >> 8) & 0xff), - static_cast((size >> 16) & 0xff), - static_cast((size >> 24) & 0xff)}; + uint8_t size_buf[4] = { + static_cast(size & 0xff), static_cast((size >> 8) & 0xff), + static_cast((size >> 16) & 0xff), static_cast((size >> 24) & 0xff)}; ssize_t written = socket->Send(size_buf, 4); if (written == -1 && errno == EBADF) { WARNING("Unable to send a response. EBADF"); return; } - ASSERT_LOG(written == 4, "What happened? written = %zd errno = %d", written, + ASSERT_LOG(written == 4, "What happened? written = %zd errno = %d", written, errno); + written = socket->Send(reinterpret_cast(response.c_str()), size); + ASSERT_LOG(written == static_cast(size), "What happened? written = %zd errno = %d", written, errno); - written = - socket->Send(reinterpret_cast(response.c_str()), size); - ASSERT_LOG(written == static_cast(size), - "What happened? written = %zd errno = %d", written, errno); } void TestChannelTransport::RegisterCommandHandler( - const std::function&)>& callback) { + const std::function&)>& callback) { command_handler_ = callback; } diff --git a/model/setup/test_channel_transport.h b/model/setup/test_channel_transport.h index a740591..14081eb 100644 --- a/model/setup/test_channel_transport.h +++ b/model/setup/test_channel_transport.h @@ -21,7 +21,7 @@ #include // for string #include // for vector -#include "net/async_data_channel.h" // for AsyncDataChannel +#include "net/async_data_channel.h" // for AsyncDataChannel #include "net/async_data_channel_server.h" // for AsyncDataChannelServer (ptr only), Con... namespace rootcanal { @@ -33,33 +33,28 @@ using android::net::ConnectCallback; // Manages communications between test channel and the controller. Mirrors the // HciTransport for the test channel. class TestChannelTransport { - public: +public: TestChannelTransport() {} ~TestChannelTransport() {} // Opens a port and returns and starts listening for incoming connections. - bool SetUp(std::shared_ptr server, - ConnectCallback connection_callback); + bool SetUp(std::shared_ptr server, ConnectCallback connection_callback); // Closes the port (if succesfully opened in SetUp). void CleanUp(); // Sets the callback that fires when data is read in WatchFd(). void RegisterCommandHandler( - const std::function&)>& callback); + const std::function&)>& callback); // Send data back to the test channel. - static void SendResponse(std::shared_ptr socket, - const std::string& response); + static void SendResponse(std::shared_ptr socket, const std::string& response); - void OnCommandReady(AsyncDataChannel* socket, - std::function unwatch); + void OnCommandReady(AsyncDataChannel* socket, std::function unwatch); - private: - std::function&)> - command_handler_; +private: + std::function&)> command_handler_; std::function)> connection_callback_; std::shared_ptr socket_server_; diff --git a/model/setup/test_command_handler.cc b/model/setup/test_command_handler.cc index 45b947c..5907184 100644 --- a/model/setup/test_command_handler.cc +++ b/model/setup/test_command_handler.cc @@ -35,12 +35,9 @@ static size_t ParseIntParam(std::string const& in) { return static_cast(std::strtoul(in.c_str(), nullptr, 0)); } -TestCommandHandler::TestCommandHandler(TestModel& test_model) - : model_(test_model) { -#define SET_HANDLER(command_name, method) \ - active_commands_[command_name] = [this](const vector& param) { \ - method(param); \ - }; +TestCommandHandler::TestCommandHandler(TestModel& test_model) : model_(test_model) { +#define SET_HANDLER(command_name, method) \ + active_commands_[command_name] = [this](const vector& param) { method(param); }; SET_HANDLER("add", AddDevice); SET_HANDLER("add_remote", AddRemote); SET_HANDLER("del", RemoveDevice); @@ -85,8 +82,7 @@ void TestCommandHandler::AddDefaults() { StartTimer({}); } -void TestCommandHandler::HandleCommand(const std::string& name, - const vector& args) { +void TestCommandHandler::HandleCommand(const std::string& name, const vector& args) { if (active_commands_.count(name) == 0) { response_string_ = "Unhandled command: " + name; send_response_(response_string_); @@ -96,7 +92,7 @@ void TestCommandHandler::HandleCommand(const std::string& name, } void TestCommandHandler::RegisterSendResponse( - const std::function callback) { + const std::function callback) { send_response_ = callback; send_response_("RegisterSendResponse called"); } @@ -118,15 +114,13 @@ void TestCommandHandler::AddDevice(const vector& args) { INFO("Add {}", new_dev->ToString()); size_t dev_index = model_.AddDevice(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& 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; } @@ -155,8 +149,8 @@ void TestCommandHandler::RemoveDevice(const vector& args) { size_t dev_index = ParseIntParam(args[0]); model_.RemoveDevice(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_); } @@ -170,8 +164,7 @@ void TestCommandHandler::AddPhy(const vector& args) { model_.AddPhy(Phy::Type::BR_EDR); response_string_ = "TestCommandHandler 'add_phy' called with 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_); } @@ -180,40 +173,36 @@ void TestCommandHandler::RemovePhy(const vector& args) { size_t phy_index = ParseIntParam(args[0]); model_.RemovePhy(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& 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 = ParseIntParam(args[0]); size_t phy_index = ParseIntParam(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_); } void TestCommandHandler::RemoveDeviceFromPhy(const vector& 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 = ParseIntParam(args[0]); size_t phy_index = ParseIntParam(args[1]); model_.RemoveDeviceFromPhy(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_); } @@ -227,8 +216,7 @@ void TestCommandHandler::List(const vector& args) { void TestCommandHandler::SetDeviceAddress(const vector& 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; } @@ -244,14 +232,13 @@ void TestCommandHandler::SetDeviceAddress(const vector& args) { void TestCommandHandler::SetDeviceConfiguration(const vector& args) { if (args.size() != 2) { - response_string_ = - "TestCommandHandler 'set_device_configuration' takes two arguments"; + response_string_ = "TestCommandHandler 'set_device_configuration' takes two arguments"; send_response_(response_string_); return; } size_t device_id = ParseIntParam(args[0]); rootcanal::configuration::ControllerPreset preset = - rootcanal::configuration::ControllerPreset::DEFAULT; + rootcanal::configuration::ControllerPreset::DEFAULT; if (args[1] == "default") { preset = rootcanal::configuration::ControllerPreset::DEFAULT; @@ -259,9 +246,10 @@ void TestCommandHandler::SetDeviceConfiguration(const vector& args) preset = rootcanal::configuration::ControllerPreset::LAIRD_BL654; } else if (args[1] == "csr_rck_pts_dongle") { preset = rootcanal::configuration::ControllerPreset::CSR_RCK_PTS_DONGLE; + } else if (args[1] == "intel_be200") { + preset = rootcanal::configuration::ControllerPreset::INTEL_BE200; } else { - response_string_ = - "TestCommandHandler 'set_device_configuration' invalid configuration preset"; + response_string_ = "TestCommandHandler 'set_device_configuration' invalid configuration preset"; send_response_(response_string_); return; } diff --git a/model/setup/test_command_handler.h b/model/setup/test_command_handler.h index 4f41c32..751016e 100644 --- a/model/setup/test_command_handler.h +++ b/model/setup/test_command_handler.h @@ -30,15 +30,14 @@ namespace rootcanal { class TestCommandHandler { - public: +public: // Sets all of the methods to be used as callbacks in the HciHandler. TestCommandHandler(TestModel& test_model); ~TestCommandHandler() = default; // Dispatches the action corresponding to the command specified by |name|. - void HandleCommand(const std::string& name, - const std::vector& args); + void HandleCommand(const std::string& name, const std::vector& args); // Dispatches the action corresponding to the command specified by |name|. void RegisterSendResponse(std::function callback); @@ -87,14 +86,13 @@ class TestCommandHandler { // For manual testing void AddDefaults(); - private: +private: TestModel& model_; std::string response_string_; - std::unordered_map&)>> - active_commands_; + std::unordered_map&)>> + active_commands_; std::function send_response_; diff --git a/model/setup/test_model.cc b/model/setup/test_model.cc index 060b4cf..eb590bd 100644 --- a/model/setup/test_model.cc +++ b/model/setup/test_model.cc @@ -18,13 +18,12 @@ #include // for size_t -#include // for operator<<, setfill -#include // for basic_ostream -#include // for shared_ptr, make... +#include // for operator<<, setfill +#include // for basic_ostream +#include // for shared_ptr, make... #include #include // for remove_extent_t #include // for move -#include #include "include/phy.h" // for Phy, Phy::Type #include "log.h" @@ -33,20 +32,19 @@ namespace rootcanal { TestModel::TestModel( - std::function get_user_id, - std::function - event_scheduler, - - std::function - periodic_event_scheduler, - - std::function cancel_tasks_from_user, - std::function cancel, - std::function(const std::string&, int, Phy::Type)> - connect_to_remote, - std::array bluetooth_address_prefix) + std::function get_user_id, + std::function + event_scheduler, + + std::function + periodic_event_scheduler, + + std::function cancel_tasks_from_user, + std::function cancel, + std::function(const std::string&, int, Phy::Type)> + connect_to_remote, + std::array bluetooth_address_prefix) : bluetooth_address_prefix_(std::move(bluetooth_address_prefix)), get_user_id_(std::move(get_user_id)), schedule_task_(std::move(event_scheduler)), @@ -57,9 +55,7 @@ TestModel::TestModel( model_user_id_ = get_user_id_(); } -TestModel::~TestModel() { - StopTimer(); -} +TestModel::~TestModel() { StopTimer(); } void TestModel::SetTimerPeriod(std::chrono::milliseconds new_period) { timer_period_ = new_period; @@ -75,9 +71,8 @@ void TestModel::SetTimerPeriod(std::chrono::milliseconds new_period) { void TestModel::StartTimer() { INFO("StartTimer()"); - timer_tick_task_ = - schedule_periodic_task_(model_user_id_, std::chrono::milliseconds(0), - timer_period_, [this]() { TestModel::Tick(); }); + timer_tick_task_ = schedule_periodic_task_(model_user_id_, std::chrono::milliseconds(0), + timer_period_, [this]() { TestModel::Tick(); }); } void TestModel::StopTimer() { @@ -86,34 +81,32 @@ void TestModel::StopTimer() { timer_tick_task_ = kInvalidTaskId; } -std::unique_ptr TestModel::CreatePhyLayer(PhyLayer::Identifier id, - Phy::Type type) { +std::unique_ptr TestModel::CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type) { return std::make_unique(id, type); } -std::shared_ptr TestModel::CreatePhyDevice( - std::string type, std::shared_ptr device) { +std::shared_ptr TestModel::CreatePhyDevice(std::string type, + std::shared_ptr device) { return std::make_shared(std::move(type), std::move(device)); } Address TestModel::GenerateBluetoothAddress(uint32_t device_id) const { Address address({ - static_cast(device_id), - bluetooth_address_prefix_[4], - bluetooth_address_prefix_[3], - bluetooth_address_prefix_[2], - bluetooth_address_prefix_[1], - bluetooth_address_prefix_[0], + static_cast(device_id), + bluetooth_address_prefix_[4], + bluetooth_address_prefix_[3], + bluetooth_address_prefix_[2], + bluetooth_address_prefix_[1], + bluetooth_address_prefix_[0], }); if (reuse_device_addresses_) { // Find the first unused address. for (uint16_t b0 = 0; b0 <= 0xff; b0++) { address.address[0] = b0; - bool used = std::any_of(phy_devices_.begin(), phy_devices_.end(), - [address](auto& device) { - return device.second->GetAddress() == address; - }); + bool used = std::any_of(phy_devices_.begin(), phy_devices_.end(), [address](auto& device) { + return device.second->GetAddress() == address; + }); if (!used) { break; } @@ -126,8 +119,7 @@ Address TestModel::GenerateBluetoothAddress(uint32_t device_id) const { // Add a device to the test model. PhyDevice::Identifier TestModel::AddDevice(std::shared_ptr device) { std::string device_type = device->GetTypeString(); - std::shared_ptr phy_device = - CreatePhyDevice(device_type, std::move(device)); + std::shared_ptr phy_device = CreatePhyDevice(device_type, std::move(device)); phy_devices_[phy_device->id] = phy_device; return phy_device->id; } @@ -157,8 +149,7 @@ void TestModel::RemovePhy(PhyLayer::Identifier phy_id) { } // Add the selected device to the selected phy. -void TestModel::AddDeviceToPhy(PhyDevice::Identifier device_id, - PhyLayer::Identifier phy_id) { +void TestModel::AddDeviceToPhy(PhyDevice::Identifier device_id, PhyLayer::Identifier phy_id) { if (phy_layers_.find(phy_id) != phy_layers_.end() && phy_devices_.find(device_id) != phy_devices_.end()) { phy_layers_[phy_id]->Register(phy_devices_[device_id]); @@ -166,15 +157,13 @@ void TestModel::AddDeviceToPhy(PhyDevice::Identifier device_id, } // Remove the selected device from the selected phy. -void TestModel::RemoveDeviceFromPhy(PhyDevice::Identifier device_id, - PhyLayer::Identifier phy_id) { +void TestModel::RemoveDeviceFromPhy(PhyDevice::Identifier device_id, PhyLayer::Identifier phy_id) { if (phy_layers_.find(phy_id) != phy_layers_.end()) { phy_layers_[phy_id]->Unregister(device_id); } } -void TestModel::AddLinkLayerConnection(std::shared_ptr device, - Phy::Type type) { +void TestModel::AddLinkLayerConnection(std::shared_ptr device, Phy::Type type) { INFO(device->id_, "Adding a new link layer connection of type: {}", type == Phy::Type::BR_EDR ? "BR_EDR" : "LOW_ENERGY"); @@ -189,9 +178,7 @@ void TestModel::AddLinkLayerConnection(std::shared_ptr device, AsyncUserId user_id = get_user_id_(); device->RegisterCloseCallback([this, device_id, user_id] { schedule_task_(user_id, std::chrono::milliseconds(0), - [this, device_id, user_id]() { - OnConnectionClosed(device_id, user_id); - }); + [this, device_id, user_id]() { OnConnectionClosed(device_id, user_id); }); }); } @@ -203,8 +190,8 @@ void TestModel::AddRemote(const std::string& server, int port, Phy::Type type) { AddLinkLayerConnection(device, type); } -PhyDevice::Identifier TestModel::AddHciConnection( - std::shared_ptr device, std::optional
address) { +PhyDevice::Identifier TestModel::AddHciConnection(std::shared_ptr device, + std::optional
address) { // clients can specify BD_ADDR or have it set based on device_id. device->SetAddress(address.value_or(GenerateBluetoothAddress(device->id_))); AddDevice(std::static_pointer_cast(device)); @@ -219,23 +206,19 @@ PhyDevice::Identifier TestModel::AddHciConnection( AsyncUserId user_id = get_user_id_(); device->RegisterCloseCallback([this, device_id, user_id] { schedule_task_(user_id, std::chrono::milliseconds(0), - [this, device_id, user_id]() { - OnConnectionClosed(device_id, user_id); - }); + [this, device_id, user_id]() { OnConnectionClosed(device_id, user_id); }); }); return device->id_; } -void TestModel::OnConnectionClosed(PhyDevice::Identifier device_id, - AsyncUserId user_id) { +void TestModel::OnConnectionClosed(PhyDevice::Identifier device_id, AsyncUserId user_id) { if (phy_devices_.find(device_id) != phy_devices_.end()) { cancel_tasks_from_user_(user_id); RemoveDevice(device_id); } } -void TestModel::SetDeviceAddress(PhyDevice::Identifier device_id, - Address address) { +void TestModel::SetDeviceAddress(PhyDevice::Identifier device_id, Address address) { if (phy_devices_.find(device_id) != phy_devices_.end()) { phy_devices_[device_id]->SetAddress(std::move(address)); } @@ -245,8 +228,8 @@ void TestModel::SetDeviceConfiguration(PhyDevice::Identifier device_id, rootcanal::configuration::Controller const& configuration) { if (phy_devices_.find(device_id) != phy_devices_.end()) { if (phy_devices_[device_id]->GetDevice()->GetTypeString() == "hci_device") { - std::shared_ptr device = std::static_pointer_cast( - phy_devices_[device_id]->GetDevice()); + std::shared_ptr device = + std::static_pointer_cast(phy_devices_[device_id]->GetDevice()); device->SetProperties(ControllerProperties(configuration)); } else { ERROR(device_id, "failed to update the configuration, device is not a controller device"); diff --git a/model/setup/test_model.h b/model/setup/test_model.h index b9871a6..09996ca 100644 --- a/model/setup/test_model.h +++ b/model/setup/test_model.h @@ -20,15 +20,15 @@ #include // for size_t #include // for function #include -#include // for shared_ptr -#include // for string -#include // for vector +#include // for shared_ptr #include +#include // for string +#include // for vector -#include "hci/address.h" // for Address -#include "model/devices/hci_device.h" // for HciDevice -#include "model/setup/async_manager.h" // for AsyncUserId, AsyncTaskId -#include "phy.h" // for Phy, Phy::Type +#include "hci/address.h" // for Address +#include "model/devices/hci_device.h" // for HciDevice +#include "model/setup/async_manager.h" // for AsyncUserId, AsyncTaskId +#include "phy.h" // for Phy, Phy::Type #include "phy_layer.h" #include "rootcanal/configuration.pb.h" @@ -38,21 +38,18 @@ class Device; using ::bluetooth::hci::Address; class TestModel { - public: - TestModel( - std::function get_user_id, - std::function - event_scheduler, - std::function - periodic_event_scheduler, - std::function cancel_tasks_from_user, - std::function cancel, - std::function(const std::string&, int, Phy::Type)> - connect_to_remote, - std::array bluetooth_address_prefix = {0xda, 0x4c, 0x10, 0xde, - 0x17}); +public: + TestModel(std::function get_user_id, + std::function + event_scheduler, + std::function + periodic_event_scheduler, + std::function cancel_tasks_from_user, + std::function cancel, + std::function(const std::string&, int, Phy::Type)> + connect_to_remote, + std::array bluetooth_address_prefix = {0xda, 0x4c, 0x10, 0xde, 0x17}); virtual ~TestModel(); TestModel(TestModel& model) = delete; @@ -63,12 +60,11 @@ class TestModel { } // Allow derived classes to use custom phy layer. - virtual std::unique_ptr CreatePhyLayer(PhyLayer::Identifier id, - Phy::Type type); + virtual std::unique_ptr CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type); // Allow derived classes to use custom phy devices. - virtual std::shared_ptr CreatePhyDevice( - std::string type, std::shared_ptr device); + virtual std::shared_ptr CreatePhyDevice(std::string type, + std::shared_ptr device); // Test model commands @@ -76,10 +72,8 @@ class TestModel { void RemoveDevice(PhyDevice::Identifier id); PhyLayer::Identifier AddPhy(Phy::Type type); void RemovePhy(PhyLayer::Identifier id); - void AddDeviceToPhy(PhyDevice::Identifier device_id, - PhyLayer::Identifier phy_id); - void RemoveDeviceFromPhy(PhyDevice::Identifier device_id, - PhyLayer::Identifier phy_id); + void AddDeviceToPhy(PhyDevice::Identifier device_id, PhyLayer::Identifier phy_id); + void RemoveDeviceFromPhy(PhyDevice::Identifier device_id, PhyLayer::Identifier phy_id); // Runtime implementation. @@ -95,8 +89,7 @@ class TestModel { void AddRemote(const std::string& server, int port, Phy::Type phy_type); // Set the device's Bluetooth address - void SetDeviceAddress(PhyDevice::Identifier device_id, - Address device_address); + void SetDeviceAddress(PhyDevice::Identifier device_id, Address device_address); void SetDeviceConfiguration(PhyDevice::Identifier device_id, rootcanal::configuration::Controller const& configuration); @@ -113,7 +106,7 @@ class TestModel { // Clear all devices and phys. void Reset(); - private: +private: Address GenerateBluetoothAddress(uint32_t device_id) const; std::map> phy_layers_; @@ -129,16 +122,14 @@ class TestModel { // Callbacks to schedule tasks. std::function get_user_id_; - std::function + schedule_task_; + std::function - schedule_task_; - std::function - schedule_periodic_task_; + schedule_periodic_task_; std::function cancel_task_; std::function cancel_tasks_from_user_; - std::function(const std::string&, int, Phy::Type)> - connect_to_remote_; + std::function(const std::string&, int, Phy::Type)> connect_to_remote_; AsyncUserId model_user_id_; AsyncTaskId timer_tick_task_{kInvalidTaskId}; diff --git a/net/async_data_channel.h b/net/async_data_channel.h index 3cd3441..d2e2963 100644 --- a/net/async_data_channel.h +++ b/net/async_data_channel.h @@ -41,7 +41,7 @@ using ReadCallback = std::function; // data. Async Sockets are usually non-blocking posix/win sockets, but could be // other types of datachannels (gRPC, qemu pipe) class AsyncDataChannel { - public: +public: virtual ~AsyncDataChannel() = default; // Receive data in the given buffer. Properly handling EINTR where @@ -84,8 +84,7 @@ class AsyncDataChannel { // not return EAGAIN. Returns false if registration of the watcher failed. // // Only one callback can be registered per socket. - virtual bool WatchForNonBlockingRead( - const ReadCallback& on_read_ready_callback) = 0; + virtual bool WatchForNonBlockingRead(const ReadCallback& on_read_ready_callback) = 0; // Stops watching this socket, you will not receive any callbacks any longer. virtual void StopWatching() = 0; diff --git a/net/async_data_channel_connector.h b/net/async_data_channel_connector.h index 5df9862..a411785 100644 --- a/net/async_data_channel_connector.h +++ b/net/async_data_channel_connector.h @@ -25,7 +25,7 @@ using namespace std::chrono_literals; // An AsyncDataChannelConnector is capable of connecting to a remote server. class AsyncDataChannelConnector { - public: +public: virtual ~AsyncDataChannelConnector() = default; // Blocks and waits until a connection to the remote server has been @@ -36,8 +36,7 @@ class AsyncDataChannelConnector { // In case of a disconnected DataChannel (socket->Connected() == false) // the errno variable can be set with the encountered error. virtual std::shared_ptr ConnectToRemoteServer( - const std::string& server, int port, - std::chrono::milliseconds timeout = 5000ms) = 0; + const std::string& server, int port, std::chrono::milliseconds timeout = 5000ms) = 0; }; } // namespace net } // namespace android diff --git a/net/async_data_channel_server.h b/net/async_data_channel_server.h index 59821ee..f63deb2 100644 --- a/net/async_data_channel_server.h +++ b/net/async_data_channel_server.h @@ -24,14 +24,14 @@ namespace net { class AsyncDataChannelServer; // Callback thas is called when a new client connection has been accepted. -using ConnectCallback = std::function, - AsyncDataChannelServer* server)>; +using ConnectCallback = + std::function, AsyncDataChannelServer* server)>; // An AsyncDataChannelServer is capable of listening to incoming connections. // // A Callback will be invoked whenever a new connection has been accepted. class AsyncDataChannelServer { - public: +public: // Destructor. virtual ~AsyncDataChannelServer() = default; @@ -62,11 +62,9 @@ class AsyncDataChannelServer { // Before the callback the server should have stopped listening for new // incoming connections. The callee is responsible for calling StartListening // if needed. - void SetOnConnectCallback(const ConnectCallback& callback) { - callback_ = callback; - }; + void SetOnConnectCallback(const ConnectCallback& callback) { callback_ = callback; } - protected: +protected: ConnectCallback callback_; }; diff --git a/net/posix/posix_async_socket.cc b/net/posix/posix_async_socket.cc index d6c982e..8ff175c 100644 --- a/net/posix/posix_async_socket.cc +++ b/net/posix/posix_async_socket.cc @@ -38,8 +38,7 @@ namespace android { namespace net { -PosixAsyncSocket::PosixAsyncSocket(int fd, AsyncManager* am) - : fd_(fd), am_(am), watching_(false) { +PosixAsyncSocket::PosixAsyncSocket(int fd, AsyncManager* am) : fd_(fd), am_(am), watching_(false) { int flags = fcntl(fd, F_GETFL); fcntl(fd, F_SETFL, flags | O_NONBLOCK); @@ -80,7 +79,7 @@ ssize_t PosixAsyncSocket::Recv(uint8_t* buffer, uint64_t bufferSize) { } DD("{} bytes ({})", res, fd_); return res; -}; +} ssize_t PosixAsyncSocket::Send(const uint8_t* buffer, uint64_t bufferSize) { errno = 0; @@ -125,8 +124,7 @@ void PosixAsyncSocket::Close() { // Clear out error int error_code = 0; socklen_t error_code_size = sizeof(error_code); - getsockopt(fd_, SOL_SOCKET, SO_ERROR, reinterpret_cast(&error_code), - &error_code_size); + getsockopt(fd_, SOL_SOCKET, SO_ERROR, reinterpret_cast(&error_code), &error_code_size); // shutdown sockets if possible, REPEAT_UNTIL_NO_INTR(shutdown(fd_, SHUT_RDWR)); @@ -139,14 +137,12 @@ void PosixAsyncSocket::Close() { fd_ = -1; } -bool PosixAsyncSocket::WatchForNonBlockingRead( - const ReadCallback& on_read_ready_callback) { +bool PosixAsyncSocket::WatchForNonBlockingRead(const ReadCallback& on_read_ready_callback) { bool expected = false; if (watching_.compare_exchange_strong(expected, true)) { - return am_->WatchFdForNonBlockingReads( - fd_, [on_read_ready_callback, this](int /* fd */) { - on_read_ready_callback(this); - }) == 0; + return am_->WatchFdForNonBlockingReads(fd_, [on_read_ready_callback, this](int /* fd */) { + on_read_ready_callback(this); + }) == 0; } return false; } diff --git a/net/posix/posix_async_socket.h b/net/posix/posix_async_socket.h index a76a215..8fa5213 100644 --- a/net/posix/posix_async_socket.h +++ b/net/posix/posix_async_socket.h @@ -32,7 +32,7 @@ using rootcanal::AsyncManager; // // Supports both Darwin and Linux. class PosixAsyncSocket : public AsyncDataChannel { - public: +public: // The AsyncManager must support the following: // // - If a callback happens on thread t, and @@ -69,14 +69,13 @@ class PosixAsyncSocket : public AsyncDataChannel { // Registers the given callback to be invoked when a recv call can be made // to read data from this socket. // Only one callback can be registered per socket. - bool WatchForNonBlockingRead( - const ReadCallback& on_read_ready_callback) override; + bool WatchForNonBlockingRead(const ReadCallback& on_read_ready_callback) override; void StopWatching() override; int fd() const { return fd_; } - private: +private: void OnReadCallback(); int fd_; diff --git a/net/posix/posix_async_socket_connector.cc b/net/posix/posix_async_socket_connector.cc index ed02bc1..4b7691a 100644 --- a/net/posix/posix_async_socket_connector.cc +++ b/net/posix/posix_async_socket_connector.cc @@ -30,17 +30,13 @@ namespace android { namespace net { -PosixAsyncSocketConnector::PosixAsyncSocketConnector(AsyncManager* am) - : am_(am) {} +PosixAsyncSocketConnector::PosixAsyncSocketConnector(AsyncManager* am) : am_(am) {} -std::shared_ptr -PosixAsyncSocketConnector::ConnectToRemoteServer( - const std::string& server, int port, - const std::chrono::milliseconds timeout) { +std::shared_ptr PosixAsyncSocketConnector::ConnectToRemoteServer( + const std::string& server, int port, const std::chrono::milliseconds timeout) { INFO("Connecting to {}:{} in {} ms", server, port, timeout.count()); int socket_fd = socket(AF_INET, SOCK_STREAM, 0); - std::shared_ptr pas = - std::make_shared(socket_fd, am_); + std::shared_ptr pas = std::make_shared(socket_fd, am_); if (socket_fd < 1) { INFO("socket() call failed: {}", strerror(errno)); @@ -61,32 +57,28 @@ PosixAsyncSocketConnector::ConnectToRemoteServer( serv_addr.sin_addr.s_addr = inet_addr(inet_ntoa(*addr_list[0])); serv_addr.sin_port = htons(port); - int result = - connect(socket_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); + int result = connect(socket_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); - if (result != 0 && errno != EWOULDBLOCK && errno != EAGAIN && - errno != EINPROGRESS) { - INFO("Failed to connect to {}:{}, error: {}", server, port, - strerror(errno)); + if (result != 0 && errno != EWOULDBLOCK && errno != EAGAIN && errno != EINPROGRESS) { + INFO("Failed to connect to {}:{}, error: {}", server, port, strerror(errno)); pas->Close(); return pas; } // wait for the connection. struct pollfd fds[] = { - { - .fd = socket_fd, - .events = POLLIN | POLLOUT | POLLHUP, - .revents = 0, - }, + { + .fd = socket_fd, + .events = POLLIN | POLLOUT | POLLHUP, + .revents = 0, + }, }; int numFdsReady = 0; REPEAT_UNTIL_NO_INTR(numFdsReady = ::poll(fds, 1, timeout.count())); if (numFdsReady <= 0) { - INFO("Failed to connect to {}:{}, error: {}", server, port, - strerror(errno)); + INFO("Failed to connect to {}:{}, error: {}", server, port, strerror(errno)); pas->Close(); return pas; } @@ -97,17 +89,14 @@ PosixAsyncSocketConnector::ConnectToRemoteServer( socklen_t sslen = sizeof(ss); if (getpeername(socket_fd, (struct sockaddr*)&ss, &sslen) < 0) { - INFO("Failed to connect to {}:{}, error: {}", server, port, - strerror(errno)); + INFO("Failed to connect to {}:{}, error: {}", server, port, strerror(errno)); pas->Close(); return pas; } int err = 0; socklen_t optLen = sizeof(err); - if (getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast(&err), - &optLen) || - err) { + if (getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast(&err), &optLen) || err) { // Either getsockopt failed or there was an error associated // with the socket. The connection did not succeed. INFO("Failed to connect to {}:{}, error: {}", server, port, strerror(err)); diff --git a/net/posix/posix_async_socket_connector.h b/net/posix/posix_async_socket_connector.h index 2bf3431..ea5c5e9 100644 --- a/net/posix/posix_async_socket_connector.h +++ b/net/posix/posix_async_socket_connector.h @@ -39,7 +39,7 @@ using namespace std::chrono_literals; // // Supports both Darwin (freebsd) and linux. class PosixAsyncSocketConnector : public AsyncDataChannelConnector { - public: +public: PosixAsyncSocketConnector(AsyncManager* am); ~PosixAsyncSocketConnector() = default; @@ -50,10 +50,9 @@ class PosixAsyncSocketConnector : public AsyncDataChannelConnector { // Note: This does not mean that the socket is fully opened! A server // might not (yet?) have called accept on the socket. std::shared_ptr ConnectToRemoteServer( - const std::string& server, int port, - std::chrono::milliseconds timeout = 5000ms); + const std::string& server, int port, std::chrono::milliseconds timeout = 5000ms); - private: +private: AsyncManager* am_; }; } // namespace net diff --git a/net/posix/posix_async_socket_server.cc b/net/posix/posix_async_socket_server.cc index 185f17d..3f20e72 100644 --- a/net/posix/posix_async_socket_server.cc +++ b/net/posix/posix_async_socket_server.cc @@ -30,8 +30,7 @@ namespace android { namespace net { class AsyncDataChannel; -PosixAsyncSocketServer::PosixAsyncSocketServer(int port, AsyncManager* am) - : port_(port), am_(am) { +PosixAsyncSocketServer::PosixAsyncSocketServer(int port, AsyncManager* am) : port_(port), am_(am) { int listen_fd = 0; struct sockaddr_in listen_address {}; socklen_t sockaddr_in_size = sizeof(struct sockaddr_in); @@ -46,8 +45,7 @@ PosixAsyncSocketServer::PosixAsyncSocketServer(int port, AsyncManager* am) } int enable = 1; - if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < - 0) { + if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) { ERROR("setsockopt(SO_REUSEADDR) failed: {}", strerror(errno)); } @@ -55,10 +53,8 @@ PosixAsyncSocketServer::PosixAsyncSocketServer(int port, AsyncManager* am) listen_address.sin_port = htons(port_); listen_address.sin_addr.s_addr = htonl(INADDR_ANY); - if (bind(listen_fd, reinterpret_cast(&listen_address), - sockaddr_in_size) < 0) { - INFO("Error binding test channel listener socket to port: {}, {}", port, - strerror(errno)); + if (bind(listen_fd, reinterpret_cast(&listen_address), sockaddr_in_size) < 0) { + INFO("Error binding test channel listener socket to port: {}, {}", port, strerror(errno)); close(listen_fd); return; } @@ -86,7 +82,7 @@ bool PosixAsyncSocketServer::StartListening() { } server_socket_->WatchForNonBlockingRead( - [this](AsyncDataChannel* /* socket */) { AcceptSocket(); }); + [this](AsyncDataChannel* /* socket */) { AcceptSocket(); }); return true; } @@ -96,17 +92,14 @@ void PosixAsyncSocketServer::Close() { } } -bool PosixAsyncSocketServer::Connected() { - return server_socket_ && server_socket_->Connected(); -} +bool PosixAsyncSocketServer::Connected() { return server_socket_ && server_socket_->Connected(); } void PosixAsyncSocketServer::AcceptSocket() { int accept_fd = 0; REPEAT_UNTIL_NO_INTR(accept_fd = accept(server_socket_->fd(), NULL, NULL)); if (accept_fd < 0) { - INFO("Error accepting test channel connection errno={} ({}).", errno, - strerror(errno)); + INFO("Error accepting test channel connection errno={} ({}).", errno, strerror(errno)); return; } diff --git a/net/posix/posix_async_socket_server.h b/net/posix/posix_async_socket_server.h index e5d012b..75590ad 100644 --- a/net/posix/posix_async_socket_server.h +++ b/net/posix/posix_async_socket_server.h @@ -33,13 +33,13 @@ namespace net { // // It uses the AsyncManager for watching the socket. class PosixAsyncSocketServer : public AsyncDataChannelServer { - public: +public: // Binds to the given port on all interfaces. // Note: do not use port 0! PosixAsyncSocketServer(int port, AsyncManager* am); // Return the port that this server was initialized with. - int port() const { return port_; }; + int port() const { return port_; } bool StartListening() override; @@ -49,7 +49,7 @@ class PosixAsyncSocketServer : public AsyncDataChannelServer { bool Connected() override; - private: +private: void AcceptSocket(); int port_; diff --git a/packets/hci_packets.pdl b/packets/hci_packets.pdl index 363002a..8f3d3c1 100644 --- a/packets/hci_packets.pdl +++ b/packets/hci_packets.pdl @@ -236,14 +236,14 @@ enum OpCode : 16 { // TESTING READ_LOOPBACK_MODE = 0x1801, WRITE_LOOPBACK_MODE = 0x1802, - ENABLE_DEVICE_UNDER_TEST_MODE = 0x1803, + ENABLE_IMPLEMENTATION_UNDER_TEST_MODE = 0x1803, WRITE_SIMPLE_PAIRING_DEBUG_MODE = 0x1804, WRITE_SECURE_CONNECTIONS_TEST_MODE = 0x180A, // LE_CONTROLLER LE_SET_EVENT_MASK = 0x2001, LE_READ_BUFFER_SIZE_V1 = 0x2002, - LE_READ_LOCAL_SUPPORTED_FEATURES = 0x2003, + LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0 = 0x2003, LE_SET_RANDOM_ADDRESS = 0x2005, LE_SET_ADVERTISING_PARAMETERS = 0x2006, LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER = 0x2007, @@ -261,7 +261,7 @@ enum OpCode : 16 { LE_CONNECTION_UPDATE = 0x2013, LE_SET_HOST_CHANNEL_CLASSIFICATION = 0x2014, LE_READ_CHANNEL_MAP = 0x2015, - LE_READ_REMOTE_FEATURES = 0x2016, + LE_READ_REMOTE_FEATURES_PAGE_0 = 0x2016, LE_ENCRYPT = 0x2017, LE_RAND = 0x2018, LE_START_ENCRYPTION = 0x2019, @@ -293,7 +293,7 @@ enum OpCode : 16 { LE_RECEIVER_TEST_V2 = 0x2033, LE_TRANSMITTER_TEST_V2 = 0x2034, LE_SET_ADVERTISING_SET_RANDOM_ADDRESS = 0x2035, - LE_SET_EXTENDED_ADVERTISING_PARAMETERS = 0x2036, + LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1 = 0x2036, LE_SET_EXTENDED_ADVERTISING_DATA = 0x2037, LE_SET_EXTENDED_SCAN_RESPONSE_DATA = 0x2038, LE_SET_EXTENDED_ADVERTISING_ENABLE = 0x2039, @@ -301,12 +301,12 @@ enum OpCode : 16 { LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS = 0x203B, LE_REMOVE_ADVERTISING_SET = 0x203C, LE_CLEAR_ADVERTISING_SETS = 0x203D, - LE_SET_PERIODIC_ADVERTISING_PARAMETERS = 0x203E, + LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1 = 0x203E, LE_SET_PERIODIC_ADVERTISING_DATA = 0x203F, LE_SET_PERIODIC_ADVERTISING_ENABLE = 0x2040, LE_SET_EXTENDED_SCAN_PARAMETERS = 0x2041, LE_SET_EXTENDED_SCAN_ENABLE = 0x2042, - LE_EXTENDED_CREATE_CONNECTION = 0x2043, + LE_EXTENDED_CREATE_CONNECTION_V1 = 0x2043, LE_PERIODIC_ADVERTISING_CREATE_SYNC = 0x2044, LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL = 0x2045, LE_PERIODIC_ADVERTISING_TERMINATE_SYNC = 0x2046, @@ -355,7 +355,7 @@ enum OpCode : 16 { LE_ISO_RECEIVE_TEST = 0x2071, LE_ISO_READ_TEST_COUNTERS = 0x2072, LE_ISO_TEST_END = 0x2073, - LE_SET_HOST_FEATURE = 0x2074, + LE_SET_HOST_FEATURE_V1 = 0x2074, LE_READ_ISO_LINK_QUALITY = 0x2075, LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL = 0x2076, LE_READ_REMOTE_TRANSMIT_POWER_LEVEL = 0x2077, @@ -366,10 +366,41 @@ enum OpCode : 16 { LE_SET_DATA_RELATED_ADDRESS_CHANGES = 0x207C, LE_SET_DEFAULT_SUBRATE = 0x207D, LE_SUBRATE_REQUEST = 0x207E, + LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V2 = 0x207F, + LE_SET_DECISION_DATA = 0x2080, + LE_SET_DECISION_INSTRUCTIONS = 0x2081, + LE_SET_PERIODIC_ADVERTISING_SUBEVENT_DATA = 0x2082, + LE_SET_PERIODIC_ADVERTISING_RESPONSE_DATA = 0x2083, + LE_SET_PERIODIC_SYNC_SUBEVENT = 0x2084, + LE_EXTENDED_CREATE_CONNECTION_V2 = 0x2085, + LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V2 = 0x2086, + LE_READ_ALL_LOCAL_SUPPORTED_FEATURES = 0x2087, + LE_READ_ALL_REMOTE_FEATURES = 0x2088, + LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES = 0x2089, + LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES = 0x208A, + LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES = 0x208B, + LE_CS_SECURITY_ENABLE = 0x208C, + LE_CS_SET_DEFAULT_SETTINGS = 0x208D, + LE_CS_READ_REMOTE_FAE_TABLE = 0x208E, + LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE = 0x208F, + LE_CS_CREATE_CONFIG = 0x2090, + LE_CS_REMOVE_CONFIG = 0x0291, + LE_CS_SET_CHANNEL_CLASSIFICATION = 0x2092, + LE_CS_SET_PROCEDURE_PARAMETERS = 0x2093, + LE_CS_PROCEDURE_ENABLE = 0x2094, + LE_CS_TEST = 0x2095, + LE_CS_TEST_END = 0x2096, + LE_ADD_DEVICE_TO_MONITORED_ADVERTISERS_LIST = 0x2098, + LE_REMOVE_DEVICE_FROM_MONITORED_ADVERTISERS_LIST = 0x2099, + LE_CLEAR_MONITORED_ADVERTISERS_LIST = 0x209A, + LE_READ_MONITORED_ADVERTISERS_LIST_SIZE = 0x209B, + LE_ENABLE_MONITORING_ADVERTISERS = 0x209C, + LE_FRAME_SPACE_UPDATE = 0x209D, // VENDOR_SPECIFIC // MSFT_OPCODE_xxxx below is needed for the tests. MSFT_OPCODE_INTEL = 0xFC1E, + INTEL_DDC_CONFIG_WRITE = 0xFC8B, LE_GET_VENDOR_CAPABILITIES = 0xFD53, LE_BATCH_SCAN = 0xFD56, LE_APCF = 0xFD57, @@ -466,6 +497,8 @@ enum OpCodeIndex : 16 { READ_CURRENT_IAC_LAP = 113, WRITE_CURRENT_IAC_LAP = 114, SET_AFH_HOST_CHANNEL_CLASSIFICATION = 121, + LE_CS_READ_REMOTE_FAE_TABLE = 122, + LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE = 123, READ_INQUIRY_SCAN_TYPE = 124, WRITE_INQUIRY_SCAN_TYPE = 125, READ_INQUIRY_MODE = 126, @@ -487,10 +520,12 @@ enum OpCodeIndex : 16 { READ_CLOCK = 157, READ_LOOPBACK_MODE = 160, WRITE_LOOPBACK_MODE = 161, - ENABLE_DEVICE_UNDER_TEST_MODE = 162, + ENABLE_IMPLEMENTATION_UNDER_TEST_MODE = 162, SETUP_SYNCHRONOUS_CONNECTION = 163, ACCEPT_SYNCHRONOUS_CONNECTION = 164, REJECT_SYNCHRONOUS_CONNECTION = 165, + LE_CS_CREATE_CONFIG = 166, + LE_CS_REMOVE_CONFIG = 167, READ_EXTENDED_INQUIRY_RESPONSE = 170, WRITE_EXTENDED_INQUIRY_RESPONSE = 171, REFRESH_ENCRYPTION_KEY = 172, @@ -514,16 +549,23 @@ enum OpCodeIndex : 16 { SEND_KEYPRESS_NOTIFICATION = 202, IO_CAPABILITY_REQUEST_NEGATIVE_REPLY = 203, READ_ENCRYPTION_KEY_SIZE = 204, + LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES = 205, + LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES = 206, + LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES = 207, SET_EVENT_MASK_PAGE_2 = 222, READ_FLOW_CONTROL_MODE = 230, WRITE_FLOW_CONTROL_MODE = 231, READ_DATA_BLOCK_SIZE = 232, + LE_CS_TEST = 233, + LE_CS_TEST_END = 234, READ_ENHANCED_TRANSMIT_POWER_LEVEL = 240, + LE_CS_SECURITY_ENABLE = 241, READ_LE_HOST_SUPPORT = 245, WRITE_LE_HOST_SUPPORT = 246, + LE_CS_SET_DEFAULT_SETTINGS = 247, LE_SET_EVENT_MASK = 250, LE_READ_BUFFER_SIZE_V1 = 251, - LE_READ_LOCAL_SUPPORTED_FEATURES = 252, + LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0 = 252, LE_SET_RANDOM_ADDRESS = 254, LE_SET_ADVERTISING_PARAMETERS = 255, LE_READ_ADVERTISING_PHYSICAL_CHANNEL_TX_POWER = 256, @@ -541,7 +583,7 @@ enum OpCodeIndex : 16 { LE_CONNECTION_UPDATE = 272, LE_SET_HOST_CHANNEL_CLASSIFICATION = 273, LE_READ_CHANNEL_MAP = 274, - LE_READ_REMOTE_FEATURES = 275, + LE_READ_REMOTE_FEATURES_PAGE_0 = 275, LE_ENCRYPT = 276, LE_RAND = 277, LE_START_ENCRYPTION = 280, @@ -551,6 +593,10 @@ enum OpCodeIndex : 16 { LE_RECEIVER_TEST_V1 = 284, LE_TRANSMITTER_TEST_V1 = 285, LE_TEST_END = 286, + LE_ENABLE_MONITORING_ADVERTISERS = 287, + LE_CS_SET_CHANNEL_CLASSIFICATION = 290, + LE_CS_SET_PROCEDURE_PARAMETERS = 291, + LE_CS_PROCEDURE_ENABLE = 292, ENHANCED_SETUP_SYNCHRONOUS_CONNECTION = 293, ENHANCED_ACCEPT_SYNCHRONOUS_CONNECTION = 294, READ_LOCAL_SUPPORTED_CODECS_V1 = 295, @@ -606,7 +652,7 @@ enum OpCodeIndex : 16 { LE_RECEIVER_TEST_V2 = 357, LE_TRANSMITTER_TEST_V2 = 360, LE_SET_ADVERTISING_SET_RANDOM_ADDRESS = 361, - LE_SET_EXTENDED_ADVERTISING_PARAMETERS = 362, + LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1 = 362, LE_SET_EXTENDED_ADVERTISING_DATA = 363, LE_SET_EXTENDED_SCAN_RESPONSE_DATA = 364, LE_SET_EXTENDED_ADVERTISING_ENABLE = 365, @@ -614,12 +660,12 @@ enum OpCodeIndex : 16 { LE_READ_NUMBER_OF_SUPPORTED_ADVERTISING_SETS = 367, LE_REMOVE_ADVERTISING_SET = 370, LE_CLEAR_ADVERTISING_SETS = 371, - LE_SET_PERIODIC_ADVERTISING_PARAMETERS = 372, + LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1 = 372, LE_SET_PERIODIC_ADVERTISING_DATA = 373, LE_SET_PERIODIC_ADVERTISING_ENABLE = 374, LE_SET_EXTENDED_SCAN_PARAMETERS = 375, LE_SET_EXTENDED_SCAN_ENABLE = 376, - LE_EXTENDED_CREATE_CONNECTION = 377, + LE_EXTENDED_CREATE_CONNECTION_V1 = 377, LE_PERIODIC_ADVERTISING_CREATE_SYNC = 380, LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL = 381, LE_PERIODIC_ADVERTISING_TERMINATE_SYNC = 382, @@ -669,7 +715,7 @@ enum OpCodeIndex : 16 { LE_ISO_RECEIVE_TEST = 436, LE_ISO_READ_TEST_COUNTERS = 437, LE_ISO_TEST_END = 440, - LE_SET_HOST_FEATURE = 441, + LE_SET_HOST_FEATURE_V1 = 441, LE_READ_ISO_LINK_QUALITY = 442, LE_ENHANCED_READ_TRANSMIT_POWER_LEVEL = 443, LE_READ_REMOTE_TRANSMIT_POWER_LEVEL = 444, @@ -686,6 +732,22 @@ enum OpCodeIndex : 16 { SET_MIN_ENCRYPTION_KEY_SIZE = 457, LE_SET_DEFAULT_SUBRATE = 460, LE_SUBRATE_REQUEST = 461, + LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V2 = 462, + LE_SET_DECISION_DATA = 463, + LE_SET_DECISION_INSTRUCTIONS = 464, + LE_SET_PERIODIC_ADVERTISING_SUBEVENT_DATA = 465, + LE_SET_PERIODIC_ADVERTISING_RESPONSE_DATA = 466, + LE_SET_PERIODIC_SYNC_SUBEVENT = 467, + LE_EXTENDED_CREATE_CONNECTION_V2 = 470, + LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V2 = 471, + LE_READ_ALL_LOCAL_SUPPORTED_FEATURES = 472, + LE_READ_ALL_REMOTE_FEATURES = 473, + LE_SET_HOST_FEATURE_V2 = 474, + LE_ADD_DEVICE_TO_MONITORED_ADVERTISERS_LIST = 475, + LE_REMOVE_DEVICE_FROM_MONITORED_ADVERTISERS_LIST = 476, + LE_CLEAR_MONITORED_ADVERTISERS_LIST = 477, + LE_READ_MONITORED_ADVERTISERS_LIST_SIZE = 480, + LE_FRAME_SPACE_UPDATE = 481, } packet Command { @@ -749,46 +811,66 @@ enum EventCode : 8 { REMOTE_HOST_SUPPORTED_FEATURES_NOTIFICATION = 0x3D, LE_META_EVENT = 0x3e, NUMBER_OF_COMPLETED_DATA_BLOCKS = 0x48, + AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED = 0x57, + ENCRYPTION_CHANGE_V2 = 0x59, VENDOR_SPECIFIC = 0xFF, } // LE events enum SubeventCode : 8 { - CONNECTION_COMPLETE = 0x01, - ADVERTISING_REPORT = 0x02, - CONNECTION_UPDATE_COMPLETE = 0x03, - READ_REMOTE_FEATURES_COMPLETE = 0x04, - LONG_TERM_KEY_REQUEST = 0x05, - REMOTE_CONNECTION_PARAMETER_REQUEST = 0x06, - DATA_LENGTH_CHANGE = 0x07, - READ_LOCAL_P256_PUBLIC_KEY_COMPLETE = 0x08, - GENERATE_DHKEY_COMPLETE = 0x09, - ENHANCED_CONNECTION_COMPLETE = 0x0a, - DIRECTED_ADVERTISING_REPORT = 0x0b, - PHY_UPDATE_COMPLETE = 0x0c, - EXTENDED_ADVERTISING_REPORT = 0x0D, - PERIODIC_ADVERTISING_SYNC_ESTABLISHED = 0x0E, - PERIODIC_ADVERTISING_REPORT = 0x0F, - PERIODIC_ADVERTISING_SYNC_LOST = 0x10, - SCAN_TIMEOUT = 0x11, - ADVERTISING_SET_TERMINATED = 0x12, - SCAN_REQUEST_RECEIVED = 0x13, - CHANNEL_SELECTION_ALGORITHM = 0x14, - CONNECTIONLESS_IQ_REPORT = 0x15, - CONNECTION_IQ_REPORT = 0x16, - CTE_REQUEST_FAILED = 0x17, - PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED = 0x18, - CIS_ESTABLISHED = 0x19, - CIS_REQUEST = 0x1A, - CREATE_BIG_COMPLETE = 0x1B, - TERMINATE_BIG_COMPLETE = 0x1C, - BIG_SYNC_ESTABLISHED = 0x1D, - BIG_SYNC_LOST = 0x1E, - REQUEST_PEER_SCA_COMPLETE = 0x1F, - PATH_LOSS_THRESHOLD = 0x20, - TRANSMIT_POWER_REPORTING = 0x21, - BIG_INFO_ADVERTISING_REPORT = 0x22, + LE_CONNECTION_COMPLETE = 0x01, + LE_ADVERTISING_REPORT = 0x02, + LE_CONNECTION_UPDATE_COMPLETE = 0x03, + LE_READ_REMOTE_FEATURES_PAGE_0_COMPLETE = 0x04, + LE_LONG_TERM_KEY_REQUEST = 0x05, + LE_REMOTE_CONNECTION_PARAMETER_REQUEST = 0x06, + LE_DATA_LENGTH_CHANGE = 0x07, + LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE = 0x08, + LE_GENERATE_DHKEY_COMPLETE = 0x09, + LE_ENHANCED_CONNECTION_COMPLETE_V1 = 0x0a, + LE_DIRECTED_ADVERTISING_REPORT = 0x0b, + LE_PHY_UPDATE_COMPLETE = 0x0c, + LE_EXTENDED_ADVERTISING_REPORT = 0x0D, + LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_V1 = 0x0E, + LE_PERIODIC_ADVERTISING_REPORT_V1 = 0x0F, + LE_PERIODIC_ADVERTISING_SYNC_LOST = 0x10, + LE_SCAN_TIMEOUT = 0x11, + LE_ADVERTISING_SET_TERMINATED = 0x12, + LE_SCAN_REQUEST_RECEIVED = 0x13, + LE_CHANNEL_SELECTION_ALGORITHM = 0x14, + LE_CONNECTIONLESS_IQ_REPORT = 0x15, + LE_CONNECTION_IQ_REPORT = 0x16, + LE_CTE_REQUEST_FAILED = 0x17, + LE_PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED_V1 = 0x18, + LE_CIS_ESTABLISHED_V1 = 0x19, + LE_CIS_REQUEST = 0x1A, + LE_CREATE_BIG_COMPLETE = 0x1B, + LE_TERMINATE_BIG_COMPLETE = 0x1C, + LE_BIG_SYNC_ESTABLISHED = 0x1D, + LE_BIG_SYNC_LOST = 0x1E, + LE_REQUEST_PEER_SCA_COMPLETE = 0x1F, + LE_PATH_LOSS_THRESHOLD = 0x20, + LE_TRANSMIT_POWER_REPORTING = 0x21, + LE_BIG_INFO_ADVERTISING_REPORT = 0x22, LE_SUBRATE_CHANGE = 0x23, + LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_V2 = 0x24, + LE_PERIODIC_ADVERTISING_REPORT_V2 = 0x25, + LE_PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED_V2 = 0x26, + LE_PERIODIC_ADVERTISING_SUBEVENT_DATA_REQUEST = 0x27, + LE_PERIODIC_ADVERTISING_RESPONSE_REPORT = 0x28, + LE_ENHANCED_CONNECTION_COMPLETE_V2 = 0x29, + LE_CIS_ESTABLISHED_V2 = 0x2A, + LE_READ_ALL_REMOTE_FEATURES_COMPLETE = 0x2B, + LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES_COMPLETE = 0x2C, + LE_CS_READ_REMOTE_FAE_TABLE_COMPLETE = 0x2D, + LE_CS_SECURITY_ENABLE_COMPLETE = 0x2E, + LE_CS_CONFIG_COMPLETE = 0x2F, + LE_CS_PROCEDURE_ENABLE_COMPLETE = 0x30, + LE_CS_SUBEVENT_RESULT = 0x31, + LE_CS_SUBEVENT_RESULT_CONTINUE = 0x32, + LE_CS_TEST_END_COMPLETE = 0x33, + LE_MONITORED_ADVERTISERS_REPORT = 0x34, + LE_FRAME_SPACE_UPDATE_COMPLETE = 0x35, } // Vendor specific events @@ -806,6 +888,11 @@ packet Event { _payload_, } +packet LeMetaEvent : Event (event_code = LE_META_EVENT) { + subevent_code : SubeventCode, + _body_, +} + // Common definitions for commands and events enum FeatureFlag : 1 { @@ -2588,6 +2675,7 @@ enum HciVersion : 8 { V_5_2 = 0x0b, V_5_3 = 0x0c, V_5_4 = 0x0d, + V_6_0 = 0x0e, } enum LmpVersion : 8 { @@ -2605,6 +2693,7 @@ enum LmpVersion : 8 { V_5_2 = 0x0b, V_5_3 = 0x0c, V_5_4 = 0x0d, + V_6_0 = 0x0e, } struct LocalVersionInformation { @@ -3013,10 +3102,10 @@ packet WriteLoopbackModeComplete : CommandComplete (command_op_code = WRITE_LOOP status : ErrorCode, } -packet EnableDeviceUnderTestMode : Command (op_code = ENABLE_DEVICE_UNDER_TEST_MODE) { +packet EnableImplementationUnderTestMode : Command (op_code = ENABLE_IMPLEMENTATION_UNDER_TEST_MODE) { } -packet EnableDeviceUnderTestModeComplete : CommandComplete (command_op_code = ENABLE_DEVICE_UNDER_TEST_MODE) { +packet EnableImplementationUnderTestModeComplete : CommandComplete (command_op_code = ENABLE_IMPLEMENTATION_UNDER_TEST_MODE) { status : ErrorCode, } @@ -3069,66 +3158,86 @@ test LeReadBufferSizeV1Complete { "\x0e\x07\x01\x02\x20\x00\xfb\x00\x10", } +/// Core Specification Vol 6, Part B 4.6 § Feature support enum LLFeaturesBits : 64 { // Byte 0 - LE_ENCRYPTION = 0x0000000000000001, - CONNECTION_PARAMETERS_REQUEST_PROCEDURE = 0x0000000000000002, - EXTENDED_REJECT_INDICATION = 0x0000000000000004, - PERIPHERAL_INITIATED_FEATURES_EXCHANGE = 0x0000000000000008, - LE_PING = 0x0000000000000010, - LE_DATA_PACKET_LENGTH_EXTENSION = 0x0000000000000020, - LL_PRIVACY = 0x0000000000000040, - EXTENDED_SCANNER_FILTER_POLICIES = 0x0000000000000080, + LE_ENCRYPTION = 0x0000000000000001, + CONNECTION_PARAMETERS_REQUEST_PROCEDURE = 0x0000000000000002, + EXTENDED_REJECT_INDICATION = 0x0000000000000004, + PERIPHERAL_INITIATED_FEATURES_EXCHANGE = 0x0000000000000008, + LE_PING = 0x0000000000000010, + LE_DATA_PACKET_LENGTH_EXTENSION = 0x0000000000000020, + LL_PRIVACY = 0x0000000000000040, + EXTENDED_SCANNER_FILTER_POLICIES = 0x0000000000000080, // Byte 1 - LE_2M_PHY = 0x0000000000000100, - STABLE_MODULATION_INDEX_TRANSMITTER = 0x0000000000000200, - STABLE_MODULATION_INDEX_RECEIVER = 0x0000000000000400, - LE_CODED_PHY = 0x0000000000000800, - LE_EXTENDED_ADVERTISING = 0x0000000000001000, - LE_PERIODIC_ADVERTISING = 0x0000000000002000, - CHANNEL_SELECTION_ALGORITHM_2 = 0x0000000000004000, - LE_POWER_CLASS_1 = 0x0000000000008000, + LE_2M_PHY = 0x0000000000000100, + STABLE_MODULATION_INDEX_TRANSMITTER = 0x0000000000000200, + STABLE_MODULATION_INDEX_RECEIVER = 0x0000000000000400, + LE_CODED_PHY = 0x0000000000000800, + LE_EXTENDED_ADVERTISING = 0x0000000000001000, + LE_PERIODIC_ADVERTISING = 0x0000000000002000, + CHANNEL_SELECTION_ALGORITHM_2 = 0x0000000000004000, + LE_POWER_CLASS_1 = 0x0000000000008000, // Byte 2 - MINIMUM_NUMBER_OF_USED_CHANNELS_PROCEDURE = 0x0000000000010000, - CONNECTION_CTE_REQUEST = 0x0000000000020000, - CONNECTION_CTE_RESPONSE = 0x0000000000040000, - CONNECTIONLESS_CTE_TRANSMITTER = 0x0000000000080000, - CONNECTIONLESS_CTE_RECEIVER = 0x0000000000100000, - ANTENNA_SWITCHING_DURING_CTE_TRANSMISSION = 0x0000000000200000, - ANTENNA_SWITCHING_DURING_CTE_RECEPTION = 0x0000000000400000, - RECEIVING_CONSTANT_TONE_EXTENSIONS = 0x0000000000800000, + MINIMUM_NUMBER_OF_USED_CHANNELS_PROCEDURE = 0x0000000000010000, + CONNECTION_CTE_REQUEST = 0x0000000000020000, + CONNECTION_CTE_RESPONSE = 0x0000000000040000, + CONNECTIONLESS_CTE_TRANSMITTER = 0x0000000000080000, + CONNECTIONLESS_CTE_RECEIVER = 0x0000000000100000, + ANTENNA_SWITCHING_DURING_CTE_TRANSMISSION = 0x0000000000200000, + ANTENNA_SWITCHING_DURING_CTE_RECEPTION = 0x0000000000400000, + RECEIVING_CONSTANT_TONE_EXTENSIONS = 0x0000000000800000, // Byte 3 - PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER = 0x0000000001000000, - PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT = 0x0000000002000000, - SLEEP_CLOCK_ACCURACY_UPDATES = 0x0000000004000000, - REMOTE_PUBLIC_KEY_VALIDATION = 0x0000000008000000, - CONNECTED_ISOCHRONOUS_STREAM_CENTRAL = 0x0000000010000000, - CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL = 0x0000000020000000, - ISOCHRONOUS_BROADCASTER = 0x0000000040000000, - SYNCHRONIZED_RECEIVER = 0x0000000080000000, + PERIODIC_ADVERTISING_SYNC_TRANSFER_SENDER = 0x0000000001000000, + PERIODIC_ADVERTISING_SYNC_TRANSFER_RECIPIENT = 0x0000000002000000, + SLEEP_CLOCK_ACCURACY_UPDATES = 0x0000000004000000, + REMOTE_PUBLIC_KEY_VALIDATION = 0x0000000008000000, + CONNECTED_ISOCHRONOUS_STREAM_CENTRAL = 0x0000000010000000, + CONNECTED_ISOCHRONOUS_STREAM_PERIPHERAL = 0x0000000020000000, + ISOCHRONOUS_BROADCASTER = 0x0000000040000000, + SYNCHRONIZED_RECEIVER = 0x0000000080000000, // Byte 4 - CONNECTED_ISOCHRONOUS_STREAM_HOST_SUPPORT = 0x0000000100000000, - LE_POWER_CONTROL_REQUEST = 0x0000000200000000, - LE_POWER_CONTROL_REQUEST_BIS = 0x0000000400000000, - LE_PATH_LOSS_MONITORING = 0x0000000800000000, - PERIODIC_ADVERTISING_ADI_SUPPORT = 0x0000001000000000, - CONNECTION_SUBRATING = 0x0000002000000000, - CONNECTION_SUBRATING_HOST_SUPPORT = 0x0000004000000000, - CHANNEL_CLASSIFICATION = 0x0000008000000000, + CONNECTED_ISOCHRONOUS_STREAM_HOST_SUPPORT = 0x0000000100000000, + LE_POWER_CONTROL_REQUEST = 0x0000000200000000, + LE_POWER_CONTROL_REQUEST_BIS = 0x0000000400000000, + LE_PATH_LOSS_MONITORING = 0x0000000800000000, + PERIODIC_ADVERTISING_ADI_SUPPORT = 0x0000001000000000, + CONNECTION_SUBRATING = 0x0000002000000000, + CONNECTION_SUBRATING_HOST_SUPPORT = 0x0000004000000000, + CHANNEL_CLASSIFICATION = 0x0000008000000000, + + // Byte 5 + ADVERTISING_CODING_SELECTION = 0x0000010000000000, + ADVERTISING_CODING_SELECTION_HOST_SUPPORT = 0x0000020000000000, + DECISION_BASED_ADVERTISING_FILTERING = 0x0000040000000000, + PERIODIC_ADVERTISING_WITH_RESPONSES_ADVERTISER = 0x0000080000000000, + PERIODIC_ADVERTISING_WITH_RESPONSES_SCANNER = 0x0000100000000000, + UNSEGMENTED_FRAMED_MODE = 0x0000200000000000, + CHANNEL_SOUNDING = 0x0000400000000000, + CHANNEL_SOUNDING_HOST_SUPPORT = 0x0000800000000000, } -packet LeReadLocalSupportedFeatures : Command (op_code = LE_READ_LOCAL_SUPPORTED_FEATURES) { +packet LeReadLocalSupportedFeaturesPage0 : Command (op_code = LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0) { } -packet LeReadLocalSupportedFeaturesComplete : CommandComplete (command_op_code = LE_READ_LOCAL_SUPPORTED_FEATURES) { +packet LeReadLocalSupportedFeaturesPage0Complete : CommandComplete (command_op_code = LE_READ_LOCAL_SUPPORTED_FEATURES_PAGE_0) { status : ErrorCode, le_features : 64, } +packet LeReadAllLocalSupportedFeatures : Command (op_code = LE_READ_ALL_LOCAL_SUPPORTED_FEATURES) { +} + +packet LeReadAllLocalSupportedFeaturesComplete : CommandComplete (command_op_code = LE_READ_ALL_LOCAL_SUPPORTED_FEATURES) { + status : ErrorCode, + max_page : 8, + le_features : 8[248], +} + packet LeSetRandomAddress : Command (op_code = LE_SET_RANDOM_ADDRESS) { random_address : Address, } @@ -3266,7 +3375,9 @@ packet LeSetScanEnableComplete : CommandComplete (command_op_code = LE_SET_SCAN_ enum InitiatorFilterPolicy : 8 { USE_PEER_ADDRESS = 0x00, - USE_FILTER_ACCEPT_LIST = 0x01, + USE_FILTER_ACCEPT_LIST_WITH_PEER_ADDRESS = 0x01, + USE_DECISION_PDUS = 0x02, + USE_FILTER_ACCEPT_LIST_WITH_DECISION_PDUS = 0x03, } packet LeCreateConnection : Command (op_code = LE_CREATE_CONNECTION) { @@ -3373,12 +3484,37 @@ packet LeReadChannelMapComplete : CommandComplete (command_op_code = LE_READ_CHA channel_map : 8[5], } -packet LeReadRemoteFeatures : Command (op_code = LE_READ_REMOTE_FEATURES) { +packet LeReadRemoteFeaturesPage0 : Command (op_code = LE_READ_REMOTE_FEATURES_PAGE_0) { + connection_handle : 12, + _reserved_ : 4, +} + +packet LeReadRemoteFeaturesPage0Status : CommandStatus (command_op_code = LE_READ_REMOTE_FEATURES_PAGE_0) { +} + +packet LeReadRemoteFeaturesPage0Complete : LeMetaEvent (subevent_code = LE_READ_REMOTE_FEATURES_PAGE_0_COMPLETE) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + le_features : 64, +} + +packet LeReadAllRemoteFeatures : Command (op_code = LE_READ_ALL_REMOTE_FEATURES) { connection_handle : 12, _reserved_ : 4, + pages_requested : 8, } -packet LeReadRemoteFeaturesStatus : CommandStatus (command_op_code = LE_READ_REMOTE_FEATURES) { +packet LeReadAllRemoteFeaturesStatus : CommandStatus (command_op_code = LE_READ_ALL_REMOTE_FEATURES) { +} + +packet LeReadAllRemoteFeaturesComplete : LeMetaEvent (subevent_code = LE_READ_ALL_REMOTE_FEATURES_COMPLETE) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + max_remote_page : 8, + max_valid_page : 8, + le_features : 8[248], } packet LeEncrypt : Command (op_code = LE_ENCRYPT) { @@ -3535,17 +3671,17 @@ packet LeWriteSuggestedDefaultDataLengthComplete : CommandComplete (command_op_c status : ErrorCode, } -packet LeReadLocalP256PublicKeyCommand : Command (op_code = LE_READ_LOCAL_P_256_PUBLIC_KEY) { +packet LeReadLocalP256PublicKey : Command (op_code = LE_READ_LOCAL_P_256_PUBLIC_KEY) { } -packet LeReadLocalP256PublicKeyCommandStatus : CommandStatus (command_op_code = LE_READ_LOCAL_P_256_PUBLIC_KEY) { +packet LeReadLocalP256PublicKeyStatus : CommandStatus (command_op_code = LE_READ_LOCAL_P_256_PUBLIC_KEY) { } -packet LeGenerateDhkeyV1Command : Command (op_code = LE_GENERATE_DHKEY_V1) { +packet LeGenerateDhkeyV1 : Command (op_code = LE_GENERATE_DHKEY_V1) { remote_p_256_public_key : 8[64], } -packet LeGenerateDhkeyV1CommandStatus : CommandStatus (command_op_code = LE_GENERATE_DHKEY_V1) { +packet LeGenerateDhkeyV1Status : CommandStatus (command_op_code = LE_GENERATE_DHKEY_V1) { } packet LeAddDeviceToResolvingList : Command (op_code = LE_ADD_DEVICE_TO_RESOLVING_LIST) { @@ -3741,6 +3877,20 @@ enum LegacyAdvertisingEventProperties : 4 { ADV_NONCONN_IND = 0, } +struct AdvertisingEventProperties { + connectable : 1, + scannable : 1, + directed : 1, + high_duty_cycle : 1, + legacy : 1, + anonymous : 1, + include_tx_power : 1, + decision : 1, + include_adva : 1, + include_adi : 1, + _reserved_ : 6, +} + enum PrimaryPhyType : 8 { LE_1M = 0x01, LE_CODED = 0x03, @@ -3753,11 +3903,17 @@ enum SecondaryPhyType : 8 { LE_CODED = 0x03, } -packet LeSetExtendedAdvertisingParametersLegacy : Command (op_code = LE_SET_EXTENDED_ADVERTISING_PARAMETERS) { +enum AdvertisingPhyOptions : 8 { + NO_PREFERENCE = 0x00, + S2_CODING_PREFERRED = 0x01, + S8_CODING_PREFERRED = 0x02, + S2_CODING_REQUIRED = 0x03, + S8_CODING_REQUIRED = 0x04, +} + +packet LeSetExtendedAdvertisingParametersV1 : Command (op_code = LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1) { advertising_handle : 8, - legacy_advertising_event_properties : LegacyAdvertisingEventProperties, - _fixed_ = 0x1 : 1, // legacy bit set - _reserved_ : 11, // advertising_event_properties reserved bits + advertising_event_properties : AdvertisingEventProperties, primary_advertising_interval_min : 24, // 0x20 - 0xFFFFFF N * 0.625 ms primary_advertising_interval_max : 24, // 0x20 - 0xFFFFFF N * 0.625 ms primary_advertising_channel_map : 3, // bit 0 - Channel 37, bit 1 - 38, bit 2 - 39 @@ -3768,30 +3924,24 @@ packet LeSetExtendedAdvertisingParametersLegacy : Command (op_code = LE_SET_EXTE advertising_filter_policy : AdvertisingFilterPolicy, _reserved_ : 6, advertising_tx_power : 8, // -127 to +20, 0x7F - no preference - _fixed_ = 0x1 : 8, // PrimaryPhyType LE_1M - _reserved_ : 8, // secondary_advertising_max_skip - _fixed_ = 0x1 : 8, // secondary_advertising_phy LE_1M + primary_advertising_phy : PrimaryPhyType, + secondary_advertising_max_skip : 8, // 1 to 255, 0x00 - AUX_ADV_IND sent before next advertising event + secondary_advertising_phy : SecondaryPhyType, advertising_sid : 8, // SID subfield from the ADI field of the PDU scan_request_notification_enable : Enable, } -test LeSetExtendedAdvertisingParametersLegacy { - "\x36\x20\x19\x00\x13\x00\x90\x01\x00\xc2\x01\x00\x07\x01\x00\x00\x00\x00\x00\x00\x00\x00\xf9\x01\x00\x01\x01\x00", - "\x36\x20\x19\x01\x13\x00\x90\x01\x00\xc2\x01\x00\x07\x01\x00\x00\x00\x00\x00\x00\x00\x00\xf9\x01\x00\x01\x01\x00", +packet LeSetExtendedAdvertisingParametersV1Complete : CommandComplete (command_op_code = LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V1) { + status : ErrorCode, + selected_tx_power : 8, // -127 to +20 } -struct AdvertisingEventProperties { - connectable : 1, - scannable : 1, - directed : 1, - high_duty_cycle : 1, - legacy : 1, - anonymous : 1, - tx_power : 1, - _reserved_ : 9, +test LeSetExtendedAdvertisingParametersV1 { + "\x36\x20\x19\x00\x13\x00\x90\x01\x00\xc2\x01\x00\x07\x01\x00\x00\x00\x00\x00\x00\x00\x00\xf9\x01\x00\x01\x01\x00", + "\x36\x20\x19\x01\x13\x00\x90\x01\x00\xc2\x01\x00\x07\x01\x00\x00\x00\x00\x00\x00\x00\x00\xf9\x01\x00\x01\x01\x00", } -packet LeSetExtendedAdvertisingParameters : Command (op_code = LE_SET_EXTENDED_ADVERTISING_PARAMETERS) { +packet LeSetExtendedAdvertisingParametersV2 : Command (op_code = LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V2) { advertising_handle : 8, advertising_event_properties : AdvertisingEventProperties, primary_advertising_interval_min : 24, // 0x20 - 0xFFFFFF N * 0.625 ms @@ -3809,9 +3959,11 @@ packet LeSetExtendedAdvertisingParameters : Command (op_code = LE_SET_EXTENDED_A secondary_advertising_phy : SecondaryPhyType, advertising_sid : 8, // SID subfield from the ADI field of the PDU scan_request_notification_enable : Enable, + primary_advertising_phy_options : AdvertisingPhyOptions, + secondary_advertising_phy_options : AdvertisingPhyOptions, } -packet LeSetExtendedAdvertisingParametersComplete : CommandComplete (command_op_code = LE_SET_EXTENDED_ADVERTISING_PARAMETERS) { +packet LeSetExtendedAdvertisingParametersV2Complete : CommandComplete (command_op_code = LE_SET_EXTENDED_ADVERTISING_PARAMETERS_V2) { status : ErrorCode, selected_tx_power : 8, // -127 to +20 } @@ -3949,7 +4101,7 @@ packet LeClearAdvertisingSetsComplete : CommandComplete (command_op_code = LE_CL status : ErrorCode, } -packet LeSetPeriodicAdvertisingParameters : Command (op_code = LE_SET_PERIODIC_ADVERTISING_PARAMETERS) { +packet LeSetPeriodicAdvertisingParametersV1 : Command (op_code = LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1) { advertising_handle : 8, periodic_advertising_interval_min : 16, // 0x006 to 0xFFFF (7.5 ms to 82s) periodic_advertising_interval_max : 16, // 0x006 to 0xFFFF (7.5 ms to 82s) @@ -3958,7 +4110,26 @@ packet LeSetPeriodicAdvertisingParameters : Command (op_code = LE_SET_PERIODIC_A _reserved_ : 9, } -packet LeSetPeriodicAdvertisingParametersComplete : CommandComplete (command_op_code = LE_SET_PERIODIC_ADVERTISING_PARAMETERS) { +packet LeSetPeriodicAdvertisingParametersV1Complete : CommandComplete (command_op_code = LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V1) { + status : ErrorCode, +} + +packet LeSetPeriodicAdvertisingParametersV2 : Command (op_code = LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V2) { + advertising_handle : 8, + periodic_advertising_interval_min : 16, // 0x006 to 0xFFFF (7.5 ms to 82s) + periodic_advertising_interval_max : 16, // 0x006 to 0xFFFF (7.5 ms to 82s) + _reserved_ : 6, + include_tx_power : 1, + _reserved_ : 9, + num_subevents : 8, // 0x00 disabled, 0x01 to 0x80 + subevent_interval : 8, // 0x06 to 0xFF × 1.25 ms + response_slot_delay : 8, // 0x01 to 0xFE × 1.25 ms + response_slot_spacing : 8, // 0x02 to 0xFF × 1.25 ms + num_response_slots : 8, +} + +packet LeSetPeriodicAdvertisingParametersV2Complete : CommandComplete (command_op_code = LE_SET_PERIODIC_ADVERTISING_PARAMETERS_V2) { + advertising_handle : 8, status : ErrorCode, } @@ -4048,7 +4219,7 @@ struct InitiatingPhyParameters { max_ce_length : 16, // 0.625ms } -packet LeExtendedCreateConnection : Command (op_code = LE_EXTENDED_CREATE_CONNECTION) { +packet LeExtendedCreateConnectionV1 : Command (op_code = LE_EXTENDED_CREATE_CONNECTION_V1) { initiator_filter_policy : InitiatorFilterPolicy, own_address_type : OwnAddressType, peer_address_type : PeerAddressType, @@ -4061,7 +4232,21 @@ test LeExtendedCreateConnection { "\x43\x20\x2a\x01\x01\x00\x00\x00\x00\x00\x00\x00\x03\x00\x08\x30\x00\x18\x00\x28\x00\x00\x00\xf4\x01\x00\x00\x00\x00\x00\x08\x30\x00\x18\x00\x28\x00\x00\x00\xf4\x01\x00\x00\x00\x00", } -packet LeExtendedCreateConnectionStatus : CommandStatus (command_op_code = LE_EXTENDED_CREATE_CONNECTION) { +packet LeExtendedCreateConnectionV1Status : CommandStatus (command_op_code = LE_EXTENDED_CREATE_CONNECTION_V1) { +} + +packet LeExtendedCreateConnectionV2 : Command (op_code = LE_EXTENDED_CREATE_CONNECTION_V2) { + advertising_handle : 8, + subevent : 8, + initiator_filter_policy : InitiatorFilterPolicy, + own_address_type : OwnAddressType, + peer_address_type : PeerAddressType, + peer_address : Address, + initiating_phys : 8, + initiating_phy_parameters : InitiatingPhyParameters[], +} + +packet LeExtendedCreateConnectionV2Status : CommandStatus (command_op_code = LE_EXTENDED_CREATE_CONNECTION_V2) { } enum PeriodicSyncCteType : 8 { @@ -4544,12 +4729,12 @@ enum LeHostFeatureBits : 8 { CONNECTION_SUBRATING_HOST_SUPPORT = 38, } -packet LeSetHostFeature : Command (op_code = LE_SET_HOST_FEATURE) { +packet LeSetHostFeatureV1 : Command (op_code = LE_SET_HOST_FEATURE_V1) { bit_number : LeHostFeatureBits, bit_value: Enable, } -packet LeSetHostFeatureComplete : CommandComplete (command_op_code = LE_SET_HOST_FEATURE) { +packet LeSetHostFeatureV1Complete : CommandComplete (command_op_code = LE_SET_HOST_FEATURE_V1) { status : ErrorCode, } @@ -4687,6 +4872,501 @@ packet LeSubrateRequest : Command (op_code = LE_SUBRATE_REQUEST) { packet LeSubrateRequestStatus : CommandStatus (command_op_code = LE_SUBRATE_REQUEST) { } +packet LeCsReadLocalSupportedCapabilities : Command (op_code = LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES) { +} + +struct CsRolesSupported { + initiator : 1, + reflector : 1, + _reserved_ : 6, +} + +struct CsModesSupported { + mode_3 : 1, + _reserved_ : 7, +} + +struct CsRttCapability { + rtt_aa_only_n : 1, + rtt_sounding_n : 1, + rtt_random_payload_n : 1, + _reserved_ : 5, +} + +struct CsNadmSoundingCapability { + normalized_attack_detector_metric : 1, + _reserved_ : 15, +} + +struct CsNadmRandomCapability { + normalized_attack_detector_metric : 1, + _reserved_ : 15, +} + +struct CsSyncPhysSupported { + le_2m_phy : 1, + le_2m_2bt_phy : 1, + _reserved_ : 6, +} + +struct CsSubfeaturesSupported { + companion_signal : 1, + frequency_actuation_error : 1, + channel_selection_algorithm : 1, + phase_based_ranging : 1, + _reserved_ : 12, +} + +struct CsTIp1TimesSupported { + support_10_microsecond : 1, + support_20_microsecond : 1, + support_30_microsecond : 1, + support_40_microsecond : 1, + support_50_microsecond : 1, + support_60_microsecond : 1, + support_80_microsecond : 1, + _reserved_ : 9, +} + +struct CsTIp2TimesSupported { + support_10_microsecond : 1, + support_20_microsecond : 1, + support_30_microsecond : 1, + support_40_microsecond : 1, + support_50_microsecond : 1, + support_60_microsecond : 1, + support_80_microsecond : 1, + _reserved_ : 9, +} + +struct CsTFcsTimesSupported { + support_15_microsecond : 1, + support_20_microsecond : 1, + support_30_microsecond : 1, + support_40_microsecond : 1, + support_50_microsecond : 1, + support_60_microsecond : 1, + support_80_microsecond : 1, + support_100_microsecond : 1, + support_120_microsecond : 1, + _reserved_ : 7, +} + +struct CsTPmTimesSupported { + support_10_microsecond : 1, + support_20_microsecond : 1, + _reserved_ : 14, +} + +struct CsTxSnrCapability { + support_18db : 1, + support_21db : 1, + support_24db : 1, + support_27db : 1, + support_30db : 1, + _reserved_ : 3, +} + +packet LeCsReadLocalSupportedCapabilitiesComplete : CommandComplete (command_op_code = LE_CS_READ_LOCAL_SUPPORTED_CAPABILITIES) { + status : ErrorCode, + num_config_supported : 8, + max_consecutive_procedures_supported : 16, + num_antennas_supported : 8, + max_antenna_paths_supported : 8, + roles_supported : CsRolesSupported, + modes_supported : CsModesSupported, + rtt_capability : CsRttCapability, + rtt_aa_only_n : 8, + rtt_sounding_n : 8, + rtt_random_payload_n : 8, + nadm_sounding_capability : CsNadmSoundingCapability, + nadm_random_capability : CsNadmRandomCapability, + cs_sync_phys_supported : CsSyncPhysSupported, + subfeatures_supported : CsSubfeaturesSupported, + t_ip1_times_supported : CsTIp1TimesSupported, + t_ip2_times_supported : CsTIp2TimesSupported, + t_fcs_times_supported : CsTFcsTimesSupported, + t_pm_times_supported : CsTPmTimesSupported, + t_sw_time_supported : 8, + tx_snr_capability : CsTxSnrCapability, +} + +packet LeCsReadRemoteSupportedCapabilities : Command (op_code = LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES) { + connection_handle: 12, + _reserved_ : 4, +} + +packet LeCsReadRemoteSupportedCapabilitiesStatus : CommandStatus (command_op_code = LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES) { +} + +packet LeCsReadRemoteSupportedCapabilitiesComplete : LeMetaEvent (subevent_code = LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES_COMPLETE) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + num_config_supported : 8, + max_consecutive_procedures_supported : 16, + num_antennas_supported : 8, + max_antenna_paths_supported : 8, + roles_supported : CsRolesSupported, + modes_supported : CsModesSupported, + rtt_capability : CsRttCapability, + rtt_aa_only_n : 8, + rtt_sounding_n : 8, + rtt_random_payload_n : 8, + nadm_sounding_capability : CsNadmSoundingCapability, + nadm_random_capability : CsNadmRandomCapability, + cs_sync_phys_supported : CsSyncPhysSupported, + subfeatures_supported : CsSubfeaturesSupported, + t_ip1_times_supported : CsTIp1TimesSupported, + t_ip2_times_supported : CsTIp2TimesSupported, + t_fcs_times_supported : CsTFcsTimesSupported, + t_pm_times_supported : CsTPmTimesSupported, + t_sw_time_supported : 8, + tx_snr_capability : CsTxSnrCapability, +} + +packet LeCsWriteCachedRemoteSupportedCapabilities : Command (op_code = LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES) { + connection_handle: 12, + _reserved_ : 4, + num_config_supported : 8, + max_consecutive_procedures_supported : 16, + num_antennas_supported : 8, + max_antenna_paths_supported : 8, + roles_supported : CsRolesSupported, + modes_supported : CsModesSupported, + rtt_capability : CsRttCapability, + rtt_aa_only_n : 8, + rtt_sounding_n : 8, + rtt_random_payload_n : 8, + nadm_sounding_capability : CsNadmSoundingCapability, + nadm_random_capability : CsNadmRandomCapability, + cs_sync_phys_supported : CsSyncPhysSupported, + subfeatures_supported : CsSubfeaturesSupported, + t_ip1_times_supported : CsTIp1TimesSupported, + t_ip2_times_supported : CsTIp2TimesSupported, + t_fcs_times_supported : CsTFcsTimesSupported, + t_pm_times_supported : CsTPmTimesSupported, + t_sw_time_supported : 8, + tx_snr_capability : CsTxSnrCapability, +} + +packet LeCsWriteCachedRemoteSupportedCapabilitiesComplete : CommandComplete (command_op_code = LE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPABILITIES) { + status : ErrorCode, + connection_handle: 12, + _reserved_ : 4, +} + +packet LeCsSecurityEnable : Command (op_code = LE_CS_SECURITY_ENABLE) { + connection_handle: 12, + _reserved_ : 4, +} + +packet LeCsSecurityEnableStatus : CommandStatus (command_op_code = LE_CS_SECURITY_ENABLE) { +} + +packet LeCsSecurityEnableComplete : LeMetaEvent (subevent_code = LE_CS_SECURITY_ENABLE_COMPLETE) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, +} + +struct CsRoleEnable { + initiator : 1, + reflector : 1, + _reserved_ : 6, +} + +enum CsSyncAntennaSelection : 8 { + ANTENNA_1 = 0x01, + ANTENNA_2 = 0x02, + ANTENNA_3 = 0x03, + ANTENNA_4 = 0x04, + ANTENNAS_IN_ORDER = 0xFE, + NO_RECOMMENDATION = 0xFF, +} + +packet LeCsSetDefaultSettings : Command (op_code = LE_CS_SET_DEFAULT_SETTINGS) { + connection_handle: 12, + _reserved_ : 4, + role_enable : CsRoleEnable, + cs_sync_antenna_selection : CsSyncAntennaSelection, + max_tx_power : 8, +} + +packet LeCsSetDefaultSettingsComplete : CommandComplete (command_op_code = LE_CS_SET_DEFAULT_SETTINGS) { + status : ErrorCode, + connection_handle: 12, + _reserved_ : 4, +} + +packet LeCsReadRemoteFaeTable : Command (op_code = LE_CS_READ_REMOTE_FAE_TABLE) { + connection_handle: 12, + _reserved_ : 4, +} + +packet LeCsReadRemoteFaeTableStatus : CommandStatus (command_op_code = LE_CS_READ_REMOTE_FAE_TABLE) { +} + +packet LeCsReadRemoteFaeTableComplete : LeMetaEvent (subevent_code = LE_CS_READ_REMOTE_FAE_TABLE_COMPLETE) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + remote_fae_table : 8[72], +} + +packet LeCsWriteCachedRemoteFaeTable : Command (op_code = LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE) { + connection_handle: 12, + _reserved_ : 4, + remote_fae_table : 8[72], +} + +packet LeCsWriteCachedRemoteFaeTableComplete : CommandComplete (command_op_code = LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE) { + status : ErrorCode, + connection_handle: 12, + _reserved_ : 4, +} + +enum CsCreateContext: 8 { + LOCAL_CONTROLLER_ONLY = 0x00, + BOTH_LOCAL_AND_REMOTE_CONTROLLER = 0x01, +} + +enum CsMainModeType: 8 { + MODE_1 = 0x01, + MODE_2 = 0x02, + MODE_3 = 0x03, +} + +enum CsSubModeType: 8 { + MODE_1 = 0x01, + MODE_2 = 0x02, + MODE_3 = 0x03, + UNUSED = 0xff, +} + +enum CsRole : 8 { + INITIATOR = 0x00, + REFLECTOR = 0x01, +} + +enum CsRttType : 8 { + RTT_AA_ONLY = 0x00, + RTT_WITH_32_BIT_SOUNDING_SEQUENCE = 0x01, + RTT_WITH_96_BIT_SOUNDING_SEQUENCE = 0x02, + RTT_WITH_32_BIT_RANDOM_SEQUENCE = 0x03, + RTT_WITH_64_BIT_RANDOM_SEQUENCE = 0x04, + RTT_WITH_96_BIT_RANDOM_SEQUENCE = 0x05, + RTT_WITH_128_BIT_RANDOM_SEQUENCE = 0x06, +} + +enum CsSyncPhy : 8 { + LE_1M_PHY = 0x01, + LE_2M_PHY = 0x02, + LE_2M_2BT_PHY = 0x03, +} + +enum CsChannelSelectionType : 8 { + TYPE_3B = 0x00, + TYPE_3C = 0x01, +} + +enum CsCh3cShape : 8 { + HAT_SHAPE = 0x00, + X_SHAPE = 0x01, +} + +enum CsAction : 8 { + CONFIG_REMOVED = 0x00, + CONFIG_CREATED = 0x01, +} + +packet LeCsConfigComplete : LeMetaEvent (subevent_code = LE_CS_CONFIG_COMPLETE) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + config_id : 8, + action : CsAction, + main_mode_type : CsMainModeType, + sub_mode_type : CsSubModeType, + min_main_mode_steps : 8, + max_main_mode_steps : 8, + main_mode_repetition : 8, + mode_0_steps : 8, + role : CsRole, + rtt_type : CsRttType, + cs_sync_phy : CsSyncPhy, + channel_map : 8[10], + channel_map_repetition : 8, + channel_selection_type : CsChannelSelectionType, + ch3c_shape : CsCh3cShape, + ch3c_jump : 8, + _reserved_ : 8, + t_ip1_time : 8, + t_ip2_time : 8, + t_fcs_time : 8, + t_pm_time : 8, +} + +packet LeCsCreateConfig : Command (op_code = LE_CS_CREATE_CONFIG) { + connection_handle: 12, + _reserved_ : 4, + config_id : 8, + create_context : CsCreateContext, + main_mode_type : CsMainModeType, + sub_mode_type : CsSubModeType, + min_main_mode_steps : 8, + max_main_mode_steps : 8, + main_mode_repetition : 8, + mode_0_steps : 8, + role : CsRole, + rtt_type : CsRttType, + cs_sync_phy : CsSyncPhy, + channel_map : 8[10], + channel_map_repetition : 8, + channel_selection_type : CsChannelSelectionType, + ch3c_shape : CsCh3cShape, + ch3c_jump : 8, + _reserved_ : 8, +} + +packet LeCsCreateConfigStatus : CommandStatus (command_op_code = LE_CS_CREATE_CONFIG) { +} + + +packet LeCsRemoveConfig : Command (op_code = LE_CS_REMOVE_CONFIG) { + connection_handle: 12, + _reserved_ : 4, + config_id : 8, +} + +packet LeCsRemoveConfigStatus : CommandStatus (command_op_code = LE_CS_REMOVE_CONFIG) { +} + +packet LeCsSetChannelClassification : Command (op_code = LE_CS_SET_CHANNEL_CLASSIFICATION) { + channel_classification : 8[10], +} + +packet LeCsSetChannelClassificationComplete : CommandComplete (command_op_code = LE_CS_SET_CHANNEL_CLASSIFICATION) { +} + +enum CsPhy : 8 { + LE_1M_PHY = 0x01, + LE_2M_PHY = 0x02, + LE_CODED_PHY_S2 = 0x03, + LE_CODED_PHY_S8 = 0x04, +} + +struct CsPreferredPeerAntenna { + use_first_ordered_antenna_element : 1, + use_second_ordered_antenna_element : 1, + use_third_ordered_antenna_element : 1, + use_fourth_ordered_antenna_element : 1, + _reserved_ : 4, +} + +enum CsSnrControl : 8 { + ADJUST_18_DB = 0x00, + ADJUST_21_DB = 0x01, + ADJUST_24_DB = 0x02, + ADJUST_27_DB = 0x03, + ADJUST_30_DB = 0x04, + NOT_APPLIED = 0xFF, +} + +packet LeCsSetProcedureParameters : Command (op_code = LE_CS_SET_PROCEDURE_PARAMETERS) { + connection_handle: 12, + _reserved_ : 4, + config_id : 8, + max_procedure_len : 16, + min_procedure_interval : 16, + max_procedure_interval : 16, + max_procedure_count : 16, + min_subevent_len : 24, + max_subevent_len : 24, + tone_antenna_config_selection : 8, + phy : CsPhy, + tx_power_delta : 8, + preferred_peer_antenna : CsPreferredPeerAntenna, + snr_control_initiator: CsSnrControl, + snr_control_reflector: CsSnrControl, +} + +packet LeCsSetProcedureParametersComplete : CommandComplete (command_op_code = LE_CS_SET_PROCEDURE_PARAMETERS) { + status : ErrorCode, + connection_handle: 12, + _reserved_ : 4, +} + +packet LeCsProcedureEnable : Command (op_code = LE_CS_PROCEDURE_ENABLE) { + connection_handle: 12, + _reserved_ : 4, + config_id : 8, + procedure_enable : Enable, +} + +packet LeCsProcedureEnableStatus : CommandStatus (command_op_code = LE_CS_PROCEDURE_ENABLE) { +} + +packet LeCsProcedureEnableComplete : LeMetaEvent (subevent_code = LE_CS_PROCEDURE_ENABLE_COMPLETE) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + config_id : 8, + state : Enable, + tone_antenna_config_selection : 8, + selected_tx_power : 8, + subevent_len : 24, + subevents_per_event : 8, + subevent_interval : 16, + event_interval : 16, + procedure_interval : 16, + procedure_count : 16, + max_procedure_len : 16, +} + +packet LeCsTest : Command (op_code = LE_CS_TEST) { + main_mode_type : CsMainModeType, + sub_mode_type : CsSubModeType, + main_mode_repetition : 8, + mode_0_steps : 8, + role : CsRole, + rtt_type : CsRttType, + cs_sync_phy : CsSyncPhy, + cs_sync_antenna_selection : 8, + subevent_len : 24, + subevent_interval : 16, + max_num_subevents : 8, + transmit_power_level : 8, + t_ip1_time : 8, + t_ip2_time : 8, + t_fcs_time : 8, + t_pm_time : 8, + t_sw_time : 8, + tone_antenna_config_selection : 8, + _reserved_ : 8, + snr_control_initiator: CsSnrControl, + snr_control_reflector: CsSnrControl, + drbg_nonce : 16, + channel_map_repetition : 8, + override_config : 16, + _size_(override_parameters_data) : 8, + override_parameters_data : 8[], +} + +packet LeCsTestComplete : CommandComplete (command_op_code = LE_CS_TEST) { + status : ErrorCode, +} + +packet LeCsTestEnd : Command (op_code = LE_CS_TEST_END) { +} + +packet LeCsTestEndStatus : CommandStatus (command_op_code = LE_CS_TEST_END) { +} + +packet LeCsTestEndComplete : LeMetaEvent (subevent_code = LE_CS_TEST_END_COMPLETE) { + status : ErrorCode, +} + // HCI Event Packets packet InquiryComplete : Event (event_code = INQUIRY_COMPLETE) { @@ -4767,6 +5447,13 @@ packet EncryptionChange : Event (event_code = ENCRYPTION_CHANGE) { encryption_enabled : EncryptionEnabled, } +packet EncryptionChangeV2 : Event (event_code = ENCRYPTION_CHANGE_V2) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + encryption_enabled : EncryptionEnabled, + key_size : 8, +} packet ChangeConnectionLinkKeyComplete : Event (event_code = CHANGE_CONNECTION_LINK_KEY_COMPLETE) { status : ErrorCode, connection_handle : 12, @@ -5116,18 +5803,18 @@ packet RemoteHostSupportedFeaturesNotification : Event (event_code = REMOTE_HOST host_supported_features : 64, } -packet LeMetaEvent : Event (event_code = LE_META_EVENT) { - subevent_code : SubeventCode, - _body_, -} - packet NumberOfCompletedDataBlocks : Event (event_code = NUMBER_OF_COMPLETED_DATA_BLOCKS) { total_num_data_blocks : 16, _payload_, // placeholder (unimplemented) } +packet AuthenticatedPayloadTimeoutExpired : Event (event_code = AUTHENTICATED_PAYLOAD_TIMEOUT_EXPIRED) { + connection_handle : 12, + _reserved_ : 4, +} + // LE Events -packet LeConnectionComplete : LeMetaEvent (subevent_code = CONNECTION_COMPLETE) { +packet LeConnectionComplete : LeMetaEvent (subevent_code = LE_CONNECTION_COMPLETE) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5157,12 +5844,12 @@ struct LeAdvertisingResponse { rssi : 8, } -packet LeAdvertisingReport : LeMetaEvent (subevent_code = ADVERTISING_REPORT) { +packet LeAdvertisingReport : LeMetaEvent (subevent_code = LE_ADVERTISING_REPORT) { _count_(responses) : 8, responses : LeAdvertisingResponse[], } -packet LeConnectionUpdateComplete : LeMetaEvent (subevent_code = CONNECTION_UPDATE_COMPLETE) { +packet LeConnectionUpdateComplete : LeMetaEvent (subevent_code = LE_CONNECTION_UPDATE_COMPLETE) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5171,21 +5858,14 @@ packet LeConnectionUpdateComplete : LeMetaEvent (subevent_code = CONNECTION_UPDA supervision_timeout : 16, // 0x000A to 0x0C80 (100ms to 32s) } -packet LeReadRemoteFeaturesComplete : LeMetaEvent (subevent_code = READ_REMOTE_FEATURES_COMPLETE) { - status : ErrorCode, - connection_handle : 12, - _reserved_ : 4, - le_features : 64, -} - -packet LeLongTermKeyRequest : LeMetaEvent (subevent_code = LONG_TERM_KEY_REQUEST) { +packet LeLongTermKeyRequest : LeMetaEvent (subevent_code = LE_LONG_TERM_KEY_REQUEST) { connection_handle : 12, _reserved_ : 4, random_number : 8[8], encrypted_diversifier : 16, } -packet LeRemoteConnectionParameterRequest : LeMetaEvent (subevent_code = REMOTE_CONNECTION_PARAMETER_REQUEST) { +packet LeRemoteConnectionParameterRequest : LeMetaEvent (subevent_code = LE_REMOTE_CONNECTION_PARAMETER_REQUEST) { connection_handle : 12, _reserved_ : 4, interval_min : 16, // 0x006 - 0x0C80 (7.5ms - 4s) @@ -5194,7 +5874,7 @@ packet LeRemoteConnectionParameterRequest : LeMetaEvent (subevent_code = REMOTE_ timeout : 16, // 0x000A to 0x0C80 (100ms to 32s) } -packet LeDataLengthChange : LeMetaEvent (subevent_code = DATA_LENGTH_CHANGE) { +packet LeDataLengthChange : LeMetaEvent (subevent_code = LE_DATA_LENGTH_CHANGE) { connection_handle : 12, _reserved_ : 4, max_tx_octets : 16, // 0x001B - 0x00FB @@ -5203,17 +5883,33 @@ packet LeDataLengthChange : LeMetaEvent (subevent_code = DATA_LENGTH_CHANGE) { max_rx_time : 16, // 0x0148 - 0x4290 } -packet ReadLocalP256PublicKeyComplete : LeMetaEvent (subevent_code = READ_LOCAL_P256_PUBLIC_KEY_COMPLETE) { +packet LeReadLocalP256PublicKeyComplete : LeMetaEvent (subevent_code = LE_READ_LOCAL_P256_PUBLIC_KEY_COMPLETE) { status : ErrorCode, - local_p_256_public_key : 8[64], + key_x_coordinate : 8[32], + key_y_coordinate : 8[32], } -packet GenerateDhKeyComplete : LeMetaEvent (subevent_code = GENERATE_DHKEY_COMPLETE) { +packet LeGenerateDhKeyComplete : LeMetaEvent (subevent_code = LE_GENERATE_DHKEY_COMPLETE) { status : ErrorCode, dh_key : 8[32], } -packet LeEnhancedConnectionComplete : LeMetaEvent (subevent_code = ENHANCED_CONNECTION_COMPLETE) { +packet LeEnhancedConnectionCompleteV1 : LeMetaEvent (subevent_code = LE_ENHANCED_CONNECTION_COMPLETE_V1) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + role : Role, + peer_address_type : AddressType, + peer_address : Address, + local_resolvable_private_address : Address, + peer_resolvable_private_address : Address, + connection_interval : 16, // 0x006 - 0x0C80 (7.5ms - 4000ms) + peripheral_latency : 16, + supervision_timeout : 16, // 0x000A to 0x0C80 (100ms to 32s) + central_clock_accuracy : ClockAccuracy, +} + +packet LeEnhancedConnectionCompleteV2 : LeMetaEvent (subevent_code = LE_ENHANCED_CONNECTION_COMPLETE_V2) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5226,6 +5922,8 @@ packet LeEnhancedConnectionComplete : LeMetaEvent (subevent_code = ENHANCED_CONN peripheral_latency : 16, supervision_timeout : 16, // 0x000A to 0x0C80 (100ms to 32s) central_clock_accuracy : ClockAccuracy, + advertising_handle : 8, + sync_handle : 16, } enum DirectAdvertisingAddressType : 8 { @@ -5254,12 +5952,12 @@ struct LeDirectedAdvertisingResponse { rssi : 8, } -packet LeDirectedAdvertisingReport : LeMetaEvent (subevent_code = DIRECTED_ADVERTISING_REPORT) { +packet LeDirectedAdvertisingReport : LeMetaEvent (subevent_code = LE_DIRECTED_ADVERTISING_REPORT) { _count_(responses) : 8, responses : LeDirectedAdvertisingResponse[], } -packet LePhyUpdateComplete : LeMetaEvent (subevent_code = PHY_UPDATE_COMPLETE) { +packet LePhyUpdateComplete : LeMetaEvent (subevent_code = LE_PHY_UPDATE_COMPLETE) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5296,12 +5994,12 @@ struct LeExtendedAdvertisingResponse { advertising_data: 8[], } -packet LeExtendedAdvertisingReport : LeMetaEvent (subevent_code = EXTENDED_ADVERTISING_REPORT) { +packet LeExtendedAdvertisingReport : LeMetaEvent (subevent_code = LE_EXTENDED_ADVERTISING_REPORT) { _count_(responses) : 8, responses : LeExtendedAdvertisingResponse[], } -packet LePeriodicAdvertisingSyncEstablished : LeMetaEvent (subevent_code = PERIODIC_ADVERTISING_SYNC_ESTABLISHED) { +packet LePeriodicAdvertisingSyncEstablishedV1 : LeMetaEvent (subevent_code = LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_V1) { status : ErrorCode, sync_handle : 12, _reserved_ : 4, @@ -5313,7 +6011,23 @@ packet LePeriodicAdvertisingSyncEstablished : LeMetaEvent (subevent_code = PERIO advertiser_clock_accuracy : ClockAccuracy, } -packet LePeriodicAdvertisingReport : LeMetaEvent (subevent_code = PERIODIC_ADVERTISING_REPORT) { +packet LePeriodicAdvertisingSyncEstablishedV2 : LeMetaEvent (subevent_code = LE_PERIODIC_ADVERTISING_SYNC_ESTABLISHED_V2) { + status : ErrorCode, + sync_handle : 12, + _reserved_ : 4, + advertising_sid : 8, + advertiser_address_type : AddressType, + advertiser_address : Address, + advertiser_phy : SecondaryPhyType, + periodic_advertising_interval : 16, + advertiser_clock_accuracy : ClockAccuracy, + num_subevents : 8, + subevent_interval : 8, + response_slot_delay : 8, + response_slot_spacing : 8, +} + +packet LePeriodicAdvertisingReportV1 : LeMetaEvent (subevent_code = LE_PERIODIC_ADVERTISING_REPORT_V1) { sync_handle : 12, _reserved_ : 4, tx_power : 8, @@ -5325,15 +6039,29 @@ packet LePeriodicAdvertisingReport : LeMetaEvent (subevent_code = PERIODIC_ADVER data : 8[], } -packet LePeriodicAdvertisingSyncLost : LeMetaEvent (subevent_code = PERIODIC_ADVERTISING_SYNC_LOST) { +packet LePeriodicAdvertisingReportV2 : LeMetaEvent (subevent_code = LE_PERIODIC_ADVERTISING_REPORT_V2) { + sync_handle : 12, + _reserved_ : 4, + tx_power : 8, + rssi : 8, + cte_type : CteType, + periodic_event_counter : 16, + subevent : 8, + data_status : DataStatus, + _reserved_: 6, + _size_(data) : 8, + data : 8[], +} + +packet LePeriodicAdvertisingSyncLost : LeMetaEvent (subevent_code = LE_PERIODIC_ADVERTISING_SYNC_LOST) { sync_handle : 12, _reserved_ : 4, } -packet LeScanTimeout : LeMetaEvent (subevent_code = SCAN_TIMEOUT) { +packet LeScanTimeout : LeMetaEvent (subevent_code = LE_SCAN_TIMEOUT) { } -packet LeAdvertisingSetTerminated : LeMetaEvent (subevent_code = ADVERTISING_SET_TERMINATED) { +packet LeAdvertisingSetTerminated : LeMetaEvent (subevent_code = LE_ADVERTISING_SET_TERMINATED) { status : ErrorCode, advertising_handle : 8, connection_handle : 12, @@ -5341,7 +6069,7 @@ packet LeAdvertisingSetTerminated : LeMetaEvent (subevent_code = ADVERTISING_SET num_completed_extended_advertising_events : 8, } -packet LeScanRequestReceived : LeMetaEvent (subevent_code = SCAN_REQUEST_RECEIVED) { +packet LeScanRequestReceived : LeMetaEvent (subevent_code = LE_SCAN_REQUEST_RECEIVED) { advertising_handle : 8, scanner_address_type : AddressType, scanner_address : Address, @@ -5352,25 +6080,25 @@ enum ChannelSelectionAlgorithm : 8 { ALGORITHM_2 = 1, } -packet LeChannelSelectionAlgorithm : LeMetaEvent (subevent_code = CHANNEL_SELECTION_ALGORITHM) { +packet LeChannelSelectionAlgorithm : LeMetaEvent (subevent_code = LE_CHANNEL_SELECTION_ALGORITHM) { connection_handle : 12, _reserved_ : 4, channel_selection_algorithm : ChannelSelectionAlgorithm, } -packet LeConnectionlessIqReport : LeMetaEvent (subevent_code = CONNECTIONLESS_IQ_REPORT) { +packet LeConnectionlessIqReport : LeMetaEvent (subevent_code = LE_CONNECTIONLESS_IQ_REPORT) { _payload_, // placeholder (unimplemented) } -packet LeConnectionIqReport : LeMetaEvent (subevent_code = CONNECTION_IQ_REPORT) { +packet LeConnectionIqReport : LeMetaEvent (subevent_code = LE_CONNECTION_IQ_REPORT) { _payload_, // placeholder (unimplemented) } -packet LeCteRequestFailed : LeMetaEvent (subevent_code = CTE_REQUEST_FAILED) { +packet LeCteRequestFailed : LeMetaEvent (subevent_code = LE_CTE_REQUEST_FAILED) { _payload_, // placeholder (unimplemented) } -packet LePeriodicAdvertisingSyncTransferReceived : LeMetaEvent (subevent_code = PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED) { +packet LePeriodicAdvertisingSyncTransferReceivedV1 : LeMetaEvent (subevent_code = LE_PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED_V1) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5386,7 +6114,51 @@ packet LePeriodicAdvertisingSyncTransferReceived : LeMetaEvent (subevent_code = advertiser_clock_accuracy : ClockAccuracy, } -packet LeCisEstablished : LeMetaEvent (subevent_code = CIS_ESTABLISHED) { +packet LePeriodicAdvertisingSyncTransferReceivedV2 : LeMetaEvent (subevent_code = LE_PERIODIC_ADVERTISING_SYNC_TRANSFER_RECEIVED_V2) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + service_data : 16, + sync_handle : 12, + _reserved_ : 4, + advertising_sid : 4, + _reserved_ : 4, + advertiser_address_type : AddressType, + advertiser_address : Address, + advertiser_phy : SecondaryPhyType, + periodic_advertising_interval : 16, + advertiser_clock_accuracy : ClockAccuracy, + num_subevents : 8, + subevent_interval : 8, + response_slot_delay : 8, + response_slot_spacing : 8, +} + +packet LeCisEstablishedV1 : LeMetaEvent (subevent_code = LE_CIS_ESTABLISHED_V1) { + status : ErrorCode, + connection_handle : 12, + _reserved_ : 4, + cig_sync_delay : 24, + cis_sync_delay : 24, + transport_latency_c_to_p : 24, + transport_latency_p_to_c : 24, + phy_c_to_p : SecondaryPhyType, + phy_p_to_c : SecondaryPhyType, + nse : 8, + bn_c_to_p : 4, + _reserved_ : 4, + bn_p_to_c : 4, + _reserved_ : 4, + ft_c_to_p : 8, + ft_p_to_c : 8, + max_pdu_c_to_p : 8, + _reserved_ : 8, + max_pdu_p_to_c : 8, + _reserved_ : 8, + iso_interval : 16, +} + +packet LeCisEstablishedV2 : LeMetaEvent (subevent_code = LE_CIS_ESTABLISHED_V2) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5408,9 +6180,15 @@ packet LeCisEstablished : LeMetaEvent (subevent_code = CIS_ESTABLISHED) { max_pdu_p_to_c : 8, _reserved_ : 8, iso_interval : 16, + sub_interval : 24, + max_sdu_c_to_p : 16, + max_sdu_p_to_c : 16, + sdu_interval_c_to_p : 24, + sdu_interval_p_to_c : 24, + framing : Enable, } -packet LeCisRequest : LeMetaEvent (subevent_code = CIS_REQUEST) { +packet LeCisRequest : LeMetaEvent (subevent_code = LE_CIS_REQUEST) { acl_connection_handle : 12, _reserved_ : 4, cis_connection_handle : 12, @@ -5419,7 +6197,7 @@ packet LeCisRequest : LeMetaEvent (subevent_code = CIS_REQUEST) { cis_id : 8, } -packet LeCreateBigComplete : LeMetaEvent (subevent_code = CREATE_BIG_COMPLETE) { +packet LeCreateBigComplete : LeMetaEvent (subevent_code = LE_CREATE_BIG_COMPLETE) { status : ErrorCode, big_handle : 8, big_sync_delay : 24, @@ -5435,12 +6213,12 @@ packet LeCreateBigComplete : LeMetaEvent (subevent_code = CREATE_BIG_COMPLETE) { connection_handle : 16[], } -packet LeTerminateBigComplete : LeMetaEvent (subevent_code = TERMINATE_BIG_COMPLETE) { +packet LeTerminateBigComplete : LeMetaEvent (subevent_code = LE_TERMINATE_BIG_COMPLETE) { big_handle : 8, reason : ErrorCode, } -packet LeBigSyncEstablished : LeMetaEvent (subevent_code = BIG_SYNC_ESTABLISHED) { +packet LeBigSyncEstablished : LeMetaEvent (subevent_code = LE_BIG_SYNC_ESTABLISHED) { status : ErrorCode, big_handle : 8, transport_latency_big : 24, @@ -5454,12 +6232,12 @@ packet LeBigSyncEstablished : LeMetaEvent (subevent_code = BIG_SYNC_ESTABLISHED) connection_handle : 16[], } -packet LeBigSyncLost : LeMetaEvent (subevent_code = BIG_SYNC_LOST) { +packet LeBigSyncLost : LeMetaEvent (subevent_code = LE_BIG_SYNC_LOST) { big_handle : 8, reason : ErrorCode, } -packet LeRequestPeerScaComplete : LeMetaEvent (subevent_code = REQUEST_PEER_SCA_COMPLETE) { +packet LeRequestPeerScaComplete : LeMetaEvent (subevent_code = LE_REQUEST_PEER_SCA_COMPLETE) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5472,7 +6250,7 @@ enum PathLossZone : 8 { HIGH = 2, } -packet LePathLossThreshold : LeMetaEvent (subevent_code = PATH_LOSS_THRESHOLD) { +packet LePathLossThreshold : LeMetaEvent (subevent_code = LE_PATH_LOSS_THRESHOLD) { connection_handle : 12, _reserved_ : 4, current_path_loss : 8, @@ -5485,7 +6263,7 @@ enum ReportingReason : 8 { READ_COMMAND_COMPLETE = 0x02, } -packet LeTransmitPowerReporting : LeMetaEvent (subevent_code = TRANSMIT_POWER_REPORTING) { +packet LeTransmitPowerReporting : LeMetaEvent (subevent_code = LE_TRANSMIT_POWER_REPORTING) { status : ErrorCode, connection_handle : 12, _reserved_ : 4, @@ -5496,7 +6274,7 @@ packet LeTransmitPowerReporting : LeMetaEvent (subevent_code = TRANSMIT_POWER_RE delta : 8, } -packet LeBigInfoAdvertisingReport : LeMetaEvent (subevent_code = BIG_INFO_ADVERTISING_REPORT) { +packet LeBigInfoAdvertisingReport : LeMetaEvent (subevent_code = LE_BIG_INFO_ADVERTISING_REPORT) { sync_handle : 12, _reserved_ : 4, num_bis : 8, @@ -5995,6 +6773,17 @@ packet LeApcfAdTypeFilterComplete : LeApcfComplete (apcf_opcode = AD_TYPE_FILTER apcf_available_spaces : 8, } +packet LeApcfTransportDiscoveryService : LeApcf (apcf_opcode = TRANSPORT_DISCOVERY_SERVICE) { + apcf_action : ApcfAction, + apcf_filter_index : 8, + apcf_transport_discovery_data : 8[], +} + +packet LeApcfTransportDiscoveryServiceComplete : LeApcfComplete (apcf_opcode = TRANSPORT_DISCOVERY_SERVICE) { + apcf_action : ApcfAction, + apcf_available_spaces : 8, +} + packet LeApcfReadExtendedFeatures : LeApcf (apcf_opcode = READ_EXTENDED_FEATURES) { } diff --git a/proto/rootcanal/configuration.proto b/proto/rootcanal/configuration.proto index 0b6db15..0beb961 100644 --- a/proto/rootcanal/configuration.proto +++ b/proto/rootcanal/configuration.proto @@ -24,6 +24,8 @@ enum ControllerPreset { LAIRD_BL654 = 1; // Official PTS dongle, CSR rck. CSR_RCK_PTS_DONGLE = 2; + // Official PTS dongle, Intel BE200. + INTEL_BE200 = 3; } message ControllerFeatures { diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 1510574..cbd11ba 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -26,11 +26,14 @@ num-derive = "0.3.3" num-integer = "0.1.45" num-traits = "0.2.14" paste = "1.0.4" -pdl-runtime = "0.2.2" +pdl-runtime = "0.3.0" pin-utils = "0.1.0" rand = "0.8.3" thiserror = "1.0.23" +[build-dependencies] +pdl-compiler = "0.3.2" + [lib] path="src/lib.rs" crate-type = ["staticlib"] diff --git a/rust/build.rs b/rust/build.rs index 793e1f9..f9d5f7a 100644 --- a/rust/build.rs +++ b/rust/build.rs @@ -14,8 +14,8 @@ use std::env; use std::fs::File; +use std::io::Write; use std::path::{Path, PathBuf}; -use std::process::{Command, Stdio}; fn main() { install_generated_module( @@ -53,35 +53,20 @@ fn install_generated_module(module_name: &str, prebuilt_var: &str, pdl_name: &Pa } } -fn generate_module(in_file: &PathBuf) { +fn generate_module(in_file: &Path) { let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); - let out_file = + let mut out_file = File::create(out_dir.join(in_file.file_name().unwrap()).with_extension("rs")).unwrap(); - // Find the pdl tool. Expecting it at CARGO_HOME/bin - let pdl = match env::var("CARGO_HOME") { - Ok(dir) => PathBuf::from(dir).join("bin").join("pdlc"), - Err(_) => PathBuf::from("pdlc"), - }; - - if !Path::new(pdl.as_os_str()).exists() { - panic!("pdl not found in the current environment: {:?}", pdl.as_os_str().to_str().unwrap()); - } - println!("cargo:rerun-if-changed={}", in_file.display()); - let output = Command::new(pdl.as_os_str().to_str().unwrap()) - .arg("--output-format") - .arg("rust") - .arg(in_file) - .stdout(Stdio::from(out_file)) - .output() - .unwrap(); - - println!( - "Status: {}, stderr: {}", - output.status, - String::from_utf8_lossy(output.stderr.as_slice()) - ); - assert!(output.status.success()); + let mut sources = pdl_compiler::ast::SourceDatabase::new(); + let parsed_file = pdl_compiler::parser::parse_file( + &mut sources, + in_file.to_str().expect("Filename is not UTF-8"), + ) + .expect("PDL parse failed"); + let analyzed_file = pdl_compiler::analyzer::analyze(&parsed_file).expect("PDL analysis failed"); + let rust_source = pdl_compiler::backends::rust_legacy::generate(&sources, &analyzed_file); + out_file.write_all(rust_source.as_bytes()).expect("Could not write to output file"); } diff --git a/rust/include/rootcanal_rs.h b/rust/include/rootcanal_rs.h index 1b395cd..e2c7080 100644 --- a/rust/include/rootcanal_rs.h +++ b/rust/include/rootcanal_rs.h @@ -32,10 +32,8 @@ struct ControllerOps { uint64_t (*get_le_features)(void* user); uint64_t (*get_le_event_mask)(void* user); void (*send_hci_event)(void* user, const uint8_t* data, uintptr_t len); - void (*send_lmp_packet)(void* user, const uint8_t (*to)[6], - const uint8_t* data, uintptr_t len); - void (*send_llcp_packet)(void* user, uint16_t handle, const uint8_t* data, - uintptr_t len); + void (*send_lmp_packet)(void* user, const uint8_t (*to)[6], const uint8_t* data, uintptr_t len); + void (*send_llcp_packet)(void* user, uint16_t handle, const uint8_t* data, uintptr_t len); }; extern "C" { @@ -84,8 +82,7 @@ void link_manager_tick(const LinkManager* lm); /// - This should be called from the thread of creation /// - `lm` must be a valid pointer /// - `data` must be valid for reads of len `len` -bool link_manager_ingest_hci(const LinkManager* lm, const uint8_t* data, - uintptr_t len); +bool link_manager_ingest_hci(const LinkManager* lm, const uint8_t* data, uintptr_t len); /// Process an LMP packet from a peer with the link manager /// Returns true if successful @@ -99,8 +96,8 @@ bool link_manager_ingest_hci(const LinkManager* lm, const uint8_t* data, /// - `lm` must be a valid pointers /// - `from` must be valid pointer for reads for 6 bytes /// - `data` must be valid for reads of len `len` -bool link_manager_ingest_lmp(const LinkManager* lm, const uint8_t (*from)[6], - const uint8_t* data, uintptr_t len); +bool link_manager_ingest_lmp(const LinkManager* lm, const uint8_t (*from)[6], const uint8_t* data, + uintptr_t len); /// Deallocate the link manager instance /// # Arguments @@ -126,8 +123,8 @@ const LinkLayer* link_layer_create(ControllerOps ops); /// - `ll` must be a valid pointer /// - `peer` must be valid for reads for 6 bytes /// - `role` must be 0 (central) or 1 (peripheral) -bool link_layer_add_link(const LinkLayer* ll, uint16_t handle, - const uint8_t (*peer_address)[6], uint8_t role); +bool link_layer_add_link(const LinkLayer* ll, uint16_t handle, const uint8_t (*peer_address)[6], + uint8_t role); /// Unregister a link with a peer inside the link layer /// Returns true if successful @@ -158,8 +155,7 @@ void link_layer_tick(const LinkLayer* ll); /// - This should be called from the thread of creation /// - `ll` must be a valid pointer /// - `data` must be valid for reads of len `len` -bool link_layer_ingest_hci(const LinkLayer* ll, const uint8_t* data, - uintptr_t len); +bool link_layer_ingest_hci(const LinkLayer* ll, const uint8_t* data, uintptr_t len); /// Process an LLCP packet from a peer with the link layer /// Returns true if successful @@ -172,8 +168,8 @@ bool link_layer_ingest_hci(const LinkLayer* ll, const uint8_t* data, /// - This should be called from the thread of creation /// - `ll` must be a valid pointers /// - `data` must be valid for reads of len `len` -bool link_layer_ingest_llcp(const LinkLayer* ll, uint16_t handle, - const uint8_t* data, uintptr_t len); +bool link_layer_ingest_llcp(const LinkLayer* ll, uint16_t handle, const uint8_t* data, + uintptr_t len); /// Query the connection handle for a CIS established with /// the input CIS and CIG identifiers. @@ -186,8 +182,7 @@ bool link_layer_ingest_llcp(const LinkLayer* ll, uint16_t handle, /// # Safety /// - This should be called from the thread of creation /// - `ll` must be a valid pointers -bool link_layer_get_cis_connection_handle(const LinkLayer* ll, uint8_t cig_id, - uint8_t cis_id, +bool link_layer_get_cis_connection_handle(const LinkLayer* ll, uint8_t cig_id, uint8_t cis_id, uint16_t* cis_connection_handle); /// Query the CIS and CIG identifiers for a CIS established with @@ -201,11 +196,9 @@ bool link_layer_get_cis_connection_handle(const LinkLayer* ll, uint8_t cig_id, /// # Safety /// - This should be called from the thread of creation /// - `ll` must be a valid pointers -bool link_layer_get_cis_information(const LinkLayer* ll, - uint16_t cis_connection_handle, - uint16_t* acl_connection_handle, - uint8_t* cig_id, uint8_t* cis_id, - uint16_t* max_sdu_tx); +bool link_layer_get_cis_information(const LinkLayer* ll, uint16_t cis_connection_handle, + uint16_t* acl_connection_handle, uint8_t* cig_id, + uint8_t* cis_id, uint16_t* max_sdu_tx); /// Deallocate the link layer instance /// # Arguments diff --git a/rust/src/llcp/iso.rs b/rust/src/llcp/iso.rs index 75754d3..1f6b11a 100644 --- a/rust/src/llcp/iso.rs +++ b/rust/src/llcp/iso.rs @@ -327,11 +327,11 @@ impl IsoManager { } fn send_hci_event>(&self, event: E) { - self.ops.send_hci_event(&event.into().to_vec()) + self.ops.send_hci_event(&event.into().encode_to_vec().unwrap()) } fn send_llcp_packet>(&self, acl_connection_handle: u16, packet: P) { - self.ops.send_llcp_packet(acl_connection_handle, &packet.into().to_vec()) + self.ops.send_llcp_packet(acl_connection_handle, &packet.into().encode_to_vec().unwrap()) } fn get_le_features(&self) -> u64 { @@ -1283,7 +1283,7 @@ impl IsoManager { conn_event_count: 0, }, ); - self.send_hci_event(hci::LeCisEstablishedBuilder { + self.send_hci_event(hci::LeCisEstablishedV1Builder { status: hci::ErrorCode::Success, connection_handle: cis_connection_handle, cig_sync_delay: parameters.cig_sync_delay, @@ -1323,7 +1323,7 @@ impl IsoManager { let cis = self.cis_connections.get_mut(&cis_connection_handle).unwrap(); cis.state = CisState::Configuration; cis.parameters = None; - self.send_hci_event(hci::LeCisEstablishedBuilder { + self.send_hci_event(hci::LeCisEstablishedV1Builder { status: hci::ErrorCode::RemoteUserTerminatedConnection, connection_handle: cis_connection_handle, cig_sync_delay: 0, @@ -1364,7 +1364,7 @@ impl IsoManager { }); let cis = self.cis_connections.get(&cis_connection_handle).unwrap(); let parameters = cis.parameters.as_ref().unwrap(); - self.send_hci_event(hci::LeCisEstablishedBuilder { + self.send_hci_event(hci::LeCisEstablishedV1Builder { status: hci::ErrorCode::Success, connection_handle: cis_connection_handle, cig_sync_delay: parameters.cig_sync_delay, diff --git a/rust/src/lmp/ec.rs b/rust/src/lmp/ec.rs index c8beee9..e7e94aa 100644 --- a/rust/src/lmp/ec.rs +++ b/rust/src/lmp/ec.rs @@ -78,7 +78,7 @@ impl PublicKey { } fn to_point(&self) -> Point { - Point::new(&self.get_x(), &self.get_y()) + Point::from_affine(self.get_x(), self.get_y()) } } @@ -251,10 +251,11 @@ impl EllipticCurve for P256r1 { const PUBLIC_KEY_SIZE: usize = 64; } +// https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates #[derive(Debug, PartialEq)] enum Point { Infinite(PhantomData), - Finite { x: BigInt, y: BigInt, _curve: PhantomData }, + Finite { x: BigInt, y: BigInt, z: BigInt, _curve: PhantomData }, } impl Point @@ -269,35 +270,61 @@ where &Self::g() * private_key } - fn new(x: &BigInt, y: &BigInt) -> Self { - Point::Finite { x: x.clone(), y: y.clone(), _curve: PhantomData } + fn new(x: BigInt, y: BigInt, z: BigInt) -> Self { + Point::Finite { x, y, z, _curve: PhantomData } + } + + fn from_affine(x: BigInt, y: BigInt) -> Self { + Self::new(x, y, BigInt::from(1)) } fn g() -> Self { - Self::new( - &BigInt::from_bytes_be(Sign::Plus, Curve::G_X.as_ref()), - &BigInt::from_bytes_be(Sign::Plus, Curve::G_Y.as_ref()), + Self::from_affine( + BigInt::from_bytes_be(Sign::Plus, Curve::G_X.as_ref()), + BigInt::from_bytes_be(Sign::Plus, Curve::G_Y.as_ref()), ) } - #[cfg(test)] - fn get_x(&self) -> Option { + fn to_affine(&self) -> Option<(BigInt, BigInt)> { match self { Point::Infinite(_) => None, - Point::Finite { x, .. } => Some(x.clone()), + Point::Finite { x, y, z, _curve } => { + let p = &Curve::p(); + let inv_z = mod_inv(z, p).unwrap(); + let affine_x = (x * inv_z.pow(2)) % p; + let affine_y = (y * inv_z.pow(3)) % p; + Some((affine_x, affine_y)) + } } } fn to_bytes(&self) -> Option> { + self.to_affine().map(|(x, y)| { + let mut x = x.to_signed_bytes_le(); + x.resize(Curve::PRIVATE_KEY_SIZE, 0); + let mut y = y.to_signed_bytes_le(); + y.resize(Curve::PRIVATE_KEY_SIZE, 0); + x.append(&mut y); + x + }) + } + + fn double(&self) -> Self { + // https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates#Point_Doubling_(4M_+_6S_or_4M_+_4S) match self { - Point::Infinite(_) => None, - Point::Finite { x, y, _curve: _ } => { - let mut x = x.to_signed_bytes_le(); - x.resize(Curve::PRIVATE_KEY_SIZE, 0); - let mut y = y.to_signed_bytes_le(); - y.resize(Curve::PRIVATE_KEY_SIZE, 0); - x.append(&mut y); - Some(x) + Point::Infinite(_) => Point::o(), + Point::Finite { y, .. } if y.is_zero() => Point::o(), + Point::Finite { x, y, z, _curve } => { + let s = 4 * x * y.pow(2); + let m: BigInt = 3 * x.pow(2) + Curve::A * z.pow(4); + + let rx = m.pow(2) - 2 * &s; + let ry = m * (s - &rx) - 8 * y.pow(4); + let rz = 2 * y * z; + + let p = &Curve::p(); + + Point::new(rx % p, ry % p, rz % p) } } } @@ -310,7 +337,7 @@ where fn clone(&self) -> Self { match self { Point::Infinite(_) => Point::o(), - Point::Finite { x, y, .. } => Point::new(x, y), + Point::Finite { x, y, z, _curve } => Point::new(x.clone(), y.clone(), z.clone()), } } } @@ -326,30 +353,38 @@ where fn add(self, rhs: &Point) -> Self::Output { // P + O = O + P = P match (self, rhs) { - (Point::Infinite(_), Point::Infinite(_)) => Self::Output::o(), + (Point::Infinite(_), Point::Infinite(_)) => Point::o(), (Point::Infinite(_), Point::Finite { .. }) => rhs.clone(), (Point::Finite { .. }, Point::Infinite(_)) => self.clone(), ( - Point::Finite { _curve: _, x: x1, y: y1 }, - Point::Finite { _curve: _, x: x2, y: y2 }, + Point::Finite { _curve: _, x: x1, y: y1, z: z1 }, + Point::Finite { _curve: _, x: x2, y: y2, z: z2 }, ) => { - // P + (-P) = O - if x1 == x2 && y1 == &(-y2) { - return Self::Output::o(); - } + // https://en.wikibooks.org/wiki/Cryptography/Prime_Curve/Jacobian_Coordinates#Point_Addition_(12M_+_4S) let p = &Curve::p(); - // d(x^3 + ax + b) / dx = (3x^2 + a) / 2y - let slope = if x1 == x2 { - (&(3 * x1.pow(2) + Curve::A) * &mod_inv(&(2 * y1), p).unwrap()) % p + let u1 = (x1 * z2.pow(2)) % p; + let u2 = (x2 * z1.pow(2)) % p; + let s1 = (y1 * z2.pow(3)) % p; + let s2 = (y2 * z1.pow(3)) % p; + + if u1 == u2 { + if s1 != s2 { + Point::o() + } else { + self.double() + } } else { - // dy/dx = (y2 - y1) / (x2 - x1) - (&(y2 - y1) * &mod_inv(&(x2 - x1), p).unwrap()) % p - }; - // Solving (x-p)(x-q)(x-r) = x^3 + ax + b - // => x = d^2 - x1 - x2 - let x = (slope.pow(2) - x1 - x2) % p; - let y = (slope * (x1 - &x) - y1) % p; - Point::new(&x, &y) + let h = &u2 - &u1; + let r = &s2 - &s1; + + let h3 = h.pow(3) % p; + let u1h2 = (u1 * h.pow(2)) % p; + let x3 = r.pow(2) - &h3 - 2 * &u1h2; + let y3 = r * (u1h2 - &x3) - s1 * h3; + let z3 = h * z1 * z2; + + Point::new(x3 % p, y3 % p, z3 % p) + } } } } @@ -371,7 +406,7 @@ where if i.is_odd() { result = &result + &addend; } - addend = &addend + &addend; + addend = addend.double(); i /= 2; } result @@ -441,10 +476,19 @@ mod tests { let priv_b = BigInt::parse_bytes(&test_case.priv_b, 16).unwrap(); let pub_a = Point::::generate_public_key(&priv_a); let pub_b = Point::::generate_public_key(&priv_b); - assert_eq!(pub_a.get_x().unwrap(), BigInt::parse_bytes(&test_case.pub_a, 16).unwrap()); + assert_eq!( + pub_a.to_affine().unwrap().0, + BigInt::parse_bytes(&test_case.pub_a, 16).unwrap() + ); let shared = &pub_a * &priv_b; - assert_eq!(shared.get_x().unwrap(), BigInt::parse_bytes(&test_case.dh_x, 16).unwrap()); - assert_eq!((&pub_a * &priv_b).get_x().unwrap(), (&pub_b * &priv_a).get_x().unwrap()); + assert_eq!( + shared.to_affine().unwrap().0, + BigInt::parse_bytes(&test_case.dh_x, 16).unwrap() + ); + assert_eq!( + (&pub_a * &priv_b).to_affine().unwrap().0, + (&pub_b * &priv_a).to_affine().unwrap().0 + ); } } @@ -455,10 +499,19 @@ mod tests { let priv_b = BigInt::parse_bytes(&test_case.priv_b, 16).unwrap(); let pub_a = Point::::generate_public_key(&priv_a); let pub_b = Point::::generate_public_key(&priv_b); - assert_eq!(pub_a.get_x().unwrap(), BigInt::parse_bytes(&test_case.pub_a, 16).unwrap()); + assert_eq!( + pub_a.to_affine().unwrap().0, + BigInt::parse_bytes(&test_case.pub_a, 16).unwrap() + ); let shared = &pub_a * &priv_b; - assert_eq!(shared.get_x().unwrap(), BigInt::parse_bytes(&test_case.dh_x, 16).unwrap()); - assert_eq!((&pub_a * &priv_b).get_x().unwrap(), (&pub_b * &priv_a).get_x().unwrap()); + assert_eq!( + shared.to_affine().unwrap().0, + BigInt::parse_bytes(&test_case.dh_x, 16).unwrap() + ); + assert_eq!( + (&pub_a * &priv_b).to_affine().unwrap().0, + (&pub_b * &priv_a).to_affine().unwrap().0 + ); } } } diff --git a/rust/src/lmp/manager.rs b/rust/src/lmp/manager.rs index 9e93a01..a8136f7 100644 --- a/rust/src/lmp/manager.rs +++ b/rust/src/lmp/manager.rs @@ -237,7 +237,7 @@ impl LinkManager { } _ => return Err(LinkManagerError::UnhandledHciPacket), }; - self.ops.send_hci_event(&event.to_vec()); + self.ops.send_hci_event(&event.encode_to_vec().unwrap()); Ok(()) } @@ -318,13 +318,15 @@ impl procedure::Context for LinkContext { fn send_hci_event>(&self, event: E) { if let Some(manager) = self.manager.upgrade() { - manager.ops.send_hci_event(&event.into().to_vec()) + manager.ops.send_hci_event(&event.into().encode_to_vec().unwrap()) } } fn send_lmp_packet>(&self, packet: P) { if let Some(manager) = self.manager.upgrade() { - manager.ops.send_lmp_packet(self.peer_address(), &packet.into().to_vec()) + manager + .ops + .send_lmp_packet(self.peer_address(), &packet.into().encode_to_vec().unwrap()) } } diff --git a/rust/src/lmp/procedure/mod.rs b/rust/src/lmp/procedure/mod.rs index c9b845d..d73c5d3 100644 --- a/rust/src/lmp/procedure/mod.rs +++ b/rust/src/lmp/procedure/mod.rs @@ -55,6 +55,7 @@ pub trait Context { SendAcceptedLmpPacketFuture(self, opcode) } + #[allow(dead_code)] fn get_private_key(&self) -> Option { None } @@ -65,7 +66,7 @@ pub trait Context { /// Future for Context::receive_hci_command and Context::receive_lmp_packet pub struct ReceiveFuture<'a, C: ?Sized, P>(fn(&'a C) -> Poll

, &'a C); -impl<'a, C, O> Future for ReceiveFuture<'a, C, O> +impl Future for ReceiveFuture<'_, C, O> where C: Context, { @@ -79,7 +80,7 @@ where /// Future for Context::receive_hci_command and Context::receive_lmp_packet pub struct SendAcceptedLmpPacketFuture<'a, C: ?Sized>(&'a C, lmp::Opcode); -impl<'a, C> Future for SendAcceptedLmpPacketFuture<'a, C> +impl Future for SendAcceptedLmpPacketFuture<'_, C> where C: Context, { diff --git a/scripts/controller_info.py b/scripts/controller_info.py index 10a74a0..cca4f09 100755 --- a/scripts/controller_info.py +++ b/scripts/controller_info.py @@ -98,66 +98,74 @@ async def br_edr_properties(host: Host): page2 = await host.expect_evt(hci.ReadLocalExtendedFeaturesComplete) print( - f"lmp_features: {{ 0x{page0.lmp_features:x}, 0x{page1.extended_lmp_features:x}, 0x{page2.extended_lmp_features:x} }}" + f"lmp_features = {{ 0x{page0.lmp_features:x}, 0x{page1.extended_lmp_features:x}, 0x{page2.extended_lmp_features:x} }};" ) await host.send_cmd(hci.ReadBufferSize()) evt = await host.expect_evt(hci.ReadBufferSizeComplete) - print(f"acl_data_packet_length: {evt.acl_data_packet_length}") - print(f"total_num_acl_data_packets: {evt.total_num_acl_data_packets}") - print(f"sco_data_packet_length: {evt.synchronous_data_packet_length}") - print(f"total_num_sco_data_packets: {evt.total_num_synchronous_data_packets}") + print(f"acl_data_packet_length = {evt.acl_data_packet_length};") + print(f"total_num_acl_data_packets = {evt.total_num_acl_data_packets};") + print(f"sco_data_packet_length = {evt.synchronous_data_packet_length};") + print(f"total_num_sco_data_packets = {evt.total_num_synchronous_data_packets};") await host.send_cmd(hci.ReadNumberOfSupportedIac()) evt = await host.expect_evt(hci.ReadNumberOfSupportedIacComplete) - print(f"num_supported_iac: {evt.num_support_iac}") + print(f"num_supported_iac = {evt.num_support_iac};") async def le_properties(host: Host): - await host.send_cmd(hci.LeReadLocalSupportedFeatures()) - evt = await host.expect_evt(hci.LeReadLocalSupportedFeaturesComplete) + await host.send_cmd(hci.LeReadLocalSupportedFeaturesPage0()) + evt = await host.expect_evt(hci.LeReadLocalSupportedFeaturesPage0Complete) - print(f"le_features: 0x{evt.le_features:x}") + print(f"le_features = 0x{evt.le_features:x};") - await host.send_cmd(hci.LeReadBufferSizeV2()) - evt = await host.expect_evt(hci.LeReadBufferSizeV2Complete) + try: + await host.send_cmd(hci.LeReadBufferSizeV2()) + evt = await host.expect_evt(hci.LeReadBufferSizeV2Complete) + + print(f"le_acl_data_packet_length = {evt.le_buffer_size.le_data_packet_length};") + print(f"total_num_le_acl_data_packets = {evt.le_buffer_size.total_num_le_packets};") + print(f"iso_data_packet_length = {evt.iso_buffer_size.le_data_packet_length};") + print(f"total_num_iso_data_packets = {evt.iso_buffer_size.total_num_le_packets};") + + except Exception: + await host.send_cmd(hci.LeReadBufferSizeV1()) + evt = await host.expect_evt(hci.LeReadBufferSizeV1Complete) - print(f"le_acl_data_packet_length: {evt.le_buffer_size.le_data_packet_length}") - print(f"total_num_le_acl_data_packets: {evt.le_buffer_size.total_num_le_packets}") - print(f"iso_data_packet_length: {evt.iso_buffer_size.le_data_packet_length}") - print(f"total_num_iso_data_packets: {evt.iso_buffer_size.total_num_le_packets}") + print(f"le_acl_data_packet_length = {evt.le_buffer_size.le_data_packet_length};") + print(f"total_num_le_acl_data_packets = {evt.le_buffer_size.total_num_le_packets};") await host.send_cmd(hci.LeReadFilterAcceptListSize()) evt = await host.expect_evt(hci.LeReadFilterAcceptListSizeComplete) - print(f"le_filter_accept_list_size: {evt.filter_accept_list_size}") + print(f"le_filter_accept_list_size = {evt.filter_accept_list_size};") await host.send_cmd(hci.LeReadResolvingListSize()) evt = await host.expect_evt(hci.LeReadResolvingListSizeComplete) - print(f"le_resolving_list_size: {evt.resolving_list_size}") + print(f"le_resolving_list_size = {evt.resolving_list_size};") await host.send_cmd(hci.LeReadSupportedStates()) evt = await host.expect_evt(hci.LeReadSupportedStatesComplete) - print(f"le_supported_states: 0x{evt.le_states:x}") + print(f"le_supported_states: 0x{evt.le_states:x};") await host.send_cmd(hci.LeReadMaximumAdvertisingDataLength()) evt = await host.expect_evt(hci.LeReadMaximumAdvertisingDataLengthComplete) - print(f"le_max_advertising_data_length: {evt.maximum_advertising_data_length}") + print(f"le_max_advertising_data_length = {evt.maximum_advertising_data_length};") await host.send_cmd(hci.LeReadNumberOfSupportedAdvertisingSets()) evt = await host.expect_evt(hci.LeReadNumberOfSupportedAdvertisingSetsComplete) - print(f"le_num_supported_advertising_sets: {evt.number_supported_advertising_sets}") + print(f"le_num_supported_advertising_sets = {evt.number_supported_advertising_sets};") await host.send_cmd(hci.LeReadPeriodicAdvertiserListSize()) evt = await host.expect_evt(hci.LeReadPeriodicAdvertiserListSizeComplete) - print(f"le_periodic_advertiser_list_size: {evt.periodic_advertiser_list_size}") + print(f"le_periodic_advertiser_list_size = {evt.periodic_advertiser_list_size};") async def run(tcp_port: int): @@ -170,16 +178,16 @@ async def run(tcp_port: int): await host.send_cmd(hci.ReadLocalVersionInformation()) evt = await host.expect_evt(hci.ReadLocalVersionInformationComplete) - print(f"hci_version: {evt.local_version_information.hci_version}") - print(f"hci_subversion: 0x{evt.local_version_information.hci_revision:x}") - print(f"lmp_version: {evt.local_version_information.lmp_version}") - print(f"lmp_subversion: 0x{evt.local_version_information.lmp_subversion:x}") - print(f"company_identifier: 0x{evt.local_version_information.manufacturer_name:x}") + print(f"hci_version = {evt.local_version_information.hci_version};") + print(f"hci_subversion = 0x{evt.local_version_information.hci_revision:x};") + print(f"lmp_version = {evt.local_version_information.lmp_version};") + print(f"lmp_subversion = 0x{evt.local_version_information.lmp_subversion:x};") + print(f"company_identifier = 0x{evt.local_version_information.manufacturer_name:x};") await host.send_cmd(hci.ReadLocalSupportedCommands()) evt = await host.expect_evt(hci.ReadLocalSupportedCommandsComplete) - print(f"supported_commands: {{ {', '.join([f'0x{b:x}' for b in evt.supported_commands])} }}") + print(f"supported_commands = {{ {', '.join([f'0x{b:02x}' for b in evt.supported_commands])} }};") try: await br_edr_properties(host) diff --git a/test/HCI/AEN/BV_06_C.py b/test/HCI/AEN/BV_06_C.py new file mode 100644 index 0000000..7a04979 --- /dev/null +++ b/test/HCI/AEN/BV_06_C.py @@ -0,0 +1,51 @@ +# Copyright 2024 Google LLC +# +# 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 +# +# https://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. + +import hci_packets as hci +import link_layer_packets as ll +import unittest +from hci_packets import ErrorCode +from py.bluetooth import Address +from py.controller import ControllerTest + + +class Test(ControllerTest): + + # HCI/AEN/BV-06-C [Public Keys] + # + # Verify that the IUT can generate a P-256 Public-Private key pair and + # return the P-256 Public Key + async def test(self): + controller = self.controller + + controller.send_cmd(hci.LeReadLocalP256PublicKey()) + + await self.expect_evt(hci.LeReadLocalP256PublicKeyStatus(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + + first = await self.expect_evt( + hci.LeReadLocalP256PublicKeyComplete(status=ErrorCode.SUCCESS, + key_x_coordinate=self.Any, + key_y_coordinate=self.Any)) + + controller.send_cmd(hci.LeReadLocalP256PublicKey()) + + await self.expect_evt(hci.LeReadLocalP256PublicKeyStatus(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + + second = await self.expect_evt( + hci.LeReadLocalP256PublicKeyComplete(status=ErrorCode.SUCCESS, + key_x_coordinate=self.Any, + key_y_coordinate=self.Any)) + + self.assertTrue( + (first.key_x_coordinate, first.key_y_coordinate) != (second.key_x_coordinate, second.key_y_coordinate)) diff --git a/test/LL/CIS/CEN/BV_01_C.py b/test/LL/CIS/CEN/BV_01_C.py index 67184f2..9b30233 100644 --- a/test/LL/CIS/CEN/BV_01_C.py +++ b/test/LL/CIS/CEN/BV_01_C.py @@ -165,22 +165,22 @@ async def test(self): # The Connection_Handle parameter is set to the value provided in the HCI_LE_Create_CIS # command. await self.expect_evt( - hci.LeCisEstablished(status=ErrorCode.SUCCESS, - connection_handle=cis_connection_handle, - cig_sync_delay=cis_ind.cig_sync_delay, - cis_sync_delay=cis_ind.cis_sync_delay, - transport_latency_c_to_p=self.Any, - transport_latency_p_to_c=self.Any, - phy_c_to_p=hci.SecondaryPhyType.LE_1M, - phy_p_to_c=hci.SecondaryPhyType.LE_1M, - nse=self.NSE, - bn_c_to_p=self.BN_C_TO_P, - bn_p_to_c=self.BN_P_TO_C, - ft_c_to_p=self.FT_C_TO_P, - ft_p_to_c=self.FT_P_TO_C, - max_pdu_c_to_p=self.Max_PDU_C_TO_P, - max_pdu_p_to_c=self.Max_PDU_P_TO_C, - iso_interval=self.ISO_Interval)) + hci.LeCisEstablishedV1(status=ErrorCode.SUCCESS, + connection_handle=cis_connection_handle, + cig_sync_delay=cis_ind.cig_sync_delay, + cis_sync_delay=cis_ind.cis_sync_delay, + transport_latency_c_to_p=self.Any, + transport_latency_p_to_c=self.Any, + phy_c_to_p=hci.SecondaryPhyType.LE_1M, + phy_p_to_c=hci.SecondaryPhyType.LE_1M, + nse=self.NSE, + bn_c_to_p=self.BN_C_TO_P, + bn_p_to_c=self.BN_P_TO_C, + ft_c_to_p=self.FT_C_TO_P, + ft_p_to_c=self.FT_P_TO_C, + max_pdu_c_to_p=self.Max_PDU_C_TO_P, + max_pdu_p_to_c=self.Max_PDU_P_TO_C, + iso_interval=self.ISO_Interval)) # 8. The Upper Tester orders the IUT to send data packets to the Lower Tester. iso_sdu = [random.randint(1, 251) for n in range(self.Max_SDU_C_TO_P)] diff --git a/test/LL/CIS/CEN/BV_03_C.py b/test/LL/CIS/CEN/BV_03_C.py index c3b0e11..21263c6 100644 --- a/test/LL/CIS/CEN/BV_03_C.py +++ b/test/LL/CIS/CEN/BV_03_C.py @@ -136,5 +136,5 @@ async def test(self): # 5. The Upper Tester receives an HCI_LE_CIS_Established event from the IUT with a status failure. # The Status field has the same value as the LL_REJECT_EXT_IND PDU in step 4. await self.expect_evt( - hci.LeCisEstablished(status=ErrorCode.REMOTE_USER_TERMINATED_CONNECTION, - connection_handle=cis_connection_handle)) + hci.LeCisEstablishedV1(status=ErrorCode.REMOTE_USER_TERMINATED_CONNECTION, + connection_handle=cis_connection_handle)) diff --git a/test/LL/CIS/CEN/BV_10_C.py b/test/LL/CIS/CEN/BV_10_C.py index cb30823..6b2020b 100644 --- a/test/LL/CIS/CEN/BV_10_C.py +++ b/test/LL/CIS/CEN/BV_10_C.py @@ -154,22 +154,22 @@ async def test(self): conn_event_count=0)) await self.expect_evt( - hci.LeCisEstablished(status=ErrorCode.SUCCESS, - connection_handle=cis_connection_handle_1, - cig_sync_delay=cis_ind_1.cig_sync_delay, - cis_sync_delay=cis_ind_1.cis_sync_delay, - transport_latency_c_to_p=self.Any, - transport_latency_p_to_c=self.Any, - phy_c_to_p=hci.SecondaryPhyType.LE_1M, - phy_p_to_c=hci.SecondaryPhyType.LE_1M, - nse=self.NSE, - bn_c_to_p=self.BN_C_TO_P, - bn_p_to_c=self.BN_P_TO_C, - ft_c_to_p=self.FT_C_TO_P, - ft_p_to_c=self.FT_P_TO_C, - max_pdu_c_to_p=self.Max_PDU_C_TO_P, - max_pdu_p_to_c=self.Max_PDU_P_TO_C, - iso_interval=self.ISO_Interval)) + hci.LeCisEstablishedV1(status=ErrorCode.SUCCESS, + connection_handle=cis_connection_handle_1, + cig_sync_delay=cis_ind_1.cig_sync_delay, + cis_sync_delay=cis_ind_1.cis_sync_delay, + transport_latency_c_to_p=self.Any, + transport_latency_p_to_c=self.Any, + phy_c_to_p=hci.SecondaryPhyType.LE_1M, + phy_p_to_c=hci.SecondaryPhyType.LE_1M, + nse=self.NSE, + bn_c_to_p=self.BN_C_TO_P, + bn_p_to_c=self.BN_P_TO_C, + ft_c_to_p=self.FT_C_TO_P, + ft_p_to_c=self.FT_P_TO_C, + max_pdu_c_to_p=self.Max_PDU_C_TO_P, + max_pdu_p_to_c=self.Max_PDU_P_TO_C, + iso_interval=self.ISO_Interval)) cis_req_2 = await self.expect_llcp(source_address=controller.address, destination_address=peer_address_2, @@ -210,22 +210,22 @@ async def test(self): conn_event_count=0)) await self.expect_evt( - hci.LeCisEstablished(status=ErrorCode.SUCCESS, - connection_handle=cis_connection_handle_2, - cig_sync_delay=cis_ind_2.cig_sync_delay, - cis_sync_delay=cis_ind_2.cis_sync_delay, - transport_latency_c_to_p=self.Any, - transport_latency_p_to_c=self.Any, - phy_c_to_p=hci.SecondaryPhyType.LE_1M, - phy_p_to_c=hci.SecondaryPhyType.LE_1M, - nse=self.NSE, - bn_c_to_p=self.BN_C_TO_P, - bn_p_to_c=self.BN_P_TO_C, - ft_c_to_p=self.FT_C_TO_P, - ft_p_to_c=self.FT_P_TO_C, - max_pdu_c_to_p=self.Max_PDU_C_TO_P, - max_pdu_p_to_c=self.Max_PDU_P_TO_C, - iso_interval=self.ISO_Interval)) + hci.LeCisEstablishedV1(status=ErrorCode.SUCCESS, + connection_handle=cis_connection_handle_2, + cig_sync_delay=cis_ind_2.cig_sync_delay, + cis_sync_delay=cis_ind_2.cis_sync_delay, + transport_latency_c_to_p=self.Any, + transport_latency_p_to_c=self.Any, + phy_c_to_p=hci.SecondaryPhyType.LE_1M, + phy_p_to_c=hci.SecondaryPhyType.LE_1M, + nse=self.NSE, + bn_c_to_p=self.BN_C_TO_P, + bn_p_to_c=self.BN_P_TO_C, + ft_c_to_p=self.FT_C_TO_P, + ft_p_to_c=self.FT_P_TO_C, + max_pdu_c_to_p=self.Max_PDU_C_TO_P, + max_pdu_p_to_c=self.Max_PDU_P_TO_C, + iso_interval=self.ISO_Interval)) # 1. The Upper Tester orders the IUT to send a payload of the specified length to the Lower Testers. iso_sdu = [random.randint(1, 251) for n in range(self.Max_SDU_C_TO_P)] diff --git a/test/LL/CIS/CEN/BV_26_C.py b/test/LL/CIS/CEN/BV_26_C.py index 010ee28..d882211 100644 --- a/test/LL/CIS/CEN/BV_26_C.py +++ b/test/LL/CIS/CEN/BV_26_C.py @@ -146,22 +146,22 @@ async def test(self): # CIS packet sent by the Lower Tester. The Connection_Handle parameter is set to the value # provided in the HCI_LE_Create_CIS command. await self.expect_evt( - hci.LeCisEstablished(status=ErrorCode.SUCCESS, - connection_handle=cis_connection_handle, - cig_sync_delay=cis_ind.cig_sync_delay, - cis_sync_delay=cis_ind.cis_sync_delay, - transport_latency_c_to_p=self.Any, - transport_latency_p_to_c=self.Any, - phy_c_to_p=hci.SecondaryPhyType.LE_1M, - phy_p_to_c=hci.SecondaryPhyType.LE_1M, - nse=cis_req.nse, - bn_c_to_p=cis_req.bn_c_to_p, - bn_p_to_c=cis_req.bn_p_to_c, - ft_c_to_p=cis_req.ft_c_to_p, - ft_p_to_c=cis_req.ft_p_to_c, - max_pdu_c_to_p=cis_req.max_pdu_c_to_p, - max_pdu_p_to_c=cis_req.max_pdu_p_to_c, - iso_interval=cis_req.iso_interval)) + hci.LeCisEstablishedV1(status=ErrorCode.SUCCESS, + connection_handle=cis_connection_handle, + cig_sync_delay=cis_ind.cig_sync_delay, + cis_sync_delay=cis_ind.cis_sync_delay, + transport_latency_c_to_p=self.Any, + transport_latency_p_to_c=self.Any, + phy_c_to_p=hci.SecondaryPhyType.LE_1M, + phy_p_to_c=hci.SecondaryPhyType.LE_1M, + nse=cis_req.nse, + bn_c_to_p=cis_req.bn_c_to_p, + bn_p_to_c=cis_req.bn_p_to_c, + ft_c_to_p=cis_req.ft_c_to_p, + ft_p_to_c=cis_req.ft_p_to_c, + max_pdu_c_to_p=cis_req.max_pdu_c_to_p, + max_pdu_p_to_c=cis_req.max_pdu_p_to_c, + iso_interval=cis_req.iso_interval)) # 7. The Upper Tester sends an HCI_LE_Setup_ISO_Data_Path command and receives a success # response from the IUT. @@ -318,22 +318,22 @@ async def test(self): # 23. The IUT sends an HCI_LE_CIS_Established event to the Upper Tester. The Connection_Handle # parameter is set to the value provided in step 16. await self.expect_evt( - hci.LeCisEstablished(status=ErrorCode.SUCCESS, - connection_handle=cis_connection_handle, - cig_sync_delay=cis_ind.cig_sync_delay, - cis_sync_delay=cis_ind.cis_sync_delay, - transport_latency_c_to_p=self.Any, - transport_latency_p_to_c=self.Any, - phy_c_to_p=hci.SecondaryPhyType.LE_1M, - phy_p_to_c=hci.SecondaryPhyType.LE_1M, - nse=cis_req.nse, - bn_c_to_p=cis_req.bn_c_to_p, - bn_p_to_c=cis_req.bn_p_to_c, - ft_c_to_p=cis_req.ft_c_to_p, - ft_p_to_c=cis_req.ft_p_to_c, - max_pdu_c_to_p=cis_req.max_pdu_c_to_p, - max_pdu_p_to_c=cis_req.max_pdu_p_to_c, - iso_interval=cis_req.iso_interval)) + hci.LeCisEstablishedV1(status=ErrorCode.SUCCESS, + connection_handle=cis_connection_handle, + cig_sync_delay=cis_ind.cig_sync_delay, + cis_sync_delay=cis_ind.cis_sync_delay, + transport_latency_c_to_p=self.Any, + transport_latency_p_to_c=self.Any, + phy_c_to_p=hci.SecondaryPhyType.LE_1M, + phy_p_to_c=hci.SecondaryPhyType.LE_1M, + nse=cis_req.nse, + bn_c_to_p=cis_req.bn_c_to_p, + bn_p_to_c=cis_req.bn_p_to_c, + ft_c_to_p=cis_req.ft_c_to_p, + ft_p_to_c=cis_req.ft_p_to_c, + max_pdu_c_to_p=cis_req.max_pdu_c_to_p, + max_pdu_p_to_c=cis_req.max_pdu_p_to_c, + iso_interval=cis_req.iso_interval)) # 24. The Upper Tester sends an HCI_LE_Setup_ISO_Data_Path command to the IUT with # Connection_Handle set to the value provided in step 16 and Data_Path_Direction set to Output. diff --git a/test/LL/CIS/PER/BV_01_C.py b/test/LL/CIS/PER/BV_01_C.py index 63e3be1..358df99 100644 --- a/test/LL/CIS/PER/BV_01_C.py +++ b/test/LL/CIS/PER/BV_01_C.py @@ -138,22 +138,22 @@ async def test(self): # CIS packet sent by the Lower Tester. The Connection_Handle parameter is the # CIS_Connection_Handle value provided in the HCI_LE_CIS_Request event. await self.expect_evt( - hci.LeCisEstablished(status=ErrorCode.SUCCESS, - connection_handle=cis_connection_handle, - cig_sync_delay=self.CIG_Sync_Delay, - cis_sync_delay=self.CIS_Sync_Delay, - transport_latency_c_to_p=self.Any, - transport_latency_p_to_c=self.Any, - phy_c_to_p=hci.SecondaryPhyType.LE_1M, - phy_p_to_c=hci.SecondaryPhyType.LE_1M, - nse=self.NSE, - bn_c_to_p=self.BN_C_TO_P, - bn_p_to_c=self.BN_P_TO_C, - ft_c_to_p=self.FT_C_TO_P, - ft_p_to_c=self.FT_P_TO_C, - max_pdu_c_to_p=self.Max_PDU_C_TO_P, - max_pdu_p_to_c=self.Max_PDU_P_TO_C, - iso_interval=self.ISO_Interval)) + hci.LeCisEstablishedV1(status=ErrorCode.SUCCESS, + connection_handle=cis_connection_handle, + cig_sync_delay=self.CIG_Sync_Delay, + cis_sync_delay=self.CIS_Sync_Delay, + transport_latency_c_to_p=self.Any, + transport_latency_p_to_c=self.Any, + phy_c_to_p=hci.SecondaryPhyType.LE_1M, + phy_p_to_c=hci.SecondaryPhyType.LE_1M, + nse=self.NSE, + bn_c_to_p=self.BN_C_TO_P, + bn_p_to_c=self.BN_P_TO_C, + ft_c_to_p=self.FT_C_TO_P, + ft_p_to_c=self.FT_P_TO_C, + max_pdu_c_to_p=self.Max_PDU_C_TO_P, + max_pdu_p_to_c=self.Max_PDU_P_TO_C, + iso_interval=self.ISO_Interval)) # 9. The Upper Tester sends an HCI_LE_Setup_ISO_Data_Path command to the IUT with the output # path enabled and receives a successful HCI_Command_Complete in response. diff --git a/test/LL/CON_/CEN/BV_41_C.py b/test/LL/CON_/CEN/BV_41_C.py index 9d377ef..f8711d5 100644 --- a/test/LL/CON_/CEN/BV_41_C.py +++ b/test/LL/CON_/CEN/BV_41_C.py @@ -41,25 +41,26 @@ async def test(self): # Prelude: Establish an ACL connection as central with the IUT. controller.send_cmd( - hci.LeExtendedCreateConnection(initiator_filter_policy=hci.InitiatorFilterPolicy.USE_PEER_ADDRESS, - own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - initiating_phys=0x1, - initiating_phy_parameters=[ - hci.InitiatingPhyParameters( - scan_interval=0x200, - scan_window=0x100, - connection_interval_min=0x200, - connection_interval_max=0x200, - max_latency=0x6, - supervision_timeout=0xc80, - min_ce_length=0, - max_ce_length=0, - ) - ])) - - await self.expect_evt(hci.LeExtendedCreateConnectionStatus(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + hci.LeExtendedCreateConnectionV1(initiator_filter_policy=hci.InitiatorFilterPolicy.USE_PEER_ADDRESS, + own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + initiating_phys=0x1, + initiating_phy_parameters=[ + hci.InitiatingPhyParameters( + scan_interval=0x200, + scan_window=0x100, + connection_interval_min=0x200, + connection_interval_max=0x200, + max_latency=0x6, + supervision_timeout=0xc80, + min_ce_length=0, + max_ce_length=0, + ) + ])) + + await self.expect_evt( + hci.LeExtendedCreateConnectionV1Status(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) controller.send_ll(ll.LeLegacyAdvertisingPdu(source_address=peer_address, advertising_address_type=ll.AddressType.PUBLIC, @@ -86,15 +87,15 @@ async def test(self): conn_supervision_timeout=0xc80)) await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=acl_connection_handle, - role=hci.Role.CENTRAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=0x200, - peripheral_latency=0x6, - supervision_timeout=0xc80, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=acl_connection_handle, + role=hci.Role.CENTRAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=0x200, + peripheral_latency=0x6, + supervision_timeout=0xc80, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) await self.expect_evt( hci.LeChannelSelectionAlgorithm(connection_handle=acl_connection_handle, diff --git a/test/LL/CON_/CEN/BV_43_C.py b/test/LL/CON_/CEN/BV_43_C.py index 914df4c..8d147c9 100644 --- a/test/LL/CON_/CEN/BV_43_C.py +++ b/test/LL/CON_/CEN/BV_43_C.py @@ -38,25 +38,26 @@ async def test(self): # Prelude: Establish an ACL connection as central with the IUT. controller.send_cmd( - hci.LeExtendedCreateConnection(initiator_filter_policy=hci.InitiatorFilterPolicy.USE_PEER_ADDRESS, - own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - initiating_phys=0x1, - initiating_phy_parameters=[ - hci.InitiatingPhyParameters( - scan_interval=0x200, - scan_window=0x100, - connection_interval_min=0x200, - connection_interval_max=0x200, - max_latency=0x6, - supervision_timeout=0xc80, - min_ce_length=0, - max_ce_length=0, - ) - ])) - - await self.expect_evt(hci.LeExtendedCreateConnectionStatus(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + hci.LeExtendedCreateConnectionV1(initiator_filter_policy=hci.InitiatorFilterPolicy.USE_PEER_ADDRESS, + own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + initiating_phys=0x1, + initiating_phy_parameters=[ + hci.InitiatingPhyParameters( + scan_interval=0x200, + scan_window=0x100, + connection_interval_min=0x200, + connection_interval_max=0x200, + max_latency=0x6, + supervision_timeout=0xc80, + min_ce_length=0, + max_ce_length=0, + ) + ])) + + await self.expect_evt( + hci.LeExtendedCreateConnectionV1Status(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) controller.send_ll(ll.LeLegacyAdvertisingPdu(source_address=peer_address, advertising_address_type=ll.AddressType.PUBLIC, @@ -83,15 +84,15 @@ async def test(self): conn_supervision_timeout=0xc80)) await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=acl_connection_handle, - role=hci.Role.CENTRAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=0x200, - peripheral_latency=0x6, - supervision_timeout=0xc80, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=acl_connection_handle, + role=hci.Role.CENTRAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=0x200, + peripheral_latency=0x6, + supervision_timeout=0xc80, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) await self.expect_evt( hci.LeChannelSelectionAlgorithm(connection_handle=acl_connection_handle, diff --git a/test/LL/CON_/INI/BV_08_C.py b/test/LL/CON_/INI/BV_08_C.py index bfc23e8..81eaded 100644 --- a/test/LL/CON_/INI/BV_08_C.py +++ b/test/LL/CON_/INI/BV_08_C.py @@ -116,16 +116,16 @@ async def test(self): # 6. Upper Tester receives an HCI_LE_Enhanced_Connection_Complete event from the IUT # including the Lower Tester address and connection interval selected. connect_complete = await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=self.Any, - role=hci.Role.CENTRAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=0x200, - peripheral_latency=0x6, - supervision_timeout=0xc80, - local_resolvable_private_address=connect_ind.source_address, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=self.Any, + role=hci.Role.CENTRAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=0x200, + peripheral_latency=0x6, + supervision_timeout=0xc80, + local_resolvable_private_address=connect_ind.source_address, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 7. After the CONNECT_IND has been received, the Lower Tester receives the first correctly # formatted LL Data Channel PDU on the data channel. diff --git a/test/LL/CON_/INI/BV_09_C.py b/test/LL/CON_/INI/BV_09_C.py index 782c25e..1107924 100644 --- a/test/LL/CON_/INI/BV_09_C.py +++ b/test/LL/CON_/INI/BV_09_C.py @@ -144,17 +144,17 @@ async def test(self): # 10. Upper Tester receives an HCI_LE_Enhanced_Connection_Complete event from the IUT # including the Lower Tester’s RPA and Identity address and connection interval selected. connect_complete = await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=self.Any, - role=hci.Role.CENTRAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - peer_resolvable_private_address=peer_resolvable_address, - local_resolvable_private_address=connect_ind.source_address, - connection_interval=0x200, - peripheral_latency=0x6, - supervision_timeout=0xc80, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=self.Any, + role=hci.Role.CENTRAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + peer_resolvable_private_address=peer_resolvable_address, + local_resolvable_private_address=connect_ind.source_address, + connection_interval=0x200, + peripheral_latency=0x6, + supervision_timeout=0xc80, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 11. After the CONNECT_IND has been received, the Lower Tester receives the first correctly # formatted LL Data Channel PDU on the data channel. diff --git a/test/LL/CON_/INI/BV_10_C.py b/test/LL/CON_/INI/BV_10_C.py index faa3d90..705e83e 100644 --- a/test/LL/CON_/INI/BV_10_C.py +++ b/test/LL/CON_/INI/BV_10_C.py @@ -144,16 +144,16 @@ async def test(self): # 10. Upper Tester receives an HCI_LE_Enhanced_Connection_Complete event from the IUT # including the Lower Tester address and connection interval selected. connect_complete = await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=self.Any, - role=hci.Role.CENTRAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - peer_resolvable_private_address=peer_resolvable_address, - connection_interval=0x200, - peripheral_latency=0x6, - supervision_timeout=0xc80, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=self.Any, + role=hci.Role.CENTRAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + peer_resolvable_private_address=peer_resolvable_address, + connection_interval=0x200, + peripheral_latency=0x6, + supervision_timeout=0xc80, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 11. After the CONNECT_IND has been received, the Lower Tester receives the first correctly # formatted LL Data Channel PDU on the data channel. diff --git a/test/LL/CON_/INI/BV_11_C.py b/test/LL/CON_/INI/BV_11_C.py index bb53412..301c7ad 100644 --- a/test/LL/CON_/INI/BV_11_C.py +++ b/test/LL/CON_/INI/BV_11_C.py @@ -152,17 +152,17 @@ async def test(self): # 10. Upper Tester receives an HCI_LE_Enhanced_Connection_Complete event from the IUT # including the Lower Tester address and connection interval selected. connect_complete = await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=self.Any, - role=hci.Role.CENTRAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - peer_resolvable_private_address=peer_resolvable_address, - local_resolvable_private_address=connect_ind.source_address, - connection_interval=0x200, - peripheral_latency=0x6, - supervision_timeout=0xc80, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=self.Any, + role=hci.Role.CENTRAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + peer_resolvable_private_address=peer_resolvable_address, + local_resolvable_private_address=connect_ind.source_address, + connection_interval=0x200, + peripheral_latency=0x6, + supervision_timeout=0xc80, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 11. After the CONNECT_IND has been received, the Lower Tester receives the first correctly # formatted LL Data Channel PDU on the data channel. diff --git a/test/LL/CON_/PER/BV_40_C.py b/test/LL/CON_/PER/BV_40_C.py index 045bca3..f3f2eae 100644 --- a/test/LL/CON_/PER/BV_40_C.py +++ b/test/LL/CON_/PER/BV_40_C.py @@ -72,15 +72,15 @@ async def test(self): conn_supervision_timeout=0x200)) await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=acl_connection_handle, - role=hci.Role.PERIPHERAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=0x200, - peripheral_latency=0x200, - supervision_timeout=0x200, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=acl_connection_handle, + role=hci.Role.PERIPHERAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=0x200, + peripheral_latency=0x200, + supervision_timeout=0x200, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) test_rounds = [ TestRound(0x00, 0x01, 0x03, 0x02, 0x00), diff --git a/test/LL/CON_/PER/BV_42_C.py b/test/LL/CON_/PER/BV_42_C.py index ae067c2..3c7545d 100644 --- a/test/LL/CON_/PER/BV_42_C.py +++ b/test/LL/CON_/PER/BV_42_C.py @@ -72,15 +72,15 @@ async def test(self): conn_supervision_timeout=0x200)) await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=acl_connection_handle, - role=hci.Role.PERIPHERAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=0x200, - peripheral_latency=0x200, - supervision_timeout=0x200, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=acl_connection_handle, + role=hci.Role.PERIPHERAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=0x200, + peripheral_latency=0x200, + supervision_timeout=0x200, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 1. Upper Tester sends an HCI_LE_Set_PHY command to the IUT with the ALL_PHYS fields set to a # value of 0x03. Upper Tester receives an HCI_Command_Status event indicating success in diff --git a/test/LL/DDI/ADV/BV_06_C.py b/test/LL/DDI/ADV/BV_06_C.py index f52edd3..f7ed090 100644 --- a/test/LL/DDI/ADV/BV_06_C.py +++ b/test/LL/DDI/ADV/BV_06_C.py @@ -90,15 +90,15 @@ async def test(self): # 6. Upper Tester receives an HCI_LE_Connection_Complete event from the IUT including the # parameters sent to the IUT in step 4. await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=connection_handle, - role=hci.Role.PERIPHERAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=LL_initiator_connInterval, - peripheral_latency=LL_initiator_connPeripheralLatency, - supervision_timeout=LL_initiator_connSupervisionTimeout, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=connection_handle, + role=hci.Role.PERIPHERAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=LL_initiator_connInterval, + peripheral_latency=LL_initiator_connPeripheralLatency, + supervision_timeout=LL_initiator_connSupervisionTimeout, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 7. The Upper Tester sends an HCI_Disconnect command to the IUT with the Connection_Handle # and receives a successful HCI_Command_Status event in return. diff --git a/test/LL/DDI/ADV/BV_07_C.py b/test/LL/DDI/ADV/BV_07_C.py index 271a4fc..afc834f 100644 --- a/test/LL/DDI/ADV/BV_07_C.py +++ b/test/LL/DDI/ADV/BV_07_C.py @@ -120,15 +120,15 @@ async def test(self): # 9. Upper Tester receives an HCI_LE_Connection_Complete event from the IUT including the # parameters sent to the IUT. await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=connection_handle, - role=hci.Role.PERIPHERAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=LL_initiator_connInterval, - peripheral_latency=LL_initiator_connPeripheralLatency, - supervision_timeout=LL_initiator_connSupervisionTimeout, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=connection_handle, + role=hci.Role.PERIPHERAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=LL_initiator_connInterval, + peripheral_latency=LL_initiator_connPeripheralLatency, + supervision_timeout=LL_initiator_connSupervisionTimeout, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 10. Peripheral Connection Terminated (connection interval, Peripheral latency, timeout, channel map, # un-encrypted, connection handle from step 9). diff --git a/test/LL/DDI/ADV/BV_09_C.py b/test/LL/DDI/ADV/BV_09_C.py index 719ddc7..d5e1c16 100644 --- a/test/LL/DDI/ADV/BV_09_C.py +++ b/test/LL/DDI/ADV/BV_09_C.py @@ -303,7 +303,7 @@ async def steps_4_14(self, peer_address: Address, peer_address_type: ll.AddressT # 13. Upper Tester receives an HCI_LE_Connection_Complete event from the IUT including the # parameters sent to the IUT. await self.expect_evt( - hci.LeEnhancedConnectionComplete( + hci.LeEnhancedConnectionCompleteV1( status=ErrorCode.SUCCESS, connection_handle=connection_handle, role=hci.Role.PERIPHERAL, @@ -373,7 +373,7 @@ async def steps_24_29(self, peer_address: Address, peer_address_type: ll.Address # parameters sent to the IUT in step 25 and as postamble: Peripheral Connection Terminated # (connection interval, Peripheral latency, timeout, channel map, un-encrypted, connection handle). await self.expect_evt( - hci.LeEnhancedConnectionComplete( + hci.LeEnhancedConnectionCompleteV1( status=ErrorCode.SUCCESS, connection_handle=connection_handle, role=hci.Role.PERIPHERAL, diff --git a/test/LL/DDI/ADV/BV_11_C.py b/test/LL/DDI/ADV/BV_11_C.py index 0a01918..a322a17 100644 --- a/test/LL/DDI/ADV/BV_11_C.py +++ b/test/LL/DDI/ADV/BV_11_C.py @@ -116,28 +116,27 @@ async def test(self): rssi=-16) # Note: Link layer sends LeConnectComplete here. - await self.expect_ll( - ll.LeConnectComplete(source_address=controller.address, - destination_address=peer_address, - initiating_address_type=ll.AddressType.PUBLIC, - advertising_address_type=ll.AddressType.PUBLIC, - conn_interval=self.LL_initiator_connInterval, - conn_peripheral_latency=self.LL_initiator_connPeripheralLatency, - conn_supervision_timeout=self.LL_initiator_connSupervisionTimeout), - ignored_pdus=[ll.LeLegacyAdvertisingPdu]) + await self.expect_ll(ll.LeConnectComplete(source_address=controller.address, + destination_address=peer_address, + initiating_address_type=ll.AddressType.PUBLIC, + advertising_address_type=ll.AddressType.PUBLIC, + conn_interval=self.LL_initiator_connInterval, + conn_peripheral_latency=self.LL_initiator_connPeripheralLatency, + conn_supervision_timeout=self.LL_initiator_connSupervisionTimeout), + ignored_pdus=[ll.LeLegacyAdvertisingPdu]) # 11. Upper Tester receives an HCI_LE_Connection_Complete event from the IUT including the # parameters sent to the IUT in step 8. await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=connection_handle, - role=hci.Role.PERIPHERAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=peer_address, - connection_interval=self.LL_initiator_connInterval, - peripheral_latency=self.LL_initiator_connPeripheralLatency, - supervision_timeout=self.LL_initiator_connSupervisionTimeout, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=connection_handle, + role=hci.Role.PERIPHERAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=peer_address, + connection_interval=self.LL_initiator_connInterval, + peripheral_latency=self.LL_initiator_connPeripheralLatency, + supervision_timeout=self.LL_initiator_connSupervisionTimeout, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 12. Upper Tester receives an HCI_LE_Disconnection_Complete event from the IUT with the reason # parameter indicating ‘connection failed to be established’, with the connection handle parameter diff --git a/test/LL/DDI/ADV/BV_19_C.py b/test/LL/DDI/ADV/BV_19_C.py index 9247324..80a8de4 100644 --- a/test/LL/DDI/ADV/BV_19_C.py +++ b/test/LL/DDI/ADV/BV_19_C.py @@ -107,15 +107,15 @@ async def test(self): # 10. Upper Tester receives an HCI_LE_Connection_Complete event from the IUT including the # parameters sent to the IUT in step 7. await self.expect_evt( - hci.LeEnhancedConnectionComplete(status=ErrorCode.SUCCESS, - connection_handle=connection_handle, - role=hci.Role.PERIPHERAL, - peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, - peer_address=public_peer_address, - connection_interval=self.LL_initiator_connInterval, - peripheral_latency=self.LL_initiator_connPeripheralLatency, - supervision_timeout=self.LL_initiator_connSupervisionTimeout, - central_clock_accuracy=hci.ClockAccuracy.PPM_500)) + hci.LeEnhancedConnectionCompleteV1(status=ErrorCode.SUCCESS, + connection_handle=connection_handle, + role=hci.Role.PERIPHERAL, + peer_address_type=hci.AddressType.PUBLIC_DEVICE_ADDRESS, + peer_address=public_peer_address, + connection_interval=self.LL_initiator_connInterval, + peripheral_latency=self.LL_initiator_connPeripheralLatency, + supervision_timeout=self.LL_initiator_connSupervisionTimeout, + central_clock_accuracy=hci.ClockAccuracy.PPM_500)) # 11. Upper Tester receives an HCI_Disconnection_Complete event from the IUT once the # Establishment Timeout has expired. diff --git a/test/LL/DDI/ADV/BV_21_C.py b/test/LL/DDI/ADV/BV_21_C.py index 064194c..56ac692 100644 --- a/test/LL/DDI/ADV/BV_21_C.py +++ b/test/LL/DDI/ADV/BV_21_C.py @@ -27,6 +27,14 @@ class Test(ControllerTest): LL_advertiser_advInterval_MAX = 0x200 LL_advertiser_Adv_Channel_Map = 0x7 + ADV_NONCONN_IND = hci.AdvertisingEventProperties( + connectable=0, + scannable=0, + directed=0, + high_duty_cycle=0, + legacy=1, + ) + # LL/DDI/ADV/BV-21-C [Extended Advertising, Legacy PDUs, Non-Connectable] async def test(self): controller = self.controller @@ -37,9 +45,9 @@ async def test(self): # Advertising_Event_Properties parameter shall be set to 00010000b (ADV_NONCONN_IND # legacy PDU). controller.send_cmd( - hci.LeSetExtendedAdvertisingParametersLegacy( + hci.LeSetExtendedAdvertisingParametersV1( advertising_handle=0, - legacy_advertising_event_properties=hci.LegacyAdvertisingEventProperties.ADV_NONCONN_IND, + advertising_event_properties=self.ADV_NONCONN_IND, primary_advertising_interval_min=self.LL_advertiser_advInterval_MIN, primary_advertising_interval_max=self.LL_advertiser_advInterval_MAX, primary_advertising_channel_map=self.LL_advertiser_Adv_Channel_Map, @@ -47,7 +55,7 @@ async def test(self): advertising_filter_policy=hci.AdvertisingFilterPolicy.ALL_DEVICES)) await self.expect_evt( - hci.LeSetExtendedAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + hci.LeSetExtendedAdvertisingParametersV1Complete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) # For each round from 1–3 based on Table 4.2: await self.steps_3_8(advertising_data=[1]) diff --git a/test/LL/DDI/ADV/BV_22_C.py b/test/LL/DDI/ADV/BV_22_C.py index dd8b5b1..0585800 100644 --- a/test/LL/DDI/ADV/BV_22_C.py +++ b/test/LL/DDI/ADV/BV_22_C.py @@ -27,6 +27,14 @@ class Test(ControllerTest): LL_advertiser_advInterval_MAX = 0x200 LL_advertiser_Adv_Channel_Map = 0x7 + ADV_IND = hci.AdvertisingEventProperties( + connectable=1, + scannable=1, + directed=0, + high_duty_cycle=0, + legacy=1, + ) + # LL/DDI/ADV/BV-22-C [Extended Advertising, Legacy PDUs, Undirected, CSA #2] async def test(self): controller = self.controller @@ -36,9 +44,9 @@ async def test(self): # IUT using all supported advertising channels and minimum advertising interval. The # Advertising_Event_Properties parameter shall be set to 00010011b (ADV_IND legacy PDU). controller.send_cmd( - hci.LeSetExtendedAdvertisingParametersLegacy( + hci.LeSetExtendedAdvertisingParametersV1( advertising_handle=0, - legacy_advertising_event_properties=hci.LegacyAdvertisingEventProperties.ADV_IND, + advertising_event_properties=self.ADV_IND, primary_advertising_interval_min=self.LL_advertiser_advInterval_MIN, primary_advertising_interval_max=self.LL_advertiser_advInterval_MAX, primary_advertising_channel_map=self.LL_advertiser_Adv_Channel_Map, @@ -46,7 +54,7 @@ async def test(self): advertising_filter_policy=hci.AdvertisingFilterPolicy.ALL_DEVICES)) await self.expect_evt( - hci.LeSetExtendedAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + hci.LeSetExtendedAdvertisingParametersV1Complete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) # 8. Repeat steps 3–7 for each Round shown in Table 4.4. await self.steps_3_7(advertising_data=[1]) diff --git a/test/LL/DDI/ADV/BV_26_C.py b/test/LL/DDI/ADV/BV_26_C.py index 24bc1d1..745ead2 100644 --- a/test/LL/DDI/ADV/BV_26_C.py +++ b/test/LL/DDI/ADV/BV_26_C.py @@ -83,29 +83,30 @@ async def steps_2_16(self, maximum_advertising_data_length: int, data_length: in # shall be set to 0x0000. The Primary_Advertising_PHY and Secondary_Advertising_PHY shall be # set to the values specified in Table 4.9. controller.send_cmd( - hci.LeSetExtendedAdvertisingParameters(advertising_handle=0, - advertising_event_properties=hci.AdvertisingEventProperties(), - primary_advertising_interval_min=self.LL_advertiser_advInterval_MIN, - primary_advertising_interval_max=self.LL_advertiser_advInterval_MAX, - primary_advertising_channel_map=self.LL_advertiser_Adv_Channel_Map, - own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, - advertising_filter_policy=hci.AdvertisingFilterPolicy.ALL_DEVICES, - primary_advertising_phy=hci.PrimaryPhyType.LE_1M)) + hci.LeSetExtendedAdvertisingParametersV1( + advertising_handle=0, + advertising_event_properties=hci.AdvertisingEventProperties(), + primary_advertising_interval_min=self.LL_advertiser_advInterval_MIN, + primary_advertising_interval_max=self.LL_advertiser_advInterval_MAX, + primary_advertising_channel_map=self.LL_advertiser_Adv_Channel_Map, + own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, + advertising_filter_policy=hci.AdvertisingFilterPolicy.ALL_DEVICES, + primary_advertising_phy=hci.PrimaryPhyType.LE_1M)) await self.expect_evt( - hci.LeSetExtendedAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + hci.LeSetExtendedAdvertisingParametersV1Complete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) # 4. The Upper Tester sends an HCI_LE_Set_Periodic_Advertising_Parameters command to the IUT # using all supported advertising channels and selected periodic interval. # Periodic_Advertising_Properties parameter shall be set to 0x0000. controller.send_cmd( - hci.LeSetPeriodicAdvertisingParameters(advertising_handle=0, - periodic_advertising_interval_min=0x100, - periodic_advertising_interval_max=0x100, - include_tx_power=False)) + hci.LeSetPeriodicAdvertisingParametersV1(advertising_handle=0, + periodic_advertising_interval_min=0x100, + periodic_advertising_interval_max=0x100, + include_tx_power=False)) await self.expect_evt( - hci.LeSetPeriodicAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + hci.LeSetPeriodicAdvertisingParametersV1Complete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) # 5. The Upper Tester sends one or more HCI_LE_Set_Periodic_Advertising_Data commands to the # IUT with values according to Table 4.10 and using random octets from 1 to 254 as the payload. If diff --git a/test/LL/DDI/ADV/BV_47_C.py b/test/LL/DDI/ADV/BV_47_C.py index 64b4718..7549daa 100644 --- a/test/LL/DDI/ADV/BV_47_C.py +++ b/test/LL/DDI/ADV/BV_47_C.py @@ -32,7 +32,7 @@ def make_advertising_event_properties(properties: int) -> hci.AdvertisingEventPr high_duty_cycle=(properties & 0x8) != 0, legacy=(properties & 0x10) != 0, anonymous=(properties & 0x20) != 0, - tx_power=(properties & 0x40) != 0) + include_tx_power=(properties & 0x40) != 0) @dataclass @@ -107,17 +107,18 @@ async def steps_2_13(self, maximum_advertising_data_length: int, advertising_eve # Peer_Address_Type shall be set to 0x00 (Public Device Address), and the Peer_Address shall be # set to the Lower Tester’s address. controller.send_cmd( - hci.LeSetExtendedAdvertisingParameters(advertising_handle=0, - advertising_event_properties=advertising_event_properties, - primary_advertising_interval_min=self.LL_advertiser_advInterval_MIN, - primary_advertising_interval_max=self.LL_advertiser_advInterval_MAX, - primary_advertising_channel_map=self.LL_advertiser_Adv_Channel_Map, - own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, - advertising_filter_policy=hci.AdvertisingFilterPolicy.ALL_DEVICES, - primary_advertising_phy=hci.PrimaryPhyType.LE_1M)) + hci.LeSetExtendedAdvertisingParametersV1( + advertising_handle=0, + advertising_event_properties=advertising_event_properties, + primary_advertising_interval_min=self.LL_advertiser_advInterval_MIN, + primary_advertising_interval_max=self.LL_advertiser_advInterval_MAX, + primary_advertising_channel_map=self.LL_advertiser_Adv_Channel_Map, + own_address_type=hci.OwnAddressType.PUBLIC_DEVICE_ADDRESS, + advertising_filter_policy=hci.AdvertisingFilterPolicy.ALL_DEVICES, + primary_advertising_phy=hci.PrimaryPhyType.LE_1M)) await self.expect_evt( - hci.LeSetExtendedAdvertisingParametersComplete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) + hci.LeSetExtendedAdvertisingParametersV1Complete(status=ErrorCode.SUCCESS, num_hci_command_packets=1)) # 4. The Upper Tester sends one or more HCI_LE_Set_Extended_Advertising_Data commands to the # IUT with values according to Table 4.6 and using random octets from 1 to 254 as the payload. If diff --git a/test/LL/DDI/SCN/BV_79_C.py b/test/LL/DDI/SCN/BV_79_C.py index c58b7e9..c85f740 100644 --- a/test/LL/DDI/SCN/BV_79_C.py +++ b/test/LL/DDI/SCN/BV_79_C.py @@ -153,7 +153,7 @@ async def test(self): # Tester containing a Status of 0x00 (Success), Sync_Handle set to a valid value, and the # Advertising_SID received in step 3. await self.expect_evt( - hci.LePeriodicAdvertisingSyncEstablished( + hci.LePeriodicAdvertisingSyncEstablishedV1( status=ErrorCode.SUCCESS, sync_handle=0, advertising_sid=advertising_sid, @@ -193,10 +193,10 @@ async def test(self): fragment_length = min(max_fragment_length, remaining_length) data_status = hci.DataStatus.CONTINUING if remaining_length > max_fragment_length else hci.DataStatus.COMPLETE await self.expect_evt( - hci.LePeriodicAdvertisingReport(sync_handle=0, - tx_power=tx_power, - rssi=0x10, - cte_type=hci.CteType.NO_CONSTANT_TONE_EXTENSION, - data_status=data_status, - data=advertising_data[offset:offset + fragment_length])) + hci.LePeriodicAdvertisingReportV1(sync_handle=0, + tx_power=tx_power, + rssi=0x10, + cte_type=hci.CteType.NO_CONSTANT_TONE_EXTENSION, + data_status=data_status, + data=advertising_data[offset:offset + fragment_length])) offset += fragment_length diff --git a/test/LL/SEC/ADV/BV_11_C.py b/test/LL/SEC/ADV/BV_11_C.py index ff100c5..d250619 100644 --- a/test/LL/SEC/ADV/BV_11_C.py +++ b/test/LL/SEC/ADV/BV_11_C.py @@ -144,7 +144,7 @@ async def test(self): conn_supervision_timeout=0xc80)) connection_complete_evt = await self.expect_evt( - hci.LeEnhancedConnectionComplete( + hci.LeEnhancedConnectionCompleteV1( status=hci.ErrorCode.SUCCESS, connection_handle=self.Any, role=hci.Role.PERIPHERAL, diff --git a/test/async_manager_unittest.cc b/test/async_manager_unittest.cc index b461b9a..dd3f366 100644 --- a/test/async_manager_unittest.cc +++ b/test/async_manager_unittest.cc @@ -38,7 +38,7 @@ namespace rootcanal { class Event { - public: +public: void set(bool set = true) { std::unique_lock lk(m_); set_ = set; @@ -54,22 +54,20 @@ class Event { bool operator*() { return set_; } - private: +private: std::mutex m_; std::condition_variable cv_; bool set_{false}; }; class AsyncManagerSocketTest : public ::testing::Test { - public: +public: static const uint16_t kPort = 6111; static const size_t kBufferSize = 16; - bool CheckBufferEquals() { - return strcmp(server_buffer_, client_buffer_) == 0; - } + bool CheckBufferEquals() { return strcmp(server_buffer_, client_buffer_) == 0; } - protected: +protected: int StartServer() { struct sockaddr_in serv_addr = {}; int fd = socket(AF_INET, SOCK_STREAM, 0); @@ -79,8 +77,7 @@ class AsyncManagerSocketTest : public ::testing::Test { serv_addr.sin_addr.s_addr = INADDR_ANY; serv_addr.sin_port = htons(kPort); int reuse_flag = 1; - EXPECT_FALSE(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_flag, - sizeof(reuse_flag)) < 0); + EXPECT_FALSE(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse_flag, sizeof(reuse_flag)) < 0); EXPECT_FALSE(bind(fd, (sockaddr*)&serv_addr, sizeof(serv_addr)) < 0); listen(fd, 1); @@ -134,8 +131,8 @@ class AsyncManagerSocketTest : public ::testing::Test { async_manager_.WatchFdForNonBlockingReads(socket_fd_, [this](int fd) { connection_fd_ = AcceptConnection(fd); - async_manager_.WatchFdForNonBlockingReads( - connection_fd_, [this](int fd) { ReadIncomingMessage(fd); }); + async_manager_.WatchFdForNonBlockingReads(connection_fd_, + [this](int fd) { ReadIncomingMessage(fd); }); }); } @@ -161,8 +158,7 @@ class AsyncManagerSocketTest : public ::testing::Test { serv_addr.sin_addr.s_addr = *(reinterpret_cast(server->h_addr)); serv_addr.sin_port = htons(kPort); - int result = - connect(socket_cli_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); + int result = connect(socket_cli_fd, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); EXPECT_GE(result, 0) << strerror(errno); return socket_cli_fd; @@ -179,7 +175,7 @@ class AsyncManagerSocketTest : public ::testing::Test { ASSERT_GT(n, 0) << strerror(errno); } - protected: +protected: AsyncManager async_manager_; int socket_fd_; int connection_fd_; @@ -230,9 +226,9 @@ TEST_F(AsyncManagerSocketTest, CanUnsubscribeTaskFromWithinTask) { using namespace std::chrono_literals; async_manager_.ExecAsyncPeriodically(1, 1ms, 2ms, [&running, this]() { EXPECT_TRUE(async_manager_.CancelAsyncTask(1)) - << "We were scheduled, so cancel should return true"; + << "We were scheduled, so cancel should return true"; EXPECT_FALSE(async_manager_.CancelAsyncTask(1)) - << "We were not scheduled, so cancel should return false"; + << "We were not scheduled, so cancel should return false"; running.set(true); }); @@ -245,28 +241,26 @@ TEST_F(AsyncManagerSocketTest, UnsubScribeWaitsUntilCompletion) { std::atomic cancel_done = false; std::atomic task_complete = false; AsyncTaskId task_id = async_manager_.ExecAsyncPeriodically( - 1, 1ms, 2ms, [&running, &cancel_done, &task_complete]() { - // Let the other thread now we are in the callback.. - running.set(true); - // Wee bit of a hack that relies on timing.. - std::this_thread::sleep_for(20ms); - EXPECT_FALSE(cancel_done.load()) - << "Task cancellation did not wait for us to complete!"; - task_complete.store(true); - }); + 1, 1ms, 2ms, [&running, &cancel_done, &task_complete]() { + // Let the other thread now we are in the callback.. + running.set(true); + // Wee bit of a hack that relies on timing.. + std::this_thread::sleep_for(20ms); + EXPECT_FALSE(cancel_done.load()) + << "Task cancellation did not wait for us to complete!"; + task_complete.store(true); + }); EXPECT_TRUE(running.wait_for(100ms)); auto start = std::chrono::system_clock::now(); // There is a 20ms wait.. so we know that this should take some time. EXPECT_TRUE(async_manager_.CancelAsyncTask(task_id)) - << "We were scheduled, so cancel should return true"; + << "We were scheduled, so cancel should return true"; cancel_done.store(true); - EXPECT_TRUE(task_complete.load()) - << "We managed to cancel a task while it was not yet finished."; + EXPECT_TRUE(task_complete.load()) << "We managed to cancel a task while it was not yet finished."; auto end = std::chrono::system_clock::now(); - auto passed_ms = - std::chrono::duration_cast(end - start); + auto passed_ms = std::chrono::duration_cast(end - start); EXPECT_GT(passed_ms.count(), 10); } @@ -336,19 +330,21 @@ TEST_F(AsyncManagerSocketTest, NoEventsAfterUnsubscribe) { // Register fd events async_manager_.WatchFdForNonBlockingReads(slow_s_fd, [&](int /*fd*/) { - if (*inslow) return; + if (*inslow) { + return; + } time_slow_called = clock::now(); - printf("slow: %lld\n", - time_slow_called.time_since_epoch().count() % 10000); + printf("slow: %lld\n", time_slow_called.time_since_epoch().count() % 10000); inslow.set(); unblock_slow.wait_for(25ms); }); async_manager_.WatchFdForNonBlockingReads(fast_s_fd, [&](int /*fd*/) { - if (*infast) return; + if (*infast) { + return; + } time_fast_called = clock::now(); - printf("fast: %lld\n", - time_fast_called.time_since_epoch().count() % 10000); + printf("fast: %lld\n", time_fast_called.time_since_epoch().count() % 10000); infast.set(); }); @@ -360,8 +356,7 @@ TEST_F(AsyncManagerSocketTest, NoEventsAfterUnsubscribe) { if (inslow.wait_for(25ms)) { async_manager_.StopWatchingFileDescriptor(fast_s_fd); time_stopped_listening = clock::now(); - printf("stop: %lld\n", - time_stopped_listening.time_since_epoch().count() % 10000); + printf("stop: %lld\n", time_stopped_listening.time_since_epoch().count() % 10000); unblock_slow.set(); } @@ -408,7 +403,7 @@ TEST_F(AsyncManagerSocketTest, TestMultipleConnections) { } class AsyncManagerTest : public ::testing::Test { - public: +public: AsyncManager async_manager_; }; @@ -418,9 +413,8 @@ TEST_F(AsyncManagerTest, TestCancelTask) { AsyncUserId user1 = async_manager_.GetNextUserId(); bool task1_ran = false; bool* task1_ran_ptr = &task1_ran; - AsyncTaskId task1_id = - async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), - [task1_ran_ptr]() { *task1_ran_ptr = true; }); + AsyncTaskId task1_id = async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), + [task1_ran_ptr]() { *task1_ran_ptr = true; }); ASSERT_TRUE(async_manager_.CancelAsyncTask(task1_id)); ASSERT_FALSE(task1_ran); } @@ -429,14 +423,12 @@ TEST_F(AsyncManagerTest, TestCancelLongTask) { AsyncUserId user1 = async_manager_.GetNextUserId(); bool task1_ran = false; bool* task1_ran_ptr = &task1_ran; - AsyncTaskId task1_id = - async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), - [task1_ran_ptr]() { *task1_ran_ptr = true; }); + AsyncTaskId task1_id = async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), + [task1_ran_ptr]() { *task1_ran_ptr = true; }); bool task2_ran = false; bool* task2_ran_ptr = &task2_ran; - AsyncTaskId task2_id = - async_manager_.ExecAsync(user1, std::chrono::seconds(2), - [task2_ran_ptr]() { *task2_ran_ptr = true; }); + AsyncTaskId task2_id = async_manager_.ExecAsync(user1, std::chrono::seconds(2), + [task2_ran_ptr]() { *task2_ran_ptr = true; }); ASSERT_FALSE(task1_ran); ASSERT_FALSE(task2_ran); while (!task1_ran) @@ -459,21 +451,16 @@ TEST_F(AsyncManagerTest, TestCancelAsyncTasksFromUser) { bool* task4_ran_ptr = &task4_ran; bool task5_ran = false; bool* task5_ran_ptr = &task5_ran; - AsyncTaskId task1_id = - async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), - [task1_ran_ptr]() { *task1_ran_ptr = true; }); - AsyncTaskId task2_id = - async_manager_.ExecAsync(user1, std::chrono::seconds(2), - [task2_ran_ptr]() { *task2_ran_ptr = true; }); - AsyncTaskId task3_id = - async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), - [task3_ran_ptr]() { *task3_ran_ptr = true; }); - AsyncTaskId task4_id = - async_manager_.ExecAsync(user1, std::chrono::seconds(2), - [task4_ran_ptr]() { *task4_ran_ptr = true; }); - AsyncTaskId task5_id = - async_manager_.ExecAsync(user2, std::chrono::milliseconds(2), - [task5_ran_ptr]() { *task5_ran_ptr = true; }); + AsyncTaskId task1_id = async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), + [task1_ran_ptr]() { *task1_ran_ptr = true; }); + AsyncTaskId task2_id = async_manager_.ExecAsync(user1, std::chrono::seconds(2), + [task2_ran_ptr]() { *task2_ran_ptr = true; }); + AsyncTaskId task3_id = async_manager_.ExecAsync(user1, std::chrono::milliseconds(2), + [task3_ran_ptr]() { *task3_ran_ptr = true; }); + AsyncTaskId task4_id = async_manager_.ExecAsync(user1, std::chrono::seconds(2), + [task4_ran_ptr]() { *task4_ran_ptr = true; }); + AsyncTaskId task5_id = async_manager_.ExecAsync(user2, std::chrono::milliseconds(2), + [task5_ran_ptr]() { *task5_ran_ptr = true; }); ASSERT_FALSE(task1_ran); while (!task1_ran || !task3_ran || !task5_ran) ; diff --git a/test/controller/le/le_add_device_to_filter_accept_list_test.cc b/test/controller/le/le_add_device_to_filter_accept_list_test.cc index e999308..fe5b0c6 100644 --- a/test/controller/le/le_add_device_to_filter_accept_list_test.cc +++ b/test/controller/le/le_add_device_to_filter_accept_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeAddDeviceToFilterAcceptListTest : public ::testing::Test { - public: +public: LeAddDeviceToFilterAcceptListTest() { // Reduce the size of the filter accept list to simplify testing. properties_.le_filter_accept_list_size = 2; @@ -32,75 +32,73 @@ class LeAddDeviceToFilterAcceptListTest : public ::testing::Test { ~LeAddDeviceToFilterAcceptListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; TEST_F(LeAddDeviceToFilterAcceptListTest, Success) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::RANDOM, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::RANDOM, + Address{1}), ErrorCode::SUCCESS); } TEST_F(LeAddDeviceToFilterAcceptListTest, ListFull) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{2}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{2}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{3}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{3}), ErrorCode::MEMORY_CAPACITY_EXCEEDED); } TEST_F(LeAddDeviceToFilterAcceptListTest, ScanningActive) { - controller_.LeSetScanParameters( - LeScanType::PASSIVE, 0x400, 0x200, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY); + controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x400, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY); controller_.LeSetScanEnable(true, false); - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeAddDeviceToFilterAcceptListTest, LegacyAdvertisingActive) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::LISTED_SCAN), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::LISTED_SCAN), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeAddDeviceToFilterAcceptListTest, ExtendedAdvertisingActive) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::COMMAND_DISALLOWED); } diff --git a/test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc b/test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc index cade4d9..94212f8 100644 --- a/test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc +++ b/test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeAddDeviceToPeriodicAdvertiserListTest : public ::testing::Test { - public: +public: LeAddDeviceToPeriodicAdvertiserListTest() { // Reduce the size of the periodic advertiser list to simplify testing. properties_.le_periodic_advertiser_list_size = 3; @@ -32,7 +32,7 @@ class LeAddDeviceToPeriodicAdvertiserListTest : public ::testing::Test { ~LeAddDeviceToPeriodicAdvertiserListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,65 +40,55 @@ class LeAddDeviceToPeriodicAdvertiserListTest : public ::testing::Test { TEST_F(LeAddDeviceToPeriodicAdvertiserListTest, Success) { ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 2), + AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 2), ErrorCode::SUCCESS); } TEST_F(LeAddDeviceToPeriodicAdvertiserListTest, ListFull) { ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 2), + AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 2), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 3), + AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 3), ErrorCode::MEMORY_CAPACITY_EXCEEDED); } TEST_F(LeAddDeviceToPeriodicAdvertiserListTest, DuplicateEntry) { ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeAddDeviceToPeriodicAdvertiserListTest, CreateSyncPending) { ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{5}, false, 0x100, 0), + PeriodicAdvertisingOptions(), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{5}, false, + 0x100, 0), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::COMMAND_DISALLOWED); } diff --git a/test/controller/le/le_add_device_to_resolving_list_test.cc b/test/controller/le/le_add_device_to_resolving_list_test.cc index b2a44d4..050a70a 100644 --- a/test/controller/le/le_add_device_to_resolving_list_test.cc +++ b/test/controller/le/le_add_device_to_resolving_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeAddDeviceToResolvingListTest : public ::testing::Test { - public: +public: LeAddDeviceToResolvingListTest() { // Reduce the size of the resolving list to simplify testing. properties_.le_resolving_list_size = 2; @@ -32,7 +32,7 @@ class LeAddDeviceToResolvingListTest : public ::testing::Test { ~LeAddDeviceToResolvingListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,30 +40,30 @@ class LeAddDeviceToResolvingListTest : public ::testing::Test { TEST_F(LeAddDeviceToResolvingListTest, Success) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{2}, std::array{2}), + PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{2}, std::array{2}), ErrorCode::SUCCESS); } TEST_F(LeAddDeviceToResolvingListTest, ListFull) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{2}, - std::array{2}, std::array{2}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{2}, + std::array{2}, std::array{2}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{3}, - std::array{3}, std::array{3}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{3}, + std::array{3}, std::array{3}), ErrorCode::MEMORY_CAPACITY_EXCEEDED); } @@ -72,8 +72,8 @@ TEST_F(LeAddDeviceToResolvingListTest, ScanningActive) { controller_.LeSetScanEnable(true, false); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::COMMAND_DISALLOWED); } @@ -82,63 +82,62 @@ TEST_F(LeAddDeviceToResolvingListTest, LegacyAdvertisingActive) { ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeAddDeviceToResolvingListTest, ExtendedAdvertisingActive) { ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeAddDeviceToResolvingListTest, PeerAddressDuplicate) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{2}, std::array{2}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{2}, std::array{2}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeAddDeviceToResolvingListTest, PeerIrkDuplicate) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeAddDeviceToResolvingListTest, EmptyPeerIrkDuplicate) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{0}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{0}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{0}, std::array{1}), + PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{0}, std::array{1}), ErrorCode::SUCCESS); } diff --git a/test/controller/le/le_clear_filter_accept_list_test.cc b/test/controller/le/le_clear_filter_accept_list_test.cc index 30eb1b0..b7d8fb8 100644 --- a/test/controller/le/le_clear_filter_accept_list_test.cc +++ b/test/controller/le/le_clear_filter_accept_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeClearFilterAcceptListTest : public ::testing::Test { - public: +public: LeClearFilterAcceptListTest() { // Reduce the size of the filter accept list to simplify testing. properties_.le_filter_accept_list_size = 2; @@ -32,69 +32,64 @@ class LeClearFilterAcceptListTest : public ::testing::Test { ~LeClearFilterAcceptListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; TEST_F(LeClearFilterAcceptListTest, Success) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeClearFilterAcceptList(), ErrorCode::SUCCESS); } TEST_F(LeClearFilterAcceptListTest, ScanningActive) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); - controller_.LeSetScanParameters( - LeScanType::PASSIVE, 0x400, 0x200, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY); + controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x400, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY); controller_.LeSetScanEnable(true, false); - ASSERT_EQ(controller_.LeClearFilterAcceptList(), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeClearFilterAcceptList(), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeClearFilterAcceptListTest, LegacyAdvertisingActive) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::LISTED_SCAN), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::LISTED_SCAN), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeClearFilterAcceptList(), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeClearFilterAcceptList(), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeClearFilterAcceptListTest, ExtendedAdvertisingActive) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeClearFilterAcceptList(), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeClearFilterAcceptList(), ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/test/controller/le/le_clear_periodic_advertiser_list_test.cc b/test/controller/le/le_clear_periodic_advertiser_list_test.cc index 9d4f347..a2e7d50 100644 --- a/test/controller/le/le_clear_periodic_advertiser_list_test.cc +++ b/test/controller/le/le_clear_periodic_advertiser_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeClearPeriodicAdvertiserListTest : public ::testing::Test { - public: +public: LeClearPeriodicAdvertiserListTest() { // Reduce the size of the periodic advertiser list to simplify testing. properties_.le_periodic_advertiser_list_size = 1; @@ -32,7 +32,7 @@ class LeClearPeriodicAdvertiserListTest : public ::testing::Test { ~LeClearPeriodicAdvertiserListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,27 +40,24 @@ class LeClearPeriodicAdvertiserListTest : public ::testing::Test { TEST_F(LeClearPeriodicAdvertiserListTest, Success) { ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeClearPeriodicAdvertiserList(), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); } TEST_F(LeClearPeriodicAdvertiserListTest, CreateSyncPending) { ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{5}, false, 0x100, 0), + PeriodicAdvertisingOptions(), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{5}, false, + 0x100, 0), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeClearPeriodicAdvertiserList(), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeClearPeriodicAdvertiserList(), ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/test/controller/le/le_clear_resolving_list_test.cc b/test/controller/le/le_clear_resolving_list_test.cc index ea37d1c..98914a5 100644 --- a/test/controller/le/le_clear_resolving_list_test.cc +++ b/test/controller/le/le_clear_resolving_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeClearResolvingListTest : public ::testing::Test { - public: +public: LeClearResolvingListTest() { // Reduce the size of the resolving list to simplify testing. properties_.le_resolving_list_size = 2; @@ -32,7 +32,7 @@ class LeClearResolvingListTest : public ::testing::Test { ~LeClearResolvingListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,8 +40,8 @@ class LeClearResolvingListTest : public ::testing::Test { TEST_F(LeClearResolvingListTest, Success) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeClearResolvingList(), ErrorCode::SUCCESS); @@ -49,8 +49,8 @@ TEST_F(LeClearResolvingListTest, Success) { TEST_F(LeClearResolvingListTest, ScanningActive) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); @@ -61,8 +61,8 @@ TEST_F(LeClearResolvingListTest, ScanningActive) { TEST_F(LeClearResolvingListTest, LegacyAdvertisingActive) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); @@ -73,20 +73,19 @@ TEST_F(LeClearResolvingListTest, LegacyAdvertisingActive) { TEST_F(LeClearResolvingListTest, ExtendedAdvertisingActive) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeClearResolvingList(), ErrorCode::COMMAND_DISALLOWED); diff --git a/test/controller/le/le_create_connection_cancel_test.cc b/test/controller/le/le_create_connection_cancel_test.cc index 995186e..d8d16e8 100644 --- a/test/controller/le/le_create_connection_cancel_test.cc +++ b/test/controller/le/le_create_connection_cancel_test.cc @@ -24,11 +24,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeCreateConnectionCancelTest : public ::testing::Test { - public: +public: LeCreateConnectionCancelTest() = default; ~LeCreateConnectionCancelTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -36,29 +36,25 @@ class LeCreateConnectionCancelTest : public ::testing::Test { TEST_F(LeCreateConnectionCancelTest, CancelLegacyConnection) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::SUCCESS); } TEST_F(LeCreateConnectionCancelTest, CancelExtendedConnection) { - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::SUCCESS); } TEST_F(LeCreateConnectionCancelTest, NoPendingConnection) { - ASSERT_EQ(controller_.LeCreateConnectionCancel(), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeCreateConnectionCancel(), ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/test/controller/le/le_create_connection_test.cc b/test/controller/le/le_create_connection_test.cc index 0c68ea9..866c493 100644 --- a/test/controller/le/le_create_connection_test.cc +++ b/test/controller/le/le_create_connection_test.cc @@ -23,11 +23,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeCreateConnectionTest : public ::testing::Test { - public: +public: LeCreateConnectionTest() = default; ~LeCreateConnectionTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -35,170 +35,151 @@ class LeCreateConnectionTest : public ::testing::Test { TEST_F(LeCreateConnectionTest, ConnectUsingPublicAddress) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::SUCCESS); } TEST_F(LeCreateConnectionTest, ConnectUsingRandomAddress) { ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::RANDOM_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::RANDOM_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::SUCCESS); } TEST_F(LeCreateConnectionTest, ConnectUsingResolvableAddress) { ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, 0x100, 0x200, - 0x010, 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0), ErrorCode::SUCCESS); } TEST_F(LeCreateConnectionTest, InitiatingActive) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{2}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{2}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeCreateConnectionTest, InvalidScanInterval) { ASSERT_EQ(controller_.LeCreateConnection( - 0x3, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x3, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x4001, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x4001, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeCreateConnectionTest, InvalidScanWindow) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x3, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x3, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x4001, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x4001, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x100, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x100, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeCreateConnectionTest, InvalidConnectionInterval) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x5, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x5, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x0c81, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x0c81, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x5, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x5, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x0c81, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x0c81, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x4001, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x100, 0x010, - 0x0c80, 0x0, 0x0), + 0x4001, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x200, 0x100, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeCreateConnectionTest, InvalidMaxLatency) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x01f4, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x01f4, 0x0c80, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeCreateConnectionTest, InvalidSupervisionTimeout) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x9, - 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x9, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c81, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c81, 0x0, 0x0), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x1f3, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, 0x100, 0x200, 0x1f3, 0x0c80, 0x0, 0x0), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeCreateConnectionTest, NoRandomAddress) { ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::RANDOM_DEVICE_ADDRESS, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::RANDOM_DEVICE_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); ASSERT_EQ(controller_.LeCreateConnection( - 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, 0x100, 0x200, - 0x010, 0x0c80, 0x0, 0x0), + 0x200, 0x200, InitiatorFilterPolicy::USE_PEER_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } diff --git a/test/controller/le/le_extended_create_connection_test.cc b/test/controller/le/le_extended_create_connection_test.cc index c5f4f63..0728271 100644 --- a/test/controller/le/le_extended_create_connection_test.cc +++ b/test/controller/le/le_extended_create_connection_test.cc @@ -26,265 +26,217 @@ namespace rootcanal { using namespace bluetooth::hci; class LeExtendedCreateConnectionTest : public ::testing::Test { - public: +public: LeExtendedCreateConnectionTest() = default; ~LeExtendedCreateConnectionTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; TEST_F(LeExtendedCreateConnectionTest, ConnectUsingPublicAddress) { - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::SUCCESS); } TEST_F(LeExtendedCreateConnectionTest, ConnectUsingRandomAddress) { ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::RANDOM_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::RANDOM_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::SUCCESS); } TEST_F(LeExtendedCreateConnectionTest, ConnectUsingResolvableAddress) { ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::SUCCESS); } TEST_F(LeExtendedCreateConnectionTest, InitiatingActive) { - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeExtendedCreateConnectionTest, NoPhy) { ASSERT_EQ(controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - 0x0, {}), + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x0, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeExtendedCreateConnectionTest, ReservedPhy) { - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x8, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x8, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeExtendedCreateConnectionTest, InvalidPhyParameters) { ASSERT_EQ(controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, - 0x1, {}), + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0), - MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0), + MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeExtendedCreateConnectionTest, InvalidScanInterval) { ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x3, 0x200, 0x100, 0x200, 0x010, 0x0c80, - 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x3, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x4001, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x4001, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeExtendedCreateConnectionTest, InvalidScanWindow) { ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x3, 0x100, 0x200, 0x010, 0x0c80, - 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x3, 0x100, 0x200, 0x010, 0x0c80, 0x0, 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x4001, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x4001, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x100, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x100, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeExtendedCreateConnectionTest, InvalidConnectionInterval) { ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x5, 0x200, 0x010, 0x0c80, - 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x5, 0x200, 0x010, 0x0c80, 0x0, 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x0c81, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x0c81, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x5, 0x010, 0x0c80, - 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x5, 0x010, 0x0c80, 0x0, 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x0c81, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x0c81, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x100, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x200, 0x100, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeExtendedCreateConnectionTest, InvalidMaxLatency) { - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x01f4, - 0x0c80, 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x01f4, 0x0c80, 0x0, + 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeExtendedCreateConnectionTest, InvalidSupervisionTimeout) { ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x9, - 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x9, 0x0, 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c81, 0x0, 0x0)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c81, 0x0, + 0x0)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x1f3, - 0x0c80, 0x0, 0x0)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x1f3, 0x0c80, 0x0, + 0x0)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeExtendedCreateConnectionTest, NoRandomAddress) { - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::RANDOM_DEVICE_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, OwnAddressType::RANDOM_DEVICE_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ( - controller_.LeExtendedCreateConnection( - InitiatorFilterPolicy::USE_PEER_ADDRESS, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, - {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, - 0x0c80, 0x0, 0x0)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeExtendedCreateConnection( + InitiatorFilterPolicy::USE_PEER_ADDRESS, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + AddressWithType{Address{1}, AddressType::PUBLIC_DEVICE_ADDRESS}, 0x1, + {MakeInitiatingPhyParameters(0x200, 0x200, 0x100, 0x200, 0x010, 0x0c80, 0x0, + 0x0)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } } // namespace rootcanal diff --git a/test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc b/test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc index 80f353d..ad8924c 100644 --- a/test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc +++ b/test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc @@ -23,11 +23,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LePeriodicAdvertisingCreateSyncCancelTest : public ::testing::Test { - public: +public: LePeriodicAdvertisingCreateSyncCancelTest() = default; ~LePeriodicAdvertisingCreateSyncCancelTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -35,18 +35,16 @@ class LePeriodicAdvertisingCreateSyncCancelTest : public ::testing::Test { TEST_F(LePeriodicAdvertisingCreateSyncCancelTest, Success) { ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(false, false, false), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 0, 0x100, 0), + PeriodicAdvertisingOptions(false, false, false), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 0, 0x100, + 0), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSyncCancel(), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSyncCancel(), ErrorCode::SUCCESS); } TEST_F(LePeriodicAdvertisingCreateSyncCancelTest, CreateSyncNotPending) { - ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSyncCancel(), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSyncCancel(), ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/test/controller/le/le_periodic_advertising_create_sync_test.cc b/test/controller/le/le_periodic_advertising_create_sync_test.cc index bf3ad7a..0ee36cd 100644 --- a/test/controller/le/le_periodic_advertising_create_sync_test.cc +++ b/test/controller/le/le_periodic_advertising_create_sync_test.cc @@ -23,11 +23,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LePeriodicAdvertisingCreateSyncTest : public ::testing::Test { - public: +public: LePeriodicAdvertisingCreateSyncTest() = default; ~LePeriodicAdvertisingCreateSyncTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -35,54 +35,50 @@ class LePeriodicAdvertisingCreateSyncTest : public ::testing::Test { TEST_F(LePeriodicAdvertisingCreateSyncTest, CreateUsingPublicAddress) { ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(false, false, false), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 0, 0x100, 0), + PeriodicAdvertisingOptions(false, false, false), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 0, 0x100, + 0), ErrorCode::SUCCESS); } TEST_F(LePeriodicAdvertisingCreateSyncTest, CreateUsingPeriodicAdvertiserList) { ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(true, false, false), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0, 0x100, 0), + PeriodicAdvertisingOptions(true, false, false), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0, + 0x100, 0), ErrorCode::SUCCESS); } TEST_F(LePeriodicAdvertisingCreateSyncTest, CreateSyncPending) { ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(false, false, false), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 0, 0x100, 0), + PeriodicAdvertisingOptions(false, false, false), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 0, 0x100, + 0), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(true, false, false), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0, 0x100, 0), + PeriodicAdvertisingOptions(true, false, false), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0, + 0x100, 0), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LePeriodicAdvertisingCreateSyncTest, InvalidSyncCteMask) { - ASSERT_EQ( - controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(false, false, false), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - 0, 0x100, - static_cast( - PeriodicSyncCteType::AVOID_AOA_CONSTANT_TONE_EXTENSION) | - static_cast( - PeriodicSyncCteType:: - AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_ONE_US_SLOTS) | - static_cast( - PeriodicSyncCteType:: - AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_TWO_US_SLOTS) | - static_cast( - PeriodicSyncCteType:: - AVOID_TYPE_THREE_CONSTANT_TONE_EXTENSION) | - static_cast( - PeriodicSyncCteType::AVOID_NO_CONSTANT_TONE_EXTENSION)), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( + PeriodicAdvertisingOptions(false, false, false), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 0, 0x100, + static_cast(PeriodicSyncCteType::AVOID_AOA_CONSTANT_TONE_EXTENSION) | + static_cast( + PeriodicSyncCteType:: + AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_ONE_US_SLOTS) | + static_cast( + PeriodicSyncCteType:: + AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_TWO_US_SLOTS) | + static_cast( + PeriodicSyncCteType::AVOID_TYPE_THREE_CONSTANT_TONE_EXTENSION) | + static_cast( + PeriodicSyncCteType::AVOID_NO_CONSTANT_TONE_EXTENSION)), + ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/test/controller/le/le_remove_device_from_filter_accept_list_test.cc b/test/controller/le/le_remove_device_from_filter_accept_list_test.cc index b3e41b6..5a05c59 100644 --- a/test/controller/le/le_remove_device_from_filter_accept_list_test.cc +++ b/test/controller/le/le_remove_device_from_filter_accept_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeRemoveDeviceFromFilterAcceptListTest : public ::testing::Test { - public: +public: LeRemoveDeviceFromFilterAcceptListTest() { // Reduce the size of the resolving list to simplify testing. properties_.le_resolving_list_size = 2; @@ -32,83 +32,81 @@ class LeRemoveDeviceFromFilterAcceptListTest : public ::testing::Test { ~LeRemoveDeviceFromFilterAcceptListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; TEST_F(LeRemoveDeviceFromFilterAcceptListTest, Success) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); } TEST_F(LeRemoveDeviceFromFilterAcceptListTest, NotFound) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList( - FilterAcceptListAddressType::RANDOM, Address{1}), + ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList(FilterAcceptListAddressType::RANDOM, + Address{1}), ErrorCode::SUCCESS); } TEST_F(LeRemoveDeviceFromFilterAcceptListTest, ScanningActive) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); - controller_.LeSetScanParameters( - LeScanType::PASSIVE, 0x400, 0x200, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY); + controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x400, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::FILTER_ACCEPT_LIST_ONLY); controller_.LeSetScanEnable(true, false); - ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeRemoveDeviceFromFilterAcceptListTest, LegacyAdvertisingActive) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::LISTED_SCAN), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::LISTED_SCAN), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeRemoveDeviceFromFilterAcceptListTest, ExtendedAdvertisingActive) { - ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeAddDeviceToFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList( - FilterAcceptListAddressType::PUBLIC, Address{1}), + ASSERT_EQ(controller_.LeRemoveDeviceFromFilterAcceptList(FilterAcceptListAddressType::PUBLIC, + Address{1}), ErrorCode::COMMAND_DISALLOWED); } diff --git a/test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc b/test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc index bb362ce..86edd3c 100644 --- a/test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc +++ b/test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeRemoveDeviceFromPeriodicAdvertiserListTest : public ::testing::Test { - public: +public: LeRemoveDeviceFromPeriodicAdvertiserListTest() { // Reduce the size of the periodic advertiser list to simplify testing. properties_.le_periodic_advertiser_list_size = 3; @@ -32,7 +32,7 @@ class LeRemoveDeviceFromPeriodicAdvertiserListTest : public ::testing::Test { ~LeRemoveDeviceFromPeriodicAdvertiserListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,43 +40,37 @@ class LeRemoveDeviceFromPeriodicAdvertiserListTest : public ::testing::Test { TEST_F(LeRemoveDeviceFromPeriodicAdvertiserListTest, Success) { ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeRemoveDeviceFromPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); } TEST_F(LeRemoveDeviceFromPeriodicAdvertiserListTest, NotFound) { ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeRemoveDeviceFromPeriodicAdvertiserList( - AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); } TEST_F(LeRemoveDeviceFromPeriodicAdvertiserListTest, CreateSyncPending) { ASSERT_EQ(controller_.LeAddDeviceToPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LePeriodicAdvertisingCreateSync( - PeriodicAdvertisingOptions(), 0, - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{5}, false, 0x100, 0), + PeriodicAdvertisingOptions(), 0, + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{5}, false, + 0x100, 0), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeRemoveDeviceFromPeriodicAdvertiserList( - AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address{1}, 1), + AdvertiserAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 1), ErrorCode::COMMAND_DISALLOWED); } diff --git a/test/controller/le/le_remove_device_from_resolving_list_test.cc b/test/controller/le/le_remove_device_from_resolving_list_test.cc index 2f9d9f5..9676514 100644 --- a/test/controller/le/le_remove_device_from_resolving_list_test.cc +++ b/test/controller/le/le_remove_device_from_resolving_list_test.cc @@ -24,7 +24,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeRemoveDeviceFromResolvingListTest : public ::testing::Test { - public: +public: LeRemoveDeviceFromResolvingListTest() { // Reduce the size of the resolving list to simplify testing. properties_.le_resolving_list_size = 2; @@ -32,7 +32,7 @@ class LeRemoveDeviceFromResolvingListTest : public ::testing::Test { ~LeRemoveDeviceFromResolvingListTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,74 +40,73 @@ class LeRemoveDeviceFromResolvingListTest : public ::testing::Test { TEST_F(LeRemoveDeviceFromResolvingListTest, Success) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeRemoveDeviceFromResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), ErrorCode::SUCCESS); } TEST_F(LeRemoveDeviceFromResolvingListTest, NotFound) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeRemoveDeviceFromResolvingList( - PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), + PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), ErrorCode::UNKNOWN_CONNECTION); } TEST_F(LeRemoveDeviceFromResolvingListTest, ScanningActive) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); controller_.LeSetScanEnable(true, false); ASSERT_EQ(controller_.LeRemoveDeviceFromResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeRemoveDeviceFromResolvingListTest, LegacyAdvertisingActive) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeRemoveDeviceFromResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeRemoveDeviceFromResolvingListTest, ExtendedAdvertisingActive) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeRemoveDeviceFromResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}), ErrorCode::COMMAND_DISALLOWED); } diff --git a/test/controller/le/le_scanning_filter_duplicates_test.cc b/test/controller/le/le_scanning_filter_duplicates_test.cc index 6ef5a2b..0c4fbab 100644 --- a/test/controller/le/le_scanning_filter_duplicates_test.cc +++ b/test/controller/le/le_scanning_filter_duplicates_test.cc @@ -32,7 +32,7 @@ namespace rootcanal { using namespace bluetooth::hci; class LeScanningFilterDuplicates : public ::testing::Test { - public: +public: LeScanningFilterDuplicates() {} ~LeScanningFilterDuplicates() override = default; @@ -49,80 +49,69 @@ class LeScanningFilterDuplicates : public ::testing::Test { // Set event mask to receive (extended) Advertising Reports controller_.SetEventMask(to_mask(EventCode::LE_META_EVENT)); - controller_.SetLeEventMask( - to_mask(SubeventCode::ADVERTISING_REPORT) | - to_mask(SubeventCode::EXTENDED_ADVERTISING_REPORT) | - to_mask(SubeventCode::DIRECTED_ADVERTISING_REPORT)); + controller_.SetLeEventMask(to_mask(SubeventCode::LE_ADVERTISING_REPORT) | + to_mask(SubeventCode::LE_EXTENDED_ADVERTISING_REPORT) | + to_mask(SubeventCode::LE_DIRECTED_ADVERTISING_REPORT)); } void StartScan(FilterDuplicates filter_duplicates) { - ASSERT_EQ(ErrorCode::SUCCESS, controller_.LeSetScanParameters( - LeScanType::ACTIVE, 0x4, 0x4, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL)); ASSERT_EQ(ErrorCode::SUCCESS, - controller_.LeSetScanEnable( - true, filter_duplicates == FilterDuplicates::ENABLED)); + controller_.LeSetScanParameters(LeScanType::ACTIVE, 0x4, 0x4, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL)); + ASSERT_EQ(ErrorCode::SUCCESS, + controller_.LeSetScanEnable(true, filter_duplicates == FilterDuplicates::ENABLED)); } - void StopScan(void) { - ASSERT_EQ(ErrorCode::SUCCESS, controller_.LeSetScanEnable(false, false)); - } + void StopScan(void) { ASSERT_EQ(ErrorCode::SUCCESS, controller_.LeSetScanEnable(false, false)); } - void StartExtendedScan(FilterDuplicates filter_duplicates, - uint16_t duration = 0, uint16_t period = 0) { + void StartExtendedScan(FilterDuplicates filter_duplicates, uint16_t duration = 0, + uint16_t period = 0) { bluetooth::hci::ScanningPhyParameters param; param.le_scan_type_ = LeScanType::ACTIVE; param.le_scan_interval_ = 0x4; param.le_scan_window_ = 0x4; + ASSERT_EQ(ErrorCode::SUCCESS, controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL, 0x1, {param})); ASSERT_EQ(ErrorCode::SUCCESS, - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, {param})); - ASSERT_EQ(ErrorCode::SUCCESS, - controller_.LeSetExtendedScanEnable(true, filter_duplicates, - duration, period)); + controller_.LeSetExtendedScanEnable(true, filter_duplicates, duration, period)); } void StopExtendedScan(void) { - ASSERT_EQ(ErrorCode::SUCCESS, controller_.LeSetExtendedScanEnable( - false, FilterDuplicates::DISABLED, 0, 0)); + ASSERT_EQ(ErrorCode::SUCCESS, + controller_.LeSetExtendedScanEnable(false, FilterDuplicates::DISABLED, 0, 0)); } /// Helper for building ScanResponse packets - static model::packets::LinkLayerPacketView LeScanResponse( - std::vector const data = {}) { + static model::packets::LinkLayerPacketView LeScanResponse(std::vector const data = {}) { return FromBuilder(model::packets::LeScanResponseBuilder::Create( - Address::kEmpty, Address::kEmpty, model::packets::AddressType::PUBLIC, - data)); + Address::kEmpty, Address::kEmpty, model::packets::AddressType::PUBLIC, data)); } /// Helper for building LeLegacyAdvertisingPdu packets static model::packets::LinkLayerPacketView LeLegacyAdvertisingPdu( - std::vector const data = {}) { + std::vector const data = {}) { return FromBuilder(model::packets::LeLegacyAdvertisingPduBuilder::Create( - Address::kEmpty, Address::kEmpty, model::packets::AddressType::PUBLIC, - model::packets::AddressType::PUBLIC, - model::packets::LegacyAdvertisingType::ADV_IND, data)); + Address::kEmpty, Address::kEmpty, model::packets::AddressType::PUBLIC, + model::packets::AddressType::PUBLIC, model::packets::LegacyAdvertisingType::ADV_IND, + data)); } /// Helper for building LeExtendedAdvertisingPdu packets static model::packets::LinkLayerPacketView LeExtendedAdvertisingPdu( - std::vector const data = {}) { + std::vector const data = {}) { return FromBuilder(model::packets::LeExtendedAdvertisingPduBuilder::Create( - Address::kEmpty, Address::kEmpty, model::packets::AddressType::PUBLIC, - model::packets::AddressType::PUBLIC, 0, 1, 0, 0, 0, - model::packets::PhyType::LE_1M, model::packets::PhyType::LE_1M, 0, - data)); + Address::kEmpty, Address::kEmpty, model::packets::AddressType::PUBLIC, + model::packets::AddressType::PUBLIC, 0, 1, 0, 0, 0, model::packets::PhyType::LE_1M, + model::packets::PhyType::LE_1M, 0, data)); } static model::packets::LinkLayerPacketView FromBuilder( - std::unique_ptr builder) { - auto data = - std::make_shared>(builder->SerializeToBytes()); - return model::packets::LinkLayerPacketView::Create( - pdl::packet::slice(data)); + std::unique_ptr builder) { + auto data = std::make_shared>(builder->SerializeToBytes()); + return model::packets::LinkLayerPacketView::Create(pdl::packet::slice(data)); } enum Filtered { @@ -146,20 +135,19 @@ class LeScanningFilterDuplicates : public ::testing::Test { return kReported; } - protected: +protected: Address address_{}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; static unsigned event_listener_called_; - private: +private: static void event_listener_(std::shared_ptr /* event */) { event_listener_called_++; } - static void remote_listener_( - std::shared_ptr /* packet */, - Phy::Type /* phy */, int8_t /* tx_power */) {} + static void remote_listener_(std::shared_ptr /* packet */, + Phy::Type /* phy */, int8_t /* tx_power */) {} }; unsigned LeScanningFilterDuplicates::event_listener_called_ = 0; @@ -226,8 +214,7 @@ TEST_F(LeScanningFilterDuplicates, ExtendedAdvertisingPduDuringExtendedScan) { ASSERT_EQ(kFiltered, SendPacketAndCheck(LeExtendedAdvertisingPdu({0, 1}))); } -TEST_F(LeScanningFilterDuplicates, - LeScanResponseToLegacyAdvertisingDuringLegacyScan) { +TEST_F(LeScanningFilterDuplicates, LeScanResponseToLegacyAdvertisingDuringLegacyScan) { StopScan(); SendPacket(LeLegacyAdvertisingPdu()); ASSERT_EQ(kFiltered, SendPacketAndCheck(LeScanResponse())); @@ -256,8 +243,7 @@ TEST_F(LeScanningFilterDuplicates, ASSERT_EQ(kFiltered, SendPacketAndCheck(LeScanResponse({0, 1}))); } -TEST_F(LeScanningFilterDuplicates, - LeScanResponseToLegacyAdvertisingDuringExtendedScan) { +TEST_F(LeScanningFilterDuplicates, LeScanResponseToLegacyAdvertisingDuringExtendedScan) { StopExtendedScan(); SendPacket(LeLegacyAdvertisingPdu()); ASSERT_EQ(kFiltered, SendPacketAndCheck(LeScanResponse())); @@ -286,8 +272,7 @@ TEST_F(LeScanningFilterDuplicates, ASSERT_EQ(kFiltered, SendPacketAndCheck(LeScanResponse({0, 1}))); } -TEST_F(LeScanningFilterDuplicates, - LeScanResponseToExtendedAdvertisingDuringLegacyScan) { +TEST_F(LeScanningFilterDuplicates, LeScanResponseToExtendedAdvertisingDuringLegacyScan) { StopScan(); SendPacket(LeExtendedAdvertisingPdu()); ASSERT_EQ(kFiltered, SendPacketAndCheck(LeScanResponse())); @@ -299,8 +284,7 @@ TEST_F(LeScanningFilterDuplicates, ASSERT_EQ(kFiltered, SendPacketAndCheck(LeScanResponse())); } -TEST_F(LeScanningFilterDuplicates, - LeScanResponseToExtendedAdvertisingDuringExtendedScan) { +TEST_F(LeScanningFilterDuplicates, LeScanResponseToExtendedAdvertisingDuringExtendedScan) { StopExtendedScan(); SendPacket(LeExtendedAdvertisingPdu()); ASSERT_EQ(kFiltered, SendPacketAndCheck(LeScanResponse())); diff --git a/test/controller/le/le_set_address_resolution_enable_test.cc b/test/controller/le/le_set_address_resolution_enable_test.cc index edfc6b8..00546f4 100644 --- a/test/controller/le/le_set_address_resolution_enable_test.cc +++ b/test/controller/le/le_set_address_resolution_enable_test.cc @@ -24,11 +24,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetAddressResolutionEnableTest : public ::testing::Test { - public: +public: LeSetAddressResolutionEnableTest() = default; ~LeSetAddressResolutionEnableTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -36,42 +36,34 @@ class LeSetAddressResolutionEnableTest : public ::testing::Test { TEST_F(LeSetAddressResolutionEnableTest, Success) { ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::SUCCESS); } TEST_F(LeSetAddressResolutionEnableTest, ScanningActive) { controller_.LeSetScanEnable(true, false); - ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), - ErrorCode::COMMAND_DISALLOWED); - ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetAddressResolutionEnableTest, LegacyAdvertisingActive) { ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), - ErrorCode::COMMAND_DISALLOWED); - ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetAddressResolutionEnableTest, ExtendedAdvertisingActive) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), - ErrorCode::COMMAND_DISALLOWED); - ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetAddressResolutionEnable(false), ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/test/controller/le/le_set_advertising_enable_test.cc b/test/controller/le/le_set_advertising_enable_test.cc index d9ffb2a..435bdd6 100644 --- a/test/controller/le/le_set_advertising_enable_test.cc +++ b/test/controller/le/le_set_advertising_enable_test.cc @@ -23,11 +23,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetAdvertisingEnableTest : public ::testing::Test { - public: +public: LeSetAdvertisingEnableTest() = default; ~LeSetAdvertisingEnableTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -35,20 +35,18 @@ class LeSetAdvertisingEnableTest : public ::testing::Test { TEST_F(LeSetAdvertisingEnableTest, EnableUsingPublicAddress) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); } TEST_F(LeSetAdvertisingEnableTest, EnableUsingRandomAddress) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::RANDOM_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::RANDOM_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); @@ -56,14 +54,14 @@ TEST_F(LeSetAdvertisingEnableTest, EnableUsingRandomAddress) { TEST_F(LeSetAdvertisingEnableTest, EnableUsingResolvableAddress) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); // Note: the command will fail if the peer address is not in the resolvable @@ -78,27 +76,24 @@ TEST_F(LeSetAdvertisingEnableTest, Disable) { TEST_F(LeSetAdvertisingEnableTest, NoRandomAddress) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::RANDOM_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::RANDOM_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetAdvertisingEnableTest, NoResolvableOrRandomAddress) { ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } } // namespace rootcanal diff --git a/test/controller/le/le_set_advertising_parameters_test.cc b/test/controller/le/le_set_advertising_parameters_test.cc index 56f85bc..1bc71fa 100644 --- a/test/controller/le/le_set_advertising_parameters_test.cc +++ b/test/controller/le/le_set_advertising_parameters_test.cc @@ -23,11 +23,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetAdvertisingParametersTest : public ::testing::Test { - public: +public: LeSetAdvertisingParametersTest() = default; ~LeSetAdvertisingParametersTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -35,10 +35,9 @@ class LeSetAdvertisingParametersTest : public ::testing::Test { TEST_F(LeSetAdvertisingParametersTest, Success) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::SUCCESS); } @@ -46,56 +45,49 @@ TEST_F(LeSetAdvertisingParametersTest, AdvertisingActive) { ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetAdvertisingParametersTest, InvalidChannelMap) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x0, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x0, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetAdvertisingParametersTest, InvalidAdvertisingInterval) { ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x0, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x0, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x4001, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x4001, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0800, 0x4001, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0800, 0x4001, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeSetAdvertisingParameters( - 0x0900, 0x0800, AdvertisingType::ADV_IND, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, 0x7, AdvertisingFilterPolicy::ALL_DEVICES), + 0x0900, 0x0800, AdvertisingType::ADV_IND, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, 0x7, + AdvertisingFilterPolicy::ALL_DEVICES), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } diff --git a/test/controller/le/le_set_extended_advertising_data_test.cc b/test/controller/le/le_set_extended_advertising_data_test.cc index ed27f12..2ffa673 100644 --- a/test/controller/le/le_set_extended_advertising_data_test.cc +++ b/test/controller/le/le_set_extended_advertising_data_test.cc @@ -24,15 +24,15 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetExtendedAdvertisingDataTest : public ::testing::Test { - public: +public: LeSetExtendedAdvertisingDataTest() { // Reduce the number of advertising sets to simplify testing. properties_.le_num_supported_advertising_sets = 2; properties_.le_max_advertising_data_length = 300; - }; + } ~LeSetExtendedAdvertisingDataTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,209 +40,199 @@ class LeSetExtendedAdvertisingDataTest : public ::testing::Test { TEST_F(LeSetExtendedAdvertisingDataTest, Complete) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingDataTest, Unchanged) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::UNCHANGED_DATA, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::UNCHANGED_DATA, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingDataTest, Fragmented) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; std::vector intermediate_advertising_data_fragment = {4, 5, 6}; std::vector last_advertising_data_fragment = {7, 8, 9}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::INTERMEDIATE_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - intermediate_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::INTERMEDIATE_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + intermediate_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - last_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::LAST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + last_advertising_data_fragment), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingDataTest, UnknownAdvertisingHandle) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 1, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(1, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); } TEST_F(LeSetExtendedAdvertisingDataTest, UnexpectedAdvertisingData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingDataTest, IncompleteLegacyAdvertisingData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_advertising_data_fragment), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingDataTest, InvalidLegacyAdvertisingData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; advertising_data.resize(32); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingDataTest, UnchangedWhenDisabled) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::UNCHANGED_DATA, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::UNCHANGED_DATA, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingDataTest, UnchangedWhenAdvertisingDataEmpty) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::UNCHANGED_DATA, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::UNCHANGED_DATA, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingDataTest, UnchangedWhenUsingLegacyAdvertising) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::UNCHANGED_DATA, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::UNCHANGED_DATA, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingDataTest, EmptyAdvertisingDataFragment) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; @@ -250,96 +240,85 @@ TEST_F(LeSetExtendedAdvertisingDataTest, EmptyAdvertisingDataFragment) { std::vector last_advertising_data_fragment = {7, 8, 9}; ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::FIRST_FRAGMENT, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::INTERMEDIATE_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ( + controller_.LeSetExtendedAdvertisingData(0, Operation::INTERMEDIATE_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::INTERMEDIATE_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - intermediate_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::INTERMEDIATE_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + intermediate_advertising_data_fragment), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::LAST_FRAGMENT, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - last_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::LAST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + last_advertising_data_fragment), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingDataTest, AdvertisingEnabled) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_advertising_data_fragment), ErrorCode::COMMAND_DISALLOWED); } -TEST_F(LeSetExtendedAdvertisingDataTest, - AdvertisingDataLargerThanMemoryCapacity) { +TEST_F(LeSetExtendedAdvertisingDataTest, AdvertisingDataLargerThanMemoryCapacity) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data_fragment = {1, 2, 3}; advertising_data_fragment.resize(properties_.le_max_advertising_data_length); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::LAST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data_fragment), ErrorCode::MEMORY_CAPACITY_EXCEEDED); } TEST_F(LeSetExtendedAdvertisingDataTest, AdvertisingDataLargerThanPduCapacity) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); // No AUX chain possible for connectable advertising PDUs, @@ -347,9 +326,9 @@ TEST_F(LeSetExtendedAdvertisingDataTest, AdvertisingDataLargerThanPduCapacity) { std::vector advertising_data = {1, 2, 3}; advertising_data.resize(254); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::PACKET_TOO_LONG); } diff --git a/test/controller/le/le_set_extended_advertising_enable_test.cc b/test/controller/le/le_set_extended_advertising_enable_test.cc index a83e726..5addb9c 100644 --- a/test/controller/le/le_set_extended_advertising_enable_test.cc +++ b/test/controller/le/le_set_extended_advertising_enable_test.cc @@ -24,136 +24,123 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetExtendedAdvertisingEnableTest : public ::testing::Test { - public: +public: LeSetExtendedAdvertisingEnableTest() { // Reduce the number of advertising sets to simplify testing. properties_.le_num_supported_advertising_sets = 2; properties_.le_max_advertising_data_length = 2000; - }; + } ~LeSetExtendedAdvertisingEnableTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; TEST_F(LeSetExtendedAdvertisingEnableTest, DisableAll) { - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(false, {}), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(false, {}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingEnableTest, DisableSelected) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - false, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(false, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingEnableTest, EnableUsingPublicAddress) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingEnableTest, EnableUsingTimeout) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0x40, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0x40, 0)}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingEnableTest, EnableUsingRandomAddress) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::RANDOM_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetAdvertisingSetRandomAddress(0, Address{1}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::RANDOM_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0x40, 0)}), + ASSERT_EQ(controller_.LeSetAdvertisingSetRandomAddress(0, Address{1}), ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0x40, 0)}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingEnableTest, EnableUsingResolvableAddress) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array{1}, std::array{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array{1}, std::array{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetAddressResolutionEnable(true), ErrorCode::SUCCESS); // Note: the command will fail if the peer address is not in the resolvable // address list and the random address is not set. // Success here signifies that the RPA was successfully generated. - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0x40, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0x40, 0)}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingEnableTest, DuplicateAdvertisingHandle) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0), MakeEnabledSet(0, 0, 0)}), + true, {MakeEnabledSet(0, 0, 0), MakeEnabledSet(0, 0, 0)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingEnableTest, UnknownAdvertisingHandle) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0), MakeEnabledSet(1, 0, 0)}), + true, {MakeEnabledSet(0, 0, 0), MakeEnabledSet(1, 0, 0)}), ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); } @@ -163,150 +150,137 @@ TEST_F(LeSetExtendedAdvertisingEnableTest, MissingAdvertisingHandle) { } TEST_F(LeSetExtendedAdvertisingEnableTest, InvalidDuration) { - ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, - MakeAdvertisingEventProperties(LEGACY | DIRECTED | CONNECTABLE | - HIGH_DUTY_CYCLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ( + controller_.LeSetExtendedAdvertisingParameters( + 0, + MakeAdvertisingEventProperties(LEGACY | DIRECTED | CONNECTABLE | HIGH_DUTY_CYCLE), + 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0x801, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0x801, 0)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingEnableTest, PartialAdvertisingData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetExtendedAdvertisingEnableTest, PartialScanResponseData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_scan_response_data_fragment = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_scan_response_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetExtendedAdvertisingEnableTest, EmptyScanResponseData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::COMMAND_DISALLOWED); } -TEST_F(LeSetExtendedAdvertisingEnableTest, - AdvertisingDataLargerThanPduCapacity) { +TEST_F(LeSetExtendedAdvertisingEnableTest, AdvertisingDataLargerThanPduCapacity) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; advertising_data.resize(254); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } -TEST_F(LeSetExtendedAdvertisingEnableTest, - AdvertisingDataLargerThanMaxPduCapacity) { +TEST_F(LeSetExtendedAdvertisingEnableTest, AdvertisingDataLargerThanMaxPduCapacity) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(0), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(0), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; advertising_data.resize(1651); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::PACKET_TOO_LONG); } TEST_F(LeSetExtendedAdvertisingEnableTest, NoRandomAddress) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::RANDOM_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::RANDOM_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingEnableTest, NoResolvableOrRandomAddress) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } diff --git a/test/controller/le/le_set_extended_advertising_parameters_test.cc b/test/controller/le/le_set_extended_advertising_parameters_test.cc index f6a73b6..9b89b88 100644 --- a/test/controller/le/le_set_extended_advertising_parameters_test.cc +++ b/test/controller/le/le_set_extended_advertising_parameters_test.cc @@ -24,14 +24,14 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetExtendedAdvertisingParametersTest : public ::testing::Test { - public: +public: LeSetExtendedAdvertisingParametersTest() { // Reduce the number of advertising sets to simplify testing. properties_.le_num_supported_advertising_sets = 2; - }; + } ~LeSetExtendedAdvertisingParametersTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -39,258 +39,244 @@ class LeSetExtendedAdvertisingParametersTest : public ::testing::Test { TEST_F(LeSetExtendedAdvertisingParametersTest, Success) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedAdvertisingParametersTest, LegacyUsed) { - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetExtendedAdvertisingParametersTest, AdvertisingSetsFull) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 1, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 1, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 2, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 2, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::MEMORY_CAPACITY_EXCEEDED); } -TEST_F(LeSetExtendedAdvertisingParametersTest, - InvalidLegacyAdvertisingEventProperties) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | DIRECTED | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); +TEST_F(LeSetExtendedAdvertisingParametersTest, InvalidLegacyAdvertisingEventProperties) { + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | DIRECTED | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingParametersTest, UnexpectedAdvertisingData) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | DIRECTED | CONNECTABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | DIRECTED | CONNECTABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingParametersTest, UnexpectedScanResponseData) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingParametersTest, InvalidLegacyAdvertisingData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; advertising_data.resize(32); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, advertising_data), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + advertising_data), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingParametersTest, InvalidLegacyScanResponseData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; scan_response_data.resize(32); - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } -TEST_F(LeSetExtendedAdvertisingParametersTest, - InvalidExtendedAdvertisingEventProperties) { +TEST_F(LeSetExtendedAdvertisingParametersTest, InvalidExtendedAdvertisingEventProperties) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE | SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, - MakeAdvertisingEventProperties(CONNECTABLE | DIRECTED | - HIGH_DUTY_CYCLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE | DIRECTED | HIGH_DUTY_CYCLE), + 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } -TEST_F(LeSetExtendedAdvertisingParametersTest, - InvalidPrimaryAdvertisingInterval) { +TEST_F(LeSetExtendedAdvertisingParametersTest, InvalidPrimaryAdvertisingInterval) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x10, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x10, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x10, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x10, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0400, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0400, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingParametersTest, InvalidChannelMap) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x0, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x0, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingParametersTest, InvalidPrimaryPhy) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_CODED, - 0, SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_CODED, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedAdvertisingParametersTest, AdvertisingActive) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(0), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(0), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::COMMAND_DISALLOWED); } diff --git a/test/controller/le/le_set_extended_scan_enable_test.cc b/test/controller/le/le_set_extended_scan_enable_test.cc index 278b9d0..298683a 100644 --- a/test/controller/le/le_set_extended_scan_enable_test.cc +++ b/test/controller/le/le_set_extended_scan_enable_test.cc @@ -23,18 +23,17 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetExtendedScanEnableTest : public ::testing::Test { - public: +public: LeSetExtendedScanEnableTest() = default; ~LeSetExtendedScanEnableTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; -static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type, - uint16_t scan_interval, +static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type, uint16_t scan_interval, uint16_t scan_window) { ScanningPhyParameters parameters; parameters.le_scan_type_ = scan_type; @@ -44,109 +43,86 @@ static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type, } TEST_F(LeSetExtendedScanEnableTest, EnableUsingPublicAddress) { - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 0, 0), + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 0, 0), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanEnableTest, EnableUsingRandomAddress) { - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::RANDOM_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::RANDOM_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 0, 0), + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 0, 0), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanEnableTest, EnableUsingResolvableAddress) { ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); + controller_.LeSetExtendedScanParameters( + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, + 0x1, {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 0, 0), + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 0, 0), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanEnableTest, ResetEachPeriod) { - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::RESET_EACH_PERIOD, 100, 1000), + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), ErrorCode::SUCCESS); + ASSERT_EQ( + controller_.LeSetExtendedScanEnable(true, FilterDuplicates::RESET_EACH_PERIOD, 100, 1000), + ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanEnableTest, Disable) { - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - false, FilterDuplicates::DISABLED, 0, 0), + ASSERT_EQ(controller_.LeSetExtendedScanEnable(false, FilterDuplicates::DISABLED, 0, 0), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanEnableTest, ValidDuration) { - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 127, 1), + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 127, 1), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanEnableTest, InvalidDuration) { - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::RESET_EACH_PERIOD, 0, 0), + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::RESET_EACH_PERIOD, 0, 0), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 128, 1), + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 128, 1), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedScanEnableTest, NoRandomAddress) { - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::RANDOM_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 0, 0), + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::RANDOM_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 0, 0), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 0, 0), + controller_.LeSetExtendedScanParameters( + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, + 0x1, {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 0, 0), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } diff --git a/test/controller/le/le_set_extended_scan_parameters_test.cc b/test/controller/le/le_set_extended_scan_parameters_test.cc index 3e1ab53..ecc61e9 100644 --- a/test/controller/le/le_set_extended_scan_parameters_test.cc +++ b/test/controller/le/le_set_extended_scan_parameters_test.cc @@ -23,18 +23,17 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetExtendedScanParametersTest : public ::testing::Test { - public: +public: LeSetExtendedScanParametersTest() = default; ~LeSetExtendedScanParametersTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; -static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type, - uint16_t scan_interval, +static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type, uint16_t scan_interval, uint16_t scan_window) { ScanningPhyParameters parameters; parameters.le_scan_type_ = scan_type; @@ -45,77 +44,64 @@ static ScanningPhyParameters MakeScanningPhyParameters(LeScanType scan_type, TEST_F(LeSetExtendedScanParametersTest, Success) { ASSERT_EQ(controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x5, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), - MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}), + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x5, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), + MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanParametersTest, ScanningActive) { ASSERT_EQ(controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x5, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), - MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}), + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x5, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), + MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanEnable( - true, FilterDuplicates::DISABLED, 0, 0), + ASSERT_EQ(controller_.LeSetExtendedScanEnable(true, FilterDuplicates::DISABLED, 0, 0), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x5, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), - MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}), + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x5, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), + MakeScanningPhyParameters(LeScanType::ACTIVE, 0x2000, 0x200)}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetExtendedScanParametersTest, ReservedPhy) { - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x80, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x80, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeSetExtendedScanParametersTest, InvalidPhyParameters) { - ASSERT_EQ(controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, {}), + ASSERT_EQ(controller_.LeSetExtendedScanParameters(OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL, 0x1, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), - MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200), + MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x200)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedScanParametersTest, InvalidScanInterval) { ASSERT_EQ(controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x0, 0x200)}), + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x0, 0x200)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedScanParametersTest, InvalidScanWindow) { ASSERT_EQ(controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x0)}), + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x0)}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ( - controller_.LeSetExtendedScanParameters( - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL, 0x1, - {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x2001)}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetExtendedScanParameters( + OwnAddressType::PUBLIC_DEVICE_ADDRESS, LeScanningFilterPolicy::ACCEPT_ALL, 0x1, + {MakeScanningPhyParameters(LeScanType::PASSIVE, 0x2000, 0x2001)}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } } // namespace rootcanal diff --git a/test/controller/le/le_set_extended_scan_response_data_test.cc b/test/controller/le/le_set_extended_scan_response_data_test.cc index fde4680..c53c9f5 100644 --- a/test/controller/le/le_set_extended_scan_response_data_test.cc +++ b/test/controller/le/le_set_extended_scan_response_data_test.cc @@ -24,15 +24,15 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetExtendedScanResponseDataTest : public ::testing::Test { - public: +public: LeSetExtendedScanResponseDataTest() { // Reduce the number of advertising sets to simplify testing. properties_.le_num_supported_advertising_sets = 2; properties_.le_max_advertising_data_length = 300; - }; + } ~LeSetExtendedScanResponseDataTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,170 +40,159 @@ class LeSetExtendedScanResponseDataTest : public ::testing::Test { TEST_F(LeSetExtendedScanResponseDataTest, Complete) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanResponseDataTest, Discard) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + {}), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanResponseDataTest, Unchanged) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::UNCHANGED_DATA, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::UNCHANGED_DATA, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedScanResponseDataTest, Fragmented) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_scan_response_data_fragment = {1, 2, 3}; std::vector intermediate_scan_response_data_fragment = {4, 5, 6}; std::vector last_scan_response_data_fragment = {7, 8, 9}; - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_scan_response_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::INTERMEDIATE_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - intermediate_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::INTERMEDIATE_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + intermediate_scan_response_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - last_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::LAST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + last_scan_response_data_fragment), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanResponseDataTest, UnknownAdvertisingHandle) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 1, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(1, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); } TEST_F(LeSetExtendedScanResponseDataTest, UnexpectedScanResponseData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedScanResponseDataTest, IncompleteLegacyScanResponseData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_scan_response_data_fragment = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_scan_response_data_fragment), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedScanResponseDataTest, InvalidLegacyScanResponseData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, - 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(LEGACY | SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; scan_response_data.resize(32); - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetExtendedScanResponseDataTest, EmptyScanResponseDataFragment) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector first_scan_response_data_fragment = {1, 2, 3}; @@ -211,152 +200,134 @@ TEST_F(LeSetExtendedScanResponseDataTest, EmptyScanResponseDataFragment) { std::vector last_scan_response_data_fragment = {7, 8, 9}; ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::FIRST_FRAGMENT, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - first_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + first_scan_response_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::INTERMEDIATE_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::INTERMEDIATE_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::INTERMEDIATE_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - intermediate_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::INTERMEDIATE_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + intermediate_scan_response_data_fragment), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + 0, Operation::LAST_FRAGMENT, FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - last_scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::LAST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + last_scan_response_data_fragment), ErrorCode::SUCCESS); } TEST_F(LeSetExtendedScanResponseDataTest, AdvertisingEnabled) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetExtendedScanResponseDataTest, EmptyExtendedScanResponseData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, {}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), + ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + {}), ErrorCode::COMMAND_DISALLOWED); } -TEST_F(LeSetExtendedScanResponseDataTest, - ScanResponseDataLargerThanMemoryCapacity) { +TEST_F(LeSetExtendedScanResponseDataTest, ScanResponseDataLargerThanMemoryCapacity) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data_fragment = {1, 2, 3}; - scan_response_data_fragment.resize( - properties_.le_max_advertising_data_length); + scan_response_data_fragment.resize(properties_.le_max_advertising_data_length); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::FIRST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::FIRST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedScanResponseData( - 0, Operation::LAST_FRAGMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, - scan_response_data_fragment), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::LAST_FRAGMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data_fragment), ErrorCode::MEMORY_CAPACITY_EXCEEDED); } -TEST_F(LeSetExtendedScanResponseDataTest, - ScanResponseDataLargerThanPduCapacity) { +TEST_F(LeSetExtendedScanResponseDataTest, ScanResponseDataLargerThanPduCapacity) { // Overwrite le_max_advertising_data_length to make sure that the correct // check is triggered. properties_.le_max_advertising_data_length = 5000; ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector scan_response_data = {1, 2, 3}; - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); // No AUX chain possible for connectable advertising PDUs, // the advertising data is limited to one PDU's payload. scan_response_data.resize(1651); - ASSERT_EQ( - controller_.LeSetExtendedScanResponseData( - 0, Operation::COMPLETE_ADVERTISEMENT, - FragmentPreference::CONTROLLER_MAY_FRAGMENT, scan_response_data), - ErrorCode::PACKET_TOO_LONG); + ASSERT_EQ(controller_.LeSetExtendedScanResponseData(0, Operation::COMPLETE_ADVERTISEMENT, + FragmentPreference::CONTROLLER_MAY_FRAGMENT, + scan_response_data), + ErrorCode::PACKET_TOO_LONG); } } // namespace rootcanal diff --git a/test/controller/le/le_set_periodic_advertising_data_test.cc b/test/controller/le/le_set_periodic_advertising_data_test.cc index 26a03d0..90bbc1a 100644 --- a/test/controller/le/le_set_periodic_advertising_data_test.cc +++ b/test/controller/le/le_set_periodic_advertising_data_test.cc @@ -24,14 +24,14 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetPeriodicAdvertisingDataTest : public ::testing::Test { - public: +public: LeSetPeriodicAdvertisingDataTest() { // Reduce the maximum advertising data length to simplify testing. properties_.le_max_advertising_data_length = 300; - }; + } ~LeSetPeriodicAdvertisingDataTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -39,233 +39,213 @@ class LeSetPeriodicAdvertisingDataTest : public ::testing::Test { TEST_F(LeSetPeriodicAdvertisingDataTest, Complete) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, advertising_data), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + advertising_data), ErrorCode::SUCCESS); } TEST_F(LeSetPeriodicAdvertisingDataTest, Unchanged) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, advertising_data), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::UNCHANGED_DATA, {}), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::UNCHANGED_DATA, {}), ErrorCode::SUCCESS); } TEST_F(LeSetPeriodicAdvertisingDataTest, Fragmented) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; std::vector intermediate_advertising_data_fragment = {4, 5, 6}; std::vector last_advertising_data_fragment = {7, 8, 9}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::FIRST_FRAGMENT, first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::FIRST_FRAGMENT, + first_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::INTERMEDIATE_FRAGMENT, - intermediate_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::INTERMEDIATE_FRAGMENT, + intermediate_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::LAST_FRAGMENT, last_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::LAST_FRAGMENT, + last_advertising_data_fragment), ErrorCode::SUCCESS); } TEST_F(LeSetPeriodicAdvertisingDataTest, UnknownAdvertisingHandle) { std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, advertising_data), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + advertising_data), ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); } TEST_F(LeSetPeriodicAdvertisingDataTest, PeriodicAdvertisingNotConfigured) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, advertising_data), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + advertising_data), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetPeriodicAdvertisingDataTest, PeriodicAdvertisingEnabled) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), ErrorCode::SUCCESS); + std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::FIRST_FRAGMENT, advertising_data), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ( + controller_.LeSetPeriodicAdvertisingData(0, Operation::FIRST_FRAGMENT, advertising_data), + ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetPeriodicAdvertisingDataTest, EmptyAdvertisingDataFragment) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; std::vector intermediate_advertising_data_fragment = {4, 5, 6}; std::vector last_advertising_data_fragment = {7, 8, 9}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::FIRST_FRAGMENT, {}), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::FIRST_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::FIRST_FRAGMENT, first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::FIRST_FRAGMENT, + first_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::INTERMEDIATE_FRAGMENT, {}), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::INTERMEDIATE_FRAGMENT, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::INTERMEDIATE_FRAGMENT, - intermediate_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::INTERMEDIATE_FRAGMENT, + intermediate_advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingData(0, Operation::LAST_FRAGMENT, {}), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::LAST_FRAGMENT, {}), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::LAST_FRAGMENT, last_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::LAST_FRAGMENT, + last_advertising_data_fragment), ErrorCode::SUCCESS); } TEST_F(LeSetPeriodicAdvertisingDataTest, UnchangedWhenDisabled) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, advertising_data), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::UNCHANGED_DATA, {}), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::UNCHANGED_DATA, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetPeriodicAdvertisingDataTest, UnchangedWhenAdvertisingDataEmpty) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::UNCHANGED_DATA, {}), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::UNCHANGED_DATA, {}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } -TEST_F(LeSetPeriodicAdvertisingDataTest, - AdvertisingDataLargerThanMemoryCapacity) { +TEST_F(LeSetPeriodicAdvertisingDataTest, AdvertisingDataLargerThanMemoryCapacity) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector advertising_data_fragment = {1, 2, 3}; advertising_data_fragment.resize(properties_.le_max_advertising_data_length); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::FIRST_FRAGMENT, advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::FIRST_FRAGMENT, + advertising_data_fragment), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::LAST_FRAGMENT, advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::LAST_FRAGMENT, + advertising_data_fragment), ErrorCode::MEMORY_CAPACITY_EXCEEDED); } diff --git a/test/controller/le/le_set_periodic_advertising_enable_test.cc b/test/controller/le/le_set_periodic_advertising_enable_test.cc index 761beea..09f5cdf 100644 --- a/test/controller/le/le_set_periodic_advertising_enable_test.cc +++ b/test/controller/le/le_set_periodic_advertising_enable_test.cc @@ -24,11 +24,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetPeriodicAdvertisingEnableTest : public ::testing::Test { - public: +public: LeSetPeriodicAdvertisingEnableTest() {} ~LeSetPeriodicAdvertisingEnableTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -36,41 +36,37 @@ class LeSetPeriodicAdvertisingEnableTest : public ::testing::Test { TEST_F(LeSetPeriodicAdvertisingEnableTest, Enable) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector advertising_data = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::COMPLETE_ADVERTISEMENT, advertising_data), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::COMPLETE_ADVERTISEMENT, + advertising_data), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), ErrorCode::SUCCESS); } TEST_F(LeSetPeriodicAdvertisingEnableTest, Disable) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(false, false, 0), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(false, false, 0), ErrorCode::SUCCESS); } TEST_F(LeSetPeriodicAdvertisingEnableTest, UnknownAdvertisingHandle) { @@ -83,20 +79,19 @@ TEST_F(LeSetPeriodicAdvertisingEnableTest, UnknownAdvertisingHandle) { TEST_F(LeSetPeriodicAdvertisingEnableTest, PartialAdvertisingData) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); std::vector first_advertising_data_fragment = {1, 2, 3}; - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData( - 0, Operation::FIRST_FRAGMENT, first_advertising_data_fragment), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingData(0, Operation::FIRST_FRAGMENT, + first_advertising_data_fragment), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), @@ -105,11 +100,11 @@ TEST_F(LeSetPeriodicAdvertisingEnableTest, PartialAdvertisingData) { TEST_F(LeSetPeriodicAdvertisingEnableTest, PeriodicAdvertisingNotConfigured) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), @@ -118,23 +113,22 @@ TEST_F(LeSetPeriodicAdvertisingEnableTest, PeriodicAdvertisingNotConfigured) { TEST_F(LeSetPeriodicAdvertisingEnableTest, InvalidAdvertisingEventProperties) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), diff --git a/test/controller/le/le_set_periodic_advertising_parameters_test.cc b/test/controller/le/le_set_periodic_advertising_parameters_test.cc index fc7aa69..301443b 100644 --- a/test/controller/le/le_set_periodic_advertising_parameters_test.cc +++ b/test/controller/le/le_set_periodic_advertising_parameters_test.cc @@ -24,11 +24,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetPeriodicAdvertisingParametersTest : public ::testing::Test { - public: +public: LeSetPeriodicAdvertisingParametersTest() = default; ~LeSetPeriodicAdvertisingParametersTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -36,124 +36,110 @@ class LeSetPeriodicAdvertisingParametersTest : public ::testing::Test { TEST_F(LeSetPeriodicAdvertisingParametersTest, Success) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::SUCCESS); } TEST_F(LeSetPeriodicAdvertisingParametersTest, UnknownAdvertisingHandle) { - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::UNKNOWN_ADVERTISING_IDENTIFIER); } TEST_F(LeSetPeriodicAdvertisingParametersTest, InvalidAdvertisingInterval) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x0, 0xffff, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x0, 0xffff, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0xffff, 0x6, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0xffff, 0x6, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } -TEST_F(LeSetPeriodicAdvertisingParametersTest, - InvalidLegacyAdvertisingEventProperties) { - ASSERT_EQ( - controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(LEGACY | DIRECTED | SCANNABLE), - 0x0800, 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, - AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, - SecondaryPhyType::LE_2M, 0x0, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); +TEST_F(LeSetPeriodicAdvertisingParametersTest, InvalidLegacyAdvertisingEventProperties) { + ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( + 0, MakeAdvertisingEventProperties(LEGACY | DIRECTED | SCANNABLE), 0x0800, + 0x0800, 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } -TEST_F(LeSetPeriodicAdvertisingParametersTest, - InvalidAdvertisingEventProperties) { +TEST_F(LeSetPeriodicAdvertisingParametersTest, InvalidAdvertisingEventProperties) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 1, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 1, MakeAdvertisingEventProperties(SCANNABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(1, 0x6, 0xffff, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(1, 0x6, 0xffff, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 2, MakeAdvertisingEventProperties(ANONYMOUS), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 2, MakeAdvertisingEventProperties(ANONYMOUS), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(2, 0x6, 0xffff, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(2, 0x6, 0xffff, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 3, MakeAdvertisingEventProperties(LEGACY), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 3, MakeAdvertisingEventProperties(LEGACY), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(3, 0x6, 0xffff, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(3, 0x6, 0xffff, false), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeSetPeriodicAdvertisingParametersTest, PeriodicAdvertisingEnabled) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::ALL_DEVICES, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::ALL_DEVICES, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::SUCCESS); - - ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingEnable(true, false, 0), ErrorCode::SUCCESS); + + ASSERT_EQ(controller_.LeSetPeriodicAdvertisingParameters(0, 0x6, 0xffff, false), + ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/test/controller/le/le_set_random_address_test.cc b/test/controller/le/le_set_random_address_test.cc index 63a60b6..a92a72d 100644 --- a/test/controller/le/le_set_random_address_test.cc +++ b/test/controller/le/le_set_random_address_test.cc @@ -24,11 +24,11 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetRandomAddressTest : public ::testing::Test { - public: +public: LeSetRandomAddressTest() = default; ~LeSetRandomAddressTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; @@ -40,26 +40,23 @@ TEST_F(LeSetRandomAddressTest, Success) { TEST_F(LeSetRandomAddressTest, ScanningActive) { controller_.LeSetScanEnable(true, false); - ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetRandomAddressTest, LegacyAdvertisingActive) { ASSERT_EQ(controller_.LeSetAdvertisingEnable(true), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetRandomAddressTest, ExtendedAdvertisingActive) { ASSERT_EQ(controller_.LeSetExtendedAdvertisingParameters( - 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, - 0x7, OwnAddressType::PUBLIC_DEVICE_ADDRESS, - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, - Address::kEmpty, AdvertisingFilterPolicy::LISTED_SCAN, 0x70, - PrimaryPhyType::LE_1M, 0, SecondaryPhyType::LE_2M, 0x0, false), + 0, MakeAdvertisingEventProperties(CONNECTABLE), 0x0800, 0x0800, 0x7, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address::kEmpty, + AdvertisingFilterPolicy::LISTED_SCAN, 0x70, PrimaryPhyType::LE_1M, 0, + SecondaryPhyType::LE_2M, 0x0, false), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable( - true, {MakeEnabledSet(0, 0, 0)}), + ASSERT_EQ(controller_.LeSetExtendedAdvertisingEnable(true, {MakeEnabledSet(0, 0, 0)}), ErrorCode::SUCCESS); // The Random Address is not used for extended advertising, diff --git a/test/controller/le/le_set_scan_enable_test.cc b/test/controller/le/le_set_scan_enable_test.cc index a522af2..08cba64 100644 --- a/test/controller/le/le_set_scan_enable_test.cc +++ b/test/controller/le/le_set_scan_enable_test.cc @@ -23,40 +23,37 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetScanEnableTest : public ::testing::Test { - public: +public: LeSetScanEnableTest() = default; ~LeSetScanEnableTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; TEST_F(LeSetScanEnableTest, EnableUsingPublicAddress) { - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS); } TEST_F(LeSetScanEnableTest, EnableUsingRandomAddress) { - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::RANDOM_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::RANDOM_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS); } TEST_F(LeSetScanEnableTest, EnableUsingResolvableAddress) { - ASSERT_EQ(controller_.LeSetScanParameters( - LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetRandomAddress(Address{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS); @@ -67,21 +64,17 @@ TEST_F(LeSetScanEnableTest, Disable) { } TEST_F(LeSetScanEnableTest, NoRandomAddress) { - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::RANDOM_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetScanEnable(true, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::RANDOM_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); - ASSERT_EQ(controller_.LeSetScanParameters( - LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), ErrorCode::SUCCESS); - ASSERT_EQ(controller_.LeSetScanEnable(true, false), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } } // namespace rootcanal diff --git a/test/controller/le/le_set_scan_parameters_test.cc b/test/controller/le/le_set_scan_parameters_test.cc index 5a27b65..13f693b 100644 --- a/test/controller/le/le_set_scan_parameters_test.cc +++ b/test/controller/le/le_set_scan_parameters_test.cc @@ -23,66 +23,59 @@ namespace rootcanal { using namespace bluetooth::hci; class LeSetScanParametersTest : public ::testing::Test { - public: +public: LeSetScanParametersTest() = default; ~LeSetScanParametersTest() override = default; - protected: +protected: Address address_{0}; ControllerProperties properties_{}; LinkLayerController controller_{address_, properties_}; }; TEST_F(LeSetScanParametersTest, Success) { - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::SUCCESS); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::SUCCESS); } TEST_F(LeSetScanParametersTest, ScanningActive) { ASSERT_EQ(controller_.LeSetScanEnable(true, false), ErrorCode::SUCCESS); - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::COMMAND_DISALLOWED); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeSetScanParametersTest, InvalidScanInterval) { - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x0, 0x200, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x0, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x4001, 0x200, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x4001, 0x200, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); } TEST_F(LeSetScanParametersTest, InvalidScanWindow) { - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x0, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x0, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x4001, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x4001, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::UNSUPPORTED_FEATURE_OR_PARAMETER_VALUE); - ASSERT_EQ( - controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x2001, - OwnAddressType::PUBLIC_DEVICE_ADDRESS, - LeScanningFilterPolicy::ACCEPT_ALL), - ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); + ASSERT_EQ(controller_.LeSetScanParameters(LeScanType::PASSIVE, 0x2000, 0x2001, + OwnAddressType::PUBLIC_DEVICE_ADDRESS, + LeScanningFilterPolicy::ACCEPT_ALL), + ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } } // namespace rootcanal diff --git a/test/controller/le/rpa_generation_test.cc b/test/controller/le/rpa_generation_test.cc index ac10271..ab7e7eb 100644 --- a/test/controller/le/rpa_generation_test.cc +++ b/test/controller/le/rpa_generation_test.cc @@ -23,15 +23,14 @@ namespace rootcanal { using namespace bluetooth::hci; class RpaGenerationTest : public ::testing::Test { - public: +public: RpaGenerationTest() = default; ~RpaGenerationTest() override = default; }; TEST_F(RpaGenerationTest, Test) { std::array irk = { - 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, - 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, + 0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf, }; AddressWithType rpa{rootcanal::LinkLayerController::generate_rpa(irk), diff --git a/test/controller/le/test_helpers.h b/test/controller/le/test_helpers.h index 4c9016c..78978f7 100644 --- a/test/controller/le/test_helpers.h +++ b/test/controller/le/test_helpers.h @@ -26,8 +26,8 @@ enum : unsigned { TX_POWER = 0x40, }; -[[maybe_unused]] static bluetooth::hci::AdvertisingEventProperties -MakeAdvertisingEventProperties(unsigned mask = 0) { +[[maybe_unused]] static bluetooth::hci::AdvertisingEventProperties MakeAdvertisingEventProperties( + unsigned mask = 0) { bluetooth::hci::AdvertisingEventProperties properties; properties.connectable_ = (mask & CONNECTABLE) != 0; properties.scannable_ = (mask & SCANNABLE) != 0; @@ -35,13 +35,12 @@ MakeAdvertisingEventProperties(unsigned mask = 0) { properties.high_duty_cycle_ = (mask & HIGH_DUTY_CYCLE) != 0; properties.legacy_ = (mask & LEGACY) != 0; properties.anonymous_ = (mask & ANONYMOUS) != 0; - properties.tx_power_ = (mask & TX_POWER) != 0; + properties.include_tx_power_ = (mask & TX_POWER) != 0; return properties; } [[maybe_unused]] static bluetooth::hci::EnabledSet MakeEnabledSet( - uint8_t advertising_handle, uint16_t duration, - uint8_t max_extended_advertising_events) { + uint8_t advertising_handle, uint16_t duration, uint8_t max_extended_advertising_events) { bluetooth::hci::EnabledSet set; set.advertising_handle_ = advertising_handle; set.duration_ = duration; @@ -49,12 +48,10 @@ MakeAdvertisingEventProperties(unsigned mask = 0) { return set; } -[[maybe_unused]] static bluetooth::hci::InitiatingPhyParameters -MakeInitiatingPhyParameters(uint16_t scan_interval, uint16_t scan_window, - uint16_t connection_interval_min, - uint16_t connection_interval_max, - uint16_t max_latency, uint16_t supervision_timeout, - uint16_t min_ce_length, uint16_t max_ce_length) { +[[maybe_unused]] static bluetooth::hci::InitiatingPhyParameters MakeInitiatingPhyParameters( + uint16_t scan_interval, uint16_t scan_window, uint16_t connection_interval_min, + uint16_t connection_interval_max, uint16_t max_latency, uint16_t supervision_timeout, + uint16_t min_ce_length, uint16_t max_ce_length) { bluetooth::hci::InitiatingPhyParameters parameters; parameters.scan_interval_ = scan_interval; parameters.scan_window_ = scan_window; diff --git a/test/h4_parser_unittest.cc b/test/h4_parser_unittest.cc index 9e4b59e..7947b62 100644 --- a/test/h4_parser_unittest.cc +++ b/test/h4_parser_unittest.cc @@ -24,8 +24,8 @@ namespace rootcanal { using PacketData = std::vector; class H4ParserTest : public ::testing::Test { - public: - protected: +public: +protected: void SetUp() override { packet_.clear(); parser_.Reset(); @@ -33,41 +33,37 @@ class H4ParserTest : public ::testing::Test { void TearDown() override { parser_.Reset(); } - void PacketReadCallback(const std::vector& packet) { - packet_ = std::move(packet); - } + void PacketReadCallback(const std::vector& packet) { packet_ = std::move(packet); } - protected: +protected: H4Parser parser_{ - [&](auto p) { - type_ = PacketType::COMMAND; - PacketReadCallback(p); - }, - [&](auto p) { - type_ = PacketType::EVENT; - PacketReadCallback(p); - }, - [&](auto p) { - type_ = PacketType::ACL; - PacketReadCallback(p); - }, - [&](auto p) { - type_ = PacketType::SCO; - PacketReadCallback(p); - }, - [&](auto p) { - type_ = PacketType::ISO; - PacketReadCallback(p); - }, - true, + [&](auto p) { + type_ = PacketType::COMMAND; + PacketReadCallback(p); + }, + [&](auto p) { + type_ = PacketType::EVENT; + PacketReadCallback(p); + }, + [&](auto p) { + type_ = PacketType::ACL; + PacketReadCallback(p); + }, + [&](auto p) { + type_ = PacketType::SCO; + PacketReadCallback(p); + }, + [&](auto p) { + type_ = PacketType::ISO; + PacketReadCallback(p); + }, + true, }; PacketData packet_; PacketType type_; }; -TEST_F(H4ParserTest, InitiallyExpectOneByte) { - ASSERT_EQ(1, (int)parser_.BytesRequested()); -} +TEST_F(H4ParserTest, InitiallyExpectOneByte) { ASSERT_EQ(1, (int)parser_.BytesRequested()); } TEST_F(H4ParserTest, SwitchStateAfterType) { uint8_t typ = (uint8_t)PacketType::ACL; @@ -114,15 +110,13 @@ TEST_F(H4ParserTest, TooMuchIsDeath) { TEST_F(H4ParserTest, WrongTypeIsDeath) { parser_.DisableRecovery(); PacketData bad_bit({0xfd}); - ASSERT_DEATH(parser_.Consume(bad_bit.data(), bad_bit.size()), - "Received invalid packet type.*"); + ASSERT_DEATH(parser_.Consume(bad_bit.data(), bad_bit.size()), "Received invalid packet type.*"); } TEST_F(H4ParserTest, CallsTheRightCallbacks) { // Make sure that the proper type of callback is invoked. - std::vector types({PacketType::ACL, PacketType::SCO, - PacketType::COMMAND, PacketType::EVENT, - PacketType::ISO}); + std::vector types({PacketType::ACL, PacketType::SCO, PacketType::COMMAND, + PacketType::EVENT, PacketType::ISO}); for (auto packetType : types) { // Configure the incoming packet. uint8_t typ = (uint8_t)packetType; diff --git a/test/invalid_packet_handler_unittest.cc b/test/invalid_packet_handler_unittest.cc index 803124b..00221be 100644 --- a/test/invalid_packet_handler_unittest.cc +++ b/test/invalid_packet_handler_unittest.cc @@ -24,17 +24,16 @@ namespace rootcanal { using namespace bluetooth::hci; class InvalidPacketHandlerTest : public ::testing::Test { - public: +public: InvalidPacketHandlerTest() = default; ~InvalidPacketHandlerTest() override = default; - protected: +protected: DualModeController controller_; }; // Set Event Mask command with missing parameters. -const std::vector kInvalidCommandPacket = {0x01, 0x0C, 0x03, - 0xff, 0xff, 0xff}; +const std::vector kInvalidCommandPacket = {0x01, 0x0C, 0x03, 0xff, 0xff, 0xff}; // Hardware Error event with code 0x43. const std::vector kHardwareErrorEvent = {0x10, 0x01, 0x43}; @@ -42,9 +41,9 @@ const std::vector kHardwareErrorEvent = {0x10, 0x01, 0x43}; TEST_F(InvalidPacketHandlerTest, DefaultHandler) { // Validate that the default invalid packet handler causes // an abort when an invalid packet is received. - ASSERT_DEATH(controller_.HandleCommand(std::make_shared>( - kInvalidCommandPacket)), - ""); + ASSERT_DEATH( + controller_.HandleCommand(std::make_shared>(kInvalidCommandPacket)), + ""); } TEST_F(InvalidPacketHandlerTest, RegisteredHandler) { @@ -58,21 +57,18 @@ TEST_F(InvalidPacketHandlerTest, RegisteredHandler) { // Validate that the registered invalid packet handler is correctly // invoked when an invalid packet is received. - controller_.RegisterInvalidPacketHandler( - [&](uint32_t id, InvalidPacketReason reason, std::string, - std::vector const& bytes) { - invalid_packet.id = id; - invalid_packet.reason = reason; - invalid_packet.bytes = bytes; - }); + controller_.RegisterInvalidPacketHandler([&](uint32_t id, InvalidPacketReason reason, std::string, + std::vector const& bytes) { + invalid_packet.id = id; + invalid_packet.reason = reason; + invalid_packet.bytes = bytes; + }); - controller_.RegisterEventChannel( - [&](std::shared_ptr> packet) { - hci_event = std::vector(*packet); - }); + controller_.RegisterEventChannel([&](std::shared_ptr> packet) { + hci_event = std::vector(*packet); + }); - controller_.HandleCommand( - std::make_shared>(kInvalidCommandPacket)); + controller_.HandleCommand(std::make_shared>(kInvalidCommandPacket)); ASSERT_EQ(invalid_packet.id, controller_.id_); ASSERT_EQ(invalid_packet.reason, InvalidPacketReason::kParseError); ASSERT_EQ(invalid_packet.bytes, kInvalidCommandPacket); diff --git a/test/main.py b/test/main.py index b61a5b8..fba8d2a 100644 --- a/test/main.py +++ b/test/main.py @@ -20,6 +20,7 @@ import unittest tests = [ + 'HCI.AEN.BV_06_C', 'LL.CIS.CEN.BV_01_C', 'LL.CIS.CEN.BV_03_C', 'LL.CIS.CEN.BV_10_C', diff --git a/test/pcap_filter_unittest.cc b/test/pcap_filter_unittest.cc index 41a8076..403f8d6 100644 --- a/test/pcap_filter_unittest.cc +++ b/test/pcap_filter_unittest.cc @@ -25,68 +25,60 @@ namespace rootcanal { using namespace bluetooth::hci; class PcapFilterTest : public ::testing::Test { - public: +public: PcapFilterTest() = default; ~PcapFilterTest() override = default; - protected: +protected: PcapFilter pcap_filter_; }; TEST_F(PcapFilterTest, UnchangedIfNotDeviceName) { // Leaves gap data entries that do not contain a name unchanged. - std::vector input_gap_data{ - 0x2, static_cast(GapDataType::FLAGS), 0x0}; - std::vector output_gap_data{input_gap_data.begin(), - input_gap_data.end()}; + std::vector input_gap_data{0x2, static_cast(GapDataType::FLAGS), 0x0}; + std::vector output_gap_data{input_gap_data.begin(), input_gap_data.end()}; pcap_filter_.FilterGapData(output_gap_data); ASSERT_EQ(input_gap_data, output_gap_data); } TEST_F(PcapFilterTest, ReplacesShortenedDeviceName) { // Replaces the input gap data once, with a name of equal length. - std::vector input_gap_data{ - 0x2, - static_cast(GapDataType::FLAGS), - 0x0, - 0x4, - static_cast(GapDataType::SHORTENED_LOCAL_NAME), - 0xa, - 0xb, - 0xc}; - std::vector output_gap_data_1{input_gap_data.begin(), - input_gap_data.end()}; + std::vector input_gap_data{0x2, + static_cast(GapDataType::FLAGS), + 0x0, + 0x4, + static_cast(GapDataType::SHORTENED_LOCAL_NAME), + 0xa, + 0xb, + 0xc}; + std::vector output_gap_data_1{input_gap_data.begin(), input_gap_data.end()}; pcap_filter_.FilterGapData(output_gap_data_1); ASSERT_EQ(input_gap_data.size(), output_gap_data_1.size()); ASSERT_NE(input_gap_data, output_gap_data_1); // Replaces the input gap data a second time with the same name. - std::vector output_gap_data_2{input_gap_data.begin(), - input_gap_data.end()}; + std::vector output_gap_data_2{input_gap_data.begin(), input_gap_data.end()}; pcap_filter_.FilterGapData(output_gap_data_2); ASSERT_EQ(output_gap_data_1, output_gap_data_2); } TEST_F(PcapFilterTest, ReplacesCompleteDeviceName) { // Replaces the input gap data once, with a name of equal length. - std::vector input_gap_data{ - 0x2, - static_cast(GapDataType::FLAGS), - 0x0, - 0x4, - static_cast(GapDataType::COMPLETE_LOCAL_NAME), - 0xa, - 0xb, - 0xc}; - std::vector output_gap_data_1{input_gap_data.begin(), - input_gap_data.end()}; + std::vector input_gap_data{0x2, + static_cast(GapDataType::FLAGS), + 0x0, + 0x4, + static_cast(GapDataType::COMPLETE_LOCAL_NAME), + 0xa, + 0xb, + 0xc}; + std::vector output_gap_data_1{input_gap_data.begin(), input_gap_data.end()}; pcap_filter_.FilterGapData(output_gap_data_1); ASSERT_EQ(input_gap_data.size(), output_gap_data_1.size()); ASSERT_NE(input_gap_data, output_gap_data_1); // Replaces the input gap data a second time with the same name. - std::vector output_gap_data_2{input_gap_data.begin(), - input_gap_data.end()}; + std::vector output_gap_data_2{input_gap_data.begin(), input_gap_data.end()}; pcap_filter_.FilterGapData(output_gap_data_2); ASSERT_EQ(output_gap_data_1, output_gap_data_2); } diff --git a/test/posix_socket_unittest.cc b/test/posix_socket_unittest.cc index e10cd00..43ec1b5 100644 --- a/test/posix_socket_unittest.cc +++ b/test/posix_socket_unittest.cc @@ -41,7 +41,7 @@ namespace net { using clock = std::chrono::system_clock; class SigPipeSignalHandler { - public: +public: SigPipeSignalHandler() { sSignal = -1; struct sigaction act = {}; @@ -53,7 +53,7 @@ class SigPipeSignalHandler { int signaled() const { return sSignal; } - private: +private: struct sigaction mOldAction; static int sSignal; @@ -67,13 +67,12 @@ int SigPipeSignalHandler::sSignal = 0; using SocketCon = std::shared_ptr; class PosixSocketTest : public testing::Test { - public: +public: PosixSocketTest() : pasc_(&async_manager_), pass_(0, &async_manager_) {} ~PosixSocketTest() { pass_.Close(); } - std::tuple connectPair( - std::chrono::milliseconds timeout = 500ms) { + std::tuple connectPair(std::chrono::milliseconds timeout = 500ms) { std::mutex m; std::condition_variable cv; @@ -81,11 +80,11 @@ class PosixSocketTest : public testing::Test { std::shared_ptr sock2; pass_.SetOnConnectCallback( - [&](std::shared_ptr sock, AsyncDataChannelServer*) { - std::unique_lock guard(m); - sock1 = std::move(sock); - cv.notify_all(); - }); + [&](std::shared_ptr sock, AsyncDataChannelServer*) { + std::unique_lock guard(m); + sock1 = std::move(sock); + cv.notify_all(); + }); EXPECT_TRUE(pass_.StartListening()); sock2 = pasc_.ConnectToRemoteServer("localhost", pass_.port(), 1000ms); @@ -93,15 +92,14 @@ class PosixSocketTest : public testing::Test { EXPECT_TRUE(sock2->Connected()); std::unique_lock lk(m); - EXPECT_TRUE( - cv.wait_for(lk, timeout, [&] { return sock1.get() != nullptr; })); + EXPECT_TRUE(cv.wait_for(lk, timeout, [&] { return sock1.get() != nullptr; })); EXPECT_TRUE(sock1); EXPECT_TRUE(sock1->Connected()); return {sock1, sock2}; } - protected: +protected: AsyncManager async_manager_; PosixAsyncSocketConnector pasc_; PosixAsyncSocketServer pass_; @@ -242,14 +240,14 @@ TEST_F(PosixSocketTest, canConnectMultiple) { std::vector> connections; bool connected = false; - pass_.SetOnConnectCallback([&](std::shared_ptr const& sock, - AsyncDataChannelServer*) { - std::unique_lock guard(m); - connections.push_back(sock); - connected = true; - ASSERT_TRUE(pass_.StartListening()); - cv.notify_all(); - }); + pass_.SetOnConnectCallback( + [&](std::shared_ptr const& sock, AsyncDataChannelServer*) { + std::unique_lock guard(m); + connections.push_back(sock); + connected = true; + ASSERT_TRUE(pass_.StartListening()); + cv.notify_all(); + }); ASSERT_TRUE(pass_.StartListening()); for (int i = 0; i < CONNECTION_COUNT; i++) { @@ -271,13 +269,12 @@ TEST_F(PosixSocketTest, noConnectWhenNotCallingStart) { std::vector> connections; bool connected = false; - pass_.SetOnConnectCallback( - [&](std::shared_ptr sock, AsyncDataChannelServer*) { - std::unique_lock guard(m); - connections.push_back(sock); - connected = true; - cv.notify_all(); - }); + pass_.SetOnConnectCallback([&](std::shared_ptr sock, AsyncDataChannelServer*) { + std::unique_lock guard(m); + connections.push_back(sock); + connected = true; + cv.notify_all(); + }); ASSERT_TRUE(pass_.StartListening()); {