Merge branch 'bugfix/nimble_issues_08092026' into 'master'

fix(nimble): fix few nimble issues 08092026

Closes BLERP-3063

See merge request espressif/esp-idf!52593
This commit is contained in:
Rahul Tank
2026-09-11 14:15:15 +05:30
2 changed files with 52 additions and 48 deletions

View File

@@ -428,6 +428,9 @@ static void read_device_services(esp_hidh_dev_t *dev)
dev->config.report_maps = NULL; dev->config.report_maps = NULL;
goto done; goto done;
} }
/* HOGP defaults to Report Protocol Mode; the Protocol Mode
* characteristic is often write-only, so it cannot be read back. */
memset(dev->protocol_mode, ESP_HID_PROTOCOL_MODE_REPORT, dev->config.report_maps_len);
} }
for (uint16_t s = 0; s < svc_count; s++) { for (uint16_t s = 0; s < svc_count; s++) {
@@ -467,6 +470,7 @@ static void read_device_services(esp_hidh_dev_t *dev)
for (uint16_t c = 0; c < ccount; c++) { for (uint16_t c = 0; c < ccount; c++) {
cuuid = ble_uuid_u16(&char_result[c].uuid.u); cuuid = ble_uuid_u16(&char_result[c].uuid.u);
chandle = char_result[c].val_handle; chandle = char_result[c].val_handle;
report = NULL;
ESP_LOGD(TAG, " CHAR:(%d), handle: %d, perm: 0x%02x, uuid: 0x%04x", ESP_LOGD(TAG, " CHAR:(%d), handle: %d, perm: 0x%02x, uuid: 0x%04x",
c + 1, chandle, char_result[c].properties, cuuid); c + 1, chandle, char_result[c].properties, cuuid);
if (suuid == BLE_SVC_GAP_UUID16) { if (suuid == BLE_SVC_GAP_UUID16) {
@@ -514,21 +518,22 @@ static void read_device_services(esp_hidh_dev_t *dev)
} }
} }
} }
continue; }
} else { continue;
if (cuuid == BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE) { } else if (suuid == BLE_SVC_HID_UUID16) {
if (char_result[c].properties & BLE_GATT_CHR_PROP_READ) { if (cuuid == BLE_SVC_HID_CHR_UUID16_PROTOCOL_MODE) {
if (read_char(dev->ble.conn_id, chandle, &rdata, &rlen) == 0 && rlen) { if ((char_result[c].properties & BLE_GATT_CHR_PROP_READ) != 0
dev->protocol_mode[hidindex] = *((uint8_t *)rdata); && dev->protocol_mode != NULL && hidindex < dev->config.report_maps_len) {
free(rdata); if (read_char(dev->ble.conn_id, chandle, &rdata, &rlen) == 0 && rlen) {
rdata = NULL; dev->protocol_mode[hidindex] = *((uint8_t *)rdata);
}
} }
free(rdata);
rdata = NULL;
} }
continue; continue;
} } else if (cuuid == BLE_SVC_HID_CHR_UUID16_REPORT_MAP) {
if (cuuid == BLE_SVC_HID_CHR_UUID16_REPORT_MAP) { if ((char_result[c].properties & BLE_GATT_CHR_PROP_READ) != 0
if (char_result[c].properties & BLE_GATT_CHR_PROP_READ) { && dev->config.report_maps != NULL && hidindex < dev->config.report_maps_len) {
if (read_char(dev->ble.conn_id, chandle, &rdata, &rlen) == 0 && rlen) { if (read_char(dev->ble.conn_id, chandle, &rdata, &rlen) == 0 && rlen) {
uint8_t *copy = nimble_hidh_dup_bytes(rdata, rlen); uint8_t *copy = nimble_hidh_dup_bytes(rdata, rlen);
if (copy) { if (copy) {
@@ -537,41 +542,38 @@ static void read_device_services(esp_hidh_dev_t *dev)
dev->config.report_maps[hidindex].len = rlen; dev->config.report_maps[hidindex].len = rlen;
} }
} }
continue; free(rdata);
} else if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_INP || cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_OUT rdata = NULL;
|| cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INP || cuuid == BLE_SVC_HID_CHR_UUID16_RPT) { }
report = (esp_hidh_dev_report_t *)malloc(sizeof(esp_hidh_dev_report_t)); continue;
if (report == NULL) { } else if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_INP || cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_OUT
ESP_LOGE(TAG, "malloc esp_hidh_dev_report_t failed"); || cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INP || cuuid == BLE_SVC_HID_CHR_UUID16_RPT) {
goto done; report = (esp_hidh_dev_report_t *)malloc(sizeof(esp_hidh_dev_report_t));
} if (report == NULL) {
report->next = NULL; ESP_LOGE(TAG, "malloc esp_hidh_dev_report_t failed");
report->permissions = char_result[c].properties; goto done;
report->handle = chandle; }
report->ccc_handle = 0; report->next = NULL;
report->report_id = 0; report->permissions = char_result[c].properties;
report->map_index = hidindex; report->handle = chandle;
if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_INP) { report->ccc_handle = 0;
report->protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT; report->report_id = 0;
report->report_type = ESP_HID_REPORT_TYPE_INPUT; report->map_index = hidindex;
report->usage = ESP_HID_USAGE_KEYBOARD; if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_INP) {
report->value_len = 8; report->protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT;
} else if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_OUT) { report->report_type = ESP_HID_REPORT_TYPE_INPUT;
report->protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT; report->usage = ESP_HID_USAGE_KEYBOARD;
report->report_type = ESP_HID_REPORT_TYPE_OUTPUT; report->value_len = 8;
report->usage = ESP_HID_USAGE_KEYBOARD; } else if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_KBD_OUT) {
report->value_len = 8; report->protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT;
} else if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INP) { report->report_type = ESP_HID_REPORT_TYPE_OUTPUT;
report->protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT; report->usage = ESP_HID_USAGE_KEYBOARD;
report->report_type = ESP_HID_REPORT_TYPE_INPUT; report->value_len = 8;
report->usage = ESP_HID_USAGE_MOUSE; } else if (cuuid == BLE_SVC_HID_CHR_UUID16_BOOT_MOUSE_INP) {
report->value_len = 8; report->protocol_mode = ESP_HID_PROTOCOL_MODE_BOOT;
} else { report->report_type = ESP_HID_REPORT_TYPE_INPUT;
report->protocol_mode = ESP_HID_PROTOCOL_MODE_REPORT; report->usage = ESP_HID_USAGE_MOUSE;
report->report_type = 0; report->value_len = 8;
report->usage = ESP_HID_USAGE_GENERIC;
report->value_len = 0;
}
} else { } else {
report->protocol_mode = ESP_HID_PROTOCOL_MODE_REPORT; report->protocol_mode = ESP_HID_PROTOCOL_MODE_REPORT;
report->report_type = 0; report->report_type = 0;
@@ -581,6 +583,8 @@ static void read_device_services(esp_hidh_dev_t *dev)
} else { } else {
continue; continue;
} }
} else {
continue;
} }
struct ble_gatt_dsc descr_result[HIDH_MAX_DSCS]; struct ble_gatt_dsc descr_result[HIDH_MAX_DSCS];
uint16_t num_dsc = HIDH_MAX_DSCS; uint16_t num_dsc = HIDH_MAX_DSCS;