linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added
@ 2016-02-15 12:30 Luiz Augusto von Dentz
  2016-02-15 12:30 ` [PATCH BlueZ 2/5] shared/gatt-client: Rename tmp_queue to svcs Luiz Augusto von Dentz
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-15 12:30 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If gatt_db_service_insert_characteristic fails print an error for the
handle.
---
 src/shared/gatt-client.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 20c195a..8486b09 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -588,8 +588,12 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
 							chrc_data->properties,
 							NULL, NULL, NULL);
 
-		if (!attr)
+		if (!attr) {
+			util_debug(client->debug_callback, client->debug_data,
+				"Failed to insert characteristic at 0x%04x",
+				chrc_data->value_handle);
 			goto failed;
+		}
 
 		if (gatt_db_attribute_get_handle(attr) !=
 							chrc_data->value_handle)
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH BlueZ 2/5] shared/gatt-client: Rename tmp_queue to svcs
  2016-02-15 12:30 [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
@ 2016-02-15 12:30 ` Luiz Augusto von Dentz
  2016-02-15 12:30 ` [PATCH BlueZ 3/5] core/device: Fix log when loading characteristic fails Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-15 12:30 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

The tmp_queue in fact store the processed services so just rename it to
svcs and stop creating extra variables for that.
---
 src/shared/gatt-client.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 8486b09..4c563c2 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -357,7 +357,7 @@ struct discovery_op {
 	struct bt_gatt_client *client;
 	struct queue *pending_svcs;
 	struct queue *pending_chrcs;
-	struct queue *tmp_queue;
+	struct queue *svcs;
 	struct gatt_db_attribute *cur_svc;
 	bool success;
 	uint16_t start;
@@ -371,7 +371,7 @@ static void discovery_op_free(struct discovery_op *op)
 {
 	queue_destroy(op->pending_svcs, NULL);
 	queue_destroy(op->pending_chrcs, free);
-	queue_destroy(op->tmp_queue, NULL);
+	queue_destroy(op->svcs, NULL);
 	free(op);
 }
 
@@ -385,7 +385,7 @@ static struct discovery_op *discovery_op_create(struct bt_gatt_client *client,
 	op = new0(struct discovery_op, 1);
 	op->pending_svcs = queue_new();
 	op->pending_chrcs = queue_new();
-	op->tmp_queue = queue_new();
+	op->svcs = queue_new();
 	op->client = client;
 	op->complete_func = complete_func;
 	op->failure_func = failure_func;
@@ -501,17 +501,11 @@ next:
 	/* Move on to the next service */
 	attr = queue_pop_head(op->pending_svcs);
 	if (!attr) {
-		struct queue *tmp_queue;
-
-		tmp_queue = op->pending_svcs;
-		op->pending_svcs = op->tmp_queue;
-		op->tmp_queue = tmp_queue;
-
 		/*
 		 * We have processed all include definitions. Move on to
 		 * characteristics.
 		 */
-		attr = queue_pop_head(op->pending_svcs);
+		attr = queue_pop_head(op->svcs);
 		if (!attr)
 			goto failed;
 
@@ -535,7 +529,7 @@ next:
 		goto failed;
 	}
 
-	queue_push_tail(op->tmp_queue, attr);
+	queue_push_tail(op->svcs, attr);
 	op->cur_svc = attr;
 	if (!gatt_db_attribute_get_service_handles(attr, &start, &end))
 		goto failed;
@@ -920,10 +914,10 @@ next:
 	}
 
 	/*
-	 * Store the service in the tmp queue to be reused during
+	 * Store the service in the svcs queue to be reused during
 	 * characteristics discovery later.
 	 */
-	queue_push_tail(op->tmp_queue, attr);
+	queue_push_tail(op->svcs, attr);
 	op->cur_svc = attr;
 
 	if (!gatt_db_attribute_get_service_handles(attr, &start, &end)) {
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH BlueZ 3/5] core/device: Fix log when loading characteristic fails
  2016-02-15 12:30 [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
  2016-02-15 12:30 ` [PATCH BlueZ 2/5] shared/gatt-client: Rename tmp_queue to svcs Luiz Augusto von Dentz
@ 2016-02-15 12:30 ` Luiz Augusto von Dentz
  2016-02-15 12:30 ` [PATCH BlueZ 4/5] core/device: Fix not reseting database if attributes cannot be loaded Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-15 12:30 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

It should log that loading fails not saving.
---
 src/device.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/device.c b/src/device.c
index 1f7c895..235145a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3012,7 +3012,7 @@ static int load_chrc(char *handle, char *value,
 							&uuid, 0, properties,
 							NULL, NULL, NULL);
 	if (!att || gatt_db_attribute_get_handle(att) != value_handle) {
-		warn("saving characteristic to db failed");
+		warn("loading characteristic to db failed");
 		return -EIO;
 	}
 
@@ -3039,13 +3039,13 @@ static int load_incl(struct gatt_db *db, char *handle, char *value,
 
 	att = gatt_db_get_attribute(db, start);
 	if (!att) {
-		warn("saving included service to db failed - no such service");
+		warn("loading included service to db failed - no such service");
 		return -EIO;
 	}
 
 	att = gatt_db_service_add_included(service, att);
 	if (!att) {
-		warn("saving included service to db failed");
+		warn("loading included service to db failed");
 		return -EIO;
 	}
 
@@ -3082,7 +3082,7 @@ static int load_service(struct gatt_db *db, char *handle, char *value)
 	att = gatt_db_insert_service(db, start, &uuid, primary,
 							end - start + 1);
 	if (!att) {
-		DBG("ERROR saving service to db!");
+		error("Unable load service into db.");
 		return -EIO;
 	}
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH BlueZ 4/5] core/device: Fix not reseting database if attributes cannot be loaded
  2016-02-15 12:30 [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
  2016-02-15 12:30 ` [PATCH BlueZ 2/5] shared/gatt-client: Rename tmp_queue to svcs Luiz Augusto von Dentz
  2016-02-15 12:30 ` [PATCH BlueZ 3/5] core/device: Fix log when loading characteristic fails Luiz Augusto von Dentz
@ 2016-02-15 12:30 ` Luiz Augusto von Dentz
  2016-02-15 12:30 ` [PATCH BlueZ 5/5] core/device: Fix not clearing Attributes before storing Luiz Augusto von Dentz
  2016-02-17 10:32 ` [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
  4 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-15 12:30 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

If one or more attributes cannot be loaded it means the database is
probably in a bad state so just clear it so the attributes can be
discovered again.
---
 src/device.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/device.c b/src/device.c
index 235145a..89462ca 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3165,8 +3165,10 @@ static int load_gatt_db_impl(GKeyFile *key_file, char **keys,
 		}
 
 		g_free(value);
-		if (ret)
+		if (ret) {
+			gatt_db_clear(db);
 			return ret;
+		}
 	}
 
 	if (current_service)
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH BlueZ 5/5] core/device: Fix not clearing Attributes before storing
  2016-02-15 12:30 [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2016-02-15 12:30 ` [PATCH BlueZ 4/5] core/device: Fix not reseting database if attributes cannot be loaded Luiz Augusto von Dentz
@ 2016-02-15 12:30 ` Luiz Augusto von Dentz
  2016-02-17 10:32 ` [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
  4 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-15 12:30 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This can leave the storage in a bad state if device start changing its
attributes the old one are never removed as the code reloads them with
g_key_file_load_from_file.
---
 src/device.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/device.c b/src/device.c
index 89462ca..14e850e 100644
--- a/src/device.c
+++ b/src/device.c
@@ -2114,6 +2114,9 @@ static void store_gatt_db(struct btd_device *device)
 	key_file = g_key_file_new();
 	g_key_file_load_from_file(key_file, filename, 0, NULL);
 
+	/* Remove current attributes since it might have changed */
+	g_key_file_remove_group(key_file, "Attributes", NULL);
+
 	saver.key_file = key_file;
 	saver.device = device;
 
@@ -3082,7 +3085,7 @@ static int load_service(struct gatt_db *db, char *handle, char *value)
 	att = gatt_db_insert_service(db, start, &uuid, primary,
 							end - start + 1);
 	if (!att) {
-		error("Unable load service into db.");
+		error("Unable load service into db!");
 		return -EIO;
 	}
 
-- 
2.5.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added
  2016-02-15 12:30 [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2016-02-15 12:30 ` [PATCH BlueZ 5/5] core/device: Fix not clearing Attributes before storing Luiz Augusto von Dentz
@ 2016-02-17 10:32 ` Luiz Augusto von Dentz
  4 siblings, 0 replies; 6+ messages in thread
From: Luiz Augusto von Dentz @ 2016-02-17 10:32 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

Hi,

On Mon, Feb 15, 2016 at 2:30 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> If gatt_db_service_insert_characteristic fails print an error for the
> handle.
> ---
>  src/shared/gatt-client.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
> index 20c195a..8486b09 100644
> --- a/src/shared/gatt-client.c
> +++ b/src/shared/gatt-client.c
> @@ -588,8 +588,12 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
>                                                         chrc_data->properties,
>                                                         NULL, NULL, NULL);
>
> -               if (!attr)
> +               if (!attr) {
> +                       util_debug(client->debug_callback, client->debug_data,
> +                               "Failed to insert characteristic at 0x%04x",
> +                               chrc_data->value_handle);
>                         goto failed;
> +               }
>
>                 if (gatt_db_attribute_get_handle(attr) !=
>                                                         chrc_data->value_handle)
> --
> 2.5.0

Applied.


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-02-17 10:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-15 12:30 [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz
2016-02-15 12:30 ` [PATCH BlueZ 2/5] shared/gatt-client: Rename tmp_queue to svcs Luiz Augusto von Dentz
2016-02-15 12:30 ` [PATCH BlueZ 3/5] core/device: Fix log when loading characteristic fails Luiz Augusto von Dentz
2016-02-15 12:30 ` [PATCH BlueZ 4/5] core/device: Fix not reseting database if attributes cannot be loaded Luiz Augusto von Dentz
2016-02-15 12:30 ` [PATCH BlueZ 5/5] core/device: Fix not clearing Attributes before storing Luiz Augusto von Dentz
2016-02-17 10:32 ` [PATCH BlueZ 1/5] shared/gatt-client: Add debug log if characteristic cannot be added Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).