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

Commit f309f110 authored by Dorin Drimus's avatar Dorin Drimus
Browse files

Allow command complete and command status with opcode 0x0 anytime

From BLUETOOTH CORE SPECIFICATION Version 5.2 | Vol 4, Part E | 4.4 COMMAND FLOW CONTROL
"The Controller can send an HCI_Command_Complete or HCI_Command_Status event with Command Opcode 0x0000 at any time to change the number of outstanding HCI Command packets that the Host can send before waiting."

Bug: 214331534
Change-Id: I5265980518f0739f56657116ff13b7f6cc73e9b9
Test: N/A, Presubmit
parent 66bb2df6
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
@@ -329,10 +329,26 @@ struct HciLayer::impl {
    ASSERT(event.IsValid());
    if (command_queue_.empty()) {
      auto event_code = event.GetEventCode();
      ASSERT_LOG(
          event_code != EventCode::COMMAND_COMPLETE && event_code != EventCode::COMMAND_STATUS,
          "Received %s without a waiting command (is the HAL sending commands, but not handling the events?)",
          EventCodeText(event_code).c_str());
      // BT Core spec 5.2 (Volume 4, Part E section 4.4) allows anytime
      // COMMAND_COMPLETE and COMMAND_STATUS with opcode 0x0 for flow control
      if (event_code == EventCode::COMMAND_COMPLETE) {
          auto view = CommandCompleteView::Create(event);
          ASSERT(view.IsValid());
          auto op_code = view.GetCommandOpCode();
          ASSERT_LOG(op_code == OpCode::NONE,
            "Received %s event with OpCode 0x%02hx (%s) without a waiting command"
            "(is the HAL sending commands, but not handling the events?)",
            EventCodeText(event_code).c_str(), op_code, OpCodeText(op_code).c_str());
      }
      if (event_code == EventCode::COMMAND_STATUS) {
          auto view = CommandStatusView::Create(event);
          ASSERT(view.IsValid());
          auto op_code = view.GetCommandOpCode();
          ASSERT_LOG(op_code == OpCode::NONE,
            "Received %s event with OpCode 0x%02hx (%s) without a waiting command"
            "(is the HAL sending commands, but not handling the events?)",
            EventCodeText(event_code).c_str(), op_code, OpCodeText(op_code).c_str());
      }
      std::unique_ptr<CommandView> no_waiting_command{nullptr};
      log_hci_event(no_waiting_command, event, module_.GetDependency<storage::StorageModule>());
    } else {