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

Commit ba7d9d51 authored by Henri Chataing's avatar Henri Chataing
Browse files

Fix failure in h4 recovery logic

The packet idc is not removed from the packet before being
sent to the command handler.

Bug: 261261502
Test: atest rootcanal_test_host
Change-Id: I9aa66e0f765c185405e002ae21d35ad784c9f9d8
parent 0a44d150
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ bool H4Parser::Consume(const uint8_t* buffer, int32_t bytes_read) {
      packet_type_ = *buffer;
      packet_.clear();
      break;

    case HCI_RECOVERY: {
      // Skip all received bytes until the HCI Reset command is received.
      // The parser can end up in a bad state when the host is restarted.
@@ -150,12 +151,16 @@ bool H4Parser::Consume(const uint8_t* buffer, int32_t bytes_read) {
        }
      }

      // Received full reset command.
      if (packet_.size() == reset_command.size()) {
        LOG_INFO("Received HCI Reset command, exiting recovery state");
        // Pop the Idc from the received packet.
        packet_.erase(packet_.begin());
        bytes_wanted_ = 0;
      }
      break;
    }

    case HCI_PREAMBLE:
    case HCI_PAYLOAD:
      packet_.insert(packet_.end(), buffer, buffer + bytes_read);
+3 −3
Original line number Diff line number Diff line
@@ -176,9 +176,9 @@ TEST_F(H4ParserTest, Recovery) {

  // Validate that the HCI Reset command was correctly received.
  ASSERT_EQ(type_, PacketType::COMMAND);
  ASSERT_EQ(packet_.size(), reset_command.size());
  for (size_t i = 0; i < packet_.size(); i++) {
    ASSERT_EQ(packet_[i], reset_command[i]);
  ASSERT_EQ(packet_.size(), reset_command.size() - 1);
  for (size_t i = 1; i < packet_.size(); i++) {
    ASSERT_EQ(packet_[i - 1], reset_command[i]);
  }
}