Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role
@ 2026-11-22 10:57 Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 1/8] avrcp: Fix not checking browsing PDU parameter length Simon Mikuda
                   ` (7 more replies)
  0 siblings, 8 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

Patches 1-11 fix the AVRCP browsing code, mostly in the controller
role: the browsing PDU parameter length is not checked against the
bytes received, the media player list cannot be read up to item
0xffffffff, ADDRESSED_PLAYER_CHANGED and TRACK_CHANGED are sent in the
wrong byte order, a player addressed before it was listed is never
browsed, Search in a folder whose name has a space crashes bluetoothd,
and listed Now Playing items lose their Name and NumberOfItems. Each
patch has its reproduction steps and the logs it showed. A unit test
and a functional test (with its documentation) cover two of them.

Patches 12-13 prepare avctp to answer a browsing command later, from a
D-Bus reply.

Patches 14-22 add browsing in the target role: a local player
registered with org.bluez.Media1.RegisterPlayer can expose a folder
tree (org.bluez.MediaFolder1 and org.bluez.MediaItem1 on the
application's objects), which a remote controller browses, and cover
art, offered in the target record for a player that registers an
ObexPort. Documentation, the D-Bus
policy and a functional test come with them.

Testing: every patch builds in maintainer mode (-Werror, ASan/UBSan)
and the unit tests CI maps to these files pass (make check). The series
was developed and tried against phones and other BlueZ controllers on
an earlier base (2026-10-12); rebased on this one it was build- and
unit-tested only, and the functional tests (test/test-functional) were
not run for this version. Valgrind, scan-build and distcheck were not
run.

Not included: the GetTotalNumberOfItems parameter length fix of the
earlier version, as a80671987 ("avrcp: Fix GetTotalNumberOfItems
command encoding") fixed the same thing.

AI assistance: Claude (claude-opus-5-5) was used for analysis, code,
tests and the commit messages; every patch carries Assisted-by.

Simon Mikuda (8):
  avrcp: Fix not checking browsing PDU parameter length
  avrcp: Fix listing media players up to item 0xffffffff
  avrcp: Fix byte order of ADDRESSED_PLAYER_CHANGED notification
  avrcp: Fix byte order of TRACK_CHANGED identifier
  avrcp: Fix not browsing a player addressed before it was listed
  player: Fix crash on Search in a folder with a space in its name
  player: Fix missing Name of listed Now Playing items
  player: Fix NumberOfItems of Now Playing after its content changed

 profiles/audio/avrcp.c  | 35 +++++++++++++++++-----
 profiles/audio/player.c | 66 ++++++++++++++++++++++++++++++++++++++---
 2 files changed, 90 insertions(+), 11 deletions(-)


base-commit: 1adfe662efeff12997df9ddd0960dbd0de9c8ea7
-- 
2.43.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 1/8] avrcp: Fix not checking browsing PDU parameter length
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  2026-11-22 18:57   ` AVRCP browsing fixes, and browsing and cover art in the target role bluez.test.bot
  2026-11-22 10:57 ` [PATCH BlueZ 2/8] avrcp: Fix listing media players up to item 0xffffffff Simon Mikuda
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

The parameter length of a browsing PDU is not checked against the
number of bytes received, so a handler takes the parameters missing
from a short PDU from whatever the buffer held before.

To reproduce, send to the target a GetFolderItems with a parameter
length of 10 but no parameters. It is answered from the zeroed buffer
as a request for the media players 0 to 0:

  btmon: AVRCP: GetFolderItems: len 0x000a
  handle_browsing_pdu() AVRCP Browsing PDU 0x71, len 0x000A
  avrcp_handle_get_folder_items() scope 0x00 start_item 0x00000000
      end_item 0x00000000
  btmon: AVRCP: GetFolderItems: len 0x002c
  btmon: Status: 0x04 (Success)
  btmon: NumOfItems: 0x0001 (1)
  btmon: Name: Player A

Reject a PDU whose parameter length does not match, as the control
channel does since commit e2b0f0d8d63e ("avrcp: Fix not checking if
params_len match number of received bytes").

Fixes: 731aec9cae63 ("AVRCP: Add handler for browsing PDUs")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/avrcp.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 2f214e982..95b1d8c47 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -2164,9 +2164,20 @@ static size_t handle_browsing_pdu(struct avctp *conn,
 	const struct browsing_pdu_handler *handler;
 	struct avrcp_browsing_header *pdu = (void *) operands;
 
+	if (operand_count < AVRCP_BROWSING_HEADER_LENGTH)
+		return avrcp_browsing_general_reject(operands);
+
 	DBG("AVRCP Browsing PDU 0x%02X, len 0x%04X", pdu->pdu_id,
 						be16_to_cpu(pdu->param_len));
 
+	if (be16_to_cpu(pdu->param_len) !=
+			operand_count - AVRCP_BROWSING_HEADER_LENGTH) {
+		DBG("AVRCP Browsing PDU parameters length don't match");
+		pdu->params[0] = AVRCP_STATUS_INVALID_PARAM;
+		pdu->param_len = cpu_to_be16(1);
+		return AVRCP_BROWSING_HEADER_LENGTH + 1;
+	}
+
 	for (handler = browsing_handlers; handler->pdu_id; handler++) {
 		if (handler->pdu_id == pdu->pdu_id)
 			goto done;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 2/8] avrcp: Fix listing media players up to item 0xffffffff
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 1/8] avrcp: Fix not checking browsing PDU parameter length Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 3/8] avrcp: Fix byte order of ADDRESSED_PLAYER_CHANGED notification Simon Mikuda
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

GetFolderItems for the media player list stops once it has
end_item - start_item + 1 items, which overflows to 0 for a request
from 0 to 0xffffffff, so the list stops before the first player and is
answered with Range Out of Bounds. That is the request the BlueZ
controller sends, so it never learns the target's players.

To reproduce, register a media player on the target and connect AVRCP
from a BlueZ controller, whose player never gets a Name:

  btmon: AVRCP: GetFolderItems: len 0x000a
  btmon: Scope: 0x00 (Media Player List)
  btmon: StartItem: 0x00000000 (0)
  btmon: EndItem: 0xffffffff (4294967295)
  avrcp_handle_get_folder_items() scope 0x00 start_item 0x00000000
      end_item 0xffffffff
  btmon: AVRCP: GetFolderItems: len 0x0001
  btmon: Status: 0x0b (Range Out of Bounds)

Fixes: d6bb0111b569 ("audio/avrcp: Add GetFolderItems support")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/avrcp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 95b1d8c47..3ab7b6d7c 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -1997,7 +1997,7 @@ static void avrcp_handle_media_player_list(struct avrcp *session,
 		struct player_item *item;
 		uint16_t namelen;
 
-		if (rsp->num_items == (end_item - start_item) + 1)
+		if (rsp->num_items > end_item - start_item)
 			break;
 
 		folder = (void *)&pdu->params[pdu->param_len];
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 3/8] avrcp: Fix byte order of ADDRESSED_PLAYER_CHANGED notification
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 1/8] avrcp: Fix not checking browsing PDU parameter length Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 2/8] avrcp: Fix listing media players up to item 0xffffffff Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 4/8] avrcp: Fix byte order of TRACK_CHANGED identifier Simon Mikuda
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

The Player Id and UID Counter of the CHANGED response were copied in
host byte order, so on a little endian host player 1 is announced as
player 256. The interim response already sends them in big endian.

To reproduce, register for EVENT_ADDRESSED_PLAYER_CHANGED and send
SetAddressedPlayer for player 1:

  AV/C: Interim  AVRCP: RegisterNotification  EventID: 0x0b
      (EVENT_ADDRESSED_PLAYER_CHANGED)
  btmon:         PlayerID: 0x0001 (1)
  btmon: AV/C: Control  AVRCP: SetAddressedPlayer pt Single len 0x0002
  btmon:         PlayerID: 0x0001 (1)
  btmon: AV/C: Changed  AVRCP: RegisterNotification pt Single len 0x0005
  btmon:         EventID: 0x0b (EVENT_ADDRESSED_PLAYER_CHANGED)
  btmon:         PlayerID: 0x0100 (256)

Fixes: 4827d6b61fd4 ("audio/avrcp: Add Set Addressed Player support")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/avrcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index 3ab7b6d7c..aff1c381a 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -803,8 +803,8 @@ void avrcp_player_event(struct avrcp_player *player, uint8_t id,
 		break;
 	case AVRCP_EVENT_ADDRESSED_PLAYER_CHANGED:
 		size = 5;
-		memcpy(&pdu->params[1], &player->id, sizeof(uint16_t));
-		memcpy(&pdu->params[3], &player->uid_counter, sizeof(uint16_t));
+		put_be16(player->id, &pdu->params[1]);
+		put_be16(player->uid_counter, &pdu->params[3]);
 		break;
 	case AVRCP_EVENT_AVAILABLE_PLAYERS_CHANGED:
 		size = 1;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 4/8] avrcp: Fix byte order of TRACK_CHANGED identifier
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
                   ` (2 preceding siblings ...)
  2026-11-22 10:57 ` [PATCH BlueZ 3/8] avrcp: Fix byte order of ADDRESSED_PLAYER_CHANGED notification Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 5/8] avrcp: Fix not browsing a player addressed before it was listed Simon Mikuda
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

The Identifier of TRACK_CHANGED, in the interim and the changed
response, was copied in host byte order. The identifiers sent so far, 0
and UINT64_MAX, read the same in either byte order, but any other one,
such as the UID of an item of a browsable player, is swapped on a
little endian host, and the controller then asks for an item that does
not exist.

To reproduce, with a target that reports the UID of the current track,
as "avrcp: Add browsing support in the target role" later in this
series does, change the track to the item of UID 2:

  btmon: EventID: 0x02 (EVENT_TRACK_CHANGED)
  btmon: Identifier: 0x 200000000000000 (144115188075855872)
  btmon: AVRCP: GetItemAttributes: len 0x000c
  btmon: UID: 0x0200000000000000 (144115188075855872)
  btmon: AVRCP: GetItemAttributes: len 0x0001
  btmon: Status: 0x09 (Does Not Exist)

Fixes: 9ab125a8ec20 ("AVRCP: Use track's UID in event notification")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/avrcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index aff1c381a..fbd212511 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -791,7 +791,7 @@ void avrcp_player_event(struct avrcp_player *player, uint8_t id,
 		break;
 	case AVRCP_EVENT_TRACK_CHANGED:
 		size = 9;
-		memcpy(&pdu->params[1], data, sizeof(uint64_t));
+		put_be64(*(const uint64_t *) data, &pdu->params[1]);
 
 		break;
 	case AVRCP_EVENT_TRACK_REACHED_END:
@@ -1629,7 +1629,7 @@ static uint8_t avrcp_handle_register_notification(struct avrcp *session,
 	case AVRCP_EVENT_TRACK_CHANGED:
 		len = 9;
 		uid = player_get_uid(player);
-		memcpy(&pdu->params[1], &uid, sizeof(uint64_t));
+		put_be64(uid, &pdu->params[1]);
 
 		break;
 	case AVRCP_EVENT_TRACK_REACHED_END:
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 5/8] avrcp: Fix not browsing a player addressed before it was listed
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
                   ` (3 preceding siblings ...)
  2026-11-22 10:57 ` [PATCH BlueZ 4/8] avrcp: Fix byte order of TRACK_CHANGED identifier Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 6/8] player: Fix crash on Search in a folder with a space in its name Simon Mikuda
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

SetBrowsedPlayer is sent for a browsable player from the player list
only if the player is addressed. But ADDRESSED_PLAYER_CHANGED does not
mark the player addressed when its id is already the id of the current
player: the player 0 of a target that has no player at connection, or
a player whose id was taken from the player list. Neither that
notification nor the SetAddressedPlayer response sends SetBrowsedPlayer,
so the player never gets the MediaFolder1 interface.

To reproduce, connect AVRCP to a target without a player, then register
a browsable player on the target. The controller gets the player from
the list as browsable, but never browses it:

  btmon: EventID: 0x0a (EVENT_AVAILABLE_PLAYERS_CHANGED)
  btmon: AVRCP: GetFolderItems: len 0x000a
  btmon: Scope: 0x00 (Media Player List)
  btmon: AVRCP: GetFolderItems: len 0x003a
  btmon: PlayerID: 0x0001 (1)
  btmon: Browsing
  btmon: Name: BlueZ Browsable Player
  bluetoothd: profiles/audio/player.c:media_player_set_browsable() true
  media_player_set_name() BlueZ Browsable Player

and no SetBrowsedPlayer follows.

Mark the player addressed also in that case, and send SetBrowsedPlayer
once the player is addressed.

Fixes: 39a62aaa29b8 ("audio/avrcp: Don't send SetBrowsedPlayer if player is not browsable")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/avrcp.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/profiles/audio/avrcp.c b/profiles/audio/avrcp.c
index fbd212511..128d7fe39 100644
--- a/profiles/audio/avrcp.c
+++ b/profiles/audio/avrcp.c
@@ -344,6 +344,8 @@ static const uint32_t company_ids[] = {
 static void avrcp_register_notification(struct avrcp *session, uint8_t event);
 static GList *player_list_settings(struct avrcp_player *player);
 static void avrcp_get_play_status(struct avrcp *session);
+static void set_browsed_player(struct avrcp *session,
+					struct avrcp_player *player);
 
 static void avrcp_browsing_record(sdp_record_t *record, sdp_data_t *version)
 {
@@ -3063,10 +3065,11 @@ static gboolean avrcp_set_addressed_player_rsp(struct avctp *conn, uint8_t code,
 	if (!operands || code != AVC_CTYPE_ACCEPTED)
 		return FALSE;
 
-	if (!avrcp_pull_header(&iov))
+	if (!avrcp_pull_header(&iov) || player->addressed)
 		return FALSE;
 
 	player->addressed = true;
+	set_browsed_player(session, player);
 
 	return FALSE;
 }
@@ -3990,8 +3993,15 @@ static void avrcp_addressed_player_changed(struct avrcp *session,
 	struct avrcp_player *player = session->controller->player;
 	uint16_t id = get_be16(&pdu->params[1]);
 
-	if (player != NULL && player->id == id)
+	if (player != NULL && player->id == id) {
+		/* SetBrowsedPlayer is sent once the player is addressed */
+		if (!player->addressed) {
+			player->addressed = true;
+			set_browsed_player(session, player);
+		}
+
 		return;
+	}
 
 	player = find_ct_player(session, id);
 	if (player == NULL) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 6/8] player: Fix crash on Search in a folder with a space in its name
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
                   ` (4 preceding siblings ...)
  2026-11-22 10:57 ` [PATCH BlueZ 5/8] avrcp: Fix not browsing a player addressed before it was listed Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 7/8] player: Fix missing Name of listed Now Playing items Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 8/8] player: Fix NumberOfItems of Now Playing after its content changed Simon Mikuda
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

The search folder object path is made from the name of the folder
searched, e.g. /Filesystem/My Music/search. A name with characters an
object path cannot have, such as a space, fails to register, and
media_player_search_complete() dereferences the NULL item.

To reproduce, browse a target with a folder named "My Music", change to
it and call Search:

  media_player_create_subfolder() /Filesystem/My Music/search
  media_folder_create_item() D-Bus failed to register
      org.bluez.MediaItem1 on
      /org/bluez/hci0/dev_00_AA_01_01_00_42/avrcp/player0/Filesystem/My
      Music/search path
  Program terminated with signal SIGSEGV, Segmentation fault.
  #0  dbus_message_iter_append_basic () from libdbus-1.so.3
  #1  dbus_message_append_args_valist () from libdbus-1.so.3
  #2  g_dbus_create_reply_valist (...) at gdbus/object.c:1572
  #3  g_dbus_create_reply (...) at gdbus/object.c:1587
  #4  media_player_search_complete (mp=..., ret=2) at
      profiles/audio/player.c:741
  #5  avrcp_search_rsp (...) at profiles/audio/avrcp.c:4460
  #6  browsing_response (...) at profiles/audio/avctp.c:964

Replace those characters with '_' in the object path of a folder named
by its path, as the search folder and the folders of the browsed player
are, and fail the search if the folder still cannot be created.

Fixes: 0a232a434d4b ("audio/player: Add implementation of MediaFolder.Search")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/player.c | 27 ++++++++++++++++++++++++---
 1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 4c94dcab4..574a026ac 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -730,8 +730,17 @@ void media_player_search_complete(struct media_player *mp, int ret)
 	}
 
 	if (search == NULL) {
+		struct media_item *item;
+
+		item = media_player_create_subfolder(mp, "search", 0);
+		if (item == NULL) {
+			reply = btd_error_failed(mp->msg,
+					"Unable to create search folder");
+			goto done;
+		}
+
 		search = g_new0(struct media_folder, 1);
-		search->item = media_player_create_subfolder(mp, "search", 0);
+		search->item = item;
 		mp->search = search;
 		mp->folders = g_slist_prepend(mp->folders, search);
 	}
@@ -1890,11 +1899,23 @@ static struct media_item *media_folder_create_item(struct media_player *mp,
 	item->player = mp;
 	item->uid = uid;
 
-	if (!uid && name[0] == '/')
+	if (!uid && name[0] == '/') {
+		char *c;
+
 		item->path = g_strdup_printf("%s%s", mp->path, name);
-	else
+
+		/* Folder names may contain characters not valid in a path */
+		for (c = item->path + strlen(mp->path); *c; c++) {
+			if (*c == '/' && c[1] != '/' && c[1] != '\0')
+				continue;
+
+			if (!g_ascii_isalnum(*c) && *c != '_')
+				*c = '_';
+		}
+	} else {
 		item->path = g_strdup_printf("%s/item%" PRIu64 "",
 						folder->item->path, uid);
+	}
 
 	item->name = g_strdup(name);
 	item->type = type;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 7/8] player: Fix missing Name of listed Now Playing items
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
                   ` (5 preceding siblings ...)
  2026-11-22 10:57 ` [PATCH BlueZ 6/8] player: Fix crash on Search in a folder with a space in its name Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  2026-11-22 10:57 ` [PATCH BlueZ 8/8] player: Fix NumberOfItems of Now Playing after its content changed Simon Mikuda
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

A track change creates the Now Playing item of the new track by its UID
alone, without a name. When the folder is listed afterwards,
media_folder_create_item() finds that item by its UID and returns it as
it is, so the current track, and any track played before, are listed
without a Name.

To reproduce, browse a target with a Now Playing list, change the track
to one of its items, and list Now Playing:

  btmon: AVRCP: GetItemAttributes: len 0x000c
  btmon: Scope: 0x03 (Now Playing)
  btmon: UID: 0x0000000000000002 (2)
  bluetoothd: profiles/audio/player.c:media_player_set_playlist_item() 2
  media_folder_create_item() (null) type audio uid 2
  ...
  btmon: AVRCP: GetFolderItems: len 0x00e5
  btmon: Name: Blue Morning
  btmon: Name: Green Afternoon
  media_folder_create_item() Blue Morning type audio uid 1
  avrcp_list_items_rsp() start 0 end 1 items 2 total 2

Item 2, "Green Afternoon", the current track, is listed without a Name.

Set the name of an existing item when it is listed.

Fixes: b18723a18e8f ("audio/player: Create item on media_player_set_playlist_item")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/player.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index 574a026ac..d4dbe1b59 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -1876,6 +1876,18 @@ void media_item_set_playable(struct media_item *item, bool value)
 					MEDIA_ITEM_INTERFACE, "Playable");
 }
 
+static void media_item_set_name(struct media_item *item, const char *name)
+{
+	if (name == NULL || g_strcmp0(item->name, name) == 0)
+		return;
+
+	g_free(item->name);
+	item->name = g_strdup(name);
+
+	g_dbus_emit_property_changed(btd_get_dbus_connection(), item->path,
+					MEDIA_ITEM_INTERFACE, "Name");
+}
+
 static struct media_item *media_folder_create_item(struct media_player *mp,
 						struct media_folder *folder,
 						const char *name,
@@ -1886,8 +1898,14 @@ static struct media_item *media_folder_create_item(struct media_player *mp,
 	const char *strtype;
 
 	item = media_folder_find_item(folder, uid);
-	if (item != NULL)
+	if (item != NULL) {
+		/*
+		 * The item may have been created by
+		 * media_player_set_playlist_item(), which has no name for it.
+		 */
+		media_item_set_name(item, name);
 		return item;
+	}
 
 	strtype = type_to_string(type);
 	if (strtype == NULL)
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH BlueZ 8/8] player: Fix NumberOfItems of Now Playing after its content changed
  2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
                   ` (6 preceding siblings ...)
  2026-11-22 10:57 ` [PATCH BlueZ 7/8] player: Fix missing Name of listed Now Playing items Simon Mikuda
@ 2026-11-22 10:57 ` Simon Mikuda
  7 siblings, 0 replies; 10+ messages in thread
From: Simon Mikuda @ 2026-11-22 10:57 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Simon Mikuda

NOW_PLAYING_CONTENT_CHANGED clears the Now Playing items but keeps the
number of items, which is requested again only when the scope changes,
and ListItems does not list past it. So a controller that stays in Now
Playing lists a grown list cut at its old length.

To reproduce, list the 2 items of Now Playing, let the target add 3
items, and list Now Playing again:

  btmon: EventID: 0x09 (EVENT_NOW_PLAYING_CONTENT_CHANGED)
  avrcp_now_playing_changed() NowPlaying changed
  bluetoothd: profiles/audio/player.c:get_items() 2
  btmon: AVRCP: GetFolderItems: len 0x0022
  btmon: Scope: 0x03 (Now Playing)
  btmon: StartItem: 0x00000000 (0)
  btmon: EndItem: 0x00000001 (1)
  avrcp_list_items_rsp() start 0 end 1 items 2 total 2

Only the 2 items listed before are listed again.

Reset the number of items, so that ListItems leaves the end of the list
to the target until it is known again, and request it again when Now
Playing is the current folder.

Fixes: 671f370a8e34 ("audio/player: Clear playlist on Now Playing Changed AVRCP event")
Assisted-by: Claude:claude-opus-5-5
---
 profiles/audio/player.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/profiles/audio/player.c b/profiles/audio/player.c
index d4dbe1b59..a24c51952 100644
--- a/profiles/audio/player.c
+++ b/profiles/audio/player.c
@@ -2067,9 +2067,28 @@ struct media_item *media_player_set_playlist_item(struct media_player *mp,
 
 void media_player_clear_playlist(struct media_player *mp)
 {
+	struct player_callback *cb = mp->cb;
+
 	if (mp->playlist) {
 		g_slist_free_full(mp->playlist->items, media_item_destroy);
 		mp->playlist->items = NULL;
+
+		/*
+		 * The number of items may have changed: leave the end of the
+		 * list to the target until it is known again.
+		 */
+		mp->playlist->number_of_items = 0;
+	}
+
+	if (mp->playlist && mp->scope == mp->playlist) {
+		g_dbus_emit_property_changed(btd_get_dbus_connection(),
+						mp->path,
+						MEDIA_FOLDER_INTERFACE,
+						"NumberOfItems");
+
+		if (cb->cbs->total_items)
+			cb->cbs->total_items(mp, mp->scope->item->name,
+							cb->user_data);
 	}
 
 	g_dbus_emit_property_changed(btd_get_dbus_connection(), mp->path,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* RE: AVRCP browsing fixes, and browsing and cover art in the target role
  2026-11-22 10:57 ` [PATCH BlueZ 1/8] avrcp: Fix not checking browsing PDU parameter length Simon Mikuda
@ 2026-11-22 18:57   ` bluez.test.bot
  0 siblings, 0 replies; 10+ messages in thread
From: bluez.test.bot @ 2026-11-22 18:57 UTC (permalink / raw)
  To: linux-bluetooth, simon.mikuda

[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/series/1218578/

---Test result---

Test Summary:
CheckPatch                    PASS      2.72 seconds
GitLint                       PASS      1.84 seconds
BuildEll                      PASS      20.84 seconds
BluezMake                     PASS      322.32 seconds
MakeCheck                     PASS      3.41 seconds
MakeDistcheck                 PASS      156.39 seconds
CheckValgrind                 PASS      167.46 seconds
CheckSmatch                   PASS      320.06 seconds
bluezmakeextell               PASS      103.13 seconds
TestFunctional                FAIL      1305.24 seconds
IncrementalBuild              PASS      345.38 seconds
ScanBuild                     PASS      1261.30 seconds

Details
##############################
Test: TestFunctional - FAIL
Desc: Run test-functional
Output:
FAIL functional.test_bap::test_bass_past_earbuds_transport_acquire[hosts11-vm3]: AssertionError: Failed to acquire: org.bluez.Error.Failed


https://github.com/bluez/bluez/pull/2871

---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-11-22 18:57 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-22 10:57 [PATCH BlueZ 0/8] AVRCP browsing fixes, and browsing and cover art in the target role Simon Mikuda
2026-11-22 10:57 ` [PATCH BlueZ 1/8] avrcp: Fix not checking browsing PDU parameter length Simon Mikuda
2026-11-22 18:57   ` AVRCP browsing fixes, and browsing and cover art in the target role bluez.test.bot
2026-11-22 10:57 ` [PATCH BlueZ 2/8] avrcp: Fix listing media players up to item 0xffffffff Simon Mikuda
2026-11-22 10:57 ` [PATCH BlueZ 3/8] avrcp: Fix byte order of ADDRESSED_PLAYER_CHANGED notification Simon Mikuda
2026-11-22 10:57 ` [PATCH BlueZ 4/8] avrcp: Fix byte order of TRACK_CHANGED identifier Simon Mikuda
2026-11-22 10:57 ` [PATCH BlueZ 5/8] avrcp: Fix not browsing a player addressed before it was listed Simon Mikuda
2026-11-22 10:57 ` [PATCH BlueZ 6/8] player: Fix crash on Search in a folder with a space in its name Simon Mikuda
2026-11-22 10:57 ` [PATCH BlueZ 7/8] player: Fix missing Name of listed Now Playing items Simon Mikuda
2026-11-22 10:57 ` [PATCH BlueZ 8/8] player: Fix NumberOfItems of Now Playing after its content changed Simon Mikuda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox