diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index efd61f9..2cb80ec 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
user_data);
}
-struct gatt_db_attribute *
-gatt_db_service_add_included(struct gatt_db_attribute *attrib,
+static struct gatt_db_attribute *
+service_insert_included(struct gatt_db_service *service, uint16_t handle,
struct gatt_db_attribute *include)
{
- struct gatt_db_service *service, *included;
+ struct gatt_db_service *included;
uint8_t value[MAX_INCLUDED_VALUE_LEN];
uint16_t included_handle, len = 0;
int index;
- if (!attrib || !include)
- return NULL;
-
- service = attrib->service;
included = include->service;
/* Adjust include to point to the first attribute */
if (!index)
return NULL;
- service->attributes[index] = new_attribute(service, 0,
+ /* Check if handle is in within service range */
+ if (handle && handle <= service->attributes[0]->handle)
+ return NULL;
+
+ if (!handle)
+ handle = get_handle_at_index(service, index - 1) + 1;
+
+ service->attributes[index] = new_attribute(service, handle,
&included_service_uuid,
value, len);
if (!service->attributes[index])
return attribute_update(service, index);
}
+struct gatt_db_attribute *
+gatt_db_service_add_included(struct gatt_db_attribute *attrib,
+ struct gatt_db_attribute *include)
+{
+ if (!attrib || !include)
+ return NULL;
+
+ return service_insert_included(attrib->service, 0, include);
+}
+
+struct gatt_db_attribute *
+gatt_db_service_insert_included(struct gatt_db_attribute *attrib,
+ uint16_t handle,
+ struct gatt_db_attribute *include)
+{
+ if (!attrib || !handle || !include)
+ return NULL;
+
+ return service_insert_included(attrib->service, handle, include);
+}
+
bool gatt_db_service_set_active(struct gatt_db_attribute *attrib, bool active)
{
struct gatt_db_service *service;
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index f8277fd..19583e7 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
struct gatt_db_attribute *
gatt_db_service_add_included(struct gatt_db_attribute *attrib,
struct gatt_db_attribute *include);
+struct gatt_db_attribute *
+gatt_db_service_insert_included(struct gatt_db_attribute *attrib,
+ uint16_t handle,
+ struct gatt_db_attribute *include);
bool gatt_db_service_set_active(struct gatt_db_attribute *attrib, bool active);
bool gatt_db_service_get_active(struct gatt_db_attribute *attrib);