Resolve memory leak in HAL
[platform/core/connectivity/bluetooth-frwk.git] / bt-oal / bluez_hal / src / bt-hal-dbus-common-utils.c
index cd8466f..730fde4 100644 (file)
  * This is RFCOMM default Channel Value
  */
 #define RFCOMM_DEFAULT_PROFILE_CHANNEL 0
+#define BT_AUDIO_SOURCE_MAX 2
 
 static char *avrcp_control_path = NULL;
+static char *avrcp_transport_path = NULL;
 
 static GDBusConnection *system_conn;
 static GDBusConnection *session_conn;
@@ -62,7 +64,13 @@ static GDBusProxy *profile_gproxy = NULL;
 static GDBusProxy *adapter_properties_proxy;
 static GDBusProxy *avrcp_ctrl_proxy;
 
-static GDBusConnection *system_gconn = NULL;
+struct avrcp_proxy {
+       GDBusProxy *avrcp_ctrl_proxy;
+       char *avrcp_control_path;
+       bt_bdaddr_t bd_addr;
+};
+
+struct avrcp_proxy proxy_array[BT_AUDIO_SOURCE_MAX];
 
 static guint bus_id;
 GDBusNodeInfo *new_conn_node;
@@ -80,31 +88,44 @@ static const gchar rfcomm_agent_xml[] =
 "  </interface>"
 "</node>";
 
-GDBusConnection *_bt_hal_gdbus_init_system_gconn(void)
+static GDBusConnection *__bt_hal_init_session_conn(void)
+{
+       if (session_conn == NULL)
+               session_conn = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
+
+       return session_conn;
+}
+
+GDBusConnection *_bt_hal_get_session_gconn(void)
+{
+       return (session_conn) ? session_conn : __bt_hal_init_session_conn();
+}
+
+static GDBusConnection *__bt_hal_init_system_gconn(void)
 {
        GError *error = NULL;
 
-       if (system_gconn != NULL)
-               return system_gconn;
+       if (system_conn != NULL)
+               return system_conn;
 
-       system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
+       system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
-       if (!system_gconn) {
+       if (!system_conn) {
                ERR("Unable to connect to dbus: %s", error->message);
                g_clear_error(&error);
        }
 
-       return system_gconn;
+       return system_conn;
 }
 
-GDBusConnection *_bt_hal_gdbus_get_system_gconn(void)
+GDBusConnection *_bt_hal_get_system_gconn(void)
 {
        GDBusConnection *local_system_gconn = NULL;
        GError *error = NULL;
 
-       if (system_gconn == NULL) {
-               system_gconn = _bt_hal_gdbus_init_system_gconn();
-       } else if (g_dbus_connection_is_closed(system_gconn)){
+       if (system_conn == NULL) {
+               system_conn = __bt_hal_init_system_gconn();
+       } else if (g_dbus_connection_is_closed(system_conn)) {
 
                local_system_gconn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error);
 
@@ -113,18 +134,16 @@ GDBusConnection *_bt_hal_gdbus_get_system_gconn(void)
                        g_clear_error(&error);
                }
 
-               system_gconn = local_system_gconn;
+               system_conn = local_system_gconn;
        }
 
-       return system_gconn;
+       return system_conn;
 }
 
 static GDBusProxy *__bt_hal_init_manager_proxy(void)
 {
        GDBusProxy *proxy;
 
-       DBG("+");
-
        if (system_conn == NULL) {
                system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
                if (system_conn == NULL)
@@ -140,7 +159,6 @@ static GDBusProxy *__bt_hal_init_manager_proxy(void)
 
        manager_gproxy = proxy;
 
-       DBG("-");
        return proxy;
 }
 
@@ -214,25 +232,40 @@ static GDBusProxy *__bt_hal_init_adapter_properties_proxy(void)
 
 void _bt_hal_set_control_device_path(const char *path)
 {
+       int i;
 
        if (path == NULL)
                return;
 
-       g_free(avrcp_control_path);
        DBG("control_path = %s", path);
-       avrcp_control_path = g_strdup(path);
+
+       for (i = 0; i < BT_AUDIO_SOURCE_MAX; i++) {
+               if (proxy_array[i].avrcp_control_path == NULL) {
+                       proxy_array[i].avrcp_control_path = g_strdup(path);
+                       DBG("PATH %s formed index %d", proxy_array[i].avrcp_control_path, i);
+                       return;
+               }
+       }
 }
 
 void _bt_hal_remove_control_device_path(const char *path)
 {
+       int i;
+
        if (path == NULL)
                return;
 
-       if (avrcp_control_path &&
-                       !g_strcmp0(avrcp_control_path, path)) {
-               DBG("control_path = %s", path);
-               g_free(avrcp_control_path);
-               avrcp_control_path = NULL;
+       for (i = 0; i < BT_AUDIO_SOURCE_MAX; i++) {
+               if (g_strcmp0(proxy_array[i].avrcp_control_path, path) == 0) {
+                       DBG("Clear AVRCP proxy[%d]", i);
+                       g_free(proxy_array[i].avrcp_control_path);
+                       g_object_unref(proxy_array[i].avrcp_ctrl_proxy);
+
+                       proxy_array[i].avrcp_control_path = NULL;
+                       proxy_array[i].avrcp_ctrl_proxy = NULL;
+                       memset(proxy_array[i].bd_addr.address, 0, 6);
+                       return;
+               }
        }
 }
 
@@ -240,17 +273,49 @@ static char *__bt_hal_extract_control_device_path(GVariantIter *iter, char *addr
 {
        char *object_path = NULL;
        char *interface_str = NULL;
+       GVariantIter *interface_iter;
        char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
 
        /* Parse the signature: oa{sa{sv}}} */
-       while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_str)) {
+       while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
                if (object_path == NULL)
-                       return  NULL;
+                       continue;
 
-               if (g_strcmp0(interface_str, BT_HAL_PLAYER_CONTROL_INTERFACE) == 0) {
-                       _bt_hal_convert_device_path_to_address(object_path, device_address);
-                       if (g_strcmp0(address, device_address) == 0)
-                               return g_strdup(object_path);
+               while(g_variant_iter_loop(interface_iter, "{&sa{sv}}", &interface_str, NULL)) {
+                       if (g_strcmp0(interface_str, BT_HAL_PLAYER_CONTROL_INTERFACE) == 0) {
+                               _bt_hal_convert_device_path_to_address(object_path, device_address);
+                               if (g_strcmp0(address, device_address) == 0) {
+                                       DBG("Object Path: %s", object_path);
+                                       g_variant_iter_free(interface_iter);
+                                       return g_strdup(object_path);
+                               }
+                       }
+               }
+       }
+       return NULL;
+}
+
+static char *__bt_hal_extract_transport_device_path(GVariantIter *iter, char *address)
+{
+       char *object_path = NULL;
+       char *interface_str = NULL;
+       GVariantIter *interface_iter;
+       char device_address[BT_HAL_ADDRESS_STRING_SIZE] = { 0 };
+
+       /* Parse the signature: oa{sa{sv}}} */
+       while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, &interface_iter)) {
+               if (object_path == NULL)
+                       continue;
+
+               while(g_variant_iter_loop(interface_iter, "{&sa{sv}}", &interface_str, NULL)) {
+                       if (g_strcmp0(interface_str, BT_HAL_MEDIATRANSPORT_INTERFACE) == 0) {
+                               _bt_hal_convert_device_path_to_address(object_path, device_address);
+                               if (g_strcmp0(address, device_address) == 0) {
+                                       DBG("Object Path: %s", object_path);
+                                       g_variant_iter_free(interface_iter);
+                                       return g_strdup(object_path);
+                               }
+                       }
                }
        }
        return NULL;
@@ -291,20 +356,51 @@ static char *__bt_hal_get_control_device_object_path(char *address)
        return object_path;
 }
 
+static char *__bt_hal_get_transport_device_object_path(char *address)
+{
+       char *object_path = NULL;
+       GDBusConnection *conn;
+       GDBusProxy *manager_proxy;
+       GVariant *result = NULL;
+       GVariantIter *iter = NULL;
+
+       conn = _bt_hal_get_system_gconn();
+       if (conn == NULL)
+               return NULL;
+
+       manager_proxy = _bt_hal_get_manager_proxy();
+       if (manager_proxy == NULL)
+               return  NULL;
+
+       result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       NULL);
+       if (!result) {
+               ERR("Can't get managed objects");
+               return NULL;
+       }
+
+       /* signature of GetManagedObjects:  a{oa{sa{sv}}} */
+       g_variant_get(result, "(a{oa{sa{sv}}})", &iter);
+       object_path = __bt_hal_extract_transport_device_path(iter, address);
+       g_variant_iter_free(iter);
+       g_variant_unref(result);
+       return object_path;
+}
+
 char *_bt_hal_get_control_device_path(bt_bdaddr_t *bd_addr)
 {
        char *control_path;
        char connected_address[BT_HAL_ADDRESS_STRING_SIZE];
 
-       DBG("+");
-
        if (avrcp_control_path != NULL)
                return avrcp_control_path;
 
        _bt_hal_convert_addr_type_to_string(connected_address, bd_addr->address);
 
-       DBG("device address = %s", connected_address);
-
        control_path = __bt_hal_get_control_device_object_path(connected_address);
        if (control_path == NULL)
                return NULL;
@@ -314,70 +410,68 @@ char *_bt_hal_get_control_device_path(bt_bdaddr_t *bd_addr)
        return control_path;
 }
 
-static GDBusConnection *__bt_hal_init_system_gconn(void)
+char *_bt_hal_get_transport_device_path(bt_bdaddr_t *bd_addr)
 {
-       if (system_conn == NULL)
-               system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
+       char *transport_path;
+       char connected_address[BT_HAL_ADDRESS_STRING_SIZE];
 
-       return system_conn;
+       if (avrcp_transport_path != NULL)
+               return avrcp_transport_path;
+
+       _bt_hal_convert_addr_type_to_string(connected_address, bd_addr->address);
+
+       transport_path = __bt_hal_get_transport_device_object_path(connected_address);
+       if (transport_path == NULL)
+               return NULL;
+
+       avrcp_transport_path = transport_path;
+       DBG("transport_path = %s", transport_path);
+       return transport_path;
 }
 
 static GDBusProxy *__bt_hal_init_avrcp_ctrl_proxy(bt_bdaddr_t *bd_addr)
 {
        GDBusProxy *manager_proxy;
        GDBusProxy *proxy;
-       char *control_path = NULL;
+       GDBusConnection *gconn = NULL;
+       int i;
 
-       if (system_conn == NULL) {
-               system_conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL);
-               if (system_conn == NULL) {
-                       return  NULL;
-               }
-       }
+       gconn = _bt_hal_get_system_gconn();
+       if (gconn == NULL)
+               return  NULL;
 
        manager_proxy = _bt_hal_get_manager_proxy();
-       if (manager_proxy == NULL) {
+       if (manager_proxy == NULL)
                return  NULL;
+
+       for (i = 0; i < BT_AUDIO_SOURCE_MAX; i++) {
+               if (proxy_array[i].avrcp_ctrl_proxy == NULL) {
+                       memcpy(proxy_array[i].bd_addr.address, bd_addr->address, 6);
+                       DBG("PATH %s formed index %d ", proxy_array[i].avrcp_control_path, i);
+                       break;
+               }
        }
 
-       control_path = _bt_hal_get_control_device_path(bd_addr);
-       if (control_path == NULL) {
-               return  NULL;
+       if (i == BT_AUDIO_SOURCE_MAX) {
+               ERR("NO free arr proxy space found");
+               return NULL;
        }
 
-       proxy = g_dbus_proxy_new_sync(system_conn, G_DBUS_PROXY_FLAGS_NONE,
+       proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE,
                        NULL, BT_HAL_BLUEZ_NAME,
-                       control_path, BT_HAL_PLAYER_CONTROL_INTERFACE,  NULL, NULL);
+                       proxy_array[i].avrcp_control_path, BT_HAL_PLAYER_CONTROL_INTERFACE,  NULL, NULL);
 
-       if (proxy == NULL) {
+       if (proxy == NULL)
                return NULL;
-       }
 
        avrcp_ctrl_proxy = proxy;
-       return proxy;
-}
+       proxy_array[i].avrcp_ctrl_proxy = proxy;
 
-static GDBusConnection *__bt_hal_init_session_conn(void)
-{
-       if (session_conn == NULL)
-               session_conn =g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL);
-
-       return session_conn;
-}
-
-GDBusConnection *_bt_hal_get_session_gconn(void)
-{
-       return (session_conn) ? session_conn : __bt_hal_init_session_conn();
-}
-
-GDBusConnection *_bt_hal_get_system_gconn(void)
-{
-       return (system_conn) ? system_conn : __bt_hal_init_system_gconn();
+       return proxy;
 }
 
 GDBusProxy *_bt_hal_get_manager_proxy(void)
 {
-       DBG("+");
        if (manager_gproxy) {
                const gchar *path =  g_dbus_proxy_get_object_path(manager_gproxy);
                if (path == NULL) {
@@ -386,7 +480,6 @@ GDBusProxy *_bt_hal_get_manager_proxy(void)
                }
                return manager_gproxy;
        }
-       DBG("-");
        return  __bt_hal_init_manager_proxy();
 }
 
@@ -407,17 +500,27 @@ GDBusProxy *_bt_hal_get_adapter_proxy(void)
 
 GDBusProxy *_bt_hal_get_avrcp_ctrl_proxy(bt_bdaddr_t *bd_addr)
 {
-       if (avrcp_ctrl_proxy) {
-               const char *path =  g_dbus_proxy_get_object_path(avrcp_ctrl_proxy);
-               if (path == NULL) {
-                       ERR("Already proxy released hence creating new proxy");
-                       return  __bt_hal_init_avrcp_ctrl_proxy(bd_addr);
-               }
+       int i;
+
+       for (i = 0; i < BT_AUDIO_SOURCE_MAX; i++) {
+               if (proxy_array[i].avrcp_ctrl_proxy
+                    && (!memcmp(proxy_array[i].bd_addr.address, bd_addr->address, 6))) {
+                       const gchar *path = g_dbus_proxy_get_object_path(proxy_array[i].avrcp_ctrl_proxy);
+
+                       if (!path) {
+                               proxy_array[i].avrcp_ctrl_proxy = NULL;
+                               ERR("Already proxy released hence creating new proxy");
+                               return  __bt_hal_init_avrcp_ctrl_proxy(bd_addr);
+                       }
 
-               return avrcp_ctrl_proxy;
+                       DBG("address found      path PATH %s", path);
+                       return proxy_array[i].avrcp_ctrl_proxy;
+               }
        }
-       return  __bt_hal_init_avrcp_ctrl_proxy(bd_addr);
 
+       DBG("address NOT found");
+
+       return  __bt_hal_init_avrcp_ctrl_proxy(bd_addr);
 }
 
 GDBusProxy *_bt_hal_get_avrcp_ctrl_properties_proxy(bt_bdaddr_t *bd_addr)
@@ -427,15 +530,14 @@ GDBusProxy *_bt_hal_get_avrcp_ctrl_properties_proxy(bt_bdaddr_t *bd_addr)
        char *control_path = NULL;
        GDBusConnection *conn = NULL;
 
-       DBG("+");
        control_path = _bt_hal_get_control_device_path(bd_addr);
-       if (control_path == NULL) {
+       if (control_path == NULL)
                return  NULL;
-       }
+
        DBG("control_path = %s", control_path);
 
        conn = _bt_hal_get_system_gconn();
-       if(conn == NULL) {
+       if (conn == NULL) {
                ERR("FAIL to get system connection");
                return NULL;
        }
@@ -452,7 +554,40 @@ GDBusProxy *_bt_hal_get_avrcp_ctrl_properties_proxy(bt_bdaddr_t *bd_addr)
                return NULL;
        }
 
-       DBG("-");
+       return proxy;
+}
+
+GDBusProxy *_bt_hal_get_avrcp_transport_properties_proxy(bt_bdaddr_t *bd_addr)
+{
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       char *transport_path = NULL;
+       GDBusConnection *conn = NULL;
+
+       transport_path = _bt_hal_get_transport_device_path(bd_addr);
+       if (transport_path == NULL)
+               return  NULL;
+
+       DBG("transport_path = %s", transport_path);
+
+       conn = _bt_hal_get_system_gconn();
+       if (conn == NULL) {
+               ERR("FAIL to get system connection");
+               return NULL;
+       }
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE,
+                       NULL, BT_HAL_BLUEZ_NAME,
+                       transport_path, BT_HAL_PROPERTIES_INTERFACE,  NULL, &error);
+
+       if (proxy == NULL) {
+               ERR("Unable to allocate new proxy");
+               if (error) {
+                       ERR("%s", error->message);
+                       g_clear_error(&error);
+               }
+               return NULL;
+       }
+
        return proxy;
 }
 
@@ -527,7 +662,6 @@ char *_bt_hal_get_adapter_path(void)
        GVariantIter *iter = NULL;
        char *adapter_path = NULL;
 
-       DBG("+");
        conn = _bt_hal_get_system_gconn();
        if (conn == NULL)
                return  NULL;
@@ -553,7 +687,7 @@ char *_bt_hal_get_adapter_path(void)
        adapter_path = __bt_hal_extract_adapter_path(iter);
        g_variant_iter_free(iter);
        g_variant_unref(result);
-       DBG("-");
+
        return adapter_path;
 }
 
@@ -628,6 +762,32 @@ void _bt_hal_deinit_proxys(void)
        }
 }
 
+GDBusProxy *_bt_hal_get_hid_agent_proxy(void)
+{
+       GDBusConnection *conn;
+       GDBusProxy *proxy;
+       GError *err = NULL;
+
+       conn = _bt_hal_get_system_gconn();
+       if (conn == NULL) {
+               ERR("_bt_hal_get_system_gconn failed");
+               return NULL;
+       }
+
+       proxy = g_dbus_proxy_new_sync(conn, G_DBUS_PROXY_FLAGS_NONE, NULL,
+                                       BT_HAL_HID_SERVICE_NAME, BT_HAL_HID_AGENT_OBJECT_PATH,
+                                       BT_HAL_HID_SERVICE_INTERFACE, NULL, &err);
+       if (proxy == NULL) {
+               if (err != NULL) {
+                       ERR("Unable to create proxy: %s", err->message);
+                       g_clear_error(&err);
+               }
+               return NULL;
+       }
+
+       return proxy;
+}
+
 void _bt_hal_convert_device_path_to_address(const char *device_path,
                char *device_address)
 {
@@ -643,9 +803,8 @@ void _bt_hal_convert_device_path_to_address(const char *device_path,
                dev_addr += 4;
                g_strlcpy(address, dev_addr, sizeof(address));
 
-               while ((pos = strchr(address, '_')) != NULL) {
+               while ((pos = strchr(address, '_')) != NULL)
                        *pos = ':';
-               }
 
                g_strlcpy(device_address, address, BT_HAL_ADDRESS_STRING_SIZE);
        }
@@ -679,7 +838,7 @@ gboolean _bt_hal_uuid_is_standard(bt_uuid_t *p_uuid)
 }
 
 void _bt_hal_convert_uuid_string_to_type(unsigned char *uuid,
-                const char *device_uuid)
+               const char *device_uuid)
 {
        uint32_t uuid0, uuid4;
        uint16_t uuid1, uuid2, uuid3, uuid5;
@@ -796,7 +955,7 @@ int _bt_hal_copy_utf8_string(char *dest, const char *src, unsigned int length)
                while (count > 0 && ((i + count) < length)) {
                        dest[i++] = *p;
                        p++;
-                       count --;
+                       count--;
                }
                p = next;
        }
@@ -805,7 +964,6 @@ int _bt_hal_copy_utf8_string(char *dest, const char *src, unsigned int length)
 
 gboolean _bt_hal_utf8_validate(char *name)
 {
-       DBG("+");
        gunichar2 *u16;
        glong items_written = 0;
 
@@ -821,7 +979,6 @@ gboolean _bt_hal_utf8_validate(char *name)
        if (items_written != g_utf8_strlen(name, -1))
                return FALSE;
 
-       DBG("-");
        return TRUE;
 }
 
@@ -835,9 +992,8 @@ int _bt_hal_set_socket_non_blocking(int socket_fd)
        if (arg < 0)
                return -errno;
 
-       if (arg & O_NONBLOCK) {
+       if (arg & O_NONBLOCK)
                ERR("Already Non-blocking \n");
-       }
 
        arg |= O_NONBLOCK;
 
@@ -878,9 +1034,8 @@ static char *__bt_hal_extract_device_path(GVariantIter *iter, char *address)
                if (object_path == NULL)
                        return  NULL;
                _bt_hal_convert_device_path_to_address(object_path, device_address);
-               if (g_strcmp0(address, device_address) == 0) {
+               if (g_strcmp0(address, device_address) == 0)
                        return g_strdup(object_path);
-               }
        }
        return NULL;
 }
@@ -920,6 +1075,41 @@ char *_bt_hal_get_device_object_path(char *address)
        return object_path;
 }
 
+GVariant *_bt_hal_get_managed_objects(void)
+{
+       GDBusConnection *conn;
+       GDBusProxy *manager_proxy;
+       GVariant *result = NULL;
+       GError *error = NULL;
+
+       conn = _bt_hal_get_system_gconn();
+       if (conn == NULL)
+               return NULL;
+
+       manager_proxy = _bt_hal_get_manager_proxy();
+       if (manager_proxy == NULL)
+               return  NULL;
+
+       result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       NULL);
+       if (!result) {
+               ERR("Can't get managed objects");
+               return NULL;
+       }
+
+       if (error) {
+               ERR("Fail to get ManagedObjects (Error: %s)", error->message);
+               g_clear_error(&error);
+       }
+
+       return result;
+}
+
+
 char *_bt_hal_convert_error_to_string(int error)
 {
        switch (error) {
@@ -1003,7 +1193,7 @@ char *_bt_hal_convert_error_to_string(int error)
 
 char * _bt_hal_convert_disc_reason_to_string(int reason)
 {
-       switch(reason) {
+       switch (reason) {
        case 1:
                return "Link loss";
        case 2:
@@ -1016,6 +1206,21 @@ char * _bt_hal_convert_disc_reason_to_string(int reason)
        }
 }
 
+int _bt_hal_convert_disc_reason_to_status(int reason)
+{
+       switch (reason) {
+       case 1:
+               return BT_STATUS_CONN_TOUT; //"Link loss"
+       case 2:
+               return BT_STATUS_CONN_TERM_LOCAL_HOST; //"Connection terminated by local host";
+       case 3:
+               return BT_STATUS_CONN_TERM_RMT_HOST; //"Connection terminated by local host";
+       case 0:
+       default:
+               return BT_STATUS_FAIL;
+       }
+}
+
 void _bt_hal_logging_connection(gboolean connect, int addr_type)
 {
        static int le_conn = 0;
@@ -1323,6 +1528,8 @@ static void __hal_new_connection_method(GDBusConnection *connection,
 
                if (cb)
                        cb(object_path, fd, &remote_addr1);
+               else
+                       close(fd);
        } else if (g_strcmp0(method_name, "RequestDisconnection") == 0) {
                g_dbus_method_invocation_return_value(invocation, NULL);
        }
@@ -1331,7 +1538,7 @@ static void __hal_new_connection_method(GDBusConnection *connection,
 static GDBusNodeInfo *_bt_hal_get_gdbus_node(const gchar *xml_data)
 {
        if (bus_id == 0) {
-               char *name = g_strdup_printf("org.bt.frwk%d", getpid());
+               char *name = g_strdup_printf("org.bt.frwk.p%d", getpid());
 
                bus_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                name,
@@ -1416,7 +1623,7 @@ int _bt_hal_discover_services(char *address, char *uuid, void *cb, gpointer func
 
                INFO("No searched device");
                adapter_proxy = _bt_hal_get_adapter_proxy();
-               if(adapter_proxy == NULL) {
+               if (adapter_proxy == NULL) {
                        ERR("adapter_proxy == NULL, return");
                        return BT_STATUS_FAIL;
                }
@@ -1479,7 +1686,7 @@ int _bt_hal_cancel_discovers(char *address)
                GVariant *ret = NULL;
                INFO("No searched device");
                adapter_proxy = _bt_hal_get_adapter_proxy();
-               if(adapter_proxy == NULL) {
+               if (adapter_proxy == NULL) {
                        ERR("adapter_proxy == NULL, return");
                        return BT_STATUS_FAIL;
                }
@@ -1533,27 +1740,25 @@ int _bt_hal_discover_service_uuids(char *address, char *remote_uuid)
        GDBusConnection *gconn;
        GError *err = NULL;
        char **uuid_value = NULL;
-       gsize size;
-       int i =0;
+       gsize size = 0;
+       int i = 0;
        GVariant *value = NULL;
        GVariant *ret = NULL;
        int result = BT_STATUS_FAIL;
 
-       DBG("+");
-
-       if(remote_uuid == NULL) {
+       if (remote_uuid == NULL) {
                ERR("remote_uuid == NULL, return");
                return BT_STATUS_FAIL;
        }
 
        gconn = _bt_hal_get_system_gconn();
-       if(gconn == NULL) {
+       if (gconn == NULL) {
                ERR("gconn == NULL, return");
                return BT_STATUS_FAIL;
        }
 
        object_path = _bt_hal_get_device_object_path(address);
-       if(object_path == NULL) {
+       if (object_path == NULL) {
                ERR("object_path == NULL, return");
                return BT_STATUS_FAIL;
        }
@@ -1561,7 +1766,7 @@ int _bt_hal_discover_service_uuids(char *address, char *remote_uuid)
        proxy = g_dbus_proxy_new_sync(gconn, G_DBUS_PROXY_FLAGS_NONE, NULL,
                        BT_HAL_BLUEZ_NAME, object_path, BT_HAL_PROPERTIES_INTERFACE, NULL,
                        &err);
-       if(proxy == NULL) {
+       if (proxy == NULL) {
                g_free(object_path);
                ERR("proxy == NULL, return");
                return BT_STATUS_FAIL;
@@ -1601,13 +1806,13 @@ int _bt_hal_discover_service_uuids(char *address, char *remote_uuid)
 
                if (size > 0) {
                        uuid_value = (char **)g_variant_get_strv(temp_value, &size);
-                       DBG("Size items %d", size);
+                       DBG("Size items %zu", size);
                }
 
                if (temp_value)
                        g_variant_unref(temp_value);
 
-               if(uuid_value) {
+               if (uuid_value) {
                        for (i = 0; uuid_value[i] != NULL; i++) {
                                DBG("Remote uuids %s, searched uuid: %s",
                                                uuid_value[i], remote_uuid);
@@ -1627,13 +1832,12 @@ done:
        if (uuid_value)
                g_free(uuid_value);
 
-       DBG("-");
        return result;
 }
 
 int bt_hal_gatt_convert_prop2string(
-                        bt_hal_gatt_characteristic_property_t properties,
-                        char *char_properties[])
+               bt_hal_gatt_characteristic_property_t properties,
+               char *char_properties[])
 {
        int flag_count = 0;
 
@@ -1699,42 +1903,42 @@ int bt_hal_gatt_convert_prop2string(
 }
 
 int bt_hal_gatt_convert_perm2string(
-                        bt_hal_gatt_permission_t properties,
-                        char *char_properties[])
-{
-        int flag_count = 0;
-
-        if (properties & BT_HAL_GATT_PERMISSION_READ) {
-                char_properties[flag_count] = g_strdup("read");
-                flag_count++;
-        }
-        if (properties & BT_HAL_GATT_PERMISSION_WRITE) {
-                char_properties[flag_count] = g_strdup("write");
-                flag_count++;
-        }
-        if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_READ) {
-                char_properties[flag_count] = g_strdup("encrypt-read");
-                flag_count++;
-        }
-        if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_WRITE) {
-                char_properties[flag_count] = g_strdup("encrypt-write");
-                flag_count++;
-        }
-        if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_READ) {
-                char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
-                flag_count++;
-        }
-        if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_WRITE) {
-                char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
-                flag_count++;
-        }
-
-        if (flag_count == 0) {
-                char_properties[flag_count] = g_strdup("read");
-                flag_count++;
-        }
-
-        return flag_count;
+               bt_hal_gatt_permission_t properties,
+               char *char_properties[])
+{
+       int flag_count = 0;
+
+       if (properties & BT_HAL_GATT_PERMISSION_READ) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+       if (properties & BT_HAL_GATT_PERMISSION_WRITE) {
+               char_properties[flag_count] = g_strdup("write");
+               flag_count++;
+       }
+       if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-read");
+               flag_count++;
+       }
+       if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-write");
+               flag_count++;
+       }
+       if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_READ) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-read");
+               flag_count++;
+       }
+       if (properties & BT_HAL_GATT_PERMISSION_ENCRYPT_AUTHENTICATED_WRITE) {
+               char_properties[flag_count] = g_strdup("encrypt-authenticated-write");
+               flag_count++;
+       }
+
+       if (flag_count == 0) {
+               char_properties[flag_count] = g_strdup("read");
+               flag_count++;
+       }
+
+       return flag_count;
 }
 
 gboolean _bt_hal_is_service_enabled(const char *uuid)
@@ -1747,8 +1951,6 @@ gboolean _bt_hal_is_service_enabled(const char *uuid)
        gchar *uuid_str;
        gboolean ret = FALSE;
 
-       DBG("+");
-
        proxy = _bt_hal_get_adapter_properties_proxy();
        if (!proxy) {
                DBG("_bt_hal_dbus_get_local_name: Adapter Properties proxy get failed!!!");
@@ -1777,7 +1979,7 @@ gboolean _bt_hal_is_service_enabled(const char *uuid)
                return FALSE;
        }
 
-       while (g_variant_iter_loop(iter, "s", &uuid_str)) {
+       while (g_variant_iter_loop(iter, "&s", &uuid_str)) {
                DBG("UUID string [%s]\n", uuid_str);
                if (!strncasecmp(uuid, uuid_str, strlen(uuid))) {
                        ret = TRUE;
@@ -1788,6 +1990,6 @@ gboolean _bt_hal_is_service_enabled(const char *uuid)
        g_variant_iter_free(iter);
        g_variant_unref(result);
        g_variant_unref(temp);
-       DBG("-");
+
        return ret;
 }