Skip to contentSkip to conversation

shared/gatt-db: Expose gatt_db_attribute

PATCH Superseded Luiz Augusto von Dentz 3 participants 15 messages Oct 30, 2014 – Oct 31, 2014 Bluetooth drivers

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH v3 1/9 shared/gatt-db: Expose gatt_db_attribute

From: Luiz Augusto von Dentz <[email protected]>

This is the new API to reduce the lookups in gatt_db and make it a little bit more convenient for batch operations, so the general idea is to be able to get a hold of it via gatt_db_get_attribute but also replace the handles in the queues with proper attributes so the server code don't have to lookup again when reading/writing, checking permissions, or any other operation that can be done directly.
---
v2: Address problems gatt_db_attribute_read and gatt_db_attribute_write pointed out by Arman.
v3: Allow gatt_db_attribute_read to work if offset equals to value length.

 src/shared/gatt-db.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/gatt-db.h | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
src/shared/gatt-db.c +49 -0
index 6b5e84c..6c7234f 100644
@@ -802,3 +802,52 @@ bool gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle,
 	return true;
 
 }
+
+struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
+							uint16_t handle)
+{
+	return NULL;
+}
+
+uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
+{
+	return 0;
+}
+
+uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
+{
+	return 0;
+}
+
+const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
+{
+	return NULL;
+}
+
+bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
+							bt_uuid_t *uuid)
+{
+	return false;
+}
+
+bool gatt_db_attribute_get_permissions(struct gatt_db_attribute *attrib,
+							uint32_t *permissions)
+{
+	return false;
+}
+
+bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
+				uint8_t opcode, bdaddr_t *bdaddr,
+				gatt_db_attribute_read_t func, void *user_data)
+{
+	return false;
+}
+
+bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
+					const uint8_t *value, size_t len,
+					uint8_t opcode, bdaddr_t *bdaddr,
+					gatt_db_attribute_write_t func,
+					void *user_data)
+{
+	return false;
+}
src/shared/gatt-db.h +33 -0
index 8d18434..0c16e88 100644
@@ -96,3 +96,36 @@ bool gatt_db_get_service_uuid(struct gatt_db *db, uint16_t handle,
 
 bool gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle,
 							uint32_t *permissions);
+
+struct gatt_db_attribute;
+
+struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
+							uint16_t handle);
+
+uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib);
+uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib);
+
+const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib);
+
+bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
+							bt_uuid_t *uuid);
+
+bool gatt_db_attribute_get_permissions(struct gatt_db_attribute *attrib,
+							uint32_t *permissions);
+
+typedef void (*gatt_db_attribute_read_t) (struct gatt_db_attribute *attrib,
+					int err, uint8_t *value, size_t length,
+					void *user_data);
+
+bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
+				uint8_t opcode, bdaddr_t *bdaddr,
+				gatt_db_attribute_read_t func, void *user_data);
+
+typedef void (*gatt_db_attribute_write_t) (struct gatt_db_attribute *attrib,
+						int err, void *user_data);
+
+bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
+					const uint8_t *value, size_t len,
+					uint8_t opcode, bdaddr_t *bdaddr,
+					gatt_db_attribute_write_t func,
+					void *user_data);
Signature · 1 line
1.9.3
author maintainer
#1 lore raw

PATCH v3 2/9 shared/gatt-db: Add gatt_db_get_attribute

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +19 -1
index 6c7234f..1bbd3c5 100644
@@ -806,7 +806,25 @@ bool gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle,
 struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
 							uint16_t handle)
 {
-	return NULL;
+	struct gatt_db_service *service;
+	uint16_t service_handle;
+
+	if (!db || !handle)
+		return NULL;
+
+	service = queue_find(db->services, find_service_for_handle,
+							UINT_TO_PTR(handle));
+	if (!service)
+		return NULL;
+
+	service_handle = service->attributes[0]->handle;
+
+	/*
+	 * We can safely get attribute from attributes array with offset,
+	 * because find_service_for_handle() check if given handle is
+	 * in service range.
+	 */
+	return service->attributes[handle - service_handle];
 }
 
 uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
Signature · 1 line
1.9.3
author maintainer
#2 lore raw

PATCH v3 3/9 shared/gatt-db: Add gatt_db_attribute_get_type

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +4 -1
index 1bbd3c5..87a0653 100644
@@ -839,7 +839,10 @@ uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
 
 const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
 {
-	return NULL;
+	if (!attrib)
+		return NULL;
+
+	return &attrib->uuid;
 }
 
 bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
Signature · 1 line
1.9.3
author maintainer
#3 lore raw

PATCH v3 4/9 shared/gatt-db: Add gatt_db_attribute_get_service_uuid

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
src/shared/gatt-db.c +33 -8
index 87a0653..bb69032 100644
@@ -46,6 +46,7 @@ struct gatt_db {
 };
 
 struct gatt_db_attribute {
+	struct gatt_db_service *service;
 	uint16_t handle;
 	bt_uuid_t uuid;
 	uint32_t permissions;
@@ -70,7 +71,8 @@ static bool match_service_by_handle(const void *data, const void *user_data)
 	return service->attributes[0]->handle == PTR_TO_UINT(user_data);
 }
 
-static struct gatt_db_attribute *new_attribute(const bt_uuid_t *type,
+static struct gatt_db_attribute *new_attribute(struct gatt_db_service *service,
+							const bt_uuid_t *type,
 							const uint8_t *val,
 							uint16_t len)
 {
@@ -80,6 +82,7 @@ static struct gatt_db_attribute *new_attribute(const bt_uuid_t *type,
 	if (!attribute)
 		return NULL;
 
+	attribute->service = service;
 	attribute->uuid = *type;
 	attribute->value_len = len;
 	if (len) {
@@ -187,7 +190,7 @@ uint16_t gatt_db_add_service(struct gatt_db *db, const bt_uuid_t *uuid,
 
 	len = uuid_to_le(uuid, value);
 
-	service->attributes[0] = new_attribute(type, value, len);
+	service->attributes[0] = new_attribute(service, type, value, len);
 	if (!service->attributes[0]) {
 		gatt_db_service_destroy(service);
 		return 0;
@@ -297,14 +300,14 @@ uint16_t gatt_db_add_characteristic(struct gatt_db *db, uint16_t handle,
 	len += sizeof(uint16_t);
 	len += uuid_to_le(uuid, &value[3]);
 
-	service->attributes[i] = new_attribute(&characteristic_uuid, value,
-									len);
+	service->attributes[i] = new_attribute(service, &characteristic_uuid,
+								value, len);
 	if (!service->attributes[i])
 		return 0;
 
 	update_attribute_handle(service, i++);
 
-	service->attributes[i] = new_attribute(uuid, NULL, 0);
+	service->attributes[i] = new_attribute(service, uuid, NULL, 0);
 	if (!service->attributes[i]) {
 		free(service->attributes[i - 1]);
 		return 0;
@@ -335,7 +338,7 @@ uint16_t gatt_db_add_char_descriptor(struct gatt_db *db, uint16_t handle,
 	if (!i)
 		return 0;
 
-	service->attributes[i] = new_attribute(uuid, NULL, 0);
+	service->attributes[i] = new_attribute(service, uuid, NULL, 0);
 	if (!service->attributes[i])
 		return 0;
 
@@ -385,8 +388,9 @@ uint16_t gatt_db_add_included_service(struct gatt_db *db, uint16_t handle,
 	if (!index)
 		return 0;
 
-	service->attributes[index] = new_attribute(&included_service_uuid,
-								value, len);
+	service->attributes[index] = new_attribute(service,
+							&included_service_uuid,
+							value, len);
 	if (!service->attributes[index])
 		return 0;
 
@@ -848,6 +852,27 @@ const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
 bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
 							bt_uuid_t *uuid)
 {
+	if (!attrib || !uuid)
+		return false;
+
+	if (attrib->value_len == sizeof(uint16_t)) {
+		uint16_t value;
+
+		value = get_le16(attrib->value);
+		bt_uuid16_create(uuid, value);
+
+		return true;
+	}
+
+	if (attrib->value_len == sizeof(uint128_t)) {
+		uint128_t value;
+
+		bswap_128(attrib->value, &value);
+		bt_uuid128_create(uuid, value);
+
+		return true;
+	}
+
 	return false;
 }
 
Signature · 1 line
1.9.3
author maintainer
#4 lore raw

PATCH v3 5/9 shared/gatt-db: Add gatt_db_attribute_get_permissions

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +6 -1
index bb69032..00023db 100644
@@ -879,7 +879,12 @@ bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
 bool gatt_db_attribute_get_permissions(struct gatt_db_attribute *attrib,
 							uint32_t *permissions)
 {
-	return false;
+	if (!attrib || !permissions)
+		return false;
+
+	*permissions = attrib->permissions;
+
+	return true;
 }
 
 bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
Signature · 1 line
1.9.3
author maintainer
#5 lore raw

PATCH v3 6/9 shared/gatt-db: Add gatt_db_attribute_read

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +22 -1
index 00023db..a70af7b 100644
@@ -891,7 +891,28 @@ bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
 				uint8_t opcode, bdaddr_t *bdaddr,
 				gatt_db_attribute_read_t func, void *user_data)
 {
-	return false;
+	uint8_t *value;
+
+	if (!attrib || !func)
+		return false;
+
+	if (attrib->read_func) {
+		/* TODO: Pass callback function to read_func */
+		attrib->read_func(attrib->handle, offset, opcode, bdaddr,
+							attrib->user_data);
+		return true;
+	}
+
+	/* Check boundary if value is stored in the db */
+	if (offset > attrib->value_len)
+		return false;
+
+	/* Guard against invalid access if offset equals to value length */
+	value = offset == attrib->value_len ? NULL : &attrib->value[offset];
+
+	func(attrib, 0, value, attrib->value_len - offset, user_data);
+
+	return true;
 }
 
 bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
Signature · 1 line
1.9.3
author maintainer
#6 lore raw

PATCH v3 7/9 shared/gatt-db: Add gatt_db_attribute_write

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +26 -1
index a70af7b..6296a82 100644
@@ -921,5 +921,30 @@ bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
 					gatt_db_attribute_write_t func,
 					void *user_data)
 {
-	return false;
+	if (!attrib && !func)
+		return false;
+
+	if (attrib->write_func) {
+		attrib->write_func(attrib->handle, offset, value, len, opcode,
+						bdaddr, attrib->user_data);
+		return true;
+	}
+
+	/* For values stored in db allocate on demand */
+	if (!attrib->value || offset >= attrib->value_len ||
+				len > (unsigned) (attrib->value_len - offset)) {
+		attrib->value = realloc(attrib->value, len + offset);
+		if (!attrib->value)
+			return false;
+		/* Init data in the first allocation */
+		if (!attrib->value_len)
+			memset(attrib->value, 0, offset);
+		attrib->value_len = len + offset;
+	}
+
+	memcpy(&attrib->value[offset], value, len);
+
+	func(attrib, 0, user_data);
+
+	return true;
 }
Signature · 1 line
1.9.3
author maintainer
#7 lore raw

PATCH v3 8/9 shared/gatt-db: Add gatt_db_attribute_get_start_handle

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +4 -1
index 6296a82..60a1b23 100644
@@ -833,7 +833,10 @@ struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
 
 uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
 {
-	return 0;
+	if (!attrib)
+		return 0;
+
+	return attrib->handle;
 }
 
 uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
Signature · 1 line
1.9.3
author maintainer
#10 lore raw

PATCH v3 9/9 shared/gatt-db: Add gatt_db_attribute_get_end_handle

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +4 -1
index 60a1b23..74cd0be 100644
@@ -841,7 +841,10 @@ uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
 
 uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
 {
-	return 0;
+	if (!attrib)
+		return 0;
+
+	return attrib->handle + attrib->service->num_handles - 1;
 }
 
 const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
Signature · 1 line
1.9.3
#14 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 118 lines

From: Luiz Augusto von Dentz <[email protected]>

This is the new API to reduce the lookups in gatt_db and make it a little bit more convenient for batch operations, so the general idea is to be able to get a hold of it via gatt_db_get_attribute but also replace the handles in the queues with proper attributes so the server code don't have to lookup again when reading/writing, checking permissions, or any other operation that can be done directly.
---
v2: Address problems gatt_db_attribute_read and gatt_db_attribute_write pointed out by Arman.
v3: Allow gatt_db_attribute_read to work if offset equals to value length.

 src/shared/gatt-db.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/gatt-db.h | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
src/shared/gatt-db.c +49 -0
index 6b5e84c..6c7234f 100644
@@ -802,3 +802,52 @@ bool gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle,
        return true;
 
 }
+
+struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
+                                                       uint16_t handle)
+{
+       return NULL;
+}
+
+uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
+{
+       return 0;
+}
+
+uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
+{
+       return 0;
+}
+
+const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
+{
+       return NULL;
+}
+
+bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
+                                                       bt_uuid_t *uuid)
+{
+       return false;
+}
+
+bool gatt_db_attribute_get_permissions(struct gatt_db_attribute *attrib,
+                                                       uint32_t *permissions)
+{
+       return false;
+}
+
+bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
+                               uint8_t opcode, bdaddr_t *bdaddr,
+                               gatt_db_attribute_read_t func, void *user_data)
+{
+       return false;
+}
+
+bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
+                                       const uint8_t *value, size_t len,
+                                       uint8_t opcode, bdaddr_t *bdaddr,
+                                       gatt_db_attribute_write_t func,
+                                       void *user_data)
+{
+       return false;
+}
src/shared/gatt-db.h +33 -1
index 8d18434..0c16e88 100644
@@ -96,3 +96,36 @@ bool gatt_db_get_service_uuid(struct gatt_db *db, uint16_t handle,
 
 bool gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle,
                                                        uint32_t *permissions);
+
+struct gatt_db_attribute;
+
+struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
+                                                       uint16_t handle);
+
+uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib);
+uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib);
+
+const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib);
+
+bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
+                                                       bt_uuid_t *uuid);
+
+bool gatt_db_attribute_get_permissions(struct gatt_db_attribute *attrib,
+                                                       uint32_t *permissions);
+
+typedef void (*gatt_db_attribute_read_t) (struct gatt_db_attribute *attrib,
+                                       int err, uint8_t *value, size_t length,
+                                       void *user_data);
+
+bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
+                               uint8_t opcode, bdaddr_t *bdaddr,
+                               gatt_db_attribute_read_t func, void *user_data);
+
+typedef void (*gatt_db_attribute_write_t) (struct gatt_db_attribute *attrib,
+                                               int err, void *user_data);
+
+bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
+                                       const uint8_t *value, size_t len,
+                                       uint8_t opcode, bdaddr_t *bdaddr,
+                                       gatt_db_attribute_write_t func,
+                                       void *user_data);
--

1.9.3

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

This patch set looks good to me.

-Arman

Quoted 122 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This is the new API to reduce the lookups in gatt_db and make it a little bit more convenient for batch operations, so the general idea is to be able to get a hold of it via gatt_db_get_attribute but also replace the handles in the queues with proper attributes so the server code don't have to lookup again when reading/writing, checking permissions, or any other operation that can be done directly.
---
v2: Address problems gatt_db_attribute_read and gatt_db_attribute_write pointed out by Arman.
v3: Allow gatt_db_attribute_read to work if offset equals to value length.

 src/shared/gatt-db.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 src/shared/gatt-db.h | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 82 insertions(+)
src/shared/gatt-db.c +49 -0
index 6b5e84c..6c7234f 100644
@@ -802,3 +802,52 @@ bool gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle,
        return true;
 
 }
+
+struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
+                                                       uint16_t handle)
+{
+       return NULL;
+}
+
+uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
+{
+       return 0;
+}
+
+uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
+{
+       return 0;
+}
+
+const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
+{
+       return NULL;
+}
+
+bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
+                                                       bt_uuid_t *uuid)
+{
+       return false;
+}
+
+bool gatt_db_attribute_get_permissions(struct gatt_db_attribute *attrib,
+                                                       uint32_t *permissions)
+{
+       return false;
+}
+
+bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
+                               uint8_t opcode, bdaddr_t *bdaddr,
+                               gatt_db_attribute_read_t func, void *user_data)
+{
+       return false;
+}
+
+bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
+                                       const uint8_t *value, size_t len,
+                                       uint8_t opcode, bdaddr_t *bdaddr,
+                                       gatt_db_attribute_write_t func,
+                                       void *user_data)
+{
+       return false;
+}
src/shared/gatt-db.h +33 -1
index 8d18434..0c16e88 100644
@@ -96,3 +96,36 @@ bool gatt_db_get_service_uuid(struct gatt_db *db, uint16_t handle,
 
 bool gatt_db_get_attribute_permissions(struct gatt_db *db, uint16_t handle,
                                                        uint32_t *permissions);
+
+struct gatt_db_attribute;
+
+struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
+                                                       uint16_t handle);
+
+uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib);
+uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib);
+
+const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib);
+
+bool gatt_db_attribute_get_service_uuid(struct gatt_db_attribute *attrib,
+                                                       bt_uuid_t *uuid);
+
+bool gatt_db_attribute_get_permissions(struct gatt_db_attribute *attrib,
+                                                       uint32_t *permissions);
+
+typedef void (*gatt_db_attribute_read_t) (struct gatt_db_attribute *attrib,
+                                       int err, uint8_t *value, size_t length,
+                                       void *user_data);
+
+bool gatt_db_attribute_read(struct gatt_db_attribute *attrib, uint16_t offset,
+                               uint8_t opcode, bdaddr_t *bdaddr,
+                               gatt_db_attribute_read_t func, void *user_data);
+
+typedef void (*gatt_db_attribute_write_t) (struct gatt_db_attribute *attrib,
+                                               int err, void *user_data);
+
+bool gatt_db_attribute_write(struct gatt_db_attribute *attrib, uint16_t offset,
+                                       const uint8_t *value, size_t len,
+                                       uint8_t opcode, bdaddr_t *bdaddr,
+                                       gatt_db_attribute_write_t func,
+                                       void *user_data);
--

1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#11 lore raw

Re: [PATCH BlueZ v3 9/9] shared/gatt-db: Add gatt_db_attribute_get_end_handle

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 11 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +0 -0
index 60a1b23..74cd0be 100644

src/shared/gatt-db.c uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib) · line 847

Quoted 8 lines
src/shared/gatt-db.c +4 -1
@@ -841,7 +841,10 @@ uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
 
 uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
 {
-       return 0;
+       if (!attrib)
+               return 0;
+
+       return attrib->handle + attrib->service->num_handles - 1;

Is this right? If I have a non-first handle (one created by gatt_db_add_characteristic) this will give me a handle off the end of the service. I'm not sure of the meaning of start/end handle here.

Quoted 10 lines
src/shared/gatt-db.c +0 -1
 }
 
 const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
--

1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Michael Janssen
#12 lore raw

Re: [PATCH BlueZ v3 9/9] shared/gatt-db: Add gatt_db_attribute_get_end_handle

Hi Luiz & Michael,

Quoted 17 lines · Michael Janssen

Hi Luiz,

Quoted 12 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +0 -0
index 60a1b23..74cd0be 100644
@@ -841,7 +841,10 @@ uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
 
Quoted 12 lines

src/shared/gatt-db.c uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib) · line 847

Quoted 7 lines
src/shared/gatt-db.c +4 -1
 uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
 {
-       return 0;
+       if (!attrib)
+               return 0;
+
+       return attrib->handle + attrib->service->num_handles - 1;

Is this right? If I have a non-first handle (one created by gatt_db_add_characteristic) this will give me a handle off the end of the service. I'm not sure of the meaning of start/end handle here.

Good catch, the logic here is incorrect if attrib is not a service declaration. I think this method should basically return the end handle of the group the attribute belongs to. I don't know if this is what Luiz originally intended but since the only two legitimate attribute group types allowed by GATT are primary and secondary service declarations, I take the end handle here to mean the corresponding service end handle.

Quoted 11 lines
Quoted 10 lines
src/shared/gatt-db.c +0 -1
 }
 
 const bt_uuid_t *gatt_db_attribute_get_type(struct gatt_db_attribute *attrib)
--

1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Quoted 6 lines

--
Michael Janssen
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Cheers,
Arman

#8 lore raw

Re: [PATCH BlueZ v3 8/9] shared/gatt-db: Add gatt_db_attribute_get_start_handle

In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 12 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +0 -0
index 6296a82..60a1b23 100644

src/shared/gatt-db.c struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db, · line 834

Quoted 2 lines
src/shared/gatt-db.c +0 -0
@@ -833,7 +833,10 @@ struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
 
 uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)

Expanding on the discussion about gatt_db_attribute_get_end_handle, should we then rename this function to gatt_db_attribute_get_handle?

Quoted 12 lines
src/shared/gatt-db.c +4 -2
 {
-       return 0;
+       if (!attrib)
+               return 0;
+
+       return attrib->handle;
 }
 
 uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
--

1.9.3

Quoted 4 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Cheers,
Arman

author maintainer
#9 lore raw

Re: [PATCH BlueZ v3 8/9] shared/gatt-db: Add gatt_db_attribute_get_start_handle

Hi Arman,

Quoted 15 lines · Arman Uguray

Hi Luiz,

Quoted 13 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +0 -0
index 6296a82..60a1b23 100644
@@ -833,7 +833,10 @@ struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db,
 
Quoted 4 lines

src/shared/gatt-db.c struct gatt_db_attribute *gatt_db_get_attribute(struct gatt_db *db, · line 834

Quoted 1 line
src/shared/gatt-db.c +0 -0
 uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)

Expanding on the discussion about gatt_db_attribute_get_end_handle, should we then rename this function to gatt_db_attribute_get_handle?

Yep.

Signature · 1 line
Luiz Augusto von Dentz
author maintainer
#13 lore raw

Re: [PATCH BlueZ v3 9/9] shared/gatt-db: Add gatt_db_attribute_get_end_handle

In reply to Arman Uguray

Hi Arman,

Quoted 32 lines · Arman Uguray

Hi Luiz & Michael,

Quoted 17 lines · Michael Janssen

Hi Luiz,

Quoted 12 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
src/shared/gatt-db.c +0 -0
index 60a1b23..74cd0be 100644
@@ -841,7 +841,10 @@ uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib)
 
Quoted 12 lines

src/shared/gatt-db.c uint16_t gatt_db_attribute_get_start_handle(struct gatt_db_attribute *attrib) · line 847

Quoted 7 lines
src/shared/gatt-db.c +4 -1
 uint16_t gatt_db_attribute_get_end_handle(struct gatt_db_attribute *attrib)
 {
-       return 0;
+       if (!attrib)
+               return 0;
+
+       return attrib->handle + attrib->service->num_handles - 1;

Is this right? If I have a non-first handle (one created by gatt_db_add_characteristic) this will give me a handle off the end of the service. I'm not sure of the meaning of start/end handle here.

Quoted 7 lines

Good catch, the logic here is incorrect if attrib is not a service declaration. I think this method should basically return the end handle of the group the attribute belongs to. I don't know if this is what Luiz originally intended but since the only two legitimate attribute group types allowed by GATT are primary and secondary service declarations, I take the end handle here to mean the corresponding service end handle.

Yep, I think I will change this to gatt_db_attribute_get_service_handles(attrib, start_handle, end_handle) the original code had this as gatt_db_get_end_handle which don't mention it is service handles we are talking about.

Signature · 1 line
Luiz Augusto von Dentz