From: Luiz Augusto von Dentz <luiz.von.dentz@xxxxxxxxx> This adds advertose.secondary command which can be used to set a secondary channel to advertise. --- client/advertising.c | 43 +++++++++++++++++++++++++++++++++++++++++++ client/advertising.h | 1 + client/main.c | 20 ++++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/client/advertising.c b/client/advertising.c index 960cdd62d..72f91b9a5 100644 --- a/client/advertising.c +++ b/client/advertising.c @@ -64,6 +64,7 @@ static struct ad { bool registered; char *type; char *local_name; + char *secondary; uint16_t local_appearance; uint16_t duration; uint16_t timeout; @@ -441,6 +442,20 @@ static gboolean get_discoverable_timeout(const GDBusPropertyTable *property, return TRUE; } +static gboolean secondary_exits(const GDBusPropertyTable *property, void *data) +{ + return ad.secondary ? TRUE : FALSE; +} + +static gboolean get_secondary(const GDBusPropertyTable *property, + DBusMessageIter *iter, void *user_data) +{ + dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, + &ad.secondary); + + return TRUE; +} + static const GDBusPropertyTable ad_props[] = { { "Type", "s", get_type }, { "ServiceUUIDs", "as", get_uuids, NULL, uuids_exists }, @@ -456,6 +471,7 @@ static const GDBusPropertyTable ad_props[] = { { "Appearance", "q", get_appearance, NULL, appearance_exits }, { "Duration", "q", get_duration, NULL, duration_exits }, { "Timeout", "q", get_timeout, NULL, timeout_exits }, + { "SecondaryChannel", "s", get_secondary, NULL, secondary_exits }, { } }; @@ -919,3 +935,30 @@ void ad_advertise_timeout(DBusConnection *conn, long int *value) return bt_shell_noninteractive_quit(EXIT_SUCCESS); } + +void ad_advertise_secondary(DBusConnection *conn, const char *value) +{ + if (!value) { + if (ad.secondary) + bt_shell_printf("Secondary Channel: %s\n", + ad.secondary); + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + } + + if (ad.secondary && !strcmp(value, ad.secondary)) + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + + free(ad.secondary); + + if (value[0] == '\0') { + ad.secondary = NULL; + return bt_shell_noninteractive_quit(EXIT_SUCCESS); + } + + ad.secondary = strdup(value); + + g_dbus_emit_property_changed(conn, AD_PATH, AD_IFACE, + "SecondaryChannel"); + + return bt_shell_noninteractive_quit(EXIT_SUCCESS); +} diff --git a/client/advertising.h b/client/advertising.h index fe3a7c8c6..9967e657b 100644 --- a/client/advertising.h +++ b/client/advertising.h @@ -41,3 +41,4 @@ void ad_advertise_data(DBusConnection *conn, int argc, char *argv[]); void ad_disable_data(DBusConnection *conn); 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); diff --git a/client/main.c b/client/main.c index 1f6e04578..2c5b05693 100644 --- a/client/main.c +++ b/client/main.c @@ -2479,6 +2479,16 @@ static void cmd_advertise_timeout(int argc, char *argv[]) ad_advertise_timeout(dbus_conn, &value); } +static void cmd_advertise_secondary(int argc, char *argv[]) +{ + if (argc < 2) { + ad_advertise_secondary(dbus_conn, NULL); + return; + } + + ad_advertise_secondary(dbus_conn, argv[1]); +} + static void ad_clear_uuids(void) { ad_disable_uuids(dbus_conn); @@ -2530,6 +2540,13 @@ static void ad_clear_timeout(void) ad_advertise_timeout(dbus_conn, &value); } +static void ad_clear_secondary(void) +{ + const char *value = ""; + + ad_advertise_secondary(dbus_conn, value); +} + static const struct clear_entry ad_clear[] = { { "uuids", ad_clear_uuids }, { "service", ad_clear_service }, @@ -2540,6 +2557,7 @@ static const struct clear_entry ad_clear[] = { { "appearance", ad_clear_appearance }, { "duration", ad_clear_duration }, { "timeout", ad_clear_timeout }, + { "secondary", ad_clear_secondary }, {} }; @@ -2583,6 +2601,8 @@ static const struct bt_shell_menu advertise_menu = { "Set/Get advertise duration" }, { "timeout", "[seconds]", cmd_advertise_timeout, "Set/Get advertise timeout" }, + { "secondary", "[1M/2M/Coded]", cmd_advertise_secondary, + "Set/Get advertise secondary channel" }, { "clear", "[uuids/service/manufacturer/config-name...]", cmd_ad_clear, "Clear advertise config" }, { } }, -- 2.17.2