diff mbox series

[BlueZ,2/2] monitor/att: Add support for decoding Characteristic Declaration

Message ID 20221104213649.36925-2-luiz.dentz@gmail.com
State New
Headers show
Series [BlueZ,1/2] monitor/att: Add handler support for Read by Type | expand

Commit Message

Luiz Augusto von Dentz Nov. 4, 2022, 9:36 p.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds supports for decoding the so called Characteristic
Declaration (0x2803):

> ACL Data RX: Handle 3585 flags 0x02 dlen 76
      ATT: Read By Type Response (0x09) len 71
        Attribute data length: 7
        Attribute data list: 10 entries
        Handle: 0x0002
        Value: 200300052a
            Properties: 0x20
              Indicate (0x20)
            Value Handle: 0x0003
            Value UUID: Service Changed (0x2a05)
        Handle: 0x0015
        Value: 021600002a
            Properties: 0x02
              Read (0x02)
            Value Handle: 0x0016
            Value UUID: Device Name (0x2a00)
        Handle: 0x0017
        Value: 021800012a
            Properties: 0x02
              Read (0x02)
            Value Handle: 0x0018
            Value UUID: Appearance (0x2a01)
        Handle: 0x0019
        Value: 021a00a62a
            Properties: 0x02
              Read (0x02)
            Value Handle: 0x001a
            Value UUID: Central Address Resolution (0x2aa6)
        Handle: 0x0029
        Value: 102a00372a
            Properties: 0x10
              Notify (0x10)
            Value Handle: 0x002a
            Value UUID: Heart Rate Measurement (0x2a37)
        Handle: 0x002c
        Value: 022d00382a
            Properties: 0x02
              Read (0x02)
            Value Handle: 0x002d
            Value UUID: Body Sensor Location (0x2a38)
        Handle: 0x002e
        Value: 082f00392a
            Properties: 0x08
              Write (0x08)
            Value Handle: 0x002f
            Value UUID: Heart Rate Control Point (0x2a39)
        Handle: 0x0031
        Value: 0a32008a2a
            Properties: 0x0a
              Read (0x02)
              Write (0x08)
            Value Handle: 0x0032
            Value UUID: First Name (0x2a8a)
        Handle: 0x0033
        Value: 0a3400902a
            Properties: 0x0a
              Read (0x02)
              Write (0x08)
            Value Handle: 0x0034
            Value UUID: Last Name (0x2a90)
        Handle: 0x0035
        Value: 0a36008c2a
            Properties: 0x0a
              Read (0x02)
              Write (0x08)
            Value Handle: 0x0036
            Value UUID: Gender (0x2a8c)
---
 monitor/att.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
diff mbox series

Patch

diff --git a/monitor/att.c b/monitor/att.c
index 289f4fc04d9a..efd840d51961 100644
--- a/monitor/att.c
+++ b/monitor/att.c
@@ -273,6 +273,46 @@  static void att_error_response(const struct l2cap_frame *frame)
 	print_field("Error: %s (0x%2.2x)", str, pdu->error);
 }
 
+static const struct bitfield_data chrc_prop_table[] = {
+	{  0, "Broadcast (0x01)"		},
+	{  1, "Read (0x02)"			},
+	{  2, "Write Without Response (0x04)"	},
+	{  3, "Write (0x08)"			},
+	{  4, "Notify (0x10)"			},
+	{  5, "Indicate (0x20)"			},
+	{  6, "Authorize (0x40)"		},
+	{  6, "Extended Properties (0x80)"	},
+	{ }
+};
+
+static void print_chrc(const struct l2cap_frame *frame)
+{
+	uint8_t prop;
+	uint8_t mask;
+
+	if (!l2cap_frame_get_u8((void *)frame, &prop)) {
+		print_text(COLOR_ERROR, "Property: invalid size");
+		return;
+	}
+
+	print_field("    Properties: 0x%2.2x", prop);
+
+	mask = print_bitfield(6, prop, chrc_prop_table);
+	if (mask)
+		print_text(COLOR_WHITE_BG, "    Unknown fields (0x%2.2x)",
+								mask);
+
+	if (!l2cap_frame_print_le16((void *)frame, "    Value Handle"))
+		return;
+
+	print_uuid("    Value UUID", frame->data, frame->size);
+}
+
+static void chrc_read(const struct l2cap_frame *frame)
+{
+	print_chrc(frame);
+}
+
 static const struct bitfield_data ccc_value_table[] = {
 	{  0, "Notification (0x01)"		},
 	{  1, "Indication (0x02)"		},
@@ -2314,6 +2354,7 @@  struct gatt_handler {
 	void (*write)(const struct l2cap_frame *frame);
 	void (*notify)(const struct l2cap_frame *frame);
 } gatt_handlers[] = {
+	GATT_HANDLER(0x2803, chrc_read, NULL, NULL),
 	GATT_HANDLER(0x2902, ccc_read, ccc_write, NULL),
 	GATT_HANDLER(0x2bc4, ase_read, NULL, ase_notify),
 	GATT_HANDLER(0x2bc5, ase_read, NULL, ase_notify),