Skip to contentSkip to conversation

Add support for setting bcode on bcast sink

PATCH Superseded Vlad Pruteanu 3 participants 11 messages Aug 20, 2024 Bluetooth drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for setting bcode on bcast sink

This series allows the user to set the broadcast code before syncing to a broadcast source. Upon calling transport.select if the source is encrypted the user will be prompted to enter the broadcast code. Then, the code is set in the associated stream's QoS. From here it can be accessed by iso_do_big_sync, which will pass it to the kernel.

Vlad Pruteanu (8):
doc/media: Add Encryption and BCode fields to QoS property
transport: Make get_bcast_qos return the encryption flag
gdbus: Add g_dbus_proxy_set_property_dict
doc/media: Make QoS property readwrite
transport: Add set_bcast_qos method
shared/bap: Enable set qos method for BT_BAP_BCAST_SINK stream client/player: Prompt the user to enter the bcode
bap: Refresh qos stored in setup before doing BIG sync

 client/player.c                  | 57 +++++++++++++++++++++
 doc/org.bluez.MediaTransport.rst | 12 ++++-
 gdbus/client.c                   | 86 ++++++++++++++++++++++++++++++++
 gdbus/gdbus.h                    |  6 +++
 profiles/audio/bap.c             |  2 +
 profiles/audio/transport.c       | 35 ++++++++++++-
 src/shared/bap.c                 |  2 +-
 7 files changed, 195 insertions(+), 5 deletions(-)
Signature · 1 line
2.40.1
#1 lore raw

PATCH 1/8 doc/media: Add Encryption and BCode fields to QoS property

This adds the missing QoS fields, Encryption and BCode.

---
 doc/org.bluez.MediaTransport.rst | 8 ++++++++
 1 file changed, 8 insertions(+)
doc/org.bluez.MediaTransport.rst +8 -0
index eb3e04ae2..b53c0cd26 100644
@@ -242,6 +242,14 @@ dict QoS [readonly, optional, ISO only, experimental]
 
 		Indicates configured framing.
 
+	:array{byte} BCode:
+
+		Indicates the string used for encryption/decryption.
+
+	:byte encryption:
+
+		Indicates if the stream is encrypted.
+
 	:byte Options:
 
 		Indicates configured broadcast options.
Signature · 1 line
2.40.1
#3 lore raw

PATCH 2/8 transport: Make get_bcast_qos return the encryption flag

In reply to Vlad Pruteanu

This adds the encryption flag to the response returned by the get_bcast_qos method.

---
 profiles/audio/transport.c | 2 ++
 1 file changed, 2 insertions(+)
profiles/audio/transport.c +2 -0
index 300145794..e8915490d 100644
@@ -1174,6 +1174,8 @@ static gboolean get_bcast_qos(const GDBusPropertyTable *property,
 					&bap->qos.bcast.packing);
 	dict_append_entry(&dict, "Framing", DBUS_TYPE_BYTE,
 					&bap->qos.bcast.framing);
+	dict_append_entry(&dict, "Encryption", DBUS_TYPE_BYTE,
+					&bap->qos.bcast.encryption);
 	if (bap->qos.bcast.bcode)
 		dict_append_array(&dict, "BCode", DBUS_TYPE_BYTE,
 					&bap->qos.bcast.bcode->iov_base,
Signature · 1 line
2.40.1
#4 lore raw

PATCH 3/8 gdbus: Add g_dbus_proxy_set_property_dict

In reply to Vlad Pruteanu

This adds a new gdbus function to allow for the setting of a dictionary type property - a{sv}. It received the name of the property, the name of the entry to be set from the dictionary, it's type and value. These values are passed as a dict entry, to the set method associated with the property. There, it must be parsed and the appropriate entry updated.

---
 gdbus/client.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gdbus/gdbus.h  |  6 ++++
 2 files changed, 92 insertions(+)
gdbus/client.c +86 -0
index 3b7faa4e4..980f8fc0f 100644
@@ -4,6 +4,7 @@
  *  D-Bus helper library
  *
  *  Copyright (C) 2004-2011  Marcel Holtmann <[email protected]>
+ *  Copyright 2024 NXP
  *
  *
  */
@@ -184,6 +185,33 @@ void g_dbus_dict_append_entry(DBusMessageIter *dict,
 	dict_append_basic(dict, DBUS_TYPE_STRING, &key, type, val);
 }
 
+static void append_dict_variant(DBusMessageIter *iter, char *entry, int type,
+							void *val)
+{
+	DBusMessageIter variant, dict;
+
+	dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT,
+					DBUS_TYPE_ARRAY_AS_STRING
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&variant);
+
+	dbus_message_iter_open_container(&variant, DBUS_TYPE_ARRAY,
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&dict);
+
+	g_dbus_dict_append_entry(&dict, entry, type, val);
+
+	dbus_message_iter_close_container(&variant, &dict);
+
+	dbus_message_iter_close_container(iter, &variant);
+}
+
 void g_dbus_dict_append_basic_array(DBusMessageIter *dict, int key_type,
 					const void *key, int type, void *val,
 					int n_elements)
@@ -885,6 +913,64 @@ gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
 	return TRUE;
 }
 
+gboolean g_dbus_proxy_set_property_dict(GDBusProxy *proxy,
+				const char *name, char *entry, int type,
+				const void *value, GDBusResultFunction function,
+				void *user_data, GDBusDestroyFunction destroy)
+{
+	struct set_property_data *data;
+	GDBusClient *client;
+	DBusMessage *msg;
+	DBusMessageIter iter;
+	DBusPendingCall *call;
+
+	if (proxy == NULL || name == NULL || value == NULL)
+		return FALSE;
+
+	if (dbus_type_is_basic(type) == FALSE)
+		return FALSE;
+
+	client = proxy->client;
+	if (client == NULL)
+		return FALSE;
+
+	data = g_try_new0(struct set_property_data, 1);
+	if (data == NULL)
+		return FALSE;
+
+	data->function = function;
+	data->user_data = user_data;
+	data->destroy = destroy;
+
+	msg = dbus_message_new_method_call(client->service_name,
+			proxy->obj_path, DBUS_INTERFACE_PROPERTIES, "Set");
+	if (msg == NULL) {
+		g_free(data);
+		return FALSE;
+	}
+
+	dbus_message_iter_init_append(msg, &iter);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING,
+							&proxy->interface);
+	dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &name);
+
+	append_dict_variant(&iter, entry, type, &value);
+
+	if (g_dbus_send_message_with_reply(client->dbus_conn, msg,
+							&call, -1) == FALSE) {
+		dbus_message_unref(msg);
+		g_free(data);
+		return FALSE;
+	}
+
+	dbus_pending_call_set_notify(call, set_property_reply, data, g_free);
+	dbus_pending_call_unref(call);
+
+	dbus_message_unref(msg);
+
+	return TRUE;
+}
+
 gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
 				const char *name, int type, const void *value,
 				size_t size, GDBusResultFunction function,
gdbus/gdbus.h +6 -0
index 6fe09b743..4aaf73b62 100644
@@ -4,6 +4,7 @@
  *  D-Bus helper library
  *
  *  Copyright (C) 2004-2011  Marcel Holtmann <[email protected]>
+ *  Copyright 2024 NXP
  *
  *
  */
@@ -362,6 +363,11 @@ gboolean g_dbus_proxy_set_property_basic(GDBusProxy *proxy,
 				GDBusResultFunction function, void *user_data,
 				GDBusDestroyFunction destroy);
 
+gboolean g_dbus_proxy_set_property_dict(GDBusProxy *proxy,
+				const char *name, char *entry, int type,
+				const void *value, GDBusResultFunction function,
+				void *user_data, GDBusDestroyFunction destroy);
+
 gboolean g_dbus_proxy_set_property_array(GDBusProxy *proxy,
 				const char *name, int type, const void *value,
 				size_t size, GDBusResultFunction function,
Signature · 1 line
2.40.1
#5 lore raw

PATCH 4/8 doc/media: Make QoS property readwrite

In reply to Vlad Pruteanu

Update the QoS property to allow for write, so that fields such as BCode can be updated.

---
 doc/org.bluez.MediaTransport.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
doc/org.bluez.MediaTransport.rst +2 -2
index b53c0cd26..4d998b2a8 100644
@@ -149,8 +149,8 @@ array{object} Links [readonly, optional, ISO only, experimental]
 
 	Linked transport objects which the transport is associated with.
 
-dict QoS [readonly, optional, ISO only, experimental]
-`````````````````````````````````````````````````````
+dict QoS [readwrite, optional, ISO only, experimental]
+``````````````````````````````````````````````````````
 
 	Only present when QoS is configured.
 
Signature · 1 line
2.40.1
#6 lore raw

PATCH 5/8 transport: Add set_bcast_qos method

In reply to Vlad Pruteanu

This adds a set method for the QoS property of bcast transports. This is needed so that applications like bluetoothctl are able to modify the QoS (for example, for setting the broadcast code).

---
 profiles/audio/transport.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
profiles/audio/transport.c +31 -2
index e8915490d..854b30601 100644
@@ -5,7 +5,7 @@
  *
  *  Copyright (C) 2006-2007  Nokia Corporation
  *  Copyright (C) 2004-2009  Marcel Holtmann <[email protected]>
- *  Copyright 2023 NXP
+ *  Copyright 2023-2024 NXP
  *
  *
  */
@@ -1208,13 +1208,42 @@ static gboolean qos_bcast_exists(const GDBusPropertyTable *property, void *data)
 	return bap->qos.bcast.io_qos.phy != 0x00;
 }
 
+static void set_bcast_qos(const GDBusPropertyTable *property,
+			DBusMessageIter *dict, GDBusPendingPropertySet id,
+			void *data)
+{
+	DBusMessageIter array, entry, value;
+	struct media_transport *transport = data;
+	struct bap_transport *bap = transport->data;
+	struct bt_bap_qos *bap_qos = bt_bap_stream_get_qos(bap->stream);
+	char *key, *str;
+
+	dbus_message_iter_recurse(dict, &array);
+
+	dbus_message_iter_recurse(&array, &entry);
+	dbus_message_iter_get_basic(&entry, &key);
+
+	dbus_message_iter_next(&entry);
+	dbus_message_iter_recurse(&entry, &value);
+
+	if (!strcasecmp(key, "BCode")) {
+		dbus_message_iter_get_basic(&value, &str);
+		bap_qos->bcast.bcode = new0(struct iovec, 1);
+		util_iov_append(bap_qos->bcast.bcode, str, strlen(str));
+	}
+
+	bt_bap_stream_qos(bap->stream, bap_qos, NULL, NULL);
+
+	g_dbus_pending_property_success(id);
+}
+
 static const GDBusPropertyTable transport_bap_bc_properties[] = {
 	{ "Device", "o", get_device },
 	{ "UUID", "s", get_uuid },
 	{ "Codec", "y", get_codec },
 	{ "Configuration", "ay", get_configuration },
 	{ "State", "s", get_state },
-	{ "QoS", "a{sv}", get_bcast_qos, NULL, qos_bcast_exists },
+	{ "QoS", "a{sv}", get_bcast_qos, set_bcast_qos, qos_bcast_exists },
 	{ "Endpoint", "o", get_endpoint, NULL, endpoint_exists },
 	{ "Location", "u", get_location },
 	{ "Metadata", "ay", get_metadata },
Signature · 1 line
2.40.1
#8 lore raw

PATCH 6/8 shared/bap: Enable set qos method for BT_BAP_BCAST_SINK stream

In reply to Vlad Pruteanu

This enables the set qos method, bap_bcast_qos, for the bcast sink streams as well.

---
 src/shared/bap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/shared/bap.c +1 -1
index a7217b417..97b96e49f 100644
@@ -2243,7 +2243,7 @@ static const struct bt_bap_stream_ops stream_ops[] = {
 			bap_ucast_release, bap_ucast_detach),
 	STREAM_OPS(BT_BAP_BCAST_SINK, bap_bcast_set_state,
 			bap_bcast_get_state,
-			bap_bcast_config, NULL, bap_bcast_sink_enable,
+			bap_bcast_config, bap_bcast_qos, bap_bcast_sink_enable,
 			bap_bcast_start, bap_bcast_disable, NULL,
 			bap_bcast_metadata, bap_bcast_sink_get_dir,
 			bap_bcast_get_location,
Signature · 1 line
2.40.1
#9 lore raw

PATCH 7/8 client/player: Prompt the user to enter the bcode

In reply to Vlad Pruteanu

This adds support for entering the broadcast code on sink side. When the user selects a transport, if the transport is encrypted, the user will be prompted to enter the broadcast code before the process of transport selection can continue.

---
 client/player.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
client/player.c +57 -0
index f1cd90966..6c79cb27c 100644
@@ -5022,8 +5022,65 @@ static void cmd_acquire_transport(int argc, char *argv[])
 	return bt_shell_noninteractive_quit(EXIT_SUCCESS);
 }
 
+static void set_bcode_cb(const DBusError *error, void *user_data)
+{
+	GDBusProxy *proxy = user_data;
+
+	if (dbus_error_is_set(error)) {
+		bt_shell_printf("Failed to set broadcast code: %s\n",
+								error->name);
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+
+	bt_shell_printf("Setting broadcast code succeeded\n");
+
+	if (!g_dbus_proxy_method_call(proxy, "Select", NULL,
+				select_reply, proxy, NULL))
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+}
+
+static void set_bcode(const char *input, void *user_data)
+{
+	GDBusProxy *proxy = user_data;
+	char *bcode = g_strdup(input);
+
+	if (g_dbus_proxy_set_property_dict(proxy, "QoS", "BCode",
+				DBUS_TYPE_STRING, bcode,
+				set_bcode_cb, user_data, NULL) == FALSE){
+		return bt_shell_noninteractive_quit(EXIT_FAILURE);
+	}
+}
+
 static void transport_select(GDBusProxy *proxy, bool prompt)
 {
+	DBusMessageIter iter, array, entry, value;
+	unsigned char encryption;
+	const char *key;
+
+	if (g_dbus_proxy_get_property(proxy, "QoS", &iter) == FALSE)
+		return;
+
+	dbus_message_iter_recurse(&iter, &array);
+
+	while (dbus_message_iter_get_arg_type(&array) !=
+						DBUS_TYPE_INVALID) {
+		dbus_message_iter_recurse(&array, &entry);
+		dbus_message_iter_get_basic(&entry, &key);
+
+		if (!strcasecmp(key, "Encryption")) {
+			dbus_message_iter_next(&entry);
+			dbus_message_iter_recurse(&entry, &value);
+			dbus_message_iter_get_basic(&value, &encryption);
+			if (encryption == 1) {
+				bt_shell_prompt_input("",
+				"Enter broadcast code:", set_bcode, proxy);
+				return;
+			}
+			break;
+		}
+		dbus_message_iter_next(&array);
+	}
+
 	if (!g_dbus_proxy_method_call(proxy, "Select", NULL,
 					select_reply, proxy, NULL)) {
 		bt_shell_printf("Failed select transport\n");
Signature · 1 line
2.40.1
#10 lore raw

PATCH 8/8 bap: Refresh qos stored in setup before doing BIG sync

In reply to Vlad Pruteanu

When syncing to an encrypted stream, after setting the broadcast code, the qos values stored in the setup must be refreshed so that they reflect this change.

---
 profiles/audio/bap.c | 2 ++
 1 file changed, 2 insertions(+)
profiles/audio/bap.c +2 -0
index a2c5a546d..80ed1a7ea 100644
@@ -3066,6 +3066,8 @@ static void iso_do_big_sync(GIOChannel *io, void *user_data)
 	iso_bc_addr.bc_bis[0] = bis_index;
 	iso_bc_addr.bc_num_bis = 1;
 
+	/* Refresh qos stored in setup */
+	setup->qos = *bt_bap_stream_get_qos(setup->stream);
 	/* Set the user requested QOS */
 	memset(&qos, 0, sizeof(qos));
 	qos.bcast.big = setup->qos.bcast.big;
Signature · 1 line
2.40.1
#7 lore raw

Re: [PATCH BlueZ 5/8] transport: Add set_bcast_qos method

In reply to Vlad Pruteanu

Hi Vlad,

Quoted 35 lines · Vlad Pruteanu

This adds a set method for the QoS property of bcast transports. This is needed so that applications like bluetoothctl are able to modify the QoS (for example, for setting the broadcast code).

---
 profiles/audio/transport.c | 33 +++++++++++++++++++++++++++++++--
 1 file changed, 31 insertions(+), 2 deletions(-)
profiles/audio/transport.c +11 -1
index e8915490d..854b30601 100644
@@ -5,7 +5,7 @@
  *
  *  Copyright (C) 2006-2007  Nokia Corporation
  *  Copyright (C) 2004-2009  Marcel Holtmann <[email protected]>
- *  Copyright 2023 NXP
+ *  Copyright 2023-2024 NXP
  *
  *
  */
@@ -1208,13 +1208,42 @@ static gboolean qos_bcast_exists(const GDBusPropertyTable *property, void *data)
        return bap->qos.bcast.io_qos.phy != 0x00;
 }
 
+static void set_bcast_qos(const GDBusPropertyTable *property,
+                       DBusMessageIter *dict, GDBusPendingPropertySet id,
+                       void *data)
+{
+       DBusMessageIter array, entry, value;
+       struct media_transport *transport = data;
+       struct bap_transport *bap = transport->data;
+       struct bt_bap_qos *bap_qos = bt_bap_stream_get_qos(bap->stream);
+       char *key, *str;
+

profiles/audio/transport.c static gboolean qos_bcast_exists(const GDBusPropertyTable *property, void *data) · line 1230

Quoted 10 lines
profiles/audio/transport.c +10 -0
+       dbus_message_iter_recurse(dict, &array);
+
+       dbus_message_iter_recurse(&array, &entry);
+       dbus_message_iter_get_basic(&entry, &key);
+
+       dbus_message_iter_next(&entry);
+       dbus_message_iter_recurse(&entry, &value);
+
+       if (!strcasecmp(key, "BCode")) {
+               dbus_message_iter_get_basic(&value, &str);

Hmm, isn't BCode a byte array? How come we are parsing as a string here?

Quoted 23 lines
profiles/audio/transport.c +10 -2
+               bap_qos->bcast.bcode = new0(struct iovec, 1);
+               util_iov_append(bap_qos->bcast.bcode, str, strlen(str));
+       }
+
+       bt_bap_stream_qos(bap->stream, bap_qos, NULL, NULL);
+
+       g_dbus_pending_property_success(id);
+}
+
 static const GDBusPropertyTable transport_bap_bc_properties[] = {
        { "Device", "o", get_device },
        { "UUID", "s", get_uuid },
        { "Codec", "y", get_codec },
        { "Configuration", "ay", get_configuration },
        { "State", "s", get_state },
-       { "QoS", "a{sv}", get_bcast_qos, NULL, qos_bcast_exists },
+       { "QoS", "a{sv}", get_bcast_qos, set_bcast_qos, qos_bcast_exists },
        { "Endpoint", "o", get_endpoint, NULL, endpoint_exists },
        { "Location", "u", get_location },
        { "Metadata", "ay", get_metadata },
--

2.40.1

Signature · 1 line
Luiz Augusto von Dentz
#2 lore raw
In reply to Vlad Pruteanu

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/project/bluetooth/list/?series=881300

---Test result---

Test Summary:

CheckPatch                    PASS      3.79 seconds
GitLint                       PASS      2.60 seconds
BuildEll                      PASS      24.77 seconds
BluezMake                     PASS      1755.43 seconds
MakeCheck                     FAIL      13.18 seconds
MakeDistcheck                 FAIL      161.22 seconds
CheckValgrind                 FAIL      253.71 seconds
CheckSmatch                   WARNING   358.86 seconds
bluezmakeextell               PASS      120.62 seconds
IncrementalBuild              PASS      13060.40 seconds
ScanBuild                     PASS      1016.95 seconds

Details
##############################
Test: MakeCheck - FAIL
Desc: Run Bluez Make Check
Output:

make[3]: *** [Makefile:11764: test-suite.log] Error 1 make[2]: *** [Makefile:11872: check-TESTS] Error 2 make[1]: *** [Makefile:12301: check-am] Error 2
make: *** [Makefile:12303: check] Error 2
##############################
Test: MakeDistcheck - FAIL
Desc: Run Bluez Make Distcheck
Output:

Package cups was not found in the pkg-config search path. Perhaps you should add the directory containing `cups.pc' to the PKG_CONFIG_PATH environment variable
No package 'cups' found
make[4]: *** [Makefile:11764: test-suite.log] Error 1 make[3]: *** [Makefile:11872: check-TESTS] Error 2 make[2]: *** [Makefile:12301: check-am] Error 2 make[1]: *** [Makefile:12303: check] Error 2
make: *** [Makefile:12224: distcheck] Error 1
##############################
Test: CheckValgrind - FAIL
Desc: Run Bluez Make Check with Valgrind
Output:

tools/mgmt-tester.c: In function ‘main’:
tools/mgmt-tester.c:12725:5: note: variable tracking size limit exceeded with ‘-fvar-tracking-assignments’, retrying without 12725 | int main(int argc, char *argv[])

      |     ^~~~

make[3]: *** [Makefile:11764: test-suite.log] Error 1
make[2]: *** [Makefile:11872: check-TESTS] Error 2
make[1]: *** [Makefile:12301: check-am] Error 2
make: *** [Makefile:12303: check] Error 2
##############################
Test: CheckSmatch - WARNING
Desc: Run smatch tool with source
Output:
src/shared/bap.c:288:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:288:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structuressrc/shared/bap.c:288:25: warning: array of flexible structuressrc/shared/bap.c: note: in included file:./src/shared/ascs.h:88:25: warning: array of flexible structures

---
Regards,
Linux Bluetooth