From 1466d0ae782537c17672c05f0a7a9694e3ddac17 Mon Sep 17 00:00:00 2001 From: Vlad Pruteanu Date: Mon, 10 Jun 2024 15:41:57 +0300 Subject: [PATCH] bluez5: bap: Use a string instead of int array to set Broadcast code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, the user sets the Broadcast Code via an array of integers in the config file. However, the Bluetooth Core Specification indicates that it should be set via a 16 byte string. This commit replaces the old implementation with the one required by the spec. Tested the commit with the example provided in the Core Spec: Broadcast Code: Børne House Result from btsnoop log: < HCI Command: LE Create Broadcast Isochronous Group (0x08|0x0068) plen 31 ... Broadcast Code[16]: 000000006573756f4820656e72b8c342 The result matches the example given in the spec. --- doc/dox/config/pipewire-devices.7.md | 2 +- spa/plugins/bluez5/bluez5-dbus.c | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/doc/dox/config/pipewire-devices.7.md b/doc/dox/config/pipewire-devices.7.md index 9d3b5464d..29658472d 100644 --- a/doc/dox/config/pipewire-devices.7.md +++ b/doc/dox/config/pipewire-devices.7.md @@ -429,7 +429,7 @@ Example: ``` bluez5.bcast_source.config = [ { - "broadcast_code": [ 1, 2, 104, 5, 83, 241, 65, 90, 162, 101, 187, 175, 198, 234, 3, 184 ], + "broadcast_code": "Børne House", "encryption: false, "bis": [ { # BIS configuration diff --git a/spa/plugins/bluez5/bluez5-dbus.c b/spa/plugins/bluez5/bluez5-dbus.c index 6770de3bb..1ef1ad2e2 100644 --- a/spa/plugins/bluez5/bluez5-dbus.c +++ b/spa/plugins/bluez5/bluez5-dbus.c @@ -175,7 +175,7 @@ struct spa_bt_bis { struct spa_bt_big { struct spa_list link; - int broadcast_code[BROADCAST_CODE_LEN]; + char broadcast_code[BROADCAST_CODE_LEN]; bool encryption; int presentation_delay; struct spa_list bis_list; @@ -6171,13 +6171,23 @@ static void parse_broadcast_source_config(struct spa_bt_monitor *monitor, const /* Iterate on all BIG values */ while (spa_json_get_string(&it[1], key, sizeof(key)) > 0) { if (spa_streq(key, "broadcast_code")) { - if (spa_json_enter_array(&it[1], &it_array[1]) <= 0) - goto parse_failed; - for (cursor = 0; cursor < BROADCAST_CODE_LEN; cursor++) { - if (spa_json_get_int(&it_array[1], &big_entry->broadcast_code[cursor]) <= 0) + /* Len is BROADCAST_CODE_LEN plus 2 (for the quotes, as they count towards the string length + * even if they don't appear in the final big_entry->broadcast_code string) plus 1 for the + * null string terminator. + */ + if (spa_json_get_string(&it[1], big_entry->broadcast_code,BROADCAST_CODE_LEN + 2 + 1) <= 0) goto parse_failed; - spa_log_debug(monitor->log, "big_entry->broadcast_code[%d] %d", cursor, big_entry->broadcast_code[cursor]); - } + /* BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 3, Part C + * 3.2.6.3 Representation + * + * The transformation from string to number shall be by + * representing the string in UTF-8, placing the resulting bytes in 8-bit fields of the + * value starting at the least significant bit, and then padding with zeros in the + * most significant bits if necessary. + */ + for (int i = 0; i <= BROADCAST_CODE_LEN/2 - 1; i++) + SPA_SWAP(big_entry->broadcast_code[i], big_entry->broadcast_code[BROADCAST_CODE_LEN - 1 -i]); + spa_log_debug(monitor->log, "big_entry->broadcast_code %s", big_entry->broadcast_code); } else if (spa_streq(key, "encryption")) { if (spa_json_get_bool(&it[1], &big_entry->encryption) <= 0) goto parse_failed;