// // Copyright 2017 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. //
using rootcanal::AsyncTaskId; using rootcanal::BaseBandSniffer; using rootcanal::HciDevice; using rootcanal::HciSniffer; using rootcanal::HciSocketTransport; using rootcanal::LinkLayerSocketDevice; using rootcanal::TaskCallback;
// 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(); if (!google::protobuf::TextFormat::ParseFromString(config_str, config) ||
config->tcp_server_size() == 0) { // Default configuration with default hci port if the input // configuration cannot be used.
SetUpHciServer(open_server, hci_port, rootcanal::ControllerProperties());
} else { // Open an HCI server for all configurations requested by // 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);
SetUpHciServer(open_server, tcp_server.tcp_port(),
rootcanal::ControllerProperties(tcp_server.configuration()));
}
}
}
// 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) {
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), [=, 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 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>());
}
}
});
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.