From 0be606aa18103d23c85054768fed23f7ef0a14da Mon Sep 17 00:00:00 2001
From: Alice Kuo <aliceypkuo@google.com>
Date: Mon, 28 Mar 2022 11:34:54 +0800
Subject: [PATCH] Correct the data path direction setting in
 HCI_LE_Remove_ISO_data_path

The data path direction is bit field in LE Remove ISO Data Path command.
Bit 0: remove input data path
Bit 1: remove output data path

Bug: 226438214
Test: make build
Change-Id: I5ee340fc36c119fecd614115f779b9cb1bb5be38
---
 .../bta/le_audio/broadcaster/state_machine.cc |  3 ++-
 system/bta/le_audio/state_machine.cc          | 27 ++++++++++---------
 system/gd/hci/hci_packets.pdl                 |  8 +++++-
 system/stack/include/btm_iso_api_types.h      |  3 +++
 system/stack/test/btm_iso_test.cc             |  2 +-
 .../model/controller/dual_mode_controller.cc  |  3 ++-
 .../model/controller/link_layer_controller.cc |  2 +-
 .../model/controller/link_layer_controller.h  |  2 +-
 8 files changed, 31 insertions(+), 19 deletions(-)

diff --git a/system/bta/le_audio/broadcaster/state_machine.cc b/system/bta/le_audio/broadcaster/state_machine.cc
index bbf7a6c3907..af15c8ccb81 100644
--- a/system/bta/le_audio/broadcaster/state_machine.cc
+++ b/system/bta/le_audio/broadcaster/state_machine.cc
@@ -488,7 +488,8 @@ class BroadcastStateMachineImpl : public BroadcastStateMachine {
 
     SetMuted(true);
     IsoManager::GetInstance()->RemoveIsoDataPath(
-        conn_handle, bluetooth::hci::iso_manager::kIsoDataPathDirectionIn);
+        conn_handle,
+        bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionInput);
   }
 
   void HandleHciEvent(uint16_t event, void* data) override {
diff --git a/system/bta/le_audio/state_machine.cc b/system/bta/le_audio/state_machine.cc
index 97d8a47d766..b452e3b7974 100644
--- a/system/bta/le_audio/state_machine.cc
+++ b/system/bta/le_audio/state_machine.cc
@@ -779,11 +779,11 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
       IsoManager::GetInstance()->RemoveIsoDataPath(
           ase->cis_conn_hdl,
           (ases_pair.sink
-               ? bluetooth::hci::iso_manager::kIsoDataPathDirectionOut
+               ? bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionOutput
                : 0x00) |
-              (ases_pair.source
-                   ? bluetooth::hci::iso_manager::kIsoDataPathDirectionIn
-                   : 0x00));
+              (ases_pair.source ? bluetooth::hci::iso_manager::
+                                      kRemoveIsoDataPathDirectionInput
+                                : 0x00));
     }
   }
 
@@ -1015,10 +1015,11 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
 
     IsoManager::GetInstance()->RemoveIsoDataPath(
         ase->cis_conn_hdl,
-        (ases_pair.sink ? bluetooth::hci::iso_manager::kIsoDataPathDirectionOut
-                        : 0x00) |
+        (ases_pair.sink
+             ? bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionOutput
+             : 0x00) |
             (ases_pair.source
-                 ? bluetooth::hci::iso_manager::kIsoDataPathDirectionIn
+                 ? bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionInput
                  : 0x00));
   }
 
@@ -1816,12 +1817,12 @@ class LeAudioGroupStateMachineImpl : public LeAudioGroupStateMachine {
               leAudioDevice->GetAsesByCisConnHdl(ase->cis_conn_hdl);
           IsoManager::GetInstance()->RemoveIsoDataPath(
               ase->cis_conn_hdl,
-              (ases_pair.sink
-                   ? bluetooth::hci::iso_manager::kIsoDataPathDirectionOut
-                   : 0x00) |
-                  (ases_pair.source
-                       ? bluetooth::hci::iso_manager::kIsoDataPathDirectionIn
-                       : 0x00));
+              (ases_pair.sink ? bluetooth::hci::iso_manager::
+                                    kRemoveIsoDataPathDirectionOutput
+                              : 0x00) |
+                  (ases_pair.source ? bluetooth::hci::iso_manager::
+                                          kRemoveIsoDataPathDirectionInput
+                                    : 0x00));
         } else if (ase->data_path_state ==
                        AudioStreamDataPathState::CIS_ESTABLISHED ||
                    ase->data_path_state ==
diff --git a/system/gd/hci/hci_packets.pdl b/system/gd/hci/hci_packets.pdl
index fd179601e61..2051261fc0b 100644
--- a/system/gd/hci/hci_packets.pdl
+++ b/system/gd/hci/hci_packets.pdl
@@ -4370,10 +4370,16 @@ packet LeSetupIsoDataPathComplete : CommandComplete (command_op_code = LE_SETUP_
   _reserved_ : 4,
 }
 
+enum RemoveDataPathDirection : 8 {
+  INPUT = 1,
+  OUTPUT = 2,
+  INPUT_AND_OUTPUT = 3,
+}
+
 packet LeRemoveIsoDataPath : LeIsoCommand (op_code = LE_REMOVE_ISO_DATA_PATH) {
   connection_handle : 12,
   _reserved_ : 4,
-  data_path_direction : DataPathDirection,
+  remove_data_path_direction : RemoveDataPathDirection,
 }
 
 packet LeRemoveIsoDataPathComplete : CommandComplete (command_op_code = LE_REMOVE_ISO_DATA_PATH) {
diff --git a/system/stack/include/btm_iso_api_types.h b/system/stack/include/btm_iso_api_types.h
index 05a444973fd..63ca700a8d9 100644
--- a/system/stack/include/btm_iso_api_types.h
+++ b/system/stack/include/btm_iso_api_types.h
@@ -44,6 +44,9 @@ namespace iso_manager {
 constexpr uint8_t kIsoDataPathDirectionIn = 0x00;
 constexpr uint8_t kIsoDataPathDirectionOut = 0x01;
 
+constexpr uint8_t kRemoveIsoDataPathDirectionInput = 0x01;
+constexpr uint8_t kRemoveIsoDataPathDirectionOutput = 0x02;
+
 constexpr uint8_t kIsoDataPathHci = 0x00;
 constexpr uint8_t kIsoDataPathPlatformDefault = 0x01;
 constexpr uint8_t kIsoDataPathDisabled = 0xFF;
diff --git a/system/stack/test/btm_iso_test.cc b/system/stack/test/btm_iso_test.cc
index f4984296f7f..0505a7e9449 100644
--- a/system/stack/test/btm_iso_test.cc
+++ b/system/stack/test/btm_iso_test.cc
@@ -1674,7 +1674,7 @@ TEST_F(IsoManagerTest, RemoveIsoDataPathValid) {
 
   // Setup and remove data paths for all CISes
   path_params.data_path_dir =
-      bluetooth::hci::iso_manager::kIsoDataPathDirectionIn;
+      bluetooth::hci::iso_manager::kRemoveIsoDataPathDirectionInput;
   for (auto& handle : volatile_test_cig_create_cmpl_evt_.conn_handles) {
     IsoManager::GetInstance()->SetupIsoDataPath(handle, path_params);
 
diff --git a/tools/rootcanal/model/controller/dual_mode_controller.cc b/tools/rootcanal/model/controller/dual_mode_controller.cc
index acd413b3681..3770fcfb112 100644
--- a/tools/rootcanal/model/controller/dual_mode_controller.cc
+++ b/tools/rootcanal/model/controller/dual_mode_controller.cc
@@ -2299,7 +2299,8 @@ void DualModeController::LeRemoveIsoDataPath(CommandView command) {
       gd_hci::LeRemoveIsoDataPathView::Create(std::move(iso_command_view));
   ASSERT(command_view.IsValid());
   link_layer_controller_.LeRemoveIsoDataPath(
-      command_view.GetConnectionHandle(), command_view.GetDataPathDirection());
+      command_view.GetConnectionHandle(),
+      command_view.GetRemoveDataPathDirection());
 }
 
 void DualModeController::LeReadRemoteFeatures(CommandView command) {
diff --git a/tools/rootcanal/model/controller/link_layer_controller.cc b/tools/rootcanal/model/controller/link_layer_controller.cc
index 871a595dd23..b4764cb6bdd 100644
--- a/tools/rootcanal/model/controller/link_layer_controller.cc
+++ b/tools/rootcanal/model/controller/link_layer_controller.cc
@@ -3395,7 +3395,7 @@ void LinkLayerController::LeSetupIsoDataPath(
 
 void LinkLayerController::LeRemoveIsoDataPath(
     uint16_t /* connection_handle */,
-    bluetooth::hci::DataPathDirection /* data_path_direction */) {}
+    bluetooth::hci::RemoveDataPathDirection /* remove_data_path_direction */) {}
 
 void LinkLayerController::HandleLeEnableEncryption(
     uint16_t handle, std::array<uint8_t, 8> rand, uint16_t ediv,
diff --git a/tools/rootcanal/model/controller/link_layer_controller.h b/tools/rootcanal/model/controller/link_layer_controller.h
index 6147fb4284f..0066c69c30a 100644
--- a/tools/rootcanal/model/controller/link_layer_controller.h
+++ b/tools/rootcanal/model/controller/link_layer_controller.h
@@ -239,7 +239,7 @@ class LinkLayerController {
                           std::vector<uint8_t> codec_configuration);
   void LeRemoveIsoDataPath(
       uint16_t connection_handle,
-      bluetooth::hci::DataPathDirection data_path_direction);
+      bluetooth::hci::RemoveDataPathDirection remove_data_path_direction);
 
   void HandleLeEnableEncryption(uint16_t handle, std::array<uint8_t, 8> rand,
                                 uint16_t ediv, std::array<uint8_t, 16> ltk);
-- 
GitLab