From 868a03ff57980cd2143e1035298fd586417993b5 Mon Sep 17 00:00:00 2001 From: Aria Burrell Date: Sun, 17 Jul 2022 04:50:50 -0600 Subject: [PATCH] Fixed empty characteristic issue with bleio+nimble. - Based on espressif/nimble's blecent example code. Confirms that the characteristic is not empty before trying to catalogue its descriptors. - Running ble_gattc_disc_all_dscs on empty (no length) characteristics fails with the (not-very-informative) BLE_HS_EINVAL error if this check is not performed. --- ports/espressif/common-hal/_bleio/Connection.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ports/espressif/common-hal/_bleio/Connection.c b/ports/espressif/common-hal/_bleio/Connection.c index 7dbcbd6e5f..63c85099e6 100644 --- a/ports/espressif/common-hal/_bleio/Connection.c +++ b/ports/espressif/common-hal/_bleio/Connection.c @@ -394,6 +394,11 @@ STATIC void discover_remote_services(bleio_connection_internal_t *self, mp_obj_t ? service->end_handle : next_characteristic->def_handle - 1; + // Pre-check if characteristic is empty so descriptor discovery doesn't fail + if (end_handle <= characteristic->handle) { + continue; + } + _last_discovery_status = BLE_ERR_SUCCESS; CHECK_NIMBLE_ERROR(ble_gattc_disc_all_dscs(self->conn_handle, characteristic->handle, end_handle,