Skip to content

Commit 1d866e4

Browse files
nimble/host: Optimize characteristics discovery
We can stop characteristics discovery as soon as there are less than 2 attributes left. This means if last characteristic has descriptor (e.g. CCC) we will save single ATT_READ_BY_TYPE_REQ/RSP transaction. As a side-effect we also resume discovery starting from the next handle after last characteristic value handle instead of characteristic declaration handle, but this is ok since there cannot be any atrtibutes (so also characteristic declarations) between characteristic declaration and characteristic value.
1 parent 9275436 commit 1d866e4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

nimble/host/src/ble_gattc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,7 +2299,9 @@ ble_gattc_disc_all_chrs_rx_adata(struct ble_gattc_proc *proc,
22992299
rc = BLE_HS_EBADDATA;
23002300
goto done;
23012301
}
2302-
proc->disc_all_chrs.prev_handle = adata->att_handle;
2302+
2303+
/* We'll resume after characteristic value */
2304+
proc->disc_all_chrs.prev_handle = chr.val_handle;
23032305

23042306
rc = 0;
23052307

@@ -2328,7 +2330,10 @@ ble_gattc_disc_all_chrs_rx_complete(struct ble_gattc_proc *proc, int status)
23282330
return BLE_HS_EDONE;
23292331
}
23302332

2331-
if (proc->disc_all_chrs.prev_handle == proc->disc_all_chrs.end_handle) {
2333+
/* We can stop discovery if there are less than 2 attributes left since
2334+
* complete characteristic requires at least 2 handles.
2335+
*/
2336+
if (proc->disc_all_chrs.prev_handle + 1 >= proc->disc_all_chrs.end_handle - 1) {
23322337
/* Characteristic discovery complete. */
23332338
ble_gattc_disc_all_chrs_cb(proc, BLE_HS_EDONE, 0, NULL);
23342339
return BLE_HS_EDONE;

0 commit comments

Comments
 (0)