diff mbox series

[BlueZ,3/4] monitor/att: Add decoding support for PAC Audio Context

Message ID 20220617004957.1148939-3-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 2bdb79cf8173daa0c44d692fcbd7d7408b4fd994
Headers show
Series [BlueZ,1/4] monitor/att: Print attribute information on ATT_REQ_RSP | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/checkpatch success Checkpatch PASS
tedd_an/gitlint success Gitlint PASS

Commit Message

Luiz Augusto von Dentz June 17, 2022, 12:49 a.m. UTC
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds decoding support for PAC Audio Context attributes:

> ACL Data RX: Handle 42 flags 0x02 dlen 9
      Channel: 65 len 5 sdu 3 [PSM 39 mode Enhanced Credit (0x81)] {chan 1}
      ATT: Read Request (0x0a) len 2
        Handle: 0x0026 Type: Supported Audio Contexts (0x2bce)
< ACL Data TX: Handle 42 flags 0x00 dlen 11
      Channel: 64 len 7 sdu 5 [PSM 39 mode Enhanced Credit (0x81)] {chan 1}
      ATT: Read Response (0x0b) len 4
        Value: ff0f0e00
        Handle: 0x0026 Type: Supported Audio Contexts (0x2bce)
            Sink Context: 0x0fff
              Unspecified (0x0001)
              Conversational (0x0002)
              Media (0x0004)
              Game (0x0008)
              Instructional (0x0010)
              Voice Assistants (0x0020)
              Live (0x0040)
              Sound Effects (0x0080)
              Notifications (0x0100)
              Ringtone (0x0200)
              Alerts (0x0400)
              Emergency alarm (0x0800)
            Source Context: 0x000e
              Conversational (0x0002)
              Media (0x0004)
              Game (0x0008)
---
 monitor/att.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)
diff mbox series

Patch

diff --git a/monitor/att.c b/monitor/att.c
index 8b47cbd9f..21fa5dde3 100644
--- a/monitor/att.c
+++ b/monitor/att.c
@@ -1118,6 +1118,69 @@  static void pac_loc_notify(const struct l2cap_frame *frame)
 	print_loc_pac(frame);
 }
 
+static const struct bitfield_data pac_context_table[] = {
+	{  0, "Unspecified (0x0001)"			},
+	{  1, "Conversational (0x0002)"			},
+	{  2, "Media (0x0004)"				},
+	{  3, "Game (0x0008)"				},
+	{  4, "Instructional (0x0010)"			},
+	{  5, "Voice Assistants (0x0020)"		},
+	{  6, "Live (0x0040)"				},
+	{  7, "Sound Effects (0x0080)"			},
+	{  8, "Notifications (0x0100)"			},
+	{  9, "Ringtone (0x0200)"			},
+	{  10, "Alerts (0x0400)"			},
+	{  11, "Emergency alarm (0x0800)"		},
+	{  12, "RFU (0x1000)"				},
+	{  13, "RFU (0x2000)"				},
+	{  14, "RFU (0x4000)"				},
+	{  15, "RFU (0x8000)"				},
+};
+
+static void print_pac_context(const struct l2cap_frame *frame)
+{
+	uint16_t snk, src;
+	uint16_t mask;
+
+	if (!l2cap_frame_get_le16((void *)frame, &snk)) {
+		print_text(COLOR_ERROR, "    value: invalid size");
+		goto done;
+	}
+
+	print_field("  Sink Context: 0x%4.4x", snk);
+
+	mask = print_bitfield(4, snk, pac_context_table);
+	if (mask)
+		print_text(COLOR_WHITE_BG, "    Unknown fields (0x%4.4x)",
+								mask);
+
+	if (!l2cap_frame_get_le16((void *)frame, &src)) {
+		print_text(COLOR_ERROR, "    sink: invalid size");
+		goto done;
+	}
+
+	print_field("  Source Context: 0x%4.4x", src);
+
+	mask = print_bitfield(4, src, pac_context_table);
+	if (mask)
+		print_text(COLOR_WHITE_BG, "    Unknown fields (0x%4.4x)",
+								mask);
+
+done:
+	if (frame->size)
+		print_hex_field("  Data", frame->data, frame->size);
+}
+
+static void pac_context_read(const struct l2cap_frame *frame)
+{
+	print_pac_context(frame);
+}
+
+static void pac_context_notify(const struct l2cap_frame *frame)
+{
+	print_pac_context(frame);
+}
+
 #define GATT_HANDLER(_uuid, _read, _write, _notify) \
 { \
 	.uuid = { \
@@ -1143,6 +1206,8 @@  struct gatt_handler {
 	GATT_HANDLER(0x2bca, pac_loc_read, NULL, pac_loc_notify),
 	GATT_HANDLER(0x2bcb, pac_read, NULL, pac_notify),
 	GATT_HANDLER(0x2bcc, pac_loc_read, NULL, pac_loc_notify),
+	GATT_HANDLER(0x2bcd, pac_context_read, NULL, pac_context_notify),
+	GATT_HANDLER(0x2bce, pac_context_read, NULL, pac_context_notify),
 };
 
 static struct gatt_handler *get_handler(struct gatt_db_attribute *attr)