All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties
@ 2016-04-22 11:42 Luiz Augusto von Dentz
  2016-04-22 11:42 ` [PATCH BlueZ 2/4] core/device: Remove code related to GattServices Luiz Augusto von Dentz
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2016-04-22 11:42 UTC (permalink / raw)
  To: linux-bluetooth

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

Extended properties are already read and stored in the database and can be
retrieved with gatt_db_attribute_get_char_data.
---
 src/gatt-client.c | 55 +++----------------------------------------------------
 1 file changed, 3 insertions(+), 52 deletions(-)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index ebb7b35..16a1f6c 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -71,7 +71,6 @@ struct service {
 	bt_uuid_t uuid;
 	char *path;
 	struct queue *chrcs;
-	struct queue *pending_ext_props;
 };
 
 struct characteristic {
@@ -1283,7 +1282,8 @@ static struct characteristic *characteristic_create(
 
 	gatt_db_attribute_get_char_data(attr, &chrc->handle,
 							&chrc->value_handle,
-							&chrc->props, NULL,
+							&chrc->props,
+							&chrc->ext_props,
 							&uuid);
 
 	chrc->attr = gatt_db_get_attribute(service->client->db,
@@ -1398,7 +1398,6 @@ static void service_free(void *data)
 	struct service *service = data;
 
 	queue_destroy(service->chrcs, NULL);  /* List should be empty here */
-	queue_destroy(service->pending_ext_props, NULL);
 	g_free(service->path);
 	free(service);
 }
@@ -1412,7 +1411,6 @@ static struct service *service_create(struct gatt_db_attribute *attr,
 
 	service = new0(struct service, 1);
 	service->chrcs = queue_new();
-	service->pending_ext_props = queue_new();
 	service->client = client;
 
 	gatt_db_attribute_get_service_data(attr, &service->start_handle,
@@ -1484,44 +1482,6 @@ static void export_desc(struct gatt_db_attribute *attr, void *user_data)
 	queue_push_tail(charac->descs, desc);
 }
 
-static void read_ext_props_cb(bool success, uint8_t att_ecode,
-					const uint8_t *value, uint16_t length,
-					void *user_data)
-{
-	struct characteristic *chrc = user_data;
-	struct service *service = chrc->service;
-
-	if (!success) {
-		error("Failed to obtain extended properties - error: 0x%02x",
-								att_ecode);
-		return;
-	}
-
-	if (!value || length != 2) {
-		error("Malformed extended properties value");
-		return;
-	}
-
-	chrc->ext_props = get_le16(value);
-	if (chrc->ext_props)
-		g_dbus_emit_property_changed(btd_get_dbus_connection(),
-						chrc->path,
-						GATT_CHARACTERISTIC_IFACE,
-						"Flags");
-
-	queue_remove(service->pending_ext_props, chrc);
-}
-
-static void read_ext_props(void *data, void *user_data)
-{
-	struct characteristic *chrc = data;
-
-	bt_gatt_client_read_value(chrc->service->client->gatt,
-							chrc->ext_props_handle,
-							read_ext_props_cb,
-							chrc, NULL);
-}
-
 static bool create_descriptors(struct gatt_db_attribute *attr,
 					struct characteristic *charac)
 {
@@ -1555,9 +1515,6 @@ static void export_char(struct gatt_db_attribute *attr, void *user_data)
 
 	queue_push_tail(service->chrcs, charac);
 
-	if (charac->ext_props_handle)
-		queue_push_tail(service->pending_ext_props, charac);
-
 	return;
 
 fail:
@@ -1574,13 +1531,7 @@ static bool create_characteristics(struct gatt_db_attribute *attr,
 
 	gatt_db_service_foreach_char(attr, export_char, &data);
 
-	if (data.failed)
-		return false;
-
-	/* Obtain extended properties */
-	queue_foreach(service->pending_ext_props, read_ext_props, NULL);
-
-	return true;
+	return !data.failed;
 }
 
 static void export_service(struct gatt_db_attribute *attr, void *user_data)
-- 
2.5.5


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

* [PATCH BlueZ 2/4] core/device: Remove code related to GattServices
  2016-04-22 11:42 [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz
@ 2016-04-22 11:42 ` Luiz Augusto von Dentz
  2016-04-22 11:42 ` [PATCH BlueZ 3/4] core/device: Fix not storing GATT attributes Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2016-04-22 11:42 UTC (permalink / raw)
  To: linux-bluetooth

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

GattService has been removed so there shouldn't be any code related to it
---
 src/device.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/device.c b/src/device.c
index 5269ee8..62a42d5 100644
--- a/src/device.c
+++ b/src/device.c
@@ -3366,9 +3366,6 @@ static gboolean gatt_services_changed(gpointer user_data)
 
 	store_gatt_db(device);
 
-	g_dbus_emit_property_changed(dbus_conn, device->path, DEVICE_INTERFACE,
-								"GattServices");
-
 	return FALSE;
 }
 
-- 
2.5.5


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

* [PATCH BlueZ 3/4] core/device: Fix not storing GATT attributes
  2016-04-22 11:42 [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz
  2016-04-22 11:42 ` [PATCH BlueZ 2/4] core/device: Remove code related to GattServices Luiz Augusto von Dentz
@ 2016-04-22 11:42 ` Luiz Augusto von Dentz
  2016-04-22 11:42 ` [PATCH BlueZ 4/4] doc/settings-storage: Add alternative format for descriptors Luiz Augusto von Dentz
  2016-04-29 10:07 ` [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz
  3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2016-04-22 11:42 UTC (permalink / raw)
  To: linux-bluetooth

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

If services has been refreshed the attributes shall be stored so they can
be reloaded properly the next time.
---
 src/device.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/device.c b/src/device.c
index 62a42d5..ed8fcdf 100644
--- a/src/device.c
+++ b/src/device.c
@@ -4576,6 +4576,8 @@ static void gatt_client_ready_cb(bool success, uint8_t att_ecode,
 	btd_gatt_client_ready(device->client_dbus);
 
 	device_svc_resolved(device, device->bdaddr_type, 0);
+
+	store_gatt_db(device);
 }
 
 static void gatt_client_service_changed(uint16_t start_handle,
-- 
2.5.5


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

* [PATCH BlueZ 4/4] doc/settings-storage: Add alternative format for descriptors
  2016-04-22 11:42 [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz
  2016-04-22 11:42 ` [PATCH BlueZ 2/4] core/device: Remove code related to GattServices Luiz Augusto von Dentz
  2016-04-22 11:42 ` [PATCH BlueZ 3/4] core/device: Fix not storing GATT attributes Luiz Augusto von Dentz
@ 2016-04-22 11:42 ` Luiz Augusto von Dentz
  2016-04-29 10:07 ` [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz
  3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2016-04-22 11:42 UTC (permalink / raw)
  To: linux-bluetooth

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

In case of some descriptors like CEP we must store the actual value since
extended properties are not part of the discovery and btd_gatt_client no
longer attempt to read it the value must be loaded in the db so
gatt_db_attribute_get_char_data is able to retrieve it.
---
 doc/settings-storage.txt |  1 +
 src/device.c             | 49 +++++++++++++++++++++++++++++++++++++++++-------
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
index aea50a6..2c34ec4 100644
--- a/doc/settings-storage.txt
+++ b/doc/settings-storage.txt
@@ -175,6 +175,7 @@ how to interpret rest of value:
     2803:value_handle:properties:uuid
 
   Descriptor:
+    value:uuid
     uuid
 
 Sample Attributes section:
diff --git a/src/device.c b/src/device.c
index ed8fcdf..b004f43 100644
--- a/src/device.c
+++ b/src/device.c
@@ -1957,6 +1957,7 @@ static void store_services(struct btd_device *device)
 
 struct gatt_saver {
 	struct btd_device *device;
+	uint16_t ext_props;
 	GKeyFile *key_file;
 };
 
@@ -1966,6 +1967,7 @@ static void store_desc(struct gatt_db_attribute *attr, void *user_data)
 	GKeyFile *key_file = saver->key_file;
 	char handle[6], value[100], uuid_str[MAX_LEN_UUID_STR];
 	const bt_uuid_t *uuid;
+	bt_uuid_t ext_uuid;
 	uint16_t handle_num;
 
 	handle_num = gatt_db_attribute_get_handle(attr);
@@ -1973,7 +1975,13 @@ static void store_desc(struct gatt_db_attribute *attr, void *user_data)
 
 	uuid = gatt_db_attribute_get_type(attr);
 	bt_uuid_to_string(uuid, uuid_str, sizeof(uuid_str));
-	sprintf(value, "%s", uuid_str);
+
+	bt_uuid16_create(&ext_uuid, GATT_CHARAC_EXT_PROPER_UUID);
+	if (!bt_uuid_cmp(uuid, &ext_uuid) && saver->ext_props)
+		sprintf(value, "%04hx:%s", saver->ext_props, uuid_str);
+	else
+		sprintf(value, "%s", uuid_str);
+
 	g_key_file_set_string(key_file, "Attributes", handle, value);
 }
 
@@ -1987,7 +1995,8 @@ static void store_chrc(struct gatt_db_attribute *attr, void *user_data)
 	bt_uuid_t uuid;
 
 	if (!gatt_db_attribute_get_char_data(attr, &handle_num, &value_handle,
-						&properties, NULL, &uuid)) {
+						&properties, &saver->ext_props,
+						&uuid)) {
 		warn("Error storing characteristic - can't get data");
 		return;
 	}
@@ -2987,24 +2996,43 @@ static void add_primary(struct gatt_db_attribute *attr, void *user_data)
 	*new_services = g_slist_append(*new_services, prim);
 }
 
+static void load_desc_value(struct gatt_db_attribute *attrib,
+						int err, void *user_data)
+{
+	if (err)
+		warn("loading descriptor value to db failed");
+}
+
 static int load_desc(char *handle, char *value,
 					struct gatt_db_attribute *service)
 {
 	char uuid_str[MAX_LEN_UUID_STR];
 	struct gatt_db_attribute *att;
 	uint16_t handle_int;
-	bt_uuid_t uuid;
+	uint16_t val;
+	bt_uuid_t uuid, ext_uuid;
 
 	if (sscanf(handle, "%04hx", &handle_int) != 1)
 		return -EIO;
 
-	if (sscanf(value, "%s", uuid_str) != 1)
-		return -EIO;
+	/* Check if there is any value stored, otherwise it is just the UUID */
+	if (sscanf(value, "%04hx:%s", &val, uuid_str) != 2) {
+		if (sscanf(value, "%s", uuid_str) != 1)
+			return -EIO;
+		val = 0;
+	}
+
+	DBG("loading descriptor handle: 0x%04x, value: 0x%04x, uuid: %s",
+				handle_int, val, uuid_str);
 
 	bt_string_to_uuid(&uuid, uuid_str);
+	bt_uuid16_create(&ext_uuid, GATT_CHARAC_EXT_PROPER_UUID);
 
-	DBG("loading descriptor handle: 0x%04x, uuid: %s", handle_int,
-								uuid_str);
+	/* If it is CEP then it must contain the value */
+	if (!bt_uuid_cmp(&uuid, &ext_uuid) && !val) {
+		warn("cannot load CEP descriptor without value");
+		return -EIO;
+	}
 
 	att = gatt_db_service_insert_descriptor(service, handle_int, &uuid,
 							0, NULL, NULL, NULL);
@@ -3013,6 +3041,13 @@ static int load_desc(char *handle, char *value,
 		return -EIO;
 	}
 
+	if (val) {
+		if (!gatt_db_attribute_write(att, 0, (uint8_t *)&val,
+						sizeof(val), 0, NULL,
+						load_desc_value, NULL))
+			return -EIO;
+	}
+
 	return 0;
 }
 
-- 
2.5.5


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

* Re: [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties
  2016-04-22 11:42 [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2016-04-22 11:42 ` [PATCH BlueZ 4/4] doc/settings-storage: Add alternative format for descriptors Luiz Augusto von Dentz
@ 2016-04-29 10:07 ` Luiz Augusto von Dentz
  3 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2016-04-29 10:07 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Fri, Apr 22, 2016 at 2:42 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> Extended properties are already read and stored in the database and can be
> retrieved with gatt_db_attribute_get_char_data.
> ---
>  src/gatt-client.c | 55 +++----------------------------------------------------
>  1 file changed, 3 insertions(+), 52 deletions(-)
>
> diff --git a/src/gatt-client.c b/src/gatt-client.c
> index ebb7b35..16a1f6c 100644
> --- a/src/gatt-client.c
> +++ b/src/gatt-client.c
> @@ -71,7 +71,6 @@ struct service {
>         bt_uuid_t uuid;
>         char *path;
>         struct queue *chrcs;
> -       struct queue *pending_ext_props;
>  };
>
>  struct characteristic {
> @@ -1283,7 +1282,8 @@ static struct characteristic *characteristic_create(
>
>         gatt_db_attribute_get_char_data(attr, &chrc->handle,
>                                                         &chrc->value_handle,
> -                                                       &chrc->props, NULL,
> +                                                       &chrc->props,
> +                                                       &chrc->ext_props,
>                                                         &uuid);
>
>         chrc->attr = gatt_db_get_attribute(service->client->db,
> @@ -1398,7 +1398,6 @@ static void service_free(void *data)
>         struct service *service = data;
>
>         queue_destroy(service->chrcs, NULL);  /* List should be empty here */
> -       queue_destroy(service->pending_ext_props, NULL);
>         g_free(service->path);
>         free(service);
>  }
> @@ -1412,7 +1411,6 @@ static struct service *service_create(struct gatt_db_attribute *attr,
>
>         service = new0(struct service, 1);
>         service->chrcs = queue_new();
> -       service->pending_ext_props = queue_new();
>         service->client = client;
>
>         gatt_db_attribute_get_service_data(attr, &service->start_handle,
> @@ -1484,44 +1482,6 @@ static void export_desc(struct gatt_db_attribute *attr, void *user_data)
>         queue_push_tail(charac->descs, desc);
>  }
>
> -static void read_ext_props_cb(bool success, uint8_t att_ecode,
> -                                       const uint8_t *value, uint16_t length,
> -                                       void *user_data)
> -{
> -       struct characteristic *chrc = user_data;
> -       struct service *service = chrc->service;
> -
> -       if (!success) {
> -               error("Failed to obtain extended properties - error: 0x%02x",
> -                                                               att_ecode);
> -               return;
> -       }
> -
> -       if (!value || length != 2) {
> -               error("Malformed extended properties value");
> -               return;
> -       }
> -
> -       chrc->ext_props = get_le16(value);
> -       if (chrc->ext_props)
> -               g_dbus_emit_property_changed(btd_get_dbus_connection(),
> -                                               chrc->path,
> -                                               GATT_CHARACTERISTIC_IFACE,
> -                                               "Flags");
> -
> -       queue_remove(service->pending_ext_props, chrc);
> -}
> -
> -static void read_ext_props(void *data, void *user_data)
> -{
> -       struct characteristic *chrc = data;
> -
> -       bt_gatt_client_read_value(chrc->service->client->gatt,
> -                                                       chrc->ext_props_handle,
> -                                                       read_ext_props_cb,
> -                                                       chrc, NULL);
> -}
> -
>  static bool create_descriptors(struct gatt_db_attribute *attr,
>                                         struct characteristic *charac)
>  {
> @@ -1555,9 +1515,6 @@ static void export_char(struct gatt_db_attribute *attr, void *user_data)
>
>         queue_push_tail(service->chrcs, charac);
>
> -       if (charac->ext_props_handle)
> -               queue_push_tail(service->pending_ext_props, charac);
> -
>         return;
>
>  fail:
> @@ -1574,13 +1531,7 @@ static bool create_characteristics(struct gatt_db_attribute *attr,
>
>         gatt_db_service_foreach_char(attr, export_char, &data);
>
> -       if (data.failed)
> -               return false;
> -
> -       /* Obtain extended properties */
> -       queue_foreach(service->pending_ext_props, read_ext_props, NULL);
> -
> -       return true;
> +       return !data.failed;
>  }
>
>  static void export_service(struct gatt_db_attribute *attr, void *user_data)
> --
> 2.5.5

Applied.


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2016-04-29 10:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-22 11:42 [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz
2016-04-22 11:42 ` [PATCH BlueZ 2/4] core/device: Remove code related to GattServices Luiz Augusto von Dentz
2016-04-22 11:42 ` [PATCH BlueZ 3/4] core/device: Fix not storing GATT attributes Luiz Augusto von Dentz
2016-04-22 11:42 ` [PATCH BlueZ 4/4] doc/settings-storage: Add alternative format for descriptors Luiz Augusto von Dentz
2016-04-29 10:07 ` [PATCH BlueZ 1/4] core/gatt-client: Don't read extended properties Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.