diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index a5f3c18..7557600 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
}
next:
- /* Move on to the next service */
- attr = queue_pop_head(op->pending_svcs);
- if (!attr)
- goto failed;
-
- if (!gatt_db_attribute_get_service_handles(attr, &start, &end))
- goto failed;
-
- op->cur_svc = attr;
-
client->discovery_req = bt_gatt_discover_characteristics(client->att,
- start, end,
+ op->svc_first,
+ op->svc_last,
discover_chrcs_cb,
discovery_op_ref(op),
discovery_op_unref);
*discovering = false;
while ((chrc_data = queue_pop_head(op->pending_chrcs))) {
- attr = gatt_db_service_insert_characteristic(op->cur_svc,
+ struct gatt_db_attribute *svc;
+ uint16_t start, end;
+
+ attr = gatt_db_insert_characteristic(client->db,
chrc_data->value_handle,
&chrc_data->uuid, 0,
chrc_data->properties,
chrc_data->value_handle)
goto failed;
+ /* Adjust current service */
+ svc = gatt_db_get_service(client->db, chrc_data->value_handle);
+ if (op->cur_svc != svc) {
+ queue_remove(op->pending_svcs, svc);
+
+ /* Done with the current service */
+ gatt_db_service_set_active(op->cur_svc, true);
+ op->cur_svc = svc;
+ }
+
+ gatt_db_attribute_get_service_handles(svc, &start, &end);
+
+ /*
+ * Ajust end_handle in case the next chrc is not within the
+ * same service.
+ */
+ if (chrc_data->end_handle > end)
+ chrc_data->end_handle = end;
+
/*
* check for descriptors presence, before initializing the
* desc_handle and avoid integer overflow during desc_handle
free(chrc_data);
continue;
}
+
desc_start = chrc_data->value_handle + 1;
client->discovery_req = bt_gatt_discover_descriptors(
struct bt_gatt_client *client = op->client;
bool discovering;
struct gatt_db_attribute *desc_attr = NULL;
- struct gatt_db_attribute *next_srv;
- uint16_t start, end;
util_debug(client->debug_callback, client->debug_data,
"Ext. prop value: 0x%04x", (uint16_t)value[0]);
if (read_ext_prop_desc(op))
return;
- /* Continue with discovery */
- do {
- if (!discover_descs(op, &discovering))
- goto failed;
-
- if (discovering)
- return;
-
- /* Done with the current service */
- gatt_db_service_set_active(op->cur_svc, true);
-
- next_srv = queue_pop_head(op->pending_svcs);
- if (!next_srv)
- goto done;
-
- if (!gatt_db_attribute_get_service_handles(next_srv, &start,
- &end))
+ if (!discover_descs(op, &discovering))
goto failed;
- } while (start == end);
-
- /* Move on to the next service */
- op->cur_svc = next_srv;
-
- client->discovery_req = bt_gatt_discover_characteristics(client->att,
- start, end,
- discover_chrcs_cb,
- discovery_op_ref(op),
- discovery_op_unref);
- if (client->discovery_req)
+ if (discovering)
return;
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start characteristic discovery");
+ /* Done with the current service */
+ gatt_db_service_set_active(op->cur_svc, true);
- discovery_op_unref(op);
+ goto done;
failed:
success = false;
struct bt_gatt_client *client = op->client;
struct bt_gatt_iter iter;
struct gatt_db_attribute *attr;
- uint16_t handle, start, end;
+ uint16_t handle;
uint128_t u128;
bt_uuid_t uuid;
char uuid_str[MAX_LEN_UUID_STR];
"handle: 0x%04x, uuid: %s",
handle, uuid_str);
- attr = gatt_db_service_insert_descriptor(op->cur_svc, handle,
+ attr = gatt_db_insert_descriptor(client->db, handle,
&uuid, 0, NULL, NULL,
NULL);
- if (!attr)
+ if (!attr) {
+ util_debug(client->debug_callback, client->debug_data,
+ "Failed to insert descriptor at 0x%04x",
+ handle);
goto failed;
+ }
if (gatt_db_attribute_get_handle(attr) != handle)
goto failed;
/* Done with the current service */
gatt_db_service_set_active(op->cur_svc, true);
- attr = queue_pop_head(op->pending_svcs);
- if (!attr)
- goto done;
-
- if (!gatt_db_attribute_get_service_handles(attr, &start, &end))
- goto failed;
-
- if (start == end)
- goto next;
-
- /* Move on to the next service */
- op->cur_svc = attr;
-
- client->discovery_req = bt_gatt_discover_characteristics(client->att,
- start, end,
- discover_chrcs_cb,
- discovery_op_ref(op),
- discovery_op_unref);
- if (client->discovery_req)
- return;
-
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start characteristic discovery");
- discovery_op_unref(op);
+ goto done;
failed:
success = false;
struct discovery_op *op = user_data;
struct bt_gatt_client *client = op->client;
struct bt_gatt_iter iter;
- struct gatt_db_attribute *attr;
struct chrc *chrc_data;
uint16_t start, end, value;
uint8_t properties;
goto done;
}
- if (!op->cur_svc || !result || !bt_gatt_iter_init(&iter, result))
+ if (!result || !bt_gatt_iter_init(&iter, result))
goto failed;
chrc_count = bt_gatt_result_characteristic_count(result);
/* Done with the current service */
gatt_db_service_set_active(op->cur_svc, true);
- attr = queue_pop_head(op->pending_svcs);
- if (!attr)
- goto done;
-
- if (!gatt_db_attribute_get_service_handles(attr, &start, &end))
- goto failed;
-
- if (start == end)
- goto next;
-
- /* Move on to the next service */
- op->cur_svc = attr;
-
- client->discovery_req = bt_gatt_discover_characteristics(client->att,
- start, end,
- discover_chrcs_cb,
- discovery_op_ref(op),
- discovery_op_unref);
- if (client->discovery_req)
- return;
-
- util_debug(client->debug_callback, client->debug_data,
- "Failed to start characteristic discovery");
- discovery_op_unref(op);
+ goto done;
failed:
success = false;