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 3/5] advertising: Add implementation of Flags property
Date: Mon,  7 May 2018 19:14:01 +0300	[thread overview]
Message-ID: <20180507161403.14181-3-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20180507161403.14181-1-luiz.dentz@gmail.com>

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

This parses the contents of Flags property and add it to AD data
directly using bt_ad_add_flags.
---
 src/advertising.c | 43 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 41 insertions(+), 2 deletions(-)

diff --git a/src/advertising.c b/src/advertising.c
index 441d0a235..202b6eec5 100644
--- a/src/advertising.c
+++ b/src/advertising.c
@@ -641,6 +641,43 @@ fail:
 	return false;
 }
 
+static bool parse_flags(DBusMessageIter *iter, struct btd_adv_client *client)
+{
+	DBusMessageIter array;
+	uint8_t *flags;
+	int len;
+
+	if (!iter) {
+		bt_ad_clear_flags(client->data);
+		client->flags &= ~MGMT_ADV_FLAG_MANAGED_FLAGS;
+		return true;
+	}
+
+	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
+		return false;
+
+	dbus_message_iter_recurse(iter, &array);
+
+	if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_BYTE)
+		goto fail;
+
+	dbus_message_iter_get_fixed_array(&array, &flags, &len);
+
+	if (!bt_ad_add_flags(client->data, flags, len))
+		goto fail;
+
+	DBG("Adding Flags 0x%02x", flags[0]);
+
+	client->flags |= MGMT_ADV_FLAG_MANAGED_FLAGS;
+
+	return true;
+
+fail:
+	bt_ad_clear_flags(client->data);
+	client->flags &= ~MGMT_ADV_FLAG_MANAGED_FLAGS;
+	return false;
+}
+
 static struct adv_parser {
 	const char *name;
 	bool (*func)(DBusMessageIter *iter, struct btd_adv_client *client);
@@ -656,6 +693,7 @@ static struct adv_parser {
 	{ "Duration", parse_duration },
 	{ "Timeout", parse_timeout },
 	{ "Data", parse_data },
+	{ "Flags", parse_flags },
 	{ },
 };
 
@@ -737,11 +775,12 @@ static int refresh_adv(struct btd_adv_client *client, mgmt_request_func_t func)
 	if (client->type == AD_TYPE_PERIPHERAL) {
 		flags = MGMT_ADV_FLAG_CONNECTABLE;
 
-		if (btd_adapter_get_discoverable(client->manager->adapter))
+		if (btd_adapter_get_discoverable(client->manager->adapter) &&
+				!(client->flags & MGMT_ADV_FLAG_MANAGED_FLAGS))
 			flags |= MGMT_ADV_FLAG_DISCOV;
 	}
 
-	flags |= client->flags;
+	flags |= client->flags & ~MGMT_ADV_FLAG_MANAGED_FLAGS;
 
 	adv_data = generate_adv_data(client, &flags, &adv_data_len);
 	if (!adv_data || (adv_data_len > calc_max_adv_len(client, flags))) {
-- 
2.14.3


  parent reply	other threads:[~2018-05-07 16:14 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-07 16:13 [PATCH BlueZ 1/5] doc/advertising-api: Add Flags property Luiz Augusto von Dentz
2018-05-07 16:14 ` [PATCH BlueZ 2/5] shared/ad: Add bt_ad_add_flags and bt_ad_clear_flags Luiz Augusto von Dentz
2018-05-07 16:14 ` Luiz Augusto von Dentz [this message]
2018-05-07 16:14 ` [PATCH BlueZ 4/5] client: Add advertise.flags command Luiz Augusto von Dentz
2018-05-07 16:14 ` [PATCH BlueZ 5/5] client: Print AD Data and Flags once registered Luiz Augusto von Dentz
2018-05-08  7:40 ` [PATCH BlueZ 1/5] doc/advertising-api: Add Flags property Luiz Augusto von Dentz
2018-05-08  8:49   ` David Llewellyn-Jones
2018-05-08  7:53 ` Marcel Holtmann
2018-05-08  9:26   ` Luiz Augusto von Dentz
2018-05-08 11:17     ` Marcel Holtmann
2018-05-11 11:12       ` Luiz Augusto von Dentz
2018-05-11 11:21         ` David Llewellyn-Jones
2018-05-11 15:34           ` Marcel Holtmann
2018-05-11 19:11             ` David Llewellyn-Jones
2018-05-11 15:32         ` Marcel Holtmann

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=20180507161403.14181-3-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).