summaryrefslogtreecommitdiff
path: root/src/gatt.c
diff options
context:
space:
mode:
authorAndre Guedes <andre.guedes@openbossa.org>2014-04-02 15:30:20 -0300
committerJohan Hedberg <johan.hedberg@intel.com>2014-04-03 10:22:55 +0300
commite985127b91331c97293ee063cb328c9e8fba9ea6 (patch)
treeaf49e86f37f382eb21b4836f5060e3ad16f0782c /src/gatt.c
parent2514293cd2c635dda51d3a562dd876056bb6c6c7 (diff)
downloadbluez-e985127b91331c97293ee063cb328c9e8fba9ea6.tar.gz
gatt: Add helper for removing GATT services
This patch adds the btd_gatt_remove_service() helper which removes a GATT primary (or secondary) Service declaration (including its characteristics) from the local attribute database.
Diffstat (limited to 'src/gatt.c')
-rw-r--r--src/gatt.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/gatt.c b/src/gatt.c
index f07effa14..306046286 100644
--- a/src/gatt.c
+++ b/src/gatt.c
@@ -26,6 +26,7 @@
#endif
#include <glib.h>
+#include <stdbool.h>
#include "log.h"
#include "lib/uuid.h"
@@ -104,6 +105,18 @@ static struct btd_attribute *new_attribute(const bt_uuid_t *type,
return attr;
}
+static bool is_service(const struct btd_attribute *attr)
+{
+ if (attr->type.type != BT_UUID16)
+ return false;
+
+ if (attr->type.value.u16 == GATT_PRIM_SVC_UUID ||
+ attr->type.value.u16 == GATT_SND_SVC_UUID)
+ return true;
+
+ return false;
+}
+
static int local_database_add(uint16_t handle, struct btd_attribute *attr)
{
attr->handle = handle;
@@ -149,6 +162,35 @@ struct btd_attribute *btd_gatt_add_service(const bt_uuid_t *uuid)
return attr;
}
+void btd_gatt_remove_service(struct btd_attribute *service)
+{
+ GList *list = g_list_find(local_attribute_db, service);
+ bool first_node;
+
+ if (!list)
+ return;
+
+ first_node = local_attribute_db == list;
+
+ /* Remove service declaration attribute */
+ free(list->data);
+ list = g_list_delete_link(list, list);
+
+ /* Remove all characteristics until next service declaration */
+ while (list && !is_service(list->data)) {
+ free(list->data);
+ list = g_list_delete_link(list, list);
+ }
+
+ /*
+ * When removing the first node, local attribute database head
+ * needs to be updated. Node removed from middle doesn't change
+ * the list head address.
+ */
+ if (first_node)
+ local_attribute_db = list;
+}
+
struct btd_attribute *btd_gatt_add_char(const bt_uuid_t *uuid,
uint8_t properties,
btd_attr_read_t read_cb,