From ac93fe0396a1554139a1c6d5842d89bec7ea2e00 Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Tue, 21 Jul 2026 10:43:51 +0800 Subject: [PATCH 1/3] fix(esp_hid/bluedroid): remove app-layer CCC gating in HID device Do not check CCCD before sending notify in battery_set, input_set and feature_set. (cherry picked from commit 81bbcaca4e694d54576d24778468da844730290e) Co-authored-by: zhanghaipeng --- components/esp_hid/src/ble_hidd.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index c46c3cab925..21cd01fa647 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2017-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -822,17 +822,15 @@ static esp_err_t esp_ble_hidd_dev_battery_set(void *devp, uint8_t level) } dev->bat_level = level; - if (!dev->connected || dev->bat_ccc.value == 0) { + if (!dev->connected) { //if we are not yet connected, that is not an error return ESP_OK; } - if (dev->bat_ccc.notify_enable) { - ret = esp_ble_gatts_send_indicate(dev->bat_svc.gatt_if, dev->conn_id, dev->bat_level_handle, 1, &dev->bat_level, false); - if (ret) { - ESP_LOGE(TAG, "esp_ble_gatts_send_notify failed: %d", ret); - return ESP_FAIL; - } + ret = esp_ble_gatts_send_indicate(dev->bat_svc.gatt_if, dev->conn_id, dev->bat_level_handle, 1, &dev->bat_level, false); + if (ret) { + ESP_LOGE(TAG, "esp_ble_gatts_send_notify failed: %d", ret); + return ESP_FAIL; } return ESP_OK; @@ -856,7 +854,7 @@ static esp_err_t esp_ble_hidd_dev_input_set(void *devp, size_t index, size_t id, return ESP_FAIL; } - if ((p_rpt = get_report_by_id_and_type(dev, id, ESP_HID_REPORT_TYPE_INPUT)) != NULL && p_rpt->ccc.value) { + if ((p_rpt = get_report_by_id_and_type(dev, id, ESP_HID_REPORT_TYPE_INPUT)) != NULL) { esp_err_t err = esp_ble_gatts_send_indicate(dev->devices[index].hid_svc.gatt_if, dev->conn_id, p_rpt->handle, length, data, p_rpt->ccc.indicate_enable); if (err != ESP_OK) { ESP_LOGE(TAG, "Send Input Indicate Failed: %d", err); @@ -896,7 +894,7 @@ static esp_err_t esp_ble_hidd_dev_feature_set(void *devp, size_t index, size_t i return ESP_FAIL; } WAIT_CB(dev); - if (dev->connected && p_rpt->ccc.value) { + if (dev->connected) { ret = esp_ble_gatts_send_indicate(dev->devices[index].hid_svc.gatt_if, dev->conn_id, p_rpt->handle, length, data, p_rpt->ccc.indicate_enable); if (ret != ESP_OK) { ESP_LOGE(TAG, "Send Feature Indicate Failed: %d", ret); From fb335e73cc7d63f18c87e2824fb0e1c2470a1deb Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Tue, 21 Jul 2026 10:44:05 +0800 Subject: [PATCH 2/3] change(ble/bluedroid): disable host trace logs when BLE Log host is off Default all Bluedroid layer trace levels to NONE when BLE async log is enabled without BLE_LOG_HOST_LOG. (cherry picked from commit 1f8f935e3faadd98d77ab1e58e6c95bf8a9913eb) Co-authored-by: zhanghaipeng --- components/bt/common/Kconfig.in | 1 - components/bt/host/bluedroid/Kconfig.in | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/components/bt/common/Kconfig.in b/components/bt/common/Kconfig.in index d4c16df32bc..2c0b992e86a 100644 --- a/components/bt/common/Kconfig.in +++ b/components/bt/common/Kconfig.in @@ -170,7 +170,6 @@ menu "BT Logs" menuconfig BT_LOG_CRITICAL_ONLY bool "Enable bandwidth-optimized log mode (critical logs only)" default n - depends on !BT_STACK_NO_LOG select BLE_LOG_ENABLED help Enable bandwidth-optimized logging for the BLE Log Async Output diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 062315c024d..3e935d04429 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -484,6 +484,7 @@ endmenu #BT debug option config BT_STACK_NO_LOG bool "Disable BT debug logs (minimize bin size)" depends on BT_BLUEDROID_ENABLED + default y if BLE_LOG_ENABLED && !BLE_LOG_HOST_LOG default n help This select can save the rodata code size From 4128693b65427aacf8b2cb7ba8fd6ab7bb2e6c4a Mon Sep 17 00:00:00 2001 From: Zhang Hai Peng Date: Tue, 21 Jul 2026 10:53:23 +0800 Subject: [PATCH 3/3] fix(ble/bluedroid): track ext scan state for rand addr check Update inq_var.state only after btsnd_hcic_ble_ext_scan_enable succeeds. Clear BTM_BLE_SCANNING on explicit stop and controller scan timeout. (cherry picked from commit 23519567e4fb6aacbc6105024002dddf71501a17) Co-authored-by: zhanghaipeng --- components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index 81d96c6904e..1fe5e27dc11 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -1114,6 +1114,12 @@ tBTM_STATUS BTM_BleExtendedScan(BOOLEAN enable, UINT16 duration, UINT16 period) if ((err = btsnd_hcic_ble_ext_scan_enable(enable, extend_adv_cb.scan_duplicate, duration, period)) != HCI_SUCCESS) { BTM_TRACE_ERROR("LE ES En=%d: cmd err=0x%x", enable, err); status = BTM_HCI_ERROR | err; + } else { + if (enable) { + btm_cb.ble_ctr_cb.inq_var.state |= BTM_BLE_SCANNING; + } else { + btm_cb.ble_ctr_cb.inq_var.state &= ~BTM_BLE_SCANNING; + } } end: @@ -1266,6 +1272,7 @@ void btm_ble_update_phy_evt(tBTM_BLE_UPDATE_PHY *params) #if (BLE_50_EXTEND_SCAN_EN == TRUE) void btm_ble_scan_timeout_evt(void) { + btm_cb.ble_ctr_cb.inq_var.state &= ~BTM_BLE_SCANNING; BTM_ExtBleCallbackTrigger(BTM_BLE_5_GAP_SCAN_TIMEOUT_EVT, NULL); } #endif // #if (BLE_50_EXTEND_SCAN_EN == TRUE)