From 6537fb763e2c81326f971c104ca25341c682b546 Mon Sep 17 00:00:00 2001 From: Marcin Kraglak Date: Thu, 15 May 2014 15:02:29 +0200 Subject: [PATCH] shared/gatt: Add helper function to get attribute type This will return uuid with attribute type or NULL if attribute was not found in database. --- src/shared/gatt-db.c | 21 +++++++++++++++++++++ src/shared/gatt-db.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index cb63754cd..0cca86f0f 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -730,3 +730,24 @@ bool gatt_db_write(struct gatt_db *db, uint16_t handle, uint16_t offset, return true; } + +const bt_uuid_t *gatt_db_get_attribute_type(struct gatt_db *db, + uint16_t handle) +{ + struct gatt_db_service *service; + struct gatt_db_attribute *attribute; + uint16_t service_handle; + + service = queue_find(db->services, find_service_for_handle, + INT_TO_PTR(handle)); + if (!service) + return NULL; + + service_handle = service->attributes[0]->handle; + + attribute = service->attributes[handle - service_handle]; + if (!attribute) + return NULL; + + return &attribute->uuid; +} diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h index 4f8b1dff5..02d564b3a 100644 --- a/src/shared/gatt-db.h +++ b/src/shared/gatt-db.h @@ -106,3 +106,6 @@ bool gatt_db_read(struct gatt_db *db, uint16_t handle, uint16_t offset, bool gatt_db_write(struct gatt_db *db, uint16_t handle, uint16_t offset, const uint8_t *value, size_t len, uint8_t att_opcode, bdaddr_t *bdaddr); + +const bt_uuid_t *gatt_db_get_attribute_type(struct gatt_db *db, + uint16_t handle); -- 2.47.3