Revert the previous SR commit for binary stabilization
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-gatt-service.c
index a79cf40..b46357d 100644 (file)
@@ -60,14 +60,15 @@ static const gchar characteristics_introspection_xml[] =
 "  <interface name='org.bluez.GattCharacteristic1'>"
 "       <method name='ReadValue'>"
 "              <arg type='s' name='address' direction='in'/>"
-"              <arg type='y' name='id' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
 "              <arg type='q' name='offset' direction='in'/>"
 "              <arg type='ay' name='Value' direction='out'/>"
 "       </method>"
 "       <method name='WriteValue'>"
 "              <arg type='s' name='address' direction='in'/>"
-"              <arg type='y' name='id' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
 "              <arg type='q' name='offset' direction='in'/>"
+"              <arg type='b' name='response_needed' direction='in'/>"
 "              <arg type='ay' name='value' direction='in'/>"
 "       </method>"
 "       <method name='StartNotify'>"
@@ -103,14 +104,15 @@ static const gchar descriptor_introspection_xml[] =
 "  <interface name='org.bluez.GattDescriptor1'>"
 "       <method name='ReadValue'>"
 "              <arg type='s' name='address' direction='in'/>"
-"              <arg type='y' name='id' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
 "              <arg type='q' name='offset' direction='in'/>"
 "              <arg type='ay' name='Value' direction='out'/>"
 "       </method>"
 "       <method name='WriteValue'>"
 "              <arg type='s' name='address' direction='in'/>"
-"              <arg type='y' name='id' direction='in'/>"
+"              <arg type='u' name='id' direction='in'/>"
 "              <arg type='q' name='offset' direction='in'/>"
+"              <arg type='b' name='response_needed' direction='in'/>"
 "              <arg type='ay' name='value' direction='in'/>"
 "       </method>"
 "  </interface>"
@@ -189,7 +191,7 @@ static gchar *app_path = NULL;
 #define GATT_CHAR_INTERFACE            "org.bluez.GattCharacteristic1"
 #define GATT_DESC_INTERFACE            "org.bluez.GattDescriptor1"
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 #define BT_HPS_OBJECT_PATH "/org/projectx/httpproxy"
 #define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
 #define PROPERTIES_CHANGED "PropertiesChanged"
@@ -234,7 +236,7 @@ static void __bt_gatt_close_gdbus_connection(void)
        BT_DBG("-");
 }
 
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
 static int __bt_send_event_to_hps(int event, GVariant *var)
 {
        GError *error = NULL;
@@ -259,7 +261,7 @@ static int __bt_send_event_to_hps(int event, GVariant *var)
                parameters = g_variant_new("(a{sv}as)", inner_builder, invalidated_builder);
                g_variant_builder_unref(invalidated_builder);
                g_variant_builder_unref(inner_builder);
-       } else if (BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED) {
+       } else if (event == BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED) {
                GVariantBuilder *inner_builder;
                GVariantBuilder *invalidated_builder;
 
@@ -273,6 +275,8 @@ static int __bt_send_event_to_hps(int event, GVariant *var)
                parameters = g_variant_new("(a{sv}as)", inner_builder, invalidated_builder);
                g_variant_builder_unref(invalidated_builder);
                g_variant_builder_unref(inner_builder);
+       } else {
+               g_varaiant_unref(var);
        }
 
        msg = g_dbus_message_new_signal(BT_HPS_OBJECT_PATH, BT_HPS_INTERFACE_NAME, PROPERTIES_CHANGED);
@@ -322,11 +326,11 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                        GVariantBuilder *svc_builder = NULL;
                        GVariantBuilder *inner_builder = NULL;
 
-                       if (register_pending_cnt > 1) {
+                       if (register_pending_cnt > 1)
                                l1 = g_slist_nth(gatt_services, len - register_pending_cnt);
-                       } else {
+                       else
                                l1 = g_slist_last(gatt_services);
-                       }
+
                        register_pending_cnt--;
 
                        if (l1 == NULL) {
@@ -632,80 +636,78 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
 
        if (g_strcmp0(method_name, "ReadValue") == 0) {
                gchar *addr = NULL;
-               guint8 req_id = 1;
+               guint req_id = 0;
                guint16 offset = 0;
                bt_gatt_read_req_t read_req = {0, };
                bt_user_info_t *user_info = NULL;
                struct gatt_req_info *req_info = NULL;
                struct gatt_service_info *svc_info = NULL;
-
-               BT_DBG("ReadValue");
-
-               g_variant_get(parameters, "(&syq)", &addr, &req_id, &offset);
+#ifdef TIZEN_FEATURE_BT_HPS
+               GVariant *param = NULL;
+#endif
 
                BT_DBG("Application path = %s", object_path);
+               BT_DBG("Sender = %s", sender);
 
-               BT_DBG("Remote Device address number = %s", addr);
-               BT_DBG("Request id = %d, Offset = %d", req_id, offset);
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info == NULL) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
 
-               BT_DBG("Sender = %s", sender);
+               svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
+               if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
+
+               g_variant_get(parameters, "(&suq)", &addr, &req_id, &offset);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
 
-               read_req.att_handle = g_strdup(object_path);
-               read_req.address = g_strdup(addr);
+               read_req.att_handle = (char *)object_path;
+               read_req.address = addr;
                read_req.req_id = req_id;
                read_req.offset = offset;
-               svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
-               if (svc_info != NULL) {
-                       read_req.service_handle = g_strdup(svc_info->serv_path);
-                       user_info = _bt_get_user_data(BT_COMMON);
-#ifdef HPS_FEATURE
-                       GVariant *param = NULL;
-#endif
+               read_req.service_handle = svc_info->serv_path;
 
-                       /* Store requets information */
-                       req_info = g_new0(struct gatt_req_info, 1);
-                       req_info->attr_path = g_strdup(object_path);
-                       req_info->svc_path = g_strdup(read_req.service_handle);
-                       req_info->request_id = req_id;
-                       req_info->offset = offset;
-                       req_info->context = invocation;
-                       gatt_requests = g_slist_append(gatt_requests, req_info);
+               /* Store requets information */
+               req_info = g_new0(struct gatt_req_info, 1);
+               req_info->attr_path = g_strdup(object_path);
+               req_info->svc_path = g_strdup(read_req.service_handle);
+               req_info->request_id = req_id;
+               req_info->offset = offset;
+               req_info->context = invocation;
+               gatt_requests = g_slist_append(gatt_requests, req_info);
 
-                       if (user_info != NULL) {
-                               _bt_common_event_cb(
-                                       BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
+               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
                                        BLUETOOTH_ERROR_NONE, &read_req,
                                        user_info->cb, user_info->user_data);
-                       }
-#ifdef HPS_FEATURE
-                       param = g_variant_new("(sssyq)",
-                                       read_req.att_handle,
-                                       read_req.service_handle,
-                                       read_req.address,
-                                       read_req.req_id,
-                                       read_req.offset);
-                       __bt_send_event_to_hps(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED, param);
+
+#ifdef TIZEN_FEATURE_BT_HPS
+               param = g_variant_new("(sssyq)",
+                               read_req.att_handle,
+                               read_req.service_handle,
+                               read_req.address,
+                               read_req.req_id,
+                               read_req.offset);
+               __bt_send_event_to_hps(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED, param);
 #endif
-               }
 
-               if (read_req.att_handle)
-                       g_free(read_req.att_handle);
-               if (read_req.address)
-                       g_free(read_req.address);
-               if (read_req.service_handle)
-                       g_free(read_req.service_handle);
                return;
        } else if (g_strcmp0(method_name, "WriteValue") == 0) {
                GVariant *var = NULL;
                gchar *addr = NULL;
-               guint8 req_id = 0;
+               guint req_id = 0;
                guint16 offset = 0;
+               gboolean response_needed = FALSE;
                bt_gatt_value_change_t value_change = {0, };
                bt_user_info_t *user_info = NULL;
                int len = 0;
                struct gatt_service_info *svc_info = NULL;
                struct gatt_req_info *req_info = NULL;
-#ifdef HPS_FEATURE
+#ifdef TIZEN_FEATURE_BT_HPS
                GVariant *param = NULL;
 #endif
 
@@ -713,56 +715,69 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                BT_DBG("Application path = %s", object_path);
                BT_DBG("Sender = %s", sender);
 
-               g_variant_get(parameters, "(&syq@ay)", &addr, &req_id, &offset, &var);
+               g_variant_get(parameters, "(&suqb@ay)",
+                               &addr, &req_id, &offset, &response_needed, &var);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
+
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (!user_info) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_variant_unref(var);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
+                       return;
+               }
 
-               value_change.att_handle = g_strdup(object_path);
-               value_change.address = g_strdup(addr);
                svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
                if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
                        g_variant_unref(var);
-                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
                        return;
                }
 
-               value_change.service_handle = g_strdup(svc_info->serv_path);
+               value_change.att_handle = (char *)object_path;
+               value_change.address = addr;
+               value_change.service_handle = svc_info->serv_path;
                value_change.offset = offset;
                value_change.req_id = req_id;
+               value_change.response_needed = response_needed;
 
                len = g_variant_get_size(var);
                if (len > 0) {
                        char *data;
 
-                       value_change.att_value = (guint8 *)malloc(len);
-                       if (!value_change.att_value) {
-                               BT_ERR("att_value is NULL");
-                               g_variant_unref(var);
-                               g_dbus_method_invocation_return_value(invocation, NULL);
-                               return;
-                       }
+                       value_change.att_value = (guint8 *)g_malloc(len);
 
                        data = (char *)g_variant_get_data(var);
                        memcpy(value_change.att_value, data, len);
                }
-
                value_change.val_len = len;
 
-               /* Store requets information */
-               req_info = g_new0(struct gatt_req_info, 1);
-               req_info->attr_path = g_strdup(object_path);
-               req_info->svc_path = g_strdup(value_change.service_handle);
-               req_info->request_id = req_id;
-               req_info->offset = offset;
-               req_info->context = invocation;
-               gatt_requests = g_slist_append(gatt_requests, req_info);
-
-               user_info = _bt_get_user_data(BT_COMMON);
-               if (user_info != NULL) {
-                       _bt_common_event_cb(
-                               BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
-                               BLUETOOTH_ERROR_NONE, &value_change,
-                               user_info->cb, user_info->user_data);
+               if (response_needed) {
+                       /* Store requets information */
+                       req_info = g_new0(struct gatt_req_info, 1);
+                       req_info->attr_path = g_strdup(object_path);
+                       req_info->svc_path = g_strdup(value_change.service_handle);
+                       req_info->request_id = req_id;
+                       req_info->offset = offset;
+                       req_info->context = invocation;
+                       gatt_requests = g_slist_append(gatt_requests, req_info);
+               } else {
+                       g_object_unref(invocation);
                }
-#ifdef HPS_FEATURE
+
+               _bt_common_event_cb(
+                       BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
+                       BLUETOOTH_ERROR_NONE, &value_change,
+                       user_info->cb, user_info->user_data);
+
+#ifdef TIZEN_FEATURE_BT_HPS
                if (len > 0) {
                        gchar *svc_path;
                        svc_path = g_strdup(svc_info->serv_path);
@@ -778,6 +793,8 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                g_free(svc_path);
                }
 #endif
+
+               g_free(value_change.att_value);
                g_variant_unref(var);
                return;
        } else if (g_strcmp0(method_name, "StartNotify") == 0) {
@@ -789,8 +806,8 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                        struct gatt_service_info *svc_info = NULL;
                        svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
                        if (svc_info) {
-                               notify_change.service_handle = g_strdup(svc_info->serv_path);
-                               notify_change.att_handle = g_strdup(object_path);
+                               notify_change.service_handle = svc_info->serv_path;
+                               notify_change.att_handle = (char *)object_path;
                                notify_change.att_notify = TRUE;
                                _bt_common_event_cb(
                                        BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
@@ -807,8 +824,8 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                        struct gatt_service_info *svc_info = NULL;
                        svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
                        if (svc_info) {
-                               notify_change.service_handle = g_strdup(svc_info->serv_path);
-                               notify_change.att_handle = g_strdup(object_path);
+                               notify_change.service_handle = svc_info->serv_path;
+                               notify_change.att_handle = (char *)object_path;
                                notify_change.att_notify = FALSE;
                                _bt_common_event_cb(
                                        BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
@@ -820,7 +837,7 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                gchar *addr = NULL;
                bt_gatt_indicate_confirm_t confirm = {0, };
                bt_user_info_t *user_info = NULL;
-               gboolean complete = 0;
+               gboolean complete = FALSE;
                struct gatt_service_info *svc_info = NULL;
 
                BT_DBG("IndicateConfirm");
@@ -828,17 +845,17 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                BT_DBG("Sender = %s", sender);
 
                g_variant_get(parameters, "(&sb)", &addr, &complete);
-
                BT_DBG("Remote Device address number = %s", addr);
-               confirm.att_handle = g_strdup(object_path);
-               confirm.address = g_strdup(addr);
+
+               confirm.att_handle = (char *)object_path;
+               confirm.address = addr;
                confirm.complete = complete;
 
                svc_info = __bt_gatt_find_gatt_service_from_char(object_path);
                if (svc_info != NULL) {
-                       confirm.service_handle = g_strdup(svc_info->serv_path);
-                       user_info = _bt_get_user_data(BT_COMMON);
+                       confirm.service_handle = svc_info->serv_path;
 
+                       user_info = _bt_get_user_data(BT_COMMON);
                        if (user_info != NULL) {
                                _bt_common_event_cb(
                                        BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_COMPLETED,
@@ -847,6 +864,7 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                        }
                }
        }
+
        g_dbus_method_invocation_return_value(invocation, NULL);
 }
 
@@ -861,62 +879,61 @@ static void __bt_gatt_desc_method_call(GDBusConnection *connection,
 {
        if (g_strcmp0(method_name, "ReadValue") == 0) {
                gchar *addr = NULL;
-               guint8 req_id = 1;
+               guint req_id = 0;
                guint16 offset = 0;
                bt_gatt_read_req_t read_req = {0, };
                bt_user_info_t *user_info = NULL;
                struct gatt_req_info *req_info = NULL;
                struct gatt_service_info *svc_info = NULL;
-               BT_DBG("ReadValue");
-
-               g_variant_get(parameters, "(&syq)", &addr, &req_id, &offset);
 
+               BT_DBG("ReadValue");
                BT_DBG("Application path = %s", object_path);
+               BT_DBG("Sender = %s", sender);
 
-               BT_DBG("Remote Device address number = %s", addr);
-               BT_DBG("Request id = %d, Offset = %d", req_id, offset);
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info == NULL) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
 
-               BT_DBG("Sender = %s", sender);
+               svc_info = __bt_gatt_find_gatt_service_from_desc(object_path);
+               if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
+                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       return;
+               }
+
+               g_variant_get(parameters, "(&suq)", &addr, &req_id, &offset);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
 
-               read_req.att_handle = g_strdup(object_path);
-               read_req.address = g_strdup(addr);
+               read_req.att_handle = (char *)object_path;
+               read_req.address = addr;
                read_req.req_id = req_id;
                read_req.offset = offset;
-               svc_info = __bt_gatt_find_gatt_service_from_desc(object_path);
-               if (svc_info != NULL) {
-                       read_req.service_handle = g_strdup(svc_info->serv_path);
-                       user_info = _bt_get_user_data(BT_COMMON);
-
-                       /* Store requets information */
-                       req_info = g_new0(struct gatt_req_info, 1);
-                       req_info->attr_path = g_strdup(object_path);
-                       req_info->svc_path = g_strdup(read_req.service_handle);
-                       req_info->request_id = req_id;
-                       req_info->offset = offset;
-                       req_info->context = invocation;
-                       gatt_requests = g_slist_append(gatt_requests, req_info);
+               read_req.service_handle = svc_info->serv_path;
 
-                       if (user_info != NULL) {
-                               _bt_common_event_cb(
-                                       BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
-                                       BLUETOOTH_ERROR_NONE, &read_req,
-                                       user_info->cb, user_info->user_data);
-                       }
-               }
+               /* Store requets information */
+               req_info = g_new0(struct gatt_req_info, 1);
+               req_info->attr_path = g_strdup(object_path);
+               req_info->svc_path = g_strdup(read_req.service_handle);
+               req_info->request_id = req_id;
+               req_info->offset = offset;
+               req_info->context = invocation;
+               gatt_requests = g_slist_append(gatt_requests, req_info);
 
-               if (read_req.att_handle)
-                       g_free(read_req.att_handle);
-               if (read_req.address)
-                       g_free(read_req.address);
-               if (read_req.service_handle)
-                       g_free(read_req.service_handle);
+               _bt_common_event_cb(
+                               BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
+                               BLUETOOTH_ERROR_NONE, &read_req,
+                               user_info->cb, user_info->user_data);
 
                return;
        } else if (g_strcmp0(method_name, "WriteValue") == 0) {
                GVariant *var = NULL;
                gchar *addr = NULL;
-               guint8 req_id = 0;
+               guint req_id = 0;
                guint16 offset = 0;
+               gboolean response_needed = FALSE;
                bt_gatt_value_change_t value_change = {0, };
                bt_user_info_t *user_info = NULL;
                int len = 0;
@@ -927,58 +944,72 @@ static void __bt_gatt_desc_method_call(GDBusConnection *connection,
                BT_DBG("Application path = %s", object_path);
                BT_DBG("Sender = %s", sender);
 
-               g_variant_get(parameters, "(&syq@ay)", &addr, &req_id, &offset, &var);
+               g_variant_get(parameters, "(&suqb@ay)",
+                               &addr, &req_id, &offset, &response_needed, &var);
+               BT_DBG("Request id = %u, Offset = %u", req_id, offset);
+
+               user_info = _bt_get_user_data(BT_COMMON);
+               if (user_info == NULL) {
+                       BT_INFO("No callback is set for %s", object_path);
+                       g_variant_unref(var);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
+                       return;
+               }
 
-               value_change.att_handle = g_strdup(object_path);
-               value_change.address = g_strdup(addr);
                svc_info = __bt_gatt_find_gatt_service_from_desc(object_path);
                if (svc_info == NULL) {
+                       BT_ERR("Coudn't find service for %s", object_path);
                        g_variant_unref(var);
-                       g_dbus_method_invocation_return_value(invocation, NULL);
+                       if (response_needed)
+                               g_dbus_method_invocation_return_value(invocation, NULL);
+                       else
+                               g_object_unref(invocation);
                        return;
                }
 
-               value_change.service_handle = g_strdup(svc_info->serv_path);
+               value_change.att_handle = (char *)object_path;
+               value_change.address = addr;
+               value_change.service_handle = svc_info->serv_path;
                value_change.offset = offset;
                value_change.req_id = req_id;
+               value_change.response_needed = response_needed;
 
                len = g_variant_get_size(var);
                if (len > 0) {
                        char *data;
 
-                       value_change.att_value = (guint8 *)malloc(len);
-                       if (!value_change.att_value) {
-                               BT_ERR("att_value is NULL");
-                               g_variant_unref(var);
-                               g_dbus_method_invocation_return_value(invocation, NULL);
-                               return;
-                       }
+                       value_change.att_value = (guint8 *)g_malloc(len);
+
                        data = (char *)g_variant_get_data(var);
                        memcpy(value_change.att_value, data, len);
                }
-               g_variant_unref(var);
-
                value_change.val_len = len;
 
-               /* Store requets information */
-               req_info = g_new0(struct gatt_req_info, 1);
-               req_info->attr_path = g_strdup(object_path);
-               req_info->svc_path = g_strdup(value_change.service_handle);
-               req_info->request_id = req_id;
-               req_info->offset = offset;
-               req_info->context = invocation;
-               gatt_requests = g_slist_append(gatt_requests, req_info);
-
-               user_info = _bt_get_user_data(BT_COMMON);
-               if (user_info != NULL) {
-                       _bt_common_event_cb(
-                               BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
-                               BLUETOOTH_ERROR_NONE, &value_change,
-                               user_info->cb, user_info->user_data);
+               if (response_needed) {
+                       /* Store requets information */
+                       req_info = g_new0(struct gatt_req_info, 1);
+                       req_info->attr_path = g_strdup(object_path);
+                       req_info->svc_path = g_strdup(value_change.service_handle);
+                       req_info->request_id = req_id;
+                       req_info->offset = offset;
+                       req_info->context = invocation;
+                       gatt_requests = g_slist_append(gatt_requests, req_info);
+               } else {
+                       g_object_unref(invocation);
                }
+
+               _bt_common_event_cb(
+                       BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
+                       BLUETOOTH_ERROR_NONE, &value_change,
+                       user_info->cb, user_info->user_data);
+
+               g_free(value_change.att_value);
+               g_variant_unref(var);
                return;
        }
-       g_dbus_method_invocation_return_value(invocation, NULL);
 }
 
 gboolean __bt_gatt_emit_interface_removed(gchar *object_path, gchar *interface)
@@ -1134,9 +1165,8 @@ static struct gatt_req_info *__bt_gatt_find_request_info(guint request_id)
        for (l = gatt_requests; l != NULL; l = l->next) {
                struct gatt_req_info *req_info = l->data;
 
-               if (req_info && req_info->request_id == request_id) {
+               if (req_info && req_info->request_id == request_id)
                        return req_info;
-               }
        }
        BT_ERR("Gatt Request not found");
        return NULL;
@@ -1397,6 +1427,8 @@ void register_application_cb(GObject *object, GAsyncResult *res, gpointer user_d
                                                error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
@@ -1420,6 +1452,8 @@ void unregister_application_cb(GObject *object, GAsyncResult *res,
                                        error->code, error->message);
                        g_clear_error(&error);
                }
+       } else {
+               g_variant_unref(result);
        }
 }
 
@@ -1486,6 +1520,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
                                        NULL, /* GDBusAuthObserver */
                                        NULL,
                                        &err);
+               g_free(address);
                if (!g_conn) {
                        if (err) {
                                BT_ERR("Unable to connect to dbus: %s", err->message);
@@ -1509,7 +1544,7 @@ static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
                                        NULL, /* GDBusAuthObserver */
                                        NULL,
                                        &err);
-
+               g_free(address);
                if (!local_system_gconn) {
                        BT_ERR("Unable to connect to dbus: %s", err->message);
                        g_clear_error(&err);
@@ -1553,7 +1588,6 @@ BT_EXPORT_API int bluetooth_gatt_init(void)
        /* Register ObjectManager interface */
        node_info = __bt_gatt_create_method_node_info(
                                        manager_introspection_xml);
-
        if (node_info == NULL) {
                BT_ERR("failed to get node info");
                goto failed;
@@ -1567,7 +1601,7 @@ BT_EXPORT_API int bluetooth_gatt_init(void)
                                                        &manager_interface_vtable,
                                                        NULL, NULL, &error);
        }
-
+       g_dbus_node_info_unref(node_info);
        if (manager_id == 0) {
                BT_ERR("failed to register: %s", error->message);
                g_error_free(error);
@@ -1648,7 +1682,6 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
 
        node_info = __bt_gatt_create_method_node_info(
                                        service_introspection_xml);
-
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1659,6 +1692,7 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
                                        node_info->interfaces[0],
                                        &serv_interface_vtable,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -1752,7 +1786,6 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
 
        node_info = __bt_gatt_create_method_node_info(
                                        characteristics_introspection_xml);
-
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1763,6 +1796,7 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
                                        node_info->interfaces[0],
                                        &char_interface_vtable,
                                        NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -1789,9 +1823,9 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
        char_info->char_id = object_id;
        char_info->char_uuid = g_strdup(char_uuid);
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                char_info->char_flags[i] = char_flags[i];
-               }
+
 
        char_info->flags_length = flag_count;
 
@@ -1807,9 +1841,8 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
 
        builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                g_variant_builder_add(builder2, "s", char_flags[i]);
-       }
 
        flags_val = g_variant_new("as", builder2);
        g_variant_builder_add(inner_builder, "{sv}", "Flags",
@@ -1888,9 +1921,8 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristic_value(
 
        builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
 
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(builder1, "y", char_value[i]);
-       }
 
        char_val = g_variant_new("ay", builder1);
                g_variant_builder_add(inner_builder, "{sv}", "Value", char_val);
@@ -1955,7 +1987,6 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
 
        node_info = __bt_gatt_create_method_node_info(
                                        descriptor_introspection_xml);
-
        if (node_info == NULL) {
                g_strfreev(line_argv);
                g_free(serv_path);
@@ -1969,6 +2000,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
                                node_info->interfaces[0],
                                &desc_interface_vtable,
                                NULL, NULL, &error);
+       g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
                BT_ERR("failed to register: %s", error->message);
@@ -1988,9 +2020,8 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        desc_info->desc_id = object_id;
        desc_info->desc_uuid = g_strdup(desc_uuid);
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                desc_info->desc_flags[i] = desc_flags[i];
-               }
 
        desc_info->flags_length = flag_count;
 
@@ -2006,9 +2037,8 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
 
        builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
-       for (i = 0; i < flag_count; i++) {
+       for (i = 0; i < flag_count; i++)
                g_variant_builder_add(builder2, "s", desc_flags[i]);
-       }
 
        flags_val = g_variant_new("as", builder2);
        g_variant_builder_add(inner_builder, "{sv}", "Flags",
@@ -2032,6 +2062,7 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
        g_strfreev(line_argv);
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
+       g_variant_builder_unref(builder2);
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -2080,9 +2111,9 @@ BT_EXPORT_API int bluetooth_gatt_set_descriptor_value(
 
        builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
 
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(builder1, "y", desc_value[i]);
-       }
+
        desc_val = g_variant_new("ay", builder1);
        g_variant_builder_add(inner_builder, "{sv}", "Value", desc_val);
 
@@ -2202,7 +2233,7 @@ BT_EXPORT_API int bluetooth_gatt_delete_services(void)
                        if (bluetooth_gatt_unregister_service(info->serv_path)
                                        != BLUETOOTH_ERROR_NONE) {
                                error = BLUETOOTH_ERROR_INTERNAL;
-                               BT_DBG(" Error in removing service %s \n",
+                               BT_ERR("Error in removing service %s \n",
                                                 info->serv_path);
                        }
                }
@@ -2246,16 +2277,18 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
                return BLUETOOTH_ERROR_INTERNAL;
        }
 
+/* Fix the svace issue : 185689
        outer_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+*/
        invalidated_builder = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
        inner_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
-       for (i = 0; i < value_length; i++) {
+       for (i = 0; i < value_length; i++)
                g_variant_builder_add(inner_builder, "y", char_value[i]);
-       }
 
        update_value = g_variant_new("ay", inner_builder);
 
+
        outer_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
        g_variant_builder_add(outer_builder, "{sv}", "Value",
                                        update_value);
@@ -2296,9 +2329,8 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
 
                char_info->char_value = (char *)realloc(char_info->char_value, value_length);
                if (char_info->char_value) {
-                       for (i = 0; i < value_length; i++) {
+                       for (i = 0; i < value_length; i++)
                                char_info->char_value[i] = char_value[i];
-                       }
                }
        }
 
@@ -2372,7 +2404,7 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
 
        err = __bt_gatt_unregister_service(svc_path);
        if (err != BLUETOOTH_ERROR_NONE) {
-               BT_DBG("Could not unregister application");
+               BT_ERR("Could not unregister application");
                return err;
        }
 
@@ -2432,9 +2464,8 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
        }
 
        ret = g_dbus_connection_unregister_object(g_conn, svc_info->prop_id);
-       if (ret) {
+       if (ret)
                BT_DBG("Unregistered the service on properties interface");
-       }
 
        /* list remove & free */
        gatt_services = g_slist_remove(gatt_services, svc_info);
@@ -2442,11 +2473,10 @@ BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
 
        new_service = FALSE;
 
-       if (gatt_services == NULL) {
+       if (gatt_services == NULL)
                serv_id = 1;
-       } else if (gatt_services->next == NULL) {
+       else if (gatt_services->next == NULL)
                serv_id--;
-       }
 
        return err;
 }
@@ -2463,37 +2493,17 @@ BT_EXPORT_API int bluetooth_gatt_send_response(int request_id, guint req_type,
        }
 
        req_info = __bt_gatt_find_request_info(request_id);
+       if (req_info == NULL) {
+               BT_ERR("Coundn't find request id [%d]", request_id);
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
 
-       if (req_info) {
-               if (resp_state != BLUETOOTH_ERROR_NONE) {
-                       g_dbus_method_invocation_return_dbus_error(req_info->context,
-                                               "org.bluez.Error.Failed", "Application Error");
-
-                       gatt_requests = g_slist_remove(gatt_requests, req_info);
+       if (resp_state != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("resp_state is 0x%X", resp_state);
 
-                       req_info->context = NULL;
-                       if (req_info->attr_path)
-                               g_free(req_info->attr_path);
-                       if (req_info->svc_path)
-                               g_free(req_info->svc_path);
-                       g_free(req_info);
+               g_dbus_method_invocation_return_dbus_error(req_info->context,
+                               "org.bluez.Error.Failed", "Application Error");
 
-                       return BLUETOOTH_ERROR_NONE;
-               }
-               if (req_type == BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ) {
-                       int i;
-                       GVariantBuilder *inner_builder = NULL;
-                       inner_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
-                       if (value_length > 0 && value != NULL) {
-                               for (i = 0; i < value_length; i++)
-                                       g_variant_builder_add(inner_builder, "y", value[i]);
-                       }
-                       g_dbus_method_invocation_return_value(req_info->context,
-                                               g_variant_new("(ay)", inner_builder));
-                       g_variant_builder_unref(inner_builder);
-               } else {
-                       g_dbus_method_invocation_return_value(req_info->context, NULL);
-               }
                gatt_requests = g_slist_remove(gatt_requests, req_info);
 
                req_info->context = NULL;
@@ -2502,9 +2512,32 @@ BT_EXPORT_API int bluetooth_gatt_send_response(int request_id, guint req_type,
                if (req_info->svc_path)
                        g_free(req_info->svc_path);
                g_free(req_info);
+
+               return BLUETOOTH_ERROR_NONE;
+       }
+
+       if (req_type == BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ) {
+               int i;
+               GVariantBuilder *inner_builder = NULL;
+               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("ay"));
+               if (value_length > 0 && value != NULL) {
+                       for (i = 0; i < value_length; i++)
+                               g_variant_builder_add(inner_builder, "y", value[i]);
+               }
+               g_dbus_method_invocation_return_value(req_info->context,
+                               g_variant_new("(ay)", inner_builder));
+               g_variant_builder_unref(inner_builder);
        } else {
-               return BLUETOOTH_ERROR_INTERNAL;
+               g_dbus_method_invocation_return_value(req_info->context, NULL);
        }
+       gatt_requests = g_slist_remove(gatt_requests, req_info);
+
+       req_info->context = NULL;
+       if (req_info->attr_path)
+               g_free(req_info->attr_path);
+       if (req_info->svc_path)
+               g_free(req_info->svc_path);
+       g_free(req_info);
 
        return BLUETOOTH_ERROR_NONE;
 }