[GATT-Server] Add offset for Read/Write operations 90/141990/3
authorGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 2 Aug 2017 07:18:53 +0000 (12:48 +0530)
committerGowtham Anandha Babu <gowtham.ab@samsung.com>
Wed, 2 Aug 2017 07:25:16 +0000 (07:25 +0000)
Change-Id: I37e668499ea2b9b79d3fd10c055444353165f1dd
Signed-off-by: Gowtham Anandha Babu <gowtham.ab@samsung.com>
src/gatt-database.c

index 79d9a9b..7dd2230 100755 (executable)
@@ -138,6 +138,9 @@ struct external_desc {
 struct pending_op {
        struct btd_device *device;
        unsigned int id;
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       uint16_t offset;
+#endif
        struct gatt_db_attribute *attrib;
        struct queue *owner_queue;
        struct iovec data;
@@ -1968,11 +1971,17 @@ static void pending_op_free(void *data)
 
        free(op);
 }
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+static struct pending_op *pending_read_new(struct btd_device *device,
+                                       struct queue *owner_queue,
+                                       struct gatt_db_attribute *attrib,
+                                       unsigned int id, uint16_t offset)
+#else
 static struct pending_op *pending_read_new(struct btd_device *device,
                                        struct queue *owner_queue,
                                        struct gatt_db_attribute *attrib,
                                        unsigned int id)
+#endif
 {
        struct pending_op *op;
 
@@ -1982,6 +1991,9 @@ static struct pending_op *pending_read_new(struct btd_device *device,
        op->device = device;
        op->attrib = attrib;
        op->id = id;
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       op->offset = offset;
+#endif
        queue_push_tail(owner_queue, op);
 
        return op;
@@ -2003,13 +2015,12 @@ static void read_setup_cb(DBusMessageIter *iter, void *user_data)
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        char dst_addr[18] = { 0 };
        char *addr_value = dst_addr;
-       uint16_t offset = 0;
        const bdaddr_t *bdaddr = device_get_address(op->device);
 
        ba2str(bdaddr, dst_addr);
        dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &addr_value);
        dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &op->id);
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &offset);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &op->offset);
 #else
        DBusMessageIter dict;
 
@@ -2026,15 +2037,27 @@ static void read_setup_cb(DBusMessageIter *iter, void *user_data)
 #endif
 }
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
 static struct pending_op *send_read(struct btd_device *device,
                                        struct gatt_db_attribute *attrib,
                                        GDBusProxy *proxy,
                                        struct queue *owner_queue,
+                                       unsigned int id,
+                                       uint16_t offset)
+#else
+static struct pending_op *send_read(struct btd_device *device,
+                                       struct gatt_db_attribute *attrib,
+                                       GDBusProxy *proxy,
+                                       struct queue *owner_queue
                                        unsigned int id)
+#endif
 {
        struct pending_op *op;
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       op = pending_read_new(device, owner_queue, attrib, id, offset);
+#else
        op = pending_read_new(device, owner_queue, attrib, id);
+#endif
 
        if (g_dbus_proxy_method_call(proxy, "ReadValue", read_setup_cb,
                                read_reply_cb, op, pending_op_free) == TRUE)
@@ -2052,14 +2075,13 @@ static void write_setup_cb(DBusMessageIter *iter, void *user_data)
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
        char dst_addr[18] = { 0 };
        char *addr_value = dst_addr;
-       uint16_t offset = 0;
        gboolean response_needed = TRUE;
        const bdaddr_t *bdaddr = device_get_address(op->device);
 
        ba2str(bdaddr, dst_addr);
        dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &addr_value);
        dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &op->id);
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &offset);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &op->offset);
        dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &response_needed);
 #endif
        dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "y", &array);
@@ -2129,13 +2151,22 @@ static void write_reply_cb(DBusMessage *message, void *user_data)
 done:
        gatt_db_attribute_write_result(op->attrib, op->id, ecode);
 }
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+static struct pending_op *pending_write_new(struct btd_device *device,
+                                       struct queue *owner_queue,
+                                       struct gatt_db_attribute *attrib,
+                                       unsigned int id,
+                                       const uint8_t *value,
+                                       size_t len,
+                                       uint16_t offset)
+#else
 static struct pending_op *pending_write_new(struct btd_device *device,
                                        struct queue *owner_queue,
                                        struct gatt_db_attribute *attrib,
                                        unsigned int id,
                                        const uint8_t *value,
                                        size_t len)
+#endif
 {
        struct pending_op *op;
 
@@ -2148,21 +2179,36 @@ static struct pending_op *pending_write_new(struct btd_device *device,
        op->owner_queue = owner_queue;
        op->attrib = attrib;
        op->id = id;
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       op->offset = offset;
+#endif
        queue_push_tail(owner_queue, op);
 
        return op;
 }
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+static struct pending_op *send_write(struct btd_device *device,
+                                       struct gatt_db_attribute *attrib,
+                                       GDBusProxy *proxy,
+                                       struct queue *owner_queue,
+                                       unsigned int id,
+                                       const uint8_t *value, size_t len,
+                                       uint16_t offset)
+#else
 static struct pending_op *send_write(struct btd_device *device,
                                        struct gatt_db_attribute *attrib,
                                        GDBusProxy *proxy,
                                        struct queue *owner_queue,
                                        unsigned int id,
                                        const uint8_t *value, size_t len)
+#endif
 {
        struct pending_op *op;
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       op = pending_write_new(device, owner_queue, attrib, id, value, len, offset);
+#else
        op = pending_write_new(device, owner_queue, attrib, id, value, len);
+#endif
 
        if (g_dbus_proxy_method_call(proxy, "WriteValue", write_setup_cb,
                                        owner_queue ? write_reply_cb : NULL,
@@ -2457,10 +2503,14 @@ static void desc_read_cb(struct gatt_db_attribute *attrib,
                error("Unable to find device object");
                goto fail;
        }
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (send_read(device, attrib, desc->proxy, desc->pending_reads, id, offset))
+#else
        if (send_read(device, attrib, desc->proxy, desc->pending_reads, id))
+#endif
                return;
 
+
 fail:
        gatt_db_attribute_read_result(attrib, id, BT_ATT_ERROR_UNLIKELY,
                                                                NULL, 0);
@@ -2485,9 +2535,13 @@ static void desc_write_cb(struct gatt_db_attribute *attrib,
                error("Unable to find device object");
                goto fail;
        }
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (send_write(device, attrib, desc->proxy, desc->pending_writes, id,
+                                                       value, len, offset))
+#else
        if (send_write(device, attrib, desc->proxy, desc->pending_writes, id,
                                                        value, len))
+#endif
                return;
 
 fail:
@@ -2537,8 +2591,11 @@ static void chrc_read_cb(struct gatt_db_attribute *attrib,
                error("Unable to find device object");
                goto fail;
        }
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (send_read(device, attrib, chrc->proxy, chrc->pending_reads, id, offset))
+#else
        if (send_read(device, attrib, chrc->proxy, chrc->pending_reads, id))
+#endif
                return;
 
 fail:
@@ -2571,8 +2628,11 @@ static void chrc_write_cb(struct gatt_db_attribute *attrib,
                queue = chrc->pending_writes;
        else
                queue = NULL;
-
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       if (send_write(device, attrib, chrc->proxy, queue, id, value, len, offset))
+#else
        if (send_write(device, attrib, chrc->proxy, queue, id, value, len))
+#endif
                return;
 
 fail: