From f5a62f6c02f7d9c3c0ee6f52a5c1adbb922ffbae Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Wed, 6 Feb 2019 16:49:03 +0200 Subject: [PATCH] gatt: Implement "type" option for Characteristic.WriteValue This implements the "type" option as documented. Change-Id: Ib3f73e27b13161c0ed44dd00bb4ad0a28e75e79a Signed-off-by: himanshu --- 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 908b3df..1e4ae3c 100644 --- a/src/gatt-client.c +++ b/src/gatt-client.c @@ -422,7 +422,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; @@ -449,6 +450,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); } @@ -502,7 +509,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) { @@ -655,7 +662,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); /* @@ -1000,7 +1007,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) { @@ -1041,6 +1048,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"); @@ -1058,7 +1066,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); /* @@ -1073,7 +1081,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn, * * "write-without-response" property set -> write command. */ #ifndef TIZEN_FEATURE_BLUEZ_MODIFY - 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, @@ -1083,7 +1092,8 @@ static DBusMessage *characteristic_write_value(DBusConnection *conn, } #endif - 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; @@ -1106,7 +1116,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.7.4