From 8fbe03bf8cc7e22beac6d1d5847b535f3de81b3b Mon Sep 17 00:00:00 2001 From: Liu Linyan Date: Wed, 3 Jun 2026 10:30:50 +0800 Subject: [PATCH] feat(ble_iso): Minor update for some ISO internal functions --- .../esp_ble_iso/host/adapter/bluedroid/gap.c | 17 ------ .../adapter/bluedroid/include/bluedroid/gap.h | 2 - .../adapter/bluedroid/include/bluedroid/iso.h | 8 +-- .../esp_ble_iso/host/adapter/bluedroid/iso.c | 54 ++++++++++++++----- .../bt/esp_ble_iso/host/adapter/nimble/gap.c | 5 -- .../host/adapter/nimble/include/nimble/gap.h | 2 - .../host/adapter/nimble/include/nimble/iso.h | 2 + .../bt/esp_ble_iso/host/adapter/nimble/iso.c | 6 +++ components/bt/esp_ble_iso/host/common/hci.c | 2 +- 9 files changed, 54 insertions(+), 44 deletions(-) diff --git a/components/bt/esp_ble_iso/host/adapter/bluedroid/gap.c b/components/bt/esp_ble_iso/host/adapter/bluedroid/gap.c index 4f34eff91fc..29590534ffc 100644 --- a/components/bt/esp_ble_iso/host/adapter/bluedroid/gap.c +++ b/components/bt/esp_ble_iso/host/adapter/bluedroid/gap.c @@ -481,23 +481,6 @@ int bt_le_bluedroid_scan_stop(void) return bluedroid_err_to_errno(status); } -int bt_le_bluedroid_iso_disconnect(uint16_t conn_handle, uint8_t reason) -{ - tBTM_STATUS status; - - LOG_DBG("[B]IsoDisconn[0x%03x][%02x]", conn_handle, reason); - - /* No direct_hci variant: HCI Disconnect returns Command_Status; - * outcome arrives via BTM_BLE_ISO_CIS_DISCONNECTED_EVT. */ - status = BTM_BleDisconCis(conn_handle, reason); - - if (status != BTM_SUCCESS) { - LOG_ERR("[B]IsoDisconnFail[0x%03x][%02x]", conn_handle, status); - } - - return bluedroid_err_to_errno(status); -} - int bt_le_bluedroid_gap_init(void) { BTM_BleGapRegisterCallback(gap_app_cb); diff --git a/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/gap.h b/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/gap.h index 03e475f52b4..352642f82cc 100644 --- a/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/gap.h +++ b/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/gap.h @@ -21,8 +21,6 @@ int bt_le_bluedroid_scan_start(const struct bt_le_scan_param *param); int bt_le_bluedroid_scan_stop(void); -int bt_le_bluedroid_iso_disconnect(uint16_t conn_handle, uint8_t reason); - int bt_le_bluedroid_gap_init(void); #ifdef __cplusplus diff --git a/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/iso.h b/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/iso.h index 4bced9c259c..75d1c1a1887 100644 --- a/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/iso.h +++ b/components/bt/esp_ble_iso/host/adapter/bluedroid/include/bluedroid/iso.h @@ -15,9 +15,11 @@ extern "C" { struct net_buf; -int bt_le_bluedroid_hci_iso_cmd_send_sync(uint16_t opcode, - struct net_buf *buf, - struct net_buf **rsp); +int bt_le_bluedroid_iso_cmd_send_sync(uint16_t opcode, + struct net_buf *buf, + struct net_buf **rsp); + +int bt_le_bluedroid_iso_disconnect(uint16_t conn_handle, uint8_t reason); int bt_le_bluedroid_iso_init(void); diff --git a/components/bt/esp_ble_iso/host/adapter/bluedroid/iso.c b/components/bt/esp_ble_iso/host/adapter/bluedroid/iso.c index e9c7bd94912..16c10d544a8 100644 --- a/components/bt/esp_ble_iso/host/adapter/bluedroid/iso.c +++ b/components/bt/esp_ble_iso/host/adapter/bluedroid/iso.c @@ -749,9 +749,9 @@ static int hci_cmd_remove_iso_data_path(struct net_buf *buf, struct net_buf **rs return 0; } -int bt_le_bluedroid_hci_iso_cmd_send_sync(uint16_t opcode, - struct net_buf *buf, - struct net_buf **rsp) +int bt_le_bluedroid_iso_cmd_send_sync(uint16_t opcode, + struct net_buf *buf, + struct net_buf **rsp) { int rc; @@ -1197,8 +1197,44 @@ static int iso_enable_cis(void) return bluedroid_err_to_errno(status); } + +static int iso_disable_cis(void) +{ + tBTM_STATUS status; + +#if USE_DIRECT_HCI + /* HCI LE Set Host Feature: Bit_Number(1) | Bit_Value(1). + * bit 32 = LE ISO Channels (Host Support). */ + uint8_t cmd_params[2] = { 32, 0 }; + + status = bt_le_bluedroid_hci_send_sync(HCI_BLE_SET_HOST_FEATURE, + cmd_params, sizeof(cmd_params), + NULL, 0); +#else /* USE_DIRECT_HCI */ + status = BTM_BleSetHostFeature(32, 0); +#endif /* USE_DIRECT_HCI */ + + return bluedroid_err_to_errno(status); +} #endif /* CONFIG_BT_ISO_UNICAST */ +int bt_le_bluedroid_iso_disconnect(uint16_t conn_handle, uint8_t reason) +{ + tBTM_STATUS status; + + LOG_DBG("[B]IsoDisconn[0x%03x][%02x]", conn_handle, reason); + + /* No direct_hci variant: HCI Disconnect returns Command_Status; + * outcome arrives via BTM_BLE_ISO_CIS_DISCONNECTED_EVT. */ + status = BTM_BleDisconCis(conn_handle, reason); + + if (status != BTM_SUCCESS) { + LOG_ERR("[B]IsoDisconnFail[0x%03x][%02x]", conn_handle, status); + } + + return bluedroid_err_to_errno(status); +} + int bt_le_bluedroid_iso_init(void) { #if CONFIG_BT_ISO_UNICAST @@ -1245,17 +1281,7 @@ void bt_le_bluedroid_iso_deinit(void) { #if CONFIG_BT_ISO_UNICAST /* Mirror bt_le_iso_init() which enables bit 32 only on unicast build. */ -#if USE_DIRECT_HCI - { - uint8_t cmd_params[2] = { 32, 0 }; - - bt_le_bluedroid_hci_send_sync(HCI_BLE_SET_HOST_FEATURE, - cmd_params, sizeof(cmd_params), - NULL, 0); - } -#else /* USE_DIRECT_HCI */ - BTM_BleSetHostFeature(32, 0); -#endif /* USE_DIRECT_HCI */ + iso_disable_cis(); #endif /* CONFIG_BT_ISO_UNICAST */ #if CONFIG_BT_ISO_RX diff --git a/components/bt/esp_ble_iso/host/adapter/nimble/gap.c b/components/bt/esp_ble_iso/host/adapter/nimble/gap.c index b64d6847a0c..87f2825cd81 100644 --- a/components/bt/esp_ble_iso/host/adapter/nimble/gap.c +++ b/components/bt/esp_ble_iso/host/adapter/nimble/gap.c @@ -287,8 +287,3 @@ int bt_le_nimble_scan_stop(void) return nimble_err_to_errno(rc); } - -int bt_le_nimble_iso_disconnect(uint16_t conn_handle, uint8_t reason) -{ - return nimble_err_to_errno(ble_gap_iso_disconnect(conn_handle, reason)); -} diff --git a/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/gap.h b/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/gap.h index a15eef9404f..7d897e25cd8 100644 --- a/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/gap.h +++ b/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/gap.h @@ -21,8 +21,6 @@ int bt_le_nimble_scan_start(const struct bt_le_scan_param *param, ble_gap_event_ int bt_le_nimble_scan_stop(void); -int bt_le_nimble_iso_disconnect(uint16_t conn_handle, uint8_t reason); - #ifdef __cplusplus } #endif diff --git a/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/iso.h b/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/iso.h index 89e508fa5c1..ebe0e7126c1 100644 --- a/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/iso.h +++ b/components/bt/esp_ble_iso/host/adapter/nimble/include/nimble/iso.h @@ -19,6 +19,8 @@ int bt_le_nimble_iso_cmd_send_sync(uint16_t opcode, struct net_buf *buf, struct net_buf **rsp); +int bt_le_nimble_iso_disconnect(uint16_t conn_handle, uint8_t reason); + int bt_le_nimble_iso_init(void); void bt_le_nimble_iso_deinit(void); diff --git a/components/bt/esp_ble_iso/host/adapter/nimble/iso.c b/components/bt/esp_ble_iso/host/adapter/nimble/iso.c index 16f75c10a9f..3ad3c9c55c9 100644 --- a/components/bt/esp_ble_iso/host/adapter/nimble/iso.c +++ b/components/bt/esp_ble_iso/host/adapter/nimble/iso.c @@ -14,6 +14,7 @@ #include <../host/iso_internal.h> #include "../src/ble_hs_priv.h" +#include "host/ble_gap.h" #include "host/ble_hs_iso.h" #include "host/ble_hs_iso_hci.h" @@ -838,6 +839,11 @@ static int iso_disable_cis(void) } #endif /* CONFIG_BT_ISO_UNICAST */ +int bt_le_nimble_iso_disconnect(uint16_t conn_handle, uint8_t reason) +{ + return nimble_err_to_errno(ble_gap_iso_disconnect(conn_handle, reason)); +} + int bt_le_nimble_iso_init(void) { int err; diff --git a/components/bt/esp_ble_iso/host/common/hci.c b/components/bt/esp_ble_iso/host/common/hci.c index 83e1a4d4d9a..e897997ebab 100644 --- a/components/bt/esp_ble_iso/host/common/hci.c +++ b/components/bt/esp_ble_iso/host/common/hci.c @@ -71,7 +71,7 @@ int bt_hci_cmd_send_sync(uint16_t opcode, LOG_DBG("HciCmdSendSync[%04x]", opcode); #if CONFIG_BT_BLUEDROID_ENABLED - return bt_le_bluedroid_hci_iso_cmd_send_sync(opcode, buf, rsp); + return bt_le_bluedroid_iso_cmd_send_sync(opcode, buf, rsp); #else return bt_le_nimble_iso_cmd_send_sync(opcode, buf, rsp); #endif