Linux-Bluetooth Archive on lore.kernel.org
 help / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 2/2] gatt: Implement "type" option for Characteristic.WriteValue
Date: Wed,  6 Feb 2019 16:52:21 +0200
Message-ID: <20190206145221.29587-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20190206145221.29587-1-luiz.dentz@gmail.com>

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

This implements the "type" option as documented.
---
 src/gatt-client.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/src/gatt-client.c b/src/gatt-client.c
index c0cc3cd38..6bcdecf09 100644
--- a/src/gatt-client.c
+++ b/src/gatt-client.c
@@ -389,7 +389,8 @@ fail:
 	desc->read_op = NULL;
 }
 
-static int parse_options(DBusMessageIter *iter, uint16_t *offset)
+static int parse_options(DBusMessageIter *iter, uint16_t *offset,
+						const char **type)
 {
 	DBusMessageIter dict;
 
@@ -416,6 +417,12 @@ static int parse_options(DBusMessageIter *iter, uint16_t *offset)
 			dbus_message_iter_get_basic(&value, offset);
 		}
 
+		if (type && strcasecmp(key, "type") == 0) {
+			if (var != DBUS_TYPE_STRING)
+				return -EINVAL;
+			dbus_message_iter_get_basic(&value, type);
+		}
+
 		dbus_message_iter_next(&dict);
 	}
 
@@ -469,7 +476,7 @@ static DBusMessage *descriptor_read_value(DBusConnection *conn,
 
 	dbus_message_iter_init(msg, &iter);
 
-	if (parse_options(&iter, &offset))
+	if (parse_options(&iter, &offset, NULL))
 		return btd_error_invalid_args(msg);
 
 	if (desc->read_op) {
@@ -599,7 +606,7 @@ static DBusMessage *descriptor_write_value(DBusConnection *conn,
 
 	dbus_message_iter_next(&iter);
 
-	if (parse_options(&iter, &offset))
+	if (parse_options(&iter, &offset, NULL))
 		return btd_error_invalid_args(msg);
 
 	/*
@@ -933,7 +940,7 @@ static DBusMessage *characteristic_read_value(DBusConnection *conn,
 
 	dbus_message_iter_init(msg, &iter);
 
-	if (parse_options(&iter, &offset))
+	if (parse_options(&iter, &offset, NULL))
 		return btd_error_invalid_args(msg);
 
 	if (chrc->read_op) {
@@ -974,6 +981,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,
 	int value_len = 0;
 	bool supported = false;
 	uint16_t offset = 0;
+	const char *type = NULL;
 
 	if (!gatt)
 		return btd_error_failed(msg, "Not connected");
@@ -991,7 +999,7 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,
 
 	dbus_message_iter_next(&iter);
 
-	if (parse_options(&iter, &offset))
+	if (parse_options(&iter, &offset, &type))
 		return btd_error_invalid_args(msg);
 
 	/*
@@ -1005,7 +1013,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,
 	 *     - If value is larger than MTU - 3: long-write
 	 *   * "write-without-response" property set -> write command.
 	 */
-	if ((chrc->ext_props & BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE)) {
+	if ((!type && (chrc->ext_props & BT_GATT_CHRC_EXT_PROP_RELIABLE_WRITE))
+			|| (type && !strcasecmp(type, "reliable"))) {
 		supported = true;
 		chrc->write_op = start_long_write(msg, chrc->value_handle, gatt,
 						true, value, value_len, offset,
@@ -1014,7 +1023,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,
 			return NULL;
 	}
 
-	if (chrc->props & BT_GATT_CHRC_PROP_WRITE) {
+	if ((!type && chrc->props & BT_GATT_CHRC_PROP_WRITE) ||
+			(type && !strcasecmp(type, "request"))) {
 		uint16_t mtu;
 
 		supported = true;
@@ -1037,7 +1047,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn,
 			return NULL;
 	}
 
-	if (!(chrc->props & BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP))
+	if ((type && strcasecmp(type, "command")) || offset ||
+			!(chrc->props & BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP))
 		goto fail;
 
 	supported = true;
-- 
2.17.2


      reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06 14:52 [PATCH BlueZ 1/2] doc/gatt-api: Add "type" option to Characteristic.WriteValue Luiz Augusto von Dentz
2019-02-06 14:52 ` Luiz Augusto von Dentz [this message]

Reply instructions:

You may reply publically 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=20190206145221.29587-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

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox