monitor/att: Add decoding support for PAC Audio Context
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Thu, 16 Jun 2022 19:31:02 +0000 (12:31 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Mon, 15 May 2023 09:25:54 +0000 (14:55 +0530)
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)

Signed-off-by: Manika Shrivastava <manika.sh@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
monitor/att.c

index b055921..2fafea3 100644 (file)
@@ -1117,6 +1117,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 = { \
@@ -1142,6 +1205,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)