mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-02 15:20:02 +00:00
apps/btshell: Fix full discovery
During full discovery, if last service does not have any characteristic but its end handle is 65535 (which is allowed by Core spec), discovery will loop forever since it assumes service was discovered if either start handle == end handle or there are characteristics discovered. This patch fixes this by adding "discovered" property to service struct which is used to check if service was already discovered.
This commit is contained in:
@@ -64,6 +64,7 @@ struct btshell_svc {
|
||||
SLIST_ENTRY(btshell_svc) next;
|
||||
struct ble_gatt_svc svc;
|
||||
struct btshell_chr_list chrs;
|
||||
bool discovered;
|
||||
};
|
||||
|
||||
SLIST_HEAD(btshell_svc_list, btshell_svc);
|
||||
@@ -95,6 +96,7 @@ int btshell_disc_svcs(uint16_t conn_handle);
|
||||
int btshell_disc_svc_by_uuid(uint16_t conn_handle, const ble_uuid_t *uuid);
|
||||
int btshell_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle);
|
||||
int btshell_disc_all_chrs_in_svc(uint16_t conn_handle, struct btshell_svc *svc);
|
||||
int btshell_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle, const ble_uuid_t *uuid);
|
||||
int btshell_disc_all_dscs(uint16_t conn_handle, uint16_t start_handle,
|
||||
|
||||
+40
-3
@@ -749,9 +749,8 @@ btshell_disc_full_chrs(uint16_t conn_handle)
|
||||
}
|
||||
|
||||
SLIST_FOREACH(svc, &conn->svcs, next) {
|
||||
if (!svc_is_empty(svc) && SLIST_EMPTY(&svc->chrs)) {
|
||||
rc = btshell_disc_all_chrs(conn_handle, svc->svc.start_handle,
|
||||
svc->svc.end_handle);
|
||||
if (!svc->discovered) {
|
||||
rc = btshell_disc_all_chrs_in_svc(conn_handle, svc);
|
||||
if (rc != 0) {
|
||||
btshell_full_disc_complete(rc);
|
||||
}
|
||||
@@ -815,6 +814,33 @@ btshell_on_disc_c(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
btshell_on_disc_c_in_s(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
const struct ble_gatt_chr *chr, void *arg)
|
||||
{
|
||||
struct btshell_svc *svc = arg;
|
||||
|
||||
switch (error->status) {
|
||||
case 0:
|
||||
btshell_chr_add(conn_handle, svc->svc.start_handle, chr);
|
||||
break;
|
||||
|
||||
case BLE_HS_EDONE:
|
||||
svc->discovered = true;
|
||||
console_printf("characteristic discovery successful\n");
|
||||
if (btshell_full_disc_prev_chr_val > 0) {
|
||||
btshell_disc_full_chrs(conn_handle);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
btshell_print_error(NULL, conn_handle, error);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
btshell_on_disc_d(uint16_t conn_handle, const struct ble_gatt_error *error,
|
||||
uint16_t chr_val_handle, const struct ble_gatt_dsc *dsc,
|
||||
@@ -1455,6 +1481,17 @@ btshell_disc_all_chrs(uint16_t conn_handle, uint16_t start_handle,
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
btshell_disc_all_chrs_in_svc(uint16_t conn_handle, struct btshell_svc *svc)
|
||||
{
|
||||
int rc;
|
||||
|
||||
rc = ble_gattc_disc_all_chrs(conn_handle, svc->svc.start_handle,
|
||||
svc->svc.end_handle, btshell_on_disc_c_in_s,
|
||||
svc);
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
btshell_disc_chrs_by_uuid(uint16_t conn_handle, uint16_t start_handle,
|
||||
uint16_t end_handle, const ble_uuid_t *uuid)
|
||||
|
||||
Reference in New Issue
Block a user