GATT Server : Provide a response necessity 86/101886/1 accepted/tizen/3.0/common/20161207.194301 accepted/tizen/3.0/ivi/20161207.011039 accepted/tizen/3.0/mobile/20161207.010930 accepted/tizen/3.0/tv/20161207.010956 accepted/tizen/3.0/wearable/20161207.011027 submit/tizen_3.0/20161206.041315
authorSeungyoun Ju <sy39.ju@samsung.com>
Fri, 2 Dec 2016 05:40:41 +0000 (14:40 +0900)
committerSeungyoun Ju <sy39.ju@samsung.com>
Fri, 2 Dec 2016 09:36:03 +0000 (18:36 +0900)
[Model] COMMON
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] Applications couldn't know whether this write request require a
 response or not
[Cause & Measure] There was no information about a response necessity.
 And reply required dbus call is always used unnecessarily. This patch
 provides a reponse necessity to above layer and uses no reply dbus call
 for Write Without Response command.
[Checking Method] Add some writable characteristics to GATT Server ->
Send some Write Without Reponse or Write Reqest from a remote device

[Team] Basic connection
[Developer] Seungyoun Ju
[Solution company] Samsung
[Change Type] Specification change

Change-Id: I958d788c6873771f33d72e6b5310f63ead3dba70

src/gatt-database.c

index 4daa2e8..46be5a8 100644 (file)
@@ -1092,23 +1092,20 @@ static void indicate_confirm_free(void *data)
 static void indicate_confirm_setup_cb(DBusMessageIter *iter, void *user_data)
 {
        struct btd_device *device = user_data;
-       char dstaddr[18] = { 0 };
-       char *addr_value = NULL;
+       char dst_addr[18] = { 0 };
+       char *addr_value = dst_addr;
        gboolean complete = FALSE;
 
        if (device_get_rpa_exist(device) == true) {
-               ba2str(device_get_rpa(device), dstaddr);
+               ba2str(device_get_rpa(device), dst_addr);
        } else {
-               ba2str(device_get_address(device), dstaddr);
+               ba2str(device_get_address(device), dst_addr);
        }
-       addr_value = g_strdup(dstaddr);
 
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
-                                                       &addr_value);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &addr_value);
 
        complete = TRUE;
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN,
-                                                       &complete);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &complete);
 }
 
 static void indicate_confirm_reply_cb(DBusMessage *message, void *user_data)
@@ -1981,21 +1978,14 @@ static struct pending_op *pending_read_new(struct queue *owner_queue,
 static void read_setup_cb(DBusMessageIter *iter, void *user_data)
 {
        struct pending_op *op = user_data;
-       char dstaddr[18] = { 0 };
-       char *addr_value = NULL;
+       char dst_addr[18] = { 0 };
+       char *addr_value = dst_addr;
        uint16_t offset = 0;
 
-       ba2str(&op->bdaddr, dstaddr);
-       addr_value = g_strdup(dstaddr);
-
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
-                                                       &addr_value);
-
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
-                                                       &op->id);
-
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
-                                                       &offset);
+       ba2str(&op->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);
 }
 #endif
 
@@ -2037,23 +2027,16 @@ static void write_setup_cb(DBusMessageIter *iter, void *user_data)
        struct pending_op *op = user_data;
        DBusMessageIter array;
 #ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-       char dstaddr[18] = { 0 };
-       char *addr_value = NULL;
+       char dst_addr[18] = { 0 };
+       char *addr_value = dst_addr;
        uint16_t offset = 0;
-#endif
+       gboolean response_needed = TRUE;
 
-#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
-       ba2str(&op->bdaddr, dstaddr);
-       addr_value = g_strdup(dstaddr);
-
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING,
-                                                       &addr_value);
-
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE,
-                                                       &op->id);
-
-       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16,
-                                                       &offset);
+       ba2str(&op->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_BOOLEAN, &response_needed);
 #endif
 
        dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "y", &array);
@@ -2513,13 +2496,38 @@ static void chrc_read_cb(struct gatt_db_attribute *attrib,
 #endif
 }
 
-#ifndef TIZEN_FEATURE_BLUEZ_MODIFY
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+struct write_without_response_data {
+       unsigned int id;
+       bdaddr_t dst_addr;
+       uint8_t dst_addr_type;
+       struct iovec *iov;
+};
+#endif
+
 static void write_without_response_setup_cb(DBusMessageIter *iter,
                                                        void *user_data)
 {
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       struct write_without_response_data *write_data = user_data;
+       struct iovec *iov = write_data->iov;
+       char dst_addr[18];
+       char *addr_str = dst_addr;
+       uint16_t offset = 0;
+       gboolean response_needed = FALSE;
+#else
        struct iovec *iov = user_data;
+#endif
        DBusMessageIter array;
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       ba2str(&write_data->dst_addr, dst_addr);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &addr_str);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &write_data->id);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &offset);
+       dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &response_needed);
+#endif
+
        dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "y", &array);
        dbus_message_iter_append_fixed_array(&array, DBUS_TYPE_BYTE,
                                                &iov->iov_base, iov->iov_len);
@@ -2527,23 +2535,37 @@ static void write_without_response_setup_cb(DBusMessageIter *iter,
 }
 
 static void send_write_without_response(struct gatt_db_attribute *attrib,
+                                       struct bt_att *att,
                                        GDBusProxy *proxy, unsigned int id,
                                        const uint8_t *value, size_t len)
 {
        struct iovec iov;
        uint8_t ecode = 0;
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       struct write_without_response_data write_data;
+#endif
 
        iov.iov_base = (uint8_t *) value;
        iov.iov_len = len;
 
+#ifdef TIZEN_FEATURE_BLUEZ_MODIFY
+       write_data.id = id;
+       write_data.iov = &iov;
+       get_dst_info(att, &write_data.dst_addr, &write_data.dst_addr_type);
+
+       if (!g_dbus_proxy_method_call(proxy, "WriteValue",
+                                       write_without_response_setup_cb,
+                                       NULL, &write_data, NULL))
+               ecode = BT_ATT_ERROR_UNLIKELY;
+#else
        if (!g_dbus_proxy_method_call(proxy, "WriteValue",
                                        write_without_response_setup_cb,
                                        NULL, &iov, NULL))
                ecode = BT_ATT_ERROR_UNLIKELY;
+#endif
 
        gatt_db_attribute_write_result(attrib, id, ecode);
 }
-#endif
 
 static void chrc_write_cb(struct gatt_db_attribute *attrib,
                                        unsigned int id, uint16_t offset,
@@ -2569,7 +2591,14 @@ static void chrc_write_cb(struct gatt_db_attribute *attrib,
                return;
        }
 
-       send_write(attrib, att, chrc->proxy, chrc->pending_writes, id, value, len);
+       if (opcode == BT_ATT_OP_WRITE_CMD) {
+               send_write_without_response(attrib, att, chrc->proxy,
+                                                       id, value, len);
+               return;
+       }
+
+       send_write(attrib, att, chrc->proxy, chrc->pending_writes,
+                                                       id, value, len);
 #else
        if (chrc->props & BT_GATT_CHRC_PROP_WRITE_WITHOUT_RESP) {
                send_write_without_response(attrib, chrc->proxy, id, value,