From 667db9a82a3f8cdc33f50b0301bd2b146ef5cf7f Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 15 Sep 2025 12:50:29 -0400 Subject: [PATCH] client/assistant: Handle assistant.push to own broadcasts --- client/assistant.c | 102 ++++++++++++++++++++++++++++++++++++--------- client/mgmt.c | 5 ++- 2 files changed, 86 insertions(+), 21 deletions(-) diff --git a/client/assistant.c b/client/assistant.c index 3551aaad8..1ff8001d7 100644 --- a/client/assistant.c +++ b/client/assistant.c @@ -47,6 +47,8 @@ struct assistant_config { GDBusProxy *proxy; /* DBus object reference */ + char *state; /* Assistant state */ + char *device; /* Device address */ struct iovec *meta; /* Stream metadata LTVs */ struct bt_iso_qos qos; /* Stream QoS parameters */ }; @@ -223,6 +225,10 @@ static void push_setup(DBusMessageIter *iter, void *user_data) DBUS_TYPE_BYTE, &cfg->meta->iov_base, cfg->meta->iov_len); + if (cfg->device) + g_dbus_dict_append_entry(&dict, "Device", DBUS_TYPE_OBJECT_PATH, + &cfg->device); + if (cfg->qos.bcast.encryption) append_qos(&dict, cfg); @@ -285,12 +291,44 @@ fail: return bt_shell_noninteractive_quit(EXIT_FAILURE); } -static void assistant_set_metadata_cfg(const char *input, void *user_data) +static bool assistant_get_qos(struct assistant_config *cfg) { - struct assistant_config *cfg = user_data; DBusMessageIter iter, dict, entry, value; const char *key; + /* Get QoS property to check if the stream is encrypted */ + if (!g_dbus_proxy_get_property(cfg->proxy, "QoS", &iter)) + return false; + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) + return false; + + dbus_message_iter_recurse(&iter, &dict); + + if (dbus_message_iter_get_arg_type(&dict) != DBUS_TYPE_DICT_ENTRY) + return false; + + 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); + + if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_BYTE) + return false; + + dbus_message_iter_get_basic(&value, &cfg->qos.bcast.encryption); + + return true; +} + +static void assistant_set_metadata_cfg(const char *input, void *user_data) +{ + struct assistant_config *cfg = user_data; + if (!strcasecmp(input, "a") || !strcasecmp(input, "auto")) goto done; @@ -305,50 +343,62 @@ static void assistant_set_metadata_cfg(const char *input, void *user_data) } done: - /* Get QoS property to check if the stream is encrypted */ - if (!g_dbus_proxy_get_property(cfg->proxy, "QoS", &iter)) + if (!assistant_get_qos(cfg)) goto fail; - if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) - goto fail; + if (cfg->qos.bcast.encryption) + /* Prompt user to enter the Broadcast Code to decrypt + * the stream + */ + bt_shell_prompt_input("Assistant", + "Enter Broadcast Code (auto/value):", + assistant_set_bcode_cfg, cfg); + else + if (!g_dbus_proxy_method_call(cfg->proxy, "Push", + push_setup, push_reply, + cfg, NULL)) { + bt_shell_printf("Failed to push assistant\n"); + goto fail; + } - dbus_message_iter_recurse(&iter, &dict); + return; - if (dbus_message_iter_get_arg_type(&dict) != DBUS_TYPE_DICT_ENTRY) - goto fail; +fail: + free(cfg->meta); + g_free(cfg); - dbus_message_iter_recurse(&dict, &entry); - dbus_message_iter_get_basic(&entry, &key); + return bt_shell_noninteractive_quit(EXIT_FAILURE); +} - if (strcasecmp(key, "Encryption") != 0) - goto fail; +static void assistant_set_device_cfg(const char *input, void *user_data) +{ + struct assistant_config *cfg = user_data; - dbus_message_iter_next(&entry); - dbus_message_iter_recurse(&entry, &value); + cfg->device = strdup(input); - if (dbus_message_iter_get_arg_type(&value) != DBUS_TYPE_BYTE) + if (!assistant_get_qos(cfg)) goto fail; - dbus_message_iter_get_basic(&value, &cfg->qos.bcast.encryption); - - if (cfg->qos.bcast.encryption) + if (cfg->qos.bcast.encryption) { /* Prompt user to enter the Broadcast Code to decrypt * the stream */ bt_shell_prompt_input("Assistant", "Enter Broadcast Code (auto/value):", assistant_set_bcode_cfg, cfg); - else + } else { if (!g_dbus_proxy_method_call(cfg->proxy, "Push", push_setup, push_reply, cfg, NULL)) { bt_shell_printf("Failed to push assistant\n"); goto fail; } + } return; fail: + free(cfg->device); free(cfg->meta); g_free(cfg); @@ -358,6 +408,7 @@ fail: static void cmd_push_assistant(int argc, char *argv[]) { struct assistant_config *cfg; + DBusMessageIter iter; cfg = new0(struct assistant_config, 1); if (!cfg) @@ -371,6 +422,17 @@ static void cmd_push_assistant(int argc, char *argv[]) goto fail; } + if (g_dbus_proxy_get_property(cfg->proxy, "State", &iter)) { + dbus_message_iter_get_basic(&iter, &cfg->state); + + if (!strcmp(cfg->state, "local")) { + /* Prompt user to enter metadata */ + bt_shell_prompt_input("Assistant", + "Enter Device (path):", + assistant_set_device_cfg, cfg); + return; + } + } /* Prompt user to enter metadata */ bt_shell_prompt_input("Assistant", "Enter Metadata (auto/value):", diff --git a/client/mgmt.c b/client/mgmt.c index 255155e41..968efdbca 100644 --- a/client/mgmt.c +++ b/client/mgmt.c @@ -369,7 +369,10 @@ static const char *settings_str[] = { "cis-central", "cis-peripheral", "iso-broadcaster", - "sync-receiver" + "sync-receiver", + "ll-privacy", + "past-sender", + "past-receiver" }; static const char *settings2str(uint32_t settings) -- 2.47.3