From 52ca0cb394f96aa4f1b98b72d8fe1dd3125f8cd0 Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Thu, 6 Jun 2013 11:06:45 +0700 Subject: [PATCH] AVRCP: Fix sending invalid attributes when responding to GetElementAttributes The list returned by media.c contains the attributes in string format not the binary format which cause us to send wrong/reserved attributes as can be observed bellow: > ACL data: handle 12 flags 0x02 dlen 58 L2CAP(d): cid 0x0041 len 54 [psm 23] AVCTP Control: Response : pt 0x00 transaction 14 pid 0x110e AV/C: Stable: address 0x48 opcode 0x00 Subunit: Panel Opcode: Vendor Dependent Company ID: 0x001958 AVRCP: GetElementAttributes: pt Single len 0x0029 AttributeCount: 0x05 Attribute: 0x00df9490 (Reserved) CharsetID: 0x006a (UTF-8) AttributeValueLength: 0x0000 AttributeValue: Attribute: 0x00e0e880 (Reserved) CharsetID: 0x006a (UTF-8) AttributeValueLength: 0x0000 AttributeValue: Attribute: 0x00e07b00 (Reserved) CharsetID: 0x006a (UTF-8) AttributeValueLength: 0x0000 AttributeValue: Attribute: 0x00e16bc0 (Reserved) CharsetID: 0x006a (UTF-8) AttributeValueLength: 0x0000 AttributeValue: Attribute: 0x00e07bc0 (Reserved) CharsetID: 0x006a (UTF-8) AttributeValueLength: 0x0000 AttributeValue: --- profiles/audio/avrcp.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c index 181bc387f..d03b41989 100644 --- a/profiles/audio/avrcp.c +++ b/profiles/audio/avrcp.c @@ -976,13 +976,43 @@ err: return AVC_CTYPE_REJECTED; } +static uint32_t str_to_metadata(const char *str) +{ + if (strcasecmp(str, "Title") == 0) + return AVRCP_MEDIA_ATTRIBUTE_TITLE; + else if (strcasecmp(str, "Artist") == 0) + return AVRCP_MEDIA_ATTRIBUTE_ARTIST; + else if (strcasecmp(str, "Album") == 0) + return AVRCP_MEDIA_ATTRIBUTE_ALBUM; + else if (strcasecmp(str, "Genre") == 0) + return AVRCP_MEDIA_ATTRIBUTE_GENRE; + else if (strcasecmp(str, "TrackNumber") == 0) + return AVRCP_MEDIA_ATTRIBUTE_TRACK; + else if (strcasecmp(str, "NumberOfTracks") == 0) + return AVRCP_MEDIA_ATTRIBUTE_N_TRACKS; + else if (strcasecmp(str, "Duration") == 0) + return AVRCP_MEDIA_ATTRIBUTE_DURATION; + + return 0; +} + static GList *player_list_metadata(struct avrcp_player *player) { - if (player != NULL) - return player->cb->list_metadata(player->user_data); + GList *l, *attrs = NULL; - return g_list_prepend(NULL, + if (player == NULL) + return g_list_prepend(NULL, GUINT_TO_POINTER(AVRCP_MEDIA_ATTRIBUTE_TITLE)); + + l = player->cb->list_metadata(player->user_data); + for (; l; l = l->next) { + const char *key = l->data; + + attrs = g_list_append(attrs, + GUINT_TO_POINTER(str_to_metadata(key))); + } + + return attrs; } static uint8_t avrcp_handle_get_element_attributes(struct avrcp *session, -- 2.11.0