linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly
@ 2016-12-01 20:40 Luiz Augusto von Dentz
  2016-12-01 20:40 ` [PATCH BlueZ 2/3] shared/gatt-db: Make gatt_db_clear call gatt_db_clear_range Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2016-12-01 20:40 UTC (permalink / raw)
  To: linux-bluetooth

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

---
 src/shared/gatt-client.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 4386692..c4102dd 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -1052,7 +1052,7 @@ static void discover_primary_cb(bool success, uint8_t att_ecode,
 					"Primary service discovery failed."
 					" ATT ECODE: 0x%02x", att_ecode);
 		/* Reset error in case of not found */
-		if (BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) {
+		if (att_ecode == BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) {
 			success = true;
 			att_ecode = 0;
 		}
-- 
2.9.3


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

* [PATCH BlueZ 2/3] shared/gatt-db: Make gatt_db_clear call gatt_db_clear_range
  2016-12-01 20:40 [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly Luiz Augusto von Dentz
@ 2016-12-01 20:40 ` Luiz Augusto von Dentz
  2016-12-01 20:40 ` [PATCH BlueZ 3/3] shared/gatt-client: Don't clear db in case of errors Luiz Augusto von Dentz
  2016-12-02 11:54 ` [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2016-12-01 20:40 UTC (permalink / raw)
  To: linux-bluetooth

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

This makes gatt_db_clear much simpler while making gatt_db_clear_range
detect full database clear resetting next_handle properly if the
database is empty.
---
 src/shared/gatt-db.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 513451f..8ef6f3b 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -410,14 +410,7 @@ bool gatt_db_remove_service(struct gatt_db *db,
 
 bool gatt_db_clear(struct gatt_db *db)
 {
-	if (!db)
-		return false;
-
-	queue_remove_all(db->services, NULL, NULL, gatt_db_service_destroy);
-
-	db->next_handle = 0;
-
-	return true;
+	return gatt_db_clear_range(db, 1, UINT16_MAX);
 }
 
 static void gatt_db_service_get_handles(const struct gatt_db_service *service,
@@ -455,12 +448,23 @@ bool gatt_db_clear_range(struct gatt_db *db, uint16_t start_handle,
 	if (!db || start_handle > end_handle)
 		return false;
 
+	/* Check if it is a full clear */
+	if (start_handle == 1 && end_handle == UINT16_MAX) {
+		queue_remove_all(db->services, NULL, NULL,
+						gatt_db_service_destroy);
+		goto done;
+	}
+
 	range.start = start_handle;
 	range.end = end_handle;
 
 	queue_remove_all(db->services, match_range, &range,
 						gatt_db_service_destroy);
 
+done:
+	if (gatt_db_isempty(db))
+		db->next_handle = 0;
+
 	return true;
 }
 
-- 
2.9.3


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

* [PATCH BlueZ 3/3] shared/gatt-client: Don't clear db in case of errors
  2016-12-01 20:40 [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly Luiz Augusto von Dentz
  2016-12-01 20:40 ` [PATCH BlueZ 2/3] shared/gatt-db: Make gatt_db_clear call gatt_db_clear_range Luiz Augusto von Dentz
@ 2016-12-01 20:40 ` Luiz Augusto von Dentz
  2016-12-02 11:54 ` [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2016-12-01 20:40 UTC (permalink / raw)
  To: linux-bluetooth

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

If the db was not empty when initializing the instance set the
discovery last handle to avoid clearing the database in case of
cache validation error.
---
 src/shared/gatt-client.c | 21 +++++----------------
 1 file changed, 5 insertions(+), 16 deletions(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index c4102dd..e133bbc 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -340,12 +340,8 @@ static void discovery_op_complete(struct discovery_op *op, bool success,
 								uint8_t err)
 {
 	/* Reset remaining range */
-	if (success) {
-		if (op->last != UINT16_MAX)
-			gatt_db_clear_range(op->client->db, op->last + 1,
-								UINT16_MAX);
-	} else
-		gatt_db_clear(op->client->db);
+	if (op->last != UINT16_MAX)
+		gatt_db_clear_range(op->client->db, op->last + 1, UINT16_MAX);
 
 	op->success = success;
 	op->complete_func(op, success, err);
@@ -368,6 +364,7 @@ static struct discovery_op *discovery_op_create(struct bt_gatt_client *client,
 	op->failure_func = failure_func;
 	op->start = start;
 	op->end = end;
+	op->last = gatt_db_isempty(client->db) ? 0 : UINT16_MAX;
 
 	return op;
 }
@@ -386,7 +383,7 @@ static void discovery_op_unref(void *data)
 	if (__sync_sub_and_fetch(&op->ref_count, 1))
 		return;
 
-	if (!op->success)
+	if (!op->success && op->failure_func)
 		op->failure_func(op);
 
 	discovery_op_free(op);
@@ -1605,13 +1602,6 @@ done:
 	notify_client_ready(client, success, att_ecode);
 }
 
-static void init_fail(struct discovery_op *op)
-{
-	struct bt_gatt_client *client = op->client;
-
-	gatt_db_clear(client->db);
-}
-
 static bool gatt_client_init(struct bt_gatt_client *client, uint16_t mtu)
 {
 	struct discovery_op *op;
@@ -1619,8 +1609,7 @@ static bool gatt_client_init(struct bt_gatt_client *client, uint16_t mtu)
 	if (client->in_init || client->ready)
 		return false;
 
-	op = discovery_op_create(client, 0x0001, 0xffff, init_complete,
-								init_fail);
+	op = discovery_op_create(client, 0x0001, 0xffff, init_complete, NULL);
 	if (!op)
 		return false;
 
-- 
2.9.3


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

* Re: [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly
  2016-12-01 20:40 [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly Luiz Augusto von Dentz
  2016-12-01 20:40 ` [PATCH BlueZ 2/3] shared/gatt-db: Make gatt_db_clear call gatt_db_clear_range Luiz Augusto von Dentz
  2016-12-01 20:40 ` [PATCH BlueZ 3/3] shared/gatt-client: Don't clear db in case of errors Luiz Augusto von Dentz
@ 2016-12-02 11:54 ` Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2016-12-02 11:54 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

Hi,

On Thu, Dec 1, 2016 at 10:40 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> ---
>  src/shared/gatt-client.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
> index 4386692..c4102dd 100644
> --- a/src/shared/gatt-client.c
> +++ b/src/shared/gatt-client.c
> @@ -1052,7 +1052,7 @@ static void discover_primary_cb(bool success, uint8_t att_ecode,
>                                         "Primary service discovery failed."
>                                         " ATT ECODE: 0x%02x", att_ecode);
>                 /* Reset error in case of not found */
> -               if (BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) {
> +               if (att_ecode == BT_ATT_ERROR_ATTRIBUTE_NOT_FOUND) {
>                         success = true;
>                         att_ecode = 0;
>                 }
> --
> 2.9.3

Ive skipped this one since Petri's patches are now applied, the other
2 were applied though.



-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2016-12-02 11:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-12-01 20:40 [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly Luiz Augusto von Dentz
2016-12-01 20:40 ` [PATCH BlueZ 2/3] shared/gatt-db: Make gatt_db_clear call gatt_db_clear_range Luiz Augusto von Dentz
2016-12-01 20:40 ` [PATCH BlueZ 3/3] shared/gatt-client: Don't clear db in case of errors Luiz Augusto von Dentz
2016-12-02 11:54 ` [PATCH BlueZ 1/3] shared/gatt-client: Fix not checking ATT error properly 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).