Rootcanal: Use LinkLayer packets for commands
Use a different LinkLayer packet for each command and response.
Use std::array for device name and keys.
Bug: 138260499
Test: Connect two phones with Rootcanal, try to pair
Change-Id: I82a54afd0821ac71324878904025732a7655abc3
diff --git a/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.cc b/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.cc
index c1fcd84..014015a 100644
--- a/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.cc
+++ b/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.cc
@@ -42,19 +42,25 @@
return unused_handle;
}
-bool AclConnectionHandler::CreatePendingConnection(Address addr) {
+bool AclConnectionHandler::CreatePendingConnection(
+ Address addr, bool authenticate_on_connect) {
if (classic_connection_pending_) {
return false;
}
classic_connection_pending_ = true;
pending_connection_address_ = addr;
+ authenticate_pending_classic_connection_ = authenticate_on_connect;
return true;
}
-bool AclConnectionHandler::HasPendingConnection(Address addr) {
+bool AclConnectionHandler::HasPendingConnection(Address addr) const {
return classic_connection_pending_ && pending_connection_address_ == addr;
}
+bool AclConnectionHandler::AuthenticatePendingConnection() const {
+ return authenticate_pending_classic_connection_;
+}
+
bool AclConnectionHandler::CancelPendingConnection(Address addr) {
if (!classic_connection_pending_ || pending_connection_address_ != addr) {
return false;
@@ -79,7 +85,8 @@
return true;
}
-bool AclConnectionHandler::HasPendingLeConnection(Address addr, uint8_t address_type) {
+bool AclConnectionHandler::HasPendingLeConnection(Address addr,
+ uint8_t address_type) const {
return le_connection_pending_ && pending_le_connection_address_ == addr &&
pending_le_connection_address_type_ == address_type;
}
diff --git a/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.h b/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.h
index 6b32952..c08f529 100644
--- a/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.h
+++ b/vendor_libs/test_vendor_lib/model/controller/acl_connection_handler.h
@@ -34,12 +34,13 @@
virtual ~AclConnectionHandler() = default;
- bool CreatePendingConnection(Address addr);
- bool HasPendingConnection(Address addr);
+ bool CreatePendingConnection(Address addr, bool authenticate_on_connect);
+ bool HasPendingConnection(Address addr) const;
bool CancelPendingConnection(Address addr);
+ bool AuthenticatePendingConnection() const;
bool CreatePendingLeConnection(Address addr, uint8_t addr_type);
- bool HasPendingLeConnection(Address addr, uint8_t addr_type);
+ bool HasPendingLeConnection(Address addr, uint8_t addr_type) const;
bool CancelPendingLeConnection(Address addr, uint8_t addr_type);
uint16_t CreateConnection(Address addr);
@@ -65,10 +66,12 @@
private:
std::unordered_map<uint16_t, AclConnection> acl_connections_;
bool classic_connection_pending_{false};
- Address pending_connection_address_;
+ Address pending_connection_address_{Address::kEmpty};
+ bool authenticate_pending_classic_connection_{false};
bool le_connection_pending_{false};
- Address pending_le_connection_address_;
- uint8_t pending_le_connection_address_type_;
+ Address pending_le_connection_address_{Address::kEmpty};
+ uint8_t pending_le_connection_address_type_{false};
+
uint16_t GetUnusedHandle();
uint16_t last_handle_{acl::kReservedHandle - 2};
void set_own_address_type(uint16_t handle, uint8_t own_address_type);
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 d4974a0..6b1a193 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
@@ -338,9 +338,8 @@
loopback_mode_ = hci::LoopbackMode::NO;
}
- auto packet = bluetooth::hci::ResetCompleteBuilder::Create(
- kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
- send_event_(std::move(packet));
+ send_event_(bluetooth::hci::ResetCompleteBuilder::Create(
+ kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS));
}
void DualModeController::HciReadBufferSize(packets::PacketView<true> args) {
@@ -941,8 +940,6 @@
// Strip FEC byte and trailing zeros
std::vector<uint8_t> clipped(args.begin() + 1, args.begin() + LastNonZero(args) + 1);
properties_.SetExtendedInquiryData(clipped);
- LOG_WARN("Write EIR Inquiry - Size = %d (%d)", static_cast<int>(properties_.GetExtendedInquiryData().size()),
- static_cast<int>(clipped.size()));
auto packet =
bluetooth::hci::WriteExtendedInquiryResponseCompleteBuilder::Create(
kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
@@ -1045,8 +1042,9 @@
void DualModeController::HciLinkKeyRequestReply(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 22, "%s size=%zu", __func__, args.size());
- Address addr = args.begin().extract<Address>();
- packets::PacketView<true> key = args.SubViewLittleEndian(6, 22);
+ auto args_it = args.begin();
+ Address addr = args_it.extract<Address>();
+ auto key = args.begin().extract<std::array<uint8_t, 16>>();
auto status = link_layer_controller_.LinkKeyRequestReply(addr, key);
auto packet = bluetooth::hci::LinkKeyRequestReplyCompleteBuilder::Create(
kNumCommandPackets, status);
@@ -1089,7 +1087,7 @@
Address remote_addr = args.begin().extract<Address>();
auto status = link_layer_controller_.SendCommandToRemoteByAddress(
- bluetooth::hci::OpCode::REMOTE_NAME_REQUEST, args, remote_addr, false);
+ bluetooth::hci::OpCode::REMOTE_NAME_REQUEST, args, remote_addr);
auto packet = bluetooth::hci::RemoteNameRequestStatusBuilder::Create(
status, kNumCommandPackets);
@@ -1192,7 +1190,6 @@
void DualModeController::HciLeSetScanEnable(packets::PacketView<true> args) {
ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
- LOG_INFO("SetScanEnable: %d %d", args[0], args[1]);
link_layer_controller_.SetLeScanEnable(args[0]);
link_layer_controller_.SetLeFilterDuplicates(args[1]);
auto packet = bluetooth::hci::LeSetScanEnableCompleteBuilder::Create(
diff --git a/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc b/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc
index b77f2ce..9e1393b 100644
--- a/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc
+++ b/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.cc
@@ -63,36 +63,56 @@
}
bluetooth::hci::ErrorCode LinkLayerController::SendCommandToRemoteByAddress(
- bluetooth::hci::OpCode opcode, PacketView<true> args, const Address& remote,
- bool use_public_address) {
- Address local_address;
- if (use_public_address) {
- local_address = properties_.GetAddress();
- } else {
- local_address = properties_.GetLeAddress();
+ bluetooth::hci::OpCode opcode, PacketView<true> args,
+ const Address& remote) {
+ Address local_address = properties_.GetAddress();
+
+ switch (opcode) {
+ case (bluetooth::hci::OpCode::REMOTE_NAME_REQUEST):
+ // LMP features get requested with remote name requests.
+ SendLinkLayerPacket(model::packets::ReadRemoteLmpFeaturesBuilder::Create(
+ local_address, remote));
+ SendLinkLayerPacket(model::packets::RemoteNameRequestBuilder::Create(
+ local_address, remote));
+ break;
+ case (bluetooth::hci::OpCode::READ_REMOTE_SUPPORTED_FEATURES):
+ SendLinkLayerPacket(
+ model::packets::ReadRemoteSupportedFeaturesBuilder::Create(
+ local_address, remote));
+ break;
+ case (bluetooth::hci::OpCode::READ_REMOTE_EXTENDED_FEATURES): {
+ uint8_t page_number =
+ (args.begin() + 2).extract<uint8_t>(); // skip the handle
+ SendLinkLayerPacket(
+ model::packets::ReadRemoteExtendedFeaturesBuilder::Create(
+ local_address, remote, page_number));
+ } break;
+ case (bluetooth::hci::OpCode::READ_REMOTE_VERSION_INFORMATION):
+ SendLinkLayerPacket(
+ model::packets::ReadRemoteVersionInformationBuilder::Create(
+ local_address, remote));
+ break;
+ case (bluetooth::hci::OpCode::READ_CLOCK_OFFSET):
+ SendLinkLayerPacket(model::packets::ReadClockOffsetBuilder::Create(
+ local_address, remote));
+ break;
+ default:
+ LOG_INFO("Dropping unhandled command 0x%04x",
+ static_cast<uint16_t>(opcode));
+ return bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND;
}
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
- std::vector<uint8_t> payload_bytes(args.begin(), args.end());
- raw_builder_ptr->AddOctets2(static_cast<uint16_t>(opcode));
- raw_builder_ptr->AddOctets(payload_bytes);
-
- auto command = model::packets::CommandBuilder::Create(
- local_address, remote, std::move(raw_builder_ptr));
-
- SendLinkLayerPacket(std::move(command));
return bluetooth::hci::ErrorCode::SUCCESS;
}
bluetooth::hci::ErrorCode LinkLayerController::SendCommandToRemoteByHandle(
bluetooth::hci::OpCode opcode, PacketView<true> args, uint16_t handle) {
// TODO: Handle LE connections
- bool use_public_address = true;
if (!connections_.HasHandle(handle)) {
return bluetooth::hci::ErrorCode::UNKNOWN_CONNECTION;
}
- return SendCommandToRemoteByAddress(opcode, args, connections_.GetAddress(handle), use_public_address);
+ return SendCommandToRemoteByAddress(opcode, args,
+ connections_.GetAddress(handle));
}
hci::Status LinkLayerController::SendAclToRemote(AclPacketView acl_packet) {
@@ -158,9 +178,6 @@
case model::packets::PacketType::ACL:
IncomingAclPacket(incoming);
break;
- case model::packets::PacketType::COMMAND:
- IncomingCommandPacket(incoming);
- break;
case model::packets::PacketType::DISCONNECT:
IncomingDisconnectPacket(incoming);
break;
@@ -181,6 +198,9 @@
case model::packets::PacketType::IO_CAPABILITY_REQUEST:
IncomingIoCapabilityRequestPacket(incoming);
break;
+ case model::packets::PacketType::IO_CAPABILITY_RESPONSE:
+ IncomingIoCapabilityResponsePacket(incoming);
+ break;
case model::packets::PacketType::IO_CAPABILITY_NEGATIVE_RESPONSE:
IncomingIoCapabilityNegativeResponsePacket(incoming);
break;
@@ -215,11 +235,45 @@
case model::packets::PacketType::PAGE_REJECT:
IncomingPageRejectPacket(incoming);
break;
- case model::packets::PacketType::RESPONSE:
- IncomingResponsePacket(incoming);
+ case (model::packets::PacketType::REMOTE_NAME_REQUEST):
+ IncomingRemoteNameRequest(incoming);
+ break;
+ case (model::packets::PacketType::REMOTE_NAME_REQUEST_RESPONSE):
+ IncomingRemoteNameRequestResponse(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_SUPPORTED_FEATURES):
+ IncomingReadRemoteSupportedFeatures(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_SUPPORTED_FEATURES_RESPONSE):
+ IncomingReadRemoteSupportedFeaturesResponse(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_LMP_FEATURES):
+ IncomingReadRemoteLmpFeatures(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_LMP_FEATURES_RESPONSE):
+ IncomingReadRemoteLmpFeaturesResponse(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_EXTENDED_FEATURES):
+ IncomingReadRemoteExtendedFeatures(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_EXTENDED_FEATURES_RESPONSE):
+ IncomingReadRemoteExtendedFeaturesResponse(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_VERSION_INFORMATION):
+ IncomingReadRemoteVersion(incoming);
+ break;
+ case (model::packets::PacketType::READ_REMOTE_VERSION_INFORMATION_RESPONSE):
+ IncomingReadRemoteVersionResponse(incoming);
+ break;
+ case (model::packets::PacketType::READ_CLOCK_OFFSET):
+ IncomingReadClockOffset(incoming);
+ break;
+ case (model::packets::PacketType::READ_CLOCK_OFFSET_RESPONSE):
+ IncomingReadClockOffsetResponse(incoming);
break;
default:
- LOG_WARN("Dropping unhandled packet of type %d", static_cast<int32_t>(incoming.GetType()));
+ LOG_WARN("Dropping unhandled packet of type %s",
+ model::packets::PacketTypeText(incoming.GetType()).c_str());
}
}
@@ -248,81 +302,149 @@
send_acl_(AclPacketBuilder::Create(local_handle, boundary_flags, broadcast_flags, std::move(builder))->ToVector());
}
-void LinkLayerController::IncomingCommandPacket(
- model::packets::LinkLayerPacketView incoming) {
- // TODO: Check the destination address to see if this packet is for me.
- auto command = model::packets::CommandView::Create(incoming);
- ASSERT(command.IsValid());
+void LinkLayerController::IncomingRemoteNameRequest(
+ model::packets::LinkLayerPacketView packet) {
+ auto view = model::packets::RemoteNameRequestView::Create(packet);
+ ASSERT(view.IsValid());
- auto args = command.GetPayload().begin();
- std::vector<uint64_t> response_data;
- hci::OpCode opcode = static_cast<hci::OpCode>(args.extract<uint16_t>());
- std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
- std::make_unique<bluetooth::packet::RawBuilder>();
+ SendLinkLayerPacket(model::packets::RemoteNameRequestResponseBuilder::Create(
+ packet.GetDestinationAddress(), packet.GetSourceAddress(),
+ properties_.GetName()));
+}
- switch (opcode) {
- case (hci::OpCode::REMOTE_NAME_REQUEST): {
- std::vector<uint8_t> name = properties_.GetName();
- LOG_INFO("Remote Name (Local Name) %d", static_cast<int>(name.size()));
- raw_builder_ptr->AddOctets1(
- static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
- raw_builder_ptr->AddOctets8(name.size());
- raw_builder_ptr->AddOctets(name);
- } break;
- case (hci::OpCode::READ_REMOTE_SUPPORTED_FEATURES):
- LOG_INFO("(%s) Remote Supported Features Requested by: %s %x",
- incoming.GetDestinationAddress().ToString().c_str(), incoming.GetSourceAddress().ToString().c_str(),
- static_cast<int>(properties_.GetSupportedFeatures()));
- raw_builder_ptr->AddOctets1(
- static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
- raw_builder_ptr->AddOctets8(properties_.GetSupportedFeatures());
- break;
- case (hci::OpCode::READ_REMOTE_EXTENDED_FEATURES): {
- uint8_t page_number = (args + 2).extract<uint8_t>(); // skip the handle
- LOG_INFO("(%s) Remote Extended Features %d Requested by: %s", incoming.GetDestinationAddress().ToString().c_str(),
- page_number, incoming.GetSourceAddress().ToString().c_str());
- uint8_t max_page_number = properties_.GetExtendedFeaturesMaximumPageNumber();
- if (page_number > max_page_number) {
- raw_builder_ptr->AddOctets1(static_cast<uint8_t>(
- bluetooth::hci::ErrorCode::INVALID_HCI_COMMAND_PARAMETERS));
- raw_builder_ptr->AddOctets1(page_number);
- raw_builder_ptr->AddOctets1(max_page_number);
- raw_builder_ptr->AddOctets8(0);
- } else {
- raw_builder_ptr->AddOctets1(
- static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
- raw_builder_ptr->AddOctets1(page_number);
- raw_builder_ptr->AddOctets1(max_page_number);
- raw_builder_ptr->AddOctets8(
- properties_.GetExtendedFeatures(page_number));
- }
- } break;
- case (hci::OpCode::READ_REMOTE_VERSION_INFORMATION):
- raw_builder_ptr->AddOctets1(
- static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
- raw_builder_ptr->AddOctets1(properties_.GetLmpPalVersion());
- raw_builder_ptr->AddOctets2(properties_.GetManufacturerName());
- raw_builder_ptr->AddOctets2(properties_.GetLmpPalSubversion());
- break;
- case (hci::OpCode::READ_CLOCK_OFFSET):
- raw_builder_ptr->AddOctets1(
- static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
- raw_builder_ptr->AddOctets2(properties_.GetClockOffset());
- break;
- default:
- LOG_INFO("Dropping unhandled command 0x%04x", static_cast<uint16_t>(opcode));
- return;
+void LinkLayerController::IncomingRemoteNameRequestResponse(
+ model::packets::LinkLayerPacketView packet) {
+ auto view = model::packets::RemoteNameRequestResponseView::Create(packet);
+ ASSERT(view.IsValid());
+
+ send_event_(bluetooth::hci::RemoteNameRequestCompleteBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, packet.GetSourceAddress(),
+ view.GetName()));
+}
+
+void LinkLayerController::IncomingReadRemoteLmpFeatures(
+ model::packets::LinkLayerPacketView packet) {
+ SendLinkLayerPacket(
+ model::packets::ReadRemoteLmpFeaturesResponseBuilder::Create(
+ packet.GetDestinationAddress(), packet.GetSourceAddress(),
+ properties_.GetExtendedFeatures(1)));
+}
+
+void LinkLayerController::IncomingReadRemoteLmpFeaturesResponse(
+ model::packets::LinkLayerPacketView packet) {
+ auto view = model::packets::ReadRemoteLmpFeaturesResponseView::Create(packet);
+ ASSERT(view.IsValid());
+ send_event_(
+ bluetooth::hci::RemoteHostSupportedFeaturesNotificationBuilder::Create(
+ packet.GetSourceAddress(), view.GetFeatures()));
+}
+
+void LinkLayerController::IncomingReadRemoteSupportedFeatures(
+ model::packets::LinkLayerPacketView packet) {
+ SendLinkLayerPacket(
+ model::packets::ReadRemoteSupportedFeaturesResponseBuilder::Create(
+ packet.GetDestinationAddress(), packet.GetSourceAddress(),
+ properties_.GetSupportedFeatures()));
+}
+
+void LinkLayerController::IncomingReadRemoteSupportedFeaturesResponse(
+ model::packets::LinkLayerPacketView packet) {
+ auto view =
+ model::packets::ReadRemoteSupportedFeaturesResponseView::Create(packet);
+ ASSERT(view.IsValid());
+ Address source = packet.GetSourceAddress();
+ if (connections_.IsDeviceConnected(source)) {
+ uint16_t handle = connections_.GetHandle(source);
+ send_event_(
+ bluetooth::hci::ReadRemoteSupportedFeaturesCompleteBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, handle, view.GetFeatures()));
+ } else {
+ LOG_INFO("Discarding response from a disconnected device %s",
+ source.ToString().c_str());
}
+}
- for (uint64_t data : response_data) {
- raw_builder_ptr->AddOctets8(data);
+void LinkLayerController::IncomingReadRemoteExtendedFeatures(
+ model::packets::LinkLayerPacketView packet) {
+ auto view = model::packets::ReadRemoteExtendedFeaturesView::Create(packet);
+ ASSERT(view.IsValid());
+ uint8_t page_number = view.GetPageNumber();
+ uint8_t error_code = static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS);
+ if (page_number > properties_.GetExtendedFeaturesMaximumPageNumber()) {
+ error_code = static_cast<uint8_t>(
+ bluetooth::hci::ErrorCode::INVALID_LMP_OR_LL_PARAMETERS);
}
+ SendLinkLayerPacket(
+ model::packets::ReadRemoteExtendedFeaturesResponseBuilder::Create(
+ packet.GetDestinationAddress(), packet.GetSourceAddress(), error_code,
+ page_number, properties_.GetExtendedFeaturesMaximumPageNumber(),
+ properties_.GetExtendedFeatures(view.GetPageNumber())));
+}
- auto response = model::packets::ResponseBuilder::Create(
- properties_.GetAddress(), incoming.GetSourceAddress(),
- static_cast<uint16_t>(opcode), std::move(raw_builder_ptr));
+void LinkLayerController::IncomingReadRemoteExtendedFeaturesResponse(
+ model::packets::LinkLayerPacketView packet) {
+ auto view =
+ model::packets::ReadRemoteExtendedFeaturesResponseView::Create(packet);
+ ASSERT(view.IsValid());
+ Address source = packet.GetSourceAddress();
+ if (connections_.IsDeviceConnected(source)) {
+ uint16_t handle = connections_.GetHandle(packet.GetSourceAddress());
+ send_event_(
+ bluetooth::hci::ReadRemoteExtendedFeaturesCompleteBuilder::Create(
+ static_cast<bluetooth::hci::ErrorCode>(view.GetStatus()), handle,
+ view.GetPageNumber(), view.GetMaxPageNumber(), view.GetFeatures()));
+ } else {
+ LOG_INFO("Discarding response from a disconnected device %s",
+ source.ToString().c_str());
+ }
+}
- SendLinkLayerPacket(std::move(response));
+void LinkLayerController::IncomingReadRemoteVersion(
+ model::packets::LinkLayerPacketView packet) {
+ SendLinkLayerPacket(
+ model::packets::ReadRemoteSupportedFeaturesResponseBuilder::Create(
+ packet.GetDestinationAddress(), packet.GetSourceAddress(),
+ properties_.GetSupportedFeatures()));
+}
+
+void LinkLayerController::IncomingReadRemoteVersionResponse(
+ model::packets::LinkLayerPacketView packet) {
+ auto view =
+ model::packets::ReadRemoteVersionInformationResponseView::Create(packet);
+ ASSERT(view.IsValid());
+ Address source = packet.GetSourceAddress();
+ if (connections_.IsDeviceConnected(source)) {
+ uint16_t handle = connections_.GetHandle(packet.GetSourceAddress());
+ send_event_(
+ bluetooth::hci::ReadRemoteVersionInformationCompleteBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, handle, view.GetLmpVersion(),
+ view.GetManufacturerName(), view.GetLmpSubversion()));
+ } else {
+ LOG_INFO("Discarding response from a disconnected device %s",
+ source.ToString().c_str());
+ }
+}
+
+void LinkLayerController::IncomingReadClockOffset(
+ model::packets::LinkLayerPacketView packet) {
+ SendLinkLayerPacket(model::packets::ReadClockOffsetResponseBuilder::Create(
+ packet.GetDestinationAddress(), packet.GetSourceAddress(),
+ properties_.GetClockOffset()));
+}
+
+void LinkLayerController::IncomingReadClockOffsetResponse(
+ model::packets::LinkLayerPacketView packet) {
+ auto view = model::packets::ReadClockOffsetResponseView::Create(packet);
+ ASSERT(view.IsValid());
+ Address source = packet.GetSourceAddress();
+ if (connections_.IsDeviceConnected(source)) {
+ uint16_t handle = connections_.GetHandle(packet.GetSourceAddress());
+ send_event_(bluetooth::hci::ReadClockOffsetCompleteBuilder::Create(
+ bluetooth::hci::ErrorCode::SUCCESS, handle, view.GetOffset()));
+ } else {
+ LOG_INFO("Discarding response from a disconnected device %s",
+ source.ToString().c_str());
+ }
}
void LinkLayerController::IncomingDisconnectPacket(
@@ -354,12 +476,19 @@
LOG_INFO("%s: Unknown connection @%s", __func__, peer.ToString().c_str());
return;
}
- auto packet = bluetooth::hci::EncryptionChangeBuilder::Create(
+ send_event_(bluetooth::hci::EncryptionChangeBuilder::Create(
bluetooth::hci::ErrorCode::SUCCESS, handle,
- bluetooth::hci::EncryptionEnabled::ON);
- send_event_(std::move(packet));
+ bluetooth::hci::EncryptionEnabled::ON));
+
+ uint16_t count = security_manager_.ReadKey(peer);
+ if (count == 0) {
+ LOG_ERROR("NO KEY HERE for %s", peer.ToString().c_str());
+ return;
+ }
+ auto array = security_manager_.GetKey(peer);
+ std::vector<uint8_t> key_vec{array.begin(), array.end()};
auto response = model::packets::EncryptConnectionResponseBuilder::Create(
- properties_.GetAddress(), peer, security_manager_.GetKey(peer));
+ properties_.GetAddress(), peer, key_vec);
SendLinkLayerPacket(std::move(response));
}
@@ -428,7 +557,6 @@
switch (basic_inquiry_response.GetInquiryType()) {
case (model::packets::InquiryType::STANDARD): {
- LOG_WARN("Incoming Standard Inquiry Response");
// TODO: Support multiple inquiries in the same packet.
auto inquiry_response =
model::packets::InquiryResponseView::Create(basic_inquiry_response);
@@ -447,7 +575,6 @@
} break;
case (model::packets::InquiryType::RSSI): {
- LOG_WARN("Incoming RSSI Inquiry Response");
auto inquiry_response =
model::packets::InquiryResponseWithRssiView::Create(
basic_inquiry_response);
@@ -465,7 +592,6 @@
} break;
case (model::packets::InquiryType::EXTENDED): {
- LOG_WARN("Incoming Extended Inquiry Response");
auto inquiry_response =
model::packets::ExtendedInquiryResponseView::Create(
basic_inquiry_response);
@@ -735,7 +861,8 @@
ASSERT(page.IsValid());
LOG_INFO("%s from %s", __func__, incoming.GetSourceAddress().ToString().c_str());
- if (!connections_.CreatePendingConnection(incoming.GetSourceAddress())) {
+ if (!connections_.CreatePendingConnection(
+ incoming.GetSourceAddress(), properties_.GetAuthenticationEnable())) {
// Send a response to indicate that we're busy, or drop the packet?
LOG_WARN("%s: Failed to create a pending connection for %s", __func__,
incoming.GetSourceAddress().ToString().c_str());
@@ -767,8 +894,10 @@
void LinkLayerController::IncomingPageResponsePacket(
model::packets::LinkLayerPacketView incoming) {
- LOG_INFO("%s: %s", __func__, incoming.GetSourceAddress().ToString().c_str());
- uint16_t handle = connections_.CreateConnection(incoming.GetSourceAddress());
+ Address peer = incoming.GetSourceAddress();
+ LOG_INFO("%s: %s", __func__, peer.ToString().c_str());
+ bool awaiting_authentication = connections_.AuthenticatePendingConnection();
+ uint16_t handle = connections_.CreateConnection(peer);
if (handle == acl::kReservedHandle) {
LOG_WARN("%s: No free handles", __func__);
return;
@@ -777,71 +906,11 @@
bluetooth::hci::ErrorCode::SUCCESS, handle, incoming.GetSourceAddress(),
bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED);
send_event_(std::move(packet));
-}
-void LinkLayerController::IncomingResponsePacket(
- model::packets::LinkLayerPacketView incoming) {
- auto response = model::packets::ResponseView::Create(incoming);
- ASSERT(response.IsValid());
-
- // TODO: Check to see if I'm expecting this response.
-
- hci::OpCode opcode = static_cast<hci::OpCode>(response.GetOpcode());
- auto args = response.GetPayload().begin();
- auto status = static_cast<bluetooth::hci::ErrorCode>(args.extract<uint8_t>());
-
- uint16_t handle = connections_.GetHandle(incoming.GetSourceAddress());
-
- switch (opcode) {
- case (hci::OpCode::REMOTE_NAME_REQUEST): {
- std::array<uint8_t, 248> remote_name;
- remote_name.fill(0x00);
- uint64_t len = args.extract<uint64_t>();
- if (len > 247) {
- len = 247; // one byte for NULL octet (0x00)
- }
- for (uint64_t i = 0; i < len; i++) {
- remote_name[i] = args.extract<uint8_t>();
- }
- auto packet = bluetooth::hci::RemoteNameRequestCompleteBuilder::Create(
- status, incoming.GetSourceAddress(), remote_name);
- send_event_(std::move(packet));
- } break;
- case (hci::OpCode::READ_REMOTE_SUPPORTED_FEATURES): {
- auto packet =
- bluetooth::hci::ReadRemoteSupportedFeaturesCompleteBuilder::Create(
- status, handle, args.extract<uint64_t>());
- send_event_(std::move(packet));
- } break;
- case (hci::OpCode::READ_REMOTE_EXTENDED_FEATURES): {
- if (status == bluetooth::hci::ErrorCode::SUCCESS) {
- auto packet =
- bluetooth::hci::ReadRemoteExtendedFeaturesCompleteBuilder::Create(
- status, handle, args.extract<uint8_t>(),
- args.extract<uint8_t>(), args.extract<uint64_t>());
- send_event_(std::move(packet));
- } else {
- auto packet =
- bluetooth::hci::ReadRemoteExtendedFeaturesCompleteBuilder::Create(
- status, handle, 0, 0, 0);
- send_event_(std::move(packet));
- }
- } break;
- case (hci::OpCode::READ_REMOTE_VERSION_INFORMATION): {
- auto packet =
- bluetooth::hci::ReadRemoteVersionInformationCompleteBuilder::Create(
- status, handle, args.extract<uint8_t>(), args.extract<uint16_t>(),
- args.extract<uint16_t>());
- send_event_(std::move(packet));
- LOG_INFO("Read remote version handle 0x%04x", handle);
- } break;
- case (hci::OpCode::READ_CLOCK_OFFSET): {
- auto packet = bluetooth::hci::ReadClockOffsetCompleteBuilder::Create(
- status, handle, args.extract<uint16_t>());
- send_event_(std::move(packet));
- } break;
- default:
- LOG_INFO("Unhandled response to command 0x%04x", static_cast<uint16_t>(opcode));
+ if (awaiting_authentication) {
+ ScheduleTask(milliseconds(5), [this, peer, handle]() {
+ HandleAuthenticationRequest(peer, handle);
+ });
}
}
@@ -964,25 +1033,24 @@
ASSERT(security_manager_.GetAuthenticationAddress() == peer);
// TODO: Public key exchange first?
switch (pairing_type) {
- case PairingType::AUTO_CONFIRMATION: {
- auto packet =
- bluetooth::hci::UserConfirmationRequestBuilder::Create(peer, 123456);
- send_event_(std::move(packet));
- } break;
+ case PairingType::AUTO_CONFIRMATION:
+ send_event_(
+ bluetooth::hci::UserConfirmationRequestBuilder::Create(peer, 123456));
+ break;
case PairingType::CONFIRM_Y_N:
- LOG_ALWAYS_FATAL("Unimplemented PairingType %d", static_cast<int>(pairing_type));
+ send_event_(
+ bluetooth::hci::UserConfirmationRequestBuilder::Create(peer, 123456));
break;
case PairingType::DISPLAY_PIN:
- LOG_ALWAYS_FATAL("Unimplemented PairingType %d", static_cast<int>(pairing_type));
+ send_event_(
+ bluetooth::hci::UserConfirmationRequestBuilder::Create(peer, 123456));
break;
case PairingType::DISPLAY_AND_CONFIRM:
- LOG_ALWAYS_FATAL("Unimplemented PairingType %d", static_cast<int>(pairing_type));
+ send_event_(
+ bluetooth::hci::UserConfirmationRequestBuilder::Create(peer, 123456));
break;
case PairingType::INPUT_PIN:
- LOG_ALWAYS_FATAL("Unimplemented PairingType %d", static_cast<int>(pairing_type));
- break;
- case PairingType::INVALID:
- LOG_ALWAYS_FATAL("Unimplemented PairingType %d", static_cast<int>(pairing_type));
+ send_event_(bluetooth::hci::UserPasskeyRequestBuilder::Create(peer));
break;
default:
LOG_ALWAYS_FATAL("Invalid PairingType %d", static_cast<int>(pairing_type));
@@ -999,9 +1067,8 @@
}
bluetooth::hci::ErrorCode LinkLayerController::LinkKeyRequestReply(
- const Address& peer, PacketView<true> key) {
- std::vector<uint8_t> key_vec(key.begin(), key.end());
- security_manager_.WriteKey(peer, key_vec);
+ const Address& peer, const std::array<uint8_t, 16>& key) {
+ security_manager_.WriteKey(peer, key);
security_manager_.AuthenticationRequestFinished();
ScheduleTask(milliseconds(5), [this, peer]() { AuthenticateRemoteStage2(peer); });
@@ -1033,19 +1100,18 @@
PairingType pairing_type = security_manager_.GetSimplePairingType();
if (pairing_type != PairingType::INVALID) {
- ScheduleTask(milliseconds(5), [this, peer, pairing_type]() { AuthenticateRemoteStage1(peer, pairing_type); });
- auto packet = model::packets::IoCapabilityResponseBuilder::Create(
+ ScheduleTask(milliseconds(5), [this, peer, pairing_type]() {
+ AuthenticateRemoteStage1(peer, pairing_type);
+ });
+ SendLinkLayerPacket(model::packets::IoCapabilityResponseBuilder::Create(
properties_.GetAddress(), peer, io_capability, oob_data_present_flag,
- authentication_requirements);
- SendLinkLayerPacket(std::move(packet));
-
+ authentication_requirements));
} else {
LOG_INFO("%s: Requesting remote capability", __func__);
- auto packet = model::packets::IoCapabilityRequestBuilder::Create(
+ SendLinkLayerPacket(model::packets::IoCapabilityRequestBuilder::Create(
properties_.GetAddress(), peer, io_capability, oob_data_present_flag,
- authentication_requirements);
- SendLinkLayerPacket(std::move(packet));
+ authentication_requirements));
}
return bluetooth::hci::ErrorCode::SUCCESS;
@@ -1072,12 +1138,19 @@
return bluetooth::hci::ErrorCode::AUTHENTICATION_FAILURE;
}
// TODO: Key could be calculated here.
- std::vector<uint8_t> key_vec{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+ std::array<uint8_t, 16> key_vec{1, 2, 3, 4, 5, 6, 7, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16};
security_manager_.WriteKey(peer, key_vec);
security_manager_.AuthenticationRequestFinished();
- ScheduleTask(milliseconds(5), [this, peer]() { AuthenticateRemoteStage2(peer); });
+ ScheduleTask(milliseconds(5), [this, peer, key_vec]() {
+ send_event_(bluetooth::hci::LinkKeyNotificationBuilder::Create(
+ peer, key_vec, bluetooth::hci::KeyType::AUTHENTICATED_P256));
+ });
+
+ ScheduleTask(milliseconds(15),
+ [this, peer]() { AuthenticateRemoteStage2(peer); });
return bluetooth::hci::ErrorCode::SUCCESS;
}
@@ -1163,8 +1236,15 @@
return;
}
+ uint16_t count = security_manager_.ReadKey(peer);
+ if (count == 0) {
+ LOG_ERROR("NO KEY HERE for %s", peer.ToString().c_str());
+ return;
+ }
+ auto array = security_manager_.GetKey(peer);
+ std::vector<uint8_t> key_vec{array.begin(), array.end()};
auto packet = model::packets::EncryptConnectionBuilder::Create(
- properties_.GetAddress(), peer, security_manager_.GetKey(peer));
+ properties_.GetAddress(), peer, key_vec);
SendLinkLayerPacket(std::move(packet));
}
@@ -1231,11 +1311,8 @@
return bluetooth::hci::ErrorCode::UNKNOWN_CONNECTION;
}
- LOG_INFO("%s: Reject in 200ms", __func__);
- ScheduleTask(milliseconds(200), [this, addr, reason]() {
- LOG_INFO("%s: Reject", __func__);
- RejectSlaveConnection(addr, reason);
- });
+ ScheduleTask(milliseconds(200),
+ [this, addr, reason]() { RejectSlaveConnection(addr, reason); });
return bluetooth::hci::ErrorCode::SUCCESS;
}
@@ -1243,10 +1320,10 @@
void LinkLayerController::RejectSlaveConnection(const Address& addr, uint8_t reason) {
auto to_send = model::packets::PageRejectBuilder::Create(
properties_.GetAddress(), addr, reason);
- LOG_INFO("%s sending page reject to %s", __func__, addr.ToString().c_str());
+ LOG_INFO("%s sending page reject to %s (reason 0x%02hhx)", __func__,
+ addr.ToString().c_str(), reason);
SendLinkLayerPacket(std::move(to_send));
- ASSERT(reason >= 0x0d && reason <= 0x0f);
auto packet = bluetooth::hci::ConnectionCompleteBuilder::Create(
static_cast<bluetooth::hci::ErrorCode>(reason), 0xeff, addr,
bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED);
@@ -1256,10 +1333,10 @@
bluetooth::hci::ErrorCode LinkLayerController::CreateConnection(
const Address& addr, uint16_t, uint8_t, uint16_t,
uint8_t allow_role_switch) {
- if (!connections_.CreatePendingConnection(addr)) {
+ if (!connections_.CreatePendingConnection(
+ addr, properties_.GetAuthenticationEnable() == 1)) {
return bluetooth::hci::ErrorCode::CONTROLLER_BUSY;
}
-
auto page = model::packets::PageBuilder::Create(
properties_.GetAddress(), addr, properties_.GetClassOfDevice(),
allow_role_switch);
@@ -1535,7 +1612,6 @@
void LinkLayerController::StartInquiry(milliseconds timeout) {
ScheduleTask(milliseconds(timeout), [this]() { LinkLayerController::InquiryTimeout(); });
inquiry_state_ = Inquiry::InquiryState::INQUIRY;
- LOG_INFO("InquiryState = %d ", static_cast<int>(inquiry_state_));
}
void LinkLayerController::InquiryCancel() {
@@ -1569,7 +1645,6 @@
if (duration_cast<milliseconds>(now - last_inquiry_) < milliseconds(2000)) {
return;
}
- LOG_INFO("Inquiry ");
auto packet = model::packets::InquiryBuilder::Create(
properties_.GetAddress(), Address::kEmpty, inquiry_mode_);
diff --git a/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h b/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h
index ffc9044..035ef2c 100644
--- a/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h
+++ b/vendor_libs/test_vendor_lib/model/controller/link_layer_controller.h
@@ -40,7 +40,7 @@
LinkLayerController(const DeviceProperties& properties) : properties_(properties) {}
bluetooth::hci::ErrorCode SendCommandToRemoteByAddress(
bluetooth::hci::OpCode opcode, packets::PacketView<true> args,
- const Address& remote, bool use_public_address);
+ const Address& remote);
bluetooth::hci::ErrorCode SendCommandToRemoteByHandle(
bluetooth::hci::OpCode opcode, packets::PacketView<true> args,
uint16_t handle);
@@ -51,8 +51,8 @@
void StartSimplePairing(const Address& address);
void AuthenticateRemoteStage1(const Address& address, PairingType pairing_type);
void AuthenticateRemoteStage2(const Address& address);
- bluetooth::hci::ErrorCode LinkKeyRequestReply(const Address& address,
- packets::PacketView<true> key);
+ bluetooth::hci::ErrorCode LinkKeyRequestReply(
+ const Address& address, const std::array<uint8_t, 16>& key);
bluetooth::hci::ErrorCode LinkKeyRequestNegativeReply(const Address& address);
bluetooth::hci::ErrorCode IoCapabilityRequestReply(
const Address& peer, uint8_t io_capability, uint8_t oob_data_present_flag,
@@ -106,7 +106,7 @@
// Set the callbacks for sending packets to the HCI.
void RegisterEventChannel(
const std::function<void(
- std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>& send_event_);
+ std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>& send_event);
void RegisterAclChannel(const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_acl);
@@ -261,7 +261,6 @@
std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet);
void IncomingAclPacket(model::packets::LinkLayerPacketView packet);
void IncomingAclAckPacket(model::packets::LinkLayerPacketView packet);
- void IncomingCommandPacket(model::packets::LinkLayerPacketView packet);
void IncomingCreateConnectionPacket(
model::packets::LinkLayerPacketView packet);
void IncomingDisconnectPacket(model::packets::LinkLayerPacketView packet);
@@ -287,7 +286,27 @@
void IncomingPagePacket(model::packets::LinkLayerPacketView packet);
void IncomingPageRejectPacket(model::packets::LinkLayerPacketView packet);
void IncomingPageResponsePacket(model::packets::LinkLayerPacketView packet);
- void IncomingResponsePacket(model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteLmpFeatures(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteLmpFeaturesResponse(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteSupportedFeatures(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteSupportedFeaturesResponse(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteExtendedFeatures(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteExtendedFeaturesResponse(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteVersion(model::packets::LinkLayerPacketView packet);
+ void IncomingReadRemoteVersionResponse(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingReadClockOffset(model::packets::LinkLayerPacketView packet);
+ void IncomingReadClockOffsetResponse(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingRemoteNameRequest(model::packets::LinkLayerPacketView packet);
+ void IncomingRemoteNameRequestResponse(
+ model::packets::LinkLayerPacketView packet);
private:
const DeviceProperties& properties_;
diff --git a/vendor_libs/test_vendor_lib/model/controller/security_manager.cc b/vendor_libs/test_vendor_lib/model/controller/security_manager.cc
index bd3072c..38b9e64 100644
--- a/vendor_libs/test_vendor_lib/model/controller/security_manager.cc
+++ b/vendor_libs/test_vendor_lib/model/controller/security_manager.cc
@@ -44,7 +44,8 @@
return key_store_.count(addr.ToString());
}
-uint16_t SecurityManager::WriteKey(const Address& addr, const std::vector<uint8_t>& key) {
+uint16_t SecurityManager::WriteKey(const Address& addr,
+ const std::array<uint8_t, 16>& key) {
if (key_store_.size() >= max_keys_) {
return 0;
}
@@ -52,7 +53,8 @@
return 1;
}
-const std::vector<uint8_t>& SecurityManager::GetKey(const Address& addr) const {
+const std::array<uint8_t, 16>& SecurityManager::GetKey(
+ const Address& addr) const {
ASSERT_LOG(ReadKey(addr), "No such key");
return key_store_.at(addr.ToString());
}
@@ -130,7 +132,53 @@
if (!(peer_requires_mitm || host_requires_mitm)) {
return PairingType::AUTO_CONFIRMATION;
}
- return PairingType::INVALID;
+ LOG_INFO("%s: host does%s require peer does%s require MITM",
+ peer_address_.ToString().c_str(), host_requires_mitm ? "" : "n't",
+ peer_requires_mitm ? "" : "n't");
+ switch (peer_io_capability_) {
+ case IoCapabilityType::DISPLAY_ONLY:
+ switch (host_io_capability_) {
+ case IoCapabilityType::DISPLAY_ONLY:
+ case IoCapabilityType::DISPLAY_YES_NO:
+ return PairingType::AUTO_CONFIRMATION;
+ case IoCapabilityType::KEYBOARD_ONLY:
+ return PairingType::INPUT_PIN;
+ case IoCapabilityType::NO_INPUT_NO_OUTPUT:
+ return PairingType::AUTO_CONFIRMATION;
+ default:
+ return PairingType::INVALID;
+ }
+ case IoCapabilityType::DISPLAY_YES_NO:
+ switch (host_io_capability_) {
+ case IoCapabilityType::DISPLAY_ONLY:
+ return PairingType::AUTO_CONFIRMATION;
+ case IoCapabilityType::DISPLAY_YES_NO:
+ return PairingType::DISPLAY_AND_CONFIRM;
+ case IoCapabilityType::KEYBOARD_ONLY:
+ return PairingType::DISPLAY_PIN;
+ case IoCapabilityType::NO_INPUT_NO_OUTPUT:
+ return PairingType::AUTO_CONFIRMATION;
+ default:
+ return PairingType::INVALID;
+ }
+ case IoCapabilityType::KEYBOARD_ONLY:
+ switch (host_io_capability_) {
+ case IoCapabilityType::DISPLAY_ONLY:
+ return PairingType::DISPLAY_PIN;
+ case IoCapabilityType::DISPLAY_YES_NO:
+ return PairingType::DISPLAY_PIN;
+ case IoCapabilityType::KEYBOARD_ONLY:
+ return PairingType::INPUT_PIN;
+ case IoCapabilityType::NO_INPUT_NO_OUTPUT:
+ return PairingType::AUTO_CONFIRMATION;
+ default:
+ return PairingType::INVALID;
+ }
+ case IoCapabilityType::NO_INPUT_NO_OUTPUT:
+ return PairingType::AUTO_CONFIRMATION;
+ default:
+ return PairingType::INVALID;
+ }
}
} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/model/controller/security_manager.h b/vendor_libs/test_vendor_lib/model/controller/security_manager.h
index 8d566ea..e77f1d1 100644
--- a/vendor_libs/test_vendor_lib/model/controller/security_manager.h
+++ b/vendor_libs/test_vendor_lib/model/controller/security_manager.h
@@ -16,10 +16,10 @@
#pragma once
+#include <array>
#include <cstdint>
#include <string>
#include <unordered_map>
-#include <vector>
#include "hci/address.h"
@@ -64,12 +64,10 @@
uint16_t DeleteKey(const Address& addr);
uint16_t ReadAllKeys() const;
uint16_t ReadKey(const Address& addr) const;
- uint16_t WriteKey(const Address& addr, const std::vector<uint8_t>& key);
- uint16_t ReadCapacity() const {
- return max_keys_;
- };
+ uint16_t WriteKey(const Address& addr, const std::array<uint8_t, 16>& key);
+ uint16_t ReadCapacity() const { return max_keys_; };
- const std::vector<uint8_t>& GetKey(const Address& addr) const;
+ const std::array<uint8_t, 16>& GetKey(const Address& addr) const;
void AuthenticationRequest(const Address& addr, uint16_t handle);
void AuthenticationRequestFinished();
@@ -89,16 +87,16 @@
private:
uint16_t max_keys_;
- std::unordered_map<std::string, std::vector<uint8_t>> key_store_;
+ std::unordered_map<std::string, std::array<uint8_t, 16>> key_store_;
bool peer_capabilities_valid_{false};
IoCapabilityType peer_io_capability_;
- bool peer_oob_present_flag_;
+ bool peer_oob_present_flag_{false};
AuthenticationType peer_authentication_requirements_;
bool host_capabilities_valid_{false};
IoCapabilityType host_io_capability_;
- bool host_oob_present_flag_;
+ bool host_oob_present_flag_{false};
AuthenticationType host_authentication_requirements_;
bool authenticating_{false};
diff --git a/vendor_libs/test_vendor_lib/model/devices/device_properties.h b/vendor_libs/test_vendor_lib/model/devices/device_properties.h
index b9d03ba..2cbd4b0 100644
--- a/vendor_libs/test_vendor_lib/model/devices/device_properties.h
+++ b/vendor_libs/test_vendor_lib/model/devices/device_properties.h
@@ -16,6 +16,7 @@
#pragma once
+#include <array>
#include <cstdint>
#include <string>
#include <vector>
@@ -145,12 +146,13 @@
}
void SetName(const std::vector<uint8_t>& name) {
- name_ = name;
+ name_.fill(0);
+ for (size_t i = 0; i < 248 && i < name.size(); i++) {
+ name_[i] = name[i];
+ }
}
- const std::vector<uint8_t>& GetName() const {
- return name_;
- }
+ const std::array<uint8_t, 248>& GetName() const { return name_; }
void SetExtendedInquiryData(const std::vector<uint8_t>& eid) {
extended_inquiry_data_ = eid;
@@ -315,7 +317,7 @@
std::vector<uint64_t> extended_features_{{0x875b3fd8fe8ffeff, 0x0f}};
ClassOfDevice class_of_device_{{0, 0, 0}};
std::vector<uint8_t> extended_inquiry_data_;
- std::vector<uint8_t> name_;
+ std::array<uint8_t, 248> name_;
Address address_;
uint8_t page_scan_repetition_mode_;
uint16_t clock_offset_;
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl b/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl
index 0c27d97..2d601cd 100644
--- a/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl
+++ b/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl
@@ -227,8 +227,7 @@
}
packet RemoteNameRequestResponse : LinkLayerPacket (type = REMOTE_NAME_REQUEST_RESPONSE) {
- _size_(name) : 8,
- name : 8[],
+ name : 8[248],
}
packet ScoPacket : LinkLayerPacket (type = SCO) {
diff --git a/vendor_libs/test_vendor_lib/test/security_manager_unittest.cc b/vendor_libs/test_vendor_lib/test/security_manager_unittest.cc
index 13aab3c..9c19c4f 100644
--- a/vendor_libs/test_vendor_lib/test/security_manager_unittest.cc
+++ b/vendor_libs/test_vendor_lib/test/security_manager_unittest.cc
@@ -16,22 +16,20 @@
*
******************************************************************************/
-#include <gtest/gtest.h>
-#include <string>
-#include <vector>
-using std::vector;
-
#include "model/controller/security_manager.h"
+#include <gtest/gtest.h>
+#include <array>
+#include <string>
+
namespace {
const std::string kTestAddr1 = "12:34:56:78:9a:bc";
const std::string kTestAddr2 = "cb:a9:87:65:43:21";
const std::string kTestAddr3 = "cb:a9:56:78:9a:bc";
const std::string kTestAddr4 = "12:34:56:78:9a:bc";
-const vector<uint8_t> kZeros_octets = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
-const vector<uint8_t> kTestAddr1_octets = {0xbc, 0x9a, 0x78, 0x56, 0x34, 0x12};
-const vector<uint8_t> kTestKey = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
- 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10};
+const std::array<uint8_t, 16> kTestKey = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
+ 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c,
+ 0x0d, 0x0e, 0x0f, 0x10};
} // namespace
namespace test_vendor_lib {