Fix the issue on AppControl share (BT) operation
[platform/core/connectivity/bluetooth-frwk.git] / bt-api / bt-gatt-service.c
index 4d30589..60c58ff 100644 (file)
@@ -155,16 +155,15 @@ int bluetooth_gatt_convert_perm2string(
 
 #define NUMBER_OF_FLAGS        10
 
-GDBusConnection *g_conn;
-guint owner_id;
-guint manager_id;
+static GDBusConnection *g_conn;
+static guint owner_id;
+static guint manager_id;
 static gboolean new_service = FALSE;
 static gboolean new_char = FALSE;
 static int serv_id = 1;
-static int register_pending_cnt = 0;
 static bool is_server_started = false;
 
-GCancellable *register_cancel;
+static GCancellable *register_cancel;
 
 /* Introspection data for the service we are exporting */
 static const gchar service_introspection_xml[] =
@@ -271,7 +270,6 @@ struct gatt_service_info {
        guint serv_id;
        gchar *service_uuid;
        guint manager_id;
-       guint prop_id;
        GSList *char_data;
        gboolean is_svc_registered;
        gboolean is_svc_primary;
@@ -343,40 +341,39 @@ static struct gatt_desc_info *__bt_gatt_find_gatt_desc_info(
                        const char *desc_path);
 
 static struct gatt_req_info *__bt_gatt_find_request_info(guint request_id);
+static int __bt_gatt_unregister_service(struct gatt_service_info *svc_info);
 
-
-
-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)
+static int bluetooth_get_characteristic_fd(int att_handle , char *address)
 {
        GSList *l;
 
-       BT_INFO("request found  path [%s] att_handle [ %d]", path, att_handle);
+       BT_DBG("Find FD for address [%s] att_handle [ %d]", address, att_handle);
+
+       /* Check for NULL address */
+       if (g_strcmp0(address, "00:00:00:00:00:00") != 0) {
+               BT_INFO("Unicast address: Use DBUS send indication");
+               return -1;
+       }
+
        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)
+
+               if (info->att_hand == att_handle) {
+                       BT_INFO("ATT handle Matched: AquireNotify Set: Remote addr[%s]", info->address);
                        return info->write_fd;
+               }
        }
-       return -1;
+       return -2;
 }
 
 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);
+       BT_DBG("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);
+               BT_DBG(" sid [ %d]" , info->att_hand);
                if (info->att_hand == att_handle)
                        return info;
        }
@@ -392,22 +389,39 @@ static void bluetooth_characteristic_info_free(bluetooth_gatt_acquire_notify_inf
 static gboolean bluetooth_gatt_write_channel_watch_cb(GIOChannel *gio,
                                        GIOCondition cond, gpointer data)
 {
+       BT_INFO("+");
+
        bluetooth_gatt_acquire_notify_info_t *chr_info = (bluetooth_gatt_acquire_notify_info_t *)data;
 
-       if (!chr_info)
+       if (!chr_info) {
+               BT_INFO("chr_info is NULL");
                return FALSE;
+       }
+
+       if (cond & G_IO_NVAL) {
+               BT_ERR("Invalid channel");
+               return FALSE;
+       }
 
-       if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
-               BT_ERR("Error : GIOCondition %d, []", cond);;
+       if (cond & (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);
+               if (g_slist_find(gatt_characteristic_server_notify_list, chr_info)) {
+                       BT_INFO("found char_info in the list");
+                       gatt_characteristic_server_notify_list = g_slist_remove(gatt_characteristic_server_notify_list, chr_info);
+                       bluetooth_characteristic_info_free(chr_info);
+               }
 
                return FALSE;
        }
 
+       if (g_slist_find(gatt_characteristic_server_notify_list, chr_info) == NULL) {
+               BT_INFO("chr_info is not in the list");
+               return FALSE;
+       }
+
        return TRUE;
 }
 
@@ -424,39 +438,10 @@ static int bluetooth_gatt_write_characteristics_value_to_fd_(
                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;
-
-       BT_DBG("+");
-
-       ret_if(g_conn == NULL);
-
-       if (!g_dbus_connection_flush_sync(g_conn, NULL, &err)) {
-               BT_ERR("Fail to flush the connection: %s", err->message);
-               g_error_free(err);
-               err = NULL;
-       }
-
-       if (!g_dbus_connection_close_sync(g_conn, NULL, &err)) {
-               if (err) {
-                       BT_ERR("Fail to close the dbus connection: %s", err->message);
-                       g_error_free(err);
+                       BT_ERR("write data failed  %d is ", written);
                }
-       }
-
-       g_object_unref(g_conn);
 
-       g_conn = NULL;
-
-       BT_DBG("-");
+               return att_result;
 }
 
 #ifdef TIZEN_FEATURE_BT_HPS
@@ -596,97 +581,60 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                                        GDBusMethodInvocation *invocation,
                                        gpointer user_data)
 {
-       GSList *l1 = NULL;
-       int len = 0;
-       int i = 0;
-
        if (g_strcmp0(method_name, "GetManagedObjects") == 0) {
                BT_DBG("Getting values for service, chars and descriptors");
 
-               GVariantBuilder *builder;
+               int svc_index = 0;
+               GVariantBuilder *builder = NULL;
                GVariantBuilder *inner_builder1 = NULL;
                GVariant *svc_char = NULL;
-               GSList *l4;
-               /*Main Builder */
-               builder = g_variant_builder_new(
-                               G_VARIANT_TYPE("a{oa{sa{sv}}}"));
-
-               /* Prepare inner builder for GattService1 interface */
+               GSList *char_list = NULL;
+               GSList *desc_list = NULL;
 
-               len = g_slist_length(gatt_services);
+               /* Main Builder */
+               builder = g_variant_builder_new(G_VARIANT_TYPE("a{oa{sa{sv}}}"));
 
-               for (i = 0; i <= len; i++) {
+               /* Prepare inner builder for GattService1 interface */
+               svc_index = g_slist_length(gatt_services) - 1;
+               for (; svc_index >= 0; svc_index--) {
                        GVariantBuilder *svc_builder = NULL;
                        GVariantBuilder *inner_builder = NULL;
+                       struct gatt_service_info *serv_info = NULL;
 
-                       if (register_pending_cnt > 1)
-                               l1 = g_slist_nth(gatt_services, len - register_pending_cnt);
-                       else
-                               l1 = g_slist_last(gatt_services);
-
-                       register_pending_cnt--;
-
-                       if (l1 == NULL) {
-                               BT_ERR("gatt service list is NULL");
-                               g_dbus_method_invocation_return_value(invocation, NULL);
-                               g_variant_builder_unref(builder);
-                               return;
-                       }
-
-                       struct gatt_service_info *serv_info = l1->data;
+                       serv_info = g_slist_nth_data(gatt_services, svc_index);
                        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;
+                               BT_ERR("serv_info is NULL");
+                               continue;
                        }
 
                        /* Prepare inner builder for GattService1 interface */
-                       BT_DBG("Creating builder for service");
-                       svc_builder = g_variant_builder_new(
-                                               G_VARIANT_TYPE("a{sa{sv}}"));
+                       BT_DBG("Creating builder for service : %s", serv_info->service_uuid);
+                       svc_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sa{sv}}"));
                        inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
 
                        g_variant_builder_add(inner_builder, "{sv}", "UUID",
                                        g_variant_new_string(serv_info->service_uuid));
-
                        g_variant_builder_add(inner_builder, "{sv}", "Primary",
                                        g_variant_new_boolean(serv_info->is_svc_primary));
 
-                       /*Characteristics*/
+                       /* Characteristics */
                        inner_builder1 = g_variant_builder_new(G_VARIANT_TYPE("ao"));
+
                        BT_DBG("Adding Charatarisitcs list");
-                       for (l4 = serv_info->char_data; l4 != NULL; l4 = l4->next) {
-                               struct gatt_char_info *char_info = l4->data;
-                                       g_variant_builder_add(inner_builder1, "o",
-                                               char_info->char_path);
-                                       BT_DBG("%s", char_info->char_path);
+                       for (char_list = serv_info->char_data; char_list != NULL; char_list = char_list->next) {
+                               struct gatt_char_info *char_info = char_list->data;
+                               g_variant_builder_add(inner_builder1, "o", char_info->char_path);
+                               BT_DBG("%s", char_info->char_path);
                        }
 
                        svc_char = g_variant_new("ao", inner_builder1);
-                       g_variant_builder_add(inner_builder, "{sv}", "Characteristics",
-                                               svc_char);
-
-                       g_variant_builder_add(svc_builder, "{sa{sv}}",
-                                                               GATT_SERV_INTERFACE,
-                                                               inner_builder);
-
-                       g_variant_builder_add(builder, "{oa{sa{sv}}}",
-                                                               serv_info->serv_path,
-                                                               svc_builder);
-
+                       g_variant_builder_add(inner_builder, "{sv}", "Characteristics", svc_char);
+                       g_variant_builder_add(svc_builder, "{sa{sv}}", GATT_SERV_INTERFACE, inner_builder);
+                       g_variant_builder_add(builder, "{oa{sa{sv}}}", serv_info->serv_path, svc_builder);
                        g_variant_builder_unref(inner_builder1);
 
                        /* Prepare inner builder for GattCharacteristic1 interface */
-
-                       GSList *l2 = serv_info->char_data;
-                       BT_DBG("Creating builder for characteristics \n");
-
-                       if (l2 == NULL)
-                               BT_DBG("characteristic data is NULL");
-
-                       for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
-
+                       for (char_list = serv_info->char_data; char_list != NULL; char_list = char_list->next) {
                                GVariantBuilder *char_builder = NULL;
                                GVariantBuilder *inner_builder = NULL;
                                GVariantBuilder *builder1 = NULL;
@@ -698,155 +646,114 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                                char *unicast = NULL;
                                gboolean notify = FALSE;
                                int i = 0;
+                               struct gatt_char_info *char_info = char_list->data;
 
-                               char_builder = g_variant_builder_new(
-                                                               G_VARIANT_TYPE(
-                                                                       "a{sa{sv}}"));
-                               inner_builder = g_variant_builder_new(
-                                                               G_VARIANT_TYPE(
-                                                                       "a{sv}"));
-
-                               struct gatt_char_info *char_info = l2->data;
                                if (char_info == NULL) {
                                        BT_ERR("char_info is NULL");
                                        continue;
                                }
 
-                               /*Uuid*/
+                               BT_DBG("Creating builder for characteristic : %s", char_info->char_uuid);
+                               char_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sa{sv}}"));
+                               inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
+
+                               /* UUID */
                                g_variant_builder_add(inner_builder, "{sv}", "UUID",
-                                       g_variant_new_string(char_info->char_uuid));
-                               /*Service*/
+                                               g_variant_new_string(char_info->char_uuid));
+
+                               /* Service */
                                g_variant_builder_add(inner_builder, "{sv}", "Service",
-                                       g_variant_new("o", serv_info->serv_path));
-                               /*Value*/
-                               builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
+                                               g_variant_new("o", serv_info->serv_path));
 
+                               /* Value */
+                               builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
                                if (char_info->char_value != NULL) {
                                        for (i = 0; i < char_info->value_length; i++) {
-                                               g_variant_builder_add(builder1, "y",
-                                                       char_info->char_value[i]);
+                                               g_variant_builder_add(builder1, "y", char_info->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);
                                }
+
                                /*Flags*/
                                builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
-
                                for (i = 0; i < char_info->flags_length; i++) {
-                                       g_variant_builder_add(builder2, "s",
-                                               char_info->char_flags[i]);
+                                       g_variant_builder_add(builder2, "s", char_info->char_flags[i]);
                                }
-
                                flags_val = g_variant_new("as", builder2);
-                               g_variant_builder_add(inner_builder, "{sv}", "Flags",
-                                                       flags_val);
+                               g_variant_builder_add(inner_builder, "{sv}", "Flags", flags_val);
 
                                /* Notifying */
-                               g_variant_builder_add(inner_builder, "{sv}", "Notifying",
-                                                       g_variant_new("b", notify));
+                               g_variant_builder_add(inner_builder, "{sv}", "Notifying", g_variant_new("b", notify));
 
                                /* Unicast */
                                unicast = g_strdup("00:00:00:00:00:00");
-                               g_variant_builder_add(inner_builder, "{sv}", "Unicast",
-                                                       g_variant_new("s", unicast));
+                               g_variant_builder_add(inner_builder, "{sv}", "Unicast", g_variant_new("s", unicast));
 
                                /*Descriptors*/
                                builder3 = g_variant_builder_new(G_VARIANT_TYPE("ao"));
                                BT_DBG("Adding Descriptors list");
-
-                               for (l4 = char_info->desc_data; l4 != NULL; l4 = l4->next) {
-                                       struct gatt_desc_info *desc_info = l4->data;
-                                               g_variant_builder_add(builder3, "o",
-                                                       desc_info->desc_path);
-                                               BT_DBG("%s", desc_info->desc_path);
+                               for (desc_list = char_info->desc_data; desc_list != NULL; desc_list = desc_list->next) {
+                                       struct gatt_desc_info *desc_info = desc_list->data;
+                                       g_variant_builder_add(builder3, "o", desc_info->desc_path);
+                                       BT_DBG("%s", desc_info->desc_path);
                                }
 
                                char_desc = g_variant_new("ao", builder3);
-                               g_variant_builder_add(inner_builder, "{sv}", "Descriptors",
-                                                       char_desc);
-
-                               g_variant_builder_add(char_builder, "{sa{sv}}",
-                                               GATT_CHAR_INTERFACE , inner_builder);
-                               g_variant_builder_add(builder, "{oa{sa{sv}}}",
-                                               char_info->char_path, char_builder);
+                               g_variant_builder_add(inner_builder, "{sv}", "Descriptors", char_desc);
+                               g_variant_builder_add(char_builder, "{sa{sv}}", GATT_CHAR_INTERFACE , inner_builder);
+                               g_variant_builder_add(builder, "{oa{sa{sv}}}", char_info->char_path, char_builder);
 
                                /*Prepare inner builder for GattDescriptor1 interface*/
-
-                               GSList *l3 = char_info->desc_data;
-
-                               if (l3 == NULL)
-                                       BT_DBG("descriptor data is NULL");
-
-                               for (l3 = char_info->desc_data; l3 != NULL; l3 = l3->next) {
-
-                                       BT_DBG("Creating builder for descriptor \n");
-
+                               for (desc_list = char_info->desc_data; desc_list != NULL; desc_list = desc_list->next) {
                                        GVariantBuilder *desc_builder = NULL;
                                        GVariantBuilder *inner_builder = NULL;
                                        GVariantBuilder *builder1 = NULL;
                                        GVariantBuilder *builder2 = NULL;
                                        GVariant *desc_val = NULL;
+                                       struct gatt_desc_info *desc_info = desc_list->data;
 
-                                       desc_builder = g_variant_builder_new(
-                                                               G_VARIANT_TYPE(
-                                                               "a{sa{sv}}"));
-                                       inner_builder = g_variant_builder_new(
-                                                               G_VARIANT_TYPE(
-                                                               "a{sv}"));
-
-                                       struct gatt_desc_info *desc_info = l3->data;
                                        if (desc_info == NULL) {
                                                BT_ERR("desc_info is NULL");
                                                continue;
                                        }
 
-                                       /*Uuid*/
-                                       g_variant_builder_add(inner_builder,
-                                               "{sv}", "UUID",
-                                               g_variant_new_string(
-                                                       desc_info->desc_uuid));
+                                       BT_DBG("Creating builder for descriptor : %s", desc_info->desc_uuid);
+                                       desc_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sa{sv}}"));
+                                       inner_builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
 
-                                       /*Characteristic*/
-                                       g_variant_builder_add(inner_builder, "{sv}",
-                                               "Characteristic",
-                                               g_variant_new("o",
-                                                       char_info->char_path));
+                                       /* UUID */
+                                       g_variant_builder_add(inner_builder, "{sv}", "UUID",
+                                                       g_variant_new_string(desc_info->desc_uuid));
 
-                                       /*Value*/
-                                       builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
+                                       /* Characteristic */
+                                       g_variant_builder_add(inner_builder, "{sv}", "Characteristic",
+                                                       g_variant_new("o", char_info->char_path));
 
+                                       /* Value */
+                                       builder1 = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
                                        if (desc_info->desc_value != NULL) {
                                                for (i = 0; i < desc_info->value_length; i++) {
-                                                       g_variant_builder_add(builder1, "y",
-                                                               desc_info->desc_value[i]);
+                                                       g_variant_builder_add(builder1, "y", desc_info->desc_value[i]);
                                                }
                                                desc_val = g_variant_new("ay", builder1);
-                                               g_variant_builder_add(inner_builder, "{sv}",
-                                                               "Value", desc_val);
+                                               g_variant_builder_add(inner_builder, "{sv}", "Value", desc_val);
                                        }
 
-                                       /*Flags*/
+                                       /* Flags */
                                        builder2 = g_variant_builder_new(G_VARIANT_TYPE("as"));
-
                                        for (i = 0; i < desc_info->flags_length; i++) {
-                                               g_variant_builder_add(builder2, "s",
-                                                       desc_info->desc_flags[i]);
+                                               g_variant_builder_add(builder2, "s", desc_info->desc_flags[i]);
                                        }
-
                                        flags_val = g_variant_new("as", builder2);
-                                       g_variant_builder_add(inner_builder, "{sv}", "Flags",
-                                                               flags_val);
+                                       g_variant_builder_add(inner_builder, "{sv}", "Flags", flags_val);
 
-                                       g_variant_builder_add(desc_builder, "{sa{sv}}",
-                                                       GATT_DESC_INTERFACE,
+                                       g_variant_builder_add(desc_builder, "{sa{sv}}", GATT_DESC_INTERFACE,
                                                        inner_builder);
-
-                                       g_variant_builder_add(builder, "{oa{sa{sv}}}",
-                                                       desc_info->desc_path,
+                                       g_variant_builder_add(builder, "{oa{sa{sv}}}", desc_info->desc_path,
                                                        desc_builder);
 
-                                       /*unref descriptor builder pointers*/
+                                       /* unref descriptor builder pointers */
                                        g_variant_builder_unref(builder1);
                                        g_variant_builder_unref(builder2);
                                        g_variant_builder_unref(inner_builder);
@@ -855,7 +762,8 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
 
                                if (unicast)
                                        g_free(unicast);
-                               /*unref char builder pointers*/
+
+                               /* unref char builder pointers */
                                g_variant_builder_unref(builder1);
                                g_variant_builder_unref(builder2);
                                g_variant_builder_unref(builder3);
@@ -863,7 +771,7 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                                g_variant_builder_unref(char_builder);
                        }
 
-                       /*unref service builder pointers*/
+                       /* unref service builder pointers */
                        g_variant_builder_unref(inner_builder);
                        g_variant_builder_unref(svc_builder);
                }
@@ -871,9 +779,7 @@ static void __bt_gatt_manager_method_call(GDBusConnection *connection,
                /* Return builder as method reply */
                BT_DBG("Sending gatt service builder values to Bluez");
                g_dbus_method_invocation_return_value(invocation,
-                                               g_variant_new(
-                                               "(a{oa{sa{sv}}})",
-                                               builder));
+                               g_variant_new("(a{oa{sa{sv}}})", builder));
                g_variant_builder_unref(builder);
        }
 }
@@ -888,8 +794,7 @@ static struct gatt_service_info *__bt_gatt_find_gatt_service_from_char(const cha
                for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
                        struct gatt_char_info *char_info = l2->data;
 
-                       if (g_strcmp0(char_info->char_path, char_path)
-                                               == 0)
+                       if (g_strcmp0(char_info->char_path, char_path) == 0)
                                return serv_info;
                }
        }
@@ -910,8 +815,7 @@ static struct gatt_service_info *__bt_gatt_find_gatt_service_from_desc(const cha
                        for (l3 = char_info->desc_data; l3 != NULL; l3 = l3->next) {
                                struct gatt_desc_info *desc_info = l3->data;
 
-                               if (g_strcmp0(desc_info->desc_path, desc_path)
-                                                       == 0)
+                               if (g_strcmp0(desc_info->desc_path, desc_path) == 0)
                                        return serv_info;
                        }
                }
@@ -977,10 +881,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,
@@ -995,6 +895,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;
@@ -1072,11 +976,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;
@@ -1099,6 +998,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;
@@ -1117,10 +1021,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,
@@ -1128,6 +1028,10 @@ 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);
@@ -1147,10 +1051,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,
@@ -1158,6 +1058,10 @@ 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);
@@ -1449,8 +1353,7 @@ static struct gatt_char_info *__bt_gatt_find_gatt_char_info(
                        for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
                                struct gatt_char_info *char_info = l2->data;
 
-                               if (g_strcmp0(char_info->char_path, char_path)
-                                                       == 0)
+                               if (g_strcmp0(char_info->char_path, char_path) == 0)
                                        return char_info;
                        }
                        BT_ERR("Gatt characteristic not found");
@@ -1474,8 +1377,7 @@ static struct gatt_desc_info *__bt_gatt_find_gatt_desc_info(
                        for (l2 = serv_info->char_data; l2 != NULL; l2 = l2->next) {
                                struct gatt_char_info *char_info = l2->data;
 
-                               if (g_strcmp0(char_info->char_path, char_path)
-                                                       == 0) {
+                               if (g_strcmp0(char_info->char_path, char_path) == 0) {
                                        for (l3 = char_info->desc_data; l3 != NULL; l3 = l3->next) {
                                                struct gatt_desc_info *desc_info = l3->data;
                                                if (g_strcmp0(desc_info->desc_path,
@@ -1511,20 +1413,14 @@ static GDBusProxy *__bt_gatt_gdbus_init_manager_proxy(const gchar *service,
        GDBusProxy *proxy;
        GError *err = NULL;
 
-       if (g_conn == NULL)
-               g_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM,
-                                                       NULL, &err);
-
+       g_conn = _bt_get_system_shared_conn();
        if (!g_conn) {
-               if (err) {
-                       BT_ERR("Unable to connect to gdbus: %s", err->message);
-                       g_clear_error(&err);
-               }
+               BT_ERR("Unable to get connection");
                return NULL;
        }
 
        proxy =  g_dbus_proxy_new_sync(g_conn,
-                       G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL,
                        service, path,
                        interface, NULL, &err);
 
@@ -1548,23 +1444,7 @@ static GDBusProxy *__bt_gatt_gdbus_get_manager_proxy(const gchar *service,
                                path, interface);
 }
 
-
-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;
-       }
-
-       BT_DBG("gatt service not found");
-}
-
-static gboolean __bt_gatt_get_service_state(const char *service_path)
+static gboolean __bt_gatt_is_service_registered(const char *service_path)
 {
        struct gatt_service_info *svc_info = NULL;
 
@@ -1596,13 +1476,10 @@ void get_service_cb(GObject *object, GAsyncResult *res, gpointer user_data)
        result = g_dbus_proxy_call_finish(G_DBUS_PROXY(object), res, &error);
 
        if (result == NULL) {
-               /* dBUS-RPC is failed */
-               BT_ERR("Dbus-RPC is failed\n");
-
+               BT_ERR("Dbus-RPC is failed");
                if (error != NULL) {
-               /* dBUS gives error cause */
-                       BT_ERR("D-Bus API failure: errCode[%x], message[%s]\n",
-                                               error->code, error->message);
+                       BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+                                       error->code, error->message);
                        g_clear_error(&error);
                }
        } else {
@@ -1641,40 +1518,25 @@ void register_application_cb(GObject *object, GAsyncResult *res, gpointer user_d
        GError *error = NULL;
        GVariant *result;
 
-       register_pending_cnt = 0;
-
        if (register_cancel) {
                g_object_unref(register_cancel);
                register_cancel = NULL;
        }
 
        result = g_dbus_proxy_call_finish(G_DBUS_PROXY(object), res, &error);
-
        if (result == NULL) {
-               /* dBUS-RPC is failed */
-               BT_ERR("Dbus-RPC is failed\n");
-
+               BT_ERR("Dbus-RPC is failed");
                if (error != NULL) {
-               /* dBUS gives error cause */
-                       BT_ERR("D-Bus API failure: errCode[%x], message[%s]\n",
-                                               error->code, error->message);
+                       BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+                                       error->code, error->message);
                        g_clear_error(&error);
                }
+               is_server_started = false;
        } else {
                g_variant_unref(result);
        }
 }
 
-static int __bt_gatt_unregister_service(const char *service_path)
-{
-       if (!__bt_gatt_get_service_state(service_path)) {
-               BT_DBG("service not registered \n");
-               return BLUETOOTH_ERROR_NOT_FOUND;
-       }
-
-       return BLUETOOTH_ERROR_NONE;
-}
-
 BT_EXPORT_API int bluetooth_gatt_unregister_application(void)
 {
        GDBusProxy *proxy = NULL;
@@ -1683,38 +1545,43 @@ BT_EXPORT_API int bluetooth_gatt_unregister_application(void)
                GVariant *ret;
                GError *err = NULL;
 
+               if (app_path == NULL) {
+                       BT_ERR("app_path is NULL");
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+
                proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
                                "/org/bluez/hci0", GATT_MNGR_INTERFACE);
-
-               if (proxy == NULL || app_path == NULL)
+               if (proxy == NULL) {
+                       BT_ERR("proxy is NULL");
                        return BLUETOOTH_ERROR_INTERNAL;
+               }
 
                BT_INFO("UnregisterApplication");
 
-               is_server_started = false;
-
                /* Async Call to Unregister Service */
-               ret = g_dbus_proxy_call_sync(proxy,
-                               "UnregisterApplication",
-                               g_variant_new("(o)",
-                                       app_path),
-                               G_DBUS_CALL_FLAGS_NONE, -1,
+               ret = g_dbus_proxy_call_sync(proxy, "UnregisterApplication",
+                               g_variant_new("(o)", app_path), G_DBUS_CALL_FLAGS_NONE, -1,
                                NULL, &err);
-
                if (ret == NULL) {
-                       /* dBUS-RPC is failed */
                        BT_ERR("dBUS-RPC is failed");
                        if (err != NULL) {
-                               /* dBUS gives error cause */
                                BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
-                               err->code, err->message);
-
+                                               err->code, err->message);
+                               if (err->code == G_DBUS_ERROR_SERVICE_UNKNOWN ||
+                                       g_strrstr(err->message, BT_ERROR_DOES_NOT_EXIST)) {
+                                       g_clear_error(&err);
+                                       goto done;
+                               }
                                g_clear_error(&err);
                        }
                        return BLUETOOTH_ERROR_INTERNAL;
                }
                g_variant_unref(ret);
 
+done:
+               is_server_started = false;
+
                BT_INFO("UnregisterApplication is completed");
 
                return BLUETOOTH_ERROR_NONE;
@@ -1724,67 +1591,8 @@ BT_EXPORT_API int bluetooth_gatt_unregister_application(void)
        return BLUETOOTH_ERROR_NONE;
 }
 
-static GDBusConnection *__bt_gatt_get_gdbus_connection(void)
-{
-       GDBusConnection *local_system_gconn = NULL;
-       char *address;
-       GError *err = NULL;
-
-       if (g_conn == NULL) {
-               address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-               if (address == NULL) {
-                       if (err) {
-                               BT_ERR("Failed to get bus address: %s", err->message);
-                               g_clear_error(&err);
-                       }
-                       return NULL;
-               }
-
-               g_conn = g_dbus_connection_new_for_address_sync(address,
-                                       G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
-                                       G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
-                                       NULL, /* GDBusAuthObserver */
-                                       NULL,
-                                       &err);
-               g_free(address);
-               if (!g_conn) {
-                       if (err) {
-                               BT_ERR("Unable to connect to dbus: %s", err->message);
-                               g_clear_error(&err);
-                       }
-                       return NULL;
-               }
-       } else if (g_dbus_connection_is_closed(g_conn)) {
-               address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
-               if (address == NULL) {
-                       if (err) {
-                               BT_ERR("Failed to get bus address: %s", err->message);
-                               g_clear_error(&err);
-                       }
-                       return NULL;
-               }
-
-               local_system_gconn = g_dbus_connection_new_for_address_sync(address,
-                                       G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT |
-                                       G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
-                                       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);
-               }
-
-               g_conn = local_system_gconn;
-       }
-
-       return g_conn;
-}
-
 BT_EXPORT_API int bluetooth_gatt_init(void)
 {
-       GDBusConnection *conn;
        GError *error = NULL;
        GDBusNodeInfo *node_info = NULL;
 
@@ -1793,24 +1601,27 @@ BT_EXPORT_API int bluetooth_gatt_init(void)
                return BLUETOOTH_ERROR_ALREADY_INITIALIZED;
        }
 
+       g_conn = _bt_get_system_shared_conn();
+       if (!g_conn) {
+               BT_ERR("Unable to get connection");
+               goto failed;
+       }
+
        if (owner_id == 0) {
-               owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
-                                       BT_GATT_SERVICE_NAME,
+               gchar *name = g_strdup_printf("%s.p%d", BT_GATT_SERVICE_NAME, getpid());
+               BT_DBG("well-known name: %s", name);
+
+               owner_id = g_bus_own_name_on_connection(g_conn, name,
                                        G_BUS_NAME_OWNER_FLAGS_NONE,
-                                       NULL, NULL, NULL, NULL, NULL);
+                                       NULL, NULL, NULL, NULL);
+               g_free(name);
        }
-
        BT_DBG("owner_id is [%d]", owner_id);
+
        app_path = g_strdup_printf("/com/%d", getpid());
 
        serv_id = 1;
 
-       conn = __bt_gatt_get_gdbus_connection();
-       if (!conn) {
-               BT_ERR("Unable to get connection");
-               goto failed;
-       }
-
        /* Register ObjectManager interface */
        node_info = __bt_gatt_create_method_node_info(
                                        manager_introspection_xml);
@@ -1845,8 +1656,6 @@ failed:
        app_path = NULL;
        owner_id = 0;
 
-       __bt_gatt_close_gdbus_connection();
-
        return BLUETOOTH_ERROR_INTERNAL;
 }
 
@@ -1860,44 +1669,38 @@ BT_EXPORT_API int bluetooth_gatt_deinit()
                register_cancel = NULL;
        }
 
-       /* Unown gdbus bus */
-       if (owner_id) {
-               /* remove/unregister all services */
-               BT_DBG("removing all registered gatt service\n");
-               bluetooth_gatt_delete_services();
+       if (owner_id == 0) {
+               BT_ERR("owner_id is zero");
+               return BLUETOOTH_ERROR_NOT_FOUND;
+       }
 
-               /* unregister the exported interface for object manager */
-               g_dbus_connection_unregister_object(g_conn,
-                                       manager_id);
+       BT_DBG("Removing all registered gatt services");
+       bluetooth_gatt_delete_services();
 
+       /* Unregister the exported interface for object manager */
+       if (manager_id) {
+               g_dbus_connection_unregister_object(g_conn, manager_id);
                manager_id = 0;
+       }
 
-               ret = bluetooth_gatt_unregister_application();
-               if (ret != BLUETOOTH_ERROR_NONE)
-                       BT_ERR("Fail to unregister application\n");
-
-               g_bus_unown_name(owner_id);
-               owner_id = 0;
-
-               g_free(app_path);
-               app_path = NULL;
+       ret = bluetooth_gatt_unregister_application();
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Fail to unregister application");
+       }
 
-               BT_DBG("Gatt service deinitialized \n");
+       g_bus_unown_name(owner_id);
+       owner_id = 0;
 
-               g_slist_free(gatt_services);
-               gatt_services = NULL;
+       g_free(app_path);
+       app_path = NULL;
 
+       if (manager_gproxy) {
                g_object_unref(manager_gproxy);
                manager_gproxy = NULL;
-
-               __bt_gatt_close_gdbus_connection();
-
-               return ret;
        }
 
-       __bt_gatt_close_gdbus_connection();
-
-       return BLUETOOTH_ERROR_NOT_FOUND;
+       BT_DBG("-");
+       return ret;
 }
 
 BT_EXPORT_API int bluetooth_gatt_add_service(const char *svc_uuid,
@@ -2024,7 +1827,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;
 
@@ -2032,9 +1835,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) {
@@ -2074,9 +1877,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"));
 
@@ -2085,24 +1888,23 @@ 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]",
@@ -2376,15 +2178,15 @@ 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}})",
-                               desc_info->desc_path, builder),
-                       &error);
+                               "org.freedesktop.Dbus.ObjectManager",
+                               "InterfacesAdded",
+                               g_variant_new("(oa{sa{sv}})",
+                                       desc_info->desc_path, builder),
+                               &error);
 
        if (error != NULL) {
                BT_ERR("D-Bus API failure: errCode[%x], \
@@ -2426,23 +2228,22 @@ int bluetooth_gatt_get_service(const char *svc_uuid)
        return BLUETOOTH_ERROR_NONE;
 }
 
-BT_EXPORT_API int bluetooth_gatt_register_service(
-                       const char *svc_path)
+BT_EXPORT_API int bluetooth_gatt_register_service(const char *svc_path)
 {
+       struct gatt_service_info *svc_info = NULL;
+
        if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_GATT_REGISTER_SERVICE)
                        == BLUETOOTH_ERROR_PERMISSION_DEINED) {
                BT_ERR("Don't have aprivilege to use this API");
                return BLUETOOTH_ERROR_PERMISSION_DEINED;
        }
 
-       register_pending_cnt++;
-
-       if (__bt_gatt_get_service_state(svc_path)) {
-               BT_DBG("service already registered \n");
-               return BLUETOOTH_ERROR_NONE;
+       svc_info = __bt_gatt_find_gatt_service_info(svc_path);
+       if (svc_info == NULL) {
+               BT_ERR("Cannot find service [%s]", svc_path);
+               return BLUETOOTH_ERROR_INTERNAL;
        }
-
-       __bt_gatt_set_service_state(svc_path, TRUE);
+       svc_info->is_svc_registered = TRUE;
 
        return BLUETOOTH_ERROR_NONE;
 }
@@ -2452,17 +2253,28 @@ BT_EXPORT_API int bluetooth_gatt_register_application(void)
        GDBusProxy *proxy = NULL;
 
        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;
                }
 
+               if (g_slist_length(gatt_services) == 0) {
+                       BT_ERR("There is no registered service");
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+
+               if (app_path == NULL) {
+                       BT_ERR("app_path is NULL");
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+
                proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
                                "/org/bluez/hci0", GATT_MNGR_INTERFACE);
-               if (proxy == NULL || app_path == NULL)
+               if (proxy == NULL) {
+                       BT_ERR("proxy is NULL");
                        return BLUETOOTH_ERROR_INTERNAL;
+               }
 
                BT_INFO("RegisterApplication");
 
@@ -2470,17 +2282,12 @@ BT_EXPORT_API int bluetooth_gatt_register_application(void)
                        g_cancellable_cancel(register_cancel);
                        g_object_unref(register_cancel);
                }
-
                register_cancel = g_cancellable_new();
 
-               g_dbus_proxy_call(proxy,
-                               "RegisterApplication",
-                               g_variant_new("(oa{sv})",
-                                       app_path, NULL),
-                               G_DBUS_CALL_FLAGS_NONE, -1,
-                               register_cancel,
-                               (GAsyncReadyCallback) register_application_cb,
-                               NULL);
+               g_dbus_proxy_call(proxy, "RegisterApplication",
+                               g_variant_new("(oa{sv})", app_path, NULL),
+                               G_DBUS_CALL_FLAGS_NONE, -1, register_cancel,
+                               (GAsyncReadyCallback)register_application_cb, NULL);
 
                is_server_started = true;
 
@@ -2495,33 +2302,31 @@ BT_EXPORT_API int bluetooth_gatt_register_application(void)
 BT_EXPORT_API int bluetooth_gatt_delete_services(void)
 {
        GSList *l;
-       int error = BLUETOOTH_ERROR_NONE;
-       l = gatt_services;
-
-       if (l != NULL) {
-               for (l = gatt_services; l != NULL; l = l->next) {
-                       struct gatt_service_info *info = l->data;
-                       BT_DBG("svc_path is %s", info->serv_path);
-                       if (bluetooth_gatt_unregister_service(info->serv_path)
-                                       != BLUETOOTH_ERROR_NONE) {
-                               error = BLUETOOTH_ERROR_INTERNAL;
-                               BT_ERR("Error in removing service %s \n",
-                                                info->serv_path);
-                       }
+       int ret = BLUETOOTH_ERROR_NONE;
+
+       if (gatt_services == NULL) {
+               BT_DBG("There are no registered services");
+               serv_id = 1;
+               return ret;
+       }
+
+       for (l = gatt_services; l != NULL; ) {
+               struct gatt_service_info *info = l->data;
+
+               // In __bt_gatt_unregister_service, current node will be removed.
+               // Go forward to next node before calling __bt_gatt_unregister_service.
+               l = l->next;
+               if (__bt_gatt_unregister_service(info) != BLUETOOTH_ERROR_NONE) {
+                       ret = BLUETOOTH_ERROR_INTERNAL;
                }
-               BT_DBG(" All services removed successfully.\n ");
-       } else {
-               BT_DBG(" There are no registered services.\n ");
        }
+       BT_INFO("All services are removed : %d", ret);
 
        g_slist_free(gatt_services);
        gatt_services = NULL;
        serv_id = 1;
 
-       if (error != BLUETOOTH_ERROR_NONE)
-               return error;
-
-       return BLUETOOTH_ERROR_NONE;
+       return ret;
 }
 
 BT_EXPORT_API int bluetooth_gatt_update_characteristic(
@@ -2543,8 +2348,8 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
        line_argv = g_strsplit_set(char_path, "/", 0);
        serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
 
-       if (!__bt_gatt_get_service_state(serv_path)) {
-               BT_DBG("service not registered for this characteristic \n");
+       if (!__bt_gatt_is_service_registered(serv_path)) {
+               BT_DBG("service not registered for this characteristic");
                g_free(serv_path);
                g_strfreev(line_argv);
                return BLUETOOTH_ERROR_INTERNAL;
@@ -2562,7 +2367,7 @@ BT_EXPORT_API int bluetooth_gatt_update_characteristic(
        g_variant_builder_add(outer_builder, "{sv}", "Value",
                                        update_value);
 
-       BT_DBG("Updating characteristic value \n");
+       BT_DBG("Updating characteristic value");
        ret = g_dbus_connection_emit_signal(g_conn, NULL,
                                        char_path,
                                        "org.freedesktop.DBus.Properties",
@@ -2667,98 +2472,103 @@ static void __bt_gatt_free_service_info(struct gatt_service_info *svc_info)
        g_free(svc_info);
 }
 
-BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
+static void __desc_info_free(gpointer data, gpointer user_data)
 {
-       GSList *l, *l1;
-       struct gatt_service_info *svc_info;
-       gboolean ret;
-       int err = BLUETOOTH_ERROR_NONE;
-
-       BT_DBG("svc_path %s", svc_path);
-       svc_info = __bt_gatt_find_gatt_service_info(svc_path);
+       struct gatt_desc_info *desc_info = data;
+       int *err = user_data;
+       int ret;
 
-       if (!svc_info) {
-               BT_ERR("Unable to find service info");
-               return BLUETOOTH_ERROR_NOT_FOUND;
-       }
+       if (desc_info == NULL)
+               return;
 
-       err = __bt_gatt_unregister_service(svc_path);
-       if (err != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("Could not unregister application");
-               return err;
+       ret = g_dbus_connection_unregister_object(g_conn, desc_info->desc_id);
+       if (ret) {
+               __bt_gatt_emit_interface_removed(desc_info->desc_path, GATT_DESC_INTERFACE);
+       } else {
+               *err = BLUETOOTH_ERROR_INTERNAL;
        }
+       __bt_gatt_free_descriptor_info(desc_info);
+}
 
-       for (l = svc_info->char_data; l != NULL; l = l->next) {
-               struct gatt_char_info *char_info = l->data;
-
-               if (char_info == NULL)
-                       break;
-
-               for (l1 = char_info->desc_data; l1 != NULL; l1 = l1->next) {
-                       struct gatt_desc_info *desc_info = l1->data;
+static void __char_info_free(gpointer data, gpointer user_data)
+{
+       struct gatt_char_info *char_info = data;
+       int *err = user_data;
+       int ret;
 
-                       if (desc_info == NULL)
-                               break;
+       if (char_info == NULL)
+               return;
 
-                       ret = g_dbus_connection_unregister_object(g_conn,
-                                               desc_info->desc_id);
-                       if (ret) {
-                               __bt_gatt_emit_interface_removed(
-                                               desc_info->desc_path,
-                                               GATT_DESC_INTERFACE);
-                       } else {
-                               err = BLUETOOTH_ERROR_INTERNAL;
-                       }
+       g_slist_foreach(char_info->desc_data, __desc_info_free, user_data);
+       g_slist_free(char_info->desc_data);
+       char_info->desc_data = NULL;
 
-                       /* list remove & free */
-                       char_info->desc_data = g_slist_remove(char_info->desc_data, desc_info);
-                       __bt_gatt_free_descriptor_info(desc_info);
-               }
+       ret = g_dbus_connection_unregister_object(g_conn, char_info->char_id);
+       if (ret) {
+               __bt_gatt_emit_interface_removed(char_info->char_path, GATT_CHAR_INTERFACE);
+       } else {
+               *err = BLUETOOTH_ERROR_INTERNAL;
+       }
+       __bt_gatt_free_characteristic_info(char_info);
+}
 
-               g_slist_free(char_info->desc_data);
-               char_info->desc_data = NULL;
+static int __bt_gatt_unregister_service(struct gatt_service_info *svc_info)
+{
+       int ret = BLUETOOTH_ERROR_NONE;
 
-               ret = g_dbus_connection_unregister_object(g_conn,
-                                       char_info->char_id);
-               if (ret) {
-                       __bt_gatt_emit_interface_removed(char_info->char_path,
-                                               GATT_CHAR_INTERFACE);
-               } else {
-                       err = BLUETOOTH_ERROR_INTERNAL;
-               }
+       if (svc_info == NULL) {
+               BT_ERR("svc_info is NULL");
+               return BLUETOOTH_ERROR_NOT_FOUND;
+       }
 
-               /* list remove & free */
-               svc_info->char_data = g_slist_remove(svc_info->char_data, char_info);
-               __bt_gatt_free_characteristic_info(char_info);
+       if (svc_info->is_svc_registered == FALSE) {
+               BT_ERR("%s is not registered", svc_info->serv_path);
+               return BLUETOOTH_ERROR_NOT_FOUND;
        }
 
+       BT_DBG("svc_path %s", svc_info->serv_path);
+
+       g_slist_foreach(svc_info->char_data, __char_info_free, &ret);
        g_slist_free(svc_info->char_data);
        svc_info->char_data = NULL;
 
-       ret = g_dbus_connection_unregister_object(g_conn, svc_info->serv_id);
-       if (ret) {
-               __bt_gatt_emit_interface_removed(svc_info->serv_path,
-                                               GATT_SERV_INTERFACE);
+       if (g_dbus_connection_unregister_object(g_conn, svc_info->serv_id) == FALSE) {
+               BT_ERR("Cannot unregister object for [%s]", svc_info->serv_path);
+               ret = BLUETOOTH_ERROR_INTERNAL;
        } else {
-               err = BLUETOOTH_ERROR_INTERNAL;
+               __bt_gatt_emit_interface_removed(svc_info->serv_path, GATT_SERV_INTERFACE);
        }
 
-       ret = g_dbus_connection_unregister_object(g_conn, svc_info->prop_id);
-       if (ret)
-               BT_DBG("Unregistered the service on properties interface");
-
-       /* list remove & free */
        gatt_services = g_slist_remove(gatt_services, svc_info);
        __bt_gatt_free_service_info(svc_info);
 
        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;
+       return ret;
+}
+
+BT_EXPORT_API int bluetooth_gatt_unregister_service(const char *svc_path)
+{
+       struct gatt_service_info *svc_info;
+       int ret = BLUETOOTH_ERROR_NONE;
+
+       BT_DBG("+");
+
+       svc_info = __bt_gatt_find_gatt_service_info(svc_path);
+
+       ret = __bt_gatt_unregister_service(svc_info);
+       if (ret != BLUETOOTH_ERROR_NONE) {
+               BT_ERR("Could not unregister service [%s]", svc_path);
+       }
+
+       BT_DBG("-");
+       return ret;
 }
 
 BT_EXPORT_API int bluetooth_gatt_send_response(int request_id, guint req_type,
@@ -2839,8 +2649,8 @@ BT_EXPORT_API int bluetooth_gatt_server_set_notification(const char *char_path,
        line_argv = g_strsplit_set(char_path, "/", 0);
        serv_path = g_strdup_printf("/%s/%s/%s", line_argv[1], line_argv[2], line_argv[3]);
 
-       if (!__bt_gatt_get_service_state(serv_path)) {
-               BT_DBG("service not registered for this characteristic \n");
+       if (!__bt_gatt_is_service_registered(serv_path)) {
+               BT_DBG("service not registered for this characteristic");
                g_free(serv_path);
                g_strfreev(line_argv);
                return BLUETOOTH_ERROR_INTERNAL;
@@ -2861,7 +2671,7 @@ BT_EXPORT_API int bluetooth_gatt_server_set_notification(const char *char_path,
        g_variant_builder_add(outer_builder, "{sv}", "Unicast",
                                g_variant_new("s", addr));
 
-       BT_DBG("Set characteristic Notification \n");
+       BT_DBG("Set characteristic Notification");
        ret = g_dbus_connection_emit_signal(g_conn, NULL,
                                        char_path,
                                        "org.freedesktop.DBus.Properties",
@@ -2888,41 +2698,6 @@ 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)
 {
@@ -3021,12 +2796,8 @@ BT_EXPORT_API int bluetooth_gatt_server_add_new_characteristic(const char *char_
 
        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);
@@ -3131,7 +2902,7 @@ BT_EXPORT_API int bluetooth_gatt_server_send_response(const bluetooth_gatt_serve
 }
 
 BT_EXPORT_API int bluetooth_gatt_server_send_indication(bluetooth_device_address_t *addr_hex,
-               const bluetooth_gatt_server_indication_params_t *param,
+               bluetooth_gatt_server_indication_params_t *param,
                const bluetooth_gatt_att_data_t *att_value)
 {
        BT_CHECK_PARAMETER(param, return);
@@ -3149,13 +2920,21 @@ BT_EXPORT_API int bluetooth_gatt_server_send_indication(bluetooth_device_address
        g_array_append_vals(in_param3, addr_hex, sizeof(bluetooth_device_address_t));
 
        _bt_convert_addr_type_to_string(addr, addr_hex->addr);
+       BT_INFO("Send Indication to address [%s]", addr);
        fd =  bluetooth_get_characteristic_fd(param->atrribute_handle, addr);
 
-       if (fd > -1)
+       if (fd > -1) {
+               BT_INFO("Send Multicast");
                result  = bluetooth_gatt_write_characteristics_value_to_fd_(fd, att_value->data, att_value->length, NULL);
-       else
+               param->fd = fd;
+       } else if (fd == -2) {
+               BT_ERR("Acquire Notify FD not found for charatcristic handle");
+               BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+               return BLUETOOTH_ERROR_INVALID_PARAM;
+       } else if (fd == -1) {
                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);
 
@@ -3251,7 +3030,20 @@ static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
 
        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);
+       BT_DBG("FD io write data  received [%s]", write_data->address);
+
+       if (cond & G_IO_NVAL) {
+               BT_ERR("Invalid channel");
+               return FALSE;
+       }
+
+       if (cond & (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;
+       }
 
        if (cond & G_IO_IN) {
                GIOStatus status = G_IO_STATUS_NORMAL;
@@ -3284,10 +3076,6 @@ static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
                }
 
                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);
@@ -3301,8 +3089,6 @@ static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
                        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);
 
@@ -3314,22 +3100,12 @@ static gboolean bluetooth_gatt_server_acquire_channel_write_cb(GIOChannel *gio,
                        } 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;
 }
 
@@ -3377,7 +3153,7 @@ void  bluetooth_gatt_server_send_acquire_write_response(GVariant * parameters)
        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))  ;
+       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;
@@ -3387,7 +3163,6 @@ void  bluetooth_gatt_server_send_acquire_write_response(GVariant * parameters)
 
        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);
@@ -3396,9 +3171,8 @@ void  bluetooth_gatt_server_send_acquire_write_response(GVariant * parameters)
        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;
+       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);
@@ -3412,94 +3186,143 @@ void  bluetooth_gatt_server_send_acquire_write_response(GVariant * parameters)
                        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);
-
+       g_object_unref(fd_list);
 }
 
+void  bluetooth_gatt_server_send_acquire_notify_response(GVariant * parameters, bt_event_info_t *event_info)
+{
+       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;
+       const char *address = NULL;
+
+       g_variant_get(parameters, "(iiiiii&s)",
+                                       &result,
+                                       &con_id,
+                                       &tran_id,
+                                       &att_han,
+                                       &mtu,
+                                       &offset,
+                                       &address);
+
+               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);
+               BT_DBG("GATT Server Acquire Notify address:    [%s]", address);
 
 
-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 ;
-                               }
+       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", pipefd[0]);
+
+       chr_info = bluetooth_get_characteristic_info_from_path(att_han);
+       if (!chr_info) {
+               BT_INFO("char info not found for ATT handle [%u]", att_han);
+               chr_info = g_malloc0(sizeof(bluetooth_gatt_acquire_notify_info_t));
+               chr_info->write_fd = fd;
+               chr_info->att_hand = att_han;
+               memcpy(chr_info->address, address, BLUETOOTH_ADDRESS_STRING_LENGTH);
 
-                               fd = pipefd[0];
+               gatt_characteristic_server_notify_list = g_slist_append(gatt_characteristic_server_notify_list, chr_info);
+       } else {
+               BT_INFO("Already AcquireNotify Set for this attribute handle by remote Client [%s]", chr_info->address);
+               chr_info->write_fd = fd;
+       }
+
+       channel = g_io_channel_unix_new(fd);
+       chr_info->io_channel = channel;
+       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);
+       chr_info->watch_id =
+               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);
 
-                               BT_INIT_PARAMS();
-                               BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       GUnixFDList *fd_list = g_unix_fd_list_new();
+       GError *error = NULL;
 
-                               //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;
+       g_unix_fd_list_append(fd_list, pipefd[1], &error);
+       g_assert_no_error(error);
+       close(pipefd[1]);
 
-                               BT_INFO("FD write %d   characterstics path   \n", pipefd[0]);
+       g_array_append_vals(in_param1, &data, sizeof(bluetooth_gatt_server_acquire_response_params_t));
 
-                               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;
+       BT_DBG("Sending event BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE file descriptor value [%d] ", data.fd);
 
-                                       gatt_characteristic_server_notify_list = g_slist_append(gatt_characteristic_server_notify_list, chr_info);
-                               } else
-                                       chr_info->write_fd = 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);
+       g_object_unref(fd_list);
 
-                               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);
+       //send
+       if (result == BLUETOOTH_ERROR_NONE) {
+               BT_DBG("sending gatt server notification state changed event");
+               bluetooth_gatt_server_notification_changed_t info;
+               bluetooth_device_address_t dev_address = { {0} };
+               memset(&info, 0x00, sizeof(bluetooth_gatt_server_notification_changed_t));
 
+               _bt_convert_addr_string_to_type(dev_address.addr, address);
+               memcpy(info.device_address.addr,
+                               dev_address.addr,
+                               BLUETOOTH_ADDRESS_LENGTH);
+               info.handle = att_han;
+               info.notification = TRUE;
 
+               _bt_gatt_server_event_cb(BLUETOOTH_EVENT_GATT_SERVER_NOTIFICATION_STATE_CHANGED,
+                               result, &info,
+                               event_info->cb, event_info->user_data);
 
+       }
+}
 
-                                GUnixFDList *fd_list = g_unix_fd_list_new();
-                                GError *error = NULL;
+void cleanup_gatt_acquire_fd(int handle)
+{
+       bluetooth_gatt_acquire_notify_info_t *chr_info = NULL;
 
-                               g_unix_fd_list_append(fd_list, pipefd[1], &error);
-                               g_assert_no_error(error);
-                               close(pipefd[1]);
+       BT_INFO("+");
 
-                               g_array_append_vals(in_param1, &data, sizeof(bluetooth_gatt_server_acquire_response_params_t));
+       chr_info = bluetooth_get_characteristic_info_from_path(handle);
 
-                               BT_INFO("Sending event BT_GATT_SERVER_ACQUIRE_NOTIFY_RESPONSE file descriptor value [%d] ", data.fd);
+       if (chr_info != NULL) {
+               BT_INFO("GATT Server: acquire notification char info found [%s]", chr_info->path);
 
-                               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);
+               if (chr_info->watch_id > 0)
+                       g_source_remove(chr_info->watch_id);
 
-                               BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+               if (chr_info->io_channel) {
+                       g_io_channel_shutdown(chr_info->io_channel, TRUE, NULL);
+                       g_io_channel_unref(chr_info->io_channel);
+               }
 
+               BT_INFO("Removing char_info from the list");
+               gatt_characteristic_server_notify_list = g_slist_remove(gatt_characteristic_server_notify_list, chr_info);
+               bluetooth_characteristic_info_free(chr_info);
+       }
 }