2023-04-05 23:20:40

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH BlueZ 5/5] client/advertising: Add support for advertise.rsi command

From: Luiz Augusto von Dentz <[email protected]>

This adds support for advertise.rsi command which can be used to request
the generation of RSI and include it as part of advertising data:

[bluetooth]# advertise.rsi --help
Show/Enable/Disable RSI to be advertised
Usage:
rsi [on/off]
[bluetooth]# advertise.rsi
RSI: on
[bluetooth]# advertise on
...
Advertising object registered
Tx Power: off
Name: off
Appearance: off
Discoverable: on
RSI: on
[bluetooth]#
---
client/advertising.c | 28 +++++++++++++++++++++++++++-
client/advertising.h | 1 +
client/main.c | 17 +++++++++++++++++
3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/client/advertising.c b/client/advertising.c
index fb9b049fde78..8b8e6d97ff80 100644
--- a/client/advertising.c
+++ b/client/advertising.c
@@ -67,9 +67,11 @@ static struct ad {
bool tx_power;
bool name;
bool appearance;
+ bool rsi;
} ad = {
.local_appearance = UINT16_MAX,
.discoverable = true,
+ .rsi = true,
};

static void ad_release(DBusConnection *conn)
@@ -176,6 +178,7 @@ static void print_ad(void)
ad.appearance ? "on" : "off");

bt_shell_printf("Discoverable: %s\n", ad.discoverable ? "on": "off");
+ bt_shell_printf("RSI: %s\n", ad.rsi ? "on": "off");

if (ad.duration)
bt_shell_printf("Duration: %u sec\n", ad.duration);
@@ -295,7 +298,7 @@ static gboolean get_manufacturer_data(const GDBusPropertyTable *property,

static gboolean includes_exists(const GDBusPropertyTable *property, void *data)
{
- return ad.tx_power || ad.name || ad.appearance;
+ return ad.tx_power || ad.name || ad.appearance || ad.rsi;
}

static gboolean get_includes(const GDBusPropertyTable *property,
@@ -323,6 +326,12 @@ static gboolean get_includes(const GDBusPropertyTable *property,
dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &str);
}

+ if (ad.rsi) {
+ const char *str = "rsi";
+
+ dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &str);
+ }
+
dbus_message_iter_close_container(iter, &array);


@@ -1023,3 +1032,20 @@ void ad_advertise_interval(DBusConnection *conn, uint32_t *min, uint32_t *max)

return bt_shell_noninteractive_quit(EXIT_SUCCESS);
}
+
+void ad_advertise_rsi(DBusConnection *conn, dbus_bool_t *value)
+{
+ if (!value) {
+ bt_shell_printf("RSI: %s\n", ad.rsi ? "on" : "off");
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+ }
+
+ if (ad.rsi == *value)
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+
+ ad.rsi = *value;
+
+ g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, "Includes");
+
+ return bt_shell_noninteractive_quit(EXIT_SUCCESS);
+}
diff --git a/client/advertising.h b/client/advertising.h
index 472396efd381..145ac80452d2 100644
--- a/client/advertising.h
+++ b/client/advertising.h
@@ -30,3 +30,4 @@ void ad_advertise_discoverable(DBusConnection *conn, dbus_bool_t *value);
void ad_advertise_discoverable_timeout(DBusConnection *conn, long int *value);
void ad_advertise_secondary(DBusConnection *conn, const char *value);
void ad_advertise_interval(DBusConnection *conn, uint32_t *min, uint32_t *max);
+void ad_advertise_rsi(DBusConnection *conn, dbus_bool_t *value);
diff --git a/client/main.c b/client/main.c
index 79895015d6a6..b433a22001a3 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2733,6 +2733,21 @@ static void cmd_advertise_interval(int argc, char *argv[])
ad_advertise_interval(dbus_conn, &min, &max);
}

+static void cmd_advertise_rsi(int argc, char *argv[])
+{
+ dbus_bool_t value;
+
+ if (argc < 2) {
+ ad_advertise_rsi(dbus_conn, NULL);
+ return;
+ }
+
+ if (!parse_argument(argc, argv, NULL, NULL, &value, NULL))
+ return bt_shell_noninteractive_quit(EXIT_FAILURE);
+
+ ad_advertise_rsi(dbus_conn, &value);
+}
+
static void ad_clear_uuids(void)
{
ad_disable_uuids(dbus_conn);
@@ -2931,6 +2946,8 @@ static const struct bt_shell_menu advertise_menu = {
"Set/Get advertise secondary channel" },
{ "interval", "[min] [max] ", cmd_advertise_interval,
"Set/Get advertise interval range" },
+ { "rsi", "[on/off]", cmd_advertise_rsi,
+ "Show/Enable/Disable RSI to be advertised", NULL },
{ "clear", "[uuids/service/manufacturer/config-name...]", cmd_ad_clear,
"Clear advertise config" },
{ } },
--
2.39.2