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

Subsystems: the rest

STALE4348d

15 messages, 3 authors, 2014-10-31 · open the first message on its own page

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:37

From: Luiz Augusto von Dentz <redacted>

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(+)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 6b5e84c..6c7234f 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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;
+}
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 8d18434..0c16e88 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -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

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:38

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 6c7234f..1bbd3c5 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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)
-- 
1.9.3

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:39

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 1bbd3c5..87a0653 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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,
-- 
1.9.3

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:40

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 41 +++++++++++++++++++++++++++++++++--------
 1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 87a0653..bb69032 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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;
 }
 
-- 
1.9.3

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:41

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index bb69032..00023db 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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,
-- 
1.9.3

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:42

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 23 ++++++++++++++++++++++-
 1 file changed, 22 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 00023db..a70af7b 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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,
-- 
1.9.3

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:43

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index a70af7b..6296a82 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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;
 }
-- 
1.9.3

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:44

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 6296a82..60a1b23 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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)
-- 
1.9.3

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-30 13:57:45

From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 60a1b23..74cd0be 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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)
-- 
1.9.3

Re: [PATCH BlueZ v3 1/9] shared/gatt-db: Expose gatt_db_attribute

From: Arman Uguray <hidden>
Date: 2014-10-30 14:17:20

Hi Luiz,
quoted hunk
From: Luiz Augusto von Dentz <redacted>

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(+)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 6b5e84c..6c7234f 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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;
+}
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 8d18434..0c16e88 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
This patch set looks good to me.

-Arman


On Thu, Oct 30, 2014 at 6:57 AM, Luiz Augusto von Dentz
[off-list ref] wrote:
quoted hunk
From: Luiz Augusto von Dentz <redacted>

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(+)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 6b5e84c..6c7234f 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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;
+}
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 8d18434..0c16e88 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

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

From: Michael Janssen <hidden>
Date: 2014-10-30 17:17:07

Hi Luiz,

On Thu, Oct 30, 2014 at 6:57 AM, Luiz Augusto von Dentz
[off-list ref] wrote:
quoted hunk
From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 60a1b23..74cd0be 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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.
 }

 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
-- 
Michael Janssen

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

From: Arman Uguray <hidden>
Date: 2014-10-30 17:54:24

Hi Luiz & Michael,
On Thu, Oct 30, 2014 at 10:17 AM, Michael Janssen [off-list ref] wrote:
Hi Luiz,

On Thu, Oct 30, 2014 at 6:57 AM, Luiz Augusto von Dentz
[off-list ref] wrote:
quoted
From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 60a1b23..74cd0be 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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.
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
 }

 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 majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
Michael Janssen
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cheers,
Arman

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

From: Arman Uguray <hidden>
Date: 2014-10-30 17:56:48

Hi Luiz,
quoted hunk
On Thu, Oct 30, 2014 at 6:57 AM, Luiz Augusto von Dentz [off-list ref] wrote:
From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 6296a82..60a1b23 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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?
 {
-       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

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Cheers,
Arman

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-31 11:00:26

Hi Arman,

On Thu, Oct 30, 2014 at 7:56 PM, Arman Uguray [off-list ref] wrote:
Hi Luiz,
quoted
On Thu, Oct 30, 2014 at 6:57 AM, Luiz Augusto von Dentz [off-list ref] wrote:
From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 6296a82..60a1b23 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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?
Yep.

-- 
Luiz Augusto von Dentz

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

From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Date: 2014-10-31 11:07:45

Hi Arman,

On Thu, Oct 30, 2014 at 7:54 PM, Arman Uguray [off-list ref] wrote:
Hi Luiz & Michael,
quoted
On Thu, Oct 30, 2014 at 10:17 AM, Michael Janssen [off-list ref] wrote:
Hi Luiz,

On Thu, Oct 30, 2014 at 6:57 AM, Luiz Augusto von Dentz
[off-list ref] wrote:
quoted
From: Luiz Augusto von Dentz <redacted>

---
 src/shared/gatt-db.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 60a1b23..74cd0be 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -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.
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.


-- 
Luiz Augusto von Dentz
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help