From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v2 13/13] client/assistant: Detect if object already contains a valid BCode
Date: Thu, 9 Oct 2025 17:29:31 -0400 [thread overview]
Message-ID: <20251009212931.445719-13-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20251009212931.445719-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
If assistant object already contains a valid (non-zero) BCode
(e.g state=local) use it instead of always request the user to
re-enter.
---
client/assistant.c | 55 ++++++++++++++++++++++++++++++++++------------
1 file changed, 41 insertions(+), 14 deletions(-)
diff --git a/client/assistant.c b/client/assistant.c
index 1ff8001d7216..ed0c8cdd6c7a 100644
--- a/client/assistant.c
+++ b/client/assistant.c
@@ -293,7 +293,7 @@ fail:
static bool assistant_get_qos(struct assistant_config *cfg)
{
- DBusMessageIter iter, dict, entry, value;
+ DBusMessageIter iter, dict;
const char *key;
/* Get QoS property to check if the stream is encrypted */
@@ -305,22 +305,45 @@ static bool assistant_get_qos(struct assistant_config *cfg)
dbus_message_iter_recurse(&iter, &dict);
- if (dbus_message_iter_get_arg_type(&dict) != DBUS_TYPE_DICT_ENTRY)
- return false;
+ while (dbus_message_iter_get_arg_type(&dict) != DBUS_TYPE_DICT_ENTRY) {
+ DBusMessageIter entry, value;
+ int var;
- dbus_message_iter_recurse(&dict, &entry);
- dbus_message_iter_get_basic(&entry, &key);
+ dbus_message_iter_recurse(&dict, &entry);
+ dbus_message_iter_get_basic(&entry, &key);
- if (strcasecmp(key, "Encryption") != 0)
- return false;
+ dbus_message_iter_next(&entry);
+ dbus_message_iter_recurse(&entry, &value);
- dbus_message_iter_next(&entry);
- dbus_message_iter_recurse(&entry, &value);
+ var = dbus_message_iter_get_arg_type(&value);
- if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_BYTE)
- return false;
+ if (!strcasecmp(key, "Encryption")) {
+ if (var != DBUS_TYPE_BYTE)
+ return false;
- dbus_message_iter_get_basic(&value, &cfg->qos.bcast.encryption);
+ dbus_message_iter_get_basic(&value,
+ &cfg->qos.bcast.encryption);
+ } else if (!strcasecmp(key, "BCode")) {
+ DBusMessageIter array;
+ struct iovec iov = {0};
+
+ if (var != DBUS_TYPE_ARRAY)
+ return false;
+
+ dbus_message_iter_recurse(&value, &array);
+ dbus_message_iter_get_fixed_array(&array,
+ &iov.iov_base,
+ (int *)&iov.iov_len);
+
+ if (iov.iov_len != 16) {
+ bt_shell_printf("Invalid size for BCode: "
+ "%zu != 16\n", iov.iov_len);
+ return false;
+ }
+
+ memcpy(cfg->qos.bcast.bcode, iov.iov_base, iov.iov_len);
+ }
+ }
return true;
}
@@ -328,6 +351,7 @@ static bool assistant_get_qos(struct assistant_config *cfg)
static void assistant_set_metadata_cfg(const char *input, void *user_data)
{
struct assistant_config *cfg = user_data;
+ uint8_t no_bcode[16] = {};
if (!strcasecmp(input, "a") || !strcasecmp(input, "auto"))
goto done;
@@ -346,7 +370,8 @@ done:
if (!assistant_get_qos(cfg))
goto fail;
- if (cfg->qos.bcast.encryption)
+ if (cfg->qos.bcast.encryption &&
+ !memcmp(cfg->qos.bcast.bcode, no_bcode, 16))
/* Prompt user to enter the Broadcast Code to decrypt
* the stream
*/
@@ -373,13 +398,15 @@ fail:
static void assistant_set_device_cfg(const char *input, void *user_data)
{
struct assistant_config *cfg = user_data;
+ uint8_t no_bcode[16] = {};
cfg->device = strdup(input);
if (!assistant_get_qos(cfg))
goto fail;
- if (cfg->qos.bcast.encryption) {
+ if (cfg->qos.bcast.encryption &&
+ !memcmp(cfg->qos.bcast.bcode, no_bcode, 16)) {
/* Prompt user to enter the Broadcast Code to decrypt
* the stream
*/
--
2.51.0
next prev parent reply other threads:[~2025-10-09 21:30 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-09 21:29 [PATCH BlueZ v2 01/13] monitor: Use PAST to refer to Periodic Advertising Sync Transfer Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 02/13] emulator: Add initial support for PAST Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 03/13] iso-tester: Add tests for PAST procedures Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 04/13] monitor: Add support for PAST MGMT settings and flags Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 05/13] MGMT: Add PAST Settings and Flags Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 06/13] device: Add initial support for setting DEVICE_FLAG_PAST Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 07/13] bass: Add " Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 08/13] iso.rst: Add documentation for PAST/rebind Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 09/13] shared/bap: Add callback broadcast instances Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 10/13] MediaAssistant: Add Device option to Push Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 11/13] bass: Implement Device option for Push Luiz Augusto von Dentz
2025-10-09 21:29 ` [PATCH BlueZ v2 12/13] client/assistant: Handle assistant.push to own broadcasts Luiz Augusto von Dentz
2025-10-09 21:29 ` Luiz Augusto von Dentz [this message]
2025-10-09 22:51 ` [BlueZ,v2,01/13] monitor: Use PAST to refer to Periodic Advertising Sync Transfer bluez.test.bot
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=20251009212931.445719-13-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