linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 4/4] client: Add advertise.secondary command
Date: Fri, 15 Feb 2019 16:23:01 +0200	[thread overview]
Message-ID: <20190215142301.30909-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20190215142301.30909-1-luiz.dentz@gmail.com>

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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


  parent reply	other threads:[~2019-02-15 14:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-15 14:22 [PATCH BlueZ 1/4] doc/advertising-api: Add support for setting Secondary Channel Luiz Augusto von Dentz
2019-02-15 14:22 ` [PATCH BlueZ 2/4] advertising: Add implementation of SupportedSecondaryChannels Luiz Augusto von Dentz
2019-02-15 14:23 ` [PATCH BlueZ 3/4] advertising: Add implementation of SecondaryChannel Luiz Augusto von Dentz
2019-02-15 14:23 ` Luiz Augusto von Dentz [this message]
2019-02-21 12:09 ` [PATCH BlueZ 1/4] doc/advertising-api: Add support for setting Secondary Channel Luiz Augusto von Dentz

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=20190215142301.30909-4-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;
as well as URLs for NNTP newsgroup(s).