RootCanal: Gracefully handle HCI Event
* remove obsoleted function for EventPacketBuilder
* prevent to use raw_packet_builder
* add constant for num_hci_command_packets
Bug: 140386699
Test: run_cert.sh
Change-Id: I4b499a434520cedb05e0cf9115e7a5814a9b8912
diff --git a/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc b/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc
index b729b38..587536a 100644
--- a/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc
+++ b/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.cc
@@ -50,6 +50,7 @@
namespace test_vendor_lib {
constexpr char DualModeController::kControllerPropertiesFile[];
constexpr uint16_t DualModeController::kSecurityManagerNumKeys;
+constexpr uint16_t kNumCommandPackets = 0x01;
// Device methods.
void DualModeController::Initialize(const std::vector<std::string>& args) {
@@ -76,16 +77,10 @@
link_layer_controller_.TimerTick();
}
-void DualModeController::SendCommandCompleteSuccess(
- bluetooth::hci::OpCode command_opcode) const {
- SendCommandCompleteOnlyStatus(command_opcode,
- bluetooth::hci::ErrorCode::SUCCESS);
-}
-
void DualModeController::SendCommandCompleteUnknownOpCodeEvent(uint16_t command_opcode) const {
std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
std::make_unique<bluetooth::packet::RawBuilder>();
- raw_builder_ptr->AddOctets1(0x01); // num_responses
+ raw_builder_ptr->AddOctets1(kNumCommandPackets);
raw_builder_ptr->AddOctets2(command_opcode);
raw_builder_ptr->AddOctets1(
static_cast<uint8_t>(bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND));
@@ -95,32 +90,6 @@
send_event_(std::move(packet));
}
-void DualModeController::SendCommandCompleteOnlyStatus(
- bluetooth::hci::OpCode command_opcode,
- bluetooth::hci::ErrorCode status) const {
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
- raw_builder_ptr->AddOctets1(static_cast<uint8_t>(status));
- auto packet = bluetooth::hci::CommandCompleteBuilder::Create(
- 0x01, command_opcode, std::move(raw_builder_ptr));
- send_event_(std::move(packet));
-}
-
-void DualModeController::SendCommandStatus(
- bluetooth::hci::ErrorCode status,
- bluetooth::hci::OpCode command_opcode) const {
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
- auto packet = bluetooth::hci::CommandStatusBuilder::Create(
- status, 0x01, command_opcode, std::move(raw_builder_ptr));
- send_event_(std::move(packet));
-}
-
-void DualModeController::SendCommandStatusSuccess(
- bluetooth::hci::OpCode command_opcode) const {
- SendCommandStatus(bluetooth::hci::ErrorCode::SUCCESS, command_opcode);
-}
-
DualModeController::DualModeController(const std::string& properties_filename, uint16_t num_keys)
: Device(properties_filename), security_manager_(num_keys) {
loopback_mode_ = hci::LoopbackMode::NO;
@@ -159,7 +128,7 @@
SET_HANDLER(OpCode::WRITE_SIMPLE_PAIRING_MODE, HciWriteSimplePairingMode);
SET_HANDLER(OpCode::WRITE_LE_HOST_SUPPORT, HciWriteLeHostSupport);
SET_HANDLER(OpCode::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT,
- HciWriteSecureConnectionHostSupport);
+ HciWriteSecureConnectionsHostSupport);
SET_HANDLER(OpCode::SET_EVENT_MASK, HciSetEventMask);
SET_HANDLER(OpCode::WRITE_INQUIRY_MODE, HciWriteInquiryMode);
SET_HANDLER(OpCode::WRITE_PAGE_SCAN_TYPE, HciWritePageScanType);
@@ -245,7 +214,7 @@
uint16_t handle = args.begin().extract<uint16_t>();
auto packet = bluetooth::hci::SniffSubratingCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, handle);
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, handle);
send_event_(std::move(packet));
}
@@ -269,15 +238,13 @@
if (loopback_mode_ == hci::LoopbackMode::LOCAL) {
uint16_t handle = acl_packet.GetHandle();
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
- raw_builder_ptr->AddOctets1(0x01);
- raw_builder_ptr->AddOctets2(handle);
- raw_builder_ptr->AddOctets2(0x01);
-
- auto packet = bluetooth::hci::EventPacketBuilder::Create(
- bluetooth::hci::EventCode::NUMBER_OF_COMPLETED_PACKETS,
- std::move(raw_builder_ptr));
+ std::vector<bluetooth::hci::CompletedPackets> completed_packets;
+ bluetooth::hci::CompletedPackets cp;
+ cp.connection_handle_ = handle;
+ cp.host_num_of_completed_packets_ = kNumCommandPackets;
+ completed_packets.push_back(cp);
+ auto packet = bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(
+ completed_packets);
send_event_(std::move(packet));
return;
}
@@ -290,15 +257,13 @@
if (loopback_mode_ == hci::LoopbackMode::LOCAL) {
uint16_t handle = sco_packet.GetHandle();
send_sco_(packet);
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
- raw_builder_ptr->AddOctets1(0x01);
- raw_builder_ptr->AddOctets2(handle);
- raw_builder_ptr->AddOctets2(0x01);
-
- auto packet = bluetooth::hci::EventPacketBuilder::Create(
- bluetooth::hci::EventCode::NUMBER_OF_COMPLETED_PACKETS,
- std::move(raw_builder_ptr));
+ std::vector<bluetooth::hci::CompletedPackets> completed_packets;
+ bluetooth::hci::CompletedPackets cp;
+ cp.connection_handle_ = handle;
+ cp.host_num_of_completed_packets_ = kNumCommandPackets;
+ completed_packets.push_back(cp);
+ auto packet = bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(
+ completed_packets);
send_event_(std::move(packet));
return;
}
@@ -361,14 +326,16 @@
loopback_mode_ = hci::LoopbackMode::NO;
}
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::RESET);
+ auto packet = bluetooth::hci::ResetCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciReadBufferSize(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet = bluetooth::hci::ReadBufferSizeCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
properties_.GetAclDataPacketSize(),
properties_.GetSynchronousDataPacketSize(),
properties_.GetTotalNumAclDataPackets(),
@@ -383,32 +350,34 @@
uint16_t handle = args.begin().extract<uint16_t>();
auto packet = bluetooth::hci::ReadEncryptionKeySizeCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, handle,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, handle,
properties_.GetEncryptionKeySize());
send_event_(std::move(packet));
}
void DualModeController::HciHostBufferSize(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::HOST_BUFFER_SIZE);
+ auto packet = bluetooth::hci::HostBufferSizeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciReadLocalVersionInformation(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
- raw_builder_ptr->AddOctets1(
- static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
- raw_builder_ptr->AddOctets1(properties_.GetVersion());
- raw_builder_ptr->AddOctets2(properties_.GetRevision());
- raw_builder_ptr->AddOctets1(properties_.GetLmpPalVersion());
- raw_builder_ptr->AddOctets2(properties_.GetManufacturerName());
- raw_builder_ptr->AddOctets2(properties_.GetLmpPalSubversion());
-
- auto packet = bluetooth::hci::CommandCompleteBuilder::Create(
- 0x01, bluetooth::hci::OpCode::READ_LOCAL_VERSION_INFORMATION,
- std::move(raw_builder_ptr));
+ bluetooth::hci::LocalVersionInformation local_version_information;
+ local_version_information.hci_version_ =
+ static_cast<bluetooth::hci::HciVersion>(properties_.GetVersion());
+ local_version_information.hci_revision_ = properties_.GetRevision();
+ local_version_information.lmp_version_ =
+ static_cast<bluetooth::hci::LmpVersion>(properties_.GetLmpPalVersion());
+ local_version_information.manufacturer_name_ =
+ properties_.GetManufacturerName();
+ local_version_information.lmp_subversion_ = properties_.GetLmpPalSubversion();
+ auto packet =
+ bluetooth::hci::ReadLocalVersionInformationCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
+ local_version_information);
send_event_(std::move(packet));
}
@@ -420,14 +389,17 @@
auto status = link_layer_controller_.SendCommandToRemoteByHandle(
bluetooth::hci::OpCode::READ_REMOTE_VERSION_INFORMATION, args, handle);
- SendCommandStatus(status,
- bluetooth::hci::OpCode::READ_REMOTE_VERSION_INFORMATION);
+ auto packet =
+ bluetooth::hci::ReadRemoteVersionInformationStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciReadBdAddr(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet = bluetooth::hci::ReadBdAddrCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, properties_.GetAddress());
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
+ properties_.GetAddress());
send_event_(std::move(packet));
}
@@ -445,7 +417,8 @@
auto packet =
bluetooth::hci::ReadLocalSupportedCommandsCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, supported_commands);
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
+ supported_commands);
send_event_(std::move(packet));
}
@@ -453,7 +426,7 @@
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet =
bluetooth::hci::ReadLocalSupportedFeaturesCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
properties_.GetSupportedFeatures());
send_event_(std::move(packet));
}
@@ -461,7 +434,7 @@
void DualModeController::HciReadLocalSupportedCodecs(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet = bluetooth::hci::ReadLocalSupportedCodecsCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
properties_.GetSupportedCodecs(), properties_.GetVendorSpecificCodecs());
send_event_(std::move(packet));
}
@@ -472,7 +445,7 @@
auto pakcet =
bluetooth::hci::ReadLocalExtendedFeaturesCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, page_number,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, page_number,
properties_.GetExtendedFeaturesMaximumPageNumber(),
properties_.GetExtendedFeatures(page_number));
send_event_(std::move(pakcet));
@@ -486,8 +459,9 @@
auto status = link_layer_controller_.SendCommandToRemoteByHandle(
bluetooth::hci::OpCode::READ_REMOTE_EXTENDED_FEATURES, args, handle);
- SendCommandStatus(status,
- bluetooth::hci::OpCode::READ_REMOTE_EXTENDED_FEATURES);
+ auto packet = bluetooth::hci::ReadRemoteExtendedFeaturesStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciSwitchRole(packets::PacketView<true> args) {
@@ -498,7 +472,9 @@
auto status = link_layer_controller_.SwitchRole(address, role);
- SendCommandStatus(status, bluetooth::hci::OpCode::SWITCH_ROLE);
+ auto packet = bluetooth::hci::SwitchRoleStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciReadRemoteSupportedFeatures(packets::PacketView<true> args) {
@@ -509,8 +485,10 @@
auto status = link_layer_controller_.SendCommandToRemoteByHandle(
bluetooth::hci::OpCode::READ_REMOTE_SUPPORTED_FEATURES, args, handle);
- SendCommandStatus(status,
- bluetooth::hci::OpCode::READ_REMOTE_SUPPORTED_FEATURES);
+ auto packet =
+ bluetooth::hci::ReadRemoteSupportedFeaturesStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciReadClockOffset(packets::PacketView<true> args) {
@@ -521,7 +499,9 @@
auto status = link_layer_controller_.SendCommandToRemoteByHandle(
bluetooth::hci::OpCode::READ_CLOCK_OFFSET, args, handle);
- SendCommandStatus(status, bluetooth::hci::OpCode::READ_CLOCK_OFFSET);
+ auto packet = bluetooth::hci::ReadClockOffsetStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciIoCapabilityRequestReply(packets::PacketView<true> args) {
@@ -536,7 +516,7 @@
auto status = link_layer_controller_.IoCapabilityRequestReply(
peer, io_capability, oob_data_present_flag, authentication_requirements);
auto packet = bluetooth::hci::IoCapabilityRequestReplyCompleteBuilder::Create(
- 0x01, status, peer);
+ kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -549,7 +529,7 @@
auto status = link_layer_controller_.UserConfirmationRequestReply(peer);
auto packet =
bluetooth::hci::UserConfirmationRequestReplyCompleteBuilder::Create(
- 0x01, status, peer);
+ kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -563,7 +543,7 @@
link_layer_controller_.UserConfirmationRequestNegativeReply(peer);
auto packet =
bluetooth::hci::UserConfirmationRequestNegativeReplyCompleteBuilder::
- Create(0x01, status, peer);
+ Create(kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -578,7 +558,7 @@
auto status =
link_layer_controller_.UserPasskeyRequestReply(peer, numeric_value);
auto packet = bluetooth::hci::UserPasskeyRequestReplyCompleteBuilder::Create(
- 0x01, status, peer);
+ kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -591,7 +571,7 @@
auto status = link_layer_controller_.UserPasskeyRequestNegativeReply(peer);
auto packet =
bluetooth::hci::UserPasskeyRequestNegativeReplyCompleteBuilder::Create(
- 0x01, status, peer);
+ kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -612,7 +592,7 @@
auto status = link_layer_controller_.RemoteOobDataRequestReply(peer, c, r);
auto packet =
bluetooth::hci::RemoteOobDataRequestReplyCompleteBuilder::Create(
- 0x01, status, peer);
+ kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -625,7 +605,7 @@
auto status = link_layer_controller_.RemoteOobDataRequestNegativeReply(peer);
auto packet =
bluetooth::hci::RemoteOobDataRequestNegativeReplyCompleteBuilder::Create(
- 0x01, status, peer);
+ kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -641,7 +621,7 @@
link_layer_controller_.IoCapabilityRequestNegativeReply(peer, reason);
auto packet =
bluetooth::hci::IoCapabilityRequestNegativeReplyCompleteBuilder::Create(
- 0x01, status, peer);
+ kNumCommandPackets, status, peer);
send_event_(std::move(packet));
}
@@ -650,7 +630,9 @@
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
ASSERT(args[0] == 1 || args[0] == 0);
link_layer_controller_.WriteSimplePairingMode(args[0] == 1);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_SIMPLE_PAIRING_MODE);
+ auto packet = bluetooth::hci::WriteSimplePairingModeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciChangeConnectionPacketType(packets::PacketView<true> args) {
@@ -662,42 +644,55 @@
auto status =
link_layer_controller_.ChangeConnectionPacketType(handle, packet_type);
- SendCommandStatus(status,
- bluetooth::hci::OpCode::CHANGE_CONNECTION_PACKET_TYPE);
+ auto packet = bluetooth::hci::ChangeConnectionPacketTypeStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteLeHostSupport(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_LE_HOST_SUPPORT);
+ auto packet = bluetooth::hci::WriteLeHostSupportCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
-void DualModeController::HciWriteSecureConnectionHostSupport(
+void DualModeController::HciWriteSecureConnectionsHostSupport(
packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
properties_.SetExtendedFeatures(properties_.GetExtendedFeatures(1) | 0x8, 1);
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT);
+ auto packet =
+ bluetooth::hci::WriteSecureConnectionsHostSupportCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciSetEventMask(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::SET_EVENT_MASK);
+ auto packet = bluetooth::hci::SetEventMaskCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteInquiryMode(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
link_layer_controller_.SetInquiryMode(args[0]);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_INQUIRY_MODE);
+ auto packet = bluetooth::hci::WriteInquiryModeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWritePageScanType(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_PAGE_SCAN_TYPE);
+ auto packet = bluetooth::hci::WritePageScanTypeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteInquiryScanType(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_INQUIRY_SCAN_TYPE);
+ auto packet = bluetooth::hci::WriteInquiryScanTypeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciAuthenticationRequested(packets::PacketView<true> args) {
@@ -705,7 +700,9 @@
uint16_t handle = args.begin().extract<uint16_t>();
auto status = link_layer_controller_.AuthenticationRequested(handle);
- SendCommandStatus(status, bluetooth::hci::OpCode::AUTHENTICATION_REQUESTED);
+ auto packet = bluetooth::hci::AuthenticationRequestedStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciSetConnectionEncryption(packets::PacketView<true> args) {
@@ -716,7 +713,9 @@
auto status =
link_layer_controller_.SetConnectionEncryption(handle, encryption_enable);
- SendCommandStatus(status, bluetooth::hci::OpCode::SET_CONNECTION_ENCRYPTION);
+ auto packet = bluetooth::hci::SetConnectionEncryptionStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciChangeConnectionLinkKey(packets::PacketView<true> args) {
@@ -726,7 +725,9 @@
auto status = link_layer_controller_.ChangeConnectionLinkKey(handle);
- SendCommandStatus(status, bluetooth::hci::OpCode::CHANGE_CONNECTION_LINK_KEY);
+ auto packet = bluetooth::hci::ChangeConnectionLinkKeyStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciMasterLinkKey(packets::PacketView<true> args) {
@@ -736,20 +737,24 @@
auto status = link_layer_controller_.MasterLinkKey(key_flag);
- SendCommandStatus(status, bluetooth::hci::OpCode::MASTER_LINK_KEY);
+ auto packet = bluetooth::hci::MasterLinkKeyStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteAuthenticationEnable(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
properties_.SetAuthenticationEnable(args[0]);
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::WRITE_AUTHENTICATION_ENABLE);
+ auto packet =
+ bluetooth::hci::WriteAuthenticationEnableCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciReadAuthenticationEnable(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet = bluetooth::hci::ReadAuthenticationEnableCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
static_cast<bluetooth::hci::AuthenticationEnable>(
properties_.GetAuthenticationEnable()));
send_event_(std::move(packet));
@@ -758,12 +763,16 @@
void DualModeController::HciWriteClassOfDevice(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size());
properties_.SetClassOfDevice(args[0], args[1], args[2]);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_CLASS_OF_DEVICE);
+ auto packet = bluetooth::hci::WriteClassOfDeviceCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWritePageTimeout(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_PAGE_TIMEOUT);
+ auto packet = bluetooth::hci::WritePageTimeoutCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciHoldMode(packets::PacketView<true> args) {
@@ -776,7 +785,9 @@
auto status = link_layer_controller_.HoldMode(handle, hold_mode_max_interval,
hold_mode_min_interval);
- SendCommandStatus(status, bluetooth::hci::OpCode::HOLD_MODE);
+ auto packet =
+ bluetooth::hci::HoldModeStatusBuilder::Create(status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciSniffMode(packets::PacketView<true> args) {
@@ -792,7 +803,9 @@
sniff_min_interval,
sniff_attempt, sniff_timeout);
- SendCommandStatus(status, bluetooth::hci::OpCode::SNIFF_MODE);
+ auto packet = bluetooth::hci::SniffModeStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciExitSniffMode(packets::PacketView<true> args) {
@@ -802,7 +815,9 @@
auto status = link_layer_controller_.ExitSniffMode(handle);
- SendCommandStatus(status, bluetooth::hci::OpCode::EXIT_SNIFF_MODE);
+ auto packet = bluetooth::hci::ExitSniffModeStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciQosSetup(packets::PacketView<true> args) {
@@ -820,13 +835,17 @@
link_layer_controller_.QosSetup(handle, service_type, token_rate,
peak_bandwidth, latency, delay_variation);
- SendCommandStatus(status, bluetooth::hci::OpCode::QOS_SETUP);
+ auto packet =
+ bluetooth::hci::QosSetupStatusBuilder::Create(status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteDefaultLinkPolicySettings(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS);
+ auto packet =
+ bluetooth::hci::WriteDefaultLinkPolicySettingsCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciFlowSpecification(packets::PacketView<true> args) {
@@ -845,7 +864,9 @@
handle, flow_direction, service_type, token_rate, token_bucket_size,
peak_bandwidth, access_latency);
- SendCommandStatus(status, bluetooth::hci::OpCode::FLOW_SPECIFICATION);
+ auto packet = bluetooth::hci::FlowSpecificationStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteLinkPolicySettings(packets::PacketView<true> args) {
@@ -859,7 +880,7 @@
link_layer_controller_.WriteLinkPolicySettings(handle, settings);
auto packet = bluetooth::hci::WriteLinkPolicySettingsCompleteBuilder::Create(
- 0x01, status, handle);
+ kNumCommandPackets, status, handle);
send_event_(std::move(packet));
}
@@ -874,7 +895,7 @@
link_layer_controller_.WriteLinkSupervisionTimeout(handle, timeout);
auto packet =
bluetooth::hci::WriteLinkSupervisionTimeoutCompleteBuilder::Create(
- 0x01, status, handle);
+ kNumCommandPackets, status, handle);
send_event_(std::move(packet));
}
@@ -890,7 +911,7 @@
std::copy_n(properties_.GetName().begin(), len, local_name.begin());
auto packet = bluetooth::hci::ReadLocalNameCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, local_name);
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, local_name);
send_event_(std::move(packet));
}
@@ -898,7 +919,9 @@
ASSERT_LOG(args.size() == 248, "%s size=%zu", __func__, args.size());
std::vector<uint8_t> clipped(args.begin(), args.begin() + LastNonZero(args) + 1);
properties_.SetName(clipped);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_LOCAL_NAME);
+ auto packet = bluetooth::hci::WriteLocalNameCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteExtendedInquiryResponse(packets::PacketView<true> args) {
@@ -908,49 +931,63 @@
properties_.SetExtendedInquiryData(clipped);
LOG_WARN("Write EIR Inquiry - Size = %d (%d)", static_cast<int>(properties_.GetExtendedInquiryData().size()),
static_cast<int>(clipped.size()));
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::WRITE_EXTENDED_INQUIRY_RESPONSE);
+ auto packet =
+ bluetooth::hci::WriteExtendedInquiryResponseCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciRefreshEncryptionKey(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
auto args_itr = args.begin();
uint16_t handle = args_itr.extract<uint16_t>();
- SendCommandStatusSuccess(bluetooth::hci::OpCode::REFRESH_ENCRYPTION_KEY);
+ auto status_packet =
+ bluetooth::hci::RefreshEncryptionKeyStatusBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
+ send_event_(std::move(status_packet));
// TODO: Support this in the link layer
- auto packet = bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create(
- bluetooth::hci::ErrorCode::SUCCESS, handle);
- send_event_(std::move(packet));
+ auto complete_packet =
+ bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, handle);
+ send_event_(std::move(complete_packet));
}
void DualModeController::HciWriteVoiceSetting(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_VOICE_SETTING);
+ auto packet = bluetooth::hci::WriteVoiceSettingCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteCurrentIacLap(packets::PacketView<true> args) {
ASSERT(args.size() > 0);
ASSERT(args.size() == 1 + (3 * args[0])); // count + 3-byte IACs
-
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_CURRENT_IAC_LAP);
+ auto packet = bluetooth::hci::WriteCurrentIacLapCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteInquiryScanActivity(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size());
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::WRITE_INQUIRY_SCAN_ACTIVITY);
+ auto packet = bluetooth::hci::WriteInquiryScanActivityCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciWriteScanEnable(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
link_layer_controller_.SetInquiryScanEnable(args[0] & 0x1);
link_layer_controller_.SetPageScanEnable(args[0] & 0x2);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_SCAN_ENABLE);
+ auto packet = bluetooth::hci::WriteScanEnableCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciSetEventFilter(packets::PacketView<true> args) {
ASSERT(args.size() > 0);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::SET_EVENT_FILTER);
+ auto packet = bluetooth::hci::SetEventFilterCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciInquiry(packets::PacketView<true> args) {
@@ -959,13 +996,17 @@
link_layer_controller_.SetInquiryMaxResponses(args[4]);
link_layer_controller_.StartInquiry(std::chrono::milliseconds(args[3] * 1280));
- SendCommandStatusSuccess(bluetooth::hci::OpCode::INQUIRY);
+ auto packet = bluetooth::hci::InquiryStatusBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciInquiryCancel(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
link_layer_controller_.InquiryCancel();
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::INQUIRY_CANCEL);
+ auto packet = bluetooth::hci::InquiryCancelCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciAcceptConnectionRequest(packets::PacketView<true> args) {
@@ -974,7 +1015,9 @@
bool try_role_switch = args[6] == 0;
auto status =
link_layer_controller_.AcceptConnectionRequest(addr, try_role_switch);
- SendCommandStatus(status, bluetooth::hci::OpCode::ACCEPT_CONNECTION_REQUEST);
+ auto packet = bluetooth::hci::AcceptConnectionRequestStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciRejectConnectionRequest(packets::PacketView<true> args) {
@@ -983,7 +1026,9 @@
Address addr = args_itr.extract<Address>();
uint8_t reason = args_itr.extract<uint8_t>();
auto status = link_layer_controller_.RejectConnectionRequest(addr, reason);
- SendCommandStatus(status, bluetooth::hci::OpCode::REJECT_CONNECTION_REQUEST);
+ auto packet = bluetooth::hci::RejectConnectionRequestStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciLinkKeyRequestReply(packets::PacketView<true> args) {
@@ -991,8 +1036,8 @@
Address addr = args.begin().extract<Address>();
packets::PacketView<true> key = args.SubViewLittleEndian(6, 22);
auto status = link_layer_controller_.LinkKeyRequestReply(addr, key);
- auto packet =
- bluetooth::hci::LinkKeyRequestReplyCompleteBuilder::Create(0x01, status);
+ auto packet = bluetooth::hci::LinkKeyRequestReplyCompleteBuilder::Create(
+ kNumCommandPackets, status);
send_event_(std::move(packet));
}
@@ -1002,7 +1047,7 @@
auto status = link_layer_controller_.LinkKeyRequestNegativeReply(addr);
auto packet =
bluetooth::hci::LinkKeyRequestNegativeReplyCompleteBuilder::Create(
- 0x01, status, addr);
+ kNumCommandPackets, status, addr);
send_event_(std::move(packet));
}
@@ -1021,7 +1066,7 @@
}
auto packet = bluetooth::hci::DeleteStoredLinkKeyCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, deleted_keys);
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, deleted_keys);
send_event_(std::move(packet));
}
@@ -1034,7 +1079,9 @@
auto status = link_layer_controller_.SendCommandToRemoteByAddress(
bluetooth::hci::OpCode::REMOTE_NAME_REQUEST, args, remote_addr, false);
- SendCommandStatus(status, bluetooth::hci::OpCode::REMOTE_NAME_REQUEST);
+ auto packet = bluetooth::hci::RemoteNameRequestStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetEventMask(packets::PacketView<true> args) {
@@ -1043,22 +1090,20 @@
uint64_t mask = args.begin().extract<uint64_t>();
link_layer_controller_.SetLeEventMask(mask);
*/
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_SET_EVENT_MASK);
+ auto packet = bluetooth::hci::LeSetEventMaskCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeReadBufferSize(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
- raw_builder_ptr->AddOctets1(
- static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
- raw_builder_ptr->AddOctets2(properties_.GetLeDataPacketLength());
- raw_builder_ptr->AddOctets1(properties_.GetTotalNumLeDataPackets());
+ bluetooth::hci::LeBufferSize le_buffer_size;
+ le_buffer_size.le_data_packet_length_ = properties_.GetLeDataPacketLength();
+ le_buffer_size.total_num_le_packets_ = properties_.GetTotalNumLeDataPackets();
- auto packet = bluetooth::hci::CommandCompleteBuilder::Create(
- 0x01, bluetooth::hci::OpCode::LE_READ_BUFFER_SIZE,
- std::move(raw_builder_ptr));
+ auto packet = bluetooth::hci::LeReadBufferSizeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, le_buffer_size);
send_event_(std::move(packet));
}
@@ -1066,7 +1111,7 @@
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet =
bluetooth::hci::LeReadLocalSupportedFeaturesCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
properties_.GetLeSupportedFeatures());
send_event_(std::move(packet));
}
@@ -1074,7 +1119,9 @@
void DualModeController::HciLeSetRandomAddress(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
properties_.SetLeAddress(args.begin().extract<Address>());
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_SET_RANDOM_ADDRESS);
+ auto packet = bluetooth::hci::LeSetRandomAddressCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetAdvertisingParameters(packets::PacketView<true> args) {
@@ -1088,28 +1135,35 @@
args_itr.extract<uint8_t>() /* AdvertisingFilterPolicy */
);
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::LE_SET_ADVERTISING_PARAMETERS);
+ auto packet =
+ bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetAdvertisingData(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 32, "%s size=%zu", __func__, args.size());
properties_.SetLeAdvertisement(std::vector<uint8_t>(args.begin() + 1, args.end()));
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_SET_ADVERTISING_DATA);
+ auto packet = bluetooth::hci::LeSetAdvertisingDataCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetScanResponseData(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 32, "%s size=%zu", __func__, args.size());
properties_.SetLeScanResponse(std::vector<uint8_t>(args.begin() + 1, args.end()));
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_SET_SCAN_RESPONSE_DATA);
+ auto packet = bluetooth::hci::LeSetScanResponseDataCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetAdvertisingEnable(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
auto status = link_layer_controller_.SetLeAdvertisingEnable(
args.begin().extract<uint8_t>());
- SendCommandCompleteOnlyStatus(
- bluetooth::hci::OpCode::LE_SET_ADVERTISING_ENABLE, status);
+ auto packet = bluetooth::hci::LeSetAdvertisingEnableCompleteBuilder::Create(
+ kNumCommandPackets, status);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetScanParameters(packets::PacketView<true> args) {
@@ -1119,7 +1173,9 @@
link_layer_controller_.SetLeScanWindow(args[3] | (args[4], 8));
link_layer_controller_.SetLeAddressType(args[5]);
link_layer_controller_.SetLeScanFilterPolicy(args[6]);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_SET_SCAN_PARAMETERS);
+ auto packet = bluetooth::hci::LeSetScanParametersCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetScanEnable(packets::PacketView<true> args) {
@@ -1127,7 +1183,9 @@
LOG_INFO("SetScanEnable: %d %d", args[0], args[1]);
link_layer_controller_.SetLeScanEnable(args[0]);
link_layer_controller_.SetLeFilterDuplicates(args[1]);
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_SET_SCAN_ENABLE);
+ auto packet = bluetooth::hci::LeSetScanEnableCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeCreateConnection(packets::PacketView<true> args) {
@@ -1154,18 +1212,23 @@
auto status = link_layer_controller_.SetLeConnect(true);
- SendCommandStatus(status, bluetooth::hci::OpCode::LE_CREATE_CONNECTION);
+ auto packet = bluetooth::hci::LeCreateConnectionStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeConnectionUpdate(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 14, "%s size=%zu", __func__, args.size());
- SendCommandStatus(
+ auto status_packet = bluetooth::hci::LeConnectionUpdateStatusBuilder::Create(
bluetooth::hci::ErrorCode::CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR,
- bluetooth::hci::OpCode::LE_CONNECTION_UPDATE);
+ kNumCommandPackets);
+ send_event_(std::move(status_packet));
- auto packet = bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create(
- bluetooth::hci::ErrorCode::SUCCESS, 0x0002, 0x0006, 0x0000, 0x01f4);
+ auto complete_packet =
+ bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, 0x0002, 0x0006, 0x0000, 0x01f4);
+ send_event_(std::move(complete_packet));
}
void DualModeController::HciCreateConnection(packets::PacketView<true> args) {
@@ -1181,7 +1244,9 @@
auto status = link_layer_controller_.CreateConnection(
address, packet_type, page_scan_mode, clock_offset, allow_role_switch);
- SendCommandStatus(status, bluetooth::hci::OpCode::CREATE_CONNECTION);
+ auto packet = bluetooth::hci::CreateConnectionStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciDisconnect(packets::PacketView<true> args) {
@@ -1193,13 +1258,17 @@
auto status = link_layer_controller_.Disconnect(handle, reason);
- SendCommandStatus(status, bluetooth::hci::OpCode::DISCONNECT);
+ auto packet = bluetooth::hci::DisconnectStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeConnectionCancel(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
link_layer_controller_.SetLeConnect(false);
- SendCommandStatusSuccess(bluetooth::hci::OpCode::LE_CREATE_CONNECTION_CANCEL);
+ auto packet = bluetooth::hci::LeCreateConnectionCancelStatusBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
+ send_event_(std::move(packet));
/* For testing Jakub's patch: Figure out a neat way to call this without
recompiling. I'm thinking about a bad device. */
/*
@@ -1211,7 +1280,7 @@
void DualModeController::HciLeReadWhiteListSize(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet = bluetooth::hci::LeReadWhiteListSizeCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
properties_.GetLeWhiteListSize());
send_event_(std::move(packet));
}
@@ -1219,24 +1288,28 @@
void DualModeController::HciLeClearWhiteList(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
link_layer_controller_.LeWhiteListClear();
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_CLEAR_WHITE_LIST);
+ auto packet = bluetooth::hci::LeClearWhiteListCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeAddDeviceToWhiteList(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
if (link_layer_controller_.LeWhiteListFull()) {
- SendCommandCompleteOnlyStatus(
- bluetooth::hci::OpCode::LE_ADD_DEVICE_TO_WHITE_LIST,
+ auto packet = bluetooth::hci::LeAddDeviceToWhiteListCompleteBuilder::Create(
+ kNumCommandPackets,
bluetooth::hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED);
+ send_event_(std::move(packet));
return;
}
auto args_itr = args.begin();
uint8_t addr_type = args_itr.extract<uint8_t>();
Address address = args_itr.extract<Address>();
link_layer_controller_.LeWhiteListAddDevice(address, addr_type);
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::LE_ADD_DEVICE_TO_WHITE_LIST);
+ auto packet = bluetooth::hci::LeAddDeviceToWhiteListCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeRemoveDeviceFromWhiteList(packets::PacketView<true> args) {
@@ -1246,15 +1319,19 @@
uint8_t addr_type = args_itr.extract<uint8_t>();
Address address = args_itr.extract<Address>();
link_layer_controller_.LeWhiteListRemoveDevice(address, addr_type);
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::LE_REMOVE_DEVICE_FROM_WHITE_LIST);
+ auto packet =
+ bluetooth::hci::LeRemoveDeviceFromWhiteListCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeClearResolvingList(
packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
link_layer_controller_.LeResolvingListClear();
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_CLEAR_RESOLVING_LIST);
+ auto packet = bluetooth::hci::LeClearResolvingListCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeAddDeviceToResolvingList(
@@ -1262,9 +1339,11 @@
ASSERT_LOG(args.size() == 39, "%s size=%zu", __func__, args.size());
if (link_layer_controller_.LeResolvingListFull()) {
- SendCommandCompleteOnlyStatus(
- bluetooth::hci::OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST,
- bluetooth::hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED);
+ auto packet =
+ bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create(
+ kNumCommandPackets,
+ bluetooth::hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED);
+ send_event_(std::move(packet));
return;
}
auto args_itr = args.begin();
@@ -1284,8 +1363,10 @@
link_layer_controller_.LeResolvingListAddDevice(address, addr_type, peerIrk,
localIrk);
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST);
+ auto packet =
+ bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeRemoveDeviceFromResolvingList(
@@ -1296,8 +1377,10 @@
uint8_t addr_type = args_itr.extract<uint8_t>();
Address address = args_itr.extract<Address>();
link_layer_controller_.LeResolvingListRemoveDevice(address, addr_type);
- SendCommandCompleteSuccess(
- bluetooth::hci::OpCode::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST);
+ auto packet =
+ bluetooth::hci::LeRemoveDeviceFromResolvingListCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeSetPrivacyMode(packets::PacketView<true> args) {
@@ -1314,7 +1397,9 @@
peer_identity_address_type, peer_identity_address, privacy_mode);
}
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::LE_SET_PRIVACY_MODE);
+ auto packet = bluetooth::hci::LeSetPrivacyModeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeReadRemoteFeatures(packets::PacketView<true> args) {
@@ -1325,7 +1410,9 @@
auto status = link_layer_controller_.SendCommandToRemoteByHandle(
bluetooth::hci::OpCode::LE_READ_REMOTE_FEATURES, args, handle);
- SendCommandStatus(status, bluetooth::hci::OpCode::LE_READ_REMOTE_FEATURES);
+ auto packet = bluetooth::hci::LeConnectionUpdateStatusBuilder::Create(
+ status, kNumCommandPackets);
+ send_event_(std::move(packet));
}
void DualModeController::HciLeRand(packets::PacketView<true> args) {
@@ -1336,14 +1423,14 @@
}
auto packet = bluetooth::hci::LeRandCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS, random_val);
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, random_val);
send_event_(std::move(packet));
}
void DualModeController::HciLeReadSupportedStates(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet = bluetooth::hci::LeReadSupportedStatesCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
properties_.GetLeSupportedStates());
send_event_(std::move(packet));
}
@@ -1352,9 +1439,8 @@
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
vector<uint8_t> caps = properties_.GetLeVendorCap();
if (caps.size() == 0) {
- SendCommandCompleteOnlyStatus(
- bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES,
- bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND);
+ SendCommandCompleteUnknownOpCodeEvent(static_cast<uint16_t>(
+ bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES));
return;
}
@@ -1365,33 +1451,33 @@
raw_builder_ptr->AddOctets(properties_.GetLeVendorCap());
auto packet = bluetooth::hci::CommandCompleteBuilder::Create(
- 0x01, bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES,
+ kNumCommandPackets, bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES,
std::move(raw_builder_ptr));
send_event_(std::move(packet));
}
void DualModeController::HciLeVendorMultiAdv(packets::PacketView<true> args) {
ASSERT(args.size() > 0);
- SendCommandCompleteOnlyStatus(bluetooth::hci::OpCode::LE_MULTI_ADVT,
- bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND);
+ SendCommandCompleteUnknownOpCodeEvent(
+ static_cast<uint16_t>(bluetooth::hci::OpCode::LE_MULTI_ADVT));
}
void DualModeController::HciLeAdvertisingFilter(packets::PacketView<true> args) {
ASSERT(args.size() > 0);
- SendCommandCompleteOnlyStatus(bluetooth::hci::OpCode::LE_ADV_FILTER,
- bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND);
+ SendCommandCompleteUnknownOpCodeEvent(
+ static_cast<uint16_t>(bluetooth::hci::OpCode::LE_ADV_FILTER));
}
void DualModeController::HciLeEnergyInfo(packets::PacketView<true> args) {
ASSERT(args.size() > 0);
- SendCommandCompleteOnlyStatus(bluetooth::hci::OpCode::LE_ENERGY_INFO,
- bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND);
+ SendCommandCompleteUnknownOpCodeEvent(
+ static_cast<uint16_t>(bluetooth::hci::OpCode::LE_ENERGY_INFO));
}
void DualModeController::HciLeExtendedScanParams(packets::PacketView<true> args) {
ASSERT(args.size() > 0);
- SendCommandCompleteOnlyStatus(bluetooth::hci::OpCode::LE_EXTENDED_SCAN_PARAMS,
- bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND);
+ SendCommandCompleteUnknownOpCodeEvent(
+ static_cast<uint16_t>(bluetooth::hci::OpCode::LE_EXTENDED_SCAN_PARAMS));
}
void DualModeController::HciLeStartEncryption(packets::PacketView<true> args) {
@@ -1405,13 +1491,14 @@
// for (size_t i = 0; i < 16; i++) {
// long_term_key.push_back(args_itr.extract<uint18_t>();
// }
- SendCommandStatus(bluetooth::hci::ErrorCode::SUCCESS,
- bluetooth::hci::OpCode::LE_START_ENCRYPTION);
+ auto status_packet = bluetooth::hci::LeStartEncryptionStatusBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
+ send_event_(std::move(status_packet));
- auto packet = bluetooth::hci::EncryptionChangeBuilder::Create(
+ auto complete_packet = bluetooth::hci::EncryptionChangeBuilder::Create(
bluetooth::hci::ErrorCode::SUCCESS, handle,
bluetooth::hci::EncryptionEnabled::OFF);
- send_event_(std::move(packet));
+ send_event_(std::move(complete_packet));
#if 0
std::shared_ptr<packets::AclPacketBuilder> encryption_information =
@@ -1469,7 +1556,7 @@
void DualModeController::HciReadLoopbackMode(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
auto packet = bluetooth::hci::ReadLoopbackModeCompleteBuilder::Create(
- 0x01, bluetooth::hci::ErrorCode::SUCCESS,
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
static_cast<bluetooth::hci::LoopbackMode>(loopback_mode_));
send_event_(std::move(packet));
}
@@ -1489,7 +1576,9 @@
bluetooth::hci::ErrorCode::SUCCESS, sco_handle, properties_.GetAddress(),
bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED);
send_event_(std::move(packet_sco));
- SendCommandCompleteSuccess(bluetooth::hci::OpCode::WRITE_LOOPBACK_MODE);
+ auto packet = bluetooth::hci::WriteLoopbackModeCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
+ send_event_(std::move(packet));
}
void DualModeController::SetAddress(Address address) {