linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 12/15] AVRCP: Fix sending invalid attributes when responding to GetElementAttributes
Date: Mon, 10 Jun 2013 13:37:07 +0300	[thread overview]
Message-ID: <1370860630-30359-12-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1370860630-30359-1-git-send-email-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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 | 39 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 34 insertions(+), 5 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index f439ab3..7eaadf4 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -977,13 +977,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,
@@ -2123,8 +2153,7 @@ static gboolean avrcp_get_item_attributes_rsp(struct avctp *conn,
 	}
 
 	if (pdu->params[0] != AVRCP_STATUS_SUCCESS || operand_count < 4) {
-		if (pdu->params[0] == AVRCP_STATUS_PLAYER_NOT_BROWSABLE)
-			avrcp_get_element_attributes(session);
+		avrcp_get_element_attributes(session);
 		return FALSE;
 	}
 
-- 
1.8.1.4


  parent reply	other threads:[~2013-06-10 10:37 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-10 10:36 [PATCH BlueZ 01/15] AVRCP: Fix crash when registering unsupported notification Luiz Augusto von Dentz
2013-06-10 10:36 ` [PATCH BlueZ 02/15] AVCTP: Fix coding style Luiz Augusto von Dentz
2013-06-10 10:36 ` [PATCH BlueZ 03/15] AVCTP: Call callback in case the request timeout Luiz Augusto von Dentz
2013-06-10 10:36 ` [PATCH BlueZ 04/15] AVRCP: Fix crash while listing available settings in TG role Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 05/15] AVRCP: Add additional protocol discriptor list for Browsing channel Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 06/15] AVRCP: Fix crash when current addressed player is removed Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 07/15] AVRCP: Fix crash if player status is NULL Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 08/15] AVRCP: Fix setting reserved bit in GetCapabilities response Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 09/15] AVRCP: Fix crash when connecting role without a record Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 10/15] AVRCP: Fix crash while setting player volume Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 11/15] core: Fix not been able to cancel Device.Connect with Device.Disconnect Luiz Augusto von Dentz
2013-06-10 10:37 ` Luiz Augusto von Dentz [this message]
2013-06-10 10:37 ` [PATCH BlueZ 13/15] AVRCP: Fix sending SetPlayerApplicationSettingValue using notify command type Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 14/15] obexd: Fix crash when resetting OPP session without a transfer Luiz Augusto von Dentz
2013-06-10 10:37 ` [PATCH BlueZ 15/15] obexd: Fix not checking for valid fd on NewConnection Luiz Augusto von Dentz
2013-06-11 21:16 ` [PATCH BlueZ 01/15] AVRCP: Fix crash when registering unsupported notification Luiz Augusto von Dentz

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=1370860630-30359-12-git-send-email-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;
as well as URLs for NNTP newsgroup(s).