Diff between bd17b4e4a0215516f493ae66e80629c130c1b1d2 and bf9ca93ce9370cf880fd0d73ad6804ab5489990e

Changed Files

File Additions Deletions Status
src/gatt-database.c +59 -3 modified

Full Patch

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 5e577e5..42ceefa 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -1185,6 +1185,12 @@ static void proxy_added_cb(GDBusProxy *proxy, void *user_data)
 			return;
 		}
 
+		if (chrc->ext_props && !incr_attr_count(service, 1)) {
+			error("Failed to increment attribute count for CEP");
+			service->failed = true;
+			return;
+		}
+
 		queue_push_tail(service->chrcs, chrc);
 	} else
 		return;
@@ -1608,6 +1614,12 @@ static void property_changed_cb(GDBusProxy *proxy, const char *name,
 static bool database_add_ccc(struct external_service *service,
 						struct external_chrc *chrc)
 {
+	if (!(chrc->props & BT_GATT_CHRC_PROP_NOTIFY) &&
+				!(chrc->props & BT_GATT_CHRC_PROP_INDICATE)) {
+		DBG("No need to create CCC entry for characteristic");
+		return true;
+	}
+
 	chrc->ccc = service_add_ccc(service->attrib, service->database,
 						ccc_write_cb, chrc, NULL);
 	if (!chrc->ccc) {
@@ -1624,6 +1636,48 @@ static bool database_add_ccc(struct external_service *service,
 	return true;
 }
 
+static void cep_write_cb(struct gatt_db_attribute *attrib, int err,
+								void *user_data)
+{
+	if (err)
+		DBG("Failed to store CEP value in the database");
+	else
+		DBG("Stored CEP value in the database");
+}
+
+static bool database_add_cep(struct external_service *service,
+						struct external_chrc *chrc)
+{
+	struct gatt_db_attribute *cep;
+	bt_uuid_t uuid;
+	uint8_t value[2];
+
+	if (!chrc->ext_props) {
+		DBG("No need to create CEP entry for characteristic");
+		return true;
+	}
+
+	bt_uuid16_create(&uuid, GATT_CHARAC_EXT_PROPER_UUID);
+	cep = gatt_db_service_add_descriptor(service->attrib, &uuid,
+							BT_ATT_PERM_READ,
+							NULL, NULL, NULL);
+	if (!cep) {
+		error("Failed to create CEP entry for characteristic");
+		return false;
+	}
+
+	memset(value, 0, sizeof(value));
+	value[0] = chrc->ext_props;
+
+	if (!gatt_db_attribute_write(cep, 0, value, sizeof(value), 0, NULL,
+							cep_write_cb, NULL)) {
+		DBG("Failed to store CEP value in the database");
+		return false;
+	}
+
+	return true;
+}
+
 static bool database_add_chrc(struct external_service *service,
 						struct external_chrc *chrc)
 {
@@ -1655,9 +1709,11 @@ static bool database_add_chrc(struct external_service *service,
 		return false;
 	}
 
-	if (chrc->props & BT_GATT_CHRC_PROP_NOTIFY ||
-				chrc->props & BT_GATT_CHRC_PROP_INDICATE)
-		return database_add_ccc(service, chrc);
+	if (!database_add_ccc(service, chrc))
+		return false;
+
+	if (!database_add_cep(service, chrc))
+		return false;
 
 	return true;
 }