public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/4] monitor/att: Print value when printing descriptors
Date: Fri, 24 Mar 2023 16:38:54 -0700	[thread overview]
Message-ID: <20230324233856.3693370-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20230324233856.3693370-1-luiz.dentz@gmail.com>

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 --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:
-- 
2.39.2


  reply	other threads:[~2023-03-24 23:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 23:38 [PATCH BlueZ 1/4] shared/gatt-db: Make gatt_db_attribute_get_value public Luiz Augusto von Dentz
2023-03-24 23:38 ` Luiz Augusto von Dentz [this message]
2023-03-24 23:38 ` [PATCH BlueZ 3/4] monitor/att: Fix not loading gatt_db for devices using RPA Luiz Augusto von Dentz
2023-03-24 23:38 ` [PATCH BlueZ 4/4] monitor: Cache IRK being parsed Luiz Augusto von Dentz
2023-03-25  2:27 ` [BlueZ,1/4] shared/gatt-db: Make gatt_db_attribute_get_value public bluez.test.bot
2023-03-27 21:20 ` [PATCH BlueZ 1/4] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230324233856.3693370-2-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox