diff options
author | 2024-06-22 15:41:53 -0700 | |
---|---|---|
committer | 2024-07-07 10:58:27 -0700 | |
commit | 2bf4c772393460d1830fbed203a65197e5999a6c (patch) | |
tree | a2d42bfe5193ec7a603aa2b540beae56ed6493cf /tools | |
parent | ace0cd51f43c3b1f8709ae962899b3f539cb0965 (diff) |
Format: apply clang rules
Restore SpacesBeforeTrailingComments to 2 to match current style
Then run clang-format -i **/**.{c,h,cc,cpp,hpp}
Then fix a bunch of typo (reported by gerrit)
Then fix unnecessary multiline string
Then fix whitespace for disabled clang format (reported by cpplint)
This is no-op
Bug: 311772251
Test: mmm packages/modules/Bluetooth
Flag: Exempt Format only
Change-Id: If135447803a40a2a07d4630ba2195e08ef8d250c
Diffstat (limited to 'tools')
119 files changed, 6628 insertions, 8904 deletions
diff --git a/tools/rootcanal/desktop/root_canal_main.cc b/tools/rootcanal/desktop/root_canal_main.cc index 20be4b9080..fde5560fbe 100644 --- a/tools/rootcanal/desktop/root_canal_main.cc +++ b/tools/rootcanal/desktop/root_canal_main.cc @@ -41,36 +41,28 @@ 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"); DEFINE_uint32(link_ble_port, 6404, "le link server tcp port"); -extern "C" const char* __asan_default_options() { - return "detect_container_overflow=0"; -} +extern "C" const char* __asan_default_options() { return "detect_container_overflow=0"; } -bool crash_callback(const void* crash_context, size_t crash_context_size, - void* /* context */) { +bool crash_callback(const void* crash_context, size_t crash_context_size, void* /* context */) { std::optional<pid_t> tid; - if (crash_context_size >= - sizeof(google_breakpad::ExceptionHandler::CrashContext)) { - auto* ctx = - static_cast<const google_breakpad::ExceptionHandler::CrashContext*>( - crash_context); + if (crash_context_size >= sizeof(google_breakpad::ExceptionHandler::CrashContext)) { + auto* ctx = static_cast<const google_breakpad::ExceptionHandler::CrashContext*>(crash_context); tid = ctx->tid; int signal_number = ctx->siginfo.si_signo; - ERROR("Process crashed, signal: {}[{}], tid: {}", strsignal(signal_number), - signal_number, ctx->tid); + ERROR("Process crashed, signal: {}[{}], tid: {}", strsignal(signal_number), signal_number, + ctx->tid); } else { ERROR("Process crashed, signal: unknown, tid: unknown"); } @@ -89,9 +81,8 @@ bool crash_callback(const void* crash_context, size_t crash_context_size, int main(int argc, char** argv) { google_breakpad::MinidumpDescriptor descriptor( - google_breakpad::MinidumpDescriptor::kMicrodumpOnConsole); - google_breakpad::ExceptionHandler eh(descriptor, nullptr, nullptr, nullptr, - true, -1); + google_breakpad::MinidumpDescriptor::kMicrodumpOnConsole); + google_breakpad::ExceptionHandler eh(descriptor, nullptr, nullptr, nullptr, true, -1); eh.set_crash_handler(crash_callback); gflags::ParseCommandLineFlags(&argc, &argv, true); @@ -130,17 +121,14 @@ int main(int argc, char** argv) { } TestEnvironment root_canal( - [](AsyncManager* am, int port) { - return std::make_shared<PosixAsyncSocketServer>(port, am); - }, - [](AsyncManager* am) { - return std::make_shared<PosixAsyncSocketConnector>(am); - }, - static_cast<int>(FLAGS_test_port), static_cast<int>(FLAGS_hci_port), - static_cast<int>(FLAGS_link_port), static_cast<int>(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<PosixAsyncSocketServer>(port, am); + }, + [](AsyncManager* am) { return std::make_shared<PosixAsyncSocketConnector>(am); }, + static_cast<int>(FLAGS_test_port), static_cast<int>(FLAGS_hci_port), + static_cast<int>(FLAGS_link_port), static_cast<int>(FLAGS_link_ble_port), + configuration_str, FLAGS_enable_hci_sniffer, FLAGS_enable_baseband_sniffer, + FLAGS_enable_pcap_filter, FLAGS_disable_address_reuse); std::promise<void> barrier; std::future<void> barrier_future = barrier.get_future(); diff --git a/tools/rootcanal/desktop/test_environment.cc b/tools/rootcanal/desktop/test_environment.cc index 512bab20eb..91eae8a3e5 100644 --- a/tools/rootcanal/desktop/test_environment.cc +++ b/tools/rootcanal/desktop/test_environment.cc @@ -56,14 +56,11 @@ using rootcanal::LinkLayerSocketDevice; using rootcanal::TaskCallback; TestEnvironment::TestEnvironment( - std::function<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> - open_server, - std::function<std::shared_ptr<AsyncDataChannelConnector>(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<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> open_server, + std::function<std::shared_ptr<AsyncDataChannelConnector>(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<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> - open_server, - int tcp_port, rootcanal::ControllerProperties properties) { + std::function<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> open_server, + int tcp_port, rootcanal::ControllerProperties properties) { INFO("Opening an HCI with port {}", tcp_port); - std::shared_ptr<AsyncDataChannelServer> server = - open_server(&async_manager_, tcp_port); - server->SetOnConnectCallback([this, properties = std::move(properties)]( - std::shared_ptr<AsyncDataChannel> 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<std::ofstream>(filename, std::ios::binary); - auto sniffer = std::static_pointer_cast<HciSniffer>(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<rootcanal::PcapFilter>()); - } - } - }); + std::shared_ptr<AsyncDataChannelServer> server = open_server(&async_manager_, tcp_port); + server->SetOnConnectCallback( + [this, properties = std::move(properties)](std::shared_ptr<AsyncDataChannel> 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<std::ofstream>(filename, std::ios::binary); + auto sniffer = std::static_pointer_cast<HciSniffer>(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<rootcanal::PcapFilter>()); + } + } + }); - server->StartListening(); - }); + server->StartListening(); + }); hci_socket_servers_.emplace_back(std::move(server)); } @@ -153,17 +144,16 @@ void TestEnvironment::initialize(std::promise<void> barrier) { barrier_ = std::move(barrier); - test_channel_transport_.RegisterCommandHandler( - [this](const std::string& name, const std::vector<std::string>& 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<std::string>& 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<void> 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<AsyncDataChannel> 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<AsyncDataChannel> 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<AsyncDataChannel> 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<AsyncDataChannel> 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<Device> TestEnvironment::ConnectToRemoteServer( - const std::string& server, int port, Phy::Type phy_type) { +std::shared_ptr<Device> 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<Device> TestEnvironment::ConnectToRemoteServer( void TestEnvironment::SetUpTestChannel() { bool transport_configured = test_channel_transport_.SetUp( - test_socket_server_, [this](std::shared_ptr<AsyncDataChannel> 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<AsyncDataChannel> 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/tools/rootcanal/desktop/test_environment.h b/tools/rootcanal/desktop/test_environment.h index 5947d07571..7f15811c89 100644 --- a/tools/rootcanal/desktop/test_environment.h +++ b/tools/rootcanal/desktop/test_environment.h @@ -47,21 +47,19 @@ using rootcanal::Device; using rootcanal::Phy; class TestEnvironment { - public: +public: TestEnvironment( - std::function<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> - open_server, - std::function<std::shared_ptr<AsyncDataChannelConnector>(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<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> open_server, + std::function<std::shared_ptr<AsyncDataChannelConnector>(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<void> barrier); void close(); - private: +private: rootcanal::AsyncManager async_manager_; rootcanal::TestChannelTransport test_channel_transport_; std::shared_ptr<AsyncDataChannelServer> test_socket_server_; @@ -78,40 +76,33 @@ class TestEnvironment { void SetUpTestChannel(); void SetUpHciServer( - std::function<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> - open_server, - int tcp_port, rootcanal::ControllerProperties properties); + std::function<std::shared_ptr<AsyncDataChannelServer>(AsyncManager*, int)> open_server, + int tcp_port, rootcanal::ControllerProperties properties); void SetUpLinkLayerServer(); void SetUpLinkBleLayerServer(); - std::shared_ptr<Device> ConnectToRemoteServer(const std::string& server, - int port, Phy::Type phy_type); + std::shared_ptr<Device> 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/tools/rootcanal/hal/bluetooth_hci.cc b/tools/rootcanal/hal/bluetooth_hci.cc index 7cea46b097..b08d59995b 100644 --- a/tools/rootcanal/hal/bluetooth_hci.cc +++ b/tools/rootcanal/hal/bluetooth_hci.cc @@ -54,12 +54,11 @@ bool BtTestConsoleEnabled() { } // namespace class BluetoothDeathRecipient : public hidl_death_recipient { - public: +public: BluetoothDeathRecipient(const sp<IBluetoothHci> hci) : mHci(hci) {} - void serviceDied( - uint64_t /* cookie */, - const wp<::android::hidl::base::V1_0::IBase>& /* who */) override { + void serviceDied(uint64_t /* cookie */, + const wp<::android::hidl::base::V1_0::IBase>& /* who */) override { ALOGE("BluetoothDeathRecipient::serviceDied - Bluetooth service died"); has_died_ = true; mHci->close(); @@ -68,26 +67,22 @@ class BluetoothDeathRecipient : public hidl_death_recipient { bool getHasDied() const { return has_died_; } void setHasDied(bool has_died) { has_died_ = has_died; } - private: +private: bool has_died_{false}; }; -BluetoothHci::BluetoothHci() - : death_recipient_(new BluetoothDeathRecipient(this)) {} +BluetoothHci::BluetoothHci() : death_recipient_(new BluetoothDeathRecipient(this)) {} -Return<void> BluetoothHci::initialize( - const sp<V1_0::IBluetoothHciCallbacks>& cb) { +Return<void> BluetoothHci::initialize(const sp<V1_0::IBluetoothHciCallbacks>& cb) { return initialize_impl(cb, nullptr); } -Return<void> BluetoothHci::initialize_1_1( - const sp<V1_1::IBluetoothHciCallbacks>& cb) { +Return<void> BluetoothHci::initialize_1_1(const sp<V1_1::IBluetoothHciCallbacks>& cb) { return initialize_impl(cb, cb); } -Return<void> BluetoothHci::initialize_impl( - const sp<V1_0::IBluetoothHciCallbacks>& cb, - const sp<V1_1::IBluetoothHciCallbacks>& cb_1_1) { +Return<void> BluetoothHci::initialize_impl(const sp<V1_0::IBluetoothHciCallbacks>& cb, + const sp<V1_1::IBluetoothHciCallbacks>& cb_1_1) { ALOGI("%s", __func__); if (cb == nullptr) { ALOGE("cb == nullptr! -> Unable to call initializationComplete(ERR)"); @@ -98,18 +93,16 @@ Return<void> BluetoothHci::initialize_impl( auto link_ret = cb->linkToDeath(death_recipient_, 0); ALOG_ASSERT(link_ret.isOk(), "Error calling linkToDeath."); - test_channel_transport_.RegisterCommandHandler( - [this](const std::string& name, const std::vector<std::string>& args) { - async_manager_.ExecAsync( - user_id_, std::chrono::milliseconds(0), - [this, name, args]() { test_channel_.HandleCommand(name, args); }); - }); + test_channel_transport_.RegisterCommandHandler([this](const std::string& name, + const std::vector<std::string>& args) { + async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), + [this, name, args]() { test_channel_.HandleCommand(name, args); }); + }); controller_ = std::make_shared<DualModeController>(); char mac_property[PROPERTY_VALUE_MAX] = ""; - property_get("vendor.bt.rootcanal_mac_address", mac_property, - "3C:5A:B4:01:02:03"); + property_get("vendor.bt.rootcanal_mac_address", mac_property, "3C:5A:B4:01:02:03"); auto addr = Address::FromString(std::string(mac_property)); if (addr) { controller_->SetAddress(*addr); @@ -117,64 +110,59 @@ Return<void> BluetoothHci::initialize_impl( LOG_ALWAYS_FATAL("Invalid address: %s", mac_property); } - controller_->RegisterEventChannel( - [this, cb](std::shared_ptr<std::vector<uint8_t>> packet) { - hidl_vec<uint8_t> hci_event(packet->begin(), packet->end()); - auto ret = cb->hciEventReceived(hci_event); - if (!ret.isOk()) { - ALOGE("Error sending event callback"); - if (!death_recipient_->getHasDied()) { - ALOGE("Closing"); - close(); - } - } - }); - - controller_->RegisterAclChannel( - [this, cb](std::shared_ptr<std::vector<uint8_t>> packet) { - hidl_vec<uint8_t> acl_packet(packet->begin(), packet->end()); - auto ret = cb->aclDataReceived(acl_packet); - if (!ret.isOk()) { - ALOGE("Error sending acl callback"); - if (!death_recipient_->getHasDied()) { - ALOGE("Closing"); - close(); - } - } - }); - - controller_->RegisterScoChannel( - [this, cb](std::shared_ptr<std::vector<uint8_t>> packet) { - hidl_vec<uint8_t> sco_packet(packet->begin(), packet->end()); - auto ret = cb->scoDataReceived(sco_packet); - if (!ret.isOk()) { - ALOGE("Error sending sco callback"); - if (!death_recipient_->getHasDied()) { - ALOGE("Closing"); - close(); - } - } - }); + controller_->RegisterEventChannel([this, cb](std::shared_ptr<std::vector<uint8_t>> packet) { + hidl_vec<uint8_t> hci_event(packet->begin(), packet->end()); + auto ret = cb->hciEventReceived(hci_event); + if (!ret.isOk()) { + ALOGE("Error sending event callback"); + if (!death_recipient_->getHasDied()) { + ALOGE("Closing"); + close(); + } + } + }); + + controller_->RegisterAclChannel([this, cb](std::shared_ptr<std::vector<uint8_t>> packet) { + hidl_vec<uint8_t> acl_packet(packet->begin(), packet->end()); + auto ret = cb->aclDataReceived(acl_packet); + if (!ret.isOk()) { + ALOGE("Error sending acl callback"); + if (!death_recipient_->getHasDied()) { + ALOGE("Closing"); + close(); + } + } + }); + + controller_->RegisterScoChannel([this, cb](std::shared_ptr<std::vector<uint8_t>> packet) { + hidl_vec<uint8_t> sco_packet(packet->begin(), packet->end()); + auto ret = cb->scoDataReceived(sco_packet); + if (!ret.isOk()) { + ALOGE("Error sending sco callback"); + if (!death_recipient_->getHasDied()) { + ALOGE("Closing"); + close(); + } + } + }); if (cb_1_1 != nullptr) { - controller_->RegisterIsoChannel( - [this, cb_1_1](std::shared_ptr<std::vector<uint8_t>> packet) { - hidl_vec<uint8_t> iso_packet(packet->begin(), packet->end()); - auto ret = cb_1_1->isoDataReceived(iso_packet); - if (!ret.isOk()) { - ALOGE("Error sending iso callback"); - if (!death_recipient_->getHasDied()) { - ALOGE("Closing"); - close(); - } - } - }); + controller_->RegisterIsoChannel([this, cb_1_1](std::shared_ptr<std::vector<uint8_t>> packet) { + hidl_vec<uint8_t> iso_packet(packet->begin(), packet->end()); + auto ret = cb_1_1->isoDataReceived(iso_packet); + if (!ret.isOk()) { + ALOGE("Error sending iso callback"); + if (!death_recipient_->getHasDied()) { + ALOGE("Closing"); + close(); + } + } + }); } // Add the controller as a device in the model. size_t controller_index = test_model_.AddDevice(controller_); - size_t low_energy_phy_index = - test_model_.AddPhy(rootcanal::Phy::Type::LOW_ENERGY); + size_t low_energy_phy_index = test_model_.AddPhy(rootcanal::Phy::Type::LOW_ENERGY); size_t classic_phy_index = test_model_.AddPhy(rootcanal::Phy::Type::BR_EDR); test_model_.AddDeviceToPhy(controller_index, low_energy_phy_index); test_model_.AddDeviceToPhy(controller_index, classic_phy_index); @@ -182,32 +170,24 @@ Return<void> BluetoothHci::initialize_impl( test_model_.StartTimer(); // Send responses to logcat if the test channel is not configured. - test_channel_.RegisterSendResponse([](const std::string& response) { - ALOGI("No test channel yet: %s", response.c_str()); - }); + test_channel_.RegisterSendResponse( + [](const std::string& response) { ALOGI("No test channel yet: %s", response.c_str()); }); if (BtTestConsoleEnabled()) { - test_socket_server_ = - std::make_shared<net::PosixAsyncSocketServer>(6111, &async_manager_); - hci_socket_server_ = - std::make_shared<net::PosixAsyncSocketServer>(6211, &async_manager_); - link_socket_server_ = - std::make_shared<net::PosixAsyncSocketServer>(6311, &async_manager_); - connector_ = - std::make_shared<net::PosixAsyncSocketConnector>(&async_manager_); + test_socket_server_ = std::make_shared<net::PosixAsyncSocketServer>(6111, &async_manager_); + hci_socket_server_ = std::make_shared<net::PosixAsyncSocketServer>(6211, &async_manager_); + link_socket_server_ = std::make_shared<net::PosixAsyncSocketServer>(6311, &async_manager_); + connector_ = std::make_shared<net::PosixAsyncSocketConnector>(&async_manager_); SetUpTestChannel(); - SetUpHciServer([this](std::shared_ptr<AsyncDataChannel> socket, - AsyncDataChannelServer* srv) { + SetUpHciServer([this](std::shared_ptr<AsyncDataChannel> socket, AsyncDataChannelServer* srv) { auto transport = HciSocketTransport::Create(socket); - test_model_.AddHciConnection( - HciDevice::Create(transport, rootcanal::ControllerProperties())); + test_model_.AddHciConnection(HciDevice::Create(transport, rootcanal::ControllerProperties())); srv->StartListening(); }); SetUpLinkLayerServer([this](std::shared_ptr<AsyncDataChannel> socket, AsyncDataChannelServer* srv) { auto phy_type = Phy::Type::BR_EDR; - test_model_.AddLinkLayerConnection( - LinkLayerSocketDevice::Create(socket, phy_type), phy_type); + test_model_.AddLinkLayerConnection(LinkLayerSocketDevice::Create(socket, phy_type), phy_type); srv->StartListening(); }); } else { @@ -217,18 +197,17 @@ Return<void> BluetoothHci::initialize_impl( test_model_.AddDeviceToPhy(controller_index + 1, low_energy_phy_index); test_channel_.AddDevice({"beacon", "be:ac:10:00:00:02", "1000"}); test_model_.AddDeviceToPhy(controller_index + 2, low_energy_phy_index); - test_channel_.AddDevice( - {"scripted_beacon", "5b:ea:c1:00:00:03", - "/data/vendor/bluetooth/bluetooth_sim_ble_playback_file", - "/data/vendor/bluetooth/bluetooth_sim_ble_playback_events"}); + test_channel_.AddDevice({"scripted_beacon", "5b:ea:c1:00:00:03", + "/data/vendor/bluetooth/bluetooth_sim_ble_playback_file", + "/data/vendor/bluetooth/bluetooth_sim_ble_playback_events"}); test_model_.AddDeviceToPhy(controller_index + 3, low_energy_phy_index); test_channel_.List({}); } unlink_cb_ = [cb](sp<BluetoothDeathRecipient>& death_recipient) { - if (death_recipient->getHasDied()) + if (death_recipient->getHasDied()) { ALOGI("Skipping unlink call, service died."); - else { + } else { auto ret = cb->unlinkToDeath(death_recipient); if (!ret.isOk()) { ALOG_ASSERT(death_recipient_->getHasDied(), @@ -252,46 +231,38 @@ Return<void> BluetoothHci::close() { } Return<void> BluetoothHci::sendHciCommand(const hidl_vec<uint8_t>& packet) { - async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), - [this, packet]() { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::shared_ptr<std::vector<uint8_t>>( - new std::vector<uint8_t>(packet)); - controller_->HandleCommand(packet_copy); - }); + async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), [this, packet]() { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::shared_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>(packet)); + controller_->HandleCommand(packet_copy); + }); return Void(); } Return<void> BluetoothHci::sendAclData(const hidl_vec<uint8_t>& packet) { - async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), - [this, packet]() { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::shared_ptr<std::vector<uint8_t>>( - new std::vector<uint8_t>(packet)); - controller_->HandleAcl(packet_copy); - }); + async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), [this, packet]() { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::shared_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>(packet)); + controller_->HandleAcl(packet_copy); + }); return Void(); } Return<void> BluetoothHci::sendScoData(const hidl_vec<uint8_t>& packet) { - async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), - [this, packet]() { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::shared_ptr<std::vector<uint8_t>>( - new std::vector<uint8_t>(packet)); - controller_->HandleSco(packet_copy); - }); + async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), [this, packet]() { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::shared_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>(packet)); + controller_->HandleSco(packet_copy); + }); return Void(); } Return<void> BluetoothHci::sendIsoData(const hidl_vec<uint8_t>& packet) { - async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), - [this, packet]() { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::shared_ptr<std::vector<uint8_t>>( - new std::vector<uint8_t>(packet)); - controller_->HandleIso(packet_copy); - }); + async_manager_.ExecAsync(user_id_, std::chrono::milliseconds(0), [this, packet]() { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::shared_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>(packet)); + controller_->HandleIso(packet_copy); + }); return Void(); } @@ -314,31 +285,31 @@ void BluetoothHci::SetUpLinkLayerServer(ConnectCallback connection_callback) { }); } -std::shared_ptr<Device> BluetoothHci::ConnectToRemoteServer( - const std::string& server, int port, Phy::Type phy_type) { +std::shared_ptr<Device> BluetoothHci::ConnectToRemoteServer(const std::string& server, int port, + Phy::Type phy_type) { auto socket = connector_->ConnectToRemoteServer(server, port); - if (!socket->Connected()) return nullptr; + if (!socket->Connected()) { + return nullptr; + } return LinkLayerSocketDevice::Create(socket, phy_type); } void BluetoothHci::SetUpTestChannel() { bool transport_configured = test_channel_transport_.SetUp( - test_socket_server_, [this](std::shared_ptr<AsyncDataChannel> conn_fd, - AsyncDataChannelServer*) { - ALOGI("Test channel connection accepted."); - test_channel_.RegisterSendResponse( - [this, conn_fd](const std::string& response) { + test_socket_server_, + [this](std::shared_ptr<AsyncDataChannel> conn_fd, AsyncDataChannelServer*) { + ALOGI("Test channel connection accepted."); + test_channel_.RegisterSendResponse([this, conn_fd](const std::string& response) { test_channel_transport_.SendResponse(conn_fd, response); }); - conn_fd->WatchForNonBlockingRead([this](AsyncDataChannel* conn_fd) { - test_channel_transport_.OnCommandReady(conn_fd, []() {}); - }); - return false; - }); - test_channel_.RegisterSendResponse([](const std::string& response) { - ALOGI("No test channel: %s", response.c_str()); - }); + conn_fd->WatchForNonBlockingRead([this](AsyncDataChannel* conn_fd) { + test_channel_transport_.OnCommandReady(conn_fd, []() {}); + }); + return false; + }); + test_channel_.RegisterSendResponse( + [](const std::string& response) { ALOGI("No test channel: %s", response.c_str()); }); if (!transport_configured) { ALOGE("Test channel SetUp failed."); @@ -349,9 +320,7 @@ void BluetoothHci::SetUpTestChannel() { } /* Fallback to shared library if there is no service. */ -IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) { - return new BluetoothHci(); -} +IBluetoothHci* HIDL_FETCH_IBluetoothHci(const char* /* name */) { return new BluetoothHci(); } } // namespace sim } // namespace V1_1 diff --git a/tools/rootcanal/hal/bluetooth_hci.h b/tools/rootcanal/hal/bluetooth_hci.h index 374542177d..95bda38957 100644 --- a/tools/rootcanal/hal/bluetooth_hci.h +++ b/tools/rootcanal/hal/bluetooth_hci.h @@ -45,25 +45,24 @@ using rootcanal::Device; using rootcanal::Phy; class BluetoothHci : public IBluetoothHci { - public: +public: BluetoothHci(); - ::android::hardware::Return<void> initialize( - const sp<V1_0::IBluetoothHciCallbacks>& cb) override; + ::android::hardware::Return<void> initialize(const sp<V1_0::IBluetoothHciCallbacks>& cb) override; ::android::hardware::Return<void> initialize_1_1( - const sp<V1_1::IBluetoothHciCallbacks>& cb) override; + const sp<V1_1::IBluetoothHciCallbacks>& cb) override; ::android::hardware::Return<void> sendHciCommand( - const ::android::hardware::hidl_vec<uint8_t>& packet) override; + const ::android::hardware::hidl_vec<uint8_t>& packet) override; ::android::hardware::Return<void> sendAclData( - const ::android::hardware::hidl_vec<uint8_t>& packet) override; + const ::android::hardware::hidl_vec<uint8_t>& packet) override; ::android::hardware::Return<void> sendScoData( - const ::android::hardware::hidl_vec<uint8_t>& packet) override; + const ::android::hardware::hidl_vec<uint8_t>& packet) override; ::android::hardware::Return<void> sendIsoData( - const ::android::hardware::hidl_vec<uint8_t>& packet) override; + const ::android::hardware::hidl_vec<uint8_t>& packet) override; ::android::hardware::Return<void> close() override; @@ -71,10 +70,9 @@ class BluetoothHci : public IBluetoothHci { static BluetoothHci* get(); - private: - ::android::hardware::Return<void> initialize_impl( - const sp<V1_0::IBluetoothHciCallbacks>& cb, - const sp<V1_1::IBluetoothHciCallbacks>& cb_1_1); +private: + ::android::hardware::Return<void> initialize_impl(const sp<V1_0::IBluetoothHciCallbacks>& cb, + const sp<V1_1::IBluetoothHciCallbacks>& cb_1_1); sp<BluetoothDeathRecipient> death_recipient_; @@ -91,8 +89,8 @@ class BluetoothHci : public IBluetoothHci { void SetUpTestChannel(); void SetUpHciServer(ConnectCallback on_connect); void SetUpLinkLayerServer(ConnectCallback on_connect); - std::shared_ptr<Device> ConnectToRemoteServer(const std::string& server, - int port, Phy::Type phy_type); + std::shared_ptr<Device> ConnectToRemoteServer(const std::string& server, int port, + Phy::Type phy_type); std::shared_ptr<rootcanal::DualModeController> controller_; @@ -102,30 +100,24 @@ class BluetoothHci : public IBluetoothHci { rootcanal::AsyncUserId user_id_ = async_manager_.GetNextUserId(); 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/tools/rootcanal/hal/service.cc b/tools/rootcanal/hal/service.cc index cef8fe72de..8e4ba1caae 100644 --- a/tools/rootcanal/hal/service.cc +++ b/tools/rootcanal/hal/service.cc @@ -33,8 +33,9 @@ int main(int /* argc */, char** /* argv */) { sp<IBluetoothHci> bluetooth = new BluetoothHci; configureRpcThreadpool(1, true); android::status_t status = bluetooth->registerAsService(); - if (status == android::OK) + if (status == android::OK) { joinRpcThreadpool(); - else + } else { ALOGE("Could not register as a service!"); + } } diff --git a/tools/rootcanal/include/crypto/crypto.h b/tools/rootcanal/include/crypto/crypto.h index f73d0f23ef..6249b16592 100644 --- a/tools/rootcanal/include/crypto/crypto.h +++ b/tools/rootcanal/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/tools/rootcanal/include/hci/address.h b/tools/rootcanal/include/hci/address.h index 18b38ee8d3..fe4d454d5d 100644 --- a/tools/rootcanal/include/hci/address.h +++ b/tools/rootcanal/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<bluetooth::hci::Address> { 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<bluetooth::hci::Address> { // 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/tools/rootcanal/include/hci/address_with_type.h b/tools/rootcanal/include/hci/address_with_type.h index 65c4223ef2..1172ac7fa2 100644 --- a/tools/rootcanal/include/hci/address_with_type.h +++ b/tools/rootcanal/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<bluetooth::hci::AddressWithType> { 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<bluetooth::hci::AddressWithType> { // 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/tools/rootcanal/include/hci/pcap_filter.h b/tools/rootcanal/include/hci/pcap_filter.h index 1731ce866d..64f55f57bb 100644 --- a/tools/rootcanal/include/hci/pcap_filter.h +++ b/tools/rootcanal/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<uint8_t> FilterHciPacket(std::vector<uint8_t> const& packet, - uint8_t idc); + std::vector<uint8_t> FilterHciPacket(std::vector<uint8_t> const& packet, uint8_t idc); std::vector<uint8_t> FilterHciCommand(std::vector<uint8_t> const& packet); std::vector<uint8_t> FilterHciEvent(std::vector<uint8_t> const& packet); // Specific filters for HCI commands. - std::vector<uint8_t> FilterWriteLocalName( - bluetooth::hci::CommandView& command); - std::vector<uint8_t> FilterWriteExtendedInquiryResponse( - bluetooth::hci::CommandView& command); - std::vector<uint8_t> FilterLeSetAdvertisingData( - bluetooth::hci::CommandView& command); - std::vector<uint8_t> FilterLeSetScanResponseData( - bluetooth::hci::CommandView& command); - std::vector<uint8_t> FilterLeSetExtendedAdvertisingData( - bluetooth::hci::CommandView& command); - std::vector<uint8_t> FilterLeSetExtendedScanResponseData( - bluetooth::hci::CommandView& command); - std::vector<uint8_t> FilterLeSetPeriodicAdvertisingData( - bluetooth::hci::CommandView& command); + std::vector<uint8_t> FilterWriteLocalName(bluetooth::hci::CommandView& command); + std::vector<uint8_t> FilterWriteExtendedInquiryResponse(bluetooth::hci::CommandView& command); + std::vector<uint8_t> FilterLeSetAdvertisingData(bluetooth::hci::CommandView& command); + std::vector<uint8_t> FilterLeSetScanResponseData(bluetooth::hci::CommandView& command); + std::vector<uint8_t> FilterLeSetExtendedAdvertisingData(bluetooth::hci::CommandView& command); + std::vector<uint8_t> FilterLeSetExtendedScanResponseData(bluetooth::hci::CommandView& command); + std::vector<uint8_t> FilterLeSetPeriodicAdvertisingData(bluetooth::hci::CommandView& command); // Specific filters for HCI events. std::vector<uint8_t> FilterReadLocalNameComplete( - bluetooth::hci::CommandCompleteView& command_complete); + bluetooth::hci::CommandCompleteView& command_complete); std::vector<uint8_t> FilterReadExtendedInquiryResponseComplete( - bluetooth::hci::CommandCompleteView& command_complete); - std::vector<uint8_t> FilterRemoteNameRequestComplete( - bluetooth::hci::EventView& event); - std::vector<uint8_t> FilterExtendedInquiryResult( - bluetooth::hci::EventView& event); - std::vector<uint8_t> FilterLeAdvertisingReport( - bluetooth::hci::LeMetaEventView& event); - std::vector<uint8_t> FilterLeExtendedAdvertisingReport( - bluetooth::hci::LeMetaEventView& event); + bluetooth::hci::CommandCompleteView& command_complete); + std::vector<uint8_t> FilterRemoteNameRequestComplete(bluetooth::hci::EventView& event); + std::vector<uint8_t> FilterExtendedInquiryResult(bluetooth::hci::EventView& event); + std::vector<uint8_t> FilterLeAdvertisingReport(bluetooth::hci::LeMetaEventView& event); + std::vector<uint8_t> 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<uint8_t>& gap_data); // Helpers to replace local names. - std::array<uint8_t, 248> ChangeDeviceName( - std::array<uint8_t, 248> const& device_name); - std::vector<uint8_t> ChangeDeviceName( - std::vector<uint8_t> const& device_name); + std::array<uint8_t, 248> ChangeDeviceName(std::array<uint8_t, 248> const& device_name); + std::vector<uint8_t> ChangeDeviceName(std::vector<uint8_t> const& device_name); - private: +private: // Map device names to anonymous replacements. - std::vector<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> - device_name_map{}; + std::vector<std::pair<std::vector<uint8_t>, std::vector<uint8_t>>> device_name_map{}; }; } // namespace rootcanal diff --git a/tools/rootcanal/include/log.h b/tools/rootcanal/include/log.h index 130800ae9a..9367f5bc7a 100644 --- a/tools/rootcanal/include/log.h +++ b/tools/rootcanal/include/log.h @@ -34,13 +34,12 @@ enum Verbosity { void SetLogColorEnable(bool); -void VLog(Verbosity verb, char const* file, int line, - std::optional<int> instance, char const* format, - fmt::format_args args); +void VLog(Verbosity verb, char const* file, int line, std::optional<int> instance, + char const* format, fmt::format_args args); template <typename... Args> -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/tools/rootcanal/include/phy.h b/tools/rootcanal/include/phy.h index 1e82c1515a..5f25fa238e 100644 --- a/tools/rootcanal/include/phy.h +++ b/tools/rootcanal/include/phy.h @@ -19,7 +19,7 @@ namespace rootcanal { class Phy { - public: +public: enum class Type { LOW_ENERGY, BR_EDR, diff --git a/tools/rootcanal/lib/hci/address.cc b/tools/rootcanal/lib/hci/address.cc index 3f9103c80f..fa85501c52 100644 --- a/tools/rootcanal/lib/hci/address.cc +++ b/tools/rootcanal/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<uint8_t, kLength> const& address) - : address(address) {} +constexpr Address::Address(std::array<uint8_t, kLength> 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<uint8_t, kLength> address{ - input.read_le<uint8_t>(), input.read_le<uint8_t>(), - input.read_le<uint8_t>(), input.read_le<uint8_t>(), - input.read_le<uint8_t>(), input.read_le<uint8_t>(), + input.read_le<uint8_t>(), input.read_le<uint8_t>(), input.read_le<uint8_t>(), + input.read_le<uint8_t>(), input.read_le<uint8_t>(), input.read_le<uint8_t>(), }; *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/tools/rootcanal/lib/hci/pcap_filter.cc b/tools/rootcanal/lib/hci/pcap_filter.cc index 4a05da0fdd..ca14ef03c7 100644 --- a/tools/rootcanal/lib/hci/pcap_filter.cc +++ b/tools/rootcanal/lib/hci/pcap_filter.cc @@ -35,21 +35,19 @@ using namespace bluetooth::hci; namespace rootcanal { -static pdl::packet::slice create_packet_view( - std::vector<uint8_t> const& packet) { +static pdl::packet::slice create_packet_view(std::vector<uint8_t> 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<std::vector<uint8_t> const>( - &packet, [](std::vector<uint8_t> const* /* ptr */) {})); + &packet, [](std::vector<uint8_t> const* /* ptr */) {})); } static std::vector<uint8_t> FilterHciAcl(std::vector<uint8_t> const& packet); static std::vector<uint8_t> FilterHciSco(std::vector<uint8_t> const& packet); static std::vector<uint8_t> FilterHciIso(std::vector<uint8_t> const& packet); -std::vector<uint8_t> PcapFilter::FilterHciPacket( - std::vector<uint8_t> const& packet, uint8_t idc) { +std::vector<uint8_t> PcapFilter::FilterHciPacket(std::vector<uint8_t> const& packet, uint8_t idc) { switch (idc) { case 0x1: return FilterHciCommand(packet); @@ -67,8 +65,7 @@ std::vector<uint8_t> PcapFilter::FilterHciPacket( return std::vector<uint8_t>(packet); } -std::vector<uint8_t> PcapFilter::FilterHciCommand( - std::vector<uint8_t> const& packet) { +std::vector<uint8_t> PcapFilter::FilterHciCommand(std::vector<uint8_t> const& packet) { auto command = CommandView::Create(create_packet_view(packet)); ASSERT(command.IsValid()); switch (command.GetOpCode()) { @@ -92,8 +89,7 @@ std::vector<uint8_t> PcapFilter::FilterHciCommand( return std::vector<uint8_t>(packet); } -std::vector<uint8_t> PcapFilter::FilterHciEvent( - std::vector<uint8_t> const& packet) { +std::vector<uint8_t> PcapFilter::FilterHciEvent(std::vector<uint8_t> const& packet) { auto event = EventView::Create(create_packet_view(packet)); ASSERT(event.IsValid()); switch (event.GetEventCode()) { @@ -138,9 +134,9 @@ static std::vector<uint8_t> FilterHciAcl(std::vector<uint8_t> const& packet) { std::vector<uint8_t> 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<uint8_t> FilterHciSco(std::vector<uint8_t> const& packet) { @@ -148,8 +144,7 @@ static std::vector<uint8_t> FilterHciSco(std::vector<uint8_t> const& packet) { std::vector<uint8_t> 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<uint8_t> FilterHciIso(std::vector<uint8_t> const& packet) { @@ -157,9 +152,9 @@ static std::vector<uint8_t> FilterHciIso(std::vector<uint8_t> const& packet) { std::vector<uint8_t> 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<uint8_t> new_name = - ChangeDeviceName(std::vector<uint8_t>{start_pos, end_pos}); + std::vector<uint8_t> new_name = ChangeDeviceName(std::vector<uint8_t>{start_pos, end_pos}); std::copy(new_name.begin(), new_name.end(), start_pos); break; } @@ -212,97 +206,86 @@ std::vector<uint8_t> PcapFilter::FilterWriteLocalName(CommandView& command) { auto parameters = WriteLocalNameView::Create(command); ASSERT(parameters.IsValid()); - std::array<uint8_t, 248> local_name = - ChangeDeviceName(parameters.GetLocalName()); + std::array<uint8_t, 248> 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<uint8_t> PcapFilter::FilterWriteExtendedInquiryResponse( - CommandView& command) { +std::vector<uint8_t> PcapFilter::FilterWriteExtendedInquiryResponse(CommandView& command) { auto parameters = WriteExtendedInquiryResponseView::Create(command); ASSERT(parameters.IsValid()); - std::array<uint8_t, 240> 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<uint8_t, 240> 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<uint8_t> PcapFilter::FilterLeSetAdvertisingData( - CommandView& command) { +std::vector<uint8_t> PcapFilter::FilterLeSetAdvertisingData(CommandView& command) { auto parameters = LeSetAdvertisingDataView::Create(command); ASSERT(parameters.IsValid()); std::vector<uint8_t> 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<uint8_t> PcapFilter::FilterLeSetScanResponseData( - CommandView& command) { +std::vector<uint8_t> PcapFilter::FilterLeSetScanResponseData(CommandView& command) { auto parameters = LeSetScanResponseDataView::Create(command); ASSERT(parameters.IsValid()); std::vector<uint8_t> 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<uint8_t> PcapFilter::FilterLeSetExtendedAdvertisingData( - CommandView& command) { +std::vector<uint8_t> PcapFilter::FilterLeSetExtendedAdvertisingData(CommandView& command) { auto parameters = LeSetExtendedAdvertisingDataView::Create(command); ASSERT(parameters.IsValid()); std::vector<uint8_t> 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<uint8_t> PcapFilter::FilterLeSetExtendedScanResponseData( - CommandView& command) { +std::vector<uint8_t> PcapFilter::FilterLeSetExtendedScanResponseData(CommandView& command) { auto parameters = LeSetExtendedScanResponseDataView::Create(command); ASSERT(parameters.IsValid()); std::vector<uint8_t> 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<uint8_t> PcapFilter::FilterLeSetPeriodicAdvertisingData( - bluetooth::hci::CommandView& command) { + bluetooth::hci::CommandView& command) { auto parameters = LeSetPeriodicAdvertisingDataView::Create(command); ASSERT(parameters.IsValid()); std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t, 240> extended_inquiry_response = - parameters.GetExtendedInquiryResponse(); + std::array<uint8_t, 240> 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<uint8_t> PcapFilter::FilterRemoteNameRequestComplete( - bluetooth::hci::EventView& event) { +std::vector<uint8_t> PcapFilter::FilterRemoteNameRequestComplete(bluetooth::hci::EventView& event) { auto parameters = RemoteNameRequestCompleteView::Create(event); ASSERT(parameters.IsValid()); @@ -348,31 +326,27 @@ std::vector<uint8_t> 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<uint8_t> PcapFilter::FilterExtendedInquiryResult( - bluetooth::hci::EventView& event) { +std::vector<uint8_t> PcapFilter::FilterExtendedInquiryResult(bluetooth::hci::EventView& event) { auto parameters = ExtendedInquiryResultView::Create(event); ASSERT(parameters.IsValid()); - std::array<uint8_t, 240> extended_inquiry_response = - parameters.GetExtendedInquiryResponse(); - FilterGapData(extended_inquiry_response.data(), - extended_inquiry_response.size()); + std::array<uint8_t, 240> 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<uint8_t> PcapFilter::FilterLeAdvertisingReport( - bluetooth::hci::LeMetaEventView& event) { +std::vector<uint8_t> PcapFilter::FilterLeAdvertisingReport(bluetooth::hci::LeMetaEventView& event) { auto parameters = LeAdvertisingReportView::Create(event); ASSERT(parameters.IsValid()); @@ -387,31 +361,28 @@ std::vector<uint8_t> PcapFilter::FilterLeAdvertisingReport( // Replace the device names in the GAP entries in the extended advertising // report. std::vector<uint8_t> PcapFilter::FilterLeExtendedAdvertisingReport( - bluetooth::hci::LeMetaEventView& event) { + bluetooth::hci::LeMetaEventView& event) { auto parameters = LeExtendedAdvertisingReportView::Create(event); ASSERT(parameters.IsValid()); - std::vector<LeExtendedAdvertisingResponse> responses = - parameters.GetResponses(); + std::vector<LeExtendedAdvertisingResponse> 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<uint8_t> generate_device_name(size_t device_nr, - size_t device_name_len, +static std::vector<uint8_t> generate_device_name(size_t device_nr, size_t device_name_len, bool padded) { std::vector<uint8_t> output; output.resize(device_name_len + 1); - int written_len = std::snprintf(reinterpret_cast<char*>(output.data()), - output.size(), "#%02zu device", device_nr); + int written_len = std::snprintf(reinterpret_cast<char*>(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<uint8_t> generate_device_name(size_t device_nr, return output; } -std::vector<uint8_t> PcapFilter::ChangeDeviceName( - std::vector<uint8_t> const& device_name) { +std::vector<uint8_t> PcapFilter::ChangeDeviceName(std::vector<uint8_t> const& device_name) { for (auto const& [old_device_name, new_device_name] : device_name_map) { if (old_device_name == device_name) { return std::vector<uint8_t>(new_device_name); @@ -431,34 +401,31 @@ std::vector<uint8_t> PcapFilter::ChangeDeviceName( } std::vector<uint8_t> 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<uint8_t>(device_name), - new_device_name, + std::vector<uint8_t>(device_name), + new_device_name, }); return new_device_name; } -std::array<uint8_t, 248> PcapFilter::ChangeDeviceName( - std::array<uint8_t, 248> const& device_name) { +std::array<uint8_t, 248> PcapFilter::ChangeDeviceName(std::array<uint8_t, 248> 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<uint8_t, 248> 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<uint8_t> 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<uint8_t, 248> 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<uint8_t>(device_name.begin(), device_name.end()), - std::move(new_device_name), + std::vector<uint8_t>(device_name.begin(), device_name.end()), + std::move(new_device_name), }); return out_device_name; } diff --git a/tools/rootcanal/lib/log.cc b/tools/rootcanal/lib/log.cc index 9c78b16a3f..dc843f3fbb 100644 --- a/tools/rootcanal/lib/log.cc +++ b/tools/rootcanal/lib/log.cc @@ -37,34 +37,30 @@ void SetLogColorEnable(bool enable) { enable_log_color = enable; } static std::array<char, 5> verbosity_tag = {'D', 'I', 'W', 'E', 'F'}; static std::array<fmt::text_style, 5> 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<fmt::color, 16> 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<int> instance, char const* format, - fmt::format_args args) { +void VLog(Verbosity verb, char const* file, int line, std::optional<int> 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<std::chrono::milliseconds>(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<unsigned int>(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/tools/rootcanal/model/controller/acl_connection.cc b/tools/rootcanal/model/controller/acl_connection.cc index 33e4c36713..3cb4172f5b 100644 --- a/tools/rootcanal/model/controller/acl_connection.cc +++ b/tools/rootcanal/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/tools/rootcanal/model/controller/acl_connection.h b/tools/rootcanal/model/controller/acl_connection.h index 86ba9513e4..793f9e8823 100644 --- a/tools/rootcanal/model/controller/acl_connection.h +++ b/tools/rootcanal/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/tools/rootcanal/model/controller/acl_connection_handler.cc b/tools/rootcanal/model/controller/acl_connection_handler.cc index 656c495b84..bdcd1f72f4 100644 --- a/tools/rootcanal/model/controller/acl_connection_handler.cc +++ b/tools/rootcanal/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<AclConnection>(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<void(TaskId)> stopStream) { +bool AclConnectionHandler::Disconnect(uint16_t handle, std::function<void(TaskId)> 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<AclConnection>(pair).GetAddress().GetAddress() == addr) { return std::get<0>(pair); @@ -210,7 +199,7 @@ uint16_t AclConnectionHandler::GetHandleOnlyAddress( } std::optional<uint16_t> 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<AddressWithType> AclConnectionHandler::GetAddressSafe( - uint16_t handle) const { +std::optional<AddressWithType> AclConnectionHandler::GetAddressSafe(uint16_t handle) const { return HasHandle(handle) ? acl_connections_.at(handle).GetAddress() : std::optional<AddressWithType>(); } @@ -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<ScoConnection>(pair).GetAddress() == addr) { ScoState state = std::get<ScoConnection>(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<ScoConnection>(pair).GetAddress() == addr) { return std::get<ScoConnection>(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<ScoConnection>(pair).GetAddress() == addr) { return std::get<ScoConnection>(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<ScoConnection>(*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<TaskId()> startStream) { +bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr, + ScoLinkParameters const& parameters, + std::function<TaskId()> startStream) { for (auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { std::get<ScoConnection>(pair).SetLinkParameters(parameters); @@ -366,13 +345,12 @@ bool AclConnectionHandler::AcceptPendingScoConnection( return false; } -bool AclConnectionHandler::AcceptPendingScoConnection( - bluetooth::hci::Address addr, ScoConnectionParameters const& parameters, - std::function<TaskId()> startStream) { +bool AclConnectionHandler::AcceptPendingScoConnection(bluetooth::hci::Address addr, + ScoConnectionParameters const& parameters, + std::function<TaskId()> startStream) { for (auto& pair : sco_connections_) { if (std::get<ScoConnection>(pair).GetAddress() == addr) { - bool ok = - std::get<ScoConnection>(pair).NegotiateLinkParameters(parameters); + bool ok = std::get<ScoConnection>(pair).NegotiateLinkParameters(parameters); std::get<ScoConnection>(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<ScoConnection>(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<ScoConnection>(pair).GetAddress() == addr) { return std::get<ScoConnection>(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<ScoConnection>(pair).GetAddress() == addr) { return std::get<ScoConnection>(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/tools/rootcanal/model/controller/acl_connection_handler.h b/tools/rootcanal/model/controller/acl_connection_handler.h index 146cc475fd..b25181b418 100644 --- a/tools/rootcanal/model/controller/acl_connection_handler.h +++ b/tools/rootcanal/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<void(TaskId)> 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<TaskId()> startStream); bool AcceptPendingScoConnection(bluetooth::hci::Address addr, ScoConnectionParameters const& parameters, std::function<TaskId()> 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<void(TaskId)> 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<uint16_t> GetAclConnectionHandle( - bluetooth::hci::Address bd_addr) const; + std::optional<uint16_t> 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<uint16_t> 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<uint16_t, AclConnection> acl_connections_; std::unordered_map<uint16_t, ScoConnection> 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/tools/rootcanal/model/controller/controller_properties.cc b/tools/rootcanal/model/controller/controller_properties.cc index 49198879d2..b9afe2cf40 100644 --- a/tools/rootcanal/model/controller/controller_properties.cc +++ b/tools/rootcanal/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,243 @@ static constexpr uint64_t LlFeatures() { static std::array<uint8_t, 64> 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_DEVICE_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, 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, }; std::array<uint8_t, 64> value{}; @@ -480,20 +440,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 +464,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 +534,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 +555,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 +572,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 +594,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 +608,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 +627,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 +636,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 +691,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 +704,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 +734,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 +807,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 +866,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 +874,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 +950,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 +983,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)); // C95: Mandatory if the LE Request Peer SCA command is supported, otherwise // excluded. // @@ -1108,8 +997,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 +1006,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 +1015,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 +1088,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 +1151,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) @@ -1478,8 +1329,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,8 +1355,7 @@ 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); @@ -1526,8 +1375,7 @@ bool ControllerProperties::CheckSupportedCommands() const { check_command_(LE_SET_PERIODIC_ADVERTISING_PARAMETERS, 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 +1497,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); @@ -1731,84 +1578,77 @@ ControllerProperties::ControllerProperties() 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<OpCodeIndex> 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, + 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, }; // Commands enabled by the LE Periodic Advertising feature bit. static std::vector<OpCodeIndex> 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, }; // Commands enabled by the LL Privacy feature bit. static std::vector<OpCodeIndex> 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<OpCodeIndex> 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<uint64_t>(bit); } else { @@ -1817,8 +1657,7 @@ static void SetLLFeatureBit(uint64_t& le_features, LLFeaturesBits bit, } static void SetSupportedCommandBits(std::array<uint8_t, 64>& supported_commands, - std::vector<OpCodeIndex> const& commands, - bool set) { + std::vector<OpCodeIndex> const& commands, bool set) { for (auto command : commands) { int index = static_cast<int>(command); if (set) { @@ -1829,8 +1668,7 @@ static void SetSupportedCommandBits(std::array<uint8_t, 64>& 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())), lmp_features({Page0LmpFeatures(), 0, Page2LmpFeatures()}), @@ -1853,14 +1691,13 @@ ControllerProperties::ControllerProperties( lmp_subversion = 0x5ad2; company_identifier = 0x7e8; supported_commands = std::array<uint8_t, 64>{ - 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<uint64_t, 3> { 0x6000000000, 0x0, 0x0 }; + lmp_features = std::array<uint64_t, 3>{0x6000000000, 0x0, 0x0}; le_features = 0x19beff017fff; le_acl_data_packet_length = 512; total_num_le_acl_data_packets = 4; @@ -1884,15 +1721,14 @@ ControllerProperties::ControllerProperties( lmp_version = bluetooth::hci::LmpVersion::V_4_2; lmp_subversion = 0x30e8; company_identifier = 0xa; - supported_commands = std::array<uint8_t, 64> { - 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<uint8_t, 64>{ + 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<uint64_t, 3> { 0x875b1fd87e8fffff, 0x0, 0x30f }; + lmp_features = std::array<uint64_t, 3>{0x875b1fd87e8fffff, 0x0, 0x30f}; acl_data_packet_length = 310; total_num_acl_data_packets = 10; sco_data_packet_length = 64; @@ -1916,40 +1752,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 +1784,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 +1804,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/tools/rootcanal/model/controller/controller_properties.h b/tools/rootcanal/model/controller/controller_properties.h index 0a153f105d..ed69b5a499 100644 --- a/tools/rootcanal/model/controller/controller_properties.h +++ b/tools/rootcanal/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; @@ -181,8 +181,7 @@ struct ControllerProperties { bool SupportsCommand(bluetooth::hci::OpCodeIndex op_code) const { int index = static_cast<int>(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/tools/rootcanal/model/controller/dual_mode_controller.cc b/tools/rootcanal/model/controller/dual_mode_controller.cc index 33782805a6..7480496a6e 100644 --- a/tools/rootcanal/model/controller/dual_mode_controller.cc +++ b/tools/rootcanal/model/controller/dual_mode_controller.cc @@ -52,12 +52,12 @@ constexpr uint8_t kTransmitPowerLevel = -20; 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 +66,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 +81,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<uint8_t>{ - static_cast<uint8_t>(ErrorCode::UNKNOWN_HCI_COMMAND)})); + kNumCommandPackets, op_code, + std::vector<uint8_t>{static_cast<uint8_t>(ErrorCode::UNKNOWN_HCI_COMMAND)})); } DualModeController::DualModeController(ControllerProperties properties) @@ -99,15 +95,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<uint8_t> const&) { FATAL("{}", message); }; + invalid_packet_handler_ = [](uint32_t, InvalidPacketReason, std::string message, + std::vector<uint8_t> const&) { FATAL("{}", message); }; link_layer_controller_.RegisterRemoteChannel( - [this](std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet, - Phy::Type phy_type, int8_t tx_power) { - this->SendLinkLayerPacket(packet, phy_type, tx_power); - }); + [this](std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet, Phy::Type phy_type, + int8_t tx_power) { this->SendLinkLayerPacket(packet, phy_type, tx_power); }); } void DualModeController::ForwardToLm(CommandView command) { @@ -120,8 +113,7 @@ void DualModeController::ForwardToLl(CommandView command) { link_layer_controller_.ForwardToLl(command); } -void DualModeController::HandleAcl( - std::shared_ptr<std::vector<uint8_t>> packet) { +void DualModeController::HandleAcl(std::shared_ptr<std::vector<uint8_t>> packet) { auto acl_packet = bluetooth::hci::AclView::Create(pdl::packet::slice(packet)); CHECK_PACKET_VIEW(acl_packet); @@ -129,33 +121,31 @@ void DualModeController::HandleAcl( uint16_t handle = acl_packet.GetHandle(); std::vector<uint8_t> 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<bluetooth::hci::CompletedPackets> 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<std::vector<uint8_t>> packet) { +void DualModeController::HandleSco(std::shared_ptr<std::vector<uint8_t>> 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<bluetooth::hci::CompletedPackets> completed_packets; bluetooth::hci::CompletedPackets cp; @@ -163,8 +153,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 +161,46 @@ void DualModeController::HandleSco( link_layer_controller_.SendScoToRemote(sco_packet); } -void DualModeController::HandleIso( - std::shared_ptr<std::vector<uint8_t>> packet) { +void DualModeController::HandleIso(std::shared_ptr<std::vector<uint8_t>> 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<std::vector<uint8_t>> packet) { - auto command_packet = - bluetooth::hci::CommandView::Create(pdl::packet::slice(packet)); +void DualModeController::HandleCommand(std::shared_ptr<std::vector<uint8_t>> 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<uint16_t>(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<int>(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<uint8_t>(packet->begin(), packet->end()))); + std::vector<uint8_t>(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 +228,30 @@ void DualModeController::HandleCommand( else { SendCommandCompleteUnknownOpCodeEvent(op_code); uint16_t raw_op_code = static_cast<uint16_t>(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<void(uint32_t, InvalidPacketReason, std::string, - std::vector<uint8_t> const&)>& handler) { + const std::function<void(uint32_t, InvalidPacketReason, std::string, + std::vector<uint8_t> const&)>& handler) { INFO(id_, "updating the invalid packet handler"); invalid_packet_handler_ = handler; } void DualModeController::RegisterEventChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_event) { - send_event_ = - [send_event](std::shared_ptr<bluetooth::hci::EventBuilder> event) { - auto bytes = std::make_shared<std::vector<uint8_t>>(); - event->Serialize(*bytes); - send_event(bytes); - }; + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_event) { + send_event_ = [send_event](std::shared_ptr<bluetooth::hci::EventBuilder> event) { + auto bytes = std::make_shared<std::vector<uint8_t>>(); + event->Serialize(*bytes); + send_event(bytes); + }; link_layer_controller_.RegisterEventChannel(send_event_); } void DualModeController::RegisterAclChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_acl) { + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_acl) { send_acl_ = [send_acl](std::shared_ptr<bluetooth::hci::AclBuilder> acl_data) { auto bytes = std::make_shared<std::vector<uint8_t>>(); acl_data->Serialize(*bytes); @@ -284,8 +261,7 @@ void DualModeController::RegisterAclChannel( } void DualModeController::RegisterScoChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_sco) { + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_sco) { send_sco_ = [send_sco](std::shared_ptr<bluetooth::hci::ScoBuilder> sco_data) { auto bytes = std::make_shared<std::vector<uint8_t>>(); sco_data->Serialize(*bytes); @@ -295,8 +271,7 @@ void DualModeController::RegisterScoChannel( } void DualModeController::RegisterIsoChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_iso) { + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_iso) { send_iso_ = [send_iso](std::shared_ptr<bluetooth::hci::IsoBuilder> iso_data) { auto bytes = std::make_shared<std::vector<uint8_t>>(); iso_data->Serialize(*bytes); @@ -315,8 +290,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 +300,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 +331,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 +349,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 +371,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 +388,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 +413,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 +457,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 +471,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 +486,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 +515,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 +532,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 +546,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<uint8_t>(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<uint8_t>(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 +565,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<uint8_t>(command_view.GetRetransmissionEffort()), - command_view.GetPacketType()); + command_view.GetBdAddr(), command_view.GetTransmitBandwidth(), + command_view.GetReceiveBandwidth(), command_view.GetMaxLatency(), + command_view.GetVoiceSetting(), + static_cast<uint8_t>(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 +588,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 +603,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 +615,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 +646,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 +661,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 +673,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 +688,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 +698,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<uint8_t>(command_view.GetRetransmissionEffort()), - command_view.GetPacketType(), datapath); + command_view.GetConnectionHandle(), transmit_bandwidth, receive_bandwidth, + command_view.GetMaxLatency(), link_layer_controller_.GetVoiceSetting(), + static_cast<uint8_t>(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 +721,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 +737,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 +749,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 +778,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 +793,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 +805,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 +820,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 +830,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<uint8_t>(command_view.GetRetransmissionEffort()), - command_view.GetPacketType()); + command_view.GetBdAddr(), transmit_bandwidth, receive_bandwidth, + command_view.GetMaxLatency(), link_layer_controller_.GetVoiceSetting(), + static_cast<uint8_t>(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 +874,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 +893,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 +906,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 +914,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 +938,9 @@ void DualModeController::ChangeConnectionPacketType(CommandView command) { uint16_t handle = command_view.GetConnectionHandle(); uint16_t packet_type = static_cast<uint16_t>(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 +951,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 +979,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 +989,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 +999,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<uint8_t>(command_view.GetInquiryMode())); - send_event_(bluetooth::hci::WriteInquiryModeCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + link_layer_controller_.SetInquiryMode(static_cast<uint8_t>(command_view.GetInquiryMode())); + send_event_(bluetooth::hci::WriteInquiryModeCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::ReadPageScanType(CommandView command) { @@ -1110,10 +1012,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 +1025,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 +1035,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 +1048,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 +1062,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 +1071,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<uint8_t>(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<bluetooth::hci::AuthenticationEnable>( - link_layer_controller_.GetAuthenticationEnable()))); + kNumCommandPackets, ErrorCode::SUCCESS, + static_cast<bluetooth::hci::AuthenticationEnable>( + link_layer_controller_.GetAuthenticationEnable()))); } void DualModeController::ReadClassOfDevice(CommandView command) { @@ -1218,8 +1111,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 +1122,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 +1134,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 +1145,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 +1159,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 +1177,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 +1190,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 +1208,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 +1225,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 +1262,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<uint8_t>(command_view.GetFlowDirection()); + uint8_t flow_direction = static_cast<uint8_t>(command_view.GetFlowDirection()); uint8_t service_type = static_cast<uint8_t>(command_view.GetServiceType()); uint32_t token_rate = command_view.GetTokenRate(); uint32_t token_bucket_size = command_view.GetTokenBucketSize(); @@ -1400,17 +1279,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 +1295,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 +1311,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 +1327,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 +1339,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 +1349,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 +1372,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 +1386,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 +1398,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 +1419,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 +1429,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 +1442,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 +1464,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 +1487,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 +1523,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 +1539,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 +1557,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 +1570,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,15 +1579,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 (command_view.GetFilterType() != bluetooth::hci::FilterType::CLEAR_ALL_FILTERS) { FATAL("unsupported event filter type"); } - send_event_(bluetooth::hci::SetEventFilterCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::SUCCESS)); + send_event_(bluetooth::hci::SetEventFilterCompleteBuilder::Create(kNumCommandPackets, + ErrorCode::SUCCESS)); } void DualModeController::Inquiry(CommandView command) { @@ -1749,15 +1601,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) { @@ -1767,45 +1618,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<uint8_t>(reason)); - send_event_(bluetooth::hci::RejectConnectionRequestStatusBuilder::Create( - status, kNumCommandPackets)); + auto status = + link_layer_controller_.RejectConnectionRequest(bd_addr, static_cast<uint8_t>(reason)); + send_event_( + bluetooth::hci::RejectConnectionRequestStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::DeleteStoredLinkKey(CommandView command) { @@ -1814,8 +1660,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) { @@ -1827,10 +1673,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) { @@ -1841,8 +1686,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) { @@ -1866,14 +1711,13 @@ 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)); } } @@ -1887,10 +1731,8 @@ 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::LeSetHostFeatureCompleteBuilder::Create(kNumCommandPackets, status)); } void DualModeController::LeReadBufferSizeV1(CommandView command) { @@ -1901,11 +1743,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) { @@ -1916,61 +1757,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); + auto command_view = bluetooth::hci::LeReadLocalSupportedFeaturesView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Read Local Supported Features"); uint64_t le_features = link_layer_controller_.GetLeSupportedFeatures(); - send_event_( - bluetooth::hci::LeReadLocalSupportedFeaturesCompleteBuilder::Create( + send_event_(bluetooth::hci::LeReadLocalSupportedFeaturesCompleteBuilder::Create( kNumCommandPackets, ErrorCode::SUCCESS, le_features)); } @@ -1981,43 +1810,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) { @@ -2026,28 +1847,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"); @@ -2055,9 +1873,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) { @@ -2067,11 +1885,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) { @@ -2083,10 +1901,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) { @@ -2100,34 +1917,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) { @@ -2138,13 +1952,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) { @@ -2152,31 +1964,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<uint8_t>(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<uint8_t>(command_view.GetAllowRoleSwitch()); + uint8_t page_scan_mode = static_cast<uint8_t>(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<uint8_t>(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(); @@ -2185,8 +1993,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) { @@ -2197,76 +2005,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)); } @@ -2277,67 +2073,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"); @@ -2348,7 +2133,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) { @@ -2361,10 +2146,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) { @@ -2374,11 +2158,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) { @@ -2389,32 +2172,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"); @@ -2422,97 +2199,78 @@ 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)); } 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::LeSetPeriodicAdvertisingParameters(CommandView command) { + auto command_view = bluetooth::hci::LeSetPeriodicAdvertisingParametersView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Periodic Advertising Parameters"); 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::LeSetPeriodicAdvertisingParametersCompleteBuilder::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"); @@ -2520,170 +2278,135 @@ 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); + auto command_view = bluetooth::hci::LeExtendedCreateConnectionView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Extended Create Connection"); @@ -2691,8 +2414,7 @@ void DualModeController::LeExtendedCreateConnection(CommandView command) { 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()) { @@ -2706,15 +2428,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::LeExtendedCreateConnectionStatusBuilder::Create(status, + kNumCommandPackets)); } void DualModeController::LeSetPrivacyMode(CommandView command) { @@ -2722,19 +2443,15 @@ 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) { @@ -2745,11 +2462,11 @@ void DualModeController::LeReadRemoteFeatures(CommandView command) { DEBUG(id_, "<< LE Read Remote Features"); DEBUG(id_, " connection_handle=0x{:x}", handle); - auto status = link_layer_controller_.SendCommandToRemoteByHandle( - OpCode::LE_READ_REMOTE_FEATURES, command_view.bytes(), handle); + auto status = link_layer_controller_.SendCommandToRemoteByHandle(OpCode::LE_READ_REMOTE_FEATURES, + command_view.bytes(), handle); - send_event_(bluetooth::hci::LeReadRemoteFeaturesStatusBuilder::Create( - status, kNumCommandPackets)); + send_event_( + bluetooth::hci::LeReadRemoteFeaturesStatusBuilder::Create(status, kNumCommandPackets)); } void DualModeController::LeEncrypt(CommandView command) { @@ -2758,11 +2475,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) { @@ -2771,64 +2488,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) { @@ -2841,20 +2546,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) { @@ -2874,29 +2576,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; @@ -2904,40 +2601,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: @@ -2946,20 +2635,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; @@ -2967,40 +2652,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: @@ -3009,192 +2686,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::TRANSPORT_DISCOVERY_SERVICE: { auto subcommand_view = - bluetooth::hci::LeApcfTransportDiscoveryServiceView::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())); + 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)); + 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); + 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<uint8_t>(command_view.GetApcfOpcode())); + ERROR(id_, "unknown APCF opcode {:#x}", static_cast<uint8_t>(command_view.GetApcfOpcode())); send_event_(bluetooth::hci::LeApcfCompleteBuilder::Create( - kNumCommandPackets, ErrorCode::INVALID_HCI_COMMAND_PARAMETERS, - command_view.GetApcfOpcode(), std::vector<uint8_t>{})); - - invalid_packet_handler_( - id_, InvalidPacketReason::kUnsupported, - fmt::format("unsupported APCF opcode {:#x}", - static_cast<uint8_t>(command_view.GetApcfOpcode())), - command_view.bytes().bytes()); + kNumCommandPackets, ErrorCode::INVALID_HCI_COMMAND_PARAMETERS, + command_view.GetApcfOpcode(), std::vector<uint8_t>{})); + + invalid_packet_handler_(id_, InvalidPacketReason::kUnsupported, + fmt::format("unsupported APCF opcode {:#x}", + static_cast<uint8_t>(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. @@ -3247,10 +2892,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; } @@ -3258,21 +2902,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<uint8_t> value(parameters.begin() + 17, - parameters.begin() + 17 + length); + std::vector<uint8_t> 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<CsrPskey>(pskey), value); @@ -3283,11 +2924,9 @@ void DualModeController::CsrVendorCommand(CommandView command) { } else { // Subcommand to read or write VARID of the selected identifier. - std::vector<uint8_t> value(parameters.begin() + 11, - parameters.begin() + 11 + length); + std::vector<uint8_t> 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<CsrVarid>(varid), value); @@ -3301,12 +2940,11 @@ complete: // 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<uint8_t>& value) const { +void DualModeController::CsrReadVarid(CsrVarid varid, std::vector<uint8_t>& value) const { switch (varid) { case CsrVarid::CSR_VARID_BUILDID: // Return the extact Build ID returned by the official PTS dongle. @@ -3316,20 +2954,17 @@ void DualModeController::CsrReadVarid(CsrVarid varid, break; default: - INFO(id_, "Unsupported read of CSR varid 0x{:04x}", - static_cast<uint16_t>(varid)); + INFO(id_, "Unsupported read of CSR varid 0x{:04x}", static_cast<uint16_t>(varid)); break; } } -void DualModeController::CsrWriteVarid( - CsrVarid varid, std::vector<uint8_t> const& /*value*/) const { - INFO(id_, "Unsupported write of CSR varid 0x{:04x}", - static_cast<uint16_t>(varid)); +void DualModeController::CsrWriteVarid(CsrVarid varid, + std::vector<uint8_t> const& /*value*/) const { + INFO(id_, "Unsupported write of CSR varid 0x{:04x}", static_cast<uint16_t>(varid)); } -void DualModeController::CsrReadPskey(CsrPskey pskey, - std::vector<uint8_t>& value) const { +void DualModeController::CsrReadPskey(CsrPskey pskey, std::vector<uint8_t>& value) const { switch (pskey) { case CsrPskey::CSR_PSKEY_ENC_KEY_LMIN: ASSERT(!value.empty()); @@ -3349,35 +2984,30 @@ void DualModeController::CsrReadPskey(CsrPskey pskey, break; default: - INFO(id_, "Unsupported read of CSR pskey 0x{:04x}", - static_cast<uint16_t>(pskey)); + INFO(id_, "Unsupported read of CSR pskey 0x{:04x}", static_cast<uint16_t>(pskey)); break; } } -void DualModeController::CsrWritePskey(CsrPskey pskey, - std::vector<uint8_t> const& value) { +void DualModeController::CsrWritePskey(CsrPskey pskey, std::vector<uint8_t> 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<uint16_t>(pskey)); + INFO(id_, "Unsupported write of CSR pskey 0x{:04x}", static_cast<uint16_t>(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"); @@ -3385,147 +3015,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::LeSetExtendedAdvertisingParameters(CommandView command) { + auto command_view = bluetooth::hci::LeSetExtendedAdvertisingParametersView::Create(command); CHECK_PACKET_VIEW(command_view); DEBUG(id_, "<< LE Set Extended Advertising Parameters"); 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::LeSetExtendedAdvertisingParametersCompleteBuilder::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) { @@ -3536,72 +3139,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)); } @@ -3612,7 +3204,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) { @@ -3627,82 +3219,60 @@ 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)); } // Note: the list does not contain all defined opcodes. // Notable exceptions: // - Vendor commands // - Read Local Supported Commands command -const std::unordered_map<OpCode, OpCodeIndex> - DualModeController::hci_command_op_code_to_index_{ +const std::unordered_map<OpCode, OpCodeIndex> 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, @@ -3717,10 +3287,8 @@ const std::unordered_map<OpCode, OpCodeIndex> 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}, @@ -3731,12 +3299,9 @@ const std::unordered_map<OpCode, OpCodeIndex> {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}, @@ -3754,42 +3319,29 @@ const std::unordered_map<OpCode, OpCodeIndex> {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, @@ -3797,14 +3349,10 @@ const std::unordered_map<OpCode, OpCodeIndex> {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, @@ -3815,19 +3363,13 @@ const std::unordered_map<OpCode, OpCodeIndex> {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}, @@ -3838,8 +3380,7 @@ const std::unordered_map<OpCode, OpCodeIndex> {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}, @@ -3847,16 +3388,12 @@ const std::unordered_map<OpCode, OpCodeIndex> 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, @@ -3873,93 +3410,67 @@ const std::unordered_map<OpCode, OpCodeIndex> 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_DEVICE_UNDER_TEST_MODE, OpCodeIndex::ENABLE_DEVICE_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, OpCodeIndex::LE_READ_LOCAL_SUPPORTED_FEATURES}, {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, @@ -3972,12 +3483,10 @@ const std::unordered_map<OpCode, OpCodeIndex> {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}, @@ -3990,26 +3499,19 @@ const std::unordered_map<OpCode, OpCodeIndex> 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}, @@ -4019,8 +3521,7 @@ const std::unordered_map<OpCode, OpCodeIndex> 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_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, @@ -4029,22 +3530,16 @@ const std::unordered_map<OpCode, OpCodeIndex> 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_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_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, OpCodeIndex::LE_EXTENDED_CREATE_CONNECTION}, {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC, OpCodeIndex::LE_PERIODIC_ADVERTISING_CREATE_SYNC}, {OpCode::LE_PERIODIC_ADVERTISING_CREATE_SYNC_CANCEL, @@ -4055,8 +3550,7 @@ const std::unordered_map<OpCode, OpCodeIndex> 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}, @@ -4077,12 +3571,9 @@ const std::unordered_map<OpCode, OpCodeIndex> 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, @@ -4092,16 +3583,13 @@ const std::unordered_map<OpCode, OpCodeIndex> {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}, @@ -4116,20 +3604,17 @@ const std::unordered_map<OpCode, OpCodeIndex> {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_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}, @@ -4137,548 +3622,501 @@ const std::unordered_map<OpCode, OpCodeIndex> 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}, - }; +}; const std::unordered_map<OpCode, DualModeController::CommandHandler> - 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, + &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}}; } // namespace rootcanal diff --git a/tools/rootcanal/model/controller/dual_mode_controller.h b/tools/rootcanal/model/controller/dual_mode_controller.h index f3b0ce1726..bf95c8a95f 100644 --- a/tools/rootcanal/model/controller/dual_mode_controller.h +++ b/tools/rootcanal/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<void(uint32_t, InvalidPacketReason, std::string, - std::vector<uint8_t> const&)>& handler); + const std::function<void(uint32_t, InvalidPacketReason, std::string, + std::vector<uint8_t> const&)>& handler); // Set the callbacks for sending packets to the HCI. void RegisterEventChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_event); + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_event); void RegisterAclChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_acl); + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_acl); void RegisterScoChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_sco); + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_sco); void RegisterIsoChannel( - const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& - send_iso); + const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_iso); // Controller commands. For error codes, see the Bluetooth Core Specification, // Version 4.2, Volume 2, Part D (page 370). @@ -540,18 +536,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 +561,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<void(std::shared_ptr<bluetooth::hci::AclBuilder>)> send_acl_; - std::function<void(std::shared_ptr<bluetooth::hci::EventBuilder>)> - send_event_; + std::function<void(std::shared_ptr<bluetooth::hci::EventBuilder>)> send_event_; std::function<void(std::shared_ptr<bluetooth::hci::ScoBuilder>)> send_sco_; std::function<void(std::shared_ptr<bluetooth::hci::IsoBuilder>)> send_iso_; // Report invalid packets received on this controller instance. - std::function<void(uint32_t, InvalidPacketReason, std::string, - std::vector<uint8_t> const&)> - invalid_packet_handler_; + std::function<void(uint32_t, InvalidPacketReason, std::string, std::vector<uint8_t> 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 +589,13 @@ class DualModeController : public Device { // Map command opcodes to the corresponding bit index in the // supported command mask. - static const std::unordered_map<OpCode, OpCodeIndex> - hci_command_op_code_to_index_; + static const std::unordered_map<OpCode, OpCodeIndex> 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<void(DualModeController*, bluetooth::hci::CommandView)>; + using CommandHandler = std::function<void(DualModeController*, bluetooth::hci::CommandView)>; static const std::unordered_map<OpCode, CommandHandler> hci_command_handlers_; }; diff --git a/tools/rootcanal/model/controller/ffi.cc b/tools/rootcanal/model/controller/ffi.cc index d01ff16653..bfb8be7486 100644 --- a/tools/rootcanal/model/controller/ffi.cc +++ b/tools/rootcanal/model/controller/ffi.cc @@ -44,50 +44,42 @@ __attribute__((constructor)) static void ConfigureLogging() { 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<std::vector<uint8_t>> data) { - send_hci(hci::Idc::EVT, data->data(), data->size()); - }); - controller->RegisterAclChannel( - [=](std::shared_ptr<std::vector<uint8_t>> data) { - send_hci(hci::Idc::ACL, data->data(), data->size()); - }); - controller->RegisterScoChannel( - [=](std::shared_ptr<std::vector<uint8_t>> data) { - send_hci(hci::Idc::SCO, data->data(), data->size()); - }); - controller->RegisterIsoChannel( - [=](std::shared_ptr<std::vector<uint8_t>> 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<std::vector<uint8_t>> data) { + send_hci(hci::Idc::EVT, data->data(), data->size()); + }); + controller->RegisterAclChannel([=](std::shared_ptr<std::vector<uint8_t>> data) { + send_hci(hci::Idc::ACL, data->data(), data->size()); + }); + controller->RegisterScoChannel([=](std::shared_ptr<std::vector<uint8_t>> data) { + send_hci(hci::Idc::SCO, data->data(), data->size()); + }); + controller->RegisterIsoChannel([=](std::shared_ptr<std::vector<uint8_t>> data) { + send_hci(hci::Idc::ISO, data->data(), data->size()); + }); controller->RegisterLinkLayerChannel( - [=](std::vector<uint8_t> const& data, Phy::Type phy, int8_t tx_power) { - send_ll(data.data(), data.size(), static_cast<int>(phy), tx_power); - }); + [=](std::vector<uint8_t> const& data, Phy::Type phy, int8_t tx_power) { + send_ll(data.data(), data.size(), static_cast<int>(phy), tx_power); + }); return controller; } -__attribute__((visibility("default"))) void ffi_controller_delete( - void* controller_) { - DualModeController* controller = - reinterpret_cast<DualModeController*>(controller_); +__attribute__((visibility("default"))) void ffi_controller_delete(void* controller_) { + DualModeController* controller = reinterpret_cast<DualModeController*>(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<DualModeController*>(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<DualModeController*>(controller_); std::shared_ptr<std::vector<uint8_t>> bytes = - std::make_shared<std::vector<uint8_t>>(data, data + data_len); + std::make_shared<std::vector<uint8_t>>(data, data + data_len); switch (idc) { case hci::Idc::CMD: @@ -103,21 +95,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<DualModeController*>(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<DualModeController*>(controller_); std::shared_ptr<std::vector<uint8_t>> bytes = - std::make_shared<std::vector<uint8_t>>(data, data + data_len); + std::make_shared<std::vector<uint8_t>>(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; @@ -125,15 +116,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<DualModeController*>(controller_); +__attribute__((visibility("default"))) void ffi_controller_tick(void* controller_) { + DualModeController* controller = reinterpret_cast<DualModeController*>(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<uint8_t, LinkLayerController::kIrkSize> irk; memcpy(irk.data(), irk_, LinkLayerController::kIrkSize); Address address = LinkLayerController::generate_rpa(irk); diff --git a/tools/rootcanal/model/controller/ffi.h b/tools/rootcanal/model/controller/ffi.h index 8b6033be02..8b1d9d27cf 100644 --- a/tools/rootcanal/model/controller/ffi.h +++ b/tools/rootcanal/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/tools/rootcanal/model/controller/le_advertiser.cc b/tools/rootcanal/model/controller/le_advertiser.cc index 0f5cfabadf..7f5a89fd12 100644 --- a/tools/rootcanal/model/controller/le_advertiser.cc +++ b/tools/rootcanal/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<slots>(adv_direct_ind_high_interval) - : slots(advertising_interval_min); + advertising_type == AdvertisingType::ADV_DIRECT_IND_HIGH + ? std::chrono::duration_cast<slots>(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<uint8_t>& advertising_data) { +ErrorCode LinkLayerController::LeSetAdvertisingData(const std::vector<uint8_t>& 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<uint8_t>& scan_response_data) { + const std::vector<uint8_t>& 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<AddressWithType> 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<AddressWithType> 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<uint16_t>(LegacyAdvertisingEventProperties::ADV_IND) && + static_cast<uint16_t>(LegacyAdvertisingEventProperties::ADV_IND) && (raw_advertising_event_properties & ~0x10) != - static_cast<uint16_t>( - LegacyAdvertisingEventProperties::ADV_DIRECT_IND_LOW) && + static_cast<uint16_t>(LegacyAdvertisingEventProperties::ADV_DIRECT_IND_LOW) && (raw_advertising_event_properties & ~0x10) != - static_cast<uint16_t>( - LegacyAdvertisingEventProperties::ADV_DIRECT_IND_HIGH) && + static_cast<uint16_t>(LegacyAdvertisingEventProperties::ADV_DIRECT_IND_HIGH) && (raw_advertising_event_properties & ~0x10) != - static_cast<uint16_t>( - LegacyAdvertisingEventProperties::ADV_SCAN_IND) && + static_cast<uint16_t>(LegacyAdvertisingEventProperties::ADV_SCAN_IND) && (raw_advertising_event_properties & ~0x10) != - static_cast<uint16_t>( - LegacyAdvertisingEventProperties::ADV_NONCONN_IND)) { + static_cast<uint16_t>(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<uint8_t>(primary_advertising_phy)); + raw_advertising_event_properties, static_cast<uint8_t>(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<uint8_t>& advertising_data) { + uint8_t advertising_handle, Operation operation, FragmentPreference fragment_preference, + const std::vector<uint8_t>& 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<uint8_t>& scan_response_data) { + uint8_t advertising_handle, Operation operation, FragmentPreference fragment_preference, + const std::vector<uint8_t>& 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<bluetooth::hci::EnabledSet>& sets) { + bool enable, const std::vector<bluetooth::hci::EnabledSet>& 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<AddressWithType> 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 @@ -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; @@ -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<uint8_t>& advertising_data) { + uint8_t advertising_handle, bluetooth::hci::Operation operation, + const std::vector<uint8_t>& 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; @@ -1665,9 +1592,8 @@ void LinkLayerController::LeAdvertising() { #endif if (IsLeEventUnmasked(SubeventCode::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<model::packets::AddressType>( - legacy_advertiser_.advertising_address.GetAddressType()), - static_cast<model::packets::AddressType>( - legacy_advertiser_.target_address.GetAddressType()), - type, - attach_advertising_data ? legacy_advertiser_.advertising_data - : std::vector<uint8_t>{}), - properties_.le_advertising_physical_channel_tx_power); + SendLeLinkLayerPacket(model::packets::LeLegacyAdvertisingPduBuilder::Create( + legacy_advertiser_.advertising_address.GetAddress(), + legacy_advertiser_.target_address.GetAddress(), + static_cast<model::packets::AddressType>( + legacy_advertiser_.advertising_address.GetAddressType()), + static_cast<model::packets::AddressType>( + legacy_advertiser_.target_address.GetAddressType()), + type, + attach_advertising_data ? legacy_advertiser_.advertising_data + : std::vector<uint8_t>{}), + properties_.le_advertising_physical_channel_tx_power); } for (auto& [_, advertiser] : extended_advertisers_) { @@ -1730,9 +1654,9 @@ 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) @@ -1740,15 +1664,14 @@ void LinkLayerController::LeAdvertising() { 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)); + 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)) { 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)) { @@ -1756,18 +1679,18 @@ void LinkLayerController::LeAdvertising() { // 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 @@ -1777,8 +1700,8 @@ void LinkLayerController::LeAdvertising() { if (IsLeEventUnmasked(SubeventCode::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<LegacyAdvertisingEventProperties>( - raw_advertising_event_properties & 0xf)) { + ExtendedAdvertiser::GetRawAdvertisingEventProperties( + advertiser.advertising_event_properties); + switch (static_cast<LegacyAdvertisingEventProperties>(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<model::packets::AddressType>( - advertiser.advertising_address.GetAddressType()), - static_cast<model::packets::AddressType>( - 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<model::packets::AddressType>( + advertiser.advertising_address.GetAddressType()), + static_cast<model::packets::AddressType>( + 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<model::packets::AddressType>( - advertiser.advertising_address.GetAddressType()), - static_cast<model::packets::AddressType>( - 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<model::packets::PhyType>( - advertiser.primary_advertising_phy), - static_cast<model::packets::PhyType>( - 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<model::packets::AddressType>( + advertiser.advertising_address.GetAddressType()), + static_cast<model::packets::AddressType>( + 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<model::packets::PhyType>(advertiser.primary_advertising_phy), + static_cast<model::packets::PhyType>(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<model::packets::AddressType>( - 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<model::packets::AddressType>( + 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/tools/rootcanal/model/controller/le_advertiser.h b/tools/rootcanal/model/controller/le_advertiser.h index cef651642b..f365370035 100644 --- a/tools/rootcanal/model/controller/le_advertiser.h +++ b/tools/rootcanal/model/controller/le_advertiser.h @@ -29,8 +29,7 @@ namespace rootcanal { // Duration type for slots (increments of 625us). -using slots = - std::chrono::duration<unsigned long long, std::ratio<625, 1000000>>; +using slots = std::chrono::duration<unsigned long long, std::ratio<625, 1000000>>; // 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<uint8_t> advertising_data{}; std::vector<uint8_t> 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/tools/rootcanal/model/controller/link_layer_controller.cc b/tools/rootcanal/model/controller/link_layer_controller.cc index c1bff2b4b5..047ea9c96e 100644 --- a/tools/rootcanal/model/controller/link_layer_controller.cc +++ b/tools/rootcanal/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); @@ -91,8 +89,7 @@ bool LinkLayerController::IsEventUnmasked(EventCode event) const { bool LinkLayerController::IsLeEventUnmasked(SubeventCode subevent) const { uint64_t bit = UINT64_C(1) << (static_cast<uint8_t>(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 +98,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 +113,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 +124,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) { 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 +145,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 +158,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 +201,7 @@ bool LinkLayerController::ResolvingListBusy() { return false; } -std::optional<AddressWithType> LinkLayerController::ResolvePrivateAddress( - AddressWithType address) { +std::optional<AddressWithType> LinkLayerController::ResolvePrivateAddress(AddressWithType address) { if (!address.IsRpa()) { return address; } @@ -223,23 +216,20 @@ std::optional<AddressWithType> 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 +238,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 +248,13 @@ bool LinkLayerController::ValidateTargetA(AddressWithType target_a, return false; } -std::optional<AddressWithType> -LinkLayerController::GenerateResolvablePrivateAddress(AddressWithType address, - IrkSelection irk) { +std::optional<AddressWithType> 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<uint8_t, LinkLayerController::kIrkSize> 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 +263,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 +275,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 +296,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 +311,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 +336,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 +389,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 +430,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 +442,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 +452,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 +461,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 +485,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 +496,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 +507,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()) && + if ((phy_c_to_p != connection.GetTxPhy() || phy_p_to_c != connection.GetRxPhy()) && IsLeEventUnmasked(SubeventCode::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 +525,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 +544,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 +555,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)) { 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 +572,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,10 +586,8 @@ 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 @@ -630,7 +596,7 @@ void LinkLayerController::IncomingLlPhyUpdateInd( (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 +605,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 +625,9 @@ ErrorCode LinkLayerController::LeSetHostFeature(uint8_t bit_number, uint64_t bit_mask = UINT64_C(1) << bit_number; if (bit_mask == - static_cast<uint64_t>( - LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_HOST_SUPPORT)) { + static_cast<uint64_t>(LLFeaturesBits::CONNECTED_ISOCHRONOUS_STREAM_HOST_SUPPORT)) { connected_isochronous_stream_host_support_ = bit_value != 0; - } else if (bit_mask == - static_cast<uint64_t>( - LLFeaturesBits::CONNECTION_SUBRATING_HOST_SUPPORT)) { + } else if (bit_mask == static_cast<uint64_t>(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 +652,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<uint8_t, kIrkSize> peer_irk, - std::array<uint8_t, kIrkSize> local_irk) { + PeerAddressType peer_identity_address_type, Address peer_identity_address, + std::array<uint8_t, kIrkSize> peer_irk, std::array<uint8_t, kIrkSize> 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 +699,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 +713,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 +749,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 +773,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 +814,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 +871,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 +895,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 +918,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 +940,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 +970,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 +1009,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 +1023,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 +1038,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 +1049,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 +1072,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 +1086,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 +1094,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; } @@ -1174,11 +1120,9 @@ ErrorCode LinkLayerController::LePeriodicAdvertisingCreateSyncCancel() { // by Host (0x44). if (IsLeEventUnmasked(SubeventCode::PERIODIC_ADVERTISING_SYNC_ESTABLISHED)) { 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::LePeriodicAdvertisingSyncEstablishedBuilder::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 +1133,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 +1152,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 +1174,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 +1186,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 +1202,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 +1228,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 +1244,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 +1255,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<bluetooth::hci::ScanningPhyParameters> - scanning_phy_parameters) { + bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy, uint8_t scanning_phys, + std::vector<bluetooth::hci::ScanningPhyParameters> scanning_phy_parameters) { uint8_t supported_phys = properties_.LeSupportedPhys(); // Extended advertising commands are disallowed when legacy advertising @@ -1353,8 +1288,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 +1334,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 +1357,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 +1384,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 +1411,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 +1451,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 +1476,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 +1488,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 +1541,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<milliseconds>( - (1 + max_latency) * slots(2 * connection_interval_max) * 2); + milliseconds min_supervision_timeout = + duration_cast<milliseconds>((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<unsigned>(min_supervision_timeout / 1ms)); + supervision_timeout * 10, static_cast<unsigned>(min_supervision_timeout / 1ms)); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } @@ -1693,16 +1620,14 @@ ErrorCode LinkLayerController::LeCreateConnectionCancel() { if (IsLeEventUnmasked(SubeventCode::ENHANCED_CONNECTION_COMPLETE)) { 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)); + 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)) { 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 +1641,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<bluetooth::hci::InitiatingPhyParameters> - initiating_phy_parameters) { + bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, + bluetooth::hci::OwnAddressType own_address_type, AddressWithType peer_address, + uint8_t initiating_phys, + std::vector<bluetooth::hci::InitiatingPhyParameters> initiating_phy_parameters) { // Extended advertising commands are disallowed when legacy advertising // commands were used since the last reset. if (!SelectExtendedAdvertising()) { @@ -1750,8 +1674,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 +1708,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 +1716,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 +1750,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 +1762,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<milliseconds>( - (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<unsigned>(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<unsigned>(min_supervision_timeout / 1ms)); return ErrorCode::INVALID_HCI_COMMAND_PARAMETERS; } } @@ -1904,54 +1818,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 +1901,7 @@ void LinkLayerController::SetSecureConnectionsSupport(bool enable) { } } -void LinkLayerController::SetLocalName( - std::array<uint8_t, kLocalNameSize> const& local_name) { +void LinkLayerController::SetLocalName(std::array<uint8_t, kLocalNameSize> const& local_name) { std::copy(local_name.begin(), local_name.end(), local_name_.begin()); } @@ -2008,12 +1912,12 @@ void LinkLayerController::SetLocalName(std::vector<uint8_t> const& local_name) { } void LinkLayerController::SetExtendedInquiryResponse( - std::array<uint8_t, 240> const& extended_inquiry_response) { + std::array<uint8_t, 240> const& extended_inquiry_response) { extended_inquiry_response_ = extended_inquiry_response; } void LinkLayerController::SetExtendedInquiryResponse( - std::vector<uint8_t> const& extended_inquiry_response) { + std::vector<uint8_t> 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 +1925,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 +1933,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<LinkLayerController*>(user); - - return controller->connections_.GetHandleOnlyAddress( - Address(*address)); - }, - - .get_address = - [](void* user, uint16_t handle, uint8_t(*result)[6]) { - auto controller = static_cast<LinkLayerController*>(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<uint8_t*>(result)); - }, - - .get_extended_features = - [](void* user, uint8_t features_page) { - auto controller = static_cast<LinkLayerController*>(user); - return controller->GetLmpFeatures(features_page); - }, - - .get_le_features = - [](void* user) { - auto controller = static_cast<LinkLayerController*>(user); - return controller->GetLeSupportedFeatures(); - }, - - .get_le_event_mask = - [](void* user) { - auto controller = static_cast<LinkLayerController*>(user); - return controller->le_event_mask_; - }, - - .send_hci_event = - [](void* user, const uint8_t* data, uintptr_t len) { - auto controller = static_cast<LinkLayerController*>(user); - - auto event_code = static_cast<EventCode>(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<LinkLayerController*>(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<LinkLayerController*>(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<LinkLayerController*>(user); + + return controller->connections_.GetHandleOnlyAddress(Address(*address)); + }, + + .get_address = + [](void* user, uint16_t handle, uint8_t(*result)[6]) { + auto controller = static_cast<LinkLayerController*>(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<uint8_t*>(result)); + }, + + .get_extended_features = + [](void* user, uint8_t features_page) { + auto controller = static_cast<LinkLayerController*>(user); + return controller->GetLmpFeatures(features_page); + }, + + .get_le_features = + [](void* user) { + auto controller = static_cast<LinkLayerController*>(user); + return controller->GetLeSupportedFeatures(); + }, + + .get_le_event_mask = + [](void* user) { + auto controller = static_cast<LinkLayerController*>(user); + return controller->le_event_mask_; + }, + + .send_hci_event = + [](void* user, const uint8_t* data, uintptr_t len) { + auto controller = static_cast<LinkLayerController*>(user); + + auto event_code = static_cast<EventCode>(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<LinkLayerController*>(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<LinkLayerController*>(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 +2022,92 @@ LinkLayerController::LinkLayerController(const Address& address, LinkLayerController::~LinkLayerController() {} void LinkLayerController::SendLeLinkLayerPacket( - std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet, - int8_t tx_power) { - std::shared_ptr<model::packets::LinkLayerPacketBuilder> shared_packet = - std::move(packet); + std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet, int8_t tx_power) { + std::shared_ptr<model::packets::LinkLayerPacketBuilder> 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<model::packets::LinkLayerPacketBuilder> packet, - int8_t tx_power) { - std::shared_ptr<model::packets::LinkLayerPacketBuilder> shared_packet = - std::move(packet); + std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet, int8_t tx_power) { + std::shared_ptr<model::packets::LinkLayerPacketBuilder> 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)); + SendLeLinkLayerPacket( + model::packets::LeReadRemoteFeaturesBuilder::Create(own_address, peer_address)); break; default: - INFO(id_, "Dropping unhandled command 0x{:04x}", - static_cast<uint16_t>(opcode)); + INFO(id_, "Dropping unhandled command 0x{:04x}", static_cast<uint16_t>(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<uint8_t>(); - 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<uint16_t>(opcode)); + INFO(id_, "Dropping unhandled command 0x{:04x}", static_cast<uint16_t>(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()); + 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 +2119,10 @@ ErrorCode LinkLayerController::SendAclToRemote( auto acl_packet_payload = acl_packet.GetPayload(); auto acl = model::packets::AclBuilder::Create( - my_address.GetAddress(), destination.GetAddress(), - static_cast<uint8_t>(acl_packet.GetPacketBoundaryFlag()), - static_cast<uint8_t>(acl_packet.GetBroadcastFlag()), - std::vector(acl_packet_payload.begin(), acl_packet_payload.end())); + my_address.GetAddress(), destination.GetAddress(), + static_cast<uint8_t>(acl_packet.GetPacketBoundaryFlag()), + static_cast<uint8_t>(acl_packet.GetBroadcastFlag()), + std::vector(acl_packet_payload.begin(), acl_packet_payload.end())); switch (phy) { case Phy::Type::BR_EDR: @@ -2247,13 +2135,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 +2153,13 @@ ErrorCode LinkLayerController::SendScoToRemote( auto sco_data = sco_packet.GetData(); std::vector<uint8_t> 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 +2180,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 +2193,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 +2203,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<int>(incoming.GetType())); + INFO(id_, "{} | Dropping packet not addressed to me {}->{} (type 0x{:x})", address_, + source_address, destination_address, static_cast<int>(incoming.GetType())); return; } @@ -2473,27 +2357,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 +2393,17 @@ void LinkLayerController::IncomingAclPacket( std::vector<uint8_t> 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 +2420,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 +2476,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 +2490,14 @@ void LinkLayerController::IncomingReadRemoteExtendedFeatures( if (page_number >= properties_.lmp_features.size()) { error_code = static_cast<uint8_t>(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 +2506,22 @@ void LinkLayerController::IncomingReadRemoteExtendedFeaturesResponse( return; } if (IsEventUnmasked(EventCode::READ_REMOTE_EXTENDED_FEATURES_COMPLETE)) { - send_event_( - bluetooth::hci::ReadRemoteExtendedFeaturesCompleteBuilder::Create( - static_cast<ErrorCode>(view.GetStatus()), handle, - view.GetPageNumber(), view.GetMaxPageNumber(), view.GetFeatures())); + send_event_(bluetooth::hci::ReadRemoteExtendedFeaturesCompleteBuilder::Create( + static_cast<ErrorCode>(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<uint8_t>(properties_.lmp_version), - static_cast<uint16_t>(properties_.lmp_subversion), - properties_.company_identifier)); + static_cast<uint16_t>(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 +2530,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 +2552,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 +2570,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<uint8_t(*)[6]>(peer.data()))); + ASSERT(link_manager_remove_link(lm_.get(), reinterpret_cast<uint8_t(*)[6]>(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 +2600,40 @@ void LinkLayerController::IncomingInquiryPacket( switch (inquiry.GetInquiryType()) { case (model::packets::InquiryType::STANDARD): { SendLinkLayerPacket(model::packets::InquiryResponseBuilder::Create( - GetAddress(), peer, static_cast<uint8_t>(GetPageScanRepetitionMode()), - class_of_device_, GetClockOffset())); + GetAddress(), peer, static_cast<uint8_t>(GetPageScanRepetitionMode()), + class_of_device_, GetClockOffset())); } break; case (model::packets::InquiryType::RSSI): { - SendLinkLayerPacket( - model::packets::InquiryResponseWithRssiBuilder::Create( - GetAddress(), peer, - static_cast<uint8_t>(GetPageScanRepetitionMode()), + SendLinkLayerPacket(model::packets::InquiryResponseWithRssiBuilder::Create( + GetAddress(), peer, static_cast<uint8_t>(GetPageScanRepetitionMode()), class_of_device_, GetClockOffset(), rssi)); } break; case (model::packets::InquiryType::EXTENDED): { - SendLinkLayerPacket( - model::packets::ExtendedInquiryResponseBuilder::Create( - GetAddress(), peer, - static_cast<uint8_t>(GetPageScanRepetitionMode()), - class_of_device_, GetClockOffset(), rssi, - extended_inquiry_response_)); + SendLinkLayerPacket(model::packets::ExtendedInquiryResponseBuilder::Create( + GetAddress(), peer, static_cast<uint8_t>(GetPageScanRepetitionMode()), + class_of_device_, GetClockOffset(), rssi, extended_inquiry_response_)); } break; default: - WARNING(id_, "Unhandled Incoming Inquiry of type {}", - static_cast<int>(inquiry.GetType())); + WARNING(id_, "Unhandled Incoming Inquiry of type {}", static_cast<int>(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<uint8_t> 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<bluetooth::hci::InquiryResponse> responses; responses.emplace_back(); @@ -2803,13 +2648,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<bluetooth::hci::InquiryResponseWithRssi> responses; responses.emplace_back(); @@ -2819,24 +2662,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<bluetooth::hci::PageScanRepetitionMode>( - inquiry_response.GetPageScanRepetitionMode()), - inquiry_response.GetClassOfDevice(), - inquiry_response.GetClockOffset(), inquiry_response.GetRssi(), - inquiry_response.GetExtendedInquiryResponse())); + inquiry_response.GetSourceAddress(), + static_cast<bluetooth::hci::PageScanRepetitionMode>( + inquiry_response.GetPageScanRepetitionMode()), + inquiry_response.GetClassOfDevice(), inquiry_response.GetClockOffset(), + inquiry_response.GetRssi(), inquiry_response.GetExtendedInquiryResponse())); } break; default: @@ -2845,8 +2685,7 @@ void LinkLayerController::IncomingInquiryResponsePacket( } } -Address LinkLayerController::generate_rpa( - std::array<uint8_t, LinkLayerController::kIrkSize> irk) { +Address LinkLayerController::generate_rpa(std::array<uint8_t, LinkLayerController::kIrkSize> 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<uint8_t, 3> prand; @@ -2868,8 +2707,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 +2718,12 @@ Address LinkLayerController::generate_rpa( } bool LinkLayerController::irk_is_zero(std::array<uint8_t, LinkLayerController::kIrkSize> 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 +2731,22 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( auto advertising_type = pdu.GetAdvertisingType(); std::vector<uint8_t> advertising_data = pdu.GetAdvertisingData(); - AddressWithType advertising_address{ - pdu.GetSourceAddress(), - static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast<AddressType>(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast<AddressType>(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 +2757,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 +2770,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 +2813,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 +2823,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 { @@ -3011,19 +2843,15 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( should_send_directed_advertising_report && IsLeEventUnmasked(SubeventCode::DIRECTED_ADVERTISING_REPORT)) { bluetooth::hci::LeDirectedAdvertisingResponse response; - response.event_type_ = - bluetooth::hci::DirectAdvertisingEventType::ADV_DIRECT_IND; - response.address_type_ = - static_cast<bluetooth::hci::DirectAdvertisingAddressType>( + response.event_type_ = bluetooth::hci::DirectAdvertisingEventType::ADV_DIRECT_IND; + response.address_type_ = static_cast<bluetooth::hci::DirectAdvertisingAddressType>( 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. @@ -3041,16 +2869,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; } @@ -3067,8 +2892,7 @@ void LinkLayerController::ScanIncomingLeLegacyAdvertisingPdu( response.scan_response_ = false; response.legacy_ = true; response.data_status_ = bluetooth::hci::DataStatus::COMPLETE; - response.address_type_ = - static_cast<bluetooth::hci::DirectAdvertisingAddressType>( + response.address_type_ = static_cast<bluetooth::hci::DirectAdvertisingAddressType>( resolved_advertising_address.GetAddressType()); response.address_ = resolved_advertising_address.GetAddress(); response.primary_phy_ = bluetooth::hci::PrimaryPhyType::LE_1M; @@ -3079,26 +2903,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 +2949,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<AddressWithType> 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 +2987,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 +2998,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<model::packets::AddressType>( - scanning_address.GetAddressType()), - static_cast<model::packets::AddressType>( - advertising_address.GetAddressType()))); + scanning_address.GetAddress(), advertising_address.GetAddress(), + static_cast<model::packets::AddressType>(scanning_address.GetAddressType()), + static_cast<model::packets::AddressType>(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 +3033,14 @@ void LinkLayerController::ConnectIncomingLeLegacyAdvertisingPdu( return; } - AddressWithType advertising_address{ - pdu.GetSourceAddress(), - static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast<AddressType>(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast<AddressType>(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) { @@ -3268,10 +3081,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 +3093,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<AddressWithType> 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 +3112,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 +3141,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<model::packets::AddressType>( - initiating_address.GetAddressType()), - static_cast<model::packets::AddressType>( - 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<model::packets::AddressType>(initiating_address.GetAddressType()), + static_cast<model::packets::AddressType>(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 +3161,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 +3171,11 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( } std::vector<uint8_t> advertising_data = pdu.GetAdvertisingData(); - AddressWithType advertising_address{ - pdu.GetSourceAddress(), - static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast<AddressType>(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast<AddressType>(pdu.GetTargetAddressType())}; bool scannable_advertising = pdu.GetScannable(); bool connectable_advertising = pdu.GetConnectable(); @@ -3384,10 +3184,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 +3197,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 +3215,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 +3230,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 +3264,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 +3278,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 { @@ -3505,27 +3295,22 @@ void LinkLayerController::ScanIncomingLeExtendedAdvertisingPdu( response.scan_response_ = false; response.legacy_ = false; response.data_status_ = bluetooth::hci::DataStatus::COMPLETE; - response.address_type_ = - static_cast<bluetooth::hci::DirectAdvertisingAddressType>( + response.address_type_ = static_cast<bluetooth::hci::DirectAdvertisingAddressType>( resolved_advertising_address.GetAddressType()); response.address_ = resolved_advertising_address.GetAddress(); - response.primary_phy_ = - static_cast<bluetooth::hci::PrimaryPhyType>(primary_phy); - response.secondary_phy_ = - static_cast<bluetooth::hci::SecondaryPhyType>(secondary_phy); + response.primary_phy_ = static_cast<bluetooth::hci::PrimaryPhyType>(primary_phy); + response.secondary_phy_ = static_cast<bluetooth::hci::SecondaryPhyType>(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 +3324,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 +3367,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<AddressWithType> 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 +3416,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<model::packets::AddressType>( - scanning_address.GetAddressType()), - static_cast<model::packets::AddressType>( - advertising_address.GetAddressType()))); + scanning_address.GetAddress(), advertising_address.GetAddress(), + static_cast<model::packets::AddressType>(scanning_address.GetAddressType()), + static_cast<model::packets::AddressType>(advertising_address.GetAddressType()))); } } void LinkLayerController::ConnectIncomingLeExtendedAdvertisingPdu( - model::packets::LeExtendedAdvertisingPduView& pdu) { + model::packets::LeExtendedAdvertisingPduView& pdu) { if (!initiator_.IsEnabled()) { return; } @@ -3665,23 +3442,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<AddressType>(pdu.GetAdvertisingAddressType())}; + AddressWithType advertising_address{pdu.GetSourceAddress(), + static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; - AddressWithType target_address{ - pdu.GetDestinationAddress(), - static_cast<AddressType>(pdu.GetTargetAddressType())}; + AddressWithType target_address{pdu.GetDestinationAddress(), + static_cast<AddressType>(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) { @@ -3722,10 +3496,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 +3508,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<AddressWithType> 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 +3527,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 +3556,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<model::packets::AddressType>( - initiating_address.GetAddressType()), - static_cast<model::packets::AddressType>( - 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<model::packets::AddressType>(initiating_address.GetAddressType()), + static_cast<model::packets::AddressType>(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 +3575,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 +3589,8 @@ void LinkLayerController::IncomingLePeriodicAdvertisingPdu( return; } - AddressWithType advertiser_address{ - pdu.GetSourceAddress(), - static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; + AddressWithType advertiser_address{pdu.GetSourceAddress(), + static_cast<AddressType>(pdu.GetAdvertisingAddressType())}; uint8_t advertising_sid = pdu.GetSid(); // When a scanner receives an advertising packet that contains a resolvable @@ -3837,20 +3599,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 +3623,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 +3646,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::PERIODIC_ADVERTISING_SYNC_ESTABLISHED)) { + send_event_(bluetooth::hci::LePeriodicAdvertisingSyncEstablishedBuilder::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_ = {}; @@ -3944,18 +3698,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<uint8_t> 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<uint8_t> 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)); + sync.sync_handle, pdu.GetTxPower(), rssi, + bluetooth::hci::CteType::NO_CONSTANT_TONE_EXTENSION, data_status, fragment_data)); } while (offset < advertising_data.size()); } @@ -3965,7 +3716,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 +3732,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 +3770,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 +3826,23 @@ void LinkLayerController::IncomingScoDisconnect( static_cast<unsigned>(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<uint8_t(*)[6]>(address.data()), packet.data(), - packet.size())); + ASSERT(link_manager_ingest_lmp(lm_.get(), reinterpret_cast<uint8_t(*)[6]>(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 +3855,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 +3868,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 +3878,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<uint8_t> fragment(packet.data() + offset, - packet.data() + offset + fragment_size); + std::vector<uint8_t> 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 +3917,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 +3930,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 +3943,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 +3952,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 +3966,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. @@ -4271,8 +3994,7 @@ uint16_t LinkLayerController::HandleLeConnection( } if (IsLeEventUnmasked(SubeventCode::ENHANCED_CONNECTION_COMPLETE)) { - AddressWithType peer_resolved_address = - connections_.GetResolvedAddress(handle); + AddressWithType peer_resolved_address = connections_.GetResolvedAddress(handle); Address peer_resolvable_private_address; Address connection_address = address.GetAddress(); AddressType peer_address_type = address.GetAddressType(); @@ -4282,28 +4004,26 @@ 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<bluetooth::hci::ClockAccuracy>(0x00))); + ErrorCode::SUCCESS, handle, role, peer_address_type, connection_address, + local_resolved_address, peer_resolvable_private_address, connection_interval, + connection_latency, supervision_timeout, + static_cast<bluetooth::hci::ClockAccuracy>(0x00))); } else if (IsLeEventUnmasked(SubeventCode::CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::LeConnectionCompleteBuilder::Create( - ErrorCode::SUCCESS, handle, role, address.GetAddressType(), - address.GetAddress(), connection_interval, connection_latency, - supervision_timeout, static_cast<bluetooth::hci::ClockAccuracy>(0x00))); + ErrorCode::SUCCESS, handle, role, address.GetAddressType(), address.GetAddress(), + connection_interval, connection_latency, supervision_timeout, + static_cast<bluetooth::hci::ClockAccuracy>(0x00))); } // Update the link layer with the new link. - ASSERT(link_layer_add_link( - ll_.get(), handle, - reinterpret_cast<const uint8_t(*)[6]>(address.GetAddress().data()), - static_cast<uint8_t>(role))); + ASSERT(link_layer_add_link(ll_.get(), handle, + reinterpret_cast<const uint8_t(*)[6]>(address.GetAddress().data()), + static_cast<uint8_t>(role))); // Note: the HCI_LE_Connection_Complete event is immediately followed by // an HCI_LE_Channel_Selection_Algorithm event if the connection is created @@ -4313,7 +4033,7 @@ uint16_t LinkLayerController::HandleLeConnection( // 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 +4044,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 +4056,13 @@ bool LinkLayerController::ProcessIncomingLegacyConnectRequest( } AddressWithType advertising_address{ - connect_ind.GetDestinationAddress(), - static_cast<AddressType>(connect_ind.GetAdvertisingAddressType()), + connect_ind.GetDestinationAddress(), + static_cast<AddressType>(connect_ind.GetAdvertisingAddressType()), }; AddressWithType initiating_address{ - connect_ind.GetSourceAddress(), - static_cast<AddressType>(connect_ind.GetInitiatingAddressType()), + connect_ind.GetSourceAddress(), + static_cast<AddressType>(connect_ind.GetInitiatingAddressType()), }; if (legacy_advertiser_.GetAdvertisingAddress() != advertising_address) { @@ -4359,7 +4079,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 +4090,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 +4123,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<model::packets::AddressType>( - initiating_address.GetAddressType()), - static_cast<model::packets::AddressType>( - advertising_address.GetAddressType()), - connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), - connect_ind.GetConnSupervisionTimeout())); + advertising_address.GetAddress(), initiating_address.GetAddress(), + static_cast<model::packets::AddressType>(initiating_address.GetAddressType()), + static_cast<model::packets::AddressType>(advertising_address.GetAddressType()), + connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), + connect_ind.GetConnSupervisionTimeout())); legacy_advertiser_.Disable(); return true; @@ -4435,8 +4151,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 +4164,20 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( } AddressWithType advertising_address{ - connect_ind.GetDestinationAddress(), - static_cast<AddressType>(connect_ind.GetAdvertisingAddressType()), + connect_ind.GetDestinationAddress(), + static_cast<AddressType>(connect_ind.GetAdvertisingAddressType()), }; AddressWithType initiating_address{ - connect_ind.GetSourceAddress(), - static_cast<AddressType>(connect_ind.GetInitiatingAddressType()), + connect_ind.GetSourceAddress(), + static_cast<AddressType>(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 +4187,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 +4198,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 +4231,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 +4244,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<model::packets::AddressType>( - initiating_address.GetAddressType()), - static_cast<model::packets::AddressType>( - advertising_address.GetAddressType()), - connect_ind.GetConnInterval(), connect_ind.GetConnPeripheralLatency(), - connect_ind.GetConnSupervisionTimeout())); + advertising_address.GetAddress(), initiating_address.GetAddress(), + static_cast<model::packets::AddressType>(initiating_address.GetAddressType()), + static_cast<model::packets::AddressType>(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 @@ -4554,17 +4263,15 @@ bool LinkLayerController::ProcessIncomingExtendedConnectRequest( if (IsLeEventUnmasked(SubeventCode::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 +4286,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<bluetooth::hci::AddressType>( - complete.GetAdvertisingAddressType())}; + incoming.GetSourceAddress(), + static_cast<bluetooth::hci::AddressType>(complete.GetAdvertisingAddressType())}; INFO(id_, "Received LE Connect complete response with advertising address {}", advertising_address); @@ -4593,10 +4300,9 @@ void LinkLayerController::IncomingLeConnectCompletePacket( HandleLeConnection(advertising_address, AddressWithType(incoming.GetDestinationAddress(), static_cast<bluetooth::hci::AddressType>( - 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 +4310,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())); + 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<uint8_t>(ErrorCode::UNSUPPORTED_REMOTE_OR_LMP_FEATURE), - 0, 0, 0)); + static_cast<uint8_t>(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)) { send_event_(bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create( - static_cast<ErrorCode>(update.GetStatus()), handle, - update.GetInterval(), update.GetLatency(), update.GetTimeout())); + static_cast<ErrorCode>(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 +4367,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 +4395,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<uint8_t>(status))); + SendLeLinkLayerPacket(model::packets::LeReadRemoteFeaturesResponseBuilder::Create( + incoming.GetDestinationAddress(), incoming.GetSourceAddress(), GetLeSupportedFeatures(), + static_cast<uint8_t>(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(), @@ -4748,13 +4439,13 @@ void LinkLayerController::IncomingLeReadRemoteFeaturesResponse( } if (IsEventUnmasked(EventCode::LE_META_EVENT)) { send_event_(bluetooth::hci::LeReadRemoteFeaturesCompleteBuilder::Create( - status, handle, response.GetFeatures())); + 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 +4459,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 +4475,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 +4495,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<model::packets::AddressType>( - 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<model::packets::AddressType>(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 +4522,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 +4546,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 +4565,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<model::packets::AddressType>( - advertising_address.GetAddressType()), - advertiser.scan_response_data), - advertiser.advertising_tx_power); + model::packets::LeScanResponseBuilder::Create( + advertising_address.GetAddress(), scanning_address.GetAddress(), + static_cast<model::packets::AddressType>(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<AddressType>(scan_request.GetScanningAddressType())}; + AddressWithType scanning_address{scan_request.GetSourceAddress(), + static_cast<AddressType>(scan_request.GetScanningAddressType())}; AddressWithType advertising_address{ - scan_request.GetDestinationAddress(), - static_cast<AddressType>(scan_request.GetAdvertisingAddressType())}; + scan_request.GetDestinationAddress(), + static_cast<AddressType>(scan_request.GetAdvertisingAddressType())}; // Note: Vol 6, Part B § 6.2 Privacy in the Advertising State. // @@ -4910,7 +4591,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 +4601,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 +4623,8 @@ void LinkLayerController::IncomingLeScanResponsePacket( } AddressWithType advertising_address{ - scan_response.GetSourceAddress(), - static_cast<AddressType>(scan_response.GetAdvertisingAddressType())}; + scan_response.GetSourceAddress(), + static_cast<AddressType>(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 +4639,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 { @@ -4996,23 +4674,22 @@ void LinkLayerController::IncomingLeScanResponsePacket( IsLeEventUnmasked(SubeventCode::EXTENDED_ADVERTISING_REPORT)) { bluetooth::hci::LeExtendedAdvertisingResponse response; response.address_ = resolved_advertising_address.GetAddress(); - response.address_type_ = - static_cast<bluetooth::hci::DirectAdvertisingAddressType>( + response.address_type_ = static_cast<bluetooth::hci::DirectAdvertisingAddressType>( 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<bluetooth::hci::PrimaryPhyType>( - scanner_.primary_scan_response_phy); - response.secondary_phy_ = static_cast<bluetooth::hci::SecondaryPhyType>( - scanner_.secondary_scan_response_phy); + response.primary_phy_ = + static_cast<bluetooth::hci::PrimaryPhyType>(scanner_.primary_scan_response_phy); + response.secondary_phy_ = + static_cast<bluetooth::hci::SecondaryPhyType>(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 +4702,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 +4725,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. @@ -5071,8 +4745,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 +4768,11 @@ void LinkLayerController::LeSynchronization() { std::vector<uint16_t> 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)); + send_event_(bluetooth::hci::LePeriodicAdvertisingSyncLostBuilder::Create(sync.sync_handle)); } } @@ -5110,8 +4781,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 +4793,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<uint8_t>(ErrorCode::CONNECTION_TIMEOUT))); return; } @@ -5137,8 +4807,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 +4816,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 +4836,12 @@ void LinkLayerController::IncomingPageRejectPacket( if (IsEventUnmasked(EventCode::CONNECTION_COMPLETE)) { send_event_(bluetooth::hci::ConnectionCompleteBuilder::Create( - static_cast<ErrorCode>(reject.GetReason()), 0, bd_addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + static_cast<ErrorCode>(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 +4855,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 +4868,19 @@ void LinkLayerController::IncomingPageResponsePacket( connection.SetRole(role); page_ = {}; - ASSERT(link_manager_add_link( - lm_.get(), reinterpret_cast<const uint8_t(*)[6]>(bd_addr.data()))); + ASSERT(link_manager_add_link(lm_.get(), reinterpret_cast<const uint8_t(*)[6]>(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 +4904,28 @@ void LinkLayerController::Close() { } void LinkLayerController::RegisterEventChannel( - const std::function<void(std::shared_ptr<bluetooth::hci::EventBuilder>)>& - send_event) { + const std::function<void(std::shared_ptr<bluetooth::hci::EventBuilder>)>& send_event) { send_event_ = send_event; } void LinkLayerController::RegisterAclChannel( - const std::function<void(std::shared_ptr<bluetooth::hci::AclBuilder>)>& - send_acl) { + const std::function<void(std::shared_ptr<bluetooth::hci::AclBuilder>)>& send_acl) { send_acl_ = send_acl; } void LinkLayerController::RegisterScoChannel( - const std::function<void(std::shared_ptr<bluetooth::hci::ScoBuilder>)>& - send_sco) { + const std::function<void(std::shared_ptr<bluetooth::hci::ScoBuilder>)>& send_sco) { send_sco_ = send_sco; } void LinkLayerController::RegisterIsoChannel( - const std::function<void(std::shared_ptr<bluetooth::hci::IsoBuilder>)>& - send_iso) { + const std::function<void(std::shared_ptr<bluetooth::hci::IsoBuilder>)>& send_iso) { send_iso_ = send_iso; } void LinkLayerController::RegisterRemoteChannel( - const std::function< - void(std::shared_ptr<model::packets::LinkLayerPacketBuilder>, Phy::Type, - int8_t)>& send_to_remote) { + const std::function<void(std::shared_ptr<model::packets::LinkLayerPacketBuilder>, Phy::Type, + int8_t)>& send_to_remote) { send_to_remote_ = send_to_remote; } @@ -5282,13 +4939,11 @@ void LinkLayerController::ForwardToLl(bluetooth::hci::CommandView command) { ASSERT(link_layer_ingest_hci(ll_.get(), packet.data(), packet.size())); } -std::vector<bluetooth::hci::Lap> const& LinkLayerController::ReadCurrentIacLap() - const { +std::vector<bluetooth::hci::Lap> const& LinkLayerController::ReadCurrentIacLap() const { return current_iac_lap_list_; } -void LinkLayerController::WriteCurrentIacLap( - std::vector<bluetooth::hci::Lap> iac_lap) { +void LinkLayerController::WriteCurrentIacLap(std::vector<bluetooth::hci::Lap> 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 +4972,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 +4986,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 +5006,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<const uint8_t(*)[6]>(bd_addr.data()))); + ASSERT(link_manager_add_link(lm_.get(), reinterpret_cast<const uint8_t(*)[6]>(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 +5052,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<ErrorCode>(reason), 0xeff, addr, - bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED)); + static_cast<ErrorCode>(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 +5098,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 +5126,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 +5135,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<uint8_t>(host_reason))); + GetAddress(), remote, static_cast<uint8_t>(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 +5171,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<uint8_t>(host_reason))); + GetAddress(), remote.GetAddress(), static_cast<uint8_t>(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<uint8_t>(host_reason))); + GetAddress(), remote.GetAddress(), static_cast<uint8_t>(host_reason))); } else { INFO(id_, "Disconnecting LE connection with {}", remote); SendLeLinkLayerPacket(model::packets::DisconnectBuilder::Create( - connections_.GetOwnAddress(handle).GetAddress(), remote.GetAddress(), - static_cast<uint8_t>(host_reason))); + connections_.GetOwnAddress(handle).GetAddress(), remote.GetAddress(), + static_cast<uint8_t>(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<uint8_t(*)[6]>(remote.GetAddress().data()))); + ASSERT(link_manager_remove_link(lm_.get(), + reinterpret_cast<uint8_t(*)[6]>(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 +5229,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 +5243,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 +5269,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 +5283,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 +5292,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 +5318,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 +5352,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<uint8_t>(ErrorCode::ROLE_CHANGE_NOT_ALLOWED))); + GetAddress(), bd_addr, static_cast<uint8_t>(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<uint8_t>(ErrorCode::SUCCESS))); + GetAddress(), bd_addr, static_cast<uint8_t>(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 +5386,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 +5409,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 +5420,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 +5434,46 @@ uint16_t LinkLayerController::ReadDefaultLinkPolicySettings() const { } void LinkLayerController::ReadLocalOobData() { - std::array<uint8_t, 16> c_array( - {'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', '0', - static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), - static_cast<uint8_t>(oob_id_ % 0x100)}); - - std::array<uint8_t, 16> r_array( - {'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', '0', - static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), - static_cast<uint8_t>(oob_id_ % 0x100)}); - - send_event_(bluetooth::hci::ReadLocalOobDataCompleteBuilder::Create( - 1, ErrorCode::SUCCESS, c_array, r_array)); + std::array<uint8_t, 16> c_array({'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', + '0', static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), + static_cast<uint8_t>(oob_id_ % 0x100)}); + + std::array<uint8_t, 16> r_array({'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '0', '0', '0', '0', '0', + '0', static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), + static_cast<uint8_t>(oob_id_ % 0x100)}); + + send_event_(bluetooth::hci::ReadLocalOobDataCompleteBuilder::Create(1, ErrorCode::SUCCESS, + c_array, r_array)); oob_id_ += 1; } void LinkLayerController::ReadLocalOobExtendedData() { - std::array<uint8_t, 16> c_192_array( - {'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', '0', '0', - static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), - static_cast<uint8_t>(oob_id_ % 0x100)}); - - std::array<uint8_t, 16> r_192_array( - {'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', '0', '0', - static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), - static_cast<uint8_t>(oob_id_ % 0x100)}); - - std::array<uint8_t, 16> c_256_array( - {'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', '0', '0', - static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), - static_cast<uint8_t>(oob_id_ % 0x100)}); - - std::array<uint8_t, 16> r_256_array( - {'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', '0', '0', - static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), - static_cast<uint8_t>(oob_id_ % 0x100)}); + std::array<uint8_t, 16> c_192_array({'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', + '0', '0', static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), + static_cast<uint8_t>(oob_id_ % 0x100)}); + + std::array<uint8_t, 16> r_192_array({'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '1', '9', '2', '0', + '0', '0', static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), + static_cast<uint8_t>(oob_id_ % 0x100)}); + + std::array<uint8_t, 16> c_256_array({'c', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', + '0', '0', static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), + static_cast<uint8_t>(oob_id_ % 0x100)}); + + std::array<uint8_t, 16> r_256_array({'r', ' ', 'a', 'r', 'r', 'a', 'y', ' ', '2', '5', '6', '0', + '0', '0', static_cast<uint8_t>((oob_id_ % 0x10000) >> 8), + static_cast<uint8_t>(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 +5486,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 +5513,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<uint8_t>(ErrorCode::SUCCESS), interval, latency, - supervision_timeout)); + connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress(), static_cast<uint8_t>(ErrorCode::SUCCESS), + interval, latency, supervision_timeout)); if (IsLeEventUnmasked(SubeventCode::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 +5536,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<uint8_t>(ErrorCode::SUCCESS), interval_max, latency, - supervision_timeout)); + connections_.GetOwnAddress(handle).GetAddress(), + connections_.GetAddress(handle).GetAddress(), static_cast<uint8_t>(ErrorCode::SUCCESS), + interval_max, latency, supervision_timeout)); if (IsLeEventUnmasked(SubeventCode::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 +5584,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<uint8_t>(reason), interval, latency, timeout)); + connections_.GetOwnAddress(connection_handle).GetAddress(), + connections_.GetAddress(connection_handle).GetAddress(), static_cast<uint8_t>(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<uint8_t, 8> rand, uint16_t ediv, - std::array<uint8_t, kLtkSize> ltk) { +void LinkLayerController::HandleLeEnableEncryption(uint16_t handle, std::array<uint8_t, 8> rand, + uint16_t ediv, + std::array<uint8_t, kLtkSize> 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<uint8_t, 8> rand, uint16_t ediv, - std::array<uint8_t, kLtkSize> ltk) { +ErrorCode LinkLayerController::LeEnableEncryption(uint16_t handle, std::array<uint8_t, 8> rand, + uint16_t ediv, + std::array<uint8_t, kLtkSize> ltk) { if (!connections_.HasHandle(handle)) { INFO(id_, "Unknown handle 0x{:04x}", handle); return ErrorCode::UNKNOWN_CONNECTION; @@ -6022,8 +5623,8 @@ ErrorCode LinkLayerController::LeEnableEncryption( return ErrorCode::SUCCESS; } -ErrorCode LinkLayerController::LeLongTermKeyRequestReply( - uint16_t handle, std::array<uint8_t, kLtkSize> ltk) { +ErrorCode LinkLayerController::LeLongTermKeyRequestReply(uint16_t handle, + std::array<uint8_t, kLtkSize> ltk) { if (!connections_.HasHandle(handle)) { INFO(id_, "Unknown handle {:04x}", handle); return ErrorCode::UNKNOWN_CONNECTION; @@ -6032,37 +5633,33 @@ 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)) { 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<uint8_t, 8>(), uint16_t(), ltk)); + connections_.GetAddress(handle).GetAddress(), std::array<uint8_t, 8>(), 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<uint8_t, 8>(), uint16_t(), std::array<uint8_t, 16>())); + connections_.GetAddress(handle).GetAddress(), std::array<uint8_t, 8>(), uint16_t(), + std::array<uint8_t, 16>())); return ErrorCode::SUCCESS; } @@ -6142,12 +5739,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; @@ -6159,16 +5755,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() { @@ -6181,8 +5775,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)); } } } @@ -6193,9 +5786,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(); @@ -6203,25 +5794,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; @@ -6236,39 +5820,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; } @@ -6284,24 +5861,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)) { @@ -6312,14 +5888,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 { @@ -6329,31 +5904,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) { @@ -6367,13 +5938,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; @@ -6385,43 +5956,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<milliseconds>( - connections_.TimeUntilLinkExpired(handle)), - [this, handle] { CheckExpiringConnection(handle); }); + SendLinkLayerPacket(model::packets::PingRequestBuilder::Create(my_address.GetAddress(), + destination.GetAddress())); + ScheduleTask( + std::chrono::duration_cast<milliseconds>(connections_.TimeUntilLinkExpired(handle)), + [this, handle] { CheckExpiringConnection(handle); }); return; } - ScheduleTask(std::chrono::duration_cast<milliseconds>( - connections_.TimeUntilLinkNearExpiring(handle)), - [this, handle] { CheckExpiringConnection(handle); }); + ScheduleTask( + std::chrono::duration_cast<milliseconds>(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::vector<uint8_t>>(std::move(sco_bytes)))); + auto sco_view = bluetooth::hci::ScoView::Create( + pdl::packet::slice(std::make_shared<std::vector<uint8_t>>(std::move(sco_bytes)))); ASSERT(sco_view.IsValid()); return SchedulePeriodicTask(0ms, 20ms, [this, address, sco_view]() { @@ -6432,10 +6001,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; @@ -6444,17 +6012,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/tools/rootcanal/model/controller/link_layer_controller.h b/tools/rootcanal/model/controller/link_layer_controller.h index 57e4cbf5d3..75a8fd3af4 100644 --- a/tools/rootcanal/model/controller/link_layer_controller.h +++ b/tools/rootcanal/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<uint8_t, LinkLayerController::kIrkSize> irk); + static Address generate_rpa(std::array<uint8_t, LinkLayerController::kIrkSize> irk); // Return true if the input IRK is all 0s. static bool irk_is_zero(std::array<uint8_t, LinkLayerController::kIrkSize> 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<void(std::shared_ptr<bluetooth::hci::EventBuilder>)>& - send_event); + const std::function<void(std::shared_ptr<bluetooth::hci::EventBuilder>)>& send_event); void RegisterAclChannel( - const std::function<void(std::shared_ptr<bluetooth::hci::AclBuilder>)>& - send_acl); + const std::function<void(std::shared_ptr<bluetooth::hci::AclBuilder>)>& send_acl); void RegisterScoChannel( - const std::function<void(std::shared_ptr<bluetooth::hci::ScoBuilder>)>& - send_sco); + const std::function<void(std::shared_ptr<bluetooth::hci::ScoBuilder>)>& send_sco); void RegisterIsoChannel( - const std::function<void(std::shared_ptr<bluetooth::hci::IsoBuilder>)>& - send_iso); + const std::function<void(std::shared_ptr<bluetooth::hci::IsoBuilder>)>& send_iso); void RegisterRemoteChannel( - const std::function< - void(std::shared_ptr<model::packets::LinkLayerPacketBuilder>, - Phy::Type, int8_t)>& send_to_remote); + const std::function<void(std::shared_ptr<model::packets::LinkLayerPacketBuilder>, + 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<AddressWithType> GenerateResolvablePrivateAddress( - AddressWithType address, IrkSelection irk); + std::optional<AddressWithType> 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<uint8_t, 8> rand, - uint16_t ediv, + void HandleLeEnableEncryption(uint16_t handle, std::array<uint8_t, 8> rand, uint16_t ediv, std::array<uint8_t, kLtkSize> ltk); - ErrorCode LeEnableEncryption(uint16_t handle, std::array<uint8_t, 8> rand, - uint16_t ediv, + ErrorCode LeEnableEncryption(uint16_t handle, std::array<uint8_t, 8> rand, uint16_t ediv, std::array<uint8_t, kLtkSize> ltk); - ErrorCode LeLongTermKeyRequestReply(uint16_t handle, - std::array<uint8_t, kLtkSize> ltk); + ErrorCode LeLongTermKeyRequestReply(uint16_t handle, std::array<uint8_t, kLtkSize> 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<uint8_t, kIrkSize> peer_irk, - std::array<uint8_t, kIrkSize> local_irk); + ErrorCode LeAddDeviceToResolvingList(PeerAddressType peer_identity_address_type, + Address peer_identity_address, + std::array<uint8_t, kIrkSize> peer_irk, + std::array<uint8_t, kIrkSize> 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<uint8_t>& advertising_data); // HCI command LE_Set_Scan_Response_Data (Vol 4, Part E § 7.8.8). - ErrorCode LeSetScanResponseData( - const std::vector<uint8_t>& scan_response_data); + ErrorCode LeSetScanResponseData(const std::vector<uint8_t>& 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<uint8_t>& advertising_data); + ErrorCode LeSetExtendedAdvertisingData(uint8_t advertising_handle, + bluetooth::hci::Operation operation, + bluetooth::hci::FragmentPreference fragment_preference, + const std::vector<uint8_t>& 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<uint8_t>& scan_response_data); + ErrorCode LeSetExtendedScanResponseData(uint8_t advertising_handle, + bluetooth::hci::Operation operation, + bluetooth::hci::FragmentPreference fragment_preference, + const std::vector<uint8_t>& scan_response_data); // HCI command LE_Set_Extended_Advertising_Enable (Vol 4, Part E § 7.8.56). - ErrorCode LeSetExtendedAdvertisingEnable( - bool enable, const std::vector<bluetooth::hci::EnabledSet>& sets); + ErrorCode LeSetExtendedAdvertisingEnable(bool enable, + const std::vector<bluetooth::hci::EnabledSet>& 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<bluetooth::hci::ScanningPhyParameters> - scanning_phy_parameters); + bluetooth::hci::OwnAddressType own_address_type, + bluetooth::hci::LeScanningFilterPolicy scanning_filter_policy, uint8_t scanning_phys, + std::vector<bluetooth::hci::ScanningPhyParameters> 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<bluetooth::hci::InitiatingPhyParameters> - initiating_phy_parameters); + bluetooth::hci::InitiatorFilterPolicy initiator_filter_policy, + bluetooth::hci::OwnAddressType own_address_type, AddressWithType peer_address, + uint8_t initiating_phys, + std::vector<bluetooth::hci::InitiatingPhyParameters> 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<uint8_t>& advertising_data); + ErrorCode LeSetPeriodicAdvertisingData(uint8_t advertising_handle, + bluetooth::hci::Operation operation, + const std::vector<uint8_t>& 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<uint8_t> 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<uint8_t> acpf_uuid_data, uint8_t* apcf_available_spaces); - ErrorCode LeApcfServiceSolicitationUuid( - bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, - std::vector<uint8_t> acpf_uuid_data, uint8_t* apcf_available_spaces); + ErrorCode LeApcfServiceSolicitationUuid(bluetooth::hci::ApcfAction apcf_action, + uint8_t apcf_filter_index, + std::vector<uint8_t> acpf_uuid_data, + uint8_t* apcf_available_spaces); - ErrorCode LeApcfLocalName(bluetooth::hci::ApcfAction apcf_action, - uint8_t apcf_filter_index, - std::vector<uint8_t> apcf_local_name, - uint8_t* apcf_available_spaces); + ErrorCode LeApcfLocalName(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector<uint8_t> apcf_local_name, uint8_t* apcf_available_spaces); ErrorCode LeApcfManufacturerData(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, std::vector<uint8_t> 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<uint8_t> 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<uint8_t> apcf_ad_data, + ErrorCode LeApcfAdTypeFilter(bluetooth::hci::ApcfAction apcf_action, uint8_t apcf_filter_index, + uint8_t ad_type, std::vector<uint8_t> apcf_ad_data, std::vector<uint8_t> apcf_ad_data_mask, uint8_t* apcf_available_spaces); - protected: - void SendLinkLayerPacket( - std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet, - int8_t tx_power = 0); - void SendLeLinkLayerPacket( - std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet, - int8_t tx_power = 0); +protected: + void SendLinkLayerPacket(std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet, + int8_t tx_power = 0); + void SendLeLinkLayerPacket(std::unique_ptr<model::packets::LinkLayerPacketBuilder> 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<uint8_t, kLocalNameSize> const& GetLocalName() { - return local_name_; - } + std::array<uint8_t, kLocalNameSize> 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<uint8_t> const& local_name); void SetLocalName(std::array<uint8_t, kLocalNameSize> const& local_name); - void SetExtendedInquiryResponse( - std::array<uint8_t, 240> const& extended_inquiry_response); - void SetExtendedInquiryResponse( - std::vector<uint8_t> const& extended_inquiry_response); + void SetExtendedInquiryResponse(std::array<uint8_t, 240> const& extended_inquiry_response); + void SetExtendedInquiryResponse(std::vector<uint8_t> 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<uint8_t, kLocalNameSize> local_name_{}; // Extended Inquiry Response (Vol 4, Part E § 6.24). - std::array<uint8_t, kExtendedInquiryResponseSize> - extended_inquiry_response_{}; + std::array<uint8_t, kExtendedInquiryResponseSize> 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<void(std::shared_ptr<bluetooth::hci::AclBuilder>)> send_acl_; - std::function<void(std::shared_ptr<bluetooth::hci::EventBuilder>)> - send_event_; + std::function<void(std::shared_ptr<bluetooth::hci::EventBuilder>)> send_event_; std::function<void(std::shared_ptr<bluetooth::hci::ScoBuilder>)> send_sco_; std::function<void(std::shared_ptr<bluetooth::hci::IsoBuilder>)> send_iso_; // Callback to send packets to remote devices. - std::function<void(std::shared_ptr<model::packets::LinkLayerPacketBuilder>, - Phy::Type phy_type, int8_t tx_power)> - send_to_remote_; + std::function<void(std::shared_ptr<model::packets::LinkLayerPacketBuilder>, 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<AddressWithType> pending_scan_request{}; - std::optional<std::chrono::steady_clock::time_point> - pending_scan_request_timeout{}; + std::optional<std::chrono::steady_clock::time_point> pending_scan_request_timeout{}; // Time keeping std::optional<std::chrono::steady_clock::time_point> 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> 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> task_queue_{}; TaskId task_counter_{0}; diff --git a/tools/rootcanal/model/controller/sco_connection.cc b/tools/rootcanal/model/controller/sco_connection.cc index e0fb08702f..0ecacf3f6f 100644 --- a/tools/rootcanal/model/controller/sco_connection.cc +++ b/tools/rootcanal/model/controller/sco_connection.cc @@ -41,14 +41,13 @@ bool ScoConnectionParameters::IsExtended() const { return ((packet_type ^ edr) & ~legacy) != 0; } -std::optional<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() - const { +std::optional<ScoLinkParameters> 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<ScoLinkParameters> 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<ScoLinkParameters> 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<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() // Compute retransmission window. unsigned retransmission_window = - retransmission_effort == - (uint8_t)RetransmissionEffort::NO_RETRANSMISSION - ? 0 - : retransmission_effort == - (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER - ? rx.slots + tx.slots - : retransmission_effort == - (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY - ? 2 * (rx.slots + tx.slots) - : 0; + retransmission_effort == (uint8_t)RetransmissionEffort::NO_RETRANSMISSION ? 0 + : retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER + ? rx.slots + tx.slots + : retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY + ? 2 * (rx.slots + tx.slots) + : 0; 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<ScoLinkParameters> 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<ScoLinkParameters> ScoConnectionParameters::GetLinkParameters() // Parameter negotiation for SCO connections: // Check packet types and validate bandwidth and latency requirements. - if (retransmission_effort == - (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER || - retransmission_effort == - (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY) { + if (retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_POWER || + retransmission_effort == (uint8_t)RetransmissionEffort::OPTIMIZED_FOR_LINK_QUALITY) { WARNING("SCO Retransmission effort must be None or Don't care"); return {}; } @@ -221,26 +204,24 @@ std::optional<ScoLinkParameters> 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/tools/rootcanal/model/controller/sco_connection.h b/tools/rootcanal/model/controller/sco_connection.h index decd842e4e..b086642dbe 100644 --- a/tools/rootcanal/model/controller/sco_connection.h +++ b/tools/rootcanal/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<TaskId()> startStream); void StopStream(std::function<void(TaskId)> 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/tools/rootcanal/model/controller/vendor_commands/le_apcf.cc b/tools/rootcanal/model/controller/vendor_commands/le_apcf.cc index a28fcd73d0..e4a774e96f 100644 --- a/tools/rootcanal/model/controller/vendor_commands/le_apcf.cc +++ b/tools/rootcanal/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 <typename T> -ErrorCode ApcfScanner::UpdateFilterList(std::vector<T>& filter_list, - size_t max_filter_list_size, - bluetooth::hci::ApcfAction action, - T filter) { +ErrorCode ApcfScanner::UpdateFilterList(std::vector<T>& 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<T>& 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<T>& 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<uint8_t> apcf_uuid_data, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfServiceUuid(ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector<uint8_t> apcf_uuid_data, + uint8_t* apcf_available_spaces) { size_t uuid_data_size = apcf_uuid_data.size() / 2; std::vector<uint8_t> uuid_data(std::begin(apcf_uuid_data), std::begin(apcf_uuid_data) + uuid_data_size); - std::vector<uint8_t> uuid_data_mask( - std::begin(apcf_uuid_data) + uuid_data_size, std::end(apcf_uuid_data)); + std::vector<uint8_t> 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<uint8_t> apcf_uuid_data, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfServiceSolicitationUuid(ApcfAction apcf_action, + uint8_t apcf_filter_index, + std::vector<uint8_t> apcf_uuid_data, + uint8_t* apcf_available_spaces) { size_t uuid_data_size = apcf_uuid_data.size() / 2; std::vector<uint8_t> uuid_data(std::begin(apcf_uuid_data), std::begin(apcf_uuid_data) + uuid_data_size); - std::vector<uint8_t> uuid_data_mask( - std::begin(apcf_uuid_data) + uuid_data_size, std::end(apcf_uuid_data)); + std::vector<uint8_t> 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<uint8_t> apcf_local_name, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfLocalName(ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector<uint8_t> apcf_local_name, + uint8_t* apcf_available_spaces) { size_t local_name_size = apcf_local_name.size() / 2; - std::vector<uint8_t> local_name( - std::begin(apcf_local_name), - std::begin(apcf_local_name) + local_name_size); - std::vector<uint8_t> 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<uint8_t> local_name(std::begin(apcf_local_name), + std::begin(apcf_local_name) + local_name_size); + std::vector<uint8_t> 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<uint8_t> apcf_manufacturer_data, - uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfManufacturerData(ApcfAction apcf_action, + uint8_t apcf_filter_index, + std::vector<uint8_t> apcf_manufacturer_data, + uint8_t* apcf_available_spaces) { size_t manufacturer_data_size = apcf_manufacturer_data.size() / 2; std::vector<uint8_t> 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<uint8_t> 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<uint8_t> apcf_service_data, uint8_t* apcf_available_spaces) { +ErrorCode LinkLayerController::LeApcfServiceData(ApcfAction apcf_action, uint8_t apcf_filter_index, + std::vector<uint8_t> apcf_service_data, + uint8_t* apcf_available_spaces) { size_t service_data_size = apcf_service_data.size() / 2; - std::vector<uint8_t> service_data( - std::begin(apcf_service_data), - std::begin(apcf_service_data) + service_data_size); - std::vector<uint8_t> service_data_mask( - std::begin(apcf_service_data) + service_data_size, - std::end(apcf_service_data)); + std::vector<uint8_t> service_data(std::begin(apcf_service_data), + std::begin(apcf_service_data) + service_data_size); + std::vector<uint8_t> 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<uint8_t> apcf_ad_data, std::vector<uint8_t> 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<uint8_t> apcf_ad_data, + std::vector<uint8_t> 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/tools/rootcanal/model/controller/vendor_commands/le_apcf.h b/tools/rootcanal/model/controller/vendor_commands/le_apcf.h index 5c6cce40c0..862ccfdb50 100644 --- a/tools/rootcanal/model/controller/vendor_commands/le_apcf.h +++ b/tools/rootcanal/model/controller/vendor_commands/le_apcf.h @@ -86,8 +86,7 @@ struct ApcfScanner { // Apply the requested modification to the selected // filter list. template <typename T> - ErrorCode UpdateFilterList(std::vector<T>& filter_list, - size_t max_filter_list_size, + ErrorCode UpdateFilterList(std::vector<T>& filter_list, size_t max_filter_list_size, bluetooth::hci::ApcfAction action, T filter); }; diff --git a/tools/rootcanal/model/devices/baseband_sniffer.cc b/tools/rootcanal/model/devices/baseband_sniffer.cc index fd3f01887b..dab58052c2 100644 --- a/tools/rootcanal/model/devices/baseband_sniffer.cc +++ b/tools/rootcanal/model/devices/baseband_sniffer.cc @@ -42,8 +42,7 @@ BaseBandSniffer::BaseBandSniffer(const std::string& filename) { output_.flush(); } -void BaseBandSniffer::AppendRecord( - std::unique_ptr<bredr_bb::BaseBandPacketBuilder> packet) { +void BaseBandSniffer::AppendRecord(std::unique_ptr<bredr_bb::BaseBandPacketBuilder> packet) { std::vector<uint8_t> bytes = packet->SerializeToBytes(); pcap::WriteRecordHeader(output_, bytes.size()); output_.write((char*)bytes.data(), bytes.size()); @@ -52,12 +51,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]; @@ -80,41 +77,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; @@ -135,22 +129,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()); @@ -158,16 +150,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/tools/rootcanal/model/devices/baseband_sniffer.h b/tools/rootcanal/model/devices/baseband_sniffer.h index 96c2b7e84e..09764794cb 100644 --- a/tools/rootcanal/model/devices/baseband_sniffer.h +++ b/tools/rootcanal/model/devices/baseband_sniffer.h @@ -35,7 +35,7 @@ class BaseBandPacketBuilder; 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<bredr_bb::BaseBandPacketBuilder> packet); std::ofstream output_; }; diff --git a/tools/rootcanal/model/devices/beacon.cc b/tools/rootcanal/model/devices/beacon.cc index d61d44bbb7..1c7c14b054 100644 --- a/tools/rootcanal/model/devices/beacon.cc +++ b/tools/rootcanal/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<std::string>& 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(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); } } -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); + std::move(LeScanResponseBuilder::Create( + address_, packet.GetSourceAddress(), AddressType::PUBLIC, + std::vector(scan_response_data_.begin(), scan_response_data_.end()))), + Phy::Type::LOW_ENERGY); } } diff --git a/tools/rootcanal/model/devices/beacon.h b/tools/rootcanal/model/devices/beacon.h index 6b33197dd7..33bd7be25c 100644 --- a/tools/rootcanal/model/devices/beacon.h +++ b/tools/rootcanal/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<std::string>& 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<uint8_t, 31> advertising_data_{}; std::array<uint8_t, 31> 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/tools/rootcanal/model/devices/beacon_swarm.cc b/tools/rootcanal/model/devices/beacon_swarm.cc index af4b7555c3..b0013d9b2b 100644 --- a/tools/rootcanal/model/devices/beacon_swarm.cc +++ b/tools/rootcanal/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<std::string>& 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/tools/rootcanal/model/devices/beacon_swarm.h b/tools/rootcanal/model/devices/beacon_swarm.h index 69f6dd44bc..70fe492821 100644 --- a/tools/rootcanal/model/devices/beacon_swarm.h +++ b/tools/rootcanal/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<std::string>& args); virtual ~BeaconSwarm() = default; @@ -40,7 +40,7 @@ class BeaconSwarm : public Beacon { virtual void Tick() override; - private: +private: static bool registered_; }; diff --git a/tools/rootcanal/model/devices/device.cc b/tools/rootcanal/model/devices/device.cc index 9fadf9e3df..59bfa7ffcf 100644 --- a/tools/rootcanal/model/devices/device.cc +++ b/tools/rootcanal/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<model::packets::LinkLayerPacketBuilder> packet, - Phy::Type type, int8_t tx_power) { +void Device::SendLinkLayerPacket(std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet, + Phy::Type type, int8_t tx_power) { SendLinkLayerPacket(packet->SerializeToBytes(), type, tx_power); } -void Device::SendLinkLayerPacket(std::vector<uint8_t> const& packet, - Phy::Type type, int8_t tx_power) { +void Device::SendLinkLayerPacket(std::vector<uint8_t> 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<void()> close_callback) { } void Device::RegisterLinkLayerChannel( - std::function<void(std::vector<uint8_t> const&, Phy::Type, int8_t)> - send_ll) { + std::function<void(std::vector<uint8_t> const&, Phy::Type, int8_t)> send_ll) { send_ll_ = send_ll; } diff --git a/tools/rootcanal/model/devices/device.h b/tools/rootcanal/model/devices/device.h index 3d5f258a29..96bccfc1e7 100644 --- a/tools/rootcanal/model/devices/device.h +++ b/tools/rootcanal/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<model::packets::LinkLayerPacketBuilder> packet, - Phy::Type type, int8_t tx_power = 0); + void SendLinkLayerPacket(std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet, + Phy::Type type, int8_t tx_power = 0); - void SendLinkLayerPacket(std::vector<uint8_t> const& packet, Phy::Type type, - int8_t tx_power = 0); + void SendLinkLayerPacket(std::vector<uint8_t> const& packet, Phy::Type type, int8_t tx_power = 0); void RegisterLinkLayerChannel( - std::function<void(std::vector<uint8_t> const&, Phy::Type, int8_t)> - send_ll); + std::function<void(std::vector<uint8_t> const&, Phy::Type, int8_t)> send_ll); void RegisterCloseCallback(std::function<void()> close_callback); - protected: +protected: // Unique device address. Used as public device address for // Bluetooth activities. Address address_; diff --git a/tools/rootcanal/model/devices/hci_device.cc b/tools/rootcanal/model/devices/hci_device.cc index 9f0b30b5f3..5597fd05fb 100644 --- a/tools/rootcanal/model/devices/hci_device.cc +++ b/tools/rootcanal/model/devices/hci_device.cc @@ -30,35 +30,34 @@ namespace rootcanal { HciDevice::HciDevice(std::shared_ptr<HciTransport> transport, ControllerProperties const& properties) - : DualModeController(ControllerProperties(properties)), - transport_(transport) { + : DualModeController(ControllerProperties(properties)), transport_(transport) { link_layer_controller_.SetLocalName(std::vector<uint8_t>({ - '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<uint8_t>({ - 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<std::vector<uint8_t>> packet) { @@ -75,30 +74,29 @@ HciDevice::HciDevice(std::shared_ptr<HciTransport> transport, }); transport_->RegisterCallbacks( - [this](PacketType packet_type, - const std::shared_ptr<std::vector<uint8_t>> 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<std::vector<uint8_t>> 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/tools/rootcanal/model/devices/hci_device.h b/tools/rootcanal/model/devices/hci_device.h index 38be7fb7bb..020e6af83c 100644 --- a/tools/rootcanal/model/devices/hci_device.h +++ b/tools/rootcanal/model/devices/hci_device.h @@ -26,14 +26,12 @@ namespace rootcanal { class HciDevice : public DualModeController { - public: - HciDevice(std::shared_ptr<HciTransport> transport, - ControllerProperties const& properties); +public: + HciDevice(std::shared_ptr<HciTransport> transport, ControllerProperties const& properties); ~HciDevice() = default; - static std::shared_ptr<HciDevice> Create( - std::shared_ptr<HciTransport> transport, - ControllerProperties const& properties) { + static std::shared_ptr<HciDevice> Create(std::shared_ptr<HciTransport> transport, + ControllerProperties const& properties) { return std::make_shared<HciDevice>(transport, properties); } @@ -43,7 +41,7 @@ class HciDevice : public DualModeController { void Close() override; - private: +private: std::shared_ptr<HciTransport> transport_; }; diff --git a/tools/rootcanal/model/devices/link_layer_socket_device.cc b/tools/rootcanal/model/devices/link_layer_socket_device.cc index e61badf070..fad0fbaffb 100644 --- a/tools/rootcanal/model/devices/link_layer_socket_device.cc +++ b/tools/rootcanal/model/devices/link_layer_socket_device.cc @@ -34,16 +34,15 @@ using std::vector; namespace rootcanal { -LinkLayerSocketDevice::LinkLayerSocketDevice( - std::shared_ptr<AsyncDataChannel> socket_fd, Phy::Type phy_type) +LinkLayerSocketDevice::LinkLayerSocketDevice(std::shared_ptr<AsyncDataChannel> socket_fd, + Phy::Type phy_type) : socket_(socket_fd), phy_type_(phy_type), size_bytes_(std::make_shared<std::vector<uint8_t>>(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<uint8_t> packet_bytes = packet.bytes().bytes(); std::vector<uint8_t> size_bytes; pdl::packet::Builder::write_le<uint32_t>(size_bytes, packet_bytes.size()); diff --git a/tools/rootcanal/model/devices/link_layer_socket_device.h b/tools/rootcanal/model/devices/link_layer_socket_device.h index b91263a479..5d28e79db1 100644 --- a/tools/rootcanal/model/devices/link_layer_socket_device.h +++ b/tools/rootcanal/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<AsyncDataChannel> socket_fd, - Phy::Type phy_type); +public: + LinkLayerSocketDevice(std::shared_ptr<AsyncDataChannel> socket_fd, Phy::Type phy_type); LinkLayerSocketDevice(LinkLayerSocketDevice&& s) = default; virtual ~LinkLayerSocketDevice() = default; - static std::unique_ptr<Device> Create( - std::shared_ptr<AsyncDataChannel> socket_fd, Phy::Type phy_type) { + static std::unique_ptr<Device> Create(std::shared_ptr<AsyncDataChannel> socket_fd, + Phy::Type phy_type) { return std::make_unique<LinkLayerSocketDevice>(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<AsyncDataChannel> socket_; Phy::Type phy_type_; bool receiving_size_{true}; diff --git a/tools/rootcanal/model/devices/scripted_beacon.cc b/tools/rootcanal/model/devices/scripted_beacon.cc index 9095d11401..20e0906411 100644 --- a/tools/rootcanal/model/devices/scripted_beacon.cc +++ b/tools/rootcanal/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<std::string>& 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<std::string>& 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); + 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); } } } 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/tools/rootcanal/model/devices/scripted_beacon.h b/tools/rootcanal/model/devices/scripted_beacon.h index 4d62ac6527..05ad079efb 100644 --- a/tools/rootcanal/model/devices/scripted_beacon.h +++ b/tools/rootcanal/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<std::string>& 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/tools/rootcanal/model/devices/sniffer.cc b/tools/rootcanal/model/devices/sniffer.cc index 793b078b52..02f5766ead 100644 --- a/tools/rootcanal/model/devices/sniffer.cc +++ b/tools/rootcanal/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<std::string>& args) { if (args.size() >= 2) { @@ -37,8 +36,8 @@ Sniffer::Sniffer(const std::vector<std::string>& 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/tools/rootcanal/model/devices/sniffer.h b/tools/rootcanal/model/devices/sniffer.h index 60bee3e9c2..1f04d295c9 100644 --- a/tools/rootcanal/model/devices/sniffer.h +++ b/tools/rootcanal/model/devices/sniffer.h @@ -26,7 +26,7 @@ namespace rootcanal { class Sniffer : public Device { - public: +public: Sniffer(const std::vector<std::string>& 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/tools/rootcanal/model/hci/h4_data_channel_packetizer.cc b/tools/rootcanal/model/hci/h4_data_channel_packetizer.cc index 15e6f3d63c..aa8edbe0ad 100644 --- a/tools/rootcanal/model/hci/h4_data_channel_packetizer.cc +++ b/tools/rootcanal/model/hci/h4_data_channel_packetizer.cc @@ -33,16 +33,14 @@ namespace rootcanal { H4DataChannelPacketizer::H4DataChannelPacketizer( - std::shared_ptr<AsyncDataChannel> socket, PacketReadCallback command_cb, - PacketReadCallback event_cb, PacketReadCallback acl_cb, - PacketReadCallback sco_cb, PacketReadCallback iso_cb, - ClientDisconnectCallback disconnect_cb) + std::shared_ptr<AsyncDataChannel> 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<AsyncDataChannel> socket) { - +void H4DataChannelPacketizer::OnDataReady(std::shared_ptr<AsyncDataChannel> 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/tools/rootcanal/model/hci/h4_data_channel_packetizer.h b/tools/rootcanal/model/hci/h4_data_channel_packetizer.h index 272373c26e..f32b64360b 100644 --- a/tools/rootcanal/model/hci/h4_data_channel_packetizer.h +++ b/tools/rootcanal/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<AsyncDataChannel> socket, - PacketReadCallback command_cb, - PacketReadCallback event_cb, - PacketReadCallback acl_cb, PacketReadCallback sco_cb, - PacketReadCallback iso_cb, +public: + H4DataChannelPacketizer(std::shared_ptr<AsyncDataChannel> 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<AsyncDataChannel> socket); - private: +private: std::shared_ptr<AsyncDataChannel> uart_socket_; H4Parser h4_parser_; diff --git a/tools/rootcanal/model/hci/h4_parser.cc b/tools/rootcanal/model/hci/h4_parser.cc index b84ad1f630..c3aa76ddd2 100644 --- a/tools/rootcanal/model/hci/h4_parser.cc +++ b/tools/rootcanal/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<size_t>(PacketType::ISO) + 1] = { +size_t H4Parser::HciGetPacketLengthForType(PacketType type, const uint8_t* preamble) { + static const size_t packet_length_offset[static_cast<size_t>(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<size_t>(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<size_t>(PacketType::ISO) + 1] = - { + static const size_t preamble_size[static_cast<size_t>(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<PacketType>(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/tools/rootcanal/model/hci/h4_parser.h b/tools/rootcanal/model/hci/h4_parser.h index e7a63636fa..a10d0b2023 100644 --- a/tools/rootcanal/model/hci/h4_parser.h +++ b/tools/rootcanal/model/hci/h4_parser.h @@ -44,12 +44,12 @@ using ClientDisconnectCallback = std::function<void()>; // 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/tools/rootcanal/model/hci/hci_sniffer.cc b/tools/rootcanal/model/hci/hci_sniffer.cc index ea3e2cbeac..9a0509daa1 100644 --- a/tools/rootcanal/model/hci/hci_sniffer.cc +++ b/tools/rootcanal/model/hci/hci_sniffer.cc @@ -28,9 +28,7 @@ HciSniffer::HciSniffer(std::shared_ptr<HciTransport> transport, SetOutputStream(outputStream); } -void HciSniffer::SetPcapFilter(std::shared_ptr<PcapFilter> filter) { - filter_ = filter; -} +void HciSniffer::SetPcapFilter(std::shared_ptr<PcapFilter> filter) { filter_ = filter; } void HciSniffer::SetOutputStream(std::shared_ptr<std::ostream> outputStream) { output_ = outputStream; @@ -42,8 +40,7 @@ void HciSniffer::SetOutputStream(std::shared_ptr<std::ostream> outputStream) { } } -void HciSniffer::AppendRecord(PacketDirection packet_direction, - PacketType packet_type, +void HciSniffer::AppendRecord(PacketDirection packet_direction, PacketType packet_type, const std::vector<uint8_t>& 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<uint8_t> filtered_packet = - filter_->FilterHciPacket(packet, idc); + std::vector<uint8_t> 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<std::vector<uint8_t>> 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<std::vector<uint8_t>> 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<uint8_t>& packet) { +void HciSniffer::Send(PacketType packet_type, const std::vector<uint8_t>& packet) { AppendRecord(PacketDirection::CONTROLLER_TO_HOST, packet_type, packet); transport_->Send(packet_type, packet); } diff --git a/tools/rootcanal/model/hci/hci_sniffer.h b/tools/rootcanal/model/hci/hci_sniffer.h index 5ad47fbe7b..79a2b9c76e 100644 --- a/tools/rootcanal/model/hci/hci_sniffer.h +++ b/tools/rootcanal/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<HciTransport> transport, std::shared_ptr<std::ostream> outputStream = nullptr, std::shared_ptr<PcapFilter> filter = nullptr); ~HciSniffer() = default; - static std::shared_ptr<HciTransport> Create( - std::shared_ptr<HciTransport> transport, - std::shared_ptr<std::ostream> outputStream = nullptr, - std::shared_ptr<PcapFilter> /*filter*/ = nullptr) { + static std::shared_ptr<HciTransport> Create(std::shared_ptr<HciTransport> transport, + std::shared_ptr<std::ostream> outputStream = nullptr, + std::shared_ptr<PcapFilter> /*filter*/ = nullptr) { return std::make_shared<HciSniffer>(transport, outputStream); } @@ -52,18 +51,15 @@ class HciSniffer : public HciTransport { void SetOutputStream(std::shared_ptr<std::ostream> outputStream); void SetPcapFilter(std::shared_ptr<PcapFilter> filter); - void Send(PacketType packet_type, - const std::vector<uint8_t>& packet) override; + void Send(PacketType packet_type, const std::vector<uint8_t>& 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<uint8_t>& packet); +private: + void AppendRecord(PacketDirection direction, PacketType type, const std::vector<uint8_t>& packet); std::shared_ptr<std::ostream> output_; std::shared_ptr<HciTransport> transport_; diff --git a/tools/rootcanal/model/hci/hci_socket_transport.cc b/tools/rootcanal/model/hci/hci_socket_transport.cc index 0fc556e9b7..d7127f561b 100644 --- a/tools/rootcanal/model/hci/hci_socket_transport.cc +++ b/tools/rootcanal/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<uint8_t>& raw_command) { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::make_shared<std::vector<uint8_t>>(raw_command); - packet_callback(PacketType::COMMAND, packet_copy); - }, - [](const std::vector<uint8_t>&) { - FATAL("Unexpected Event in HciSocketTransport!"); - }, - [packet_callback](const std::vector<uint8_t>& raw_acl) { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::make_shared<std::vector<uint8_t>>(raw_acl); - packet_callback(PacketType::ACL, packet_copy); - }, - [packet_callback](const std::vector<uint8_t>& raw_sco) { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::make_shared<std::vector<uint8_t>>(raw_sco); - packet_callback(PacketType::SCO, packet_copy); - }, - [packet_callback](const std::vector<uint8_t>& raw_iso) { - std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::make_shared<std::vector<uint8_t>>(raw_iso); - packet_callback(PacketType::ISO, packet_copy); - }, - close_callback); + socket_, + [packet_callback](const std::vector<uint8_t>& raw_command) { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::make_shared<std::vector<uint8_t>>(raw_command); + packet_callback(PacketType::COMMAND, packet_copy); + }, + [](const std::vector<uint8_t>&) { FATAL("Unexpected Event in HciSocketTransport!"); }, + [packet_callback](const std::vector<uint8_t>& raw_acl) { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::make_shared<std::vector<uint8_t>>(raw_acl); + packet_callback(PacketType::ACL, packet_copy); + }, + [packet_callback](const std::vector<uint8_t>& raw_sco) { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::make_shared<std::vector<uint8_t>>(raw_sco); + packet_callback(PacketType::SCO, packet_copy); + }, + [packet_callback](const std::vector<uint8_t>& raw_iso) { + std::shared_ptr<std::vector<uint8_t>> packet_copy = + std::make_shared<std::vector<uint8_t>>(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<uint8_t>& packet) { +void HciSocketTransport::Send(PacketType packet_type, const std::vector<uint8_t>& 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<uint8_t>(packet_type); diff --git a/tools/rootcanal/model/hci/hci_socket_transport.h b/tools/rootcanal/model/hci/hci_socket_transport.h index e6e4a356ac..660c42e3ea 100644 --- a/tools/rootcanal/model/hci/hci_socket_transport.h +++ b/tools/rootcanal/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<AsyncDataChannel> socket); ~HciSocketTransport() = default; - static std::shared_ptr<HciTransport> Create( - std::shared_ptr<AsyncDataChannel> socket) { + static std::shared_ptr<HciTransport> Create(std::shared_ptr<AsyncDataChannel> socket) { return std::make_shared<HciSocketTransport>(socket); } - void Send(PacketType packet_type, - const std::vector<uint8_t>& packet) override; + void Send(PacketType packet_type, const std::vector<uint8_t>& 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<AsyncDataChannel> socket_; H4DataChannelPacketizer h4_{socket_, [](const std::vector<uint8_t>&) {}, diff --git a/tools/rootcanal/model/hci/hci_transport.h b/tools/rootcanal/model/hci/hci_transport.h index 5aa10f160c..9f3662e692 100644 --- a/tools/rootcanal/model/hci/hci_transport.h +++ b/tools/rootcanal/model/hci/hci_transport.h @@ -24,22 +24,19 @@ namespace rootcanal { -using PacketCallback = std::function<void( - PacketType, const std::shared_ptr<std::vector<uint8_t>>)>; +using PacketCallback = std::function<void(PacketType, const std::shared_ptr<std::vector<uint8_t>>)>; using CloseCallback = std::function<void()>; 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<uint8_t> const& packet) = 0; + virtual void Send(PacketType packet_type, std::vector<uint8_t> 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/tools/rootcanal/model/setup/async_manager.cc b/tools/rootcanal/model/setup/async_manager.cc index caa92a0fc0..2475212bc1 100644 --- a/tools/rootcanal/model/setup/async_manager.cc +++ b/tools/rootcanal/model/setup/async_manager.cc @@ -16,26 +16,29 @@ #include "async_manager.h" +#include <fcntl.h> +#include <sys/select.h> +#include <unistd.h> + #include <algorithm> #include <atomic> #include <condition_variable> -#include <fcntl.h> #include <mutex> -#include <sys/select.h> #include <thread> -#include <unistd.h> #include <vector> #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<std::recursive_mutex> 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<Task>( - std::chrono::steady_clock::now() + delay, callback, user_id)); + return scheduleTask( + std::make_shared<Task>(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<Task>( - std::chrono::steady_clock::now() + delay, period, callback, user_id)); + return scheduleTask(std::make_shared<Task>(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<Task>& t1, - const std::shared_ptr<Task>& t2) const { + bool operator()(const std::shared_ptr<Task>& t1, const std::shared_ptr<Task>& t2) const { return *t1 < *t2; } }; @@ -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/tools/rootcanal/model/setup/async_manager.h b/tools/rootcanal/model/setup/async_manager.h index d1861d2f6d..a8eaff0e43 100644 --- a/tools/rootcanal/model/setup/async_manager.h +++ b/tools/rootcanal/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/tools/rootcanal/model/setup/device_boutique.cc b/tools/rootcanal/model/setup/device_boutique.cc index ad04cbe28f..78258629f0 100644 --- a/tools/rootcanal/model/setup/device_boutique.cc +++ b/tools/rootcanal/model/setup/device_boutique.cc @@ -22,27 +22,24 @@ using std::vector; namespace rootcanal { -std::unordered_map<std::string, std::function<std::shared_ptr<Device>( - const vector<std::string>&)>>& +std::unordered_map<std::string, std::function<std::shared_ptr<Device>(const vector<std::string>&)>>& DeviceBoutique::GetMap() { - static std::unordered_map<std::string, std::function<std::shared_ptr<Device>( - const vector<std::string>&)>> - impl; + static std::unordered_map<std::string, + std::function<std::shared_ptr<Device>(const vector<std::string>&)>> + impl; return impl; } // Register a constructor for a device type. bool DeviceBoutique::Register( - const std::string& device_type, - const std::function<std::shared_ptr<Device>(const vector<std::string>&)> - method) { + const std::string& device_type, + const std::function<std::shared_ptr<Device>(const vector<std::string>&)> method) { INFO("Registering {}", device_type); GetMap()[device_type] = method; return true; } -std::shared_ptr<Device> DeviceBoutique::Create( - const vector<std::string>& args) { +std::shared_ptr<Device> DeviceBoutique::Create(const vector<std::string>& args) { ASSERT(!args.empty()); auto device = GetMap().find(args[0]); diff --git a/tools/rootcanal/model/setup/device_boutique.h b/tools/rootcanal/model/setup/device_boutique.h index 2f074041a0..fc57a24377 100644 --- a/tools/rootcanal/model/setup/device_boutique.h +++ b/tools/rootcanal/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<std::shared_ptr<Device>(const std::vector<std::string>&)> - method); + std::string const& device_type, + std::function<std::shared_ptr<Device>(const std::vector<std::string>&)> method); // Call the function that matches arg[0] with args static std::shared_ptr<Device> Create(const std::vector<std::string>& args); - private: - static std::unordered_map<std::string, std::function<std::shared_ptr<Device>( - const std::vector<std::string>&)>>& +private: + static std::unordered_map< + std::string, std::function<std::shared_ptr<Device>(const std::vector<std::string>&)>>& GetMap(); }; diff --git a/tools/rootcanal/model/setup/phy_device.cc b/tools/rootcanal/model/setup/phy_device.cc index 59f3d52b43..297c0ee7bd 100644 --- a/tools/rootcanal/model/setup/phy_device.cc +++ b/tools/rootcanal/model/setup/phy_device.cc @@ -26,8 +26,7 @@ PhyDevice::PhyDevice(std::string type, std::shared_ptr<Device> 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<Device> PhyDevice::GetDevice() const { - return device_; -} +std::shared_ptr<Device> PhyDevice::GetDevice() const { return device_; } void PhyDevice::SetAddress(bluetooth::hci::Address address) { device_->SetAddress(std::move(address)); } -void PhyDevice::Receive(std::vector<uint8_t> const& packet, Phy::Type type, - int8_t rssi) { +void PhyDevice::Receive(std::vector<uint8_t> const& packet, Phy::Type type, int8_t rssi) { std::shared_ptr<std::vector<uint8_t>> packet_copy = - std::make_shared<std::vector<uint8_t>>(packet); + std::make_shared<std::vector<uint8_t>>(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<uint8_t> const& packet, Phy::Type type, } } -void PhyDevice::Send(std::vector<uint8_t> const& packet, Phy::Type type, - int8_t tx_power) { +void PhyDevice::Send(std::vector<uint8_t> 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/tools/rootcanal/model/setup/phy_device.h b/tools/rootcanal/model/setup/phy_device.h index af45dbedd4..1a989bfa43 100644 --- a/tools/rootcanal/model/setup/phy_device.h +++ b/tools/rootcanal/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> 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<uint8_t> const& packet, Phy::Type type, int8_t rssi); - void Send(std::vector<uint8_t> const& packet, Phy::Type type, - int8_t tx_power); + void Send(std::vector<uint8_t> const& packet, Phy::Type type, int8_t tx_power); bluetooth::hci::Address GetAddress() const; std::shared_ptr<Device> GetDevice() const; @@ -52,7 +51,7 @@ class PhyDevice { const Identifier id; const std::string type; - private: +private: const std::shared_ptr<Device> device_; std::unordered_set<PhyLayer*> phy_layers_; }; diff --git a/tools/rootcanal/model/setup/phy_layer.cc b/tools/rootcanal/model/setup/phy_layer.cc index 301979c85f..2e15f74d9f 100644 --- a/tools/rootcanal/model/setup/phy_layer.cc +++ b/tools/rootcanal/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<uint8_t> 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/tools/rootcanal/model/setup/phy_layer.h b/tools/rootcanal/model/setup/phy_layer.h index 4c14f45d48..2c96db7da3 100644 --- a/tools/rootcanal/model/setup/phy_layer.h +++ b/tools/rootcanal/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<PhyDevice> 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<std::shared_ptr<rootcanal::PhyDevice>> phy_devices_; }; diff --git a/tools/rootcanal/model/setup/test_channel_transport.cc b/tools/rootcanal/model/setup/test_channel_transport.cc index 6b04326be6..d59cbb507f 100644 --- a/tools/rootcanal/model/setup/test_channel_transport.cc +++ b/tools/rootcanal/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<uint8_t> 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<std::string> 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<uint8_t> 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<AsyncDataChannel> socket, const std::string& response) { +void TestChannelTransport::SendResponse(std::shared_ptr<AsyncDataChannel> 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<uint8_t>(size & 0xff), - static_cast<uint8_t>((size >> 8) & 0xff), - static_cast<uint8_t>((size >> 16) & 0xff), - static_cast<uint8_t>((size >> 24) & 0xff)}; + uint8_t size_buf[4] = { + static_cast<uint8_t>(size & 0xff), static_cast<uint8_t>((size >> 8) & 0xff), + static_cast<uint8_t>((size >> 16) & 0xff), static_cast<uint8_t>((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<const uint8_t*>(response.c_str()), size); + ASSERT_LOG(written == static_cast<int>(size), "What happened? written = %zd errno = %d", written, errno); - written = - socket->Send(reinterpret_cast<const uint8_t*>(response.c_str()), size); - ASSERT_LOG(written == static_cast<int>(size), - "What happened? written = %zd errno = %d", written, errno); } void TestChannelTransport::RegisterCommandHandler( - const std::function<void(const std::string&, - const std::vector<std::string>&)>& callback) { + const std::function<void(const std::string&, const std::vector<std::string>&)>& callback) { command_handler_ = callback; } diff --git a/tools/rootcanal/model/setup/test_channel_transport.h b/tools/rootcanal/model/setup/test_channel_transport.h index a7405918d8..14081eb70b 100644 --- a/tools/rootcanal/model/setup/test_channel_transport.h +++ b/tools/rootcanal/model/setup/test_channel_transport.h @@ -21,7 +21,7 @@ #include <string> // for string #include <vector> // 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<AsyncDataChannelServer> server, - ConnectCallback connection_callback); + bool SetUp(std::shared_ptr<AsyncDataChannelServer> 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<void(const std::string&, - const std::vector<std::string>&)>& callback); + const std::function<void(const std::string&, const std::vector<std::string>&)>& callback); // Send data back to the test channel. - static void SendResponse(std::shared_ptr<AsyncDataChannel> socket, - const std::string& response); + static void SendResponse(std::shared_ptr<AsyncDataChannel> socket, const std::string& response); - void OnCommandReady(AsyncDataChannel* socket, - std::function<void(void)> unwatch); + void OnCommandReady(AsyncDataChannel* socket, std::function<void(void)> unwatch); - private: - std::function<void(const std::string&, const std::vector<std::string>&)> - command_handler_; +private: + std::function<void(const std::string&, const std::vector<std::string>&)> command_handler_; std::function<void(std::shared_ptr<AsyncDataChannel>)> connection_callback_; std::shared_ptr<AsyncDataChannelServer> socket_server_; diff --git a/tools/rootcanal/model/setup/test_command_handler.cc b/tools/rootcanal/model/setup/test_command_handler.cc index 45b947c09b..93315ae16e 100644 --- a/tools/rootcanal/model/setup/test_command_handler.cc +++ b/tools/rootcanal/model/setup/test_command_handler.cc @@ -35,12 +35,9 @@ static size_t ParseIntParam(std::string const& in) { return static_cast<size_t>(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<std::string>& param) { \ - method(param); \ - }; +TestCommandHandler::TestCommandHandler(TestModel& test_model) : model_(test_model) { +#define SET_HANDLER(command_name, method) \ + active_commands_[command_name] = [this](const vector<std::string>& param) { method(param); }; SET_HANDLER("add", 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<std::string>& args) { +void TestCommandHandler::HandleCommand(const std::string& name, const vector<std::string>& args) { if (active_commands_.count(name) == 0) { response_string_ = "Unhandled command: " + name; send_response_(response_string_); @@ -96,7 +92,7 @@ void TestCommandHandler::HandleCommand(const std::string& name, } void TestCommandHandler::RegisterSendResponse( - const std::function<void(const std::string&)> callback) { + const std::function<void(const std::string&)> callback) { send_response_ = callback; send_response_("RegisterSendResponse called"); } @@ -118,15 +114,13 @@ void TestCommandHandler::AddDevice(const vector<std::string>& 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<std::string>& args) { if (args.size() < 3) { - response_string_ = - "TestCommandHandler usage: add_remote host port phy_type"; + response_string_ = "TestCommandHandler usage: add_remote host port phy_type"; send_response_(response_string_); return; } @@ -155,8 +149,8 @@ void TestCommandHandler::RemoveDevice(const vector<std::string>& 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<std::string>& 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<std::string>& 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<std::string>& args) { if (args.size() != 2) { - response_string_ = - "TestCommandHandler 'add_device_to_phy' takes two arguments"; + response_string_ = "TestCommandHandler 'add_device_to_phy' takes two arguments"; send_response_(response_string_); return; } size_t dev_index = 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<std::string>& args) { if (args.size() != 2) { - response_string_ = - "TestCommandHandler 'del_device_from_phy' takes two arguments"; + response_string_ = "TestCommandHandler 'del_device_from_phy' takes two arguments"; send_response_(response_string_); return; } size_t dev_index = 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<std::string>& args) { void TestCommandHandler::SetDeviceAddress(const vector<std::string>& args) { if (args.size() != 2) { - response_string_ = - "TestCommandHandler 'set_device_address' takes two arguments"; + response_string_ = "TestCommandHandler 'set_device_address' takes two arguments"; send_response_(response_string_); return; } @@ -244,14 +232,13 @@ void TestCommandHandler::SetDeviceAddress(const vector<std::string>& args) { void TestCommandHandler::SetDeviceConfiguration(const vector<std::string>& 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; @@ -260,8 +247,7 @@ void TestCommandHandler::SetDeviceConfiguration(const vector<std::string>& args) } else if (args[1] == "csr_rck_pts_dongle") { preset = rootcanal::configuration::ControllerPreset::CSR_RCK_PTS_DONGLE; } 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/tools/rootcanal/model/setup/test_command_handler.h b/tools/rootcanal/model/setup/test_command_handler.h index 4f41c3222a..751016e6af 100644 --- a/tools/rootcanal/model/setup/test_command_handler.h +++ b/tools/rootcanal/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<std::string>& args); + void HandleCommand(const std::string& name, const std::vector<std::string>& args); // Dispatches the action corresponding to the command specified by |name|. void RegisterSendResponse(std::function<void(const std::string&)> callback); @@ -87,14 +86,13 @@ class TestCommandHandler { // For manual testing void AddDefaults(); - private: +private: TestModel& model_; std::string response_string_; - std::unordered_map<std::string, - std::function<void(const std::vector<std::string>&)>> - active_commands_; + std::unordered_map<std::string, std::function<void(const std::vector<std::string>&)>> + active_commands_; std::function<void(const std::string&)> send_response_; diff --git a/tools/rootcanal/model/setup/test_model.cc b/tools/rootcanal/model/setup/test_model.cc index 060b4cfb83..eb590bde8a 100644 --- a/tools/rootcanal/model/setup/test_model.cc +++ b/tools/rootcanal/model/setup/test_model.cc @@ -18,13 +18,12 @@ #include <stdlib.h> // for size_t -#include <iomanip> // for operator<<, setfill -#include <iostream> // for basic_ostream -#include <memory> // for shared_ptr, make... +#include <iomanip> // for operator<<, setfill +#include <iostream> // for basic_ostream +#include <memory> // for shared_ptr, make... #include <optional> #include <type_traits> // for remove_extent_t #include <utility> // for move -#include <optional> #include "include/phy.h" // for Phy, Phy::Type #include "log.h" @@ -33,20 +32,19 @@ namespace rootcanal { TestModel::TestModel( - std::function<AsyncUserId()> get_user_id, - std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, - const TaskCallback&)> - event_scheduler, - - std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, - std::chrono::milliseconds, const TaskCallback&)> - periodic_event_scheduler, - - std::function<void(AsyncUserId)> cancel_tasks_from_user, - std::function<void(AsyncTaskId)> cancel, - std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> - connect_to_remote, - std::array<uint8_t, 5> bluetooth_address_prefix) + std::function<AsyncUserId()> get_user_id, + std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, const TaskCallback&)> + event_scheduler, + + std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, std::chrono::milliseconds, + const TaskCallback&)> + periodic_event_scheduler, + + std::function<void(AsyncUserId)> cancel_tasks_from_user, + std::function<void(AsyncTaskId)> cancel, + std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> + connect_to_remote, + std::array<uint8_t, 5> 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<PhyLayer> TestModel::CreatePhyLayer(PhyLayer::Identifier id, - Phy::Type type) { +std::unique_ptr<PhyLayer> TestModel::CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type) { return std::make_unique<PhyLayer>(id, type); } -std::shared_ptr<PhyDevice> TestModel::CreatePhyDevice( - std::string type, std::shared_ptr<Device> device) { +std::shared_ptr<PhyDevice> TestModel::CreatePhyDevice(std::string type, + std::shared_ptr<Device> device) { return std::make_shared<PhyDevice>(std::move(type), std::move(device)); } Address TestModel::GenerateBluetoothAddress(uint32_t device_id) const { Address address({ - static_cast<uint8_t>(device_id), - bluetooth_address_prefix_[4], - bluetooth_address_prefix_[3], - bluetooth_address_prefix_[2], - bluetooth_address_prefix_[1], - bluetooth_address_prefix_[0], + static_cast<uint8_t>(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> device) { std::string device_type = device->GetTypeString(); - std::shared_ptr<PhyDevice> phy_device = - CreatePhyDevice(device_type, std::move(device)); + std::shared_ptr<PhyDevice> 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> device, - Phy::Type type) { +void TestModel::AddLinkLayerConnection(std::shared_ptr<Device> 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> 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<HciDevice> device, std::optional<Address> address) { +PhyDevice::Identifier TestModel::AddHciConnection(std::shared_ptr<HciDevice> device, + std::optional<Address> 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>(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<DualModeController> device = std::static_pointer_cast<HciDevice>( - phy_devices_[device_id]->GetDevice()); + std::shared_ptr<DualModeController> device = + std::static_pointer_cast<HciDevice>(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/tools/rootcanal/model/setup/test_model.h b/tools/rootcanal/model/setup/test_model.h index b9871a6c62..09996ca3df 100644 --- a/tools/rootcanal/model/setup/test_model.h +++ b/tools/rootcanal/model/setup/test_model.h @@ -20,15 +20,15 @@ #include <cstddef> // for size_t #include <functional> // for function #include <map> -#include <memory> // for shared_ptr -#include <string> // for string -#include <vector> // for vector +#include <memory> // for shared_ptr #include <optional> +#include <string> // for string +#include <vector> // 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<AsyncUserId()> get_user_id, - std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, - const TaskCallback&)> - event_scheduler, - std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, - std::chrono::milliseconds, const TaskCallback&)> - periodic_event_scheduler, - std::function<void(AsyncUserId)> cancel_tasks_from_user, - std::function<void(AsyncTaskId)> cancel, - std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> - connect_to_remote, - std::array<uint8_t, 5> bluetooth_address_prefix = {0xda, 0x4c, 0x10, 0xde, - 0x17}); +public: + TestModel(std::function<AsyncUserId()> get_user_id, + std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, const TaskCallback&)> + event_scheduler, + std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, + std::chrono::milliseconds, const TaskCallback&)> + periodic_event_scheduler, + std::function<void(AsyncUserId)> cancel_tasks_from_user, + std::function<void(AsyncTaskId)> cancel, + std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> + connect_to_remote, + std::array<uint8_t, 5> 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<PhyLayer> CreatePhyLayer(PhyLayer::Identifier id, - Phy::Type type); + virtual std::unique_ptr<PhyLayer> CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type); // Allow derived classes to use custom phy devices. - virtual std::shared_ptr<PhyDevice> CreatePhyDevice( - std::string type, std::shared_ptr<Device> device); + virtual std::shared_ptr<PhyDevice> CreatePhyDevice(std::string type, + std::shared_ptr<Device> 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<PhyLayer::Identifier, std::shared_ptr<PhyLayer>> phy_layers_; @@ -129,16 +122,14 @@ class TestModel { // Callbacks to schedule tasks. std::function<AsyncUserId()> get_user_id_; - std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, + std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, const TaskCallback&)> + schedule_task_; + std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, std::chrono::milliseconds, const TaskCallback&)> - schedule_task_; - std::function<AsyncTaskId(AsyncUserId, std::chrono::milliseconds, - std::chrono::milliseconds, const TaskCallback&)> - schedule_periodic_task_; + schedule_periodic_task_; std::function<void(AsyncTaskId)> cancel_task_; std::function<void(AsyncUserId)> cancel_tasks_from_user_; - std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> - connect_to_remote_; + std::function<std::shared_ptr<Device>(const std::string&, int, Phy::Type)> connect_to_remote_; AsyncUserId model_user_id_; AsyncTaskId timer_tick_task_{kInvalidTaskId}; diff --git a/tools/rootcanal/net/async_data_channel.h b/tools/rootcanal/net/async_data_channel.h index 3cd3441950..d2e2963592 100644 --- a/tools/rootcanal/net/async_data_channel.h +++ b/tools/rootcanal/net/async_data_channel.h @@ -41,7 +41,7 @@ using ReadCallback = std::function<void(AsyncDataChannel*)>; // 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/tools/rootcanal/net/async_data_channel_connector.h b/tools/rootcanal/net/async_data_channel_connector.h index 5df986223f..a411785023 100644 --- a/tools/rootcanal/net/async_data_channel_connector.h +++ b/tools/rootcanal/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<AsyncDataChannel> 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/tools/rootcanal/net/async_data_channel_server.h b/tools/rootcanal/net/async_data_channel_server.h index 59821ee5d7..f63deb244c 100644 --- a/tools/rootcanal/net/async_data_channel_server.h +++ b/tools/rootcanal/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<void(std::shared_ptr<AsyncDataChannel>, - AsyncDataChannelServer* server)>; +using ConnectCallback = + std::function<void(std::shared_ptr<AsyncDataChannel>, 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/tools/rootcanal/net/posix/posix_async_socket.cc b/tools/rootcanal/net/posix/posix_async_socket.cc index d6c982e70a..8ff175ce0a 100644 --- a/tools/rootcanal/net/posix/posix_async_socket.cc +++ b/tools/rootcanal/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<void*>(&error_code), - &error_code_size); + getsockopt(fd_, SOL_SOCKET, SO_ERROR, reinterpret_cast<void*>(&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/tools/rootcanal/net/posix/posix_async_socket.h b/tools/rootcanal/net/posix/posix_async_socket.h index a76a215a51..8fa521371a 100644 --- a/tools/rootcanal/net/posix/posix_async_socket.h +++ b/tools/rootcanal/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/tools/rootcanal/net/posix/posix_async_socket_connector.cc b/tools/rootcanal/net/posix/posix_async_socket_connector.cc index ed02bc130d..4b7691a528 100644 --- a/tools/rootcanal/net/posix/posix_async_socket_connector.cc +++ b/tools/rootcanal/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<AsyncDataChannel> -PosixAsyncSocketConnector::ConnectToRemoteServer( - const std::string& server, int port, - const std::chrono::milliseconds timeout) { +std::shared_ptr<AsyncDataChannel> 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<PosixAsyncSocket> pas = - std::make_shared<PosixAsyncSocket>(socket_fd, am_); + std::shared_ptr<PosixAsyncSocket> pas = std::make_shared<PosixAsyncSocket>(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<char*>(&err), - &optLen) || - err) { + if (getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, reinterpret_cast<char*>(&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/tools/rootcanal/net/posix/posix_async_socket_connector.h b/tools/rootcanal/net/posix/posix_async_socket_connector.h index 2bf34319aa..ea5c5e9fe8 100644 --- a/tools/rootcanal/net/posix/posix_async_socket_connector.h +++ b/tools/rootcanal/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<AsyncDataChannel> 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/tools/rootcanal/net/posix/posix_async_socket_server.cc b/tools/rootcanal/net/posix/posix_async_socket_server.cc index 185f17dd2d..3f20e72f18 100644 --- a/tools/rootcanal/net/posix/posix_async_socket_server.cc +++ b/tools/rootcanal/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<sockaddr*>(&listen_address), - sockaddr_in_size) < 0) { - INFO("Error binding test channel listener socket to port: {}, {}", port, - strerror(errno)); + if (bind(listen_fd, reinterpret_cast<sockaddr*>(&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/tools/rootcanal/net/posix/posix_async_socket_server.h b/tools/rootcanal/net/posix/posix_async_socket_server.h index e5d012b9ba..75590adcdb 100644 --- a/tools/rootcanal/net/posix/posix_async_socket_server.h +++ b/tools/rootcanal/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/tools/rootcanal/rust/include/rootcanal_rs.h b/tools/rootcanal/rust/include/rootcanal_rs.h index 1b395cd632..e2c7080c41 100644 --- a/tools/rootcanal/rust/include/rootcanal_rs.h +++ b/tools/rootcanal/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/tools/rootcanal/test/async_manager_unittest.cc b/tools/rootcanal/test/async_manager_unittest.cc index b461b9a44e..dd3f366d3d 100644 --- a/tools/rootcanal/test/async_manager_unittest.cc +++ b/tools/rootcanal/test/async_manager_unittest.cc @@ -38,7 +38,7 @@ namespace rootcanal { class Event { - public: +public: void set(bool set = true) { std::unique_lock<std::mutex> 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<in_addr_t*>(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<bool> cancel_done = false; std::atomic<bool> 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<std::chrono::milliseconds>(end - start); + auto passed_ms = std::chrono::duration_cast<std::chrono::milliseconds>(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/tools/rootcanal/test/controller/le/le_add_device_to_filter_accept_list_test.cc b/tools/rootcanal/test/controller/le/le_add_device_to_filter_accept_list_test.cc index e99930818b..fe5b0c6975 100644 --- a/tools/rootcanal/test/controller/le/le_add_device_to_filter_accept_list_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc b/tools/rootcanal/test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc index cade4d9733..94212f8d3b 100644 --- a/tools/rootcanal/test/controller/le/le_add_device_to_periodic_advertiser_list_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_add_device_to_resolving_list_test.cc b/tools/rootcanal/test/controller/le/le_add_device_to_resolving_list_test.cc index b2a44d4812..050a70a520 100644 --- a/tools/rootcanal/test/controller/le/le_add_device_to_resolving_list_test.cc +++ b/tools/rootcanal/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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{2}, std::array<uint8_t, 16>{2}), + PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{2}, std::array<uint8_t, 16>{2}), ErrorCode::SUCCESS); } TEST_F(LeAddDeviceToResolvingListTest, ListFull) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{2}, - std::array<uint8_t, 16>{2}, std::array<uint8_t, 16>{2}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{2}, + std::array<uint8_t, 16>{2}, std::array<uint8_t, 16>{2}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{3}, - std::array<uint8_t, 16>{3}, std::array<uint8_t, 16>{3}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{3}, + std::array<uint8_t, 16>{3}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), ErrorCode::COMMAND_DISALLOWED); } TEST_F(LeAddDeviceToResolvingListTest, PeerAddressDuplicate) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{2}, std::array<uint8_t, 16>{2}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{2}, std::array<uint8_t, 16>{2}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeAddDeviceToResolvingListTest, PeerIrkDuplicate) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), ErrorCode::INVALID_HCI_COMMAND_PARAMETERS); } TEST_F(LeAddDeviceToResolvingListTest, EmptyPeerIrkDuplicate) { ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{0}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{0}, std::array<uint8_t, 16>{1}), ErrorCode::SUCCESS); ASSERT_EQ(controller_.LeAddDeviceToResolvingList( - PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, - std::array<uint8_t, 16>{0}, std::array<uint8_t, 16>{1}), + PeerAddressType::RANDOM_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{0}, std::array<uint8_t, 16>{1}), ErrorCode::SUCCESS); } diff --git a/tools/rootcanal/test/controller/le/le_clear_filter_accept_list_test.cc b/tools/rootcanal/test/controller/le/le_clear_filter_accept_list_test.cc index 30eb1b09aa..b7d8fb8630 100644 --- a/tools/rootcanal/test/controller/le/le_clear_filter_accept_list_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_clear_periodic_advertiser_list_test.cc b/tools/rootcanal/test/controller/le/le_clear_periodic_advertiser_list_test.cc index 9d4f347e10..a2e7d50a58 100644 --- a/tools/rootcanal/test/controller/le/le_clear_periodic_advertiser_list_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_clear_resolving_list_test.cc b/tools/rootcanal/test/controller/le/le_clear_resolving_list_test.cc index ea37d1c982..98914a5da9 100644 --- a/tools/rootcanal/test/controller/le/le_clear_resolving_list_test.cc +++ b/tools/rootcanal/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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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/tools/rootcanal/test/controller/le/le_create_connection_cancel_test.cc b/tools/rootcanal/test/controller/le/le_create_connection_cancel_test.cc index 995186e2f5..d8d16e8295 100644 --- a/tools/rootcanal/test/controller/le/le_create_connection_cancel_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_create_connection_test.cc b/tools/rootcanal/test/controller/le/le_create_connection_test.cc index 0c68ea9b85..866c493a18 100644 --- a/tools/rootcanal/test/controller/le/le_create_connection_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_extended_create_connection_test.cc b/tools/rootcanal/test/controller/le/le_extended_create_connection_test.cc index c5f4f63c69..072827147f 100644 --- a/tools/rootcanal/test/controller/le/le_extended_create_connection_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc b/tools/rootcanal/test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc index 80f353db5a..ad8924cf78 100644 --- a/tools/rootcanal/test/controller/le/le_periodic_advertising_create_sync_cancel_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_periodic_advertising_create_sync_test.cc b/tools/rootcanal/test/controller/le/le_periodic_advertising_create_sync_test.cc index bf3ad7aada..0ee36cd055 100644 --- a/tools/rootcanal/test/controller/le/le_periodic_advertising_create_sync_test.cc +++ b/tools/rootcanal/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<uint8_t>( - PeriodicSyncCteType::AVOID_AOA_CONSTANT_TONE_EXTENSION) | - static_cast<uint8_t>( - PeriodicSyncCteType:: - AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_ONE_US_SLOTS) | - static_cast<uint8_t>( - PeriodicSyncCteType:: - AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_TWO_US_SLOTS) | - static_cast<uint8_t>( - PeriodicSyncCteType:: - AVOID_TYPE_THREE_CONSTANT_TONE_EXTENSION) | - static_cast<uint8_t>( - 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<uint8_t>(PeriodicSyncCteType::AVOID_AOA_CONSTANT_TONE_EXTENSION) | + static_cast<uint8_t>( + PeriodicSyncCteType:: + AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_ONE_US_SLOTS) | + static_cast<uint8_t>( + PeriodicSyncCteType:: + AVOID_AOD_CONSTANT_TONE_EXTENSION_WITH_TWO_US_SLOTS) | + static_cast<uint8_t>( + PeriodicSyncCteType::AVOID_TYPE_THREE_CONSTANT_TONE_EXTENSION) | + static_cast<uint8_t>( + PeriodicSyncCteType::AVOID_NO_CONSTANT_TONE_EXTENSION)), + ErrorCode::COMMAND_DISALLOWED); } } // namespace rootcanal diff --git a/tools/rootcanal/test/controller/le/le_remove_device_from_filter_accept_list_test.cc b/tools/rootcanal/test/controller/le/le_remove_device_from_filter_accept_list_test.cc index b3e41b696e..5a05c5900d 100644 --- a/tools/rootcanal/test/controller/le/le_remove_device_from_filter_accept_list_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc b/tools/rootcanal/test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc index bb362cefdd..86edd3c929 100644 --- a/tools/rootcanal/test/controller/le/le_remove_device_from_periodic_advertiser_list_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_remove_device_from_resolving_list_test.cc b/tools/rootcanal/test/controller/le/le_remove_device_from_resolving_list_test.cc index 2f9d9f55af..9676514dc3 100644 --- a/tools/rootcanal/test/controller/le/le_remove_device_from_resolving_list_test.cc +++ b/tools/rootcanal/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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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/tools/rootcanal/test/controller/le/le_scanning_filter_duplicates_test.cc b/tools/rootcanal/test/controller/le/le_scanning_filter_duplicates_test.cc index 6ef5a2b1bf..6a817ce6bf 100644 --- a/tools/rootcanal/test/controller/le/le_scanning_filter_duplicates_test.cc +++ b/tools/rootcanal/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::ADVERTISING_REPORT) | + to_mask(SubeventCode::EXTENDED_ADVERTISING_REPORT) | + to_mask(SubeventCode::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<uint8_t> const data = {}) { + static model::packets::LinkLayerPacketView LeScanResponse(std::vector<uint8_t> 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<uint8_t> const data = {}) { + std::vector<uint8_t> 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<uint8_t> const data = {}) { + std::vector<uint8_t> 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<pdl::packet::Builder> builder) { - auto data = - std::make_shared<std::vector<uint8_t>>(builder->SerializeToBytes()); - return model::packets::LinkLayerPacketView::Create( - pdl::packet::slice(data)); + std::unique_ptr<pdl::packet::Builder> builder) { + auto data = std::make_shared<std::vector<uint8_t>>(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<EventBuilder> /* event */) { event_listener_called_++; } - static void remote_listener_( - std::shared_ptr<model::packets::LinkLayerPacketBuilder> /* packet */, - Phy::Type /* phy */, int8_t /* tx_power */) {} + static void remote_listener_(std::shared_ptr<model::packets::LinkLayerPacketBuilder> /* 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/tools/rootcanal/test/controller/le/le_set_address_resolution_enable_test.cc b/tools/rootcanal/test/controller/le/le_set_address_resolution_enable_test.cc index edfc6b823f..00546f4517 100644 --- a/tools/rootcanal/test/controller/le/le_set_address_resolution_enable_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_set_advertising_enable_test.cc b/tools/rootcanal/test/controller/le/le_set_advertising_enable_test.cc index d9ffb2a5ab..435bdd6ec4 100644 --- a/tools/rootcanal/test/controller/le/le_set_advertising_enable_test.cc +++ b/tools/rootcanal/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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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/tools/rootcanal/test/controller/le/le_set_advertising_parameters_test.cc b/tools/rootcanal/test/controller/le/le_set_advertising_parameters_test.cc index 56f85bc3fa..1bc71fa200 100644 --- a/tools/rootcanal/test/controller/le/le_set_advertising_parameters_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_set_extended_advertising_data_test.cc b/tools/rootcanal/test/controller/le/le_set_extended_advertising_data_test.cc index ed27f1280d..2ffa673aa6 100644 --- a/tools/rootcanal/test/controller/le/le_set_extended_advertising_data_test.cc +++ b/tools/rootcanal/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<uint8_t> 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<uint8_t> 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<uint8_t> first_advertising_data_fragment = {1, 2, 3}; std::vector<uint8_t> intermediate_advertising_data_fragment = {4, 5, 6}; std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> first_advertising_data_fragment = {1, 2, 3}; @@ -250,96 +240,85 @@ TEST_F(LeSetExtendedAdvertisingDataTest, EmptyAdvertisingDataFragment) { std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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/tools/rootcanal/test/controller/le/le_set_extended_advertising_enable_test.cc b/tools/rootcanal/test/controller/le/le_set_extended_advertising_enable_test.cc index a83e72631d..5addb9cbe3 100644 --- a/tools/rootcanal/test/controller/le/le_set_extended_advertising_enable_test.cc +++ b/tools/rootcanal/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<uint8_t, 16>{1}, std::array<uint8_t, 16>{1}), + PeerAddressType::PUBLIC_DEVICE_OR_IDENTITY_ADDRESS, Address{1}, + std::array<uint8_t, 16>{1}, std::array<uint8_t, 16>{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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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/tools/rootcanal/test/controller/le/le_set_extended_advertising_parameters_test.cc b/tools/rootcanal/test/controller/le/le_set_extended_advertising_parameters_test.cc index f6a73b6c03..9b89b88319 100644 --- a/tools/rootcanal/test/controller/le/le_set_extended_advertising_parameters_test.cc +++ b/tools/rootcanal/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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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/tools/rootcanal/test/controller/le/le_set_extended_scan_enable_test.cc b/tools/rootcanal/test/controller/le/le_set_extended_scan_enable_test.cc index 278b9d06aa..298683a0df 100644 --- a/tools/rootcanal/test/controller/le/le_set_extended_scan_enable_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_set_extended_scan_parameters_test.cc b/tools/rootcanal/test/controller/le/le_set_extended_scan_parameters_test.cc index 3e1ab5390a..ecc61e94d5 100644 --- a/tools/rootcanal/test/controller/le/le_set_extended_scan_parameters_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_set_extended_scan_response_data_test.cc b/tools/rootcanal/test/controller/le/le_set_extended_scan_response_data_test.cc index fde4680ec7..c53c9f5a85 100644 --- a/tools/rootcanal/test/controller/le/le_set_extended_scan_response_data_test.cc +++ b/tools/rootcanal/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<uint8_t> 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<uint8_t> 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<uint8_t> first_scan_response_data_fragment = {1, 2, 3}; std::vector<uint8_t> intermediate_scan_response_data_fragment = {4, 5, 6}; std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> first_scan_response_data_fragment = {1, 2, 3}; @@ -211,152 +200,134 @@ TEST_F(LeSetExtendedScanResponseDataTest, EmptyScanResponseDataFragment) { std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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/tools/rootcanal/test/controller/le/le_set_periodic_advertising_data_test.cc b/tools/rootcanal/test/controller/le/le_set_periodic_advertising_data_test.cc index 26a03d0eca..90bbc1ae68 100644 --- a/tools/rootcanal/test/controller/le/le_set_periodic_advertising_data_test.cc +++ b/tools/rootcanal/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<uint8_t> 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<uint8_t> 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<uint8_t> first_advertising_data_fragment = {1, 2, 3}; std::vector<uint8_t> intermediate_advertising_data_fragment = {4, 5, 6}; std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> 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<uint8_t> first_advertising_data_fragment = {1, 2, 3}; std::vector<uint8_t> intermediate_advertising_data_fragment = {4, 5, 6}; std::vector<uint8_t> 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<uint8_t> 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<uint8_t> 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/tools/rootcanal/test/controller/le/le_set_periodic_advertising_enable_test.cc b/tools/rootcanal/test/controller/le/le_set_periodic_advertising_enable_test.cc index 761beea620..09f5cdf8f4 100644 --- a/tools/rootcanal/test/controller/le/le_set_periodic_advertising_enable_test.cc +++ b/tools/rootcanal/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<uint8_t> 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<uint8_t> 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/tools/rootcanal/test/controller/le/le_set_periodic_advertising_parameters_test.cc b/tools/rootcanal/test/controller/le/le_set_periodic_advertising_parameters_test.cc index fc7aa69b36..301443b6eb 100644 --- a/tools/rootcanal/test/controller/le/le_set_periodic_advertising_parameters_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_set_random_address_test.cc b/tools/rootcanal/test/controller/le/le_set_random_address_test.cc index 63a60b65e4..a92a72d660 100644 --- a/tools/rootcanal/test/controller/le/le_set_random_address_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_set_scan_enable_test.cc b/tools/rootcanal/test/controller/le/le_set_scan_enable_test.cc index a522af2400..08cba642d8 100644 --- a/tools/rootcanal/test/controller/le/le_set_scan_enable_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/le_set_scan_parameters_test.cc b/tools/rootcanal/test/controller/le/le_set_scan_parameters_test.cc index 5a27b6522e..13f693ba3c 100644 --- a/tools/rootcanal/test/controller/le/le_set_scan_parameters_test.cc +++ b/tools/rootcanal/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/tools/rootcanal/test/controller/le/rpa_generation_test.cc b/tools/rootcanal/test/controller/le/rpa_generation_test.cc index ac102719a4..ab7e7ebcfa 100644 --- a/tools/rootcanal/test/controller/le/rpa_generation_test.cc +++ b/tools/rootcanal/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<uint8_t, rootcanal::LinkLayerController::kIrkSize> 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/tools/rootcanal/test/controller/le/test_helpers.h b/tools/rootcanal/test/controller/le/test_helpers.h index 4c9016c22c..45d3257496 100644 --- a/tools/rootcanal/test/controller/le/test_helpers.h +++ b/tools/rootcanal/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; @@ -40,8 +40,7 @@ MakeAdvertisingEventProperties(unsigned mask = 0) { } [[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/tools/rootcanal/test/h4_parser_unittest.cc b/tools/rootcanal/test/h4_parser_unittest.cc index 9e4b59e67c..7947b623ba 100644 --- a/tools/rootcanal/test/h4_parser_unittest.cc +++ b/tools/rootcanal/test/h4_parser_unittest.cc @@ -24,8 +24,8 @@ namespace rootcanal { using PacketData = std::vector<uint8_t>; 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<uint8_t>& packet) { - packet_ = std::move(packet); - } + void PacketReadCallback(const std::vector<uint8_t>& 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<PacketType> types({PacketType::ACL, PacketType::SCO, - PacketType::COMMAND, PacketType::EVENT, - PacketType::ISO}); + std::vector<PacketType> 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/tools/rootcanal/test/invalid_packet_handler_unittest.cc b/tools/rootcanal/test/invalid_packet_handler_unittest.cc index 803124bdcd..00221be966 100644 --- a/tools/rootcanal/test/invalid_packet_handler_unittest.cc +++ b/tools/rootcanal/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<uint8_t> kInvalidCommandPacket = {0x01, 0x0C, 0x03, - 0xff, 0xff, 0xff}; +const std::vector<uint8_t> kInvalidCommandPacket = {0x01, 0x0C, 0x03, 0xff, 0xff, 0xff}; // Hardware Error event with code 0x43. const std::vector<uint8_t> kHardwareErrorEvent = {0x10, 0x01, 0x43}; @@ -42,9 +41,9 @@ const std::vector<uint8_t> 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<std::vector<uint8_t>>( - kInvalidCommandPacket)), - ""); + ASSERT_DEATH( + controller_.HandleCommand(std::make_shared<std::vector<uint8_t>>(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<uint8_t> 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<uint8_t> const& bytes) { + invalid_packet.id = id; + invalid_packet.reason = reason; + invalid_packet.bytes = bytes; + }); - controller_.RegisterEventChannel( - [&](std::shared_ptr<std::vector<uint8_t>> packet) { - hci_event = std::vector<uint8_t>(*packet); - }); + controller_.RegisterEventChannel([&](std::shared_ptr<std::vector<uint8_t>> packet) { + hci_event = std::vector<uint8_t>(*packet); + }); - controller_.HandleCommand( - std::make_shared<std::vector<uint8_t>>(kInvalidCommandPacket)); + controller_.HandleCommand(std::make_shared<std::vector<uint8_t>>(kInvalidCommandPacket)); ASSERT_EQ(invalid_packet.id, controller_.id_); ASSERT_EQ(invalid_packet.reason, InvalidPacketReason::kParseError); ASSERT_EQ(invalid_packet.bytes, kInvalidCommandPacket); diff --git a/tools/rootcanal/test/pcap_filter_unittest.cc b/tools/rootcanal/test/pcap_filter_unittest.cc index 41a80768a7..403f8d64b2 100644 --- a/tools/rootcanal/test/pcap_filter_unittest.cc +++ b/tools/rootcanal/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<uint8_t> input_gap_data{ - 0x2, static_cast<uint8_t>(GapDataType::FLAGS), 0x0}; - std::vector<uint8_t> output_gap_data{input_gap_data.begin(), - input_gap_data.end()}; + std::vector<uint8_t> input_gap_data{0x2, static_cast<uint8_t>(GapDataType::FLAGS), 0x0}; + std::vector<uint8_t> 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<uint8_t> input_gap_data{ - 0x2, - static_cast<uint8_t>(GapDataType::FLAGS), - 0x0, - 0x4, - static_cast<uint8_t>(GapDataType::SHORTENED_LOCAL_NAME), - 0xa, - 0xb, - 0xc}; - std::vector<uint8_t> output_gap_data_1{input_gap_data.begin(), - input_gap_data.end()}; + std::vector<uint8_t> input_gap_data{0x2, + static_cast<uint8_t>(GapDataType::FLAGS), + 0x0, + 0x4, + static_cast<uint8_t>(GapDataType::SHORTENED_LOCAL_NAME), + 0xa, + 0xb, + 0xc}; + std::vector<uint8_t> 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<uint8_t> output_gap_data_2{input_gap_data.begin(), - input_gap_data.end()}; + std::vector<uint8_t> 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<uint8_t> input_gap_data{ - 0x2, - static_cast<uint8_t>(GapDataType::FLAGS), - 0x0, - 0x4, - static_cast<uint8_t>(GapDataType::COMPLETE_LOCAL_NAME), - 0xa, - 0xb, - 0xc}; - std::vector<uint8_t> output_gap_data_1{input_gap_data.begin(), - input_gap_data.end()}; + std::vector<uint8_t> input_gap_data{0x2, + static_cast<uint8_t>(GapDataType::FLAGS), + 0x0, + 0x4, + static_cast<uint8_t>(GapDataType::COMPLETE_LOCAL_NAME), + 0xa, + 0xb, + 0xc}; + std::vector<uint8_t> 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<uint8_t> output_gap_data_2{input_gap_data.begin(), - input_gap_data.end()}; + std::vector<uint8_t> 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/tools/rootcanal/test/posix_socket_unittest.cc b/tools/rootcanal/test/posix_socket_unittest.cc index e10cd00dae..43ec1b57e3 100644 --- a/tools/rootcanal/test/posix_socket_unittest.cc +++ b/tools/rootcanal/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<AsyncDataChannel>; class PosixSocketTest : public testing::Test { - public: +public: PosixSocketTest() : pasc_(&async_manager_), pass_(0, &async_manager_) {} ~PosixSocketTest() { pass_.Close(); } - std::tuple<SocketCon, SocketCon> connectPair( - std::chrono::milliseconds timeout = 500ms) { + std::tuple<SocketCon, SocketCon> 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<AsyncDataChannel> sock2; pass_.SetOnConnectCallback( - [&](std::shared_ptr<AsyncDataChannel> sock, AsyncDataChannelServer*) { - std::unique_lock<std::mutex> guard(m); - sock1 = std::move(sock); - cv.notify_all(); - }); + [&](std::shared_ptr<AsyncDataChannel> sock, AsyncDataChannelServer*) { + std::unique_lock<std::mutex> 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<std::mutex> 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<std::shared_ptr<AsyncDataChannel>> connections; bool connected = false; - pass_.SetOnConnectCallback([&](std::shared_ptr<AsyncDataChannel> const& sock, - AsyncDataChannelServer*) { - std::unique_lock<std::mutex> guard(m); - connections.push_back(sock); - connected = true; - ASSERT_TRUE(pass_.StartListening()); - cv.notify_all(); - }); + pass_.SetOnConnectCallback( + [&](std::shared_ptr<AsyncDataChannel> const& sock, AsyncDataChannelServer*) { + std::unique_lock<std::mutex> 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<std::shared_ptr<AsyncDataChannel>> connections; bool connected = false; - pass_.SetOnConnectCallback( - [&](std::shared_ptr<AsyncDataChannel> sock, AsyncDataChannelServer*) { - std::unique_lock<std::mutex> guard(m); - connections.push_back(sock); - connected = true; - cv.notify_all(); - }); + pass_.SetOnConnectCallback([&](std::shared_ptr<AsyncDataChannel> sock, AsyncDataChannelServer*) { + std::unique_lock<std::mutex> guard(m); + connections.push_back(sock); + connected = true; + cv.notify_all(); + }); ASSERT_TRUE(pass_.StartListening()); { |