2018-04-18 08:37:10

by Grzegorz Kołodziejczyk

[permalink] [raw]
Subject: [PATCH BlueZ 1/3] client: Add missing newline character to shell printfs

This patch adds missing newline characters to shell printfs. It fixes
printig issues.
---
client/gatt.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/client/gatt.c b/client/gatt.c
index 7103c4f83..52a999dc9 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -627,7 +627,8 @@ static void write_attribute(GDBusProxy *proxy, char *arg)
bt_shell_printf("Attempting to write fd %d\n",
io_get_fd(write_io.io));
if (io_send(write_io.io, &iov, 1) < 0) {
- bt_shell_printf("Failed to write: %s", strerror(errno));
+ bt_shell_printf("Failed to write: %s\n",
+ strerror(errno));
return bt_shell_noninteractive_quit(EXIT_FAILURE);
}
return;
@@ -1622,7 +1623,7 @@ static void authorize_write_response(const char *input, void *user_data)
goto error;
}

- bt_shell_printf("[" COLORED_CHG "] Attribute %s written" , chrc->path);
+ bt_shell_printf("[" COLORED_CHG "] Attribute %s written\n", chrc->path);

g_dbus_emit_property_changed(aad->conn, chrc->path, CHRC_INTERFACE,
"Value");
@@ -1671,7 +1672,7 @@ static DBusMessage *chrc_write_value(DBusConnection *conn, DBusMessage *msg,
"org.bluez.Error.InvalidArguments",
NULL);

- bt_shell_printf("[" COLORED_CHG "] Attribute %s written" , chrc->path);
+ bt_shell_printf("[" COLORED_CHG "] Attribute %s written\n", chrc->path);

g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE, "Value");

@@ -1789,8 +1790,8 @@ static DBusMessage *chrc_start_notify(DBusConnection *conn, DBusMessage *msg,
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);

chrc->notifying = true;
- bt_shell_printf("[" COLORED_CHG "] Attribute %s notifications enabled",
- chrc->path);
+ bt_shell_printf("[" COLORED_CHG "] Attribute %s notifications "
+ "enabled\n", chrc->path);
g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE,
"Notifying");

@@ -1806,8 +1807,8 @@ static DBusMessage *chrc_stop_notify(DBusConnection *conn, DBusMessage *msg,
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);

chrc->notifying = false;
- bt_shell_printf("[" COLORED_CHG "] Attribute %s notifications disabled",
- chrc->path);
+ bt_shell_printf("[" COLORED_CHG "] Attribute %s notifications "
+ "disabled\n", chrc->path);
g_dbus_emit_property_changed(conn, chrc->path, CHRC_INTERFACE,
"Notifying");

@@ -1819,7 +1820,8 @@ static DBusMessage *chrc_confirm(DBusConnection *conn, DBusMessage *msg,
{
struct chrc *chrc = user_data;

- bt_shell_printf("Attribute %s indication confirm received", chrc->path);
+ bt_shell_printf("Attribute %s indication confirm received\n",
+ chrc->path);

return dbus_message_new_method_return(msg);
}
@@ -2012,7 +2014,7 @@ static DBusMessage *desc_write_value(DBusConnection *conn, DBusMessage *msg,
bt_shell_printf("WriteValue: %s offset %u link %s\n",
path_to_address(device), offset, link);

- bt_shell_printf("[" COLORED_CHG "] Attribute %s written" , desc->path);
+ bt_shell_printf("[" COLORED_CHG "] Attribute %s written\n" , desc->path);

g_dbus_emit_property_changed(conn, desc->path, CHRC_INTERFACE, "Value");

--
2.13.6



2018-04-18 08:37:11

by Grzegorz Kołodziejczyk

[permalink] [raw]
Subject: [PATCH BlueZ 2/3] client: Fix writing attribute values

Attribute values is not copied with dbus_message_iter_get_fixed_array,
so gatt write callback needs to replace old value with reallocation and
copy.
---
client/gatt.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/client/gatt.c b/client/gatt.c
index 52a999dc9..102c11437 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -1589,12 +1589,18 @@ static DBusMessage *chrc_read_value(DBusConnection *conn, DBusMessage *msg,
static int parse_value_arg(DBusMessageIter *iter, uint8_t **value, int *len)
{
DBusMessageIter array;
+ uint8_t *read_value;
+ int read_len;

if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
return -EINVAL;

dbus_message_iter_recurse(iter, &array);
- dbus_message_iter_get_fixed_array(&array, value, len);
+ dbus_message_iter_get_fixed_array(&array, &read_value, &read_len);
+
+ g_free(*value);
+ *value = g_memdup(read_value, read_len);
+ *len = read_len;

return 0;
}
--
2.13.6


2018-04-18 08:37:12

by Grzegorz Kołodziejczyk

[permalink] [raw]
Subject: [PATCH BlueZ 3/3] shared/gatt-server: Fix prepare write queuing

Multiple prepare writes may be done for multiple attributes. Queue
mechanism must be aware of handle under which preparation is done.
---
src/shared/gatt-server.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c
index 4b554f665..20d01fd08 100644
--- a/src/shared/gatt-server.c
+++ b/src/shared/gatt-server.c
@@ -1190,6 +1190,14 @@ static bool prep_data_new(struct bt_gatt_server *server,
return true;
}

+static bool match_prep_attr_handle(const void *data, const void *match_data)
+{
+ const struct prep_write_data *prep_data = data;
+ const uint16_t *match_handle = match_data;
+
+ return prep_data->handle == *match_handle;
+}
+
static bool store_prep_data(struct bt_gatt_server *server,
uint16_t handle, uint16_t offset,
uint16_t length, uint8_t *value)
@@ -1200,7 +1208,9 @@ static bool store_prep_data(struct bt_gatt_server *server,
* Now lets check if prep write is a continuation of long write
* If so do aggregation of data
*/
- prep_data = queue_peek_tail(server->prep_queue);
+ prep_data = queue_find(server->prep_queue, match_prep_attr_handle,
+ &handle);
+
if (prep_data && (prep_data->handle == handle) &&
(offset == (prep_data->length + prep_data->offset)))
return append_prep_data(prep_data, handle, length, value);
--
2.13.6