diff mbox series

[BlueZ,1/4] shared/gatt-db: Introduce gatt_db_service_add_ccc

Message ID 20220121205454.1413365-1-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/4] shared/gatt-db: Introduce gatt_db_service_add_ccc | expand

Commit Message

Luiz Augusto von Dentz Jan. 21, 2022, 8:54 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds gatt_db_service_add_ccc so the likes of plugins can use it
with the defaults callbacks which is useful for tracking their states.
---
 src/shared/gatt-db.c | 53 ++++++++++++++++++++++++++++++++++++++++++++
 src/shared/gatt-db.h |  7 ++++++
 2 files changed, 60 insertions(+)

Comments

Luiz Augusto von Dentz Jan. 28, 2022, 2:02 a.m. UTC | #1
Hi,

On Fri, Jan 21, 2022 at 3:40 PM <bluez.test.bot@gmail.com> wrote:
>
> This is automated email and please do not reply to this email!
>
> Dear submitter,
>
> Thank you for submitting the patches to the linux bluetooth mailing list.
> This is a CI test results with your patch series:
> PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=607383
>
> ---Test result---
>
> Test Summary:
> CheckPatch                    PASS      2.01 seconds
> GitLint                       PASS      1.36 seconds
> Prep - Setup ELL              PASS      38.22 seconds
> Build - Prep                  PASS      0.41 seconds
> Build - Configure             PASS      7.70 seconds
> Build - Make                  PASS      1301.25 seconds
> Make Check                    PASS      11.02 seconds
> Make Check w/Valgrind         PASS      399.26 seconds
> Make Distcheck                PASS      212.75 seconds
> Build w/ext ELL - Configure   PASS      7.61 seconds
> Build w/ext ELL - Make        PASS      1290.35 seconds
> Incremental Build with patchesPASS      5245.61 seconds
>
>
>
> ---
> Regards,
> Linux Bluetooth

Pushed.
diff mbox series

Patch

diff --git a/src/shared/gatt-db.c b/src/shared/gatt-db.c
index 3a02289ce..12ff5badb 100644
--- a/src/shared/gatt-db.c
+++ b/src/shared/gatt-db.c
@@ -44,6 +44,12 @@  static const bt_uuid_t included_service_uuid = { .type = BT_UUID16,
 static const bt_uuid_t ext_desc_uuid = { .type = BT_UUID16,
 				.value.u16 = GATT_CHARAC_EXT_PROPER_UUID };
 
+struct gatt_db_ccc {
+	gatt_db_read_t read_func;
+	gatt_db_write_t write_func;
+	void *user_data;
+};
+
 struct gatt_db {
 	int ref_count;
 	struct bt_crypto *crypto;
@@ -57,6 +63,8 @@  struct gatt_db {
 
 	gatt_db_authorize_cb_t authorize;
 	void *authorize_data;
+
+	struct gatt_db_ccc *ccc;
 };
 
 struct notify {
@@ -444,6 +452,7 @@  static void gatt_db_destroy(struct gatt_db *db)
 		timeout_remove(db->hash_id);
 
 	queue_destroy(db->services, gatt_db_service_destroy);
+	free(db->ccc);
 	free(db);
 }
 
@@ -1038,6 +1047,50 @@  gatt_db_service_add_descriptor(struct gatt_db_attribute *attrib,
 					user_data);
 }
 
+struct gatt_db_attribute *
+gatt_db_service_add_ccc(struct gatt_db_attribute *attrib, uint32_t permissions)
+{
+	struct gatt_db *db;
+	struct gatt_db_attribute *ccc;
+	bt_uuid_t uuid;
+
+	if (!attrib)
+		return NULL;
+
+	db = attrib->service->db;
+
+	if (!db->ccc)
+		return NULL;
+
+	bt_uuid16_create(&uuid, GATT_CLIENT_CHARAC_CFG_UUID);
+
+	ccc = service_insert_descriptor(attrib->service, 0, &uuid,
+					permissions,
+					db->ccc->read_func,
+					db->ccc->write_func,
+					db->ccc->user_data);
+	if (!ccc)
+		return ccc;
+
+	gatt_db_attribute_set_fixed_length(ccc, 2);
+
+	return ccc;
+}
+
+void gatt_db_ccc_register(struct gatt_db *db, gatt_db_read_t read_func,
+				gatt_db_write_t write_func, void *user_data)
+{
+	if (!db)
+		return;
+
+	if (!db->ccc)
+		db->ccc = new0(struct gatt_db_ccc, 1);
+
+	db->ccc->read_func = read_func;
+	db->ccc->write_func = write_func;
+	db->ccc->user_data = user_data;
+}
+
 static struct gatt_db_attribute *
 service_insert_included(struct gatt_db_service *service, uint16_t handle,
 					struct gatt_db_attribute *include)
diff --git a/src/shared/gatt-db.h b/src/shared/gatt-db.h
index 321a2aba6..3de22403c 100644
--- a/src/shared/gatt-db.h
+++ b/src/shared/gatt-db.h
@@ -92,6 +92,7 @@  gatt_db_service_add_descriptor(struct gatt_db_attribute *attrib,
 					gatt_db_read_t read_func,
 					gatt_db_write_t write_func,
 					void *user_data);
+
 struct gatt_db_attribute *
 gatt_db_service_insert_descriptor(struct gatt_db_attribute *attrib,
 					uint16_t handle,
@@ -101,6 +102,9 @@  gatt_db_service_insert_descriptor(struct gatt_db_attribute *attrib,
 					gatt_db_write_t write_func,
 					void *user_data);
 
+struct gatt_db_attribute *
+gatt_db_service_add_ccc(struct gatt_db_attribute *attrib, uint32_t permissions);
+
 struct gatt_db_attribute *
 gatt_db_insert_included(struct gatt_db *db, uint16_t handle,
 			struct gatt_db_attribute *include);
@@ -192,6 +196,9 @@  unsigned int gatt_db_register(struct gatt_db *db,
 					gatt_db_destroy_func_t destroy);
 bool gatt_db_unregister(struct gatt_db *db, unsigned int id);
 
+void gatt_db_ccc_register(struct gatt_db *db, gatt_db_read_t read_func,
+				gatt_db_write_t write_func, void *user_data);
+
 typedef uint8_t (*gatt_db_authorize_cb_t)(struct gatt_db_attribute *attrib,
 					uint8_t opcode, struct bt_att *att,
 					void *user_data);