mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-06-06 05:14:45 +00:00
fix(nimble): Handle count correctly by considering offset.
This commit is contained in:
@@ -63,7 +63,8 @@ typedef struct {
|
||||
* @param conn_handle Connection handle of the peer device.
|
||||
* @param svc_uuid UUID of the service to search for (can be NULL to fetch all services).
|
||||
* @param result Output buffer to store the retrieved service(s).
|
||||
* @param count Number of entries in the cache
|
||||
* @param count The number of services to retrieve. It will be updated with the actual
|
||||
* number of services found, starting at the given offset (if specified).
|
||||
* @param offset Index offset for paginated access (used when more services exist).
|
||||
*
|
||||
* @return 0 on success, error code otherwise.
|
||||
@@ -84,7 +85,8 @@ int ble_gattc_get_service(uint16_t conn_handle,
|
||||
* @param start_handle Start handle of the attribute range (usually the service's start handle).
|
||||
* @param end_handle End handle of the attribute range (usually the service's end handle).
|
||||
* @param result Output buffer to store the retrieved characteristics.
|
||||
* @param count The number of characteristics to retrieve. It will be updated with the actual number of characteristics found.
|
||||
* @param count The number of characteristics to retrieve. It will be updated with the actual
|
||||
* number of characteristics found, starting at the given offset (if specified).
|
||||
* @param offset The position offset to retrieve
|
||||
*
|
||||
* @return 0 on success, error code otherwise.
|
||||
@@ -105,7 +107,8 @@ int ble_gattc_get_all_char(uint16_t conn_handle,
|
||||
* @param conn_handle Connection handle of the peer device.
|
||||
* @param char_handle Handle of the characteristic whose descriptors are to be fetched.
|
||||
* @param result Output buffer to store the retrieved descriptors.
|
||||
* @param count The number of descriptors to retrieve. It will be updated with the actual number of descriptors found.
|
||||
* @param count The number of descriptors to retrieve. It will be updated with the actual
|
||||
* number of descriptors found, starting at the given offset (if specified).
|
||||
* @param offset The position offset to retrieve
|
||||
*
|
||||
* @return 0 on success, error code otherwise.
|
||||
@@ -129,7 +132,8 @@ int ble_gattc_get_all_descr(uint16_t conn_handle,
|
||||
* @param end_handle End handle of the attribute range.
|
||||
* @param char_uuid UUID of the characteristic to search for.
|
||||
* @param result Output buffer to store the retrieved characteristics.
|
||||
* @param count The number of characteristics to retrieve. It will be updated with the actual number of characteristics found.
|
||||
* @param count The number of characteristics to retrieve. It will be updated with the actual
|
||||
* number of characteristics found, starting at the given offset (if specified).
|
||||
*
|
||||
* @return 0 on success, error code otherwise.
|
||||
*/
|
||||
@@ -153,7 +157,8 @@ int ble_gattc_get_char_by_uuid(uint16_t conn_handle,
|
||||
* @param char_uuid UUID of the characteristic to which the descriptor belongs.
|
||||
* @param descr_uuid UUID of the descriptor to search for.
|
||||
* @param result Output buffer to store the retrieved descriptors.
|
||||
* @param count The number of descriptors to retrieve. It will be updated with the actual number of descriptors found.
|
||||
* @param count The number of descriptors to retrieve. It will be updated with the actual
|
||||
* number of descriptors found, starting at the given offset (if specified).
|
||||
*
|
||||
* @return 0 on success, error code otherwise.
|
||||
*/
|
||||
@@ -174,7 +179,8 @@ int ble_gattc_get_descr_by_uuid(uint16_t conn_handle,
|
||||
* @param char_handle Handle of the characteristic whose descriptors are to be searched.
|
||||
* @param descr_uuid UUID of the descriptor to search for.
|
||||
* @param result Output buffer to store the retrieved descriptors.
|
||||
* @param count The number of descriptors to retrieve. It will be updated with the actual number of descriptors found.
|
||||
* @param count The number of descriptors to retrieve. It will be updated with the actual
|
||||
* number of descriptors found, starting at the given offset (if specified).
|
||||
*
|
||||
* @return 0 on success, error code otherwise.
|
||||
*/
|
||||
@@ -195,7 +201,8 @@ int ble_gattc_get_descr_by_char_handle(uint16_t conn_handle,
|
||||
* @param end_handle End handle of the attribute range.
|
||||
* @param incl_uuid UUID of the included service to search for (can be NULL to fetch all).
|
||||
* @param result Output buffer to store the retrieved included services.
|
||||
* @param count The number of included services to retrieve. It will be updated with the actual number of included services found.
|
||||
* @param count The number of included services to retrieve. It will be updated with the actual
|
||||
* number of included services found, starting at the given offset (if specified).
|
||||
*
|
||||
* @return 0 on success, error code otherwise.
|
||||
*/
|
||||
|
||||
@@ -3149,6 +3149,8 @@ static void ble_gattc_fill_gatt_db_conversion(uint16_t *count, uint16_t num, esp
|
||||
uint16_t offset, void *result, ble_gattc_db_elem_t *db)
|
||||
{
|
||||
uint16_t db_size = ((*count + offset) > num) ? (num - offset) : *count;
|
||||
*count = db_size;
|
||||
|
||||
switch (type) {
|
||||
case ESP_BLE_GATT_DB_PRIMARY_SERVICE:
|
||||
case ESP_BLE_GATT_DB_SECONDARY_SERVICE: {
|
||||
@@ -3307,7 +3309,6 @@ int ble_gattc_get_service(uint16_t conn_handle,
|
||||
ble_gattc_fill_gatt_db_conversion(count, svc_num, ESP_BLE_GATT_DB_PRIMARY_SERVICE, offset, (void *)result, db);
|
||||
}
|
||||
|
||||
*count = svc_num;
|
||||
//free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
@@ -3337,7 +3338,6 @@ int ble_gattc_get_all_char(uint16_t conn_handle,
|
||||
ble_gattc_fill_gatt_db_conversion(count, char_num, ESP_BLE_GATT_DB_CHARACTERISTIC, offset, (void *)result, db);
|
||||
}
|
||||
|
||||
*count = char_num;
|
||||
//free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
@@ -3366,7 +3366,6 @@ int ble_gattc_get_all_descr(uint16_t conn_handle,
|
||||
ble_gattc_fill_gatt_db_conversion(count, descr_num, ESP_BLE_GATT_DB_DESCRIPTOR, offset, (void *)result, db);
|
||||
}
|
||||
|
||||
*count = descr_num;
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
@@ -3397,7 +3396,6 @@ int ble_gattc_get_char_by_uuid(uint16_t conn_handle,
|
||||
ble_gattc_fill_gatt_db_conversion(count, char_num, ESP_BLE_GATT_DB_CHARACTERISTIC, 0, (void *)result, db);
|
||||
}
|
||||
|
||||
*count = char_num;
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
@@ -3430,7 +3428,6 @@ int ble_gattc_get_descr_by_uuid(uint16_t conn_handle,
|
||||
ble_gattc_fill_gatt_db_conversion(count, descr_num, ESP_BLE_GATT_DB_DESCRIPTOR, 0, (void *)result, db);
|
||||
}
|
||||
|
||||
*count = descr_num;
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
@@ -3460,7 +3457,6 @@ int ble_gattc_get_descr_by_char_handle(uint16_t conn_handle,
|
||||
ble_gattc_fill_gatt_db_conversion(count, descr_num, ESP_BLE_GATT_DB_DESCRIPTOR, 0, (void *)result, db);
|
||||
}
|
||||
|
||||
*count = descr_num;
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
@@ -3493,7 +3489,6 @@ int ble_gattc_get_include_service(uint16_t conn_handle,
|
||||
ble_gattc_fill_gatt_db_conversion(count, incl_num, ESP_BLE_GATT_DB_INCLUDED_SERVICE, 0, (void *)result, db);
|
||||
}
|
||||
|
||||
*count = incl_num;
|
||||
//free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
|
||||
Reference in New Issue
Block a user