RootCanal: Upgrade the LinkLayer in RootCanal to PDL
Bug: 140384404
Test: run_cert.sh
Change-Id: I32f250c60cfc7aa32e4ccfdbbd408e1ee4e0a674
diff --git a/test/rootcanal/Android.bp b/test/rootcanal/Android.bp
index 206f363..3a1871b 100644
--- a/test/rootcanal/Android.bp
+++ b/test/rootcanal/Android.bp
@@ -39,6 +39,9 @@
"-Werror",
"-DHAS_NO_BDROID_BUILDCFG",
],
+ generated_headers: [
+ "RootCanalGeneratedPackets_h",
+ ],
static_libs: [
"android.hardware.bluetooth-async",
"android.hardware.bluetooth-hci",
@@ -79,6 +82,9 @@
"-Werror",
"-DHAS_NO_BDROID_BUILDCFG",
],
+ generated_headers: [
+ "RootCanalGeneratedPackets_h",
+ ],
static_libs: [
"android.hardware.bluetooth-async",
"android.hardware.bluetooth-hci",
diff --git a/types/class_of_device.h b/types/class_of_device.h
index 8c2ab37..4c37ebf 100644
--- a/types/class_of_device.h
+++ b/types/class_of_device.h
@@ -20,6 +20,9 @@
#include <string>
+namespace bluetooth {
+namespace types {
+
/** Bluetooth Class of Device */
class ClassOfDevice final {
public:
@@ -52,3 +55,8 @@
os << c.ToString();
return os;
}
+
+} // namespace types
+} // namespace bluetooth
+
+using ::bluetooth::types::ClassOfDevice; // TODO, remove
\ No newline at end of file
diff --git a/vendor_libs/test_vendor_lib/Android.bp b/vendor_libs/test_vendor_lib/Android.bp
index d4d554d..d53f201 100644
--- a/vendor_libs/test_vendor_lib/Android.bp
+++ b/vendor_libs/test_vendor_lib/Android.bp
@@ -35,6 +35,7 @@
"model/setup/test_channel_transport.cc",
"model/setup/test_command_handler.cc",
"model/setup/test_model.cc",
+ ":BluetoothPacketSources",
],
cflags: [
"-fvisibility=hidden",
@@ -47,6 +48,9 @@
"include",
".",
],
+ generated_headers: [
+ "RootCanalGeneratedPackets_h",
+ ],
include_dirs: [
"system/bt",
"system/bt/gd",
@@ -120,6 +124,9 @@
"system/bt",
"system/bt/gd",
],
+ generated_headers: [
+ "RootCanalGeneratedPackets_h",
+ ],
shared_libs: [
"liblog",
],
@@ -128,3 +135,17 @@
"libbt-rootcanal",
],
}
+
+genrule {
+ name: "RootCanalGeneratedPackets_h",
+ tools: [
+ "bluetooth_packetgen",
+ ],
+ cmd: "$(location bluetooth_packetgen) --root_namespace=model --include=system/bt/vendor_libs/test_vendor_lib --out=$(genDir) $(in)",
+ srcs: [
+ "packets/link_layer_packets.pdl",
+ ],
+ out: [
+ "packets/link_layer_packets.h",
+ ],
+}
diff --git a/vendor_libs/test_vendor_lib/include/link.h b/vendor_libs/test_vendor_lib/include/link.h
deleted file mode 100644
index 798bba7..0000000
--- a/vendor_libs/test_vendor_lib/include/link.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-namespace test_vendor_lib {
-class Link {
- public:
- static constexpr size_t kSizeBytes = sizeof(uint32_t);
- static constexpr size_t kTypeBytes = sizeof(uint8_t);
-
- enum class PacketType : uint8_t {
- UNKNOWN,
- ACL,
- COMMAND,
- DISCONNECT,
- ENCRYPT_CONNECTION,
- ENCRYPT_CONNECTION_RESPONSE,
- EVENT,
- INQUIRY,
- INQUIRY_RESPONSE,
- IO_CAPABILITY_REQUEST,
- IO_CAPABILITY_RESPONSE,
- IO_CAPABILITY_NEGATIVE_RESPONSE,
- LE_ADVERTISEMENT,
- LE_CONNECT,
- LE_CONNECT_COMPLETE,
- LE_SCAN,
- LE_SCAN_RESPONSE,
- PAGE,
- PAGE_RESPONSE,
- PAGE_REJECT,
- RESPONSE,
- SCO,
- };
-};
-} // namespace test_vendor_lib
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 6e9e775..2e5c20c 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
@@ -67,7 +67,8 @@
return "Simulated Bluetooth Controller";
}
-void DualModeController::IncomingPacket(packets::LinkLayerPacketView incoming) {
+void DualModeController::IncomingPacket(
+ model::packets::LinkLayerPacketView incoming) {
link_layer_controller_.IncomingPacket(incoming);
}
@@ -111,7 +112,8 @@
properties_.SetAddress(public_address);
link_layer_controller_.RegisterRemoteChannel(
- [this](std::shared_ptr<packets::LinkLayerPacketBuilder> packet, Phy::Type phy_type) {
+ [this](std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
+ Phy::Type phy_type) {
DualModeController::SendLinkLayerPacket(packet, phy_type);
});
diff --git a/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.h b/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.h
index cd3dcfc..af52ecb 100644
--- a/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.h
+++ b/vendor_libs/test_vendor_lib/model/controller/dual_mode_controller.h
@@ -60,7 +60,8 @@
virtual std::string GetTypeString() const override;
- virtual void IncomingPacket(packets::LinkLayerPacketView incoming) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView incoming) override;
virtual void TimerTick() override;
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 93b06dd..0feba95 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
@@ -22,20 +22,9 @@
#include "packets/hci/command_packet_view.h"
#include "packets/hci/event_packet_builder.h"
#include "packets/hci/sco_packet_builder.h"
-#include "packets/link_layer/command_builder.h"
-#include "packets/link_layer/command_view.h"
-#include "packets/link_layer/disconnect_view.h"
-#include "packets/link_layer/encrypt_connection_view.h"
-#include "packets/link_layer/inquiry_response_view.h"
-#include "packets/link_layer/inquiry_view.h"
-#include "packets/link_layer/io_capability_view.h"
-#include "packets/link_layer/le_advertisement_view.h"
-#include "packets/link_layer/le_connect_complete_view.h"
-#include "packets/link_layer/le_connect_view.h"
-#include "packets/link_layer/page_reject_view.h"
-#include "packets/link_layer/page_response_view.h"
-#include "packets/link_layer/page_view.h"
-#include "packets/link_layer/response_view.h"
+
+#include "packet/raw_builder.h"
+#include "packets/link_layer_packets.h"
using std::vector;
using namespace std::chrono;
@@ -53,25 +42,42 @@
return -(rssi);
}
-void LinkLayerController::SendLeLinkLayerPacket(std::shared_ptr<LinkLayerPacketBuilder> packet) {
- ScheduleTask(milliseconds(50), [this, packet]() { send_to_remote_(packet, Phy::Type::LOW_ENERGY); });
+void LinkLayerController::SendLeLinkLayerPacket(
+ std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet) {
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder> shared_packet =
+ std::move(packet);
+ ScheduleTask(milliseconds(50), [this, shared_packet]() {
+ send_to_remote_(std::move(shared_packet), Phy::Type::LOW_ENERGY);
+ });
}
-void LinkLayerController::SendLinkLayerPacket(std::shared_ptr<LinkLayerPacketBuilder> packet) {
- ScheduleTask(milliseconds(50), [this, packet]() { send_to_remote_(packet, Phy::Type::BR_EDR); });
+void LinkLayerController::SendLinkLayerPacket(
+ std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet) {
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder> shared_packet =
+ std::move(packet);
+ ScheduleTask(milliseconds(50), [this, shared_packet]() {
+ send_to_remote_(std::move(shared_packet), Phy::Type::BR_EDR);
+ });
}
hci::Status LinkLayerController::SendCommandToRemoteByAddress(hci::OpCode opcode, PacketView<true> args,
const Address& remote, bool use_public_address) {
- std::shared_ptr<LinkLayerPacketBuilder> command;
Address local_address;
if (use_public_address) {
local_address = properties_.GetAddress();
} else {
local_address = properties_.GetLeAddress();
}
- command = LinkLayerPacketBuilder::WrapCommand(CommandBuilder::Create(static_cast<uint16_t>(opcode), args),
- local_address, remote);
+
+ 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 hci::Status::SUCCESS;
}
@@ -92,15 +98,11 @@
return hci::Status::UNKNOWN_CONNECTION;
}
- std::unique_ptr<ViewForwarderBuilder> acl_builder = ViewForwarderBuilder::Create(acl_packet);
-
Address my_address = properties_.GetAddress();
Address destination = connections_.GetAddress(handle);
if (connections_.GetOwnAddressType(handle) != 0) { // If it's not public, it must be LE
my_address = properties_.GetLeAddress();
}
- std::shared_ptr<LinkLayerPacketBuilder> acl =
- LinkLayerPacketBuilder::WrapAcl(std::move(acl_builder), my_address, destination);
LOG_INFO("%s(%s): handle 0x%x size %d", __func__, properties_.GetAddress().ToString().c_str(), handle,
static_cast<int>(acl_packet.size()));
@@ -108,11 +110,32 @@
ScheduleTask(milliseconds(5), [this, handle]() {
send_event_(EventPacketBuilder::CreateNumberOfCompletedPacketsEvent(handle, 1)->ToVector());
});
- SendLinkLayerPacket(acl);
+
+ auto acl_payload = acl_packet.GetPayload();
+
+ std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
+ std::make_unique<bluetooth::packet::RawBuilder>();
+ std::vector<uint8_t> payload_bytes(acl_payload.begin(), acl_payload.end());
+
+ uint16_t first_two_bytes =
+ static_cast<uint16_t>(acl_packet.GetHandle()) +
+ (static_cast<uint16_t>(acl_packet.GetPacketBoundaryFlags()) << 12) +
+ (static_cast<uint16_t>(acl_packet.GetBroadcastFlags()) << 14);
+ raw_builder_ptr->AddOctets2(first_two_bytes);
+ raw_builder_ptr->AddOctets2(static_cast<uint16_t>(payload_bytes.size()));
+ raw_builder_ptr->AddOctets(payload_bytes);
+
+ auto acl = model::packets::AclPacketBuilder::Create(
+ my_address, destination, std::move(raw_builder_ptr));
+
+ SendLinkLayerPacket(std::move(acl));
return hci::Status::SUCCESS;
}
-void LinkLayerController::IncomingPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingPacket(
+ model::packets::LinkLayerPacketView incoming) {
+ ASSERT(incoming.IsValid());
+
// TODO: Resolvable private addresses?
if (incoming.GetDestinationAddress() != properties_.GetAddress() &&
incoming.GetDestinationAddress() != properties_.GetLeAddress() &&
@@ -122,70 +145,67 @@
}
switch (incoming.GetType()) {
- case Link::PacketType::ACL:
+ case model::packets::PacketType::ACL:
IncomingAclPacket(incoming);
break;
- case Link::PacketType::COMMAND:
+ case model::packets::PacketType::COMMAND:
IncomingCommandPacket(incoming);
break;
- case Link::PacketType::DISCONNECT:
+ case model::packets::PacketType::DISCONNECT:
IncomingDisconnectPacket(incoming);
break;
- case Link::PacketType::ENCRYPT_CONNECTION:
+ case model::packets::PacketType::ENCRYPT_CONNECTION:
IncomingEncryptConnection(incoming);
break;
- case Link::PacketType::ENCRYPT_CONNECTION_RESPONSE:
+ case model::packets::PacketType::ENCRYPT_CONNECTION_RESPONSE:
IncomingEncryptConnectionResponse(incoming);
break;
- case Link::PacketType::INQUIRY:
+ case model::packets::PacketType::INQUIRY:
if (inquiry_scans_enabled_) {
IncomingInquiryPacket(incoming);
}
break;
- case Link::PacketType::INQUIRY_RESPONSE:
+ case model::packets::PacketType::INQUIRY_RESPONSE:
IncomingInquiryResponsePacket(incoming);
break;
- case Link::PacketType::IO_CAPABILITY_REQUEST:
+ case model::packets::PacketType::IO_CAPABILITY_REQUEST:
IncomingIoCapabilityRequestPacket(incoming);
break;
- case Link::PacketType::IO_CAPABILITY_RESPONSE:
- IncomingIoCapabilityResponsePacket(incoming);
- break;
- case Link::PacketType::IO_CAPABILITY_NEGATIVE_RESPONSE:
+ case model::packets::PacketType::IO_CAPABILITY_NEGATIVE_RESPONSE:
IncomingIoCapabilityNegativeResponsePacket(incoming);
break;
- case Link::PacketType::LE_ADVERTISEMENT:
+ case model::packets::PacketType::LE_ADVERTISEMENT:
if (le_scan_enable_ || le_connect_) {
IncomingLeAdvertisementPacket(incoming);
}
break;
- case Link::PacketType::LE_CONNECT:
+ case model::packets::PacketType::LE_CONNECT:
IncomingLeConnectPacket(incoming);
break;
- case Link::PacketType::LE_CONNECT_COMPLETE:
+ case model::packets::PacketType::LE_CONNECT_COMPLETE:
IncomingLeConnectCompletePacket(incoming);
break;
- case Link::PacketType::LE_SCAN:
+ case model::packets::PacketType::LE_SCAN:
// TODO: Check Advertising flags and see if we are scannable.
IncomingLeScanPacket(incoming);
break;
- case Link::PacketType::LE_SCAN_RESPONSE:
+ case model::packets::PacketType::LE_SCAN_RESPONSE:
if (le_scan_enable_ && le_scan_type_ == 1) {
IncomingLeScanResponsePacket(incoming);
}
break;
- case Link::PacketType::PAGE:
+ case model::packets::PacketType::PAGE:
if (page_scans_enabled_) {
IncomingPagePacket(incoming);
}
break;
- case Link::PacketType::PAGE_REJECT:
- IncomingPageRejectPacket(incoming);
- break;
- case Link::PacketType::PAGE_RESPONSE:
+ case model::packets::PacketType::PAGE_RESPONSE:
IncomingPageResponsePacket(incoming);
break;
- case Link::PacketType::RESPONSE:
+ case model::packets::PacketType::PAGE_REJECT:
+ IncomingPageRejectPacket(incoming);
+ break;
+ case model::packets::PacketType::RESPONSE:
IncomingResponsePacket(incoming);
break;
default:
@@ -193,26 +213,40 @@
}
}
-void LinkLayerController::IncomingAclPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingAclPacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_INFO("Acl Packet %s -> %s", incoming.GetSourceAddress().ToString().c_str(),
incoming.GetDestinationAddress().ToString().c_str());
- AclPacketView acl_view = AclPacketView::Create(incoming.GetPayload());
+
+ auto acl = model::packets::AclPacketView::Create(incoming);
+ ASSERT(acl.IsValid());
+ auto payload = acl.GetPayload();
+ std::shared_ptr<std::vector<uint8_t>> payload_bytes =
+ std::make_shared<std::vector<uint8_t>>(payload.begin(), payload.end());
+
+ AclPacketView acl_view = AclPacketView::Create(payload_bytes);
LOG_INFO("%s: remote handle 0x%x size %d", __func__, acl_view.GetHandle(), static_cast<int>(acl_view.size()));
uint16_t local_handle = connections_.GetHandle(incoming.GetSourceAddress());
LOG_INFO("%s: local handle 0x%x", __func__, local_handle);
acl::PacketBoundaryFlagsType boundary_flags = acl_view.GetPacketBoundaryFlags();
acl::BroadcastFlagsType broadcast_flags = acl_view.GetBroadcastFlags();
- std::unique_ptr<ViewForwarderBuilder> builder = ViewForwarderBuilder::Create(acl_view.GetPayload());
+ std::unique_ptr<RawBuilder> builder = std::make_unique<RawBuilder>();
+ std::vector<uint8_t> raw_data(acl_view.GetPayload().begin(),
+ acl_view.GetPayload().end());
+ builder->AddOctets(raw_data);
send_acl_(AclPacketBuilder::Create(local_handle, boundary_flags, broadcast_flags, std::move(builder))->ToVector());
}
-void LinkLayerController::IncomingCommandPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingCommandPacket(
+ model::packets::LinkLayerPacketView incoming) {
// TODO: Check the destination address to see if this packet is for me.
- CommandView command = CommandView::GetCommand(incoming);
- hci::OpCode opcode = static_cast<hci::OpCode>(command.GetOpcode());
- auto args = command.GetData();
+ auto command = model::packets::CommandView::Create(incoming);
+ ASSERT(command.IsValid());
+
+ auto args = command.GetPayload().begin();
std::vector<uint64_t> response_data;
+ hci::OpCode opcode = static_cast<hci::OpCode>(args.extract<uint16_t>());
switch (opcode) {
case (hci::OpCode::REMOTE_NAME_REQUEST): {
@@ -268,14 +302,26 @@
LOG_INFO("Dropping unhandled command 0x%04x", static_cast<uint16_t>(opcode));
return;
}
- SendLinkLayerPacket(
- LinkLayerPacketBuilder::WrapResponse(ResponseBuilder::Create(static_cast<uint16_t>(opcode), response_data),
- properties_.GetAddress(), incoming.GetSourceAddress()));
+
+ std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
+ std::make_unique<bluetooth::packet::RawBuilder>();
+ for (uint64_t data : response_data) {
+ raw_builder_ptr->AddOctets8(data);
+ }
+
+ auto response = model::packets::ResponseBuilder::Create(
+ properties_.GetAddress(), incoming.GetSourceAddress(),
+ static_cast<uint16_t>(opcode), std::move(raw_builder_ptr));
+
+ SendLinkLayerPacket(std::move(response));
}
-void LinkLayerController::IncomingDisconnectPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingDisconnectPacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_INFO("Disconnect Packet");
- DisconnectView disconnect = DisconnectView::GetDisconnect(incoming);
+ auto disconnect = model::packets::DisconnectView::Create(incoming);
+ ASSERT(disconnect.IsValid());
+
Address peer = incoming.GetSourceAddress();
uint16_t handle = connections_.GetHandle(peer);
if (handle == acl::kReservedHandle) {
@@ -288,8 +334,10 @@
ScheduleTask(milliseconds(20), [this, handle, reason]() { DisconnectCleanup(handle, reason); });
}
-void LinkLayerController::IncomingEncryptConnection(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingEncryptConnection(
+ model::packets::LinkLayerPacketView incoming) {
LOG_INFO("%s", __func__);
+
// TODO: Check keys
Address peer = incoming.GetSourceAddress();
uint16_t handle = connections_.GetHandle(peer);
@@ -298,11 +346,13 @@
return;
}
send_event_(EventPacketBuilder::CreateEncryptionChange(hci::Status::SUCCESS, handle, 1)->ToVector());
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapEncryptConnectionResponse(
- EncryptConnectionBuilder::Create(security_manager_.GetKey(peer)), properties_.GetAddress(), peer));
+ auto response = model::packets::EncryptConnectionResponseBuilder::Create(
+ properties_.GetAddress(), peer, security_manager_.GetKey(peer));
+ SendLinkLayerPacket(std::move(response));
}
-void LinkLayerController::IncomingEncryptConnectionResponse(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingEncryptConnectionResponse(
+ model::packets::LinkLayerPacketView incoming) {
LOG_INFO("%s", __func__);
// TODO: Check keys
uint16_t handle = connections_.GetHandle(incoming.GetSourceAddress());
@@ -313,86 +363,119 @@
send_event_(EventPacketBuilder::CreateEncryptionChange(hci::Status::SUCCESS, handle, 1)->ToVector());
}
-void LinkLayerController::IncomingInquiryPacket(LinkLayerPacketView incoming) {
- InquiryView inquiry = InquiryView::GetInquiry(incoming);
- std::unique_ptr<InquiryResponseBuilder> inquiry_response;
- switch (inquiry.GetType()) {
- case (Inquiry::InquiryType::STANDARD):
- inquiry_response = InquiryResponseBuilder::CreateStandard(
- properties_.GetPageScanRepetitionMode(), properties_.GetClassOfDevice(), properties_.GetClockOffset());
- break;
+void LinkLayerController::IncomingInquiryPacket(
+ model::packets::LinkLayerPacketView incoming) {
+ auto inquiry = model::packets::InquiryView::Create(incoming);
+ ASSERT(inquiry.IsValid());
- case (Inquiry::InquiryType::RSSI):
- inquiry_response =
- InquiryResponseBuilder::CreateRssi(properties_.GetPageScanRepetitionMode(), properties_.GetClassOfDevice(),
- properties_.GetClockOffset(), GetRssi());
- break;
+ Address peer = incoming.GetSourceAddress();
- case (Inquiry::InquiryType::EXTENDED):
- inquiry_response = InquiryResponseBuilder::CreateExtended(
- properties_.GetPageScanRepetitionMode(), properties_.GetClassOfDevice(), properties_.GetClockOffset(),
- GetRssi(), properties_.GetExtendedInquiryData());
- break;
+ switch (inquiry.GetInquiryType()) {
+ case (model::packets::InquiryType::STANDARD): {
+ auto inquiry_response = model::packets::InquiryResponseBuilder::Create(
+ properties_.GetAddress(), peer,
+ properties_.GetPageScanRepetitionMode(),
+ properties_.GetClassOfDevice(), properties_.GetClockOffset());
+ SendLinkLayerPacket(std::move(inquiry_response));
+ } break;
+ case (model::packets::InquiryType::RSSI): {
+ auto inquiry_response =
+ model::packets::InquiryResponseWithRssiBuilder::Create(
+ properties_.GetAddress(), peer,
+ properties_.GetPageScanRepetitionMode(),
+ properties_.GetClassOfDevice(), properties_.GetClockOffset(),
+ GetRssi());
+ SendLinkLayerPacket(std::move(inquiry_response));
+ } break;
+ case (model::packets::InquiryType::EXTENDED): {
+ auto inquiry_response =
+ model::packets::ExtendedInquiryResponseBuilder::Create(
+ properties_.GetAddress(), peer,
+ properties_.GetPageScanRepetitionMode(),
+ properties_.GetClassOfDevice(), properties_.GetClockOffset(),
+ GetRssi(), properties_.GetExtendedInquiryData());
+ SendLinkLayerPacket(std::move(inquiry_response));
+
+ } break;
default:
LOG_WARN("Unhandled Incoming Inquiry of type %d", static_cast<int>(inquiry.GetType()));
return;
}
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapInquiryResponse(std::move(inquiry_response), properties_.GetAddress(),
- incoming.GetSourceAddress()));
- // TODO: Send an Inquriy Response Notification Event 7.7.74
+ // TODO: Send an Inquiry Response Notification Event 7.7.74
}
-void LinkLayerController::IncomingInquiryResponsePacket(LinkLayerPacketView incoming) {
- InquiryResponseView inquiry_response = InquiryResponseView::GetInquiryResponse(incoming);
+void LinkLayerController::IncomingInquiryResponsePacket(
+ model::packets::LinkLayerPacketView incoming) {
+ auto basic_inquiry_response =
+ model::packets::BasicInquiryResponseView::Create(incoming);
+ ASSERT(basic_inquiry_response.IsValid());
std::vector<uint8_t> eir;
- switch (inquiry_response.GetType()) {
- case (Inquiry::InquiryType::STANDARD): {
+ switch (basic_inquiry_response.GetInquiryType()) {
+ case (model::packets::InquiryType::STANDARD): {
LOG_WARN("Incoming Standard Inquiry Response");
// TODO: Support multiple inquiries in the same packet.
- std::unique_ptr<EventPacketBuilder> inquiry_result = EventPacketBuilder::CreateInquiryResultEvent();
- bool result_added =
- inquiry_result->AddInquiryResult(incoming.GetSourceAddress(), inquiry_response.GetPageScanRepetitionMode(),
- inquiry_response.GetClassOfDevice(), inquiry_response.GetClockOffset());
- ASSERT(result_added);
+ auto inquiry_response =
+ model::packets::InquiryResponseView::Create(basic_inquiry_response);
+ ASSERT(inquiry_response.IsValid());
+ std::unique_ptr<EventPacketBuilder> inquiry_result =
+ EventPacketBuilder::CreateInquiryResultEvent();
+ bool result_added = inquiry_result->AddInquiryResult(
+ inquiry_response.GetSourceAddress(),
+ inquiry_response.GetPageScanRepetitionMode(),
+ inquiry_response.GetClassOfDevice(),
+ inquiry_response.GetClockOffset());
+ CHECK(result_added);
send_event_(inquiry_result->ToVector());
} break;
- case (Inquiry::InquiryType::RSSI):
+ case (model::packets::InquiryType::RSSI): {
LOG_WARN("Incoming RSSI Inquiry Response");
+ auto inquiry_response =
+ model::packets::InquiryResponseWithRssiView::Create(
+ basic_inquiry_response);
+ ASSERT(inquiry_response.IsValid());
send_event_(EventPacketBuilder::CreateExtendedInquiryResultEvent(
- incoming.GetSourceAddress(), inquiry_response.GetPageScanRepetitionMode(),
- inquiry_response.GetClassOfDevice(), inquiry_response.GetClockOffset(), GetRssi(), eir)
+ incoming.GetSourceAddress(),
+ inquiry_response.GetPageScanRepetitionMode(),
+ inquiry_response.GetClassOfDevice(),
+ inquiry_response.GetClockOffset(),
+ inquiry_response.GetRssi(), eir)
->ToVector());
- break;
+ } break;
- case (Inquiry::InquiryType::EXTENDED): {
+ case (model::packets::InquiryType::EXTENDED): {
LOG_WARN("Incoming Extended Inquiry Response");
- auto eir_itr = inquiry_response.GetExtendedData();
- size_t eir_bytes = eir_itr.NumBytesRemaining();
- LOG_WARN("Payload size = %d", static_cast<int>(eir_bytes));
- for (size_t i = 0; i < eir_bytes; i++) {
- eir.push_back(eir_itr.extract<uint8_t>());
- }
+ auto inquiry_response =
+ model::packets::ExtendedInquiryResponseView::Create(
+ basic_inquiry_response);
+ ASSERT(inquiry_response.IsValid());
+ eir = inquiry_response.GetExtendedData();
send_event_(EventPacketBuilder::CreateExtendedInquiryResultEvent(
- incoming.GetSourceAddress(), inquiry_response.GetPageScanRepetitionMode(),
- inquiry_response.GetClassOfDevice(), inquiry_response.GetClockOffset(), GetRssi(), eir)
+ incoming.GetSourceAddress(),
+ inquiry_response.GetPageScanRepetitionMode(),
+ inquiry_response.GetClassOfDevice(),
+ inquiry_response.GetClockOffset(), GetRssi(), eir)
->ToVector());
} break;
default:
- LOG_WARN("Unhandled Incoming Inquiry Response of type %d", static_cast<int>(inquiry_response.GetType()));
+ LOG_WARN("Unhandled Incoming Inquiry Response of type %d",
+ static_cast<int>(basic_inquiry_response.GetInquiryType()));
}
}
-void LinkLayerController::IncomingIoCapabilityRequestPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingIoCapabilityRequestPacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_DEBUG("%s", __func__);
if (!simple_pairing_mode_enabled_) {
LOG_WARN("%s: Only simple pairing mode is implemented", __func__);
return;
}
- auto request = IoCapabilityView::GetIoCapability(incoming);
- Address peer = incoming.GetSourceAddress();
+ auto request = model::packets::IoCapabilityRequestView::Create(incoming);
+ ASSERT(request.IsValid());
+
+ Address peer = incoming.GetSourceAddress();
uint8_t io_capability = request.GetIoCapability();
uint8_t oob_data_present = request.GetOobDataPresent();
uint8_t authentication_requirements = request.GetAuthenticationRequirements();
@@ -414,29 +497,38 @@
StartSimplePairing(peer);
}
-void LinkLayerController::IncomingIoCapabilityResponsePacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingIoCapabilityResponsePacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_DEBUG("%s", __func__);
- auto response = IoCapabilityView::GetIoCapability(incoming);
+
+ auto response = model::packets::IoCapabilityResponseView::Create(incoming);
+ ASSERT(response.IsValid());
+
Address peer = incoming.GetSourceAddress();
uint8_t io_capability = response.GetIoCapability();
uint8_t oob_data_present = response.GetOobDataPresent();
uint8_t authentication_requirements = response.GetAuthenticationRequirements();
- security_manager_.SetPeerIoCapability(peer, io_capability, oob_data_present, authentication_requirements);
+ security_manager_.SetPeerIoCapability(peer, io_capability, oob_data_present,
+ authentication_requirements);
- send_event_(EventPacketBuilder::CreateIoCapabilityResponseEvent(peer, io_capability, oob_data_present,
- authentication_requirements)
- ->ToVector());
+ send_event_(
+ EventPacketBuilder::CreateIoCapabilityResponseEvent(
+ peer, io_capability, oob_data_present, authentication_requirements)
+ ->ToVector());
PairingType pairing_type = security_manager_.GetSimplePairingType();
if (pairing_type != PairingType::INVALID) {
- ScheduleTask(milliseconds(5), [this, peer, pairing_type]() { AuthenticateRemoteStage1(peer, pairing_type); });
+ ScheduleTask(milliseconds(5), [this, peer, pairing_type]() {
+ AuthenticateRemoteStage1(peer, pairing_type);
+ });
} else {
LOG_INFO("%s: Security Manager returned INVALID", __func__);
}
}
-void LinkLayerController::IncomingIoCapabilityNegativeResponsePacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingIoCapabilityNegativeResponsePacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_DEBUG("%s", __func__);
Address peer = incoming.GetSourceAddress();
@@ -445,21 +537,21 @@
security_manager_.InvalidateIoCapabilities();
}
-void LinkLayerController::IncomingLeAdvertisementPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingLeAdvertisementPacket(
+ model::packets::LinkLayerPacketView incoming) {
// TODO: Handle multiple advertisements per packet.
Address address = incoming.GetSourceAddress();
- LeAdvertisementView advertisement = LeAdvertisementView::GetLeAdvertisementView(incoming);
- LeAdvertisement::AdvertisementType adv_type = advertisement.GetAdvertisementType();
- LeAdvertisement::AddressType address_type = advertisement.GetAddressType();
+ auto advertisement = model::packets::LeAdvertisementView::Create(incoming);
+ ASSERT(advertisement.IsValid());
+ auto adv_type = static_cast<LeAdvertisement::AdvertisementType>(
+ advertisement.GetAdvertisementType());
+ auto address_type =
+ static_cast<LeAdvertisement::AddressType>(advertisement.GetAddressType());
if (le_scan_enable_) {
- vector<uint8_t> ad;
- auto itr = advertisement.GetData();
- size_t ad_size = itr.NumBytesRemaining();
- for (size_t i = 0; i < ad_size; i++) {
- ad.push_back(itr.extract<uint8_t>());
- }
+ vector<uint8_t> ad = advertisement.GetData();
+
std::unique_ptr<EventPacketBuilder> le_adverts = EventPacketBuilder::CreateLeAdvertisingReportEvent();
if (!le_adverts->AddLeAdvertisingReport(adv_type, address_type, address, ad, GetRssi())) {
@@ -471,9 +563,9 @@
// Active scanning
if (le_scan_enable_ && le_scan_type_ == 1) {
- std::shared_ptr<LinkLayerPacketBuilder> to_send =
- LinkLayerPacketBuilder::WrapLeScan(properties_.GetLeAddress(), address);
- SendLeLinkLayerPacket(to_send);
+ auto to_send = model::packets::LeScanBuilder::Create(
+ properties_.GetLeAddress(), address);
+ SendLeLinkLayerPacket(std::move(to_send));
}
// Connect
@@ -490,11 +582,13 @@
le_connect_ = false;
le_scan_enable_ = false;
- std::shared_ptr<LinkLayerPacketBuilder> to_send = LinkLayerPacketBuilder::WrapLeConnect(
- LeConnectBuilder::Create(le_connection_interval_min_, le_connection_interval_max_, le_connection_latency_,
- le_connection_supervision_timeout_, static_cast<uint8_t>(le_address_type_)),
- properties_.GetLeAddress(), incoming.GetSourceAddress());
- SendLeLinkLayerPacket(to_send);
+ auto to_send = model::packets::LeConnectBuilder::Create(
+ properties_.GetLeAddress(), incoming.GetSourceAddress(),
+ le_connection_interval_min_, le_connection_interval_max_,
+ le_connection_latency_, le_connection_supervision_timeout_,
+ static_cast<uint8_t>(le_address_type_));
+
+ SendLeLinkLayerPacket(std::move(to_send));
}
}
@@ -514,8 +608,10 @@
->ToVector());
}
-void LinkLayerController::IncomingLeConnectPacket(LinkLayerPacketView incoming) {
- auto connect = LeConnectView::GetLeConnect(incoming);
+void LinkLayerController::IncomingLeConnectPacket(
+ model::packets::LinkLayerPacketView incoming) {
+ auto connect = model::packets::LeConnectView::Create(incoming);
+ ASSERT(connect.IsValid());
uint16_t connection_interval = (connect.GetLeConnectionIntervalMax() + connect.GetLeConnectionIntervalMin()) / 2;
if (!connections_.CreatePendingLeConnection(incoming.GetSourceAddress(),
static_cast<uint8_t>(connect.GetAddressType()))) {
@@ -527,54 +623,63 @@
static_cast<uint8_t>(properties_.GetLeAdvertisingOwnAddressType()),
static_cast<uint8_t>(hci::Role::SLAVE), connection_interval, connect.GetLeConnectionLatency(),
connect.GetLeConnectionSupervisionTimeout());
- std::shared_ptr<LinkLayerPacketBuilder> to_send = LinkLayerPacketBuilder::WrapLeConnectComplete(
- LeConnectCompleteBuilder::Create(connection_interval, connect.GetLeConnectionLatency(),
- connect.GetLeConnectionSupervisionTimeout(),
- properties_.GetLeAdvertisingOwnAddressType()),
- incoming.GetDestinationAddress(), incoming.GetSourceAddress());
- SendLeLinkLayerPacket(to_send);
+
+ auto to_send = model::packets::LeConnectCompleteBuilder::Create(
+ incoming.GetDestinationAddress(), incoming.GetSourceAddress(),
+ connection_interval, connect.GetLeConnectionLatency(),
+ connect.GetLeConnectionSupervisionTimeout(),
+ properties_.GetLeAdvertisingOwnAddressType());
+ SendLeLinkLayerPacket(std::move(to_send));
}
-void LinkLayerController::IncomingLeConnectCompletePacket(LinkLayerPacketView incoming) {
- auto complete = LeConnectCompleteView::GetLeConnectComplete(incoming);
+void LinkLayerController::IncomingLeConnectCompletePacket(
+ model::packets::LinkLayerPacketView incoming) {
+ auto complete = model::packets::LeConnectCompleteView::Create(incoming);
+ ASSERT(complete.IsValid());
HandleLeConnection(incoming.GetSourceAddress(), static_cast<uint8_t>(complete.GetAddressType()),
static_cast<uint8_t>(le_address_type_), static_cast<uint8_t>(hci::Role::MASTER),
complete.GetLeConnectionInterval(), complete.GetLeConnectionLatency(),
complete.GetLeConnectionSupervisionTimeout());
}
-void LinkLayerController::IncomingLeScanPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingLeScanPacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_INFO("LE Scan Packet");
- std::unique_ptr<LeAdvertisementBuilder> response = LeAdvertisementBuilder::Create(
- static_cast<LeAdvertisement::AddressType>(properties_.GetLeAddressType()),
- static_cast<LeAdvertisement::AdvertisementType>(properties_.GetLeAdvertisementType()),
+
+ auto to_send = model::packets::LeScanResponseBuilder::Create(
+ properties_.GetLeAddress(), incoming.GetSourceAddress(),
+ static_cast<model::packets::AddressType>(properties_.GetLeAddressType()),
+ static_cast<model::packets::AdvertisementType>(
+ properties_.GetLeAdvertisementType()),
properties_.GetLeScanResponse());
- std::shared_ptr<LinkLayerPacketBuilder> to_send = LinkLayerPacketBuilder::WrapLeScanResponse(
- std::move(response), properties_.GetLeAddress(), incoming.GetSourceAddress());
- SendLeLinkLayerPacket(to_send);
+
+ SendLeLinkLayerPacket(std::move(to_send));
}
-void LinkLayerController::IncomingLeScanResponsePacket(LinkLayerPacketView incoming) {
- LeAdvertisementView scan_response = LeAdvertisementView::GetLeAdvertisementView(incoming);
- vector<uint8_t> ad;
- auto itr = scan_response.GetData();
- size_t scan_size = itr.NumBytesRemaining();
- for (size_t i = 0; i < scan_size; i++) {
- ad.push_back(itr.extract<uint8_t>());
- }
+void LinkLayerController::IncomingLeScanResponsePacket(
+ model::packets::LinkLayerPacketView incoming) {
+ auto scan_response = model::packets::LeScanResponseView::Create(incoming);
+ ASSERT(scan_response.IsValid());
+ vector<uint8_t> ad = scan_response.GetData();
+ auto adv_type = static_cast<LeAdvertisement::AdvertisementType>(
+ scan_response.GetAdvertisementType());
+ auto address_type =
+ static_cast<LeAdvertisement::AddressType>(scan_response.GetAddressType());
std::unique_ptr<EventPacketBuilder> le_adverts = EventPacketBuilder::CreateLeAdvertisingReportEvent();
- if (!le_adverts->AddLeAdvertisingReport(scan_response.GetAdvertisementType(), scan_response.GetAddressType(),
- incoming.GetSourceAddress(), ad, GetRssi())) {
+ if (!le_adverts->AddLeAdvertisingReport(
+ adv_type, address_type, incoming.GetSourceAddress(), ad, GetRssi())) {
LOG_INFO("Couldn't add the scan response.");
} else {
send_event_(le_adverts->ToVector());
}
}
-void LinkLayerController::IncomingPagePacket(LinkLayerPacketView incoming) {
- PageView page = PageView::GetPage(incoming);
+void LinkLayerController::IncomingPagePacket(
+ model::packets::LinkLayerPacketView incoming) {
+ auto page = model::packets::PageView::Create(incoming);
+ ASSERT(page.IsValid());
LOG_INFO("%s from %s", __func__, incoming.GetSourceAddress().ToString().c_str());
if (!connections_.CreatePendingConnection(incoming.GetSourceAddress())) {
@@ -588,16 +693,19 @@
->ToVector());
}
-void LinkLayerController::IncomingPageRejectPacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingPageRejectPacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_INFO("%s: %s", __func__, incoming.GetSourceAddress().ToString().c_str());
- PageRejectView reject = PageRejectView::GetPageReject(incoming);
+ auto reject = model::packets::PageRejectView::Create(incoming);
+ ASSERT(reject.IsValid());
LOG_INFO("%s: Sending CreateConnectionComplete", __func__);
send_event_(EventPacketBuilder::CreateConnectionCompleteEvent(static_cast<hci::Status>(reject.GetReason()), 0x0eff,
incoming.GetSourceAddress(), hci::LinkType::ACL, false)
->ToVector());
}
-void LinkLayerController::IncomingPageResponsePacket(LinkLayerPacketView incoming) {
+void LinkLayerController::IncomingPageResponsePacket(
+ model::packets::LinkLayerPacketView incoming) {
LOG_INFO("%s: %s", __func__, incoming.GetSourceAddress().ToString().c_str());
uint16_t handle = connections_.CreateConnection(incoming.GetSourceAddress());
if (handle == acl::kReservedHandle) {
@@ -609,13 +717,15 @@
->ToVector());
}
-void LinkLayerController::IncomingResponsePacket(LinkLayerPacketView incoming) {
- ResponseView response = ResponseView::GetResponse(incoming);
+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.GetResponseData();
+ auto args = response.GetPayload().begin();
hci::Status status = static_cast<hci::Status>(args.extract<uint64_t>());
uint16_t handle = connections_.GetHandle(incoming.GetSourceAddress());
@@ -680,22 +790,20 @@
}
last_le_advertisement_ = now;
- LeAdvertisement::AddressType own_address_type =
- static_cast<LeAdvertisement::AddressType>(properties_.GetLeAdvertisingOwnAddressType());
- std::shared_ptr<packets::LinkLayerPacketBuilder> to_send;
- std::unique_ptr<packets::LeAdvertisementBuilder> ad;
+ auto own_address_type = static_cast<model::packets::AddressType>(
+ properties_.GetLeAdvertisingOwnAddressType());
Address advertising_address = Address::kEmpty;
- if (own_address_type == LeAdvertisement::AddressType::PUBLIC) {
+ if (own_address_type == model::packets::AddressType::PUBLIC) {
advertising_address = properties_.GetAddress();
- } else if (own_address_type == LeAdvertisement::AddressType::RANDOM) {
+ } else if (own_address_type == model::packets::AddressType::RANDOM) {
advertising_address = properties_.GetLeAddress();
}
ASSERT(advertising_address != Address::kEmpty);
- ad = packets::LeAdvertisementBuilder::Create(own_address_type,
- static_cast<LeAdvertisement::AdvertisementType>(own_address_type),
- properties_.GetLeAdvertisement());
- to_send = packets::LinkLayerPacketBuilder::WrapLeAdvertisement(std::move(ad), advertising_address);
- SendLeLinkLayerPacket(to_send);
+ auto to_send = model::packets::LeAdvertisementBuilder::Create(
+ advertising_address, Address::kEmpty, own_address_type,
+ static_cast<model::packets::AdvertisementType>(own_address_type),
+ properties_.GetLeAdvertisement());
+ SendLeLinkLayerPacket(std::move(to_send));
}
void LinkLayerController::Connections() {
@@ -718,7 +826,9 @@
}
void LinkLayerController::RegisterRemoteChannel(
- const std::function<void(std::shared_ptr<LinkLayerPacketBuilder>, Phy::Type)>& callback) {
+ const std::function<void(
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder>, Phy::Type)>&
+ callback) {
send_to_remote_ = callback;
}
@@ -835,16 +945,21 @@
security_manager_.SetLocalIoCapability(peer, io_capability, oob_data_present_flag, authentication_requirements);
PairingType pairing_type = security_manager_.GetSimplePairingType();
+
if (pairing_type != PairingType::INVALID) {
ScheduleTask(milliseconds(5), [this, peer, pairing_type]() { AuthenticateRemoteStage1(peer, pairing_type); });
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapIoCapabilityResponse(
- IoCapabilityBuilder::Create(io_capability, oob_data_present_flag, authentication_requirements),
- properties_.GetAddress(), peer));
+ auto packet = model::packets::IoCapabilityResponseBuilder::Create(
+ properties_.GetAddress(), peer, io_capability, oob_data_present_flag,
+ authentication_requirements);
+ SendLinkLayerPacket(std::move(packet));
+
} else {
LOG_INFO("%s: Requesting remote capability", __func__);
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapIoCapabilityRequest(
- IoCapabilityBuilder::Create(io_capability, oob_data_present_flag, authentication_requirements),
- properties_.GetAddress(), peer));
+
+ auto packet = model::packets::IoCapabilityRequestBuilder::Create(
+ properties_.GetAddress(), peer, io_capability, oob_data_present_flag,
+ authentication_requirements);
+ SendLinkLayerPacket(std::move(packet));
}
return hci::Status::SUCCESS;
@@ -857,8 +972,9 @@
security_manager_.InvalidateIoCapabilities();
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapIoCapabilityNegativeResponse(
- IoCapabilityNegativeResponseBuilder::Create(static_cast<uint8_t>(reason)), properties_.GetAddress(), peer));
+ auto packet = model::packets::IoCapabilityNegativeResponseBuilder::Create(
+ properties_.GetAddress(), peer, static_cast<uint8_t>(reason));
+ SendLinkLayerPacket(std::move(packet));
return hci::Status::SUCCESS;
}
@@ -949,8 +1065,9 @@
return;
}
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapEncryptConnection(
- EncryptConnectionBuilder::Create(security_manager_.GetKey(peer)), properties_.GetAddress(), peer));
+ auto packet = model::packets::EncryptConnectionBuilder::Create(
+ properties_.GetAddress(), peer, security_manager_.GetKey(peer));
+ SendLinkLayerPacket(std::move(packet));
}
hci::Status LinkLayerController::SetConnectionEncryption(uint16_t handle, uint8_t encryption_enable) {
@@ -990,10 +1107,10 @@
}
void LinkLayerController::MakeSlaveConnection(const Address& addr, bool try_role_switch) {
- std::shared_ptr<LinkLayerPacketBuilder> to_send = LinkLayerPacketBuilder::WrapPageResponse(
- PageResponseBuilder::Create(try_role_switch), properties_.GetAddress(), addr);
LOG_INFO("%s sending page response to %s", __func__, addr.ToString().c_str());
- SendLinkLayerPacket(to_send);
+ auto to_send = model::packets::PageResponseBuilder::Create(
+ properties_.GetAddress(), addr, try_role_switch);
+ SendLinkLayerPacket(std::move(to_send));
uint16_t handle = connections_.CreateConnection(addr);
if (handle == acl::kReservedHandle) {
@@ -1022,10 +1139,10 @@
}
void LinkLayerController::RejectSlaveConnection(const Address& addr, uint8_t reason) {
- std::shared_ptr<LinkLayerPacketBuilder> to_send =
- LinkLayerPacketBuilder::WrapPageReject(PageRejectBuilder::Create(reason), properties_.GetAddress(), addr);
+ auto to_send = model::packets::PageRejectBuilder::Create(
+ properties_.GetAddress(), addr, reason);
LOG_INFO("%s sending page reject to %s", __func__, addr.ToString().c_str());
- SendLinkLayerPacket(to_send);
+ SendLinkLayerPacket(std::move(to_send));
ASSERT(reason >= 0x0d && reason <= 0x0f);
send_event_(EventPacketBuilder::CreateConnectionCompleteEvent(static_cast<hci::Status>(reason), 0xeff, addr,
@@ -1039,8 +1156,10 @@
return hci::Status::CONTROLLER_BUSY;
}
- std::unique_ptr<PageBuilder> page = PageBuilder::Create(properties_.GetClassOfDevice(), allow_role_switch);
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapPage(std::move(page), properties_.GetAddress(), addr));
+ auto page = model::packets::PageBuilder::Create(
+ properties_.GetAddress(), addr, properties_.GetClassOfDevice(),
+ allow_role_switch);
+ SendLinkLayerPacket(std::move(page));
return hci::Status::SUCCESS;
}
@@ -1059,9 +1178,9 @@
}
const Address& remote = connections_.GetAddress(handle);
- std::shared_ptr<LinkLayerPacketBuilder> to_send =
- LinkLayerPacketBuilder::WrapDisconnect(DisconnectBuilder::Create(reason), properties_.GetAddress(), remote);
- SendLinkLayerPacket(to_send);
+ auto packet = model::packets::DisconnectBuilder::Create(
+ properties_.GetAddress(), remote, reason);
+ SendLinkLayerPacket(std::move(packet));
ASSERT_LOG(connections_.Disconnect(handle), "Disconnecting %hx", handle);
ScheduleTask(milliseconds(20), [this, handle]() {
@@ -1310,7 +1429,7 @@
}
void LinkLayerController::SetInquiryMode(uint8_t mode) {
- inquiry_mode_ = static_cast<Inquiry::InquiryType>(mode);
+ inquiry_mode_ = static_cast<model::packets::InquiryType>(mode);
}
void LinkLayerController::SetInquiryLAP(uint64_t lap) {
@@ -1327,10 +1446,10 @@
return;
}
LOG_INFO("Inquiry ");
- std::unique_ptr<InquiryBuilder> inquiry = InquiryBuilder::Create(inquiry_mode_);
- std::shared_ptr<LinkLayerPacketBuilder> to_send =
- LinkLayerPacketBuilder::WrapInquiry(std::move(inquiry), properties_.GetAddress());
- SendLinkLayerPacket(to_send);
+
+ auto packet = model::packets::InquiryBuilder::Create(
+ properties_.GetAddress(), Address::kEmpty, inquiry_mode_);
+ SendLinkLayerPacket(std::move(packet));
last_inquiry_ = now;
}
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 9adb714..659093b 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
@@ -19,14 +19,12 @@
#include "acl_connection_handler.h"
#include "include/hci.h"
#include "include/inquiry.h"
-#include "include/link.h"
#include "include/phy.h"
#include "model/devices/device_properties.h"
#include "model/setup/async_manager.h"
#include "packets/hci/acl_packet_view.h"
#include "packets/hci/sco_packet_view.h"
-#include "packets/link_layer/link_layer_packet_builder.h"
-#include "packets/link_layer/link_layer_packet_view.h"
+#include "packets/link_layer_packets.h"
#include "security_manager.h"
#include "types/address.h"
@@ -77,7 +75,7 @@
void DisconnectCleanup(uint16_t handle, uint8_t reason);
public:
- void IncomingPacket(packets::LinkLayerPacketView incoming);
+ void IncomingPacket(model::packets::LinkLayerPacketView incoming);
void TimerTick();
@@ -93,7 +91,9 @@
void RegisterScoChannel(const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_sco);
void RegisterRemoteChannel(
- const std::function<void(std::shared_ptr<packets::LinkLayerPacketBuilder>, Phy::Type)>& send_to_remote);
+ const std::function<void(
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder>, Phy::Type)>&
+ send_to_remote);
// Set the callbacks for scheduling tasks.
void RegisterTaskScheduler(
@@ -216,35 +216,46 @@
hci::Status WriteLinkSupervisionTimeout(uint16_t handle, uint16_t timeout);
protected:
- void SendLeLinkLayerPacket(std::shared_ptr<packets::LinkLayerPacketBuilder> packet);
- void SendLinkLayerPacket(std::shared_ptr<packets::LinkLayerPacketBuilder> packet);
- void IncomingAclPacket(packets::LinkLayerPacketView packet);
- void IncomingAclAckPacket(packets::LinkLayerPacketView packet);
- void IncomingCommandPacket(packets::LinkLayerPacketView packet);
- void IncomingCreateConnectionPacket(packets::LinkLayerPacketView packet);
- void IncomingDisconnectPacket(packets::LinkLayerPacketView packet);
- void IncomingEncryptConnection(packets::LinkLayerPacketView packet);
- void IncomingEncryptConnectionResponse(packets::LinkLayerPacketView packet);
- void IncomingInquiryPacket(packets::LinkLayerPacketView packet);
- void IncomingInquiryResponsePacket(packets::LinkLayerPacketView packet);
- void IncomingIoCapabilityRequestPacket(packets::LinkLayerPacketView packet);
- void IncomingIoCapabilityResponsePacket(packets::LinkLayerPacketView packet);
- void IncomingIoCapabilityNegativeResponsePacket(packets::LinkLayerPacketView packet);
- void IncomingLeAdvertisementPacket(packets::LinkLayerPacketView packet);
- void IncomingLeConnectPacket(packets::LinkLayerPacketView packet);
- void IncomingLeConnectCompletePacket(packets::LinkLayerPacketView packet);
- void IncomingLeScanPacket(packets::LinkLayerPacketView packet);
- void IncomingLeScanResponsePacket(packets::LinkLayerPacketView packet);
- void IncomingPagePacket(packets::LinkLayerPacketView packet);
- void IncomingPageRejectPacket(packets::LinkLayerPacketView packet);
- void IncomingPageResponsePacket(packets::LinkLayerPacketView packet);
- void IncomingResponsePacket(packets::LinkLayerPacketView packet);
+ void SendLeLinkLayerPacket(
+ std::unique_ptr<model::packets::LinkLayerPacketBuilder> packet);
+ void SendLinkLayerPacket(
+ 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);
+ void IncomingEncryptConnection(model::packets::LinkLayerPacketView packet);
+ void IncomingEncryptConnectionResponse(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingInquiryPacket(model::packets::LinkLayerPacketView packet);
+ void IncomingInquiryResponsePacket(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingIoCapabilityRequestPacket(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingIoCapabilityResponsePacket(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingIoCapabilityNegativeResponsePacket(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingLeAdvertisementPacket(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingLeConnectPacket(model::packets::LinkLayerPacketView packet);
+ void IncomingLeConnectCompletePacket(
+ model::packets::LinkLayerPacketView packet);
+ void IncomingLeScanPacket(model::packets::LinkLayerPacketView packet);
+ void IncomingLeScanResponsePacket(model::packets::LinkLayerPacketView packet);
+ void IncomingPagePacket(model::packets::LinkLayerPacketView packet);
+ void IncomingPageRejectPacket(model::packets::LinkLayerPacketView packet);
+ void IncomingPageResponsePacket(model::packets::LinkLayerPacketView packet);
+ void IncomingResponsePacket(model::packets::LinkLayerPacketView packet);
private:
const DeviceProperties& properties_;
AclConnectionHandler connections_;
// Add timestamps?
- std::vector<std::shared_ptr<packets::LinkLayerPacketBuilder>> commands_awaiting_responses_;
+ std::vector<std::shared_ptr<model::packets::LinkLayerPacketBuilder>>
+ commands_awaiting_responses_;
// Timing related state
std::vector<AsyncTaskId> controller_events_;
@@ -263,7 +274,9 @@
std::function<void(std::shared_ptr<std::vector<uint8_t>>)> send_sco_;
// Callback to send packets to remote devices.
- std::function<void(std::shared_ptr<packets::LinkLayerPacketBuilder>, Phy::Type phy_type)> send_to_remote_;
+ std::function<void(std::shared_ptr<model::packets::LinkLayerPacketBuilder>,
+ Phy::Type phy_type)>
+ send_to_remote_;
// LE state
std::vector<uint8_t> le_event_mask_;
@@ -300,7 +313,7 @@
SecurityManager security_manager_{10};
std::chrono::steady_clock::time_point last_inquiry_;
- Inquiry::InquiryType inquiry_mode_;
+ model::packets::InquiryType inquiry_mode_;
Inquiry::InquiryState inquiry_state_;
uint64_t inquiry_lap_;
uint8_t inquiry_max_responses_;
diff --git a/vendor_libs/test_vendor_lib/model/devices/beacon.cc b/vendor_libs/test_vendor_lib/model/devices/beacon.cc
index b162cba..492ddcc 100644
--- a/vendor_libs/test_vendor_lib/model/devices/beacon.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/beacon.cc
@@ -61,12 +61,15 @@
void Beacon::TimerTick() {
if (IsAdvertisementAvailable()) {
last_advertisement_ = std::chrono::steady_clock::now();
- std::unique_ptr<packets::LeAdvertisementBuilder> ad = packets::LeAdvertisementBuilder::Create(
- LeAdvertisement::AddressType::PUBLIC,
- static_cast<LeAdvertisement::AdvertisementType>(properties_.GetLeAdvertisementType()),
+ auto ad = model::packets::LeAdvertisementBuilder::Create(
+ properties_.GetLeAddress(), Address::kEmpty,
+ model::packets::AddressType::PUBLIC,
+ static_cast<model::packets::AdvertisementType>(
+ properties_.GetLeAdvertisementType()),
properties_.GetLeAdvertisement());
- std::shared_ptr<packets::LinkLayerPacketBuilder> to_send =
- packets::LinkLayerPacketBuilder::WrapLeAdvertisement(std::move(ad), properties_.GetLeAddress());
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
+ std::move(ad);
+
std::vector<std::shared_ptr<PhyLayer>> le_phys = phy_layers_[Phy::Type::LOW_ENERGY];
for (std::shared_ptr<PhyLayer> phy : le_phys) {
phy->Send(to_send);
@@ -74,13 +77,17 @@
}
}
-void Beacon::IncomingPacket(packets::LinkLayerPacketView packet) {
- if (packet.GetDestinationAddress() == properties_.GetLeAddress() && packet.GetType() == Link::PacketType::LE_SCAN) {
- std::unique_ptr<packets::LeAdvertisementBuilder> scan_response = packets::LeAdvertisementBuilder::Create(
- LeAdvertisement::AddressType::PUBLIC, LeAdvertisement::AdvertisementType::SCAN_RESPONSE,
+void Beacon::IncomingPacket(model::packets::LinkLayerPacketView packet) {
+ if (packet.GetDestinationAddress() == properties_.GetLeAddress() &&
+ packet.GetType() == model::packets::PacketType::LE_SCAN) {
+ auto scan_response = model::packets::LeAdvertisementBuilder::Create(
+ properties_.GetLeAddress(), packet.GetSourceAddress(),
+ model::packets::AddressType::PUBLIC,
+ model::packets::AdvertisementType::SCAN_RESPONSE,
properties_.GetLeScanResponse());
- std::shared_ptr<packets::LinkLayerPacketBuilder> to_send = packets::LinkLayerPacketBuilder::WrapLeScanResponse(
- std::move(scan_response), properties_.GetLeAddress(), packet.GetSourceAddress());
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
+ std::move(scan_response);
+
std::vector<std::shared_ptr<PhyLayer>> le_phys = phy_layers_[Phy::Type::LOW_ENERGY];
for (auto phy : le_phys) {
phy->Send(to_send);
diff --git a/vendor_libs/test_vendor_lib/model/devices/beacon.h b/vendor_libs/test_vendor_lib/model/devices/beacon.h
index 8499ab8..87bb228 100644
--- a/vendor_libs/test_vendor_lib/model/devices/beacon.h
+++ b/vendor_libs/test_vendor_lib/model/devices/beacon.h
@@ -42,7 +42,8 @@
// Set the address and advertising interval from string args.
virtual void Initialize(const std::vector<std::string>& args) override;
- virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView packet) override;
virtual void TimerTick() override;
diff --git a/vendor_libs/test_vendor_lib/model/devices/car_kit.cc b/vendor_libs/test_vendor_lib/model/devices/car_kit.cc
index dcf977f..9f325a4 100644
--- a/vendor_libs/test_vendor_lib/model/devices/car_kit.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/car_kit.cc
@@ -35,7 +35,8 @@
link_layer_controller_.RegisterEventChannel([](std::shared_ptr<std::vector<uint8_t>>) {});
link_layer_controller_.RegisterScoChannel([](std::shared_ptr<std::vector<uint8_t>>) {});
link_layer_controller_.RegisterRemoteChannel(
- [this](std::shared_ptr<packets::LinkLayerPacketBuilder> packet, Phy::Type phy_type) {
+ [this](std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
+ Phy::Type phy_type) {
CarKit::SendLinkLayerPacket(packet, phy_type);
});
@@ -90,7 +91,7 @@
link_layer_controller_.TimerTick();
}
-void CarKit::IncomingPacket(packets::LinkLayerPacketView packet) {
+void CarKit::IncomingPacket(model::packets::LinkLayerPacketView packet) {
LOG_WARN("Incoming Packet");
link_layer_controller_.IncomingPacket(packet);
}
diff --git a/vendor_libs/test_vendor_lib/model/devices/car_kit.h b/vendor_libs/test_vendor_lib/model/devices/car_kit.h
index 94057ad..6822f27 100644
--- a/vendor_libs/test_vendor_lib/model/devices/car_kit.h
+++ b/vendor_libs/test_vendor_lib/model/devices/car_kit.h
@@ -45,7 +45,8 @@
return "car_kit";
}
- virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView packet) override;
virtual void TimerTick() override;
diff --git a/vendor_libs/test_vendor_lib/model/devices/device.cc b/vendor_libs/test_vendor_lib/model/devices/device.cc
index 2ca4636..216d6c0 100644
--- a/vendor_libs/test_vendor_lib/model/devices/device.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/device.cc
@@ -55,7 +55,16 @@
(std::chrono::steady_clock::now() >= last_advertisement_ + advertising_interval_ms_);
}
-void Device::SendLinkLayerPacket(std::shared_ptr<packets::LinkLayerPacketBuilder> to_send, Phy::Type phy_type) {
+void Device::SendLinkLayerPacket(
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send,
+ Phy::Type phy_type) {
+ for (auto phy : phy_layers_[phy_type]) {
+ phy->Send(to_send);
+ }
+}
+
+void Device::SendLinkLayerPacket(model::packets::LinkLayerPacketView to_send,
+ Phy::Type phy_type) {
for (auto phy : phy_layers_[phy_type]) {
phy->Send(to_send);
}
diff --git a/vendor_libs/test_vendor_lib/model/devices/device.h b/vendor_libs/test_vendor_lib/model/devices/device.h
index c1f2265..7ab05c3 100644
--- a/vendor_libs/test_vendor_lib/model/devices/device.h
+++ b/vendor_libs/test_vendor_lib/model/devices/device.h
@@ -24,10 +24,10 @@
#include "model/devices/device_properties.h"
#include "model/setup/phy_layer.h"
-#include "packets/link_layer/link_layer_packet_builder.h"
-#include "packets/link_layer/link_layer_packet_view.h"
#include "types/address.h"
+#include "packets/link_layer_packets.h"
+
namespace test_vendor_lib {
// Represent a Bluetooth Device
@@ -72,9 +72,13 @@
void UnregisterPhyLayer(Phy::Type phy_type, uint32_t factory_id);
- virtual void IncomingPacket(packets::LinkLayerPacketView){};
+ virtual void IncomingPacket(model::packets::LinkLayerPacketView){};
- virtual void SendLinkLayerPacket(std::shared_ptr<packets::LinkLayerPacketBuilder> packet, Phy::Type phy_type);
+ virtual void SendLinkLayerPacket(
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
+ Phy::Type phy_type);
+ virtual void SendLinkLayerPacket(model::packets::LinkLayerPacketView packet,
+ Phy::Type phy_type);
protected:
std::map<Phy::Type, std::vector<std::shared_ptr<PhyLayer>>> phy_layers_;
diff --git a/vendor_libs/test_vendor_lib/model/devices/keyboard.cc b/vendor_libs/test_vendor_lib/model/devices/keyboard.cc
index 1daa05d..1244d3e 100644
--- a/vendor_libs/test_vendor_lib/model/devices/keyboard.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/keyboard.cc
@@ -80,7 +80,7 @@
}
}
-void Keyboard::IncomingPacket(packets::LinkLayerPacketView packet) {
+void Keyboard::IncomingPacket(model::packets::LinkLayerPacketView packet) {
if (!connected_) {
Beacon::IncomingPacket(packet);
}
diff --git a/vendor_libs/test_vendor_lib/model/devices/keyboard.h b/vendor_libs/test_vendor_lib/model/devices/keyboard.h
index 871fa52..cf00dfe 100644
--- a/vendor_libs/test_vendor_lib/model/devices/keyboard.h
+++ b/vendor_libs/test_vendor_lib/model/devices/keyboard.h
@@ -40,7 +40,8 @@
// Initialize the device based on the values of |args|.
virtual void Initialize(const std::vector<std::string>& args) override;
- virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView packet) override;
virtual void TimerTick() override;
diff --git a/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc b/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc
index 99f0c9d..ab2c5f1 100644
--- a/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.cc
@@ -18,8 +18,6 @@
#include <unistd.h>
-#include "packets/link_layer/link_layer_packet_builder.h"
-#include "packets/link_layer/link_layer_packet_view.h"
#include "packets/packet_view.h"
#include "packets/view.h"
@@ -32,16 +30,18 @@
void LinkLayerSocketDevice::TimerTick() {
if (bytes_left_ == 0) {
- received_ = std::make_shared<std::vector<uint8_t>>(Link::kSizeBytes);
- size_t bytes_received = socket_.TryReceive(Link::kSizeBytes, received_->data());
+ size_t size_bytes = sizeof(uint32_t);
+ received_ = std::make_shared<std::vector<uint8_t>>(size_bytes);
+ size_t bytes_received = socket_.TryReceive(size_bytes, received_->data());
if (bytes_received == 0) {
return;
}
- ASSERT_LOG(bytes_received == Link::kSizeBytes, "bytes_received == %d", static_cast<int>(bytes_received));
- packets::PacketView<true> size({packets::View(received_, 0, Link::kSizeBytes)});
+ ASSERT_LOG(bytes_received == size_bytes, "bytes_received == %d",
+ static_cast<int>(bytes_received));
+ packets::PacketView<true> size({packets::View(received_, 0, size_bytes)});
bytes_left_ = size.begin().extract<uint32_t>();
- received_->resize(Link::kSizeBytes + bytes_left_);
- offset_ = Link::kSizeBytes;
+ received_->resize(size_bytes + bytes_left_);
+ offset_ = size_bytes;
}
size_t bytes_received = socket_.TryReceive(bytes_left_, received_->data() + offset_);
if (bytes_received == 0) {
@@ -50,14 +50,23 @@
bytes_left_ -= bytes_received;
offset_ += bytes_received;
if (bytes_left_ == 0) {
- SendLinkLayerPacket(packets::LinkLayerPacketBuilder::ReWrap(received_), phy_type_);
+ bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian> packet_view(
+ received_);
+ auto packet = model::packets::LinkLayerPacketView::Create(packet_view);
+ ASSERT(packet.IsValid());
+ SendLinkLayerPacket(packet, phy_type_);
offset_ = 0;
received_.reset();
}
}
-void LinkLayerSocketDevice::IncomingPacket(packets::LinkLayerPacketView packet) {
- socket_.TrySend(packet);
+void LinkLayerSocketDevice::IncomingPacket(
+ model::packets::LinkLayerPacketView packet) {
+ std::shared_ptr<std::vector<uint8_t>> payload_bytes =
+ std::make_shared<std::vector<uint8_t>>(packet.begin(), packet.end());
+ packets::PacketView<true> packet_view(payload_bytes);
+
+ socket_.TrySend(packet_view);
}
} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h b/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h
index d3bbb2e..2b662d1 100644
--- a/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h
+++ b/vendor_libs/test_vendor_lib/model/devices/link_layer_socket_device.h
@@ -20,9 +20,8 @@
#include <vector>
#include "device.h"
-#include "include/link.h"
#include "include/phy.h"
-#include "packets/link_layer/link_layer_packet_view.h"
+#include "packets/link_layer_packets.h"
#include "polled_socket.h"
namespace test_vendor_lib {
@@ -43,7 +42,8 @@
virtual void Initialize(const std::vector<std::string>&) override {}
- virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView packet) override;
virtual void TimerTick() override;
@@ -53,7 +53,7 @@
size_t bytes_left_{0};
size_t offset_;
std::shared_ptr<std::vector<uint8_t>> received_;
- std::vector<packets::LinkLayerPacketView> packet_queue_;
+ std::vector<model::packets::LinkLayerPacketView> packet_queue_;
};
} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/model/devices/loopback.cc b/vendor_libs/test_vendor_lib/model/devices/loopback.cc
index 18af1c1..e0b9f35 100644
--- a/vendor_libs/test_vendor_lib/model/devices/loopback.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/loopback.cc
@@ -66,15 +66,20 @@
void Loopback::TimerTick() {}
-void Loopback::IncomingPacket(packets::LinkLayerPacketView packet) {
+void Loopback::IncomingPacket(model::packets::LinkLayerPacketView packet) {
LOG_INFO("Got a packet of type %d", static_cast<int>(packet.GetType()));
- if (packet.GetDestinationAddress() == properties_.GetLeAddress() && packet.GetType() == Link::PacketType::LE_SCAN) {
+ if (packet.GetDestinationAddress() == properties_.GetLeAddress() &&
+ packet.GetType() == model::packets::PacketType::LE_SCAN) {
LOG_INFO("Got a scan");
- std::unique_ptr<packets::LeAdvertisementBuilder> scan_response = packets::LeAdvertisementBuilder::Create(
- LeAdvertisement::AddressType::PUBLIC, LeAdvertisement::AdvertisementType::SCAN_RESPONSE,
+
+ auto scan_response = model::packets::LeAdvertisementBuilder::Create(
+ properties_.GetLeAddress(), packet.GetSourceAddress(),
+ model::packets::AddressType::PUBLIC,
+ model::packets::AdvertisementType::SCAN_RESPONSE,
properties_.GetLeScanResponse());
- std::shared_ptr<packets::LinkLayerPacketBuilder> to_send = packets::LinkLayerPacketBuilder::WrapLeScanResponse(
- std::move(scan_response), properties_.GetLeAddress(), packet.GetSourceAddress());
+ std::shared_ptr<model::packets::LinkLayerPacketBuilder> to_send =
+ std::move(scan_response);
+
std::vector<std::shared_ptr<PhyLayer>> le_phys = phy_layers_[Phy::Type::LOW_ENERGY];
for (auto phy : le_phys) {
LOG_INFO("Sending a Scan Response on a Phy");
diff --git a/vendor_libs/test_vendor_lib/model/devices/loopback.h b/vendor_libs/test_vendor_lib/model/devices/loopback.h
index 31dd1cd..dd5c069 100644
--- a/vendor_libs/test_vendor_lib/model/devices/loopback.h
+++ b/vendor_libs/test_vendor_lib/model/devices/loopback.h
@@ -42,7 +42,8 @@
// Set the address and advertising interval from string args.
virtual void Initialize(const std::vector<std::string>& args) override;
- virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView packet) override;
virtual void TimerTick() override;
diff --git a/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.cc b/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.cc
index 82cf04f..db87028 100644
--- a/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.cc
@@ -18,16 +18,14 @@
#include "model/setup/device_boutique.h"
#include "os/log.h"
-#include "packets/link_layer/link_layer_packet_builder.h"
-#include "packets/link_layer/link_layer_packet_view.h"
using std::vector;
namespace test_vendor_lib {
-using packets::LinkLayerPacketBuilder;
-using packets::LinkLayerPacketView;
-using packets::PageResponseBuilder;
+using model::packets::LinkLayerPacketBuilder;
+using model::packets::LinkLayerPacketView;
+using model::packets::PageResponseBuilder;
bool RemoteLoopbackDevice::registered_ = DeviceBoutique::Register("remote_loopback", &RemoteLoopbackDevice::Create);
@@ -44,27 +42,23 @@
if (Address::FromString(args[1], addr)) properties_.SetAddress(addr);
}
-void RemoteLoopbackDevice::IncomingPacket(LinkLayerPacketView packet) {
+void RemoteLoopbackDevice::IncomingPacket(
+ model::packets::LinkLayerPacketView packet) {
// TODO: Check sender?
// TODO: Handle other packet types
Phy::Type phy_type = Phy::Type::BR_EDR;
- Link::PacketType type = packet.GetType();
+ model::packets::PacketType type = packet.GetType();
switch (type) {
- case Link::PacketType::PAGE:
- SendLinkLayerPacket(LinkLayerPacketBuilder::WrapPageResponse(
- PageResponseBuilder::Create(true), packet.GetSourceAddress(), packet.GetSourceAddress()),
- Phy::Type::BR_EDR);
+ case model::packets::PacketType::PAGE:
+ SendLinkLayerPacket(
+ PageResponseBuilder::Create(packet.GetSourceAddress(),
+ packet.GetSourceAddress(), true),
+ Phy::Type::BR_EDR);
break;
default: {
LOG_WARN("Resend = %d", static_cast<int>(packet.size()));
- std::shared_ptr<std::vector<uint8_t>> extracted_packet = std::make_shared<std::vector<uint8_t>>();
- extracted_packet->reserve(packet.size());
- for (const auto byte : packet) {
- extracted_packet->push_back(byte);
- }
-
- SendLinkLayerPacket(LinkLayerPacketBuilder::ReWrap(extracted_packet), phy_type);
+ SendLinkLayerPacket(packet, phy_type);
}
}
}
diff --git a/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.h b/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.h
index 5513677..98c9a83 100644
--- a/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.h
+++ b/vendor_libs/test_vendor_lib/model/devices/remote_loopback_device.h
@@ -20,7 +20,6 @@
#include <vector>
#include "device.h"
-#include "packets/link_layer/link_layer_packet_view.h"
namespace test_vendor_lib {
@@ -41,7 +40,8 @@
virtual void Initialize(const std::vector<std::string>& args) override;
- virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView packet) override;
private:
static bool registered_;
diff --git a/vendor_libs/test_vendor_lib/model/devices/sniffer.cc b/vendor_libs/test_vendor_lib/model/devices/sniffer.cc
index ba47893..c4586d1 100644
--- a/vendor_libs/test_vendor_lib/model/devices/sniffer.cc
+++ b/vendor_libs/test_vendor_lib/model/devices/sniffer.cc
@@ -39,7 +39,7 @@
void Sniffer::TimerTick() {}
-void Sniffer::IncomingPacket(packets::LinkLayerPacketView packet) {
+void Sniffer::IncomingPacket(model::packets::LinkLayerPacketView packet) {
Address source = packet.GetSourceAddress();
Address dest = packet.GetDestinationAddress();
bool match_source = device_to_sniff_ == source;
diff --git a/vendor_libs/test_vendor_lib/model/devices/sniffer.h b/vendor_libs/test_vendor_lib/model/devices/sniffer.h
index 3e0cfef..162a401 100644
--- a/vendor_libs/test_vendor_lib/model/devices/sniffer.h
+++ b/vendor_libs/test_vendor_lib/model/devices/sniffer.h
@@ -20,7 +20,7 @@
#include <vector>
#include "device.h"
-#include "packets/link_layer/link_layer_packet_view.h"
+#include "packets/link_layer_packets.h"
#include "types/address.h"
namespace test_vendor_lib {
@@ -42,7 +42,8 @@
return "sniffer";
}
- virtual void IncomingPacket(packets::LinkLayerPacketView packet) override;
+ virtual void IncomingPacket(
+ model::packets::LinkLayerPacketView packet) override;
virtual void TimerTick() override;
diff --git a/vendor_libs/test_vendor_lib/model/setup/phy_layer.h b/vendor_libs/test_vendor_lib/model/setup/phy_layer.h
index e49c412..9f2bc7a 100644
--- a/vendor_libs/test_vendor_lib/model/setup/phy_layer.h
+++ b/vendor_libs/test_vendor_lib/model/setup/phy_layer.h
@@ -17,19 +17,22 @@
#pragma once
#include "include/phy.h"
-#include "packets/link_layer/link_layer_packet_builder.h"
-#include "packets/link_layer/link_layer_packet_view.h"
+#include "packets/link_layer_packets.h"
namespace test_vendor_lib {
class PhyLayer {
public:
- PhyLayer(Phy::Type phy_type, uint32_t id, const std::function<void(packets::LinkLayerPacketView)>& device_receive)
+ PhyLayer(Phy::Type phy_type, uint32_t id,
+ const std::function<void(model::packets::LinkLayerPacketView)>&
+ device_receive)
: phy_type_(phy_type), id_(id), transmit_to_device_(device_receive) {}
- virtual void Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) = 0;
+ virtual void Send(
+ const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet) = 0;
+ virtual void Send(model::packets::LinkLayerPacketView packet) = 0;
- virtual void Receive(packets::LinkLayerPacketView packet) = 0;
+ virtual void Receive(model::packets::LinkLayerPacketView packet) = 0;
virtual void TimerTick() = 0;
@@ -52,7 +55,8 @@
uint32_t id_;
protected:
- const std::function<void(packets::LinkLayerPacketView)> transmit_to_device_;
+ const std::function<void(model::packets::LinkLayerPacketView)>
+ transmit_to_device_;
};
} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc b/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc
index 654962e..e1da9f3 100644
--- a/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc
+++ b/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.cc
@@ -30,9 +30,11 @@
}
std::shared_ptr<PhyLayer> PhyLayerFactory::GetPhyLayer(
- const std::function<void(packets::LinkLayerPacketView)>& device_receive) {
+ const std::function<void(model::packets::LinkLayerPacketView)>&
+ device_receive) {
std::shared_ptr<PhyLayer> new_phy =
- std::make_shared<PhyLayerImpl>(phy_type_, next_id_++, device_receive, std::shared_ptr<PhyLayerFactory>(this));
+ std::make_shared<PhyLayerImpl>(phy_type_, next_id_++, device_receive,
+ std::shared_ptr<PhyLayerFactory>(this));
phy_layers_.push_back(new_phy);
return new_phy;
}
@@ -47,18 +49,32 @@
}
}
-void PhyLayerFactory::Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet, uint32_t id) {
+void PhyLayerFactory::Send(
+ const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
+ uint32_t id) {
// Convert from a Builder to a View
- std::shared_ptr<std::vector<uint8_t>> serialized_packet =
- std::shared_ptr<std::vector<uint8_t>>(new std::vector<uint8_t>());
- std::back_insert_iterator<std::vector<uint8_t>> itr(*serialized_packet);
- serialized_packet->reserve(packet->size());
- packet->Serialize(itr);
- packets::LinkLayerPacketView packet_view = packets::LinkLayerPacketView::Create(serialized_packet);
+ auto bytes = std::make_shared<std::vector<uint8_t>>();
+ bluetooth::packet::BitInserter i(*bytes);
+ bytes->reserve(packet->size());
+ packet->Serialize(i);
+ auto packet_view =
+ bluetooth::packet::PacketView<bluetooth::packet::kLittleEndian>(bytes);
+ auto link_layer_packet_view =
+ model::packets::LinkLayerPacketView::Create(packet_view);
+ ASSERT(link_layer_packet_view.IsValid());
for (const auto phy : phy_layers_) {
if (id != phy->GetId()) {
- phy->Receive(packet_view);
+ phy->Receive(link_layer_packet_view);
+ }
+ }
+}
+
+void PhyLayerFactory::Send(model::packets::LinkLayerPacketView packet,
+ uint32_t id) {
+ for (const auto phy : phy_layers_) {
+ if (id != phy->GetId()) {
+ phy->Receive(packet);
}
}
}
@@ -82,16 +98,23 @@
}
}
-PhyLayerImpl::PhyLayerImpl(Phy::Type phy_type, uint32_t id,
- const std::function<void(packets::LinkLayerPacketView)>& device_receive,
- const std::shared_ptr<PhyLayerFactory>& factory)
+PhyLayerImpl::PhyLayerImpl(
+ Phy::Type phy_type, uint32_t id,
+ const std::function<void(model::packets::LinkLayerPacketView)>&
+ device_receive,
+ const std::shared_ptr<PhyLayerFactory>& factory)
: PhyLayer(phy_type, id, device_receive), factory_(factory) {}
PhyLayerImpl::~PhyLayerImpl() {
Unregister();
}
-void PhyLayerImpl::Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) {
+void PhyLayerImpl::Send(
+ const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet) {
+ factory_->Send(packet, GetId());
+}
+
+void PhyLayerImpl::Send(model::packets::LinkLayerPacketView packet) {
factory_->Send(packet, GetId());
}
@@ -103,7 +126,7 @@
return factory_->GetFactoryId() == id;
}
-void PhyLayerImpl::Receive(packets::LinkLayerPacketView packet) {
+void PhyLayerImpl::Receive(model::packets::LinkLayerPacketView packet) {
transmit_to_device_(packet);
}
diff --git a/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h b/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h
index aaf14f8..003236a 100644
--- a/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h
+++ b/vendor_libs/test_vendor_lib/model/setup/phy_layer_factory.h
@@ -20,8 +20,7 @@
#include <vector>
#include "include/phy.h"
-#include "packets/link_layer/link_layer_packet_builder.h"
-#include "packets/link_layer/link_layer_packet_view.h"
+#include "packets/link_layer_packets.h"
#include "phy_layer.h"
namespace test_vendor_lib {
@@ -38,7 +37,9 @@
uint32_t GetFactoryId();
- std::shared_ptr<PhyLayer> GetPhyLayer(const std::function<void(packets::LinkLayerPacketView)>& device_receive);
+ std::shared_ptr<PhyLayer> GetPhyLayer(
+ const std::function<void(model::packets::LinkLayerPacketView)>&
+ device_receive);
void UnregisterPhyLayer(uint32_t id);
@@ -47,7 +48,10 @@
virtual std::string ToString() const;
protected:
- virtual void Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet, uint32_t id);
+ virtual void Send(
+ const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
+ uint32_t id);
+ virtual void Send(model::packets::LinkLayerPacketView packet, uint32_t id);
private:
Phy::Type phy_type_;
@@ -58,12 +62,17 @@
class PhyLayerImpl : public PhyLayer {
public:
- PhyLayerImpl(Phy::Type phy_type, uint32_t id, const std::function<void(packets::LinkLayerPacketView)>& device_receive,
+ PhyLayerImpl(Phy::Type phy_type, uint32_t id,
+ const std::function<void(model::packets::LinkLayerPacketView)>&
+ device_receive,
const std::shared_ptr<PhyLayerFactory>& factory);
virtual ~PhyLayerImpl() override;
- virtual void Send(const std::shared_ptr<packets::LinkLayerPacketBuilder> packet) override;
- virtual void Receive(packets::LinkLayerPacketView packet) override;
+ virtual void Send(
+ const std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet)
+ override;
+ virtual void Send(model::packets::LinkLayerPacketView packet) override;
+ virtual void Receive(model::packets::LinkLayerPacketView packet) override;
virtual void Unregister() override;
virtual bool IsFactoryId(uint32_t factory_id) override;
virtual void TimerTick() override;
diff --git a/vendor_libs/test_vendor_lib/model/setup/test_model.cc b/vendor_libs/test_vendor_lib/model/setup/test_model.cc
index 05500a1..ebd5fb9 100644
--- a/vendor_libs/test_vendor_lib/model/setup/test_model.cc
+++ b/vendor_libs/test_vendor_lib/model/setup/test_model.cc
@@ -131,8 +131,10 @@
return;
}
auto dev = device->second;
- dev->RegisterPhyLayer(
- phy->second->GetPhyLayer([dev](packets::LinkLayerPacketView packet) { dev->IncomingPacket(packet); }));
+ dev->RegisterPhyLayer(phy->second->GetPhyLayer(
+ [dev](model::packets::LinkLayerPacketView packet) {
+ dev->IncomingPacket(packet);
+ }));
}
void TestModel::DelDeviceFromPhy(size_t dev_index, size_t phy_index) {
diff --git a/vendor_libs/test_vendor_lib/packets/Android.bp b/vendor_libs/test_vendor_lib/packets/Android.bp
index 9378492..69a7b00 100644
--- a/vendor_libs/test_vendor_lib/packets/Android.bp
+++ b/vendor_libs/test_vendor_lib/packets/Android.bp
@@ -24,8 +24,6 @@
"hci/le_meta_event_builder.cc",
"hci/sco_packet_builder.cc",
"hci/sco_packet_view.cc",
- "link_layer/link_layer_packet_builder.cc",
- "link_layer/link_layer_packet_view.cc",
],
cflags: [
"-fvisibility=hidden",
@@ -56,7 +54,6 @@
"clang_coverage_bin",
],
srcs: [
- "test/link_layer_packet_builder_test.cc",
"test/packet_builder_test.cc",
"test/packet_view_test.cc",
"hci/test/acl_builder_test.cc",
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/command_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/command_builder.h
deleted file mode 100644
index ea3a1a2..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/command_builder.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class CommandBuilder : public PacketBuilder<true> {
- public:
- virtual ~CommandBuilder() = default;
-
- static std::unique_ptr<CommandBuilder> Create(uint16_t opcode, PacketView<true> args) {
- return std::unique_ptr<CommandBuilder>(new CommandBuilder(opcode, args));
- }
-
- virtual size_t size() const override {
- return sizeof(opcode_) + args_.size();
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(opcode_, it);
- for (const auto&& byte : args_) {
- insert(byte, it);
- }
- }
-
- private:
- explicit CommandBuilder(uint16_t opcode, PacketView<true> args) : opcode_(opcode), args_(args) {}
- uint16_t opcode_;
- PacketView<true> args_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/command_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/command_view.h
deleted file mode 100644
index 6e83051..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/command_view.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "os/log.h"
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class CommandView : public PacketView<true> {
- public:
- CommandView(const CommandView&) = default;
- virtual ~CommandView() = default;
-
- static CommandView GetCommand(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::COMMAND);
- return CommandView(view.GetPayload());
- }
-
- uint16_t GetOpcode() {
- return begin().extract<uint16_t>();
- }
-
- Iterator<true> GetData() {
- return begin() + sizeof(uint16_t);
- }
-
- private:
- CommandView() = delete;
- CommandView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/disconnect_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/disconnect_builder.h
deleted file mode 100644
index 8083c85..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/disconnect_builder.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class DisconnectBuilder : public PacketBuilder<true> {
- public:
- virtual ~DisconnectBuilder() = default;
-
- static std::unique_ptr<DisconnectBuilder> Create(uint8_t reason) {
- return std::unique_ptr<DisconnectBuilder>(new DisconnectBuilder(reason));
- }
-
- virtual size_t size() const override {
- return sizeof(reason_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- *it++ = reason_;
- }
-
- private:
- explicit DisconnectBuilder(uint8_t reason) : reason_(reason) {}
- uint8_t reason_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/disconnect_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/disconnect_view.h
deleted file mode 100644
index 3e72513..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/disconnect_view.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class DisconnectView : public PacketView<true> {
- public:
- DisconnectView(const DisconnectView&) = default;
- virtual ~DisconnectView() = default;
-
- static DisconnectView GetDisconnect(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::DISCONNECT);
- return DisconnectView(view.GetPayload());
- }
-
- uint8_t GetReason() {
- return at(0);
- }
-
- private:
- DisconnectView() = delete;
- DisconnectView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/encrypt_connection_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/encrypt_connection_builder.h
deleted file mode 100644
index 702d2b4..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/encrypt_connection_builder.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class EncryptConnectionBuilder : public PacketBuilder<true> {
- public:
- virtual ~EncryptConnectionBuilder() = default;
-
- static std::unique_ptr<EncryptConnectionBuilder> Create(const std::vector<uint8_t>& key) {
- return std::unique_ptr<EncryptConnectionBuilder>(new EncryptConnectionBuilder(key));
- }
-
- virtual size_t size() const override {
- return key_.size();
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert_vector(key_, it);
- }
-
- private:
- explicit EncryptConnectionBuilder(const std::vector<uint8_t>& key) : key_(key.begin(), key.begin() + 16) {}
- std::vector<uint8_t> key_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/encrypt_connection_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/encrypt_connection_view.h
deleted file mode 100644
index 22006d0..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/encrypt_connection_view.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class EncryptConnectionView : public PacketView<true> {
- public:
- EncryptConnectionView(const EncryptConnectionView&) = default;
- virtual ~EncryptConnectionView() = default;
-
- static EncryptConnectionView GetEncryptConnection(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::ENCRYPT_CONNECTION ||
- view.GetType() == Link::PacketType::ENCRYPT_CONNECTION_RESPONSE);
- return EncryptConnectionView(view.GetPayload());
- }
-
- Iterator<true> GetKey() {
- return begin();
- }
-
- private:
- EncryptConnectionView() = delete;
- EncryptConnectionView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_builder.h
deleted file mode 100644
index 4c60ce0..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_builder.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "inquiry.h"
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class InquiryBuilder : public PacketBuilder<true> {
- public:
- virtual ~InquiryBuilder() = default;
-
- static std::unique_ptr<InquiryBuilder> Create(Inquiry::InquiryType inquiry_type) {
- return std::unique_ptr<InquiryBuilder>(new InquiryBuilder(inquiry_type));
- }
-
- virtual size_t size() const override {
- return sizeof(uint8_t);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(static_cast<uint8_t>(inquiry_type_), it);
- }
-
- private:
- explicit InquiryBuilder(Inquiry::InquiryType inquiry_type) : inquiry_type_(inquiry_type) {}
- Inquiry::InquiryType inquiry_type_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_response_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_response_builder.h
deleted file mode 100644
index 5db0be5..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_response_builder.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "include/inquiry.h"
-#include "packets/packet_builder.h"
-#include "types/class_of_device.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class InquiryResponseBuilder : public PacketBuilder<true> {
- public:
- virtual ~InquiryResponseBuilder() = default;
-
- static std::unique_ptr<InquiryResponseBuilder> CreateStandard(uint8_t page_scan_repetition_mode,
- const ClassOfDevice& class_of_device,
- uint16_t clock_offset) {
- return std::unique_ptr<InquiryResponseBuilder>(new InquiryResponseBuilder(
- Inquiry::InquiryType::STANDARD, page_scan_repetition_mode, class_of_device, clock_offset));
- }
- static std::unique_ptr<InquiryResponseBuilder> CreateRssi(uint8_t page_scan_repetition_mode,
- const ClassOfDevice& class_of_device, uint16_t clock_offset,
- uint8_t rssi) {
- return std::unique_ptr<InquiryResponseBuilder>(new InquiryResponseBuilder(
- Inquiry::InquiryType::RSSI, page_scan_repetition_mode, class_of_device, clock_offset, rssi));
- }
- static std::unique_ptr<InquiryResponseBuilder> CreateExtended(uint8_t page_scan_repetition_mode,
- const ClassOfDevice& class_of_device,
- uint16_t clock_offset, uint8_t rssi,
- const std::vector<uint8_t>& extended_data) {
- return std::unique_ptr<InquiryResponseBuilder>(new InquiryResponseBuilder(
- Inquiry::InquiryType::EXTENDED, page_scan_repetition_mode, class_of_device, clock_offset, rssi, extended_data));
- }
-
- virtual size_t size() const override {
- size_t inquiry_size =
- sizeof(inquiry_type_) + sizeof(page_scan_repetition_mode_) + sizeof(class_of_device_) + sizeof(clock_offset_);
- if (inquiry_type_ == Inquiry::InquiryType::STANDARD) {
- return inquiry_size;
- }
- inquiry_size += sizeof(rssi_);
- if (inquiry_type_ == Inquiry::InquiryType::RSSI) {
- return inquiry_size;
- }
-
- return inquiry_size + extended_data_.size();
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(static_cast<uint8_t>(inquiry_type_), it);
- insert(page_scan_repetition_mode_, it);
- insert_class_of_device(class_of_device_, it);
- insert(clock_offset_, it);
- if (inquiry_type_ == Inquiry::InquiryType::STANDARD) {
- return;
- }
- insert(rssi_, it);
- if (inquiry_type_ == Inquiry::InquiryType::RSSI) {
- return;
- }
- insert_vector(extended_data_, it);
- }
-
- private:
- Inquiry::InquiryType inquiry_type_;
- uint8_t page_scan_repetition_mode_;
- ClassOfDevice class_of_device_;
- uint16_t clock_offset_;
- uint8_t rssi_{0xff};
- std::vector<uint8_t> extended_data_;
- explicit InquiryResponseBuilder(Inquiry::InquiryType inquiry_type, uint8_t page_scan_repetition_mode,
- const ClassOfDevice& class_of_device, uint16_t clock_offset)
- : inquiry_type_(inquiry_type), page_scan_repetition_mode_(page_scan_repetition_mode),
- class_of_device_(class_of_device), clock_offset_(clock_offset) {}
- explicit InquiryResponseBuilder(Inquiry::InquiryType inquiry_type, uint8_t page_scan_repetition_mode,
- const ClassOfDevice& class_of_device, uint16_t clock_offset, uint8_t rssi)
- : inquiry_type_(inquiry_type), page_scan_repetition_mode_(page_scan_repetition_mode),
- class_of_device_(class_of_device), clock_offset_(clock_offset), rssi_(rssi) {}
- explicit InquiryResponseBuilder(Inquiry::InquiryType inquiry_type, uint8_t page_scan_repetition_mode,
- const ClassOfDevice& class_of_device, uint16_t clock_offset, uint8_t rssi,
- const std::vector<uint8_t>& extended_data)
- : inquiry_type_(inquiry_type), page_scan_repetition_mode_(page_scan_repetition_mode),
- class_of_device_(class_of_device), clock_offset_(clock_offset), rssi_(rssi), extended_data_(extended_data) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_response_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_response_view.h
deleted file mode 100644
index f963134..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_response_view.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "include/inquiry.h"
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class InquiryResponseView : public PacketView<true> {
- public:
- InquiryResponseView(const InquiryResponseView&) = default;
- virtual ~InquiryResponseView() = default;
-
- static InquiryResponseView GetInquiryResponse(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::INQUIRY_RESPONSE);
- return InquiryResponseView(view.GetPayload());
- }
-
- Inquiry::InquiryType GetType() {
- return static_cast<Inquiry::InquiryType>(at(0));
- }
-
- uint8_t GetPageScanRepetitionMode() {
- return at(1);
- }
-
- ClassOfDevice GetClassOfDevice() {
- size_t offset = 2 * sizeof(uint8_t);
- return (begin() + offset).extract<ClassOfDevice>();
- }
-
- uint16_t GetClockOffset() {
- size_t offset = 2 * sizeof(uint8_t) + 3;
- return (begin() + offset).extract<uint16_t>();
- }
-
- uint8_t GetRssi() {
- size_t offset = 2 * sizeof(uint8_t) + 3 + sizeof(uint16_t);
- return at(offset);
- }
-
- Iterator<true> GetExtendedData() {
- size_t offset = 2 * sizeof(uint8_t) + 3 + sizeof(uint16_t) + sizeof(uint8_t);
- return begin() + offset;
- }
-
- private:
- InquiryResponseView() = delete;
- InquiryResponseView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_view.h
deleted file mode 100644
index ea8fac9..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/inquiry_view.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "inquiry.h"
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class InquiryView : public PacketView<true> {
- public:
- InquiryView(const InquiryView&) = default;
- virtual ~InquiryView() = default;
-
- static InquiryView GetInquiry(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::INQUIRY);
- return InquiryView(view.GetPayload());
- }
-
- Inquiry::InquiryType GetType() {
- return static_cast<Inquiry::InquiryType>(at(0));
- }
-
- private:
- InquiryView() = delete;
- InquiryView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_builder.h
deleted file mode 100644
index 16843d1..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_builder.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class IoCapabilityBuilder : public PacketBuilder<true> {
- public:
- virtual ~IoCapabilityBuilder() = default;
-
- static std::unique_ptr<IoCapabilityBuilder> Create(uint8_t io_capability, uint8_t oob_data_present,
- uint8_t authentication_requirements) {
- return std::unique_ptr<IoCapabilityBuilder>(
- new IoCapabilityBuilder(io_capability, oob_data_present, authentication_requirements));
- }
-
- virtual size_t size() const override {
- return sizeof(io_capability_) + sizeof(oob_data_present_) + sizeof(authentication_requirements_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(io_capability_, it);
- insert(oob_data_present_, it);
- insert(authentication_requirements_, it);
- }
-
- private:
- explicit IoCapabilityBuilder(uint8_t io_capability, uint8_t oob_data_present, uint8_t authentication_requirements)
- : io_capability_(io_capability), oob_data_present_(oob_data_present),
- authentication_requirements_(authentication_requirements) {}
- uint8_t io_capability_;
- uint8_t oob_data_present_;
- uint8_t authentication_requirements_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_negative_response_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_negative_response_builder.h
deleted file mode 100644
index cd86314..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_negative_response_builder.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class IoCapabilityNegativeResponseBuilder : public PacketBuilder<true> {
- public:
- virtual ~IoCapabilityNegativeResponseBuilder() = default;
-
- static std::unique_ptr<IoCapabilityNegativeResponseBuilder> Create(uint8_t reason) {
- return std::unique_ptr<IoCapabilityNegativeResponseBuilder>(new IoCapabilityNegativeResponseBuilder(reason));
- }
-
- virtual size_t size() const override {
- return sizeof(reason_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(reason_, it);
- }
-
- private:
- explicit IoCapabilityNegativeResponseBuilder(uint8_t reason) : reason_(reason) {}
- uint8_t reason_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_negative_response_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_negative_response_view.h
deleted file mode 100644
index 5997814..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_negative_response_view.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class IoCapabilityNegativeResponseView : public PacketView<true> {
- public:
- IoCapabilityNegativeResponseView(const IoCapabilityNegativeResponseView&) = default;
- virtual ~IoCapabilityNegativeResponseView() = default;
-
- static IoCapabilityNegativeResponseView GetIoCapabilityNegativeResponse(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::IO_CAPABILITY_NEGATIVE_RESPONSE);
- return IoCapabilityNegativeResponseView(view.GetPayload());
- }
-
- uint8_t GetReason() {
- return at(0);
- }
-
- private:
- IoCapabilityNegativeResponseView() = delete;
- IoCapabilityNegativeResponseView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_view.h
deleted file mode 100644
index 90a162c..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/io_capability_view.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class IoCapabilityView : public PacketView<true> {
- public:
- IoCapabilityView(const IoCapabilityView&) = default;
- virtual ~IoCapabilityView() = default;
-
- static IoCapabilityView GetIoCapability(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::IO_CAPABILITY_RESPONSE ||
- view.GetType() == Link::PacketType::IO_CAPABILITY_REQUEST);
- return IoCapabilityView(view.GetPayload());
- }
-
- uint8_t GetIoCapability() {
- return at(0);
- }
- uint8_t GetOobDataPresent() {
- return at(1);
- }
- uint8_t GetAuthenticationRequirements() {
- return at(2);
- }
-
- private:
- IoCapabilityView() = delete;
- IoCapabilityView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/le_advertisement_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/le_advertisement_builder.h
deleted file mode 100644
index 8c0e71b..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/le_advertisement_builder.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "include/le_advertisement.h"
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class LeAdvertisementBuilder : public PacketBuilder<true>, public LeAdvertisement {
- public:
- virtual ~LeAdvertisementBuilder() = default;
-
- static std::unique_ptr<LeAdvertisementBuilder> Create(AddressType address_type, AdvertisementType advertisement_type,
- const std::vector<uint8_t>& advertisement) {
- return std::unique_ptr<LeAdvertisementBuilder>(
- new LeAdvertisementBuilder(address_type, advertisement_type, advertisement));
- }
-
- virtual size_t size() const override {
- return sizeof(address_type_) + sizeof(advertisement_type_) + advertisement_.size();
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(static_cast<uint8_t>(address_type_), it);
- insert(static_cast<uint8_t>(advertisement_type_), it);
- insert_vector(advertisement_, it);
- }
-
- private:
- LeAdvertisementBuilder() = delete;
- explicit LeAdvertisementBuilder(AddressType address_type, AdvertisementType advertisement_type,
- const std::vector<uint8_t>& advertisement)
- : address_type_(address_type), advertisement_type_(advertisement_type), advertisement_(advertisement) {}
- AddressType address_type_;
- AdvertisementType advertisement_type_;
- std::vector<uint8_t> advertisement_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/le_advertisement_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/le_advertisement_view.h
deleted file mode 100644
index 574af28..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/le_advertisement_view.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "include/link.h"
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class LeAdvertisementView : public PacketView<true>, public LeAdvertisement {
- public:
- LeAdvertisementView(const LeAdvertisementView&) = default;
- virtual ~LeAdvertisementView() = default;
-
- static LeAdvertisementView GetLeAdvertisementView(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::LE_ADVERTISEMENT ||
- view.GetType() == Link::PacketType::LE_SCAN_RESPONSE);
- return LeAdvertisementView(view.GetPayload());
- }
-
- AddressType GetAddressType() {
- return static_cast<AddressType>(at(0));
- }
- AdvertisementType GetAdvertisementType() {
- return static_cast<AdvertisementType>(at(1));
- }
- Iterator<true> GetData() {
- return begin() + 2 * sizeof(uint8_t);
- }
-
- private:
- LeAdvertisementView() = delete;
- LeAdvertisementView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_builder.h
deleted file mode 100644
index f33fc42..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_builder.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class LeConnectBuilder : public PacketBuilder<true> {
- public:
- virtual ~LeConnectBuilder() = default;
-
- static std::unique_ptr<LeConnectBuilder> Create(uint16_t le_connection_interval_min,
- uint16_t le_connection_interval_max, uint16_t le_connection_latency,
- uint16_t le_connection_supervision_timeout,
- uint8_t peer_address_type) {
- return std::unique_ptr<LeConnectBuilder>(
- new LeConnectBuilder(le_connection_interval_min, le_connection_interval_max, le_connection_latency,
- le_connection_supervision_timeout, peer_address_type));
- }
-
- virtual size_t size() const override {
- return sizeof(le_connection_interval_min_) + sizeof(le_connection_interval_max_) + sizeof(le_connection_latency_) +
- sizeof(le_connection_supervision_timeout_) + sizeof(peer_address_type_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(le_connection_interval_min_, it);
- insert(le_connection_interval_max_, it);
- insert(le_connection_latency_, it);
- insert(le_connection_supervision_timeout_, it);
- insert(peer_address_type_, it);
- }
-
- private:
- explicit LeConnectBuilder(uint16_t le_connection_interval_min, uint16_t le_connection_interval_max,
- uint16_t le_connection_latency, uint16_t le_connection_supervision_timeout,
- uint8_t peer_address_type)
- : le_connection_interval_min_(le_connection_interval_min),
- le_connection_interval_max_(le_connection_interval_max), le_connection_latency_(le_connection_latency),
- le_connection_supervision_timeout_(le_connection_supervision_timeout), peer_address_type_(peer_address_type)
-
- {}
- uint16_t le_connection_interval_min_;
- uint16_t le_connection_interval_max_;
- uint16_t le_connection_latency_;
- uint16_t le_connection_supervision_timeout_;
- uint8_t peer_address_type_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_complete_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_complete_builder.h
deleted file mode 100644
index 379c3d4..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_complete_builder.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class LeConnectCompleteBuilder : public PacketBuilder<true> {
- public:
- virtual ~LeConnectCompleteBuilder() = default;
-
- static std::unique_ptr<LeConnectCompleteBuilder> Create(uint16_t le_connection_interval,
- uint16_t le_connection_latency,
- uint16_t le_connection_supervision_timeout,
- uint8_t peer_address_type) {
- return std::unique_ptr<LeConnectCompleteBuilder>(new LeConnectCompleteBuilder(
- le_connection_interval, le_connection_latency, le_connection_supervision_timeout, peer_address_type));
- }
-
- virtual size_t size() const override {
- return sizeof(le_connection_interval_) + sizeof(le_connection_latency_) +
- sizeof(le_connection_supervision_timeout_) + sizeof(peer_address_type_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(le_connection_interval_, it);
- insert(le_connection_latency_, it);
- insert(le_connection_supervision_timeout_, it);
- insert(peer_address_type_, it);
- }
-
- private:
- explicit LeConnectCompleteBuilder(uint16_t le_connection_interval, uint16_t le_connection_latency,
- uint16_t le_connection_supervision_timeout, uint8_t peer_address_type)
- : le_connection_interval_(le_connection_interval), le_connection_latency_(le_connection_latency),
- le_connection_supervision_timeout_(le_connection_supervision_timeout), peer_address_type_(peer_address_type)
-
- {}
- uint16_t le_connection_interval_;
- uint16_t le_connection_latency_;
- uint16_t le_connection_supervision_timeout_;
- uint8_t peer_address_type_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_complete_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_complete_view.h
deleted file mode 100644
index 88f5075..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_complete_view.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class LeConnectCompleteView : public PacketView<true> {
- public:
- LeConnectCompleteView(const LeConnectCompleteView&) = default;
- virtual ~LeConnectCompleteView() = default;
-
- static LeConnectCompleteView GetLeConnectComplete(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::LE_CONNECT_COMPLETE);
- return LeConnectCompleteView(view.GetPayload());
- }
-
- uint16_t GetLeConnectionInterval() {
- return begin().extract<uint16_t>();
- }
-
- uint16_t GetLeConnectionLatency() {
- return (begin() + 2).extract<uint16_t>();
- }
-
- uint16_t GetLeConnectionSupervisionTimeout() {
- return (begin() + 4).extract<uint16_t>();
- }
-
- uint8_t GetAddressType() {
- return (begin() + 6).extract<uint8_t>();
- }
-
- private:
- LeConnectCompleteView() = delete;
- LeConnectCompleteView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_view.h
deleted file mode 100644
index 3fca36e..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/le_connect_view.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class LeConnectView : public PacketView<true> {
- public:
- LeConnectView(const LeConnectView&) = default;
- virtual ~LeConnectView() = default;
-
- static LeConnectView GetLeConnect(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::LE_CONNECT);
- return LeConnectView(view.GetPayload());
- }
-
- uint16_t GetLeConnectionIntervalMin() {
- return begin().extract<uint16_t>();
- }
-
- uint16_t GetLeConnectionIntervalMax() {
- return (begin() + 2).extract<uint16_t>();
- }
-
- uint16_t GetLeConnectionLatency() {
- return (begin() + 4).extract<uint16_t>();
- }
-
- uint16_t GetLeConnectionSupervisionTimeout() {
- return (begin() + 6).extract<uint16_t>();
- }
-
- uint8_t GetAddressType() {
- return (begin() + 8).extract<uint8_t>();
- }
-
- private:
- LeConnectView() = delete;
- LeConnectView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_builder.cc b/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_builder.cc
deleted file mode 100644
index 816e444..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_builder.cc
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "link_layer_packet_builder.h"
-#include "link_layer_packet_view.h"
-
-using std::vector;
-
-namespace test_vendor_lib {
-
-namespace packets {
-
-LinkLayerPacketBuilder::LinkLayerPacketBuilder(Link::PacketType type, const Address& source, const Address& dest)
- : type_(type), source_addr_(source), dest_addr_(dest) {}
-
-LinkLayerPacketBuilder::LinkLayerPacketBuilder(Link::PacketType type, std::unique_ptr<PacketBuilder> packet,
- const Address& source)
- : type_(type), source_addr_(source), dest_addr_(Address::kEmpty), builder_(std::move(packet)) {}
-
-LinkLayerPacketBuilder::LinkLayerPacketBuilder(Link::PacketType type, std::unique_ptr<PacketBuilder> packet,
- const Address& source, const Address& dest)
- : type_(type), source_addr_(source), dest_addr_(dest), builder_(std::move(packet)) {}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapAcl(std::unique_ptr<ViewForwarderBuilder> acl,
- const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::ACL, std::move(acl), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapCommand(std::unique_ptr<CommandBuilder> command,
- const Address& source,
- const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::COMMAND, std::move(command), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapDisconnect(
- std::unique_ptr<DisconnectBuilder> disconnect, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::DISCONNECT, std::move(disconnect), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapEncryptConnection(
- std::unique_ptr<EncryptConnectionBuilder> encrypt_connection, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::ENCRYPT_CONNECTION, std::move(encrypt_connection), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapEncryptConnectionResponse(
- std::unique_ptr<EncryptConnectionBuilder> encrypt_connection, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(new LinkLayerPacketBuilder(
- Link::PacketType::ENCRYPT_CONNECTION_RESPONSE, std::move(encrypt_connection), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapInquiry(std::unique_ptr<InquiryBuilder> inquiry,
- const Address& source) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::INQUIRY, std::move(inquiry), source));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapInquiryResponse(
- std::unique_ptr<InquiryResponseBuilder> inquiry_response, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::INQUIRY_RESPONSE, std::move(inquiry_response), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapIoCapabilityRequest(
- std::unique_ptr<IoCapabilityBuilder> io_capability, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::IO_CAPABILITY_REQUEST, std::move(io_capability), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapIoCapabilityResponse(
- std::unique_ptr<IoCapabilityBuilder> io_capability, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::IO_CAPABILITY_RESPONSE, std::move(io_capability), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapIoCapabilityNegativeResponse(
- std::unique_ptr<IoCapabilityNegativeResponseBuilder> io_capability_negative_response, const Address& source,
- const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(new LinkLayerPacketBuilder(
- Link::PacketType::IO_CAPABILITY_NEGATIVE_RESPONSE, std::move(io_capability_negative_response), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapLeAdvertisement(
- std::unique_ptr<LeAdvertisementBuilder> advertisement, const Address& source) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::LE_ADVERTISEMENT, std::move(advertisement), source));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapLeConnect(std::unique_ptr<LeConnectBuilder> connect,
- const Address& source,
- const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::LE_CONNECT, std::move(connect), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapLeConnectComplete(
- std::unique_ptr<LeConnectCompleteBuilder> connect_complete, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::LE_CONNECT_COMPLETE, std::move(connect_complete), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapLeScan(const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(new LinkLayerPacketBuilder(Link::PacketType::LE_SCAN, source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapLeScanResponse(
- std::unique_ptr<LeAdvertisementBuilder> scan_response, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::LE_SCAN_RESPONSE, std ::move(scan_response), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapPage(std::unique_ptr<PageBuilder> page,
- const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::PAGE, std::move(page), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapPageReject(
- std::unique_ptr<PageRejectBuilder> page_reject, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::PAGE_REJECT, std::move(page_reject), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapPageResponse(
- std::unique_ptr<PageResponseBuilder> page_response, const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::PAGE_RESPONSE, std::move(page_response), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapResponse(std::unique_ptr<ResponseBuilder> response,
- const Address& source,
- const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::RESPONSE, std::move(response), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::WrapSco(std::unique_ptr<ViewForwarderBuilder> sco,
- const Address& source, const Address& dest) {
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(Link::PacketType::SCO, std::move(sco), source, dest));
-}
-
-std::shared_ptr<LinkLayerPacketBuilder> LinkLayerPacketBuilder::ReWrap(
- const std::shared_ptr<std::vector<uint8_t>> raw_packet) {
- LinkLayerPacketView received = LinkLayerPacketView::Create(raw_packet);
- Link::PacketType packet_type = received.GetType();
- Address source = received.GetSourceAddress();
- Address dest = received.GetDestinationAddress();
- PacketView<true> payload = received.GetPayload();
- std::unique_ptr<PacketBuilder> builder = ViewForwarderBuilder::Create(payload);
- return std::shared_ptr<LinkLayerPacketBuilder>(
- new LinkLayerPacketBuilder(packet_type, std::move(builder), source, dest));
-}
-
-size_t LinkLayerPacketBuilder::size() const {
- size_t builder_size = (builder_ ? builder_->size() : 0);
- return Link::kTypeBytes + Link::kSizeBytes + 2 * Address::kLength + builder_size;
-}
-
-void LinkLayerPacketBuilder::Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const {
- insert(static_cast<uint32_t>(size() - Link::kSizeBytes), it);
- insert(static_cast<uint8_t>(type_), it);
- insert_address(source_addr_.address, it);
- insert_address(dest_addr_.address, it);
- if (builder_) {
- builder_->Serialize(it);
- }
-}
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_builder.h
deleted file mode 100644
index 3101155..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_builder.h
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <string>
-#include <vector>
-
-#include "link.h"
-#include "packets/link_layer/command_builder.h"
-#include "packets/link_layer/disconnect_builder.h"
-#include "packets/link_layer/encrypt_connection_builder.h"
-#include "packets/link_layer/inquiry_builder.h"
-#include "packets/link_layer/inquiry_response_builder.h"
-#include "packets/link_layer/io_capability_builder.h"
-#include "packets/link_layer/io_capability_negative_response_builder.h"
-#include "packets/link_layer/le_advertisement_builder.h"
-#include "packets/link_layer/le_connect_builder.h"
-#include "packets/link_layer/le_connect_complete_builder.h"
-#include "packets/link_layer/page_builder.h"
-#include "packets/link_layer/page_reject_builder.h"
-#include "packets/link_layer/page_response_builder.h"
-#include "packets/link_layer/response_builder.h"
-#include "packets/link_layer/view_forwarder_builder.h"
-#include "packets/packet_builder.h"
-#include "types/address.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-// Link-layer packets are an abstraction of LMP PDUs.
-class LinkLayerPacketBuilder : PacketBuilder<true> {
- public:
- virtual ~LinkLayerPacketBuilder() = default;
-
- static std::shared_ptr<LinkLayerPacketBuilder> WrapAcl(std::unique_ptr<ViewForwarderBuilder> acl,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapCommand(std::unique_ptr<CommandBuilder> command,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapDisconnect(std::unique_ptr<DisconnectBuilder> disconnect,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapEncryptConnection(
- std::unique_ptr<EncryptConnectionBuilder> encrypt_connection, const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapEncryptConnectionResponse(
- std::unique_ptr<EncryptConnectionBuilder> encrypt_connection, const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapInquiry(std::unique_ptr<InquiryBuilder> inquiry,
- const Address& source);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapInquiryResponse(
- std::unique_ptr<InquiryResponseBuilder> inquiry_response, const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapIoCapabilityRequest(
- std::unique_ptr<IoCapabilityBuilder> io_capability, const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapIoCapabilityResponse(
- std::unique_ptr<IoCapabilityBuilder> io_capability, const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapIoCapabilityNegativeResponse(
- std::unique_ptr<IoCapabilityNegativeResponseBuilder> io_capability_negative_response, const Address& source,
- const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapLeAdvertisement(
- std::unique_ptr<LeAdvertisementBuilder> advertisement, const Address& source);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapLeConnect(std::unique_ptr<LeConnectBuilder> connect,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapLeConnectComplete(
- std::unique_ptr<LeConnectCompleteBuilder> connect_complete, const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapLeScan(const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapLeScanResponse(
- std::unique_ptr<LeAdvertisementBuilder> scan_response, const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapPage(std::unique_ptr<PageBuilder> page, const Address& source,
- const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapPageReject(std::unique_ptr<PageRejectBuilder> page_response,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapPageResponse(std::unique_ptr<PageResponseBuilder> page_response,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapResponse(const std::unique_ptr<ResponseBuilder> response,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> WrapSco(std::unique_ptr<ViewForwarderBuilder> sco,
- const Address& source, const Address& dest);
- static std::shared_ptr<LinkLayerPacketBuilder> ReWrap(const std::shared_ptr<std::vector<uint8_t>> raw_packet);
-
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override;
-
- virtual size_t size() const override;
-
- private:
- LinkLayerPacketBuilder(const LinkLayerPacketBuilder&) = delete;
- LinkLayerPacketBuilder() = delete;
- LinkLayerPacketBuilder(Link::PacketType type, const Address& source, const Address& dest);
- LinkLayerPacketBuilder(Link::PacketType type, std::unique_ptr<PacketBuilder> builder, const Address& source,
- const Address& dest);
- LinkLayerPacketBuilder(Link::PacketType type, std::unique_ptr<PacketBuilder> builder, const Address& source);
- Link::PacketType type_;
- Address source_addr_;
- Address dest_addr_;
- std::unique_ptr<PacketBuilder> builder_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_view.cc b/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_view.cc
deleted file mode 100644
index 31cbdbf..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_view.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "link_layer_packet_view.h"
-
-#include "os/log.h"
-
-namespace test_vendor_lib {
-constexpr size_t Link::kSizeBytes;
-constexpr size_t Link::kTypeBytes;
-
-namespace packets {
-LinkLayerPacketView::LinkLayerPacketView(std::shared_ptr<std::vector<uint8_t>> raw) : PacketView<true>(raw) {}
-
-LinkLayerPacketView LinkLayerPacketView::Create(std::shared_ptr<std::vector<uint8_t>> raw) {
- ASSERT(raw->size() >= Link::kSizeBytes + Link::kTypeBytes + 2 * Address::kLength);
- return LinkLayerPacketView(raw);
-}
-
-Link::PacketType LinkLayerPacketView::GetType() const {
- return static_cast<Link::PacketType>(at(Link::kSizeBytes));
-}
-
-Address LinkLayerPacketView::GetSourceAddress() const {
- size_t offset = Link::kSizeBytes + Link::kTypeBytes;
- return (begin() + offset).extract<Address>();
-}
-
-Address LinkLayerPacketView::GetDestinationAddress() const {
- size_t offset = Link::kSizeBytes + Link::kTypeBytes + Address::kLength;
- return (begin() + offset).extract<Address>();
-}
-
-PacketView<true> LinkLayerPacketView::GetPayload() const {
- return SubViewLittleEndian(Link::kSizeBytes + Link::kTypeBytes + 2 * Address::kLength, size());
-}
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_view.h
deleted file mode 100644
index bdbfaa7..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/link_layer_packet_view.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <string>
-#include <vector>
-
-#include "include/link.h"
-#include "packets/packet_view.h"
-#include "types/address.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-// Link-layer packets are an abstraction of LMP PDUs.
-class LinkLayerPacketView : public PacketView<true> {
- public:
- LinkLayerPacketView(const LinkLayerPacketView&) = default;
- virtual ~LinkLayerPacketView() = default;
-
- static LinkLayerPacketView Create(std::shared_ptr<std::vector<uint8_t>> raw);
-
- Link::PacketType GetType() const;
- Address GetSourceAddress() const;
- Address GetDestinationAddress() const;
- PacketView<true> GetPayload() const;
-
- private:
- LinkLayerPacketView() = delete;
- LinkLayerPacketView(std::shared_ptr<std::vector<uint8_t>> raw);
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/page_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/page_builder.h
deleted file mode 100644
index 9b219d7..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/page_builder.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-#include "types/class_of_device.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class PageBuilder : public PacketBuilder<true> {
- public:
- virtual ~PageBuilder() = default;
-
- static std::unique_ptr<PageBuilder> Create(const ClassOfDevice& class_of_device, uint8_t allow_role_switch) {
- return std::unique_ptr<PageBuilder>(new PageBuilder(class_of_device, allow_role_switch));
- }
-
- virtual size_t size() const override {
- return sizeof(class_of_device_) + sizeof(allow_role_switch_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert_class_of_device(class_of_device_, it);
- insert(allow_role_switch_, it);
- }
-
- private:
- explicit PageBuilder(const ClassOfDevice& class_of_device, uint8_t allow_role_switch)
- : class_of_device_(class_of_device), allow_role_switch_(allow_role_switch) {}
- ClassOfDevice class_of_device_;
- uint8_t allow_role_switch_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/page_reject_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/page_reject_builder.h
deleted file mode 100644
index ebf84d2..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/page_reject_builder.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class PageRejectBuilder : public PacketBuilder<true> {
- public:
- virtual ~PageRejectBuilder() = default;
-
- static std::unique_ptr<PageRejectBuilder> Create(uint8_t reason) {
- return std::unique_ptr<PageRejectBuilder>(new PageRejectBuilder(reason));
- }
-
- virtual size_t size() const override {
- return sizeof(reason_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(reason_, it);
- }
-
- private:
- explicit PageRejectBuilder(uint8_t reason) : reason_(reason) {}
- uint8_t reason_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/page_reject_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/page_reject_view.h
deleted file mode 100644
index 0c7611c..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/page_reject_view.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class PageRejectView : public PacketView<true> {
- public:
- PageRejectView(const PageRejectView&) = default;
- virtual ~PageRejectView() = default;
-
- static PageRejectView GetPageReject(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::PAGE_REJECT);
- return PageRejectView(view.GetPayload());
- }
-
- uint8_t GetReason() {
- return at(0);
- }
-
- private:
- PageRejectView() = delete;
- PageRejectView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/page_response_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/page_response_builder.h
deleted file mode 100644
index da7c853..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/page_response_builder.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class PageResponseBuilder : public PacketBuilder<true> {
- public:
- virtual ~PageResponseBuilder() = default;
-
- static std::unique_ptr<PageResponseBuilder> Create(uint8_t try_role_switch) {
- return std::unique_ptr<PageResponseBuilder>(new PageResponseBuilder(try_role_switch));
- }
-
- virtual size_t size() const override {
- return sizeof(try_role_switch_);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(try_role_switch_, it);
- }
-
- private:
- explicit PageResponseBuilder(uint8_t try_role_switch) : try_role_switch_(try_role_switch) {}
- uint8_t try_role_switch_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/page_response_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/page_response_view.h
deleted file mode 100644
index 1510528..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/page_response_view.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class PageResponseView : public PacketView<true> {
- public:
- PageResponseView(const PageResponseView&) = default;
- virtual ~PageResponseView() = default;
-
- static PageResponseView GetPageResponse(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::PAGE_RESPONSE);
- return PageResponseView(view.GetPayload());
- }
-
- uint8_t GetTryRoleSwitch() {
- return at(0);
- }
-
- private:
- PageResponseView() = delete;
- PageResponseView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/page_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/page_view.h
deleted file mode 100644
index 7f54b89..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/page_view.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class PageView : public PacketView<true> {
- public:
- PageView(const PageView&) = default;
- virtual ~PageView() = default;
-
- static PageView GetPage(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::PAGE);
- return PageView(view.GetPayload());
- }
-
- ClassOfDevice GetClassOfDevice() {
- return begin().extract<ClassOfDevice>();
- }
-
- uint8_t GetAllowRoleSwitch() {
- return at(3);
- }
-
- private:
- PageView() = delete;
- PageView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/response_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/response_builder.h
deleted file mode 100644
index 18f765d..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/response_builder.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-#include <vector>
-
-#include "packets/packet_builder.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class ResponseBuilder : public PacketBuilder<true> {
- public:
- virtual ~ResponseBuilder() = default;
-
- static std::unique_ptr<ResponseBuilder> Create(uint16_t opcode, const std::vector<uint64_t>& data) {
- return std::unique_ptr<ResponseBuilder>(new ResponseBuilder(opcode, data));
- }
-
- virtual size_t size() const override {
- return sizeof(opcode_) + data_.size() * sizeof(uint64_t);
- }
-
- protected:
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- insert(opcode_, it);
- insert_vector(data_, it);
- }
-
- private:
- explicit ResponseBuilder(uint16_t opcode, const std::vector<uint64_t> data) : opcode_(opcode), data_(data) {}
- uint16_t opcode_;
- std::vector<uint64_t> data_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/response_view.h b/vendor_libs/test_vendor_lib/packets/link_layer/response_view.h
deleted file mode 100644
index 60316a8..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/response_view.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-
-#include "packets/link_layer/link_layer_packet_view.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class ResponseView : public PacketView<true> {
- public:
- ResponseView(const ResponseView&) = default;
- virtual ~ResponseView() = default;
-
- static ResponseView GetResponse(const LinkLayerPacketView& view) {
- ASSERT(view.GetType() == Link::PacketType::RESPONSE);
- return ResponseView(view.GetPayload());
- }
-
- uint16_t GetOpcode() {
- return begin().extract<uint16_t>();
- }
-
- Iterator<true> GetResponseData() {
- return begin() + sizeof(uint16_t);
- }
-
- private:
- ResponseView() = delete;
- ResponseView(const PacketView<true>& view) : PacketView(view) {}
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer/view_forwarder_builder.h b/vendor_libs/test_vendor_lib/packets/link_layer/view_forwarder_builder.h
deleted file mode 100644
index 81f7b5b..0000000
--- a/vendor_libs/test_vendor_lib/packets/link_layer/view_forwarder_builder.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <cstdint>
-#include <memory>
-
-#include "packets/packet_builder.h"
-#include "packets/packet_view.h"
-
-namespace test_vendor_lib {
-namespace packets {
-
-class ViewForwarderBuilder : public PacketBuilder<true> {
- public:
- virtual ~ViewForwarderBuilder() = default;
-
- static std::unique_ptr<ViewForwarderBuilder> Create(PacketView<true> view) {
- return std::unique_ptr<ViewForwarderBuilder>(new ViewForwarderBuilder(view));
- }
-
- virtual size_t size() const override {
- return view_.size();
- }
-
- virtual void Serialize(std::back_insert_iterator<std::vector<uint8_t>> it) const override {
- for (size_t i = 0; i < view_.size(); i++) {
- insert(view_[i], it);
- }
- }
-
- private:
- explicit ViewForwarderBuilder(PacketView<true> view) : view_(view) {}
- PacketView<true> view_;
-};
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl b/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl
new file mode 100644
index 0000000..0194ab3
--- /dev/null
+++ b/vendor_libs/test_vendor_lib/packets/link_layer_packets.pdl
@@ -0,0 +1,171 @@
+little_endian_packets
+
+custom_field Address : 48 "types/"
+custom_field ClassOfDevice : 24 "types/"
+
+enum PacketType : 8 {
+ UNKNOWN = 0x00,
+ ACL = 0x01,
+ COMMAND = 0x02,
+ DISCONNECT = 0x03,
+ ENCRYPT_CONNECTION = 0x04,
+ ENCRYPT_CONNECTION_RESPONSE = 0x05,
+ EVENT = 0x06,
+ INQUIRY = 0x07,
+ INQUIRY_RESPONSE = 0x08,
+ IO_CAPABILITY_REQUEST = 0x09,
+ IO_CAPABILITY_RESPONSE = 0x0A,
+ IO_CAPABILITY_NEGATIVE_RESPONSE = 0x0B,
+ LE_ADVERTISEMENT = 0x0C,
+ LE_CONNECT = 0x0D,
+ LE_CONNECT_COMPLETE = 0x0E,
+ LE_SCAN = 0x0F,
+ LE_SCAN_RESPONSE = 0x10,
+ PAGE = 0x11,
+ PAGE_RESPONSE = 0x12,
+ PAGE_REJECT = 0x13,
+ RESPONSE = 0x14,
+ SCO = 0x15,
+}
+
+packet LinkLayerPacket {
+ type : PacketType,
+ source_address : Address,
+ destination_address : Address,
+ _body_,
+}
+
+packet AclPacket : LinkLayerPacket (type = ACL) {
+ _payload_,
+}
+
+packet Command : LinkLayerPacket (type = COMMAND) {
+ _payload_,
+}
+
+packet Disconnect : LinkLayerPacket (type = DISCONNECT) {
+ reason : 8,
+}
+
+packet EncryptConnection : LinkLayerPacket (type = ENCRYPT_CONNECTION) {
+ key : 8[],
+}
+
+packet EncryptConnectionResponse : LinkLayerPacket (type = ENCRYPT_CONNECTION_RESPONSE) {
+ key : 8[],
+}
+
+enum InquiryState : 8 {
+ STANDBY = 0x00,
+ INQUIRY = 0x01,
+}
+
+enum InquiryType : 8 {
+ STANDARD = 0x00,
+ RSSI = 0x01,
+ EXTENDED = 0x02,
+}
+
+packet Inquiry : LinkLayerPacket (type = INQUIRY) {
+ inquiry_type : InquiryType,
+}
+
+packet BasicInquiryResponse : LinkLayerPacket(type = INQUIRY_RESPONSE) {
+ inquiry_type : InquiryType,
+ page_scan_repetition_mode : 8,
+ class_of_device : ClassOfDevice,
+ clock_offset : 15,
+ _reserved_ : 1,
+ _body_,
+}
+
+packet InquiryResponse : BasicInquiryResponse (inquiry_type = STANDARD) {
+}
+
+packet InquiryResponseWithRssi : BasicInquiryResponse (inquiry_type = RSSI) {
+ rssi: 8,
+}
+
+packet ExtendedInquiryResponse : BasicInquiryResponse (inquiry_type = EXTENDED) {
+ rssi: 8,
+ extended_data : 8[],
+}
+
+packet IoCapabilityRequest : LinkLayerPacket (type = IO_CAPABILITY_REQUEST) {
+ io_capability : 8,
+ oob_data_present : 8,
+ authentication_requirements : 8,
+}
+
+packet IoCapabilityResponse : LinkLayerPacket (type = IO_CAPABILITY_RESPONSE) {
+ io_capability : 8,
+ oob_data_present : 8,
+ authentication_requirements : 8,
+}
+
+packet IoCapabilityNegativeResponse : LinkLayerPacket (type = IO_CAPABILITY_NEGATIVE_RESPONSE) {
+ reason : 8,
+}
+
+enum AddressType : 8 {
+ PUBLIC = 0,
+ RANDOM = 1,
+ PUBLIC_IDENTITY = 2,
+ RANDOM_IDENTITY = 3,
+}
+
+enum AdvertisementType : 8 {
+ ADV_IND = 0, // Connectable and scannable
+ ADV_DIRECT_IND = 1, // Connectable directed
+ ADV_SCAN_IND = 2, // Scannable undirected
+ ADV_NONCONN_IND = 3, // Non connectable undirected
+ SCAN_RESPONSE = 4,
+}
+
+packet LeAdvertisement : LinkLayerPacket (type = LE_ADVERTISEMENT) {
+ address_type : AddressType,
+ advertisement_type : AdvertisementType,
+ data : 8[],
+}
+
+packet LeConnect : LinkLayerPacket (type = LE_CONNECT) {
+ le_connection_interval_min : 16,
+ le_connection_interval_max : 16,
+ le_connection_latency : 16,
+ le_connection_supervision_timeout : 16,
+ address_type : 8,
+}
+
+packet LeConnectComplete : LinkLayerPacket (type = LE_CONNECT_COMPLETE) {
+ le_connection_interval : 16,
+ le_connection_latency : 16,
+ le_connection_supervision_timeout : 16,
+ address_type : 8,
+}
+
+packet LeScan : LinkLayerPacket (type = LE_SCAN) {
+}
+
+packet LeScanResponse : LinkLayerPacket (type = LE_SCAN_RESPONSE) {
+ address_type : AddressType,
+ advertisement_type : AdvertisementType,
+ data : 8[],
+}
+
+packet Page : LinkLayerPacket (type = PAGE) {
+ class_of_device : ClassOfDevice,
+ allow_role_switch : 8,
+}
+
+packet PageResponse : LinkLayerPacket (type = PAGE_RESPONSE) {
+ try_role_switch : 8,
+}
+
+packet PageReject : LinkLayerPacket (type = PAGE_REJECT) {
+ reason : 8,
+}
+
+packet Response : LinkLayerPacket (type = RESPONSE) {
+ opcode : 16,
+ _payload_,
+}
diff --git a/vendor_libs/test_vendor_lib/packets/packet_view.h b/vendor_libs/test_vendor_lib/packets/packet_view.h
index 16255fa..22c530a 100644
--- a/vendor_libs/test_vendor_lib/packets/packet_view.h
+++ b/vendor_libs/test_vendor_lib/packets/packet_view.h
@@ -32,6 +32,7 @@
class PacketView {
public:
PacketView(const std::forward_list<class View> fragments);
+ PacketView(std::shared_ptr<std::vector<uint8_t>> packet);
PacketView(const PacketView& PacketView) = default;
virtual ~PacketView() = default;
@@ -49,9 +50,6 @@
PacketView<false> SubViewBigEndian(size_t begin, size_t end) const;
- protected:
- PacketView(std::shared_ptr<std::vector<uint8_t>> packet);
-
private:
std::forward_list<View> fragments_;
size_t length_;
diff --git a/vendor_libs/test_vendor_lib/packets/test/link_layer_packet_builder_test.cc b/vendor_libs/test_vendor_lib/packets/test/link_layer_packet_builder_test.cc
deleted file mode 100644
index 3a14142..0000000
--- a/vendor_libs/test_vendor_lib/packets/test/link_layer_packet_builder_test.cc
+++ /dev/null
@@ -1,512 +0,0 @@
-/*
- * Copyright 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "packets/link_layer/link_layer_packet_builder.h"
-
-#include <gtest/gtest.h>
-#include <forward_list>
-#include <memory>
-
-#include "link.h"
-#include "packets/link_layer/command_view.h"
-#include "packets/link_layer/disconnect_view.h"
-#include "packets/link_layer/encrypt_connection_view.h"
-#include "packets/link_layer/inquiry_response_view.h"
-#include "packets/link_layer/inquiry_view.h"
-#include "packets/link_layer/io_capability_negative_response_view.h"
-#include "packets/link_layer/io_capability_view.h"
-#include "packets/link_layer/le_advertisement_view.h"
-#include "packets/link_layer/page_response_view.h"
-#include "packets/link_layer/page_view.h"
-#include "packets/link_layer/response_view.h"
-
-using std::vector;
-
-namespace {
-vector<uint8_t> count = {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
-};
-
-} // namespace
-
-namespace test_vendor_lib {
-namespace packets {
-
-class LinkLayerPacketBuilderTest : public ::testing::Test {
- public:
- LinkLayerPacketBuilderTest() = default;
- ~LinkLayerPacketBuilderTest() override = default;
-
- Address source_{{0x01, 0x02, 0x03, 0x04, 0x05, 0x06}};
- Address dest_{{0x11, 0x12, 0x13, 0x14, 0x15, 0x16}};
-};
-
-TEST_F(LinkLayerPacketBuilderTest, constructorTest) {
- uint8_t reason = 0xf2;
- auto disconnect = DisconnectBuilder::Create(reason);
- ASSERT_EQ(disconnect->size(), sizeof(reason));
- auto wrapped_disconnect = LinkLayerPacketBuilder::WrapDisconnect(std::move(disconnect), source_, dest_);
-
- size_t wrapped_size = sizeof(uint8_t) + sizeof(uint32_t) + 2 * sizeof(Address) + sizeof(reason);
- ASSERT_EQ(wrapped_disconnect->size(), wrapped_size);
- std::vector<uint8_t> wrapped_vect;
- std::back_insert_iterator<std::vector<uint8_t>> it(wrapped_vect);
- wrapped_disconnect->Serialize(it);
- ASSERT_EQ(wrapped_size, wrapped_vect.size());
-
- std::vector<uint8_t> hand_wrapped_vect;
- // Add the size
- hand_wrapped_vect.push_back(sizeof(uint8_t) + 2 * sizeof(Address) + sizeof(reason));
- hand_wrapped_vect.push_back(0);
- hand_wrapped_vect.push_back(0);
- hand_wrapped_vect.push_back(0);
-
- hand_wrapped_vect.push_back(static_cast<uint8_t>(Link::PacketType::DISCONNECT));
-
- for (auto byte : source_.address) {
- hand_wrapped_vect.push_back(byte);
- }
- for (auto byte : dest_.address) {
- hand_wrapped_vect.push_back(byte);
- }
- hand_wrapped_vect.push_back(reason);
- ASSERT_EQ(wrapped_vect, hand_wrapped_vect);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, disconnectTest) {
- uint8_t reason = 0x32;
- auto disconnect_builder = DisconnectBuilder::Create(reason);
- auto wrapped_disconnect = LinkLayerPacketBuilder::WrapDisconnect(std::move(disconnect_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_disconnect->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_disconnect->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::DISCONNECT);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- DisconnectView disconnect = DisconnectView::GetDisconnect(view);
- ASSERT_EQ(disconnect.GetReason(), reason);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, encryptConnectionTest) {
- std::vector<uint8_t> key = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
- auto encrypt_connection_builder = EncryptConnectionBuilder::Create(key);
- auto wrapped_encrypt_connection =
- LinkLayerPacketBuilder::WrapEncryptConnection(std::move(encrypt_connection_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_encrypt_connection->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_encrypt_connection->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::ENCRYPT_CONNECTION);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- EncryptConnectionView encrypt_connection = EncryptConnectionView::GetEncryptConnection(view);
- auto key_itr = encrypt_connection.GetKey();
- ASSERT_EQ(key_itr.NumBytesRemaining(), key.size());
- for (size_t i = 0; i < key.size(); i++) {
- ASSERT_EQ(key[i], key_itr.extract<uint8_t>());
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, encryptConnectionResponseTest) {
- std::vector<uint8_t> key = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
- auto encrypt_connection_builder = EncryptConnectionBuilder::Create(key);
- auto wrapped_encrypt_connection_response =
- LinkLayerPacketBuilder::WrapEncryptConnectionResponse(std::move(encrypt_connection_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_encrypt_connection_response->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_encrypt_connection_response->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::ENCRYPT_CONNECTION_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- EncryptConnectionView encrypt_connection = EncryptConnectionView::GetEncryptConnection(view);
- auto key_itr = encrypt_connection.GetKey();
- ASSERT_EQ(key_itr.NumBytesRemaining(), key.size());
- for (size_t i = 0; i < key.size(); i++) {
- ASSERT_EQ(key[i], key_itr.extract<uint8_t>());
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, inquiryTest) {
- Inquiry::InquiryType inquiry_type = Inquiry::InquiryType::RSSI;
- auto inquiry_builder = InquiryBuilder::Create(inquiry_type);
- auto wrapped_inquiry = LinkLayerPacketBuilder::WrapInquiry(std::move(inquiry_builder), source_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_inquiry->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_inquiry->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::INQUIRY);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(Address::kEmpty, view.GetDestinationAddress());
- ASSERT_EQ(InquiryView::GetInquiry(view).GetType(), inquiry_type);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, standardInquiryResponseTest) {
- uint8_t mode = 23;
- ClassOfDevice class_of_device{{0x11, 0x22, 0x33}};
- uint16_t offset = 0x3456;
- auto inquiry_response_builder = InquiryResponseBuilder::CreateStandard(mode, class_of_device, offset);
- auto wrapped_inquiry =
- LinkLayerPacketBuilder::WrapInquiryResponse(std::move(inquiry_response_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_inquiry->Serialize(it);
- ASSERT_EQ(packet_ptr->size(), 24u);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_inquiry->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::INQUIRY_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- ASSERT_EQ(view.GetPayload().size(), 7u);
- InquiryResponseView inquiry_response = InquiryResponseView::GetInquiryResponse(view);
- ASSERT_EQ(inquiry_response.GetClockOffset(), offset);
- ASSERT_EQ(inquiry_response.GetType(), Inquiry::InquiryType::STANDARD);
- ASSERT_EQ(inquiry_response.GetPageScanRepetitionMode(), mode);
- ASSERT_EQ(inquiry_response.GetClassOfDevice(), class_of_device);
- ASSERT_EQ(inquiry_response.GetClockOffset(), offset);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, rssiInquiryResponseTest) {
- uint8_t mode = 23;
- ClassOfDevice class_of_device{{0x11, 0x22, 0x33}};
- uint16_t offset = 0x3456;
- uint8_t rssi = 0x78;
- auto inquiry_response_builder = InquiryResponseBuilder::CreateRssi(mode, class_of_device, offset, rssi);
- auto wrapped_inquiry =
- LinkLayerPacketBuilder::WrapInquiryResponse(std::move(inquiry_response_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_inquiry->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_inquiry->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::INQUIRY_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- InquiryResponseView inquiry_response = InquiryResponseView::GetInquiryResponse(view);
- ASSERT_EQ(inquiry_response.GetClockOffset(), offset);
- ASSERT_EQ(inquiry_response.GetType(), Inquiry::InquiryType::RSSI);
- ASSERT_EQ(inquiry_response.GetPageScanRepetitionMode(), mode);
- ASSERT_EQ(inquiry_response.GetClassOfDevice(), class_of_device);
- ASSERT_EQ(inquiry_response.GetClockOffset(), offset);
- ASSERT_EQ(inquiry_response.GetRssi(), rssi);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, extendedInquiryResponseTest) {
- uint8_t mode = 23;
- ClassOfDevice class_of_device{{0x11, 0x22, 0x33}};
- uint16_t offset = 0x3456;
- uint8_t rssi = 0x78;
- auto inquiry_response_builder = InquiryResponseBuilder::CreateExtended(mode, class_of_device, offset, rssi, count);
- auto wrapped_inquiry =
- LinkLayerPacketBuilder::WrapInquiryResponse(std::move(inquiry_response_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_inquiry->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_inquiry->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::INQUIRY_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- InquiryResponseView inquiry_response = InquiryResponseView::GetInquiryResponse(view);
- ASSERT_EQ(inquiry_response.GetClockOffset(), offset);
- ASSERT_EQ(inquiry_response.GetType(), Inquiry::InquiryType::EXTENDED);
- ASSERT_EQ(inquiry_response.GetPageScanRepetitionMode(), mode);
- ASSERT_EQ(inquiry_response.GetClassOfDevice(), class_of_device);
- ASSERT_EQ(inquiry_response.GetClockOffset(), offset);
- ASSERT_EQ(inquiry_response.GetRssi(), rssi);
- auto ext_it = inquiry_response.GetExtendedData();
- ASSERT_EQ(ext_it.NumBytesRemaining(), count.size());
- for (size_t i = 0; i < count.size(); i++) {
- ASSERT_EQ(count[i], *(ext_it++));
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, ioCapabilityRequestTest) {
- uint8_t io_cap = 0x2;
- uint8_t oob_data_present = 0x1;
- uint8_t authentication_requirements = 0x5;
- auto io_capability_builder = IoCapabilityBuilder::Create(io_cap, oob_data_present, authentication_requirements);
- auto wrapped_io_capability_request =
- LinkLayerPacketBuilder::WrapIoCapabilityRequest(std::move(io_capability_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_io_capability_request->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_io_capability_request->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::IO_CAPABILITY_REQUEST);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- IoCapabilityView io_capability = IoCapabilityView::GetIoCapability(view);
- ASSERT_EQ(io_capability.GetIoCapability(), io_cap);
- ASSERT_EQ(io_capability.GetOobDataPresent(), oob_data_present);
- ASSERT_EQ(io_capability.GetAuthenticationRequirements(), authentication_requirements);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, ioCapabilityResponseTest) {
- uint8_t io_cap = 0x2;
- uint8_t oob_data_present = 0x1;
- uint8_t authentication_requirements = 0x5;
- auto io_capability_builder = IoCapabilityBuilder::Create(io_cap, oob_data_present, authentication_requirements);
- auto wrapped_io_capability_response =
- LinkLayerPacketBuilder::WrapIoCapabilityResponse(std::move(io_capability_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_io_capability_response->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_io_capability_response->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::IO_CAPABILITY_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- IoCapabilityView io_capability = IoCapabilityView::GetIoCapability(view);
- ASSERT_EQ(io_capability.GetIoCapability(), io_cap);
- ASSERT_EQ(io_capability.GetOobDataPresent(), oob_data_present);
- ASSERT_EQ(io_capability.GetAuthenticationRequirements(), authentication_requirements);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, ioCapabilityNegativeResponseTest) {
- uint8_t reason = 23;
- auto io_capability_negative_response_builder = IoCapabilityNegativeResponseBuilder::Create(reason);
- auto wrapped_io_capability_negative_response = LinkLayerPacketBuilder::WrapIoCapabilityNegativeResponse(
- std::move(io_capability_negative_response_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_io_capability_negative_response->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_io_capability_negative_response->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::IO_CAPABILITY_NEGATIVE_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- IoCapabilityNegativeResponseView io_capability_negative_response =
- IoCapabilityNegativeResponseView::GetIoCapabilityNegativeResponse(view);
- ASSERT_EQ(io_capability_negative_response.GetReason(), reason);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, pageTest) {
- uint8_t allow_role_switch = 1;
- ClassOfDevice class_of_device{{0x11, 0x22, 0x33}};
- auto page_builder = PageBuilder::Create(class_of_device, allow_role_switch);
- auto wrapped_page = LinkLayerPacketBuilder::WrapPage(std::move(page_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_page->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_page->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::PAGE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- PageView page = PageView::GetPage(view);
- ASSERT_EQ(page.GetAllowRoleSwitch(), allow_role_switch);
- ASSERT_EQ(page.GetClassOfDevice(), class_of_device);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, pageResponseTest) {
- uint8_t try_role_switch = 2;
- auto page_response_builder = PageResponseBuilder::Create(try_role_switch);
- auto wrapped_page_response =
- LinkLayerPacketBuilder::WrapPageResponse(std::move(page_response_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_page_response->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_page_response->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::PAGE_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- PageResponseView page_response = PageResponseView::GetPageResponse(view);
- ASSERT_EQ(page_response.GetTryRoleSwitch(), try_role_switch);
-}
-
-TEST_F(LinkLayerPacketBuilderTest, responseTest) {
- uint16_t opcode = 0x1234;
- std::vector<uint64_t> data{
- 0x7060504030201000, 0x7161514131211101, 0x7262524232221202, 0x7363534333231303,
- 0x7464544434241404, 0x7565554535251505, 0x7666564636261606, 0x7767574737271707,
- 0x7868584838281808, 0x7969594939291909, 0x7a6a5a4a3a2a1a0a, 0x7b6b5b4b3b2b1b0b,
- 0x7c6c5c4c3c2c1c0c, 0x7d6d5d4d3d2d1d0d, 0x7e6e5e4e3e2e1e0e, 0x7f6f5f4f3f2f1f0f,
- };
- auto response_builder = ResponseBuilder::Create(opcode, data);
- auto wrapped_response = LinkLayerPacketBuilder::WrapResponse(std::move(response_builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_response->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_response->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- ResponseView response = ResponseView::GetResponse(view);
- ASSERT_EQ(opcode, response.GetOpcode());
- auto data_it = response.GetResponseData();
- ASSERT_EQ(data.size(), data_it.NumBytesRemaining() / sizeof(uint64_t));
- ASSERT_EQ(0u, data_it.NumBytesRemaining() % sizeof(uint64_t));
- for (size_t i = 0; i < data.size(); i++) {
- ASSERT_EQ(data[i], data_it.extract<uint64_t>());
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, wrapAclTest) {
- std::shared_ptr<std::vector<uint8_t>> count_shared = std::make_shared<std::vector<uint8_t>>(count);
- View count_view(count_shared, 0, count_shared->size());
- PacketView<true> count_packet_view({count_view});
- auto builder = ViewForwarderBuilder::Create(count_packet_view);
- auto wrapped_acl = LinkLayerPacketBuilder::WrapAcl(std::move(builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_acl->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_acl->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::ACL);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- auto acl_view = view.GetPayload();
- ASSERT_EQ(acl_view.size(), count_view.size());
- for (size_t i = 0; i < count_view.size(); i++) {
- ASSERT_EQ(acl_view[i], count_view[i]);
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, wrapCommandTest) {
- uint16_t opcode = 0x0102;
- std::shared_ptr<std::vector<uint8_t>> count_shared = std::make_shared<std::vector<uint8_t>>(count);
- View count_view(count_shared, 0, count_shared->size());
- PacketView<true> args({count_view});
- auto builder = CommandBuilder::Create(opcode, args);
- auto wrapped_command = LinkLayerPacketBuilder::WrapCommand(std::move(builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_command->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_command->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::COMMAND);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- auto command_view = CommandView::GetCommand(view);
- ASSERT_EQ(opcode, command_view.GetOpcode());
- auto args_itr = command_view.GetData();
- ASSERT_EQ(args_itr.NumBytesRemaining(), count.size());
- for (size_t i = 0; i < count.size(); i++) {
- ASSERT_EQ(*args_itr++, count[i]);
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, wrapLeAdvertisementTest) {
- LeAdvertisement::AddressType address_type = LeAdvertisement::AddressType::RANDOM;
- LeAdvertisement::AdvertisementType advertisement_type = LeAdvertisement::AdvertisementType::ADV_NONCONN_IND;
- auto builder = LeAdvertisementBuilder::Create(address_type, advertisement_type, count);
- auto wrapped_le_advertisement = LinkLayerPacketBuilder::WrapLeAdvertisement(std::move(builder), source_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_le_advertisement->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_le_advertisement->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::LE_ADVERTISEMENT);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(Address::kEmpty, view.GetDestinationAddress());
- LeAdvertisementView le_advertisement_view = LeAdvertisementView::GetLeAdvertisementView(view);
- ASSERT_EQ(address_type, le_advertisement_view.GetAddressType());
- ASSERT_EQ(advertisement_type, le_advertisement_view.GetAdvertisementType());
- auto le_advertisement_itr = le_advertisement_view.GetData();
- ASSERT_EQ(le_advertisement_itr.NumBytesRemaining(), count.size());
- for (size_t i = 0; i < count.size(); i++) {
- ASSERT_EQ(*(le_advertisement_itr++), count[i]);
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, wrapLeScanTest) {
- auto le_scan = LinkLayerPacketBuilder::WrapLeScan(source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- le_scan->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), le_scan->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::LE_SCAN);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- auto le_scan_view = view.GetPayload();
- ASSERT_EQ(0u, le_scan_view.size());
-}
-
-TEST_F(LinkLayerPacketBuilderTest, wrapLeScanResponseTest) {
- LeAdvertisement::AddressType address_type = LeAdvertisement::AddressType::PUBLIC_IDENTITY;
- LeAdvertisement::AdvertisementType advertisement_type = LeAdvertisement::AdvertisementType::SCAN_RESPONSE;
- auto builder = LeAdvertisementBuilder::Create(address_type, advertisement_type, count);
- auto wrapped_scan_response = LinkLayerPacketBuilder::WrapLeScanResponse(std::move(builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_scan_response->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_scan_response->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::LE_SCAN_RESPONSE);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- LeAdvertisementView le_advertisement_view = LeAdvertisementView::GetLeAdvertisementView(view);
- ASSERT_EQ(address_type, le_advertisement_view.GetAddressType());
- ASSERT_EQ(advertisement_type, le_advertisement_view.GetAdvertisementType());
- auto scan_response_itr = le_advertisement_view.GetData();
- ASSERT_EQ(scan_response_itr.NumBytesRemaining(), count.size());
- for (size_t i = 0; i < count.size(); i++) {
- ASSERT_EQ((*scan_response_itr++), count[i]);
- }
-}
-
-TEST_F(LinkLayerPacketBuilderTest, wrapScoTest) {
- std::shared_ptr<std::vector<uint8_t>> count_shared = std::make_shared<std::vector<uint8_t>>(count);
- View count_view(count_shared, 0, count_shared->size());
- PacketView<true> count_packet_view({count_view});
- auto builder = ViewForwarderBuilder::Create(count_packet_view);
- auto wrapped_sco = LinkLayerPacketBuilder::WrapSco(std::move(builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_sco->Serialize(it);
-
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
- ASSERT_EQ(view.size(), wrapped_sco->size());
- ASSERT_EQ(view.GetType(), Link::PacketType::SCO);
- ASSERT_EQ(source_, view.GetSourceAddress());
- ASSERT_EQ(dest_, view.GetDestinationAddress());
- auto sco_view = view.GetPayload();
- ASSERT_EQ(sco_view.size(), count.size());
- for (size_t i = 0; i < count.size(); i++) {
- ASSERT_EQ(sco_view[i], count[i]);
- }
-}
-
-} // namespace packets
-} // namespace test_vendor_lib
diff --git a/vendor_libs/test_vendor_lib/test/link_layer_socket_device_test.cc b/vendor_libs/test_vendor_lib/test/link_layer_socket_device_test.cc
index 0ddd2fc..5b4ee49 100644
--- a/vendor_libs/test_vendor_lib/test/link_layer_socket_device_test.cc
+++ b/vendor_libs/test_vendor_lib/test/link_layer_socket_device_test.cc
@@ -27,11 +27,8 @@
#include <sys/types.h>
#include <unistd.h>
-#include "include/link.h"
#include "model/setup/async_manager.h"
#include "packets/link_layer/command_view.h"
-#include "packets/link_layer/link_layer_packet_builder.h"
-#include "packets/link_layer/link_layer_packet_view.h"
std::vector<uint8_t> count = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
@@ -185,14 +182,7 @@
LinkLayerPacketView NextPacket() {
std::shared_ptr<std::vector<uint8_t>> count_shared = std::make_shared<std::vector<uint8_t>>(count);
- View count_view(count_shared, 0, count_shared->size());
- PacketView<true> args({count_view});
- auto builder = CommandBuilder::Create(packet_id_++, args);
- auto wrapped_command = LinkLayerPacketBuilder::WrapCommand(std::move(builder), source_, dest_);
- std::shared_ptr<std::vector<uint8_t>> packet_ptr = std::make_shared<std::vector<uint8_t>>();
- std::back_insert_iterator<std::vector<uint8_t>> it(*packet_ptr);
- wrapped_command->Serialize(it);
- LinkLayerPacketView view = LinkLayerPacketView::Create(packet_ptr);
+ LinkLayerPacketView view = LinkLayerPacketView::Create(count_shared);
return view;
}
diff --git a/vendor_libs/test_vendor_lib/types/address.h b/vendor_libs/test_vendor_lib/types/address.h
index 1aa8c97..12e2dbb 100644
--- a/vendor_libs/test_vendor_lib/types/address.h
+++ b/vendor_libs/test_vendor_lib/types/address.h
@@ -20,6 +20,9 @@
#include <string>
+namespace bluetooth {
+namespace types {
+
/** Bluetooth Address */
class Address final {
public:
@@ -74,3 +77,8 @@
os << a.ToString();
return os;
}
+
+} // namespace types
+} // namespace bluetooth
+
+using ::bluetooth::types::Address; // TODO, remove
diff --git a/vendor_libs/test_vendor_lib/types/class_of_device.h b/vendor_libs/test_vendor_lib/types/class_of_device.h
index 8c2ab37..4c37ebf 100644
--- a/vendor_libs/test_vendor_lib/types/class_of_device.h
+++ b/vendor_libs/test_vendor_lib/types/class_of_device.h
@@ -20,6 +20,9 @@
#include <string>
+namespace bluetooth {
+namespace types {
+
/** Bluetooth Class of Device */
class ClassOfDevice final {
public:
@@ -52,3 +55,8 @@
os << c.ToString();
return os;
}
+
+} // namespace types
+} // namespace bluetooth
+
+using ::bluetooth::types::ClassOfDevice; // TODO, remove
\ No newline at end of file