public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: raghu447 <raghavendra.rao@collabora.com>
To: linux-bluetooth@vger.kernel.org
Cc: raghavendra <raghavendra.rao@collabora.com>
Subject: [PATCH BlueZ v4 2/2] client: make advertise.name use public broadcast name
Date: Wed, 29 Apr 2026 11:40:45 +0530	[thread overview]
Message-ID: <20260429061045.9115-3-raghavendra.rao@collabora.com> (raw)
In-Reply-To: <20260429061045.9115-1-raghavendra.rao@collabora.com>

From: raghavendra <raghavendra.rao@collabora.com>

---
 client/advertising.c | 74 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 74 insertions(+)

diff --git a/client/advertising.c b/client/advertising.c
index 2fc2ac9c6..5ca391635 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -31,6 +31,7 @@
 #define AD_PATH "/org/bluez/advertising"
 #define AD_IFACE "org.bluez.LEAdvertisement1"
 #define AD_PUBLIC_BROADCAST_UUID "0x1856"
+#define AD_TYPE_PUBLIC_BROADCAST_NAME 0x30
 #define AD_PUBLIC_BROADCAST_SQ BIT(1)
 #define AD_PUBLIC_BROADCAST_HQ BIT(2)
 
@@ -1016,6 +1017,62 @@ static bool ad_is_public_broadcast_uuid(const char *uuid)
 	return uuid && !bt_uuid_strcmp(uuid, AD_PUBLIC_BROADCAST_UUID);
 }
 
+static bool ad_broadcast_in_use(void)
+{
+	return ad_is_public_broadcast_uuid(ad.service[AD_TYPE_AD].uuid);
+}
+
+static bool ad_has_public_broadcast_name(void)
+{
+	return ad.data[AD_TYPE_AD].valid &&
+		ad.data[AD_TYPE_AD].type == AD_TYPE_PUBLIC_BROADCAST_NAME &&
+		ad.data[AD_TYPE_AD].data.len > 0;
+}
+
+static void ad_print_public_broadcast_name(void)
+{
+	if (!ad_has_public_broadcast_name()) {
+		bt_shell_printf("Public Broadcast Name not set\n");
+		return;
+	}
+
+	bt_shell_printf("Public Broadcast Name: %.*s\n",
+			(int) ad.data[AD_TYPE_AD].data.len,
+			(char *) ad.data[AD_TYPE_AD].data.data);
+}
+
+static bool ad_set_public_broadcast_name(DBusConnection *conn,
+						const char *name)
+{
+	struct ad_data data;
+	size_t len;
+
+	if (!name || !strlen(name)) {
+		bt_shell_printf("Public Broadcast Name cannot be empty\n");
+		return false;
+	}
+
+	len = strlen(name);
+	if (len > sizeof(data.data)) {
+		bt_shell_printf("Public Broadcast Name too long\n");
+		return false;
+	}
+
+	memset(&data, 0, sizeof(data));
+	memcpy(data.data, name, len);
+	data.len = len;
+
+	ad_clear_data(AD_TYPE_AD);
+	ad.data[AD_TYPE_AD].valid = true;
+	ad.data[AD_TYPE_AD].type = AD_TYPE_PUBLIC_BROADCAST_NAME;
+	ad.data[AD_TYPE_AD].data = data;
+
+	g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE,
+					prop_names.data[AD_TYPE_AD]);
+
+	return true;
+}
+
 static const char *ad_public_broadcast_state(void)
 {
 	if (!ad_is_public_broadcast_uuid(ad.service[AD_TYPE_AD].uuid))
@@ -1203,6 +1260,23 @@ void ad_advertise_name(DBusConnection *conn, bool value)
 
 void ad_advertise_local_name(DBusConnection *conn, const char *name)
 {
+	if (ad_broadcast_in_use()) {
+		if (!name) {
+			ad_print_public_broadcast_name();
+			return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+		}
+
+		if (ad_has_public_broadcast_name() &&
+		    ad.data[AD_TYPE_AD].data.len == strlen(name) &&
+		    !memcmp(ad.data[AD_TYPE_AD].data.data, name, strlen(name)))
+			return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+
+		if (!ad_set_public_broadcast_name(conn, name))
+			return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+		return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+	}
+
 	if (!name) {
 		if (ad.local_name)
 			bt_shell_printf("LocalName: %s\n", ad.local_name);
-- 
2.43.0


  parent reply	other threads:[~2026-04-29  6:11 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-17 14:26 [PATCH BlueZ 0/1] client: add public-broadcast advertise helper raghava447
2026-03-17 14:26 ` [PATCH BlueZ 1/1] client: Add public-broadcast profile advertise command raghava447
2026-03-17 16:21   ` client: add public-broadcast advertise helper bluez.test.bot
2026-03-17 18:00   ` [PATCH BlueZ 1/1] client: Add public-broadcast profile advertise command Luiz Augusto von Dentz
2026-03-20  8:34     ` raghava447
2026-04-24 14:18 ` [PATCH BlueZ v2 0/2] client: Add public broadcast advertising support raghu447
2026-04-24 14:18   ` [PATCH v2 1/2] client: add public-broadcast advertising command raghu447
2026-04-24 14:41     ` Luiz Augusto von Dentz
2026-04-24 14:44     ` Luiz Augusto von Dentz
     [not found]       ` <19dd4843cc9.16a62f4c253537.8494966934612526917@collabora.com>
2026-04-28 14:42         ` Luiz Augusto von Dentz
2026-04-24 16:23     ` client: Add public broadcast advertising support bluez.test.bot
2026-04-24 14:18   ` [PATCH v2 2/2] client: make advertise.name use public broadcast name raghu447
2026-04-28 14:40     ` [PATCH BlueZ v3 0/2] client: Add public broadcast advertising support raghu447
2026-04-28 14:40       ` [PATCH BlueZ v3 1/2] client: add public-broadcast advertising command raghu447
2026-04-28 16:27         ` client: Add public broadcast advertising support bluez.test.bot
2026-04-29  6:10         ` [PATCH BlueZ v4 0/2] " raghu447
2026-04-29  6:10           ` [PATCH BlueZ v4 1/2] client: add public-broadcast advertising command raghu447
2026-04-29  6:46             ` client: Add public broadcast advertising support bluez.test.bot
2026-04-29  7:46             ` [PATCH BlueZ v5 0/2] " raghu447
2026-04-29  7:46               ` [PATCH BlueZ v5 1/2] client: add public-broadcast advertising command raghu447
2026-04-29  9:21                 ` client: Add public broadcast advertising support bluez.test.bot
2026-04-29  7:46               ` [PATCH BlueZ v5 2/2] client: make advertise.name use public broadcast name raghu447
2026-04-29 13:50               ` [PATCH BlueZ v5 0/2] client: Add public broadcast advertising support patchwork-bot+bluetooth
2026-04-29  6:10           ` raghu447 [this message]
2026-04-28 14:40       ` [PATCH BlueZ v3 2/2] client: make advertise.name use public broadcast name raghu447

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=20260429061045.9115-3-raghavendra.rao@collabora.com \
    --to=raghavendra.rao@collabora.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