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

Commit a6b8e5af authored by Myles Watson's avatar Myles Watson Committed by android-build-merger
Browse files

Bluetooth: Use fixed-size preambles

am: 71390182

Change-Id: I764ed03fcefd7d9f224962d01669001cb6f4d73b
parents 257a7d98 71390182
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -49,11 +49,10 @@ const size_t packet_length_offset_for_type[] = {
    0, HCI_LENGTH_OFFSET_CMD, HCI_LENGTH_OFFSET_ACL, HCI_LENGTH_OFFSET_SCO,
    HCI_LENGTH_OFFSET_EVT};

size_t HciGetPacketLengthForType(HciPacketType type,
                                 const hidl_vec<uint8_t>& packet) {
size_t HciGetPacketLengthForType(HciPacketType type, const uint8_t* preamble) {
  size_t offset = packet_length_offset_for_type[type];
  if (type != HCI_PACKET_TYPE_ACL_DATA) return packet[offset];
  return (((packet[offset + 1]) << 8) | packet[offset]);
  if (type != HCI_PACKET_TYPE_ACL_DATA) return preamble[offset];
  return (((preamble[offset + 1]) << 8) | preamble[offset]);
}

HC_BT_HDR* WrapPacketAndCopy(uint16_t event, const hidl_vec<uint8_t>& data) {
@@ -307,7 +306,6 @@ void VendorInterface::OnDataReady(int fd) {
            hci_packet_type_ <= HCI_PACKET_TYPE_EVENT)
          << "buffer[0] = " << static_cast<unsigned int>(buffer[0]);
      hci_parser_state_ = HCI_TYPE_READY;
      hci_packet_.resize(HCI_PREAMBLE_SIZE_MAX);
      hci_packet_bytes_remaining_ = preamble_size_for_type[hci_packet_type_];
      hci_packet_bytes_read_ = 0;
      break;
@@ -315,16 +313,18 @@ void VendorInterface::OnDataReady(int fd) {

    case HCI_TYPE_READY: {
      size_t bytes_read = TEMP_FAILURE_RETRY(
          read(fd, hci_packet_.data() + hci_packet_bytes_read_,
          read(fd, hci_packet_preamble_ + hci_packet_bytes_read_,
               hci_packet_bytes_remaining_));
      CHECK(bytes_read > 0);
      hci_packet_bytes_remaining_ -= bytes_read;
      hci_packet_bytes_read_ += bytes_read;
      if (hci_packet_bytes_remaining_ == 0) {
        size_t packet_length =
            HciGetPacketLengthForType(hci_packet_type_, hci_packet_);
            HciGetPacketLengthForType(hci_packet_type_, hci_packet_preamble_);
        hci_packet_.resize(preamble_size_for_type[hci_packet_type_] +
                           packet_length);
        memcpy(hci_packet_.data(), hci_packet_preamble_,
               preamble_size_for_type[hci_packet_type_]);
        hci_packet_bytes_remaining_ = packet_length;
        hci_parser_state_ = HCI_PAYLOAD;
        hci_packet_bytes_read_ = 0;
+1 −0
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ class VendorInterface {
  enum HciParserState { HCI_IDLE, HCI_TYPE_READY, HCI_PAYLOAD };
  HciParserState hci_parser_state_{HCI_IDLE};
  HciPacketType hci_packet_type_{HCI_PACKET_TYPE_UNKNOWN};
  uint8_t hci_packet_preamble_[HCI_PREAMBLE_SIZE_MAX];
  hidl_vec<uint8_t> hci_packet_;
  size_t hci_packet_bytes_remaining_;
  size_t hci_packet_bytes_read_;