client: Add support for optional gatt read offset parameter
This patch extends missing optional gatt read offset parameter.
diff --git a/client/gatt.c b/client/gatt.c
index 7d63c02..1766651 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -518,6 +518,7 @@
static void read_setup(DBusMessageIter *iter, void *user_data)
{
DBusMessageIter dict;
+ uint16_t *offset = user_data;
dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
@@ -525,14 +526,16 @@
DBUS_TYPE_VARIANT_AS_STRING
DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
&dict);
- /* TODO: Add offset support */
+
+ g_dbus_dict_append_entry(&dict, "offset", DBUS_TYPE_UINT16, offset);
+
dbus_message_iter_close_container(iter, &dict);
}
-static void read_attribute(GDBusProxy *proxy)
+static void read_attribute(GDBusProxy *proxy, uint16_t offset)
{
if (g_dbus_proxy_method_call(proxy, "ReadValue", read_setup, read_reply,
- NULL, NULL) == FALSE) {
+ &offset, NULL) == FALSE) {
bt_shell_printf("Failed to read\n");
return bt_shell_noninteractive_quit(EXIT_FAILURE);
}
@@ -540,14 +543,19 @@
bt_shell_printf("Attempting to read %s\n", g_dbus_proxy_get_path(proxy));
}
-void gatt_read_attribute(GDBusProxy *proxy)
+void gatt_read_attribute(GDBusProxy *proxy, int argc, char *argv[])
{
const char *iface;
+ uint16_t offset = 0;
iface = g_dbus_proxy_get_interface(proxy);
if (!strcmp(iface, "org.bluez.GattCharacteristic1") ||
!strcmp(iface, "org.bluez.GattDescriptor1")) {
- read_attribute(proxy);
+
+ if (argc == 2)
+ offset = atoi(argv[1]);
+
+ read_attribute(proxy, offset);
return;
}
diff --git a/client/gatt.h b/client/gatt.h
index f4c36b8..274c76b 100644
--- a/client/gatt.h
+++ b/client/gatt.h
@@ -34,7 +34,7 @@
GDBusProxy *gatt_select_attribute(GDBusProxy *parent, const char *path);
char *gatt_attribute_generator(const char *text, int state);
-void gatt_read_attribute(GDBusProxy *proxy);
+void gatt_read_attribute(GDBusProxy *proxy, int argc, char *argv[]);
void gatt_write_attribute(GDBusProxy *proxy, const char *arg);
void gatt_notify_attribute(GDBusProxy *proxy, bool enable);
diff --git a/client/main.c b/client/main.c
index b96278d..57a85f1 100644
--- a/client/main.c
+++ b/client/main.c
@@ -1908,7 +1908,7 @@
return bt_shell_noninteractive_quit(EXIT_FAILURE);
}
- gatt_read_attribute(default_attr);
+ gatt_read_attribute(default_attr, argc, argv);
}
static void cmd_write(int argc, char *argv[])
@@ -2415,7 +2415,7 @@
"Select attribute", attribute_generator },
{ "attribute-info", "[attribute/UUID]", cmd_attribute_info,
"Select attribute", attribute_generator },
- { "read", NULL, cmd_read, "Read attribute value" },
+ { "read", "[offset]", cmd_read, "Read attribute value" },
{ "write", "<data=xx xx ...>", cmd_write,
"Write attribute value" },
{ "acquire-write", NULL, cmd_acquire_write,