diff mbox series

[BlueZ,2/4] monitor/att: Print value when printing descriptors

Message ID 20230324233856.3693370-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/4] shared/gatt-db: Make gatt_db_attribute_get_value public | expand

Commit Message

Luiz Augusto von Dentz March 24, 2023, 11:38 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This prints the value attribute information when print attribute
descriptors:

< ACL Data TX: Handle 3585 flags 0x00 dlen 9
      ATT: Write Request (0x12) len 4
        Handle: 0x002c Type: Client Characteristic Configuration (0x2902)
        Value Handle: 0x002b Type: Battery Level (0x2a19)
          Data: 0100
            Notification (0x01)
---
 monitor/att.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)
diff mbox series

Patch

diff --git a/monitor/att.c b/monitor/att.c
index 9f329370d698..42d1afe701a1 100644
--- a/monitor/att.c
+++ b/monitor/att.c
@@ -122,6 +122,56 @@  static struct att_read *att_get_read(const struct l2cap_frame *frame)
 	return queue_remove_if(data->reads, match_read_frame, (void *)frame);
 }
 
+static void print_value(struct gatt_db_attribute *attr)
+{
+	uint16_t handle;
+	struct gatt_db_attribute *val;
+	const bt_uuid_t *uuid;
+	bt_uuid_t chrc = {
+		.type = BT_UUID16,
+		.value.u16 = 0x2803,
+	};
+	char label[27];
+
+	uuid = gatt_db_attribute_get_type(attr);
+	if (!uuid)
+		return;
+
+	/* Skip in case of characteristic declaration since it already prints
+	 * the value handle and properties.
+	 */
+	if (!bt_uuid_cmp(uuid, &chrc))
+		return;
+
+	val = gatt_db_attribute_get_value(attr);
+	if (!val || val == attr)
+		return;
+
+	uuid = gatt_db_attribute_get_type(val);
+	if (!uuid)
+		return;
+
+	handle = gatt_db_attribute_get_handle(val);
+	if (!handle)
+		return;
+
+	switch (uuid->type) {
+	case BT_UUID16:
+		sprintf(label, "Value Handle: 0x%4.4x Type", handle);
+		print_field("%s: %s (0x%4.4x)", label,
+				bt_uuid16_to_str(uuid->value.u16),
+				uuid->value.u16);
+		return;
+	case BT_UUID128:
+		sprintf(label, "Value Handle: 0x%4.4x Type", handle);
+		print_uuid(label, &uuid->value.u128, 16);
+		return;
+	case BT_UUID_UNSPEC:
+	case BT_UUID32:
+		break;
+	}
+}
+
 static void print_attribute(struct gatt_db_attribute *attr)
 {
 	uint16_t handle;
@@ -142,10 +192,12 @@  static void print_attribute(struct gatt_db_attribute *attr)
 		print_field("%s: %s (0x%4.4x)", label,
 				bt_uuid16_to_str(uuid->value.u16),
 				uuid->value.u16);
+		print_value(attr);
 		return;
 	case BT_UUID128:
 		sprintf(label, "Handle: 0x%4.4x Type", handle);
 		print_uuid(label, &uuid->value.u128, 16);
+		print_value(attr);
 		return;
 	case BT_UUID_UNSPEC:
 	case BT_UUID32: