Skip to contentSkip to conversation

shared/gatt-client: Automatically add CCC when discovering

PATCH Applied Luiz Augusto von Dentz 1 participant 2 messages Aug 26, 2019 – Sep 6, 2019 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/1 shared/gatt-client: Automatically add CCC when discovering

From: Luiz Augusto von Dentz <[email protected]>

The spec mandates that a CCC exists if either notify or indicate property is marked:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2357

"If set, the Client Characteristic Configuration Descriptor shall exist."

---
 src/shared/gatt-client.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
src/shared/gatt-client.c +25 -0
index 225915d43..38a416ed3 100644
@@ -659,6 +659,31 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
 
 		desc_start = chrc_data->value_handle + 1;
 
+		if (desc_start == chrc_data->end_handle &&
+			(chrc_data->properties & BT_GATT_CHRC_PROP_NOTIFY ||
+			 chrc_data->properties & BT_GATT_CHRC_PROP_INDICATE)) {
+			bt_uuid_t ccc_uuid;
+
+			/* If there is only one descriptor that must be the CCC
+			 * in case either notify or indicate are supported.
+			 */
+			bt_uuid16_create(&ccc_uuid,
+					GATT_CLIENT_CHARAC_CFG_UUID);
+			attr = gatt_db_insert_descriptor(client->db, desc_start,
+							&ccc_uuid, 0, NULL,
+							NULL, NULL);
+			if (attr) {
+				free(chrc_data);
+				continue;
+			}
+		}
+
+		/* Check if the start range is within characteristic range */
+		if (desc_start > chrc_data->end_handle) {
+			free(chrc_data);
+			continue;
+		}
+
 		client->discovery_req = bt_gatt_discover_descriptors(
 							client->att, desc_start,
 							chrc_data->end_handle,
Signature · 1 line
2.21.0
author maintainer Applied
#1 lore raw

Hi,

Quoted 51 lines · Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The spec mandates that a CCC exists if either notify or indicate property is marked:

BLUETOOTH CORE SPECIFICATION Version 5.1 | Vol 3, Part G page 2357

"If set, the Client Characteristic Configuration Descriptor shall exist."

---
 src/shared/gatt-client.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
src/shared/gatt-client.c +25 -1
index 225915d43..38a416ed3 100644
@@ -659,6 +659,31 @@ static bool discover_descs(struct discovery_op *op, bool *discovering)
 
                desc_start = chrc_data->value_handle + 1;
 
+               if (desc_start == chrc_data->end_handle &&
+                       (chrc_data->properties & BT_GATT_CHRC_PROP_NOTIFY ||
+                        chrc_data->properties & BT_GATT_CHRC_PROP_INDICATE)) {
+                       bt_uuid_t ccc_uuid;
+
+                       /* If there is only one descriptor that must be the CCC
+                        * in case either notify or indicate are supported.
+                        */
+                       bt_uuid16_create(&ccc_uuid,
+                                       GATT_CLIENT_CHARAC_CFG_UUID);
+                       attr = gatt_db_insert_descriptor(client->db, desc_start,
+                                                       &ccc_uuid, 0, NULL,
+                                                       NULL, NULL);
+                       if (attr) {
+                               free(chrc_data);
+                               continue;
+                       }
+               }
+
+               /* Check if the start range is within characteristic range */
+               if (desc_start > chrc_data->end_handle) {
+                       free(chrc_data);
+                       continue;
+               }
+
                client->discovery_req = bt_gatt_discover_descriptors(
                                                        client->att, desc_start,
                                                        chrc_data->end_handle,
--
Quoted 1 line

2.21.0

Applied.

Signature · 1 line
Luiz Augusto von Dentz