Linux-Bluetooth Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH BlueZ] shared/gatt-client: Automatically add CCC when discovering
@ 2019-08-26 12:06 Luiz Augusto von Dentz
  2019-09-06  8:14 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2019-08-26 12:06 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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(+)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 225915d43..38a416ed3 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -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,
-- 
2.21.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH BlueZ] shared/gatt-client: Automatically add CCC when discovering
  2019-08-26 12:06 [PATCH BlueZ] shared/gatt-client: Automatically add CCC when discovering Luiz Augusto von Dentz
@ 2019-09-06  8:14 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 2+ messages in thread
From: Luiz Augusto von Dentz @ 2019-09-06  8:14 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

On Mon, Aug 26, 2019 at 3:06 PM Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
>
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> 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(+)
>
> diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
> index 225915d43..38a416ed3 100644
> --- a/src/shared/gatt-client.c
> +++ b/src/shared/gatt-client.c
> @@ -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,
> --
> 2.21.0

Applied.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-26 12:06 [PATCH BlueZ] shared/gatt-client: Automatically add CCC when discovering Luiz Augusto von Dentz
2019-09-06  8:14 ` Luiz Augusto von Dentz

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox