[PATCH v2 27/40] shared/gatt: Add support to read from database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/shared/gatt-db.c | 36 ++++++++++++++++++++++++++++++++++++
 src/shared/gatt-db.h |  3 +++
 2 files changed, 39 insertions(+)

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index b716ae6..dfe1a76 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -671,3 +671,39 @@ void gatt_db_find_information(struct gatt_db *db, uint16_t start_handle,
 
 	queue_foreach(db->services, find_information, &data);
 }
+
+static bool find_service_for_handle(const void *data, const void *user_data)
+{
+	const struct gatt_db_service *service = data;
+	uint16_t handle = PTR_TO_INT(user_data);
+	uint16_t start, end;
+
+	start = service->attributes[0]->handle;
+	end = start + service->num_handles;
+
+	return (start <= handle) && (handle < end);
+}
+
+bool gatt_db_read(struct gatt_db *db, uint16_t handle, uint16_t offset,
+				void *req_data, gatt_db_complete_func_t cb)
+{
+	struct gatt_db_service *service;
+	uint16_t service_handle;
+	struct gatt_db_attribute *a;
+
+	service = queue_find(db->services, find_service_for_handle,
+						INT_TO_PTR(handle));
+	if (!service)
+		return false;
+
+	service_handle = service->attributes[0]->handle;
+
+	a = service->attributes[handle - service_handle];
+	if (!a || !a->read_func)
+		return false;
+
+	a->read_func(handle, offset, req_data, cb, a->user_data);
+
+
+	return true;
+}
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 921e896..9a56c51 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -109,3 +109,6 @@ struct gatt_db_find_information {
 void gatt_db_find_information(struct gatt_db *db, uint16_t start_handle,
 							uint16_t end_handle,
 							struct queue *queue);
+
+bool gatt_db_read(struct gatt_db *db, uint16_t handle, uint16_t offset,
+			void *req_data, gatt_db_complete_func_t complete_cb);
-- 
1.8.4

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




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux