Diff between b2e75916392e77f5c2224b7c8caa9b8e6c59b2c9 and 7c3ca2a6b940d36c553fabe38066fabc66530dc9

Changed Files

File Additions Deletions Status
src/shared/gatt-client.c +5 -5 modified
unit/test-gatt.c +29 -14 modified

Full Patch

diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 4e10f24..9511ea8 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -1585,20 +1585,20 @@ static bool notify_data_write_ccc(struct notify_data *notify_data, bool enable,
 {
 	uint8_t pdu[4];
 	unsigned int att_id;
+	uint16_t properties = notify_data->chrc->properties;
 
 	assert(notify_data->chrc->ccc_handle);
 	memset(pdu, 0, sizeof(pdu));
 	put_le16(notify_data->chrc->ccc_handle, pdu);
 
 	if (enable) {
-		/* Try to enable notifications and/or indications based on
+		/* Try to enable notifications or indications based on
 		 * whatever the characteristic supports.
 		 */
-		if (notify_data->chrc->properties & BT_GATT_CHRC_PROP_NOTIFY)
+		if (properties & BT_GATT_CHRC_PROP_NOTIFY)
 			pdu[2] = 0x01;
-
-		if (notify_data->chrc->properties & BT_GATT_CHRC_PROP_INDICATE)
-			pdu[2] |= 0x02;
+		else if (properties & BT_GATT_CHRC_PROP_INDICATE)
+			pdu[2] = 0x02;
 
 		if (!pdu[2])
 			return false;
diff --git a/unit/test-gatt.c b/unit/test-gatt.c
index 4aa87d0..6a47268 100644
--- a/unit/test-gatt.c
+++ b/unit/test-gatt.c
@@ -241,8 +241,8 @@ struct context {
 #define CHARACTERISTIC_DISC_SMALL_DB					\
 		raw_pdu(0x08, 0x01, 0x00, 0xff, 0xff, 0x03, 0x28),	\
 		raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29,	\
-			0x2a),						\
-		raw_pdu(0x08, 0x03, 0x00, 0xff, 0xff, 0x03, 0x28),	\
+			0x2a, 0x07, 0x00, 0x22, 0x08, 0x00, 0x28, 0x2a),\
+		raw_pdu(0x08, 0x08, 0x00, 0xff, 0xff, 0x03, 0x28),	\
 		raw_pdu(0x09, 0x07, 0x12, 0xf0, 0x02, 0x13, 0xf0, 0x00,	\
 			0x2a),						\
 		raw_pdu(0x08, 0x13, 0xf0, 0xff, 0xff, 0x03, 0x28),	\
@@ -256,11 +256,17 @@ struct context {
 		raw_pdu(0x01, 0x08, 0x18, 0xf0, 0x0a)
 
 #define DESCRIPTOR_DISC_SMALL_DB					\
-		raw_pdu(0x04, 0x04, 0x00, 0x10, 0x00),			\
+		raw_pdu(0x04, 0x04, 0x00, 0x06, 0x00),			\
 		raw_pdu(0x05, 0x01, 0x04, 0x00, 0x02, 0x29, 0x05, 0x00,	\
 			0x01, 0x29),					\
-		raw_pdu(0x04, 0x06, 0x00, 0x10, 0x00),			\
-		raw_pdu(0x01, 0x04, 0x06, 0x00, 0x0a),			\
+		raw_pdu(0x04, 0x06, 0x00, 0x06, 0x00),			\
+		raw_pdu(0x05, 0x01, 0x06, 0x00, 0x00, 0x29),		\
+		raw_pdu(0x0a, 0x06, 0x00),				\
+		raw_pdu(0x0b, 0x01, 0x00),				\
+		raw_pdu(0x04, 0x09, 0x00, 0x10, 0x00),			\
+		raw_pdu(0x05, 0x01, 0x09, 0x00, 0x02, 0x29),		\
+		raw_pdu(0x04, 0x0a, 0x00, 0x10, 0x00),			\
+		raw_pdu(0x01, 0x04, 0x0a, 0x00, 0x0a),			\
 		raw_pdu(0x04, 0x16, 0xf0, 0x16, 0xf0),			\
 		raw_pdu(0x05, 0x01, 0x16, 0xf0, 0x00, 0x29),		\
 		raw_pdu(0x0a, 0x16, 0xf0),				\
@@ -1565,6 +1571,13 @@ static struct gatt_db *make_test_spec_small_db(void)
 							"Manufacturer Name"),
 		DESCRIPTOR(GATT_CHARAC_EXT_PROPER_UUID, BT_ATT_PERM_READ, 0x01,
 									0x00),
+		CHARACTERISTIC_STR(GATT_CHARAC_SOFTWARE_REVISION_STRING,
+						BT_ATT_PERM_READ,
+						BT_GATT_CHRC_PROP_READ |
+						BT_GATT_CHRC_PROP_INDICATE,
+						"5.59"),
+		DESCRIPTOR(GATT_CLIENT_CHARAC_CFG_UUID, BT_ATT_PERM_READ
+			| BT_ATT_PERM_WRITE, 0x00, 0x00),
 
 		PRIMARY_SERVICE(0xF010, GAP_UUID, 9),
 		INCLUDE(0x0001),
@@ -2308,7 +2321,7 @@ static void test_indication(struct context *context)
 }
 
 static const struct test_step test_indication_1 = {
-	.handle = 0x0003,
+	.handle = 0x0008,
 	.func = test_indication,
 	.value = read_data_1,
 	.length = 0x03,
@@ -2573,9 +2586,10 @@ int main(int argc, char *argv[])
 			raw_pdu(0x03, 0x00, 0x02),
 			raw_pdu(0x08, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x28),
 			raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29,
-					0x2a),
-			raw_pdu(0x08, 0x03, 0x00, 0x0f, 0x00, 0x03, 0x28),
-			raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a));
+					0x2a, 0x07, 0x00, 0x22, 0x08, 0x00,
+					0x28, 0x2a),
+			raw_pdu(0x08, 0x08, 0x00, 0x0f, 0x00, 0x03, 0x28),
+			raw_pdu(0x01, 0x08, 0x08, 0x00, 0x0a));
 
 	define_test_server("/TP/GAD/SR/BV-04-C/large-1", test_server,
 			ts_large_db_1, NULL,
@@ -2626,9 +2640,10 @@ int main(int argc, char *argv[])
 			raw_pdu(0x03, 0x00, 0x02),
 			raw_pdu(0x08, 0x01, 0x00, 0x0f, 0x00, 0x03, 0x28),
 			raw_pdu(0x09, 0x07, 0x02, 0x00, 0xb2, 0x03, 0x00, 0x29,
-					0x2a),
-			raw_pdu(0x08, 0x03, 0x00, 0x0f, 0x00, 0x03, 0x28),
-			raw_pdu(0x01, 0x08, 0x03, 0x00, 0x0a));
+					0x2a, 0x07, 0x00, 0x22, 0x08, 0x00,
+					0x28, 0x2a),
+			raw_pdu(0x08, 0x08, 0x00, 0x0f, 0x00, 0x03, 0x28),
+			raw_pdu(0x01, 0x08, 0x08, 0x00, 0x0a));
 
 	define_test_server("/TP/GAD/SR/BV-05-C/large-1", test_server,
 			ts_large_db_1, NULL,
@@ -3241,7 +3256,7 @@ int main(int argc, char *argv[])
 			&test_notification_1,
 			CLIENT_INIT_PDUS,
 			SMALL_DB_DISCOVERY_PDUS,
-			raw_pdu(0x12, 0x04, 0x00, 0x03, 0x00),
+			raw_pdu(0x12, 0x04, 0x00, 0x01, 0x00),
 			raw_pdu(0x13),
 			raw_pdu(),
 			raw_pdu(0x1B, 0x03, 0x00, 0x01, 0x02, 0x03));
@@ -3267,7 +3282,7 @@ int main(int argc, char *argv[])
 			&test_indication_1,
 			CLIENT_INIT_PDUS,
 			SMALL_DB_DISCOVERY_PDUS,
-			raw_pdu(0x12, 0x04, 0x00, 0x03, 0x00),
+			raw_pdu(0x12, 0x09, 0x00, 0x02, 0x00),
 			raw_pdu(0x13),
 			raw_pdu(),
 			raw_pdu(0x1D, 0x03, 0x00, 0x01, 0x02, 0x03),