// // 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 android::hardware::hidl_vec; using ::bluetooth::hci::Address; using rootcanal::AsyncTaskId; using rootcanal::DualModeController; using rootcanal::HciDevice; using rootcanal::HciSocketTransport; using rootcanal::LinkLayerSocketDevice; using rootcanal::TaskCallback;
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();
}
}
});
}
// 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 classic_phy_index = test_model_.AddPhy(rootcanal::Phy::Type::BR_EDR);
test_model_.AddDeviceToPhy(controller_index, low_energy_phy_index);
test_model_.AddDeviceToPhy(controller_index, classic_phy_index);
test_model_.SetTimerPeriod(std::chrono::milliseconds(10));
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()); });
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_);
SetUpTestChannel();
SetUpHciServer([this](std::shared_ptr<AsyncDataChannel> socket, AsyncDataChannelServer* srv) { auto transport = HciSocketTransport::Create(socket);
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);
srv->StartListening();
});
} else { // This should be configurable in the future.
ALOGI("Adding Beacons so the scan list is not empty.");
test_channel_.AddDevice({"beacon", "be:ac:10:00:00:01", "1000"});
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_model_.AddDeviceToPhy(controller_index + 3, low_energy_phy_index);
test_channel_.List({});
}
unlink_cb_ = [cb](sp<BluetoothDeathRecipient>& death_recipient) { if (death_recipient->getHasDied()) {
ALOGI("Skipping unlink call, service died.");
} else { auto ret = cb->unlinkToDeath(death_recipient); if (!ret.isOk()) {
ALOG_ASSERT(death_recipient_->getHasDied(), "Error calling unlink, but no death notification.");
}
}
};
auto init_ret = cb->initializationComplete(V1_0::Status::SUCCESS); if (!init_ret.isOk()) {
ALOG_ASSERT(death_recipient_->getHasDied(), "Error sending init callback, but no death notification.");
} returnVoid();
}
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.