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 v2 2/7] advertising: Add implementation of Duration and Timeout
Date: Thu,  2 Nov 2017 16:43:47 +0200	[thread overview]
Message-ID: <20171102144352.32353-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20171102144352.32353-1-luiz.dentz@gmail.com>

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

This adds implementation of Duration and Timeout property and properly
set them in Add Advertising:

@ MGMT Command: Add Advertising (0x003e) plen 11
        Instance: 1
        Flags: 0x00000003
          Switch into Connectable mode
          Advertise as Discoverable
        Duration: 4
        Timeout: 0
        Advertising data length: 0
        Scan response length: 0
---
 src/advertising.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/src/advertising.c b/src/advertising.c
index d4d95c1c3..31a5fff5c 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -64,6 +64,9 @@ struct btd_adv_client {
 	char *path;
 	char *name;
 	uint16_t appearance;
+	uint16_t duration;
+	uint16_t timeout;
+	unsigned int to_id;
 	GDBusClient *client;
 	GDBusProxy *proxy;
 	DBusMessage *reg;
@@ -97,6 +100,9 @@ static void client_free(void *data)
 {
 	struct btd_adv_client *client = data;
 
+	if (client->to_id > 0)
+		g_source_remove(client->to_id);
+
 	if (client->client) {
 		g_dbus_client_set_disconnect_watch(client->client, NULL, NULL);
 		g_dbus_client_unref(client->client);
@@ -491,6 +497,48 @@ static bool parse_appearance(DBusMessageIter *iter,
 	return true;
 }
 
+static bool parse_duration(DBusMessageIter *iter,
+					struct btd_adv_client *client)
+{
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT16)
+		return false;
+
+	dbus_message_iter_get_basic(iter, &client->duration);
+
+	return true;
+}
+
+static gboolean client_timeout(void *user_data)
+{
+	struct btd_adv_client *client = user_data;
+
+	DBG("");
+
+	client->to_id = 0;
+
+	client_release(client);
+	client_remove(client);
+
+	return FALSE;
+}
+
+static bool parse_timeout(DBusMessageIter *iter,
+					struct btd_adv_client *client)
+{
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_UINT16)
+		return false;
+
+	dbus_message_iter_get_basic(iter, &client->timeout);
+
+	if (client->to_id)
+		g_source_remove(client->to_id);
+
+	client->to_id = g_timeout_add_seconds(client->timeout, client_timeout,
+								client);
+
+	return true;
+}
+
 static struct adv_parser {
 	const char *name;
 	bool (*func)(DBusMessageIter *iter, struct btd_adv_client *client);
@@ -503,6 +551,8 @@ static struct adv_parser {
 	{ "Includes", parse_includes },
 	{ "LocalName", parse_local_name },
 	{ "Appearance", parse_appearance },
+	{ "Duration", parse_duration },
+	{ "Timeout", parse_timeout },
 	{ },
 };
 
@@ -611,6 +661,7 @@ static int refresh_adv(struct btd_adv_client *client, mgmt_request_func_t func)
 
 	cp->flags = htobl(flags);
 	cp->instance = client->instance;
+	cp->duration = client->duration;
 	cp->adv_data_len = adv_data_len;
 	cp->scan_rsp_len = scan_rsp_len;
 	memcpy(cp->data, adv_data, adv_data_len);
-- 
2.13.6


  reply	other threads:[~2017-11-02 14:43 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-02 14:43 [PATCH v2 1/7] doc/advertising-api: Add Duration and Timeout Luiz Augusto von Dentz
2017-11-02 14:43 ` Luiz Augusto von Dentz [this message]
2017-11-02 14:43 ` [PATCH v2 3/7] client: Add set-advertise-{duration, timeout} Luiz Augusto von Dentz
2017-11-10  6:40   ` ERAMOTO Masaya
2017-11-10 12:06     ` Luiz Augusto von Dentz
2017-11-13  5:15       ` ERAMOTO Masaya
2017-11-02 14:43 ` [PATCH v2 4/7] advertising: Use client proxy to release Luiz Augusto von Dentz
2017-11-02 14:43 ` [PATCH v2 5/7] core: Add LEAdvertisement1 to bluetooth.conf Luiz Augusto von Dentz
2017-11-02 14:43 ` [PATCH v2 6/7] core: Cleanup bluetooth.conf Luiz Augusto von Dentz
2017-11-02 14:43 ` [PATCH v2 7/7] tests: Remove test-thermometer Luiz Augusto von Dentz
2017-11-03 11:21 ` [PATCH v2 1/7] doc/advertising-api: Add Duration and Timeout 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=20171102144352.32353-2-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).