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

Commit 8ddf4045 authored by Chris Manton's avatar Chris Manton
Browse files

Add main/shim/helpers::MakeLegacyBtHdrPacket

Bug: 166280067
Tag: #refactor
Test: act.py -tc BleCocTest
Test: ble paired 2 phones
Test: classic paired Bose SoundLink

Change-Id: Idc3083dbd8639b416880dbb8b07667a9356e82ed
parent d881ba40
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@
#include "hci/address_with_type.h"

#include "gd/packet/raw_builder.h"
#include "osi/include/allocator.h"
#include "stack/include/bt_types.h"
#include "stack/include/hci_error_code.h"

@@ -101,6 +102,20 @@ inline std::unique_ptr<bluetooth::packet::RawBuilder> MakeUniquePacket(
  return payload;
}

inline BT_HDR* MakeLegacyBtHdrPacket(
    std::unique_ptr<bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian>>
        packet,
    const std::vector<uint8_t>& preamble) {
  std::vector<uint8_t> packet_vector(packet->begin(), packet->end());
  BT_HDR* buffer = static_cast<BT_HDR*>(
      osi_calloc(packet_vector.size() + preamble.size() + sizeof(BT_HDR)));
  std::copy(preamble.begin(), preamble.end(), buffer->data);
  std::copy(packet_vector.begin(), packet_vector.end(),
            buffer->data + preamble.size());
  buffer->len = preamble.size() + packet_vector.size();
  return buffer;
}

inline tHCI_STATUS ToLegacyHciErrorCode(hci::ErrorCode reason) {
  switch (reason) {
    case hci::ErrorCode::SUCCESS: