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

Commit 06c1463a authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "Fix failure in h4 recovery logic"

parents 7dd4ee00 ba7d9d51
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]);
  }
}