From 7520829ddd20852bcfb04487b401d36c462ed684 Mon Sep 17 00:00:00 2001 From: Mitch Cairns Date: Wed, 5 Feb 2025 09:59:20 -0800 Subject: [PATCH] fix(esp_hid): Enable notifications/Indications for HID Devices When HID devices reconnect to a host such as a WIndows device, Windows will not subscribe to notifications/indications, resulting in a state where no reports may be sent. Open to another fix, but this ought to be looked into and resolved. It results in HID devices only being able to report on initial pairing, and not again with reconnections thereafter. NOTE: This does not always happen on Windows devices due to some caching behavior apparently. But, where it does occur, it is consistent behavior. --- components/esp_hid/src/ble_hidd.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/components/esp_hid/src/ble_hidd.c b/components/esp_hid/src/ble_hidd.c index ec8d9fd29b..185271d3b1 100644 --- a/components/esp_hid/src/ble_hidd.c +++ b/components/esp_hid/src/ble_hidd.c @@ -476,6 +476,17 @@ static void hid_event_handler(esp_ble_hidd_dev_t *dev, int device_index, esp_gat dev->conn_id = param->connect.conn_id; memcpy(dev->remote_bda, param->connect.remote_bda, ESP_BD_ADDR_LEN); + // ADD THIS BLOCK: Initialize CCC for all reports + for (int i = 0; i < dev->devices[device_index].reports_len; i++) { + hidd_le_report_item_t *map = &dev->devices[device_index].reports[i]; + if (map->ccc_handle && !map->ccc.notify_enable && !map->ccc.indicate_enable) { + ESP_LOGW(TAG, "Initializing CCC for report %d", map->report_id); + map->ccc.notify_enable = true; + map->ccc.indicate_enable = true; + map->ccc.value = 0x03; // Enable notifications and indications + } + } + esp_ble_set_encryption(param->connect.remote_bda, ESP_BLE_SEC_ENCRYPT_NO_MITM); esp_hidd_event_data_t cb_param = {