From 8180fab0d3497c119559bb8d99631f88bff43d8e Mon Sep 17 00:00:00 2001 From: Liu Linyan Date: Thu, 3 Sep 2026 17:42:34 +0800 Subject: [PATCH] fix(ble_audio): Allow empty reading value for BLE Audio implementation --- .../bt/esp_ble_iso/host/adapter/bluedroid/gatt/gatt.c | 2 +- .../bt/esp_ble_iso/host/common/include/common/gatt.h | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/components/bt/esp_ble_iso/host/adapter/bluedroid/gatt/gatt.c b/components/bt/esp_ble_iso/host/adapter/bluedroid/gatt/gatt.c index 41268ba502f..4676ce7faa2 100644 --- a/components/bt/esp_ble_iso/host/adapter/bluedroid/gatt/gatt.c +++ b/components/bt/esp_ble_iso/host/adapter/bluedroid/gatt/gatt.c @@ -1759,7 +1759,7 @@ static void handle_gattc_read_chrc_event(struct bt_le_gattc_read_chrc_event *eve goto end; } - val = event->value; + val = READ_VALUE(event); vlen = event->len; /* By-UUID read: report the matched handle in params->by_uuid.start_handle (like diff --git a/components/bt/esp_ble_iso/host/common/include/common/gatt.h b/components/bt/esp_ble_iso/host/common/include/common/gatt.h index b020603902f..b3456b66afd 100644 --- a/components/bt/esp_ble_iso/host/common/include/common/gatt.h +++ b/components/bt/esp_ble_iso/host/common/include/common/gatt.h @@ -81,6 +81,16 @@ struct bt_le_gattc_notify_rx_event { ((const void *)((_event)->value != NULL ? (const uint8_t *)(_event)->value \ : (const uint8_t *)"")) +/* Same collision on the read path: NULL data marks the end of a read, so a lib read + * handler that sees it reports ATT invalid-length. A zero-length value is a real + * response - MCS 3.5 requires an empty Track Title when there is no current track - + * so keep the pointer non-NULL for the value callback. The adapter emits the + * end-of-read callback itself and still passes NULL there, so the two stay distinct. + */ +#define READ_VALUE(_event) \ + ((const uint8_t *)((_event)->value != NULL ? (const uint8_t *)(_event)->value \ + : (const uint8_t *)"")) + struct bt_le_gatts_notify_tx_event { bool is_notify; uint16_t conn_handle;