Return-Path: From: Lukasz Rymanowski To: linux-bluetooth@vger.kernel.org Cc: szymon.janc@tieto.com, Marcin Kraglak Subject: [PATCH 19/36] shared/gatt: Add function to find by type Date: Tue, 29 Apr 2014 03:14:50 +0200 Message-Id: <1398734107-4793-21-git-send-email-lukasz.rymanowski@tieto.com> In-Reply-To: <1398734107-4793-1-git-send-email-lukasz.rymanowski@tieto.com> References: <1398734107-4793-1-git-send-email-lukasz.rymanowski@tieto.com> Sender: linux-bluetooth-owner@vger.kernel.org List-ID: From: Marcin Kraglak It will look for attributes with given uuid and value. --- src/shared/gatt-db.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/shared/gatt-db.h | 12 +++++++++ 2 files changed, 84 insertions(+) diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c index 26fdc84..c3645f1 100644 --- a/src/shared/gatt-db.c +++ b/src/shared/gatt-db.c @@ -480,3 +480,75 @@ void gatt_db_read_by_group_type(struct gatt_db *db, uint16_t start_handle, queue_foreach(db->services, read_by_group_type, &data); } + +struct find_by_type_value_data { + struct queue *queue; + bt_uuid_t uuid; + uint16_t start_handle; + uint16_t end_handle; + uint16_t value_length; + const uint8_t *value; +}; + +static void find_by_type_value(void *data, void *user_data) +{ + struct find_by_type_value_data *search_data = user_data; + struct gatt_db_service *service = data; + struct gatt_db_attribute *attribute; + struct gatt_db_range *range; + int i; + + if (!service->active) + return; + + for (i = 0; i < service->num_handles; i++) { + attribute = service->attributes[i]; + + if (!attribute) + continue; + + if ((attribute->handle < search_data->start_handle) || + (attribute->handle > search_data->end_handle)) + continue; + + if (bt_uuid_cmp(&search_data->uuid, &attribute->uuid)) + continue; + + if (attribute->value_len != search_data->value_length) + continue; + + if (!memcmp(attribute->value, search_data->value, + attribute->value_len)) + continue; + + range = new0(struct gatt_db_range, 1); + if (!range) + return; + + range->handle = attribute->handle; + range->end_group = service->attributes[0]->handle + + service->num_handles - 1; + + if (!queue_push_tail(search_data->queue, range)) + free(range); + } +} + +void gatt_db_find_by_type_value(struct gatt_db *db, uint16_t start_handle, + uint16_t end_handle, + const bt_uuid_t type, + const uint8_t *value, + uint16_t length, + struct queue *queue) +{ + struct find_by_type_value_data data; + + data.uuid = type; + data.start_handle = start_handle; + data.end_handle = end_handle; + data.queue = queue; + data.value_length = length; + data.value = value; + + queue_foreach(db->services, find_by_type_value, &data); +} diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h index 9d5e214..6b7897c 100644 --- a/src/shared/gatt-db.h +++ b/src/shared/gatt-db.h @@ -71,3 +71,15 @@ void gatt_db_read_by_group_type(struct gatt_db *db, uint16_t start_handle, uint16_t end_handle, const bt_uuid_t type, struct queue *queue); + +struct gatt_db_range { + uint16_t handle; + uint16_t end_group; +}; + +void gatt_db_find_by_type_value(struct gatt_db *db, uint16_t start_handle, + uint16_t end_handle, + const bt_uuid_t type, + const uint8_t *value, + uint16_t length, + struct queue *queue); -- 1.8.4