/* Function to find out if a descriptor discovery is required. 
This function finds out if there is a possibility of existence of descriptors between current characteristic and the next characteristic. If so, this function will compute the handle range on which the descriptors may be present and will return it. If the current characteristic is the last known characteristic, then this function will use the service end handle to find out if the current characteristic can have descriptors. */
static bool is_desc_discovery_reqd(ble_db_discovery_t *p_db_discovery, ble_gatt_db_char_t *p_curr_char, ble_gatt_db_char_t *p_next_char, ble_gattc_handle_range_t *p_handle_range)
/* Function to find out if a descriptor discovery is required. 
This function finds out if there is a possibility of existence of descriptors between current characteristic and the next characteristic. If so, this function will compute the handle range on which the descriptors may be present and will return it. If the current characteristic is the last known characteristic, then this function will use the service end handle to find out if the current characteristic can have descriptors. */
static bool is_desc_discovery_reqd(ble_db_discovery_t *p_db_discovery, ble_gatt_db_char_t *p_curr_char, ble_gatt_db_char_t *p_next_char, ble_gattc_handle_range_t *p_handle_range)
{
    if (p_next_char == NULL)
    {
        if (
            p_curr_char->characteristic.handle_value ==
            p_db_discovery->services[p_db_discovery->curr_srv_ind].handle_range.end_handle
           )
        {
            return false;
        }
        p_handle_range->start_handle = p_curr_char->characteristic.handle_value + 1;
        p_handle_range->end_handle =
            p_db_discovery->services[p_db_discovery->curr_srv_ind].handle_range.end_handle;
        return true;
    }
    if ((p_curr_char->characteristic.handle_value + 1) == p_next_char->characteristic.handle_decl)
    {
        return false;
    }
    p_handle_range->start_handle = p_curr_char->characteristic.handle_value + 1;
    p_handle_range->end_handle   = p_next_char->characteristic.handle_decl - 1;
    return true;
}