Merge "Revert "Fix incorrect interface name and improve dbus policy"" into tizen
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-gatt-service.c
index c3bfc49..b912965 100644 (file)
 #include<unistd.h>
 #include<stdint.h>
 #include<stdbool.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <gio/gunixfdlist.h>
 
 #include "bt-common.h"
+/* TODO_40 : 4.0 merge - Need to check why includes bt-event-handler.h */
+#include "bt-event-handler.h"
 #include "bt-internal-types.h"
 
+
+#include "bluetooth-gatt-server-api.h"
+#include "bt-request-sender.h"
+#define BT_GATT_ATT_UUID_LEN_MAX 50
+#define BT_GATT_SERVER_DBUS_NAME_LEN_MAX 50
+
+static GSList *gatt_characteristic_server_notify_list = NULL;;
+
+/* Common defintions to follow , applicable for both
+   GATT_DIRECT and RELAY */
+
+
+#define NUMBER_OF_FLAGS 10
+
+
+int bluetooth_gatt_convert_prop2string(
+                       bt_gatt_characteristic_property_t properties,
+                       char *char_properties[])
+{
+       int flag_count = 0;
+
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_BROADCAST) {
+               char_properties[flag_count] = g_strdup("broadcast");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE_NO_RESPONSE) {
+               char_properties[flag_count] = g_strdup("write-without-response");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE) {
+               char_properties[flag_count] = g_strdup("write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY) {
+               char_properties[flag_count] = g_strdup("notify");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_INDICATE) {
+               char_properties[flag_count] = g_strdup("indicate");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_SIGNED_WRITE) {
+               char_properties[flag_count] = g_strdup("authenticated-signed-writes");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_RELIABLE_WRITE) {
+               char_properties[flag_count] = g_strdup("reliable-write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITABLE_AUXILIARIES) {
+               char_properties[flag_count] = g_strdup("writable-auxiliaries");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
+               flag_count++;
+       }
+
+       if (flag_count == 0) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+
+       return flag_count;
+}
+
+int bluetooth_gatt_convert_perm2string(
+                       bt_gatt_permission_t properties,
+                       char *char_properties[])
+{
+       int flag_count = 0;
+
+       if (properties & BLUETOOTH_GATT_PERMISSION_READ) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_WRITE) {
+               char_properties[flag_count] = g_strdup("write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-write");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
+               flag_count++;
+       }
+       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
+               flag_count++;
+       }
+
+       if (flag_count == 0) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+
+       return flag_count;
+}
+
+
 #define NUMBER_OF_FLAGS        10
 
 GDBusConnection *g_conn;
@@ -217,6 +344,93 @@ static struct gatt_desc_info *__bt_gatt_find_gatt_desc_info(
 
 static struct gatt_req_info *__bt_gatt_find_request_info(guint request_id);
 
+
+
+typedef struct {
+       int write_fd;
+       int relpy_fd;
+       int mtu;
+       int att_hand;
+       char *path ;
+} bluetooth_gatt_acquire_notify_info_t;
+
+
+static int bluetooth_get_characteristic_fd(int att_handle , char *path)
+{
+       GSList *l;
+
+       BT_INFO("request found  path [%s] att_handle [ %d]", path, att_handle);
+       for (l = gatt_characteristic_server_notify_list; l != NULL; l = l->next) {
+               bluetooth_gatt_acquire_notify_info_t *info = l->data;
+               BT_INFO(" sid [ %d]" , info->att_hand);
+               if (info->att_hand == att_handle)
+                       return info->write_fd;
+       }
+       return -1;
+}
+
+static bluetooth_gatt_acquire_notify_info_t * bluetooth_get_characteristic_info_from_path(int att_handle)
+{
+       GSList *l;
+
+       BT_INFO("request found  att_handle [ %d]", att_handle);
+       for (l = gatt_characteristic_server_notify_list; l != NULL; l = l->next) {
+               bluetooth_gatt_acquire_notify_info_t *info = l->data;
+               BT_INFO(" sid [ %d]" , info->att_hand);
+               if (info->att_hand == att_handle)
+                       return info;
+       }
+       return NULL;
+}
+
+
+static void bluetooth_characteristic_info_free(bluetooth_gatt_acquire_notify_info_t *chr_info)
+{
+               g_free(chr_info);
+}
+
+static gboolean bluetooth_gatt_write_channel_watch_cb(GIOChannel *gio,
+                                       GIOCondition cond, gpointer data)
+{
+       bluetooth_gatt_acquire_notify_info_t *chr_info = (bluetooth_gatt_acquire_notify_info_t *)data;
+
+       if (!chr_info)
+               return FALSE;
+
+       if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
+               BT_ERR("Error : GIOCondition %d, []", cond);;
+               g_io_channel_shutdown(gio, TRUE, NULL);
+               g_io_channel_unref(gio);
+
+               gatt_characteristic_server_notify_list = g_slist_remove(gatt_characteristic_server_notify_list, chr_info);
+               bluetooth_characteristic_info_free(chr_info);
+
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+static int bluetooth_gatt_write_characteristics_value_to_fd_(
+                        int fd, const guint8 *value, int length,
+                       gpointer user_data)
+{
+
+               int written;
+               int att_result = BLUETOOTH_ERROR_NONE;
+
+               BT_CHECK_PARAMETER(value, return);
+
+               written = write(fd, value, length);
+               if (written != length) {
+                       att_result = BLUETOOTH_ERROR_INTERNAL;
+                       BT_INFO("write data failed  %d is ", written);
+               } else
+                  BT_INFO("write data %s is sucess ", value);
+
+               return att_result;
+}
+
 static void __bt_gatt_close_gdbus_connection(void)
 {
        GError *err = NULL;
@@ -270,7 +484,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;
 
@@ -284,6 +498,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);
@@ -413,6 +629,7 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                        if (l1 == NULL) {
                                BT_ERR("gatt service list is NULL");
                                g_dbus_method_invocation_return_value(invocation, NULL);
+                               g_variant_builder_unref(builder);
                                return;
                        }
 
@@ -420,6 +637,7 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                        if (serv_info == NULL) {
                                BT_ERR("service info value is NULL");
                                g_dbus_method_invocation_return_value(invocation, NULL);
+                               g_variant_builder_unref(builder);
                                return;
                        }
 
@@ -656,6 +874,7 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                                                g_variant_new(
                                                "(a{oa{sa{sv}}})",
                                                builder));
+               g_variant_builder_unref(builder);
        }
 }
 
@@ -758,10 +977,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                req_info->context = invocation;
                gatt_requests = g_slist_append(gatt_requests, req_info);
 
-               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED,
-                                       BLUETOOTH_ERROR_NONE, &read_req,
-                                       user_info->cb, user_info->user_data);
-
 #if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
                param = g_variant_new("(sssyq)",
                                read_req.att_handle,
@@ -776,6 +991,10 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_READ_REQUESTED, param);
 #endif
 #endif
+
+               _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;
@@ -853,11 +1072,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                        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);
-
 #if defined(TIZEN_FEATURE_BT_HPS) || defined(TIZEN_FEATURE_BT_OTP)
                if (len > 0) {
                        gchar *svc_path;
@@ -880,6 +1094,11 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                }
 #endif
 
+               _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;
@@ -898,10 +1117,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                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,
-                                       BLUETOOTH_ERROR_NONE, &notify_change,
-                                       user_info->cb, user_info->user_data);
 #if TIZEN_FEATURE_BT_OTP
                                param = g_variant_new("(ssb)",
                                notify_change.att_handle,
@@ -909,8 +1124,14 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                notify_change.att_notify);
                                __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, param);
 #endif
+                               _bt_common_event_cb(
+                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
+                                       BLUETOOTH_ERROR_NONE, &notify_change,
+                                       user_info->cb, user_info->user_data);
                        }
                }
+               g_object_unref(invocation);
+               return;
        } else if (g_strcmp0(method_name, "StopNotify") == 0) {
                bt_user_info_t *user_info = NULL;
                bt_gatt_char_notify_change_t notify_change = {0, };
@@ -926,10 +1147,6 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                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,
-                                       BLUETOOTH_ERROR_NONE, &notify_change,
-                                       user_info->cb, user_info->user_data);
 #if TIZEN_FEATURE_BT_OTP
                                param = g_variant_new("(ssb)",
                                notify_change.att_handle,
@@ -937,8 +1154,14 @@ static void __bt_gatt_char_method_call(GDBusConnection *connection,
                                notify_change.att_notify);
                                __bt_send_event_to_otp(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED, param);
 #endif
+                               _bt_common_event_cb(
+                                       BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
+                                       BLUETOOTH_ERROR_NONE, &notify_change,
+                                       user_info->cb, user_info->user_data);
                        }
                }
+               g_object_unref(invocation);
+               return;
        } else if (g_strcmp0(method_name, "IndicateConfirm") == 0) {
                gchar *addr = NULL;
                bt_gatt_indicate_confirm_t confirm = {0, };
@@ -1152,24 +1375,28 @@ static const GDBusInterfaceVTable desc_interface_vtable = {
        __bt_gatt_desc_method_call,
        NULL,
        NULL,
+       { 0 }
 };
 
 static const GDBusInterfaceVTable char_interface_vtable = {
        __bt_gatt_char_method_call,
        NULL,
        NULL,
+       { 0 }
 };
 
 static const GDBusInterfaceVTable serv_interface_vtable = {
        NULL,
        NULL,
        NULL,
+       { 0 }
 };
 
 static const GDBusInterfaceVTable manager_interface_vtable = {
        __bt_gatt_manager_method_call,
        NULL,
-       NULL
+       NULL,
+       { 0 }
 };
 
 static GDBusNodeInfo *__bt_gatt_create_method_node_info(
@@ -1321,122 +1548,17 @@ static GDBusProxy *__bt_gatt_gdbus_get_manager_proxy(const gchar *service,
                                path, interface);
 }
 
-int bluetooth_gatt_convert_prop2string(
-                       bt_gatt_characteristic_property_t properties,
-                       char *char_properties[])
+
+static void __bt_gatt_set_service_state(const char *service_path,
+                       gboolean state)
 {
-       int flag_count = 0;
+       struct gatt_service_info *svc_info = NULL;
+       svc_info = __bt_gatt_find_gatt_service_info(service_path);
 
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_BROADCAST) {
-               char_properties[flag_count] = g_strdup("broadcast");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_READ) {
-               char_properties[flag_count] = g_strdup("read");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE_NO_RESPONSE) {
-               char_properties[flag_count] = g_strdup("write-without-response");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITE) {
-               char_properties[flag_count] = g_strdup("write");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_NOTIFY) {
-               char_properties[flag_count] = g_strdup("notify");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_INDICATE) {
-               char_properties[flag_count] = g_strdup("indicate");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_SIGNED_WRITE) {
-               char_properties[flag_count] = g_strdup("authenticated-signed-writes");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_RELIABLE_WRITE) {
-               char_properties[flag_count] = g_strdup("reliable-write");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_WRITABLE_AUXILIARIES) {
-               char_properties[flag_count] = g_strdup("writable-auxiliaries");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_READ) {
-               char_properties[flag_count] = g_strdup("encrypt-read");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_WRITE) {
-               char_properties[flag_count] = g_strdup("encrypt-write");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_READ) {
-               char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_WRITE) {
-               char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
-               flag_count++;
-       }
-
-       if (flag_count == 0) {
-               char_properties[flag_count] = g_strdup("read");
-               flag_count++;
-       }
-
-       return flag_count;
-}
-
-int bluetooth_gatt_convert_perm2string(
-                       bt_gatt_permission_t properties,
-                       char *char_properties[])
-{
-       int flag_count = 0;
-
-       if (properties & BLUETOOTH_GATT_PERMISSION_READ) {
-               char_properties[flag_count] = g_strdup("read");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_PERMISSION_WRITE) {
-               char_properties[flag_count] = g_strdup("write");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_READ) {
-               char_properties[flag_count] = g_strdup("encrypt-read");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_WRITE) {
-               char_properties[flag_count] = g_strdup("encrypt-write");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_READ) {
-               char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
-               flag_count++;
-       }
-       if (properties & BLUETOOTH_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_WRITE) {
-               char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
-               flag_count++;
-       }
-
-       if (flag_count == 0) {
-               char_properties[flag_count] = g_strdup("read");
-               flag_count++;
-       }
-
-       return flag_count;
-}
-
-static void __bt_gatt_set_service_state(const char *service_path,
-                       gboolean state)
-{
-       struct gatt_service_info *svc_info = NULL;
-       svc_info = __bt_gatt_find_gatt_service_info(service_path);
-
-       if (svc_info != NULL) {
-               BT_DBG("Updating the gatt service register state %d", state);
-               svc_info->is_svc_registered = state;
-               return;
+       if (svc_info != NULL) {
+               BT_DBG("Updating the gatt service register state %d", state);
+               svc_info->is_svc_registered = state;
+               return;
        }
 
        BT_DBG("gatt service not found");
@@ -1850,6 +1972,12 @@ BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
                                g_variant_new("(oa{sa{sv}})",
                                path, builder),
                                &error);
+       if (error != NULL) {
+               /* dbus gives error cause */
+               BT_ERR("d-bus api failure: errcode[%x], message[%s]",
+                               error->code, error->message);
+               g_clear_error(&error);
+       }
 
        new_service = TRUE;
 
@@ -1896,7 +2024,7 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
        node_info = __bt_gatt_create_method_node_info(
-                                       characteristics_introspection_xml);
+                       characteristics_introspection_xml);
        if (node_info == NULL)
                return BLUETOOTH_ERROR_INTERNAL;
 
@@ -1904,9 +2032,9 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
        BT_DBG("gatt characteristic path is [%s]", path);
 
        object_id = g_dbus_connection_register_object(g_conn, path,
-                                       node_info->interfaces[0],
-                                       &char_interface_vtable,
-                                       NULL, NULL, &error);
+                       node_info->interfaces[0],
+                       &char_interface_vtable,
+                       NULL, NULL, &error);
        g_dbus_node_info_unref(node_info);
 
        if (object_id == 0) {
@@ -1946,9 +2074,9 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
        inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
 
        g_variant_builder_add(inner_builder, "{sv}", "UUID",
-                               g_variant_new("s", char_uuid));
+                       g_variant_new("s", char_uuid));
        g_variant_builder_add(inner_builder, "{sv}", "Service",
-                               g_variant_new("o", svc_path));
+                       g_variant_new("o", svc_path));
 
        builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
 
@@ -1957,23 +2085,30 @@ BT_EXPORT_API int bluetooth_gatt_add_new_characteristic(
 
        flags_val = g_variant_new("as", builder2);
        g_variant_builder_add(inner_builder, "{sv}", "Flags",
-                               flags_val);
+                       flags_val);
 
        builder3 = g_variant_builder_new(G_VARIANT_TYPE("ao"));
 
        g_variant_builder_add(inner_builder, "{sv}", "Descriptors",
-                               g_variant_new("ao", builder3));
+                       g_variant_new("ao", builder3));
 
        g_variant_builder_add(builder, "{sa{sv}}",
-                               GATT_CHAR_INTERFACE,
-                               inner_builder);
+                       GATT_CHAR_INTERFACE,
+                       inner_builder);
 
        g_dbus_connection_emit_signal(g_conn, NULL, "/",
-                               "org.freedesktop.Dbus.ObjectManager",
-                               "InterfacesAdded",
-                               g_variant_new("(oa{sa{sv}})",
+                       "org.freedesktop.Dbus.ObjectManager",
+                       "InterfacesAdded",
+                       g_variant_new("(oa{sa{sv}})",
                                path, builder),
-                               &error);
+                       &error);
+
+       if (error) {
+               /* dBUS gives error cause */
+               BT_ERR("Could not Emit Signal: errCode[%x], message[%s]",
+                               error->code, error->message);
+               g_clear_error(&error);
+       }
 
        *char_path = g_strdup(path);
 
@@ -2036,7 +2171,7 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristic_value(
                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);
+       g_variant_builder_add(inner_builder, "{sv}", "Value", char_val);
 
        g_variant_builder_add(builder, "{sa{sv}}",
                        GATT_CHAR_INTERFACE,
@@ -2046,9 +2181,15 @@ BT_EXPORT_API int bluetooth_gatt_set_characteristic_value(
                        "org.freedesktop.Dbus.ObjectManager",
                        "InterfacesAdded",
                        g_variant_new("(oa{sa{sv}})",
-                       char_info->char_path, builder),
+                               char_info->char_path, builder),
                        &error);
 
+       if (error) {
+               /* dBUS gives error cause */
+               BT_ERR("Could not Emit Signal: errCode[%x], message[%s]",
+                               error->code, error->message);
+               g_clear_error(&error);
+       }
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
        g_variant_builder_unref(builder1);
@@ -2165,6 +2306,12 @@ BT_EXPORT_API int bluetooth_gatt_add_descriptor(
                                g_variant_new("(oa{sa{sv}})",
                                path, builder),
                                &error);
+       if (error) {
+               /* dBUS gives error cause */
+               BT_ERR("Could not Emit Signal: errCode[%x], message[%s]",
+                               error->code, error->message);
+               g_clear_error(&error);
+       }
 
        *desc_path = g_strdup(path);
 
@@ -2229,15 +2376,22 @@ BT_EXPORT_API int bluetooth_gatt_set_descriptor_value(
        g_variant_builder_add(inner_builder, "{sv}", "Value", desc_val);
 
        g_variant_builder_add(builder, "{sa{sv}}",
-                               GATT_DESC_INTERFACE,
-                               inner_builder);
+                       GATT_DESC_INTERFACE,
+                       inner_builder);
 
        g_dbus_connection_emit_signal(g_conn, NULL, "/",
-                               "org.freedesktop.Dbus.ObjectManager",
-                               "InterfacesAdded",
-                               g_variant_new("(oa{sa{sv}})",
+                       "org.freedesktop.Dbus.ObjectManager",
+                       "InterfacesAdded",
+                       g_variant_new("(oa{sa{sv}})",
                                desc_info->desc_path, builder),
-                               &error);
+                       &error);
+
+       if (error != NULL) {
+               BT_ERR("D-Bus API failure: errCode[%x], \
+                               message[%s]",
+                               error->code, error->message);
+               g_clear_error(&error);
+       }
 
        g_variant_builder_unref(inner_builder);
        g_variant_builder_unref(builder);
@@ -2405,7 +2559,6 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
 
        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);
 
@@ -2734,3 +2887,619 @@ BT_EXPORT_API int bluetooth_gatt_server_set_notification(const char *char_path,
 
        return err;
 }
+
+
+#if 0
+BT_EXPORT_API int bluetooth_gatt_register_application(int instance_id)
+{
+       BT_INIT_PARAMS();
+
+       if (!is_server_started) {
+
+               if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_GATT_REGISTER_APPLICATION)
+                               == BLUETOOTH_ERROR_PERMISSION_DEINED) {
+                       BT_ERR("Don't have aprivilege to use this API");
+                       return BLUETOOTH_ERROR_PERMISSION_DEINED;
+               }
+
+               BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+               g_array_append_vals(in_param1, &instance_id, sizeof(int));
+
+               ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_REGISTER_APPLICATION,
+                               in_param1, in_param2, in_param3, in_param4, &out_param);
+               BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+               if (ret != BLUETOOTH_ERROR_NONE) {
+                       BT_ERR("Register application failed");
+                       return ret;
+               }
+               is_server_started = true;
+
+               return BLUETOOTH_ERROR_NONE;
+       }
+
+       BT_INFO("Already RegisterApplication");
+       return BLUETOOTH_ERROR_NONE;
+}
+#endif
+
+BT_EXPORT_API int bluetooth_gatt_server_init(int *instance_id, gatt_server_cb_func_ptr callback_ptr,
+                                               void *user_data)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       /* Register event handler for GATT */
+       ret = _bt_register_event(BT_GATT_SERVER_EVENT, (void *)callback_ptr, user_data);
+
+       if (ret != BLUETOOTH_ERROR_NONE &&
+                       ret != BLUETOOTH_ERROR_ALREADY_INITIALIZED) {
+               BT_ERR("Fail to init the event handler");
+               BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+               goto done;
+       }
+
+       ret = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_REGISTER,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       /* App ID -1 is invalid */
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_INFO("GATT Server Registration failed result [%d]", ret);
+               *instance_id = -1;
+       } else {
+               *instance_id = g_array_index(out_param, int, 0);
+               BT_INFO("GATT Server Registered successfully: App Instance ID [%d]", *instance_id);
+       }
+
+done:
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       BT_INFO("GATT Server instance ID obtained [%d]", *instance_id);
+       return ret;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_deinit(void)
+{
+       int ret;
+       BT_INFO("GATT Server Deinitialize");
+       /* Unregister the event */
+       ret = _bt_unregister_event(BT_GATT_SERVER_EVENT);
+
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to deinit the event handler");
+               return ret;
+       }
+
+       _bt_set_user_data(BT_GATT_SERVER, NULL, NULL);
+
+       return ret;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_add_service(const char *svc_uuid, int type, int numhandles,
+               int instance_id, int *service_handle)
+{
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(svc_uuid, return);
+
+       int result;
+       char uuid[BT_GATT_ATT_UUID_LEN_MAX + 1];
+
+       g_strlcpy(uuid, svc_uuid, sizeof(uuid));
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &type, sizeof(int));
+       g_array_append_vals(in_param2, &numhandles, sizeof(int));
+       g_array_append_vals(in_param3, uuid, BT_GATT_ATT_UUID_LEN_MAX + 1);
+       g_array_append_vals(in_param4, &instance_id, sizeof(int));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_ADD_SERVICE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       /* ATT handle 0 is reserved, hence it can not be used by app.
+          It will be used to indicate error in regsitering attribute */
+       if (result != BLUETOOTH_ERROR_NONE)
+               *service_handle = 0;
+       else
+               *service_handle = g_array_index(out_param, int, 0);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_add_new_characteristic(const char *char_uuid,
+               const bluetooth_gatt_server_attribute_params_t *param,
+                                               int *char_handle)
+{
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(char_uuid, return);
+       BT_CHECK_PARAMETER(param, return);
+
+       int result;
+       char uuid[BT_GATT_ATT_UUID_LEN_MAX + 1];
+       int flag_count = 0;
+       char *char_flags[NUMBER_OF_FLAGS];
+
+       g_strlcpy(uuid, char_uuid, sizeof(uuid));
+       flag_count = bluetooth_gatt_convert_prop2string(param->properties, char_flags);
+       BT_INFO("Flag count [%d]", flag_count);
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, param, sizeof(bluetooth_gatt_server_attribute_params_t));
+       g_array_append_vals(in_param2, uuid, BT_GATT_ATT_UUID_LEN_MAX + 1);
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_ADD_CHARACTERISTIC,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       /* ATT handle 0 is reserved, hence it can not be used by app.
+          It will be used to indicate error in regsitering attribute */
+       if (result != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("GATT Server Add characteristic failed.. result [%d]", result);
+               *char_handle = 0;
+       } else {
+               *char_handle = g_array_index(out_param, int, 0);
+               BT_DBG("GATT Server Add characteristic success result [%d] char chandle [%d]", result, *char_handle);
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_add_descriptor(const char *desc_uuid, bt_gatt_permission_t permissions,
+               int service_handle, int instance_id, int *descriptor_handle)
+{
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(desc_uuid, return);
+
+       int result;
+       char uuid[BT_GATT_ATT_UUID_LEN_MAX + 1];
+
+       g_strlcpy(uuid, desc_uuid, sizeof(uuid));
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &service_handle, sizeof(int));
+       g_array_append_vals(in_param2, &instance_id, sizeof(int));
+       g_array_append_vals(in_param3, &permissions, sizeof(bt_gatt_permission_t));
+       g_array_append_vals(in_param4, uuid, BT_GATT_ATT_UUID_LEN_MAX + 1);
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_ADD_DESCRIPTOR,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       /* ATT handle 0 is reserved, hence it can not be used by app.
+          It will be used to indicate error in regsitering attribute */
+       if (result != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("GATT Server Add Descriptor failed.. result [%d] desc handle [%d]", result, *descriptor_handle);
+               *descriptor_handle = 0;
+       } else {
+               *descriptor_handle = g_array_index(out_param, int, 0);
+               BT_INFO("GATT Server Add Descriptor Successful.. result [%d] desc handle [%d]", result, *descriptor_handle);
+       }
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_start_service(int service_handle, int instance_id)
+{
+       BT_CHECK_ENABLED(return);
+       int result;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &service_handle, sizeof(int));
+       g_array_append_vals(in_param2, &instance_id, sizeof(int));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_START_SERVICE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_send_response(const bluetooth_gatt_server_response_params_t *param,
+               const bluetooth_gatt_att_data_t *value)
+{
+       BT_CHECK_PARAMETER(param, return);
+       BT_CHECK_PARAMETER(value, return);
+       BT_CHECK_ENABLED(return);
+       int result;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, value, sizeof(bluetooth_gatt_att_data_t));
+       g_array_append_vals(in_param2, param, sizeof(bluetooth_gatt_server_response_params_t));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_SEND_RESPONSE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
+               const bluetooth_gatt_server_indication_params_t *param,
+               const bluetooth_gatt_att_data_t *att_value)
+{
+       BT_CHECK_PARAMETER(param, return);
+       BT_CHECK_PARAMETER(att_value, return);
+       BT_CHECK_ENABLED(return);
+       int result = 0 ;
+       char addr[BLUETOOTH_ADDRESS_STRING_LENGTH] ;
+       int fd = -1;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, att_value, sizeof(bluetooth_gatt_att_data_t));
+       g_array_append_vals(in_param2, param, sizeof(bluetooth_gatt_server_indication_params_t));
+       g_array_append_vals(in_param3, addr_hex, sizeof(bluetooth_device_address_t));
+
+       _bt_convert_addr_type_to_string(addr, addr_hex->addr);
+       fd =  bluetooth_get_characteristic_fd(param->atrribute_handle, addr);
+
+       if (fd > -1)
+               result  = bluetooth_gatt_write_characteristics_value_to_fd_(fd, att_value->data, att_value->length, NULL);
+       else
+               result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_SEND_INDICATION,
+                               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_stop_service(int service_handle, int instance_id)
+{
+       BT_CHECK_ENABLED(return);
+       int result;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &service_handle, sizeof(int));
+       g_array_append_vals(in_param2, &instance_id, sizeof(int));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_STOP_SERVICE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_delete_service(int service_handle, int instance_id)
+{
+       BT_CHECK_ENABLED(return);
+       int result;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &service_handle, sizeof(int));
+       g_array_append_vals(in_param2, &instance_id, sizeof(int));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_DELETE_SERVICE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+/* Tizen Platform Specific */
+BT_EXPORT_API int bluetooth_gatt_server_update_characteristic(int instance_id,
+                               const bluetooth_gatt_server_update_value_t *value)
+{
+       BT_CHECK_ENABLED(return);
+       BT_CHECK_PARAMETER(value, return);
+       int result;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &instance_id, sizeof(int));
+       g_array_append_vals(in_param2, value, sizeof(bluetooth_gatt_server_update_value_t));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_UPDATE_VALUE,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       return result;
+}
+
+BT_EXPORT_API int bluetooth_gatt_server_unregister(int instance_id)
+{
+       BT_CHECK_ENABLED(return);
+       int result;
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       g_array_append_vals(in_param1, &instance_id, sizeof(int));
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GATT_SERVER_DEREGISTER,
+                       in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result != BLUETOOTH_ERROR_NONE)
+               BT_INFO("GATT Server Unregistration failed result [%d]", result);
+       else
+               BT_INFO("GATT Server Unregistration successful");
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       return result;
+}
+
+
+static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
+                                       GIOCondition cond, gpointer data)
+{
+
+       bluetooth_gatt_server_acquire_write_info_t *write_data =  (bluetooth_gatt_server_acquire_write_info_t*)data;
+
+       BT_INFO("FD io write data  received  remote adress  [%s]\n", write_data->address);
+
+       if (cond & G_IO_IN) {
+               GIOStatus status = G_IO_STATUS_NORMAL;
+               GError *err = NULL;
+               char *buffer = NULL;
+               gsize len = 0;
+               int BUF = BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX;
+
+               buffer = g_malloc0(BUF);
+
+               status = g_io_channel_read_chars(gio, buffer,
+                               BUF, &len, &err);
+
+               if (status != G_IO_STATUS_NORMAL) {
+                       BT_ERR("IO Channel read is failed with %d", status);
+                       g_free(buffer);
+                       if (err) {
+                               BT_ERR("IO Channel read error [%s]", err->message);
+                               if (status == G_IO_STATUS_ERROR) {
+                                       BT_ERR("cond : %d", cond);
+                                       g_error_free(err);
+                                       g_io_channel_shutdown(gio, TRUE, NULL);
+                                       g_io_channel_unref(gio);
+
+                                       return FALSE;
+                               }
+                               g_error_free(err);
+                       }
+                       return FALSE;
+               }
+
+               if (len > 0) {
+
+                       BT_INFO(" FD io sending  value changed %s %d \n", buffer, len);
+
+
+                       bluetooth_gatt_server_write_requested_info_t write_info;
+                       if (len < BLUETOOTH_GATT_ATT_DATA_LENGTH_MAX)
+                       memcpy(write_info.data.data, buffer, len);
+
+                       write_info.length = len;
+                       write_info.need_resp = false;
+                       write_info.attribute_handle = write_data->attribute_handle;
+                       //memcpy()
+                       _bt_convert_addr_string_to_type(write_info.device_address.addr,  write_data->address);
+                       write_info.connection_id = write_data->connection_id;
+                       write_info.offset = write_data->offset;
+                       write_info.request_id = -2;
+
+                       BT_INFO("ACQUIRING EVENT \n");
+
+                       bt_event_info_t *event_info;
+                       event_info = _bt_event_get_cb_data(BT_GATT_SERVER_EVENT);
+
+                       if (event_info) {
+
+                               _bt_common_event_cb(BLUETOOTH_EVENT_GATT_SERVER_VALUE_CHANGED,
+                                                       BLUETOOTH_ERROR_NONE, &write_info,
+                                               event_info->cb, event_info->user_data);
+                       } else {
+                               BT_ERR("eventinfo failed");
+                       }
+
+
+               }
+               g_free(buffer);
+
+               return TRUE;
+       }
+
+       if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
+               BT_ERR("Error : GIOCondition %d, ]", cond);
+               g_io_channel_shutdown(gio, TRUE, NULL);
+               g_io_channel_unref(gio);
+
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+void  bluetooth_gatt_server_send_acquire_write_response(GVariant * parameters)
+{
+       int con_id  =  -1;
+       int tran_id  =  -1;
+       int att_han  =  -1;
+       int pipefd[2] = {-1,};
+       int mtu  = -1;
+       int offset  = -1;
+       char err_msg[512] = {'\0'};
+       GIOChannel *channel = NULL;
+       char *addr = NULL;
+       int result =  -1;
+
+       g_variant_get(parameters, "(iiiiii&s)",
+                                       &result,
+                                       &con_id,
+                                       &tran_id,
+                                       &att_han,
+                                       &mtu,
+                                       &offset,
+                                       &addr);
+
+       BT_DBG("GATT Server  Acquire Write From Remote Client [%s]", addr);
+       BT_DBG("GATT ServerAcquire  Conn ID:   [%d]", con_id);
+       BT_DBG("GATT Server Acquire write  att handle:[%d]", att_han);
+       BT_DBG("GATT Server Acquire Write Offset:    [%d]", offset);
+
+
+       if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipefd) < 0) {
+                       strerror_r(errno, err_msg, sizeof(err_msg));
+                       BT_ERR("socketpair(): %s", err_msg);
+                       return ;
+       }
+
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       //param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+       bluetooth_gatt_server_acquire_response_params_t  data;
+       data.req_type  = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_WRITE;
+       data.fd = pipefd[1];
+       data.mtu = mtu;
+       data.request_id = tran_id;
+
+       bluetooth_gatt_server_acquire_write_info_t  *write_info = g_malloc0(sizeof(bluetooth_gatt_server_acquire_write_info_t))  ;
+
+       write_info->attribute_handle = att_han;
+       write_info->connection_id  = tran_id;
+       write_info->offset = offset;
+
+        memcpy(write_info->address,  addr ,  BLUETOOTH_ADDRESS_STRING_LENGTH);
+
+       BT_INFO("FD read %d   remote address  [%s ] \n", pipefd[0], addr);
+
+
+       channel = g_io_channel_unix_new(pipefd[0]);
+       g_io_channel_set_encoding(channel, NULL, NULL);
+       g_io_channel_set_buffered(channel, FALSE);
+       g_io_channel_set_close_on_unref(channel, TRUE);
+       g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
+       g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP),
+                       bluetooth_gatt_server_acquire_channel_write_cb, write_info);
+
+
+        GUnixFDList *fd_list = g_unix_fd_list_new();
+        GError *error = NULL;
+
+       g_unix_fd_list_append(fd_list, pipefd[1], &error);
+       g_assert_no_error(error);
+       close(pipefd[1]);
+
+       g_array_append_vals(in_param1, &data, sizeof(bluetooth_gatt_server_acquire_response_params_t));
+
+       BT_INFO("Sending event BT_GATT_SERVER_ACQURE_WRITE_RESPONSE file descriptor value [%d] [ %s],", data.fd, addr);
+
+       result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_GATT_SERVER_ACQURE_WRITE_RESPONSE,
+                       in_param1, in_param2, in_param3, in_param4, fd_list, &out_param, NULL);
+
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+}
+
+
+
+void  bluetooth_gatt_server_send_acquire_notify_response(GVariant * parameters)
+{
+                       int con_id  =  -1;
+                       int tran_id  =  -1;
+                       int att_han  =  -1;
+                       int pipefd[2] = {-1,};
+                       int mtu  = -1;
+                       int offset  = -1;
+                       char err_msg[512] = {'\0'};
+                       GIOChannel *channel = NULL;
+                       int result =  -1;
+                       int fd = -1;
+                       bluetooth_gatt_acquire_notify_info_t *chr_info;
+
+                       g_variant_get(parameters, "(iiiiii)",
+                                                       &result,
+                                                       &con_id,
+                                                       &tran_id,
+                                                       &att_han,
+                                                       &mtu,
+                                                       &offset);
+
+                               BT_DBG("GATT ServerAcquire  Conn ID:   [%d]", con_id);
+                               BT_DBG("GATT Server Acquire notify  att handle:[%d]", att_han);
+                               BT_DBG("GATT Server Acquire Notify Offset:    [%d]", offset);
+
+
+                       if (socketpair(AF_UNIX, SOCK_STREAM, 0, pipefd) < 0) {
+                                       strerror_r(errno, err_msg, sizeof(err_msg));
+                                       BT_ERR("socketpair(): %s", err_msg);
+                                       return ;
+                               }
+
+                               fd = pipefd[0];
+
+                               BT_INIT_PARAMS();
+                               BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+                               //param1 = g_array_new(TRUE, TRUE, sizeof(gchar));
+                               bluetooth_gatt_server_acquire_response_params_t  data;
+                               data.req_type  = BLUETOOTH_GATT_REQUEST_TYPE_ACQUIRE_NOTIFY;
+                               data.fd = pipefd[1];
+                               data.mtu = mtu;
+                               data.request_id = tran_id;
+
+                               BT_INFO("FD write %d   characterstics path   \n", pipefd[0]);
+
+                               chr_info = bluetooth_get_characteristic_info_from_path(att_han);
+                               if (!chr_info) {
+                                       chr_info = g_malloc0(sizeof(bluetooth_gatt_acquire_notify_info_t));
+                                       chr_info->write_fd = fd;
+                                       chr_info->att_hand = att_han;
+
+                                       gatt_characteristic_server_notify_list = g_slist_append(gatt_characteristic_server_notify_list, chr_info);
+                               } else
+                                       chr_info->write_fd = fd;
+
+
+                               channel = g_io_channel_unix_new(fd);
+                               g_io_channel_set_encoding(channel, NULL, NULL);
+                               g_io_channel_set_buffered(channel, FALSE);
+                               g_io_channel_set_close_on_unref(channel, TRUE);
+                               g_io_channel_set_flags(channel, G_IO_FLAG_NONBLOCK, NULL);
+                               g_io_add_watch(channel, (G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL),
+                                               bluetooth_gatt_write_channel_watch_cb, chr_info);
+
+
+
+
+                                GUnixFDList *fd_list = g_unix_fd_list_new();
+                                GError *error = NULL;
+
+                               g_unix_fd_list_append(fd_list, pipefd[1], &error);
+                               g_assert_no_error(error);
+                               close(pipefd[1]);
+
+                               g_array_append_vals(in_param1, &data, sizeof(bluetooth_gatt_server_acquire_response_params_t));
+
+                               BT_INFO("Sending event BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE file descriptor value [%d] ", data.fd);
+
+                               result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE,
+                                               in_param1, in_param2, in_param3, in_param4, fd_list, &out_param, NULL);
+
+                               BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+}