Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae1cdd13 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "RootCanal: Remove AclPacketBuilder and ScoPacketBuilder"

parents f3198a93 77c621a4
Loading
Loading
Loading
Loading
+15 −6
Original line number Diff line number Diff line
@@ -26,9 +26,8 @@
#include "packet/raw_builder.h"

#include "hci.h"
#include "packets/hci/acl_packet_view.h"
#include "packets/hci/command_packet_view.h"
#include "packets/hci/sco_packet_view.h"
#include "packets/packet_view.h"

using std::vector;
using test_vendor_lib::hci::EventCode;
@@ -234,7 +233,9 @@ void DualModeController::RegisterTaskCancel(std::function<void(AsyncTaskId)> tas
}

void DualModeController::HandleAcl(std::shared_ptr<std::vector<uint8_t>> packet) {
  auto acl_packet = packets::AclPacketView::Create(packet);
  bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(packet);
  auto acl_packet = bluetooth::hci::AclPacketView::Create(raw_packet);
  ASSERT(acl_packet.IsValid());
  if (loopback_mode_ == hci::LoopbackMode::LOCAL) {
    uint16_t handle = acl_packet.GetHandle();

@@ -253,7 +254,8 @@ void DualModeController::HandleAcl(std::shared_ptr<std::vector<uint8_t>> packet)
}

void DualModeController::HandleSco(std::shared_ptr<std::vector<uint8_t>> packet) {
  auto sco_packet = packets::ScoPacketView::Create(packet);
  bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(packet);
  auto sco_packet = bluetooth::hci::ScoPacketView::Create(raw_packet);
  if (loopback_mode_ == hci::LoopbackMode::LOCAL) {
    uint16_t handle = sco_packet.GetHandle();
    send_sco_(packet);
@@ -314,8 +316,15 @@ void DualModeController::RegisterEventChannel(

void DualModeController::RegisterAclChannel(
    const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) {
  link_layer_controller_.RegisterAclChannel(callback);
  send_acl_ = callback;
  send_acl_ =
      [callback](std::shared_ptr<bluetooth::hci::AclPacketBuilder> acl_data) {
        auto bytes = std::make_shared<std::vector<uint8_t>>();
        bluetooth::packet::BitInserter bit_inserter(*bytes);
        bytes->reserve(acl_data->size());
        acl_data->Serialize(bit_inserter);
        callback(std::move(bytes));
      };
  link_layer_controller_.RegisterAclChannel(send_acl_);
}

void DualModeController::RegisterScoChannel(
+2 −1
Original line number Diff line number Diff line
@@ -435,7 +435,8 @@ class DualModeController : public Device {
  void SendCommandCompleteUnknownOpCodeEvent(uint16_t command_opcode) const;

  // Callbacks to send packets back to the HCI.
  std::function<void(std::shared_ptr<std::vector<uint8_t>>)> send_acl_;
  std::function<void(std::shared_ptr<bluetooth::hci::AclPacketBuilder>)>
      send_acl_;
  std::function<void(std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>
      send_event_;
  std::function<void(std::shared_ptr<std::vector<uint8_t>>)> send_sco_;
+22 −14
Original line number Diff line number Diff line
@@ -19,9 +19,7 @@
#include "hci.h"
#include "include/le_advertisement.h"
#include "os/log.h"
#include "packets/hci/acl_packet_builder.h"
#include "packets/hci/command_packet_view.h"
#include "packets/hci/sco_packet_builder.h"
#include "packets/raw_builder.h"

#include "packet/raw_builder.h"
@@ -115,7 +113,8 @@ bluetooth::hci::ErrorCode LinkLayerController::SendCommandToRemoteByHandle(
                                      connections_.GetAddress(handle));
}

hci::Status LinkLayerController::SendAclToRemote(AclPacketView acl_packet) {
hci::Status LinkLayerController::SendAclToRemote(
    bluetooth::hci::AclPacketView acl_packet) {
  uint16_t handle = acl_packet.GetHandle();
  if (!connections_.HasHandle(handle)) {
    return hci::Status::UNKNOWN_CONNECTION;
@@ -149,8 +148,8 @@ hci::Status LinkLayerController::SendAclToRemote(AclPacketView acl_packet) {

  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);
      (static_cast<uint16_t>(acl_packet.GetPacketBoundaryFlag()) << 12) +
      (static_cast<uint16_t>(acl_packet.GetBroadcastFlag()) << 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);
@@ -288,18 +287,26 @@ void LinkLayerController::IncomingAclPacket(
  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);
  bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(
      payload_bytes);
  auto acl_view = bluetooth::hci::AclPacketView::Create(raw_packet);
  ASSERT(acl_view.IsValid());

  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<RawBuilder> builder = std::make_unique<RawBuilder>();
  std::vector<uint8_t> raw_data(acl_view.GetPayload().begin(),
  std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
      std::make_unique<bluetooth::packet::RawBuilder>();
  std::vector<uint8_t> payload_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());
  raw_builder_ptr->AddOctets(payload_data);

  auto acl_packet = bluetooth::hci::AclPacketBuilder::Create(
      local_handle, acl_view.GetPacketBoundaryFlag(),
      acl_view.GetBroadcastFlag(), std::move(raw_builder_ptr));

  send_acl_(std::move(acl_packet));
}

void LinkLayerController::IncomingRemoteNameRequest(
@@ -958,7 +965,8 @@ void LinkLayerController::RegisterEventChannel(
}

void LinkLayerController::RegisterAclChannel(
    const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) {
    const std::function<
        void(std::shared_ptr<bluetooth::hci::AclPacketBuilder>)>& callback) {
  send_acl_ = callback;
}

+8 −6
Original line number Diff line number Diff line
@@ -24,9 +24,8 @@
#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_packets.h"
#include "packets/packet_view.h"
#include "security_manager.h"

namespace test_vendor_lib {
@@ -44,8 +43,8 @@ class LinkLayerController {
  bluetooth::hci::ErrorCode SendCommandToRemoteByHandle(
      bluetooth::hci::OpCode opcode, packets::PacketView<true> args,
      uint16_t handle);
  hci::Status SendScoToRemote(packets::ScoPacketView sco_packet);
  hci::Status SendAclToRemote(packets::AclPacketView acl_packet);
  hci::Status SendScoToRemote(bluetooth::hci::ScoPacketView sco_packet);
  hci::Status SendAclToRemote(bluetooth::hci::AclPacketView acl_packet);

  void WriteSimplePairingMode(bool enabled);
  void StartSimplePairing(const Address& address);
@@ -108,7 +107,9 @@ class LinkLayerController {
      const std::function<void(
          std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>& send_event);

  void RegisterAclChannel(const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_acl);
  void RegisterAclChannel(
      const std::function<
          void(std::shared_ptr<bluetooth::hci::AclPacketBuilder>)>& send_acl);

  void RegisterScoChannel(const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& send_sco);

@@ -327,7 +328,8 @@ class LinkLayerController {
  std::function<void(AsyncTaskId)> cancel_task_;

  // Callbacks to send packets back to the HCI.
  std::function<void(std::shared_ptr<std::vector<uint8_t>>)> send_acl_;
  std::function<void(std::shared_ptr<bluetooth::hci::AclPacketBuilder>)>
      send_acl_;
  std::function<void(std::shared_ptr<bluetooth::hci::EventPacketBuilder>)>
      send_event_;
  std::function<void(std::shared_ptr<std::vector<uint8_t>>)> send_sco_;
+2 −1
Original line number Diff line number Diff line
@@ -31,7 +31,8 @@ CarKit::CarKit() : Device(kCarKitPropertiesFile) {
  page_scan_delay_ms_ = std::chrono::milliseconds(600);

  // Stub in packet handling for now
  link_layer_controller_.RegisterAclChannel([](std::shared_ptr<std::vector<uint8_t>>) {});
  link_layer_controller_.RegisterAclChannel(
      [](std::shared_ptr<bluetooth::hci::AclPacketBuilder>) {});
  link_layer_controller_.RegisterEventChannel(
      [](std::shared_ptr<bluetooth::hci::EventPacketBuilder>) {});
  link_layer_controller_.RegisterScoChannel([](std::shared_ptr<std::vector<uint8_t>>) {});
Loading