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

Commit 29634f79 authored by Chris Manton's avatar Chris Manton Committed by Automerger Merge Worker
Browse files

Add main/shim/helpers::MakeLegacyBtHdrPacket am: 8ddf4045

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1460808

Change-Id: I155880a6a848ee91d53e5b4310b497834d97cda4
parents ffd37e4d 8ddf4045
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: