Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] shared/gatt-client: Do not assume single descriptor is CCC
@ 2026-11-30  7:33 Matthew Garrett
  2026-11-30 10:39 ` bluez.test.bot
  0 siblings, 1 reply; 2+ messages in thread
From: Matthew Garrett @ 2026-11-30  7:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Matthew Garrett

3.3.1.1 of the spec notes that notify and indicate properties require
that a CCC descriptor must be present, which implies that if a
characteristic only has a single descriptor it must be a CCC.
e8b9e6e33087 implements this logic, and assigns the descriptor to the
characteristic's CCC role.

Unfortunately, reality disagrees. We already handle notification
characteristics that lack a CCC - we allow notifications to be enabled
and assume that something else will happen to enable them, and then
deliver them. But because of e8b9e6e33087, if a notification
characteristic has a single descriptor following it, we will assume that
it's a CCC and so will assume that we can write to it in order to enable
notifications, and will error out if we can't.

The GE Cync bulbs that I have here have make use of the Telink BLE mesh
protocol. They provide a service with the following characteristics:

  Service 00010203-0405-0607-0809-0a0b0c0d1910 (handle 0x0010)
    Characteristic 00010203-0405-0607-0809-0a0b0c0d1911
      decl 0x0011, value 0x0012, props 0x1e (read/write-no-resp/write/notify)
      Descriptor 0x0013: 0x2901 (User Description), value "Status"
    Characteristic 00010203-0405-0607-0809-0a0b0c0d1912
      decl 0x0014, value 0x0015, props 0x0e (read/write-no-resp/write)
      Descriptor 0x0016: 0x2901 (User Description), value "Command"
    Characteristic 00010203-0405-0607-0809-0a0b0c0d1913
      decl 0x0017, value 0x0018, props 0x06 (read/write-no-resp)
      Descriptor 0x0019: 0x2901 (User Description), value "OTA"
    Characteristic 00010203-0405-0607-0809-0a0b0c0d1914
      decl 0x001a, value 0x001b, props 0x0e (read/write-no-resp/write)
      Descriptor 0x001c: 0x2901 (User Description), value "Pair"

Note that ...1911 has notify support, but the following descriptor is
User Description rather than CCC. e8b9e6e33087 means we assume that it's
a CCC anyway, and as a result attempting to enable notifications results
in a write to 0x13 which is read-only and gets an error and we're all
sad. We do not get any notifications today, or any other day. What the
hardware actually expects is that we write 0x01 to 0x0012, at which
point notifications are enabled, but if we've already errored out on
notification enabled then they'll never be delivered even if the
hardware is sending them.

This patch reverts most of e8b9e6e33087 and adds additional test cases
that correspond to the behaviour seen in this device, and now I get
notifications.

Fixes: e8b9e6e33087 ("shared/gatt-client: Automatically add CCC when discovering")
---
 src/shared/gatt-client.c | 19 -------------------
 unit/test-gatt.c         | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 31982bd29..6b177ebc0 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -787,25 +787,6 @@ 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);
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 3a35ccbc1..e25991639 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -321,7 +321,9 @@ struct context {
 		raw_pdu(0x09, 0x07, 0x02, 0x00, props, 0x03, 0x00, 0x05,\
 				0x2a),					\
 		raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),	\
-		raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a)
+		raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),			\
+		raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),			\
+		raw_pdu(0x05, 0x01, 0x04, 0x00, 0x02, 0x29)
 
 #define SERVER_MTU_EXCHANGE_PDU raw_pdu(0x02, 0x17, 0x00)
 
@@ -3922,6 +3924,33 @@ int main(int argc, char *argv[])
 			raw_pdu(),
 			raw_pdu(0x1B, 0x03, 0x00, 0x01, 0x02, 0x03));
 
+	/*
+	 * Characteristic declaring Notify with a single non-CCC descriptor
+	 * (0x2901 User Description): descriptor discovery must not assume
+	 * 0x2902, and notification registration must succeed without writing
+	 * to the non-CCC descriptor.
+	 */
+	define_test_client("/robustness/notify-single-non-ccc-desc",
+			test_client, NULL, &test_notification_1,
+			CLIENT_INIT_PDUS,
+			raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28),
+			raw_pdu(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x10, 0x19),
+			raw_pdu(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28),
+			raw_pdu(0x01, 0x10, 0x05, 0x00, 0x0a),
+			raw_pdu(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28),
+			raw_pdu(0x01, 0x10, 0x01, 0x00, 0x0a),
+			raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28),
+			raw_pdu(0x01, 0x08, 0x01, 0x00, 0x0a),
+			raw_pdu(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),
+			raw_pdu(0x09, 0x07, 0x02, 0x00, 0x10, 0x03, 0x00, 0x11,
+					0x19),
+			raw_pdu(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28),
+			raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a),
+			raw_pdu(0x04, 0x04, 0x00, 0x04, 0x00),
+			raw_pdu(0x05, 0x01, 0x04, 0x00, 0x01, 0x29),
+			raw_pdu(),
+			raw_pdu(0x1B, 0x03, 0x00, 0x01, 0x02, 0x03));
+
 	/* Service Changed with Indicate: indications are enabled */
 	define_test_client("/robustness/svc-chngd-indicate", test_client,
 			NULL, &test_svc_chngd_register_1,
-- 
2.55.0


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

end of thread, other threads:[~2026-11-30 10:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30  7:33 [PATCH] shared/gatt-client: Do not assume single descriptor is CCC Matthew Garrett
2026-11-30 10:39 ` bluez.test.bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox