119 lines
3.2 KiB
Diff
119 lines
3.2 KiB
Diff
From 974b6dc47feac4252146a38e5e1ff3af12c68f53 Mon Sep 17 00:00:00 2001
|
|
Message-Id: <974b6dc47feac4252146a38e5e1ff3af12c68f53.1671703778.git.stefan@agner.ch>
|
|
In-Reply-To: <9abb3fc6095dc933a226116cdbbfd2b6779a41a6.1671703778.git.stefan@agner.ch>
|
|
References: <9abb3fc6095dc933a226116cdbbfd2b6779a41a6.1671703778.git.stefan@agner.ch>
|
|
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
|
|
Date: Thu, 15 Dec 2022 15:26:20 -0800
|
|
Subject: [PATCH] shared/gatt-client: Fix not removing pending services
|
|
|
|
If there are no characteristics to discover, or for some reason
|
|
bt_gatt_discover_descriptors is skiped, or the last attribute is
|
|
actually a included service the service should be removed from
|
|
pending list as there will be no more attributes to be discovered.
|
|
|
|
Fixes: https://github.com/bluez/bluez/issues/438
|
|
---
|
|
src/shared/gatt-client.c | 46 +++++++++++++++++++++++++++++++---------
|
|
1 file changed, 36 insertions(+), 10 deletions(-)
|
|
|
|
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
|
|
index ba9228ddf..c92af91fc 100644
|
|
--- a/src/shared/gatt-client.c
|
|
+++ b/src/shared/gatt-client.c
|
|
@@ -521,6 +521,24 @@ static void discovery_req_clear(struct bt_gatt_client *client)
|
|
client->discovery_req = NULL;
|
|
}
|
|
|
|
+static void discover_remove_pending(struct discovery_op *op,
|
|
+ struct gatt_db_attribute *attr)
|
|
+{
|
|
+ struct gatt_db_attribute *svc;
|
|
+
|
|
+ svc = gatt_db_attribute_get_service(attr);
|
|
+ if (!svc)
|
|
+ return;
|
|
+
|
|
+ if (!queue_remove(op->pending_svcs, svc))
|
|
+ return;
|
|
+
|
|
+ gatt_db_service_set_active(svc, true);
|
|
+
|
|
+ if (op->cur_svc == svc)
|
|
+ op->cur_svc = NULL;
|
|
+}
|
|
+
|
|
static void discover_chrcs_cb(bool success, uint8_t att_ecode,
|
|
struct bt_gatt_result *result,
|
|
void *user_data);
|
|
@@ -597,12 +615,26 @@ static void discover_incl_cb(bool success, uint8_t att_ecode,
|
|
gatt_db_attribute_get_handle(attr), handle);
|
|
goto failed;
|
|
}
|
|
+
|
|
+ if (!gatt_db_attribute_get_service_data(attr, NULL, &end,
|
|
+ NULL, NULL)) {
|
|
+ DBG(client, "Unable to get service data at 0x%04x",
|
|
+ handle);
|
|
+ goto failed;
|
|
+ }
|
|
+
|
|
+ /* Skip if there are no attributes */
|
|
+ if (handle == end)
|
|
+ discover_remove_pending(op, attr);
|
|
}
|
|
|
|
next:
|
|
range = queue_pop_head(op->discov_ranges);
|
|
- if (!range)
|
|
+ if (!range) {
|
|
+ /* Skip if there are no attributes */
|
|
+ discover_remove_pending(op, op->cur_svc);
|
|
goto failed;
|
|
+ }
|
|
|
|
client->discovery_req = bt_gatt_discover_characteristics(client->att,
|
|
range->start,
|
|
@@ -746,6 +778,9 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
|
|
goto failed;
|
|
}
|
|
|
|
+ /* Done with the current service */
|
|
+ discover_remove_pending(op, op->cur_svc);
|
|
+
|
|
done:
|
|
free(chrc_data);
|
|
return true;
|
|
@@ -819,9 +854,6 @@ static void ext_prop_read_cb(bool success, uint8_t att_ecode,
|
|
if (discovering)
|
|
return;
|
|
|
|
- /* Done with the current service */
|
|
- gatt_db_service_set_active(op->cur_svc, true);
|
|
-
|
|
goto done;
|
|
|
|
failed:
|
|
@@ -909,9 +941,6 @@ next:
|
|
if (discovering)
|
|
return;
|
|
|
|
- /* Done with the current service */
|
|
- gatt_db_service_set_active(op->cur_svc, true);
|
|
-
|
|
goto done;
|
|
|
|
failed:
|
|
@@ -1018,9 +1047,6 @@ next:
|
|
if (discovering)
|
|
return;
|
|
|
|
- /* Done with the current service */
|
|
- gatt_db_service_set_active(op->cur_svc, true);
|
|
-
|
|
goto done;
|
|
|
|
failed:
|
|
--
|
|
2.39.0
|
|
|