Handle GATT client app's termination
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-gatt-client.c
index 552ed57..17ccddb 100644 (file)
@@ -123,6 +123,7 @@ typedef struct {
 
 typedef struct {
        bt_bdaddr_t bd_addr;    /*remote server address*/
+       int conn_id;
        int inst_id;            /*server instance id*/
        GSList *gatt_list_services;
 } hal_gattc_server_info_t;
@@ -145,7 +146,12 @@ static guint pending_le_conn_timer_id = 0;
 static int bt_conn_id = 0;
 static int bt_inst_id = 0;
 
-#define BT_GATTC_CL_MAX 32
+/* Should match the range with bt-service-gatt.c's MAX_APPS_SUPPORTED */
+/* TODO: Adjust MAX Client after modifying MAX app handle logic */
+#define BT_GATTC_CL_MAX 11
+
+static int assigned_if = 0;
+static gboolean client_if_used[BT_GATTC_CL_MAX];
 
 typedef struct {
        int conn_id;
@@ -162,8 +168,6 @@ typedef struct {
 
 static GSList * hal_gattc_client_app_list = NULL;
 
-static int bt_client_if = 0;
-
 struct conn_mtu_s {
        int conn_id;
        int mtu;
@@ -184,6 +188,48 @@ static hal_gattc_server_info_t *__bt_find_gatt_conn_info(const bt_bdaddr_t *serv
 static hal_gattc_client_info_t *__bt_find_gatt_client_info(bt_bdaddr_t *serv_addr);
 static hal_gattc_client_info_t *__bt_find_gatt_client_info_from_conn_id(int conn_id);
 
+void _bt_hal_gatt_client_init(void)
+{
+       assigned_if = 0;
+       memset(client_if_used, 0x00, sizeof(client_if_used));
+}
+
+static int __bt_hal_gatt_assign_if(void)
+{
+       int index;
+
+       index = assigned_if + 1;
+
+       if (index >= BT_GATTC_CL_MAX)
+               index = 1;
+
+       while (client_if_used[index] == TRUE) {
+               if (index == assigned_if) {
+                       /* No available ID */
+                       ERR("All interface ID is used");
+                       return -1;
+               }
+
+               index++;
+
+               if (index >= BT_GATTC_CL_MAX)
+                       index = 1;
+       }
+
+       assigned_if = index;
+       client_if_used[index] = TRUE;
+
+       return assigned_if;
+}
+
+static void __bt_hal_gatt_delete_if(int client_if)
+{
+       if (client_if >= BT_GATTC_CL_MAX || client_if < 0)
+               return;
+
+       client_if_used[client_if] = FALSE;
+}
+
 
 /* To send stack event to hal-av handler */
 void _bt_hal_register_gatt_client_handler_cb(handle_stack_msg cb)
@@ -208,7 +254,6 @@ static gboolean __bt_hal_register_client_cb(gpointer user_data)
        struct hal_ev_gatt_client_registered ev;
        hal_gatt_client_app *client_info = user_data;
 
-       DBG("+");
        /* Prepare to send AV connecting event */
        memset(&ev, 0, sizeof(ev));
        ev.status = BT_STATUS_SUCCESS;
@@ -226,14 +271,10 @@ static gboolean __bt_hal_register_client_cb(gpointer user_data)
        return FALSE;
 }
 
-static int __hal_generate_client_id()
-{
-       return ++bt_client_if;
-}
-
 static hal_gatt_client_app *__hal_gattc_add_client_app(bt_uuid_t *app_uuid)
 {
        GSList *l;
+       int client_if = 0;
        hal_gatt_client_app *info = NULL;
        hal_gatt_client_app *gattc_app = NULL;
 
@@ -249,11 +290,17 @@ static hal_gatt_client_app *__hal_gattc_add_client_app(bt_uuid_t *app_uuid)
                }
        }
 
+       client_if = __bt_hal_gatt_assign_if();
+       if (client_if == -1) {
+               ERR("Fail to allocate the client if");
+               return NULL;
+       }
+
        DBG("adding the gatt client app");
 
        //add client app
        gattc_app = g_malloc0(sizeof(hal_gatt_client_app));
-       gattc_app->client_if = __hal_generate_client_id();
+       gattc_app->client_if = client_if;
        memcpy(&gattc_app->app_uuid, app_uuid, sizeof(bt_uuid_t));
 
        hal_gattc_client_app_list = g_slist_append(hal_gattc_client_app_list, gattc_app);
@@ -266,7 +313,6 @@ static bt_status_t __hal_gattc_register_client_app(bt_uuid_t *app_uuid)
        hal_gatt_client_app *gattc_app = NULL;
        hal_gatt_client_app *client_app_info = NULL;
 
-       DBG("+");
        /* add gatt client in list */
        gattc_app = __hal_gattc_add_client_app(app_uuid);
        if (gattc_app == NULL) {
@@ -289,7 +335,6 @@ static bt_status_t __hal_gattc_register_client_app(bt_uuid_t *app_uuid)
 bt_status_t btif_gattc_register_client(bt_uuid_t *uuid)
 {
        CHECK_BTGATT_INIT();
-       DBG("+");
 
        return __hal_gattc_register_client_app(uuid);
 }
@@ -306,14 +351,19 @@ bt_status_t btif_gattc_add_connection_info(const bt_bdaddr_t *bd_addr, int conn_
        client_info->conn_id = conn_id;
        client_info->inst_id = server_inst_id;
        hal_gattc_client_info_list = g_slist_append(hal_gattc_client_info_list, client_info);
+       DBG("Added client connection info in list");
 
        /* Add server connection info in list */
-       server_info = g_malloc0(sizeof(hal_gattc_server_info_t));
-       memcpy(server_info->bd_addr.address, bd_addr->address, BT_HAL_ADDRESS_LENGTH_MAX);
-       server_info->inst_id = server_inst_id;
-       hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, server_info);
+       server_info = __bt_find_gatt_conn_info(bd_addr);
+       if (server_info == NULL) {
+               server_info = g_malloc0(sizeof(hal_gattc_server_info_t));
+               memcpy(server_info->bd_addr.address, bd_addr->address, BT_HAL_ADDRESS_LENGTH_MAX);
+               server_info->conn_id = conn_id;
+               server_info->inst_id = server_inst_id;
+               hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, server_info);
+               DBG("Added server connection info in list");
+       }
 
-       DBG("Added client/server connection info in list");
        return BT_STATUS_SUCCESS;
 }
 
@@ -334,6 +384,9 @@ bt_status_t __hal_gattc_unregister_client(int client_if)
 
                if (info->client_if == client_if) {
                        DBG("gatt client app found");
+
+                       __bt_hal_gatt_delete_if(client_if);
+
                        hal_gattc_client_app_list = g_slist_remove(hal_gattc_client_app_list, info);
                        g_free(info);
                }
@@ -347,7 +400,6 @@ bt_status_t __hal_gattc_unregister_client(int client_if)
 bt_status_t btif_gattc_unregister_client(int client_if)
 {
        CHECK_BTGATT_INIT();
-       DBG("+");
 
        return __hal_gattc_unregister_client(client_if);
 }
@@ -374,7 +426,6 @@ bt_status_t btif_gattc_client_connect(int client_if, const bt_bdaddr_t *bd_addr,
        int ret = BT_STATUS_SUCCESS;
 
        CHECK_BTGATT_INIT();
-       DBG("+");
 
        if (NULL == bd_addr)
                return BT_STATUS_PARM_INVALID;
@@ -516,8 +567,6 @@ bt_status_t btif_gattc_client_disconnect(int client_if, const bt_bdaddr_t *bd_ad
 {
        CHECK_BTGATT_INIT();
 
-       DBG("+");
-
        return _hal_gattc_disconnect(client_if, bd_addr, conn_id);
 }
 
@@ -530,8 +579,6 @@ bt_status_t refresh(int client_if, const bt_bdaddr_t *bd_addr)
 
 static hal_gattc_service_t* _gattc_find_service_from_uuid(hal_gattc_server_info_t *conn_info, bt_uuid_t *svc_uuid)
 {
-       DBG("+");
-
        GSList *l;
        hal_gattc_service_t *info = NULL;
 
@@ -540,11 +587,10 @@ static hal_gattc_service_t* _gattc_find_service_from_uuid(hal_gattc_server_info_
                if (info == NULL)
                        continue;
 
-               if (!memcmp(&info->svc_uuid, svc_uuid, sizeof(bt_uuid_t))) {
-                       INFO("Found GATT service uuid");
+               if (!memcmp(&info->svc_uuid, svc_uuid, sizeof(bt_uuid_t)))
                        return info;
                }
-       }
+
        return NULL;
 }
 
@@ -552,8 +598,6 @@ static hal_gattc_service_t* _gattc_find_service_from_uuid(hal_gattc_server_info_
 static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_svc, bt_uuid_t *char_uuid,
                                bt_gatt_characteristic_property_t prop)
 {
-       DBG("+");
-
        GSList *l;
        hal_gattc_char_t *info = NULL;
 
@@ -564,7 +608,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_s
 
                if (!memcmp(&info->chr_uuid, char_uuid, sizeof(bt_uuid_t)) &&
                        (info->permission & prop)) {
-                       INFO("Found GATT char uuid");
                        return info;
                }
        }
@@ -573,8 +616,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid(hal_gattc_service_t *gattc_s
 
 static hal_gattc_char_t* _gattc_find_char_from_uuid_for_notify(hal_gattc_service_t *gattc_svc, bt_uuid_t *char_uuid)
 {
-       DBG("+");
-
        GSList *l;
        hal_gattc_char_t *info = NULL;
 
@@ -586,7 +627,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid_for_notify(hal_gattc_service
                if (!memcmp(&info->chr_uuid, char_uuid, sizeof(bt_uuid_t)) &&
                        ((info->permission & HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY) ||
                                (info->permission & HAL_GATT_CHARACTERISTIC_PROPERTY_INDICATE))) {
-                       INFO("Found GATT char uuid");
                        return info;
                }
        }
@@ -595,8 +635,6 @@ static hal_gattc_char_t* _gattc_find_char_from_uuid_for_notify(hal_gattc_service
 
 static hal_gattc_desc_t* _gattc_find_desc_from_uuid(hal_gattc_char_t *gattc_char, bt_uuid_t *desc_uuid)
 {
-       DBG("+");
-
        GSList *l;
        hal_gattc_desc_t *info = NULL;
 
@@ -605,11 +643,9 @@ static hal_gattc_desc_t* _gattc_find_desc_from_uuid(hal_gattc_char_t *gattc_char
                if (info == NULL)
                        continue;
 
-               if (!memcmp(&info->desc_uuid, desc_uuid, sizeof(bt_uuid_t))) {
-                       INFO("Found GATT descriptor uuid");
+               if (!memcmp(&info->desc_uuid, desc_uuid, sizeof(bt_uuid_t)))
                        return info;
                }
-       }
        return NULL;
 }
 
@@ -617,7 +653,6 @@ static hal_gattc_desc_t* _gattc_find_desc_from_uuid(hal_gattc_char_t *gattc_char
 static hal_gattc_service_t* _hal_gatt_client_add_service(hal_gattc_server_info_t *conn_info,
                const char *uuid_str, const char *object_path, int is_primary)
 {
-       DBG("+");
        hal_gattc_service_t *gattc_service = NULL;
 
        gattc_service = g_malloc0(sizeof(hal_gattc_service_t));
@@ -625,18 +660,15 @@ static hal_gattc_service_t* _hal_gatt_client_add_service(hal_gattc_server_info_t
        _bt_hal_convert_uuid_string_to_type(gattc_service->svc_uuid.uu, uuid_str);
        gattc_service->is_primary = is_primary;
 
-       DBG("service count[%d]", g_slist_length(conn_info->gatt_list_services));
+       INFO("[%d] [%s] [%s]", g_slist_length(conn_info->gatt_list_services), object_path + 15, uuid_str);
 
        conn_info->gatt_list_services = g_slist_append(conn_info->gatt_list_services, gattc_service);
 
-       DBG("svc path [%s] svc uuid [%s]", object_path, uuid_str);
-
        return gattc_service;
 }
 
 static void _hal_gattc_add_characteristic(hal_gattc_service_t *gatt_svc, char *char_handle)
 {
-       DBG("+");
        hal_gattc_char_t *gattc_char = NULL;
 
        gattc_char = g_malloc0(sizeof(hal_gattc_char_t));
@@ -655,8 +687,6 @@ static void _gattc_create_new_service(hal_gattc_server_info_t *conn_info, gboole
        int i;
        gchar *gp_char_path = NULL;
 
-       DBG("+");
-
        /* add the service */
        gatt_svc = _hal_gatt_client_add_service(conn_info, uuid_str, object_path, is_primary);
        if (gatt_svc == NULL) {
@@ -681,9 +711,6 @@ static void _hal_gattc_add_descriptor(hal_gattc_char_t *gattc_char, char *desc_p
        gattc_desc->desc_path = g_strdup(desc_path);
 
        gattc_char->gatt_list_descs = g_slist_append(gattc_char->gatt_list_descs, gattc_desc);
-
-       DBG("char path: [%s]", gattc_char->chr_path);
-       DBG("desc path: [%s]", gattc_desc->desc_path);
 }
 
 static void _hal_gattc_update_char_property(hal_gattc_char_t *gattc_char, const char* char_uuid_str,
@@ -692,17 +719,12 @@ static void _hal_gattc_update_char_property(hal_gattc_char_t *gattc_char, const
        gchar *gp_desc_path = NULL;
        int i;
 
-       DBG("+");
-
        if (char_uuid_str == NULL) {
                DBG("char_uuid_str is NULL");
                return;
        }
 
        //update the char uuid
-       DBG("char UUID: [%s] ", char_uuid_str);
-       DBG("char path: [%s]", gattc_char->chr_path);
-
        _bt_hal_convert_uuid_string_to_type(gattc_char->chr_uuid.uu, char_uuid_str);
 
        //update char permission
@@ -717,8 +739,6 @@ static void _hal_gattc_update_char_property(hal_gattc_char_t *gattc_char, const
 
 static void _hal_gattc_update_desc_property(hal_gattc_desc_t *gattc_desc, const char* desc_uuid_str)
 {
-       DBG("+");
-
        if (desc_uuid_str == NULL) {
                DBG("char_uuid_str is NULL");
                return;
@@ -743,34 +763,26 @@ static void browse_service_char(int conn_id)
 
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (conn_info == NULL) {
-               ERR("conn_info is NULL");
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return;
        }
 
-       DBG("service count[%d]", g_slist_length(conn_info->gatt_list_services));
-
        for (l = conn_info->gatt_list_services; l != NULL; l = g_slist_next(l)) {
                svc_info = (hal_gattc_service_t*)l->data;
                if (svc_info == NULL)
                        continue;
 
-               DBG("[%s]", svc_info->svc_path);
-
                /* find characteristic object path */
                for (k = svc_info->gatt_list_chars; k != NULL; k = g_slist_next(k)) {
                        char_info = (hal_gattc_char_t *)k->data;
                        if (char_info == NULL)
                                continue;
 
-                       DBG("[%s]", char_info->chr_path);
-
                        /* descriptor */
                        for (m = char_info->gatt_list_descs; m != NULL; m = g_slist_next(m)) {
                                desc_info = (hal_gattc_desc_t *)m->data;
                                if (desc_info == NULL)
                                        continue;
-
-                               DBG("[%s]", desc_info->desc_path);
                        }
                }
        }
@@ -809,14 +821,35 @@ static bt_status_t _gattc_client_search_service(int conn_id)
        GVariantIter *char_iter = NULL;
        GPtrArray *gp_char_array  = NULL;
 
-       DBG("+");
-
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info");
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
+#if 0
+       // TODO: This logic is not able to handle in case service-added event is coming unexpectedly.
+       /* Check the service info is stored */
+       if (g_slist_length(conn_info->gatt_list_services) > 0) {
+               GSList *l = NULL;
+               hal_gattc_service_t *svc_info = NULL;
+               char svc_uuid_str[BT_HAL_UUID_STRING_LEN] = {0, };
+               DBG("Send event from service info list");
+               for (l = conn_info->gatt_list_services; l != NULL; l = g_slist_next(l)) {
+                       svc_info = l->data;
+                       if (svc_info == NULL)
+                               continue;
+                       _bt_hal_convert_uuid_type_to_string(svc_uuid_str, svc_info->svc_uuid.uu);
+                       _bt_hal_send_search_service_result_event(conn_id,
+                                       svc_info->is_primary, svc_uuid_str, conn_info->inst_id);
+               }
+               _bt_hal_send_search_service_complete_event(conn_id, BT_STATUS_SUCCESS);
+               return BT_STATUS_SUCCESS;
+       } else {
+               DBG("No stored service, request to bluez");
+       }
+#endif
+
        _bt_hal_convert_addr_type_to_string(device_address,
                        (unsigned char *)conn_info->bd_addr.address);
 
@@ -848,19 +881,16 @@ static bt_status_t _gattc_client_search_service(int conn_id)
                        while (g_variant_iter_loop(svc_iter, "{sv}", &key, &value)) {
                                if (g_strcmp0(key, "Primary") == 0) {
                                        is_primary = g_variant_get_boolean(value);
-                                       DBG("primary");
                                        if (is_primary) {
                                                g_ptr_array_add(gp_array, (gpointer)object_path);
                                                svc_count++;
                                        }
                                } else if (g_strcmp0(key, "UUID") == 0) {
                                        uuid_str = g_variant_get_string(value, &len);
-                                       DBG(" UUID: [%s]", uuid_str);
                                } else if (g_strcmp0(key, "Characteristics") == 0) {
                                        g_variant_get(value, "ao", &char_iter);
                                        if (char_iter != NULL) {
                                                while (g_variant_iter_loop(char_iter, "&o", &char_handle)) {
-                                                       DBG("char handle : %s", char_handle);
                                                        g_ptr_array_add(gp_char_array, (gpointer)char_handle);
                                                }
                                        }
@@ -868,7 +898,6 @@ static bt_status_t _gattc_client_search_service(int conn_id)
                        }
 
                        if (uuid_str) {
-                               DBG("send search service result event");
                                _bt_hal_send_search_service_result_event(conn_id, is_primary,
                                                uuid_str, conn_info->inst_id);
 
@@ -926,8 +955,6 @@ static void _bt_hal_send_client_char_search_result_event(int conn_id, int status
                return;
        }
 
-       DBG("sending gatt client search char result event conn_id[%d] status[%d]", conn_id, status);
-
        memset(&ev, 0, sizeof(ev));
        ev.conn_id = conn_id;
        ev.inst_id = svc_id->id.inst_id;
@@ -936,13 +963,12 @@ static void _bt_hal_send_client_char_search_result_event(int conn_id, int status
        memcpy(ev.svc_uuid, svc_id->id.uuid.uu, sizeof(ev.svc_uuid));
 
        if (status == BT_STATUS_SUCCESS) {
-               DBG("building char uuid");
+               /* building char uuid */
                memcpy(ev.char_uuid, char_uuid->uu, sizeof(ev.char_uuid));
                ev.char_prop = char_prop;
        }
 
-       DBG("sending the char search event");
-
+       DBG("sending the char search event.  conn_id[%d] status[%d]", conn_id, status);
        event_cb(HAL_EV_GATT_CLIENT_CHARAC_SEARCH_RESULT, (void *)&ev, sizeof(ev));
 }
 
@@ -985,6 +1011,40 @@ static int _hal_get_permission_flag(char *permission)
        return ret;
 }
 
+static void __hal_convert_permission_flag_to_str(unsigned int permission)
+{
+       char perm[200] = { 0, };
+
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_BROADCAST)
+               g_strlcat(perm, "broadcast ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_READ)
+               g_strlcat(perm, "read ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE_NO_RESPONSE)
+               g_strlcat(perm, "write-without-response ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE)
+               g_strlcat(perm, "write ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY)
+               g_strlcat(perm, "notify ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_INDICATE)
+               g_strlcat(perm, "indicate ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_SIGNED_WRITE)
+               g_strlcat(perm, "authenticated-signed-writes ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_RELIABLE_WRITE)
+               g_strlcat(perm, "reliable-write ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_WRITABLE_AUXILIARIES)
+               g_strlcat(perm, "writable-auxiliaries ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_READ)
+               g_strlcat(perm, "encrypt-read ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_WRITE)
+               g_strlcat(perm, "encrypt-write ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_READ)
+               g_strlcat(perm, "encrypt-authenticated-read ", sizeof(perm));
+       if (permission & HAL_GATT_CHARACTERISTIC_PROPERTY_ENCRYPT_AUTHENTICATED_WRITE)
+               g_strlcat(perm, "encrypt-authenticated-write ", sizeof(perm));
+
+       DBG("permission [0x%04x] : %s\n", permission, perm);
+       return;
+}
 
 static bt_status_t _hal_gattc_get_characteristic_info(hal_gattc_char_t *gattc_char)
 {
@@ -1011,8 +1071,6 @@ static bt_status_t _hal_gattc_get_characteristic_info(hal_gattc_char_t *gattc_ch
        }
        char_handle = gattc_char->chr_path;
 
-       DBG("char path:[%s]", gattc_char->chr_path);
-
        g_conn = _bt_hal_get_system_gconn();
        if (NULL == g_conn) {
                 ERR("_bt_gdbus_get_system_gconn returned NULL");
@@ -1055,20 +1113,18 @@ static bt_status_t _hal_gattc_get_characteristic_info(hal_gattc_char_t *gattc_ch
        while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
                if (!g_strcmp0(key, "UUID")) {
                        char_uuid_str = g_variant_dup_string(value, &len);
-                       DBG("char UUID [%s]", char_uuid_str);
+                       INFO("%s [%s]", char_handle + 37, char_uuid_str);
                } else if (!g_strcmp0(key, "Flags")) {
                        g_variant_get(value, "as", &char_perm_iter);
                                char_permission = 0x00;
 
                        while (g_variant_iter_loop(char_perm_iter, "s", &permission)) {
-                               DBG("char permission: [%s]", permission);
                                char_permission |= _hal_get_permission_flag(permission);
                        }
+                       __hal_convert_permission_flag_to_str(char_permission);
                } else if (!g_strcmp0(key, "Descriptors")) {
                        g_variant_get(value, "ao", &char_desc_iter);
                        while (g_variant_iter_loop(char_desc_iter, "&o", &char_desc_handle)) {
-                               DBG("char descriptor : %s", char_desc_handle);
-
                                g_ptr_array_add(gp_desc_array, (gpointer)char_desc_handle);
                        }
                }
@@ -1095,11 +1151,9 @@ static bt_status_t _gattc_get_all_characteristic(int conn_id,
        char svc_uuid_str[BT_HAL_UUID_STRING_LEN];
        int status = BT_STATUS_FAIL;
 
-       DBG("conn_id[%d]", conn_id);
-
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -1120,14 +1174,11 @@ static bt_status_t _gattc_get_all_characteristic(int conn_id,
 
                /* send event */
                if (BT_STATUS_SUCCESS == status) {
-                       DBG("Sending the success charateristics event");
                        _bt_hal_send_client_char_search_result_event(conn_id, status, srvc_id,
                                        &gattc_char->chr_uuid, gattc_char->permission);
                }
        }
 
-       DBG("sending final event");
-
        status = BT_STATUS_FAIL;
        _bt_hal_send_client_char_search_result_event(conn_id, status, srvc_id, NULL, 0);
 
@@ -1144,7 +1195,6 @@ static bt_status_t _gattc_get_all_characteristic(int conn_id,
 bt_status_t btif_gattc_get_characteristic(int conn_id,
                btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *start_char_id)
 {
-       DBG("+");
        CHECK_BTGATT_INIT();
 
        if (start_char_id == NULL) {
@@ -1170,16 +1220,12 @@ static bt_status_t _hal_gattc_get_descriptor_info(hal_gattc_desc_t *gattc_desc)
        char* desc_handle = NULL;
        const gchar *desc_uuid_str = NULL;
 
-       DBG("+");
-
        if (gattc_desc->desc_path == NULL) {
                DBG("desc path is NULL");
                return BT_STATUS_FAIL;
        }
        desc_handle = gattc_desc->desc_path;
 
-       DBG("desc path:[%s]", gattc_desc->desc_path);
-
        g_conn = _bt_hal_get_system_gconn();
        if (NULL == g_conn) {
                ERR("_bt_gdbus_get_system_gconn returned NULL");
@@ -1220,7 +1266,6 @@ static bt_status_t _hal_gattc_get_descriptor_info(hal_gattc_desc_t *gattc_desc)
        while (g_variant_iter_loop(property_iter, "{sv}", &key, &value)) {
                if (!g_strcmp0(key, "UUID")) {
                        desc_uuid_str = g_variant_get_string(value, &len);
-                       DBG("desc UUID [%s]", desc_uuid_str);
                        _hal_gattc_update_desc_property(gattc_desc, desc_uuid_str);
                        break;
                }
@@ -1243,8 +1288,6 @@ static void _bt_hal_send_client_desc_search_result_event(int conn_id, int status
                return;
        }
 
-       DBG("sending gatt client search desc result event conn_id[%d] status[%d]", conn_id, status);
-
        memset(&ev, 0, sizeof(ev));
        ev.conn_id = conn_id;
        ev.inst_id = svc_id->id.inst_id;
@@ -1255,11 +1298,11 @@ static void _bt_hal_send_client_desc_search_result_event(int conn_id, int status
        memcpy(ev.char_uuid, char_id->uuid.uu, sizeof(ev.char_uuid));
 
        if (status == BT_STATUS_SUCCESS) {
-               DBG("building desc uuid");
+               /* building desc uuid */
                memcpy(ev.desc_uuid, desc_uuid->uu, sizeof(ev.desc_uuid));
        }
 
-       DBG("sending the desc search event");
+       DBG("sending the desc search event. conn_id[%d] status[%d]", conn_id, status);
 
        event_cb(HAL_EV_GATT_CLIENT_DESC_SEARCH_RESULT, (void *)&ev, sizeof(ev));
 }
@@ -1279,7 +1322,7 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id,
 
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -1314,7 +1357,6 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id,
 
                                /* send event */
                                if (BT_STATUS_SUCCESS == status) {
-                                       DBG("Sending the success descriptor event");
                                        _bt_hal_send_client_desc_search_result_event(conn_id, status, srvc_id,
                                                        char_id, &gattc_desc->desc_uuid);
                                }
@@ -1322,8 +1364,6 @@ static bt_status_t _hal_gattc_get_all_descriptor(int conn_id,
                }
        }
 
-       DBG("sending final event");
-
        status = BT_STATUS_FAIL;
        _bt_hal_send_client_desc_search_result_event(conn_id, status, srvc_id, char_id, NULL);
 
@@ -1341,11 +1381,9 @@ bt_status_t btif_gattc_get_descriptor(int conn_id,
                btgatt_srvc_id_t *srvc_id, btgatt_gatt_id_t *char_id,
                btgatt_gatt_id_t *start_descr_id)
 {
-       DBG("+");
        CHECK_BTGATT_INIT();
 
        if (start_descr_id == NULL) {
-               DBG("Get all the descriptors");
                return _hal_gattc_get_all_descriptor(conn_id, srvc_id, char_id);
        } else {
                DBG("TBD Get specific descriptor");
@@ -1362,8 +1400,6 @@ static void __hal_send_char_read_event(hal_gatt_resp_data_t *resp_data, int resu
                return;
        }
 
-       DBG("sending gatt client charac read conn_id[%d] status[%d]", resp_data->conn_id, result);
-
        memset(&ev, 0, sizeof(ev));
        ev.conn_id = resp_data->conn_id;
        ev.inst_id = resp_data->srvc_id.id.inst_id;
@@ -1375,11 +1411,11 @@ static void __hal_send_char_read_event(hal_gatt_resp_data_t *resp_data, int resu
 
        ev.len = len;
        if (len > 0) {
-               DBG("building the char read value [%d]", len);
+               /* building the char read value */
                memcpy(ev.value, value, len);
        }
 
-       DBG("sending the gatt client read charac event");
+       DBG("sending gatt client charac read event. conn_id[%d] status[%d]", resp_data->conn_id, result);
 
        event_cb(HAL_EV_GATT_CLIENT_READ_CHARAC, (void *)&ev, sizeof(ev));
 }
@@ -1396,8 +1432,6 @@ static void __hal_internal_read_char_cb(GObject *source_object,
        hal_gatt_resp_data_t *resp_data = user_data;
        int result = BT_STATUS_SUCCESS;
 
-       DBG("+");
-
        system_gconn = _bt_hal_get_system_gconn();
        value = g_dbus_connection_call_finish(system_gconn, res, &error);
 
@@ -1418,11 +1452,6 @@ static void __hal_internal_read_char_cb(GObject *source_object,
        while (g_variant_iter_loop(iter, "y", &g_byte))
                g_byte_array_append(gp_byte_array, &g_byte, 1);
 
-/*
-       DBG("value is");
-       for (i = 0; i < gp_byte_array->len; i++)
-               DBG("%02x", gp_byte_array->data[i]);
-*/
 
        //send value  event
        __hal_send_char_read_event(resp_data, result, gp_byte_array->data, gp_byte_array->len);
@@ -1433,10 +1462,8 @@ static void __hal_internal_read_char_cb(GObject *source_object,
        g_variant_iter_free(iter);
        g_variant_unref(value);
 
-       DBG("-");
 }
 
-
 static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t *srvc_id,
                btgatt_gatt_id_t *char_id, int auth_req)
 {
@@ -1454,7 +1481,7 @@ static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t
        /* get the connection info */
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -1466,7 +1493,6 @@ static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t
        }
 
        _bt_hal_convert_uuid_type_to_string(svc_uuid_str, gattc_service->svc_uuid.uu);
-       DBG("%s %s", gattc_service->svc_path + 37, svc_uuid_str);
 
        /* find characteristic */
        gattc_char = _gattc_find_char_from_uuid(gattc_service, &char_id->uuid,
@@ -1498,8 +1524,6 @@ static bt_status_t _hal_read_characteristic_value(int conn_id, btgatt_srvc_id_t
 
        char_handle = gattc_char->chr_path;
 
-       DBG("calling char read value");
-
        g_dbus_connection_call(g_conn, BT_HAL_BLUEZ_NAME, char_handle, BT_HAL_GATT_CHAR_INTERFACE,
                        "ReadValue", g_variant_new("(a{sv})", builder),
                        G_VARIANT_TYPE("(ay)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL,
@@ -1516,7 +1540,6 @@ bt_status_t btif_read_characteristic(int conn_id,
                int auth_req)
 {
        CHECK_BTGATT_INIT();
-       DBG("+");
 
        return _hal_read_characteristic_value(conn_id, srvc_id, char_id, auth_req);
 }
@@ -1530,8 +1553,6 @@ static void __hal_send_char_write_event(hal_gatt_resp_data_t *resp_data, int res
                return;
        }
 
-       DBG("sending gatt client charac write conn_id[%d] status[%d]", resp_data->conn_id, result);
-
        memset(&ev, 0, sizeof(ev));
        ev.conn_id = resp_data->conn_id;
        ev.inst_id = resp_data->srvc_id.id.inst_id;
@@ -1541,7 +1562,7 @@ static void __hal_send_char_write_event(hal_gatt_resp_data_t *resp_data, int res
        memcpy(ev.svc_uuid, resp_data->srvc_id.id.uuid.uu, sizeof(ev.svc_uuid));
        memcpy(ev.char_uuid, resp_data->char_id.uuid.uu, sizeof(ev.char_uuid));
 
-       DBG("sending the gatt client write charac event");
+       DBG("sending gatt client charac write event. conn_id[%d] status[%d]", resp_data->conn_id, result);
 
        event_cb(HAL_EV_GATT_CLIENT_WRITE_CHARAC, (void *)&ev, sizeof(ev));
 }
@@ -1636,7 +1657,7 @@ static int __bluetooth_gatt_acquire_write_fd(const char *chr, int *fd, int *mtu)
        g_variant_get(value, "(hq)", &idx, &att_mtu);
        *fd = g_unix_fd_list_get(fd_list, idx, NULL);
 
-       INFO("FD is %d index is %d mtu is %d", *fd, idx, att_mtu);
+       INFO("Acquired Write fd %d,  index %d, mtu %d", *fd, idx, att_mtu);
        *mtu = att_mtu;
 
        g_object_unref(fd_list);
@@ -1687,7 +1708,7 @@ static int __bluetooth_gatt_acquire_notify_fd(const char *chr, int *fd, int *mtu
        notify_fd = g_unix_fd_list_get(fd_list, idx, NULL);
        *mtu = att_mtu;
 
-       INFO("Acquired characteristic Notify fd %d, mtu %d", notify_fd, *mtu);
+       INFO("Acquired Notify fd %d, mtu %d", notify_fd, *mtu);
 
        *fd = notify_fd;
 
@@ -1718,8 +1739,6 @@ static bt_status_t _hal_write_characteristic_value(int conn_id, btgatt_srvc_id_t
        bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE;
        int ret = BT_STATUS_SUCCESS;
 
-       DBG("+");
-
        ret = __hal_get_write_prop(write_type, &write_prop);
        if (BT_STATUS_FAIL == ret) {
                DBG("received invalid  write type:[%d] ", write_type);
@@ -1729,7 +1748,7 @@ static bt_status_t _hal_write_characteristic_value(int conn_id, btgatt_srvc_id_t
        /* get the connection info */
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -1808,13 +1827,12 @@ bt_status_t btif_get_acquire_write_fd(int conn_id,
        bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_WRITE_NO_RESPONSE;
        int ret = BT_STATUS_SUCCESS;
 
-       DBG("+");
        DBG("svc isntance id:[%d]", srvc_id->id.inst_id);
 
        /* get the connection info */
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -1838,7 +1856,6 @@ bt_status_t btif_get_acquire_write_fd(int conn_id,
        if (ret != BT_STATUS_SUCCESS)
                return ret;
 
-       INFO("Characterstics FD erite  characterstics fd is %d", *fd);
        return ret;
 }
 
@@ -1855,13 +1872,12 @@ bt_status_t btif_get_acquire_notify_fd(int conn_id,
        bt_gatt_characteristic_property_t write_prop = HAL_GATT_CHARACTERISTIC_PROPERTY_NOTIFY;
        int ret = BT_STATUS_SUCCESS;
 
-       DBG("+");
-       DBG("svc isntance id:[%d]", srvc_id->id.inst_id);
+       DBG("svc isntance id [%d]", srvc_id->id.inst_id);
 
        /* get the connection info */
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -1885,8 +1901,6 @@ bt_status_t btif_get_acquire_notify_fd(int conn_id,
        if (ret != BT_STATUS_SUCCESS)
                return ret;
 
-       INFO("Characterstics FD write characterstics fd is %d", *fd);
-
        return ret;
 }
 
@@ -1899,8 +1913,6 @@ bt_status_t btif_write_characteristic(int conn_id,
 {
        CHECK_BTGATT_INIT();
 
-       DBG("+");
-
        DBG("svc isntance id:[%d]", srvc_id->id.inst_id);
        return _hal_write_characteristic_value(conn_id, srvc_id, char_id, write_type,
                                len, auth_req, p_value);
@@ -1915,8 +1927,6 @@ static void __hal_send_desc_read_event(hal_gatt_resp_data_t *resp_data, int resu
                return;
        }
 
-       DBG("sending gatt client desc read conn_id[%d] status[%d]", resp_data->conn_id, result);
-
        memset(&ev, 0, sizeof(ev));
        ev.conn_id = resp_data->conn_id;
        ev.inst_id = resp_data->srvc_id.id.inst_id;
@@ -1929,11 +1939,11 @@ static void __hal_send_desc_read_event(hal_gatt_resp_data_t *resp_data, int resu
 
        ev.len = len;
        if (len > 0) {
-               DBG("building the desc read value [%d]", len);
+               /* building the desc read value */
                memcpy(ev.value, value, len);
        }
 
-       DBG("sending the gatt client read descriptor event");
+       DBG("sending gatt client desc read conn_id[%d] status[%d]", resp_data->conn_id, result);
 
        event_cb(HAL_EV_GATT_CLIENT_READ_DESC, (void *)&ev, sizeof(ev));
 }
@@ -2008,12 +2018,10 @@ static bt_status_t _hal_read_descriptor_value(int conn_id, btgatt_srvc_id_t *srv
 
        hal_gattc_desc_t *gattc_desc = NULL;
 
-       DBG("+");
-
        /* get the connection info */
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -2104,8 +2112,6 @@ static void __hal_send_desc_write_event(hal_gatt_resp_data_t *resp_data, int res
                return;
        }
 
-       DBG("sending gatt client charac write conn_id[%d] status[%d]", resp_data->conn_id, result);
-
        memset(&ev, 0, sizeof(ev));
        ev.conn_id = resp_data->conn_id;
        ev.inst_id = resp_data->srvc_id.id.inst_id;
@@ -2116,7 +2122,7 @@ static void __hal_send_desc_write_event(hal_gatt_resp_data_t *resp_data, int res
        memcpy(ev.char_uuid, resp_data->char_id.uuid.uu, sizeof(ev.char_uuid));
        memcpy(ev.desc_uuid, resp_data->desc_id.uuid.uu, sizeof(ev.desc_uuid));
 
-       DBG("sending the gatt client write charac event");
+       DBG("sending gatt client charac write event. conn_id[%d] status[%d]", resp_data->conn_id, result);
 
        event_cb(HAL_EV_GATT_CLIENT_WRITE_DESC, (void *)&ev, sizeof(ev));
 }
@@ -2189,7 +2195,7 @@ static bt_status_t _hal_write_descriptor_value(int conn_id, btgatt_srvc_id_t *sr
        /* get the connection info */
        conn_info = __bt_find_gatt_conn_info_from_conn_id(conn_id);
        if (NULL == conn_info) {
-               ERR("Failed to get the conn_info for conn_id[%d]", conn_id);
+               ERR("Failed to get the conn_info for conn_id [%d]", conn_id);
                return BT_STATUS_FAIL;
        }
 
@@ -2678,8 +2684,6 @@ bt_status_t btif_gattc_conn_parameter_update(bt_bdaddr_t *bd, int min_int, int m
 {
        CHECK_BTGATT_INIT();
 
-       DBG("+");
-
        return __hal_update_conn_parameter(bd, min_int, max_int, latency, timeout);
 }
 
@@ -2699,8 +2703,6 @@ static void __bt_request_att_mtu_device_cb(GDBusProxy *proxy, GAsyncResult *res,
        struct hal_ev_gatt_client_mtu_exchange_completed  ev;
        struct conn_mtu_s *conn_mtu = (struct conn_mtu_s *)user_data;
 
-       DBG("+");
-
        reply = g_dbus_proxy_call_finish(proxy, res, &g_error);
        g_object_unref(proxy);
        if (reply == NULL) {
@@ -3292,13 +3294,11 @@ const btgatt_client_interface_t btgatt_client_interface = {
        .batchscan_enb_batch_scan = batchscan_enb_batch_scan,
        .batchscan_dis_batch_scan = batchscan_dis_batch_scan,
        .batchscan_read_reports = batchscan_read_reports,
-       .add_connection_info = btif_gattc_add_connection_info
+       .add_connection_info = btif_gattc_add_connection_info,
 };
 
 static hal_gattc_server_info_t *__bt_find_gatt_conn_info(const bt_bdaddr_t *serv_addr)
 {
-       DBG("+");
-
        GSList *l;
        hal_gattc_server_info_t *info = NULL;
 
@@ -3307,18 +3307,15 @@ static hal_gattc_server_info_t *__bt_find_gatt_conn_info(const bt_bdaddr_t *serv
                if (info == NULL)
                        continue;
 
-               if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t))) {
-                       INFO("GATT connection found addr");
+               if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t)))
                        return info;
                }
-       }
+
        return NULL;
 }
 
 static hal_gattc_client_info_t *__bt_find_gatt_client_info(bt_bdaddr_t *serv_addr)
 {
-       DBG("+");
-
        GSList *l;
        hal_gattc_client_info_t *info = NULL;
 
@@ -3327,11 +3324,10 @@ static hal_gattc_client_info_t *__bt_find_gatt_client_info(bt_bdaddr_t *serv_add
                if (info == NULL)
                        continue;
 
-               if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t))) {
-                       INFO("GATT client info found addr");
+               if (!memcmp(&info->bd_addr, serv_addr, sizeof(bt_bdaddr_t)))
                        return info;
                }
-       }
+
        return NULL;
 }
 
@@ -3345,11 +3341,10 @@ static hal_gattc_client_info_t *__bt_find_gatt_client_info_from_conn_id(int conn
                if (info == NULL)
                        continue;
 
-               if (info->conn_id == conn_id) {
-                       INFO("GATT client info found for conn_id [%d]", conn_id);
+               if (info->conn_id == conn_id)
                        return info;
                }
-       }
+
        return NULL;
 }
 
@@ -3372,7 +3367,6 @@ static hal_gattc_server_info_t *__bt_find_gatt_conn_info_from_conn_id(int  conn_
 
                if ((info->inst_id == gattc_client->inst_id) &&
                        !memcmp(&info->bd_addr, &gattc_client->bd_addr, sizeof(bt_bdaddr_t))) {
-                       INFO("GATT connection found for conn_id [%d]", conn_id);
                        return info;
                }
        }
@@ -3548,6 +3542,7 @@ static void __le_connection_req_cb(GDBusProxy *proxy, GAsyncResult *res,
        /*add gatt server connection info*/
        gatt_conn_info = g_malloc0(sizeof(hal_gattc_server_info_t));
        memcpy(gatt_conn_info->bd_addr.address, gattc_data->bd_addr.address, BT_HAL_ADDRESS_LENGTH_MAX);
+       gatt_conn_info->conn_id = gattc_data->conn_id;
        gatt_conn_info->inst_id = gattc_data->inst_id;
        hal_gattc_server_info_list = g_slist_append(hal_gattc_server_info_list, gatt_conn_info);
 
@@ -3709,7 +3704,7 @@ static void _bt_hal_send_search_service_result_event(int conn_id, int is_primary
                return;
        }
 
-       DBG("sending gatt client search service result event conn_id[%d]", conn_id);
+       DBG("Send service searching result. [%s] conn_id[%d]", uuid_str, conn_id);
 
        memset(&ev, 0, sizeof(ev));
        ev.conn_id = conn_id;
@@ -3901,9 +3896,15 @@ static bt_status_t __hal_gattc_get_service_info(hal_gattc_server_info_t *server_
                }
        }
 
+       if (uuid_str == NULL || gp_char_array == NULL) {
+               ERR("uuid_str and gp_char_array should be set");
+               goto done;
+       }
+
        /* Create new service */
        _gattc_create_new_service(server_info, is_primary, uuid_str, service_path, gp_char_array);
 
+done:
        g_variant_iter_free(property_iter);
        g_variant_unref(result);
        g_object_unref(properties_proxy);
@@ -3963,7 +3964,6 @@ void _bt_hal_handle_gattc_service_changed_event(gboolean is_added, const char *p
 
        _bt_hal_convert_device_path_to_address(path, address);
        _bt_hal_convert_addr_string_to_type(ev.bdaddr, address);
-       ev.change_type = is_added;
        server_info = __bt_find_gatt_conn_info((bt_bdaddr_t *)ev.bdaddr);
        if (server_info == NULL) {
                ERR("service_info is NULL");
@@ -3971,11 +3971,16 @@ void _bt_hal_handle_gattc_service_changed_event(gboolean is_added, const char *p
        }
 
        if (is_added) {
+               /* Get service UUID from path */
                __bt_hal_gattc_get_uuid_from_path(path, &uuid_str);
-               DBG("GATT Service(%s) Added", uuid_str);
-               /* Set UUID by using path */
-               _bt_hal_convert_uuid_string_to_type(ev.uuid, uuid_str);
-               g_free(uuid_str);
+               if (uuid_str) {
+                       DBG("conn_id(%d) GATT Service(%s) Added", server_info->conn_id, uuid_str);
+                       _bt_hal_convert_uuid_string_to_type(ev.uuid, uuid_str);
+                       g_free(uuid_str);
+               } else {
+                       ERR("uuid_str is NULL");
+                       return;
+               }
 
                /* Create new service and append into the list */
                __hal_gattc_get_service_info(server_info, path);
@@ -3989,10 +3994,8 @@ void _bt_hal_handle_gattc_service_changed_event(gboolean is_added, const char *p
                        if (g_strcmp0(service->svc_path, path) == 0) {
                                memcpy(ev.uuid, service->svc_uuid.uu, sizeof(bt_uuid_t));
                                uuid_str = g_malloc0(BT_HAL_UUID_STRING_LEN);
-                               /* Set UUID from stored service info */
                                _bt_hal_convert_uuid_type_to_string(uuid_str, ev.uuid);
-                               DBG("GATT Service(%s) Removed", uuid_str);
-                               g_free(uuid_str);
+                               DBG("conn_id(%d) GATT Service(%s) Removed", server_info->conn_id, uuid_str);
 
                                /* Remove service info in list */
                                server_info->gatt_list_services = g_slist_remove(server_info->gatt_list_services, service);
@@ -4000,9 +4003,18 @@ void _bt_hal_handle_gattc_service_changed_event(gboolean is_added, const char *p
                                break;
                        }
                }
+
+               if (uuid_str) {
+                       g_free(uuid_str);
+               } else {
+                       ERR("uuid_str is NULL");
+                       return;
+               }
        }
 
        /* Send GATT Client service changed event */
+       ev.change_type = is_added;
+       ev.conn_id = server_info->conn_id;
+       ev.inst_id = server_info->inst_id;
        event_cb(HAL_EV_GATT_CLIENT_SERVICE_CHANGED, (void *)&ev, sizeof(ev));
 }
-