Skip to content

Commit

Permalink
Sync with aosp main
Browse files Browse the repository at this point in the history
Synchronized to packages/modules/Bluetooth
commit b6245f8beee5e87e66659d54136bc9714826585f

Changelist:
- Set support for APCF Transport Discovery Service filter to false
- Use Jacobian Coordinates in Point implementation
- Use pow for consistency
- Do not report an invalid packet for unsupported LE Apcf Transport Discovert Service command
- Send well formatted Apcf command complete event
- Update to pdl 0.3.0
- Typo in LE Apcf Transport Discovery Data command handling
- Reset APCF scanner in LinkLayerController::Reset()
- Set the default value of acl_data_packet_length to 1023
- Encryption Change V2
- Implement the command LE Read Local P-256 Public Key
- Add Authenticated Payload Timeout Expired event
- Update to Core version 6.0
- Update build.rs to directly use the pdl_compiler library
- Add INTEL_BE200 controller preset
- Update controller_info.py script
  • Loading branch information
hchataing committed Feb 3, 2025
1 parent 5f7ab5f commit 7d63eb6
Show file tree
Hide file tree
Showing 154 changed files with 8,299 additions and 9,367 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- name: Install dependencies
run: |
cargo install pdl-compiler --version 0.2.2
cargo install pdl-compiler --version 0.3.2
- name: Build
run: |
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:

- name: Install dependencies
run: |
cargo install pdl-compiler --version 0.2.2
cargo install pdl-compiler --version 0.3.2
python3 -m pip install hatch
- name: Set VERSION
Expand Down
6 changes: 3 additions & 3 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,21 @@ cc_proto_library(

genrule(
name = "lmp_packets_rs",
cmd = "pdlc --output-format rust $(location rust/lmp_packets.pdl) > $(location lmp_packets.rs)",
cmd = "pdlc --output-format rust_legacy $(location rust/lmp_packets.pdl) > $(location lmp_packets.rs)",
outs = ["lmp_packets.rs"],
srcs = ["rust/lmp_packets.pdl"],
)

genrule(
name = "llcp_packets_rs",
cmd = "pdlc --output-format rust $(location rust/llcp_packets.pdl) > $(location llcp_packets.rs)",
cmd = "pdlc --output-format rust_legacy $(location rust/llcp_packets.pdl) > $(location llcp_packets.rs)",
outs = ["llcp_packets.rs"],
srcs = ["rust/llcp_packets.pdl"],
)

genrule(
name = "hci_packets_rs",
cmd = "pdlc --output-format rust $(location //packets:hci_packets.pdl) > $(location hci_packets.rs)",
cmd = "pdlc --output-format rust_legacy $(location //packets:hci_packets.pdl) > $(location hci_packets.rs)",
outs = ["hci_packets.rs"],
srcs = ["//packets:hci_packets.pdl"],
visibility = ["//visibility:public"],
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ crate.spec(package = "num-derive", version = "0.3.3")
crate.spec(package = "num-integer", version = "0.1.45")
crate.spec(package = "num-traits", version = "0.2.14")
crate.spec(package = "paste", version = "1.0.4")
crate.spec(package = "pdl-runtime", version = "0.2.2")
crate.spec(package = "pdl-runtime", version = "0.3.2")
crate.spec(package = "pin-utils", version = "0.1.0")
crate.spec(package = "rand", version = "0.8.3")
crate.spec(package = "thiserror", version = "1.0.23")
Expand Down
25 changes: 10 additions & 15 deletions desktop/root_canal_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,13 @@ using namespace rootcanal;

DEFINE_string(controller_properties_file, "", "deprecated");
DEFINE_string(configuration, "", "controller configuration (see config.proto)");
DEFINE_string(configuration_file, "",
"controller configuration file path (see config.proto)");
DEFINE_string(configuration_file, "", "controller configuration file path (see config.proto)");
DEFINE_string(default_commands_file, "", "deprecated");
DEFINE_bool(enable_log_color, false, "enable log colors");
DEFINE_bool(enable_hci_sniffer, false, "enable hci sniffer");
DEFINE_bool(enable_baseband_sniffer, false, "enable baseband sniffer");
DEFINE_bool(enable_pcap_filter, false, "enable PCAP filter");
DEFINE_bool(disable_address_reuse, false,
"prevent rootcanal from reusing device addresses");
DEFINE_bool(disable_address_reuse, false, "prevent rootcanal from reusing device addresses");
DEFINE_uint32(test_port, 6401, "test tcp port");
DEFINE_uint32(hci_port, 6402, "hci server tcp port");
DEFINE_uint32(link_port, 6403, "link server tcp port");
Expand Down Expand Up @@ -95,17 +93,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();
Expand Down
193 changes: 88 additions & 105 deletions desktop/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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()));
}
Expand All @@ -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), [=, this]() {
auto transport = HciSocketTransport::Create(socket);
if (enable_hci_sniffer_) {
transport = HciSniffer::Create(transport);
}
auto device = HciDevice::Create(transport, properties);
auto device_id = test_model_.AddHciConnection(device);

if (enable_hci_sniffer_) {
auto filename = "rootcanal_" + std::to_string(device_id) + "_" +
device->GetAddress().ToString() + ".pcap";
for (auto i = 0; std::filesystem::exists(filename); i++) {
filename = "rootcanal_" + std::to_string(device_id) + "_" +
device->GetAddress().ToString() + "_" + std::to_string(i) + ".pcap";
}
auto file = std::make_shared<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));
}

Expand All @@ -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();
Expand All @@ -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__);
Expand All @@ -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;
Expand All @@ -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"});
Expand Down
Loading

0 comments on commit 7d63eb6

Please sign in to comment.