Add the session timer to handle the exception case
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-agent.c
old mode 100755 (executable)
new mode 100644 (file)
index c0a4a91..d231908
@@ -1,11 +1,5 @@
 /*
- * Bluetooth-frwk
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
- *              Girishashok Joshi <girish.joshi@samsung.com>
- *              Chanyeol Park <chanyeol.park@samsung.com>
+ * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,9 +22,9 @@
 #include <stacktrim.h>
 #include <syspopup_caller.h>
 #include <vconf.h>
-#include <package-manager.h>
+#include <bundle_internal.h>
 
-#ifdef TIZEN_NETWORK_TETHERING_ENABLE
+#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
 #include <tethering.h>
 #endif
 
 #include "bt-service-device.h"
 #include "bt-service-audio.h"
 
+#ifdef TIZEN_DPM_ENABLE
+#include "bt-service-dpm.h"
+#endif
+
 #define BT_APP_AUTHENTICATION_TIMEOUT          35
 #define BT_APP_AUTHORIZATION_TIMEOUT           15
 
 #define GN_UUID "00001117-0000-1000-8000-00805f9b34fb"
 #define BNEP_UUID "0000000f-0000-1000-8000-00805f9b34fb"
 #define HID_UUID "00001124-0000-1000-8000-00805f9b34fb"
+#define HID_DEVICE_UUID                "00001124-0000-1000-8000-00805f9b43bf"
 #define SAP_UUID_OLD "a49eb41e-cb06-495c-9f4f-bb80a90cdf00"
 #define SAP_UUID_NEW "a49eb41e-cb06-495c-9f4f-aa80a90cdf4a"
+#define IOTIVITY_UUID "12341234-1C25-481F-9DFB-59193D238280"
 
 #define BT_AGENT_OBJECT "/org/bluez/agent/frwk_agent"
 
 #define BT_AGENT_SIGNAL_RFCOMM_AUTHORIZE "RfcommAuthorize"
 #define BT_AGENT_SIGNAL_OBEX_AUTHORIZE "ObexAuthorize"
 
-#define BT_PIN_MAX_LENGTH 16
 #define BT_PASSKEY_MAX_LENGTH 4
 
 #define BT_AGENT_SYSPOPUP_TIMEOUT_FOR_MULTIPLE_POPUPS 200
 #define BT_AGENT_SYSPOPUP_MAX_ATTEMPT 3
 #define BT_PAN_MAX_CONNECTION 4
+
 extern guint nap_connected_device_count;
 
+static char *passkey_watcher = NULL;
+
+#define G_VARIANT_UNREF(variant) \
+       g_variant_unref(variant); \
+       variant = NULL
+
 static int __bt_agent_is_auto_response(uint32_t dev_class, const gchar *address,
                                                        const gchar *name);
 static gboolean __bt_agent_is_hid_keyboard(uint32_t dev_class);
@@ -91,7 +97,6 @@ static void __bt_agent_release_memory(void)
        /* Release Stack Memory*/
        stack_trim();
 }
-
 static gboolean __bt_agent_system_popup_timer_cb(gpointer user_data)
 {
        int ret;
@@ -120,190 +125,9 @@ static gboolean __bt_agent_system_popup_timer_cb(gpointer user_data)
        return (ret < 0) ? TRUE : FALSE;
 }
 
-#ifdef TIZEN_WEARABLE
-static void __bt_unbond_cb(DBusGProxy *proxy, DBusGProxyCall *call,
-                               gpointer user_data)
-{
-       GError *err = NULL;
-
-       dbus_g_proxy_end_call(proxy, call, &err, G_TYPE_INVALID);
-       if (err != NULL) {
-               BT_ERR("Error occured in RemoveBonding [%s]\n", err->message);
-               g_error_free(err);
-               return;
-       }
-
-       BT_INFO("Unbonding is done");
-       return;
-}
-
-static gboolean __bt_unpair_device(void)
-{
-       GArray *device_list;
-       int no_of_device;
-       int i;
-
-       device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
-       if (device_list == NULL) {
-               BT_ERR("g_array_new is failed");
-               return FALSE;
-       }
-
-       if (_bt_get_bonded_devices(&device_list) != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("_bt_get_bonded_devices is failed");
-               g_array_free(device_list, TRUE);
-               return FALSE;
-       }
-
-       no_of_device = device_list->len / sizeof(bluetooth_device_info_t);
-       for (i = 0; i < no_of_device; i++) {
-               DBusGProxy *adapter_proxy;
-               bluetooth_device_info_t info;
-               char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
-               char *device_path = NULL;
-
-               info = g_array_index(device_list, bluetooth_device_info_t, i);
-               if (info.device_class.major_class ==
-                               BLUETOOTH_DEVICE_MAJOR_CLASS_AUDIO)
-                       continue;
-
-               adapter_proxy = _bt_get_adapter_proxy();
-               if (!adapter_proxy) {
-                       BT_ERR("adapter_proxy is NULL");
-                       g_array_free(device_list, TRUE);
-                       return FALSE;
-               }
-
-               _bt_convert_addr_type_to_string(addr, info.device_address.addr);
-               device_path = _bt_get_device_object_path(addr);
-               if (device_path == NULL) {
-                       BT_ERR("device_path is NULL");
-                       g_array_free(device_list, TRUE);
-                       return FALSE;
-               }
-
-               if (!dbus_g_proxy_begin_call(adapter_proxy, "UnpairDevice",
-                                       (DBusGProxyCallNotify)__bt_unbond_cb,
-                                       NULL, NULL,
-                                       DBUS_TYPE_G_OBJECT_PATH, device_path,
-                                       G_TYPE_INVALID)) {
-                       BT_ERR("RemoveBonding begin failed\n");
-                       g_array_free(device_list, TRUE);
-                       return FALSE;
-               }
-               BT_INFO("unbonding %s is requested", addr);
-
-               g_array_free(device_list, TRUE);
-               return TRUE;
-       }
-
-       g_array_free(device_list, TRUE);
-       return FALSE;
-}
-
-static DBusHandlerResult __bt_popup_event_filter(DBusConnection *conn,
-               DBusMessage *msg, void *data)
-{
-       int response;
-
-       BT_DBG("+");
-
-       if (msg == NULL)
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-       if (!dbus_message_is_signal(msg, "User.Bluetooth.syspopup", "ResetResponse"))
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
-       if (!dbus_message_get_args(msg, NULL,
-                               DBUS_TYPE_INT32, &response,
-                               DBUS_TYPE_INVALID)) {
-               return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-       }
-
-       BT_DBG("response = %d", response);
-
-       BT_DBG("-");
-       return DBUS_HANDLER_RESULT_HANDLED;
-}
-
-static void  __bt_register_popup_event_signal(void)
-{
-       DBusError dbus_error;
-       DBusGConnection *gconn;
-       DBusConnection *conn;
-
-       BT_DBG("+\n");
-
-       gconn = _bt_get_system_gconn();
-       if (gconn == NULL)
-               return;
-
-       conn = dbus_g_connection_get_connection(gconn);
-       if (conn == NULL)
-               return;
-
-       dbus_connection_add_filter(conn, __bt_popup_event_filter, NULL, NULL);
-
-       dbus_error_init(&dbus_error);
-       dbus_bus_add_match(conn,
-                       "type='signal',interface='User.Bluetooth.syspopup'"
-                       ",member='ResetResponse'", &dbus_error);
-       if (dbus_error_is_set(&dbus_error)) {
-               BT_ERR("Error: %s\n", dbus_error.message);
-               dbus_error_free(&dbus_error);
-               return;
-       }
-
-       BT_DBG("-\n");
-       return;
-}
-
-static gboolean __is_reset_required(const gchar *address)
-{
-       GArray *device_list;
-       uint32_t no_of_device;
-       uint32_t i;
-       bluetooth_device_info_t info;
-       gboolean is_required = FALSE;
-
-       device_list = g_array_new(FALSE, FALSE, sizeof(gchar));
-       if (device_list == NULL) {
-               BT_ERR("g_array_new is failed");
-               return FALSE;
-       }
-
-       if (_bt_get_bonded_devices(&device_list) != BLUETOOTH_ERROR_NONE) {
-               BT_ERR("_bt_get_bonded_devices is failed");
-               g_array_free(device_list, TRUE);
-               return FALSE;
-       }
-
-       no_of_device = device_list->len / sizeof(bluetooth_device_info_t);
-       for (i = 0; i < no_of_device; i++) {
-               char addr[BT_ADDRESS_STRING_SIZE] = { 0 };
-
-               info = g_array_index(device_list, bluetooth_device_info_t, i);
-
-               _bt_convert_addr_type_to_string(addr, info.device_address.addr);
-               if (g_strcmp0(address, addr) == 0) {
-                       BT_DBG("This device is already in paired list");
-                       is_required = FALSE;
-                       break;
-               }
-
-               if (info.device_class.major_class != BLUETOOTH_DEVICE_MAJOR_CLASS_AUDIO) {
-                       is_required = TRUE;
-                       break;
-               }
-       }
-       g_array_free(device_list, TRUE);
-
-       return is_required;
-}
-#endif
-
 int _bt_launch_system_popup(bt_agent_event_type_t event_type,
                                                        const char *device_name,
+                                                       const unsigned char *auth_info,
                                                        char *passkey,
                                                        const char *filename,
                                                        const char *agent_path)
@@ -319,6 +143,7 @@ int _bt_launch_system_popup(bt_agent_event_type_t event_type,
        }
 
        bundle_add(b, "device-name", device_name);
+       bundle_add(b, "auth-info", (const char *)auth_info);
        bundle_add(b, "passkey", passkey);
        bundle_add(b, "file", filename);
        bundle_add(b, "agent-path", agent_path);
@@ -377,13 +202,6 @@ int _bt_launch_system_popup(bt_agent_event_type_t event_type,
                g_strlcpy(event_str, "message-request", sizeof(event_str));
                break;
 
-#ifdef TIZEN_WEARABLE
-       case BT_AGENT_EVENT_SYSTEM_RESET_REQUEST:
-               __bt_register_popup_event_signal();
-               g_strlcpy(event_str, "system-reset-request", sizeof(event_str));
-               break;
-#endif
-
        case BT_AGENT_EVENT_LEGACY_PAIR_FAILED_FROM_REMOTE:
                g_strlcpy(event_str, "remote-legacy-pair-failed", sizeof(event_str));
                break;
@@ -411,53 +229,98 @@ int _bt_launch_system_popup(bt_agent_event_type_t event_type,
        return 0;
 }
 
-static gboolean __pincode_request(GapAgent *agent, DBusGProxy *device)
+static GVariant *__bt_service_getall(GDBusProxy *device, const char *interface)
 {
-       uint32_t device_class;
-       GHashTable *hash = NULL;
-       GValue *value;
-       const gchar *address;
-       const gchar *name;
        GError *error = NULL;
+       GVariant *reply;
+
+       reply = g_dbus_proxy_call_sync(device,
+                       "GetAll", g_variant_new("(s)", interface),
+                       G_DBUS_CALL_FLAGS_NONE, -1,
+                       NULL, &error);
+       if (reply == NULL) {
+               ERR("GetAll dBUS-RPC failed");
+               if (error) {
+                       ERR("D-Bus API failure: errCode[%x], message[%s]",
+                               error->code, error->message);
+                       g_clear_error(&error);
+               }
+               return NULL;
+       }
 
-       BT_INFO("+");
+       return reply;
+}
 
-       dbus_g_proxy_call(device, "GetAll", &error,
-                               G_TYPE_STRING, BT_DEVICE_INTERFACE,
-                               G_TYPE_INVALID,
-                               dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
-                               G_TYPE_VALUE), &hash, G_TYPE_INVALID);
-       if (error) {
-               BT_ERR("error in GetBasicProperties [%s]\n", error->message);
-               g_error_free(error);
+static gboolean __pincode_request(GapAgentPrivate *agent, GDBusProxy *device)
+{
+       uint32_t device_class;
+       gchar *address = NULL;
+       unsigned char auth_info[5] = {0, };
+       gchar *name = NULL;
+       GVariant *reply = NULL;
+       GVariant *reply_temp = NULL;
+       GVariant *tmp_value;
+       char pin_code[BLUETOOTH_PIN_CODE_MAX_LENGTH + 1];
+
+       BT_DBG("+");
+
+#ifdef TIZEN_DPM_ENABLE
+       if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
+               BT_ERR("Not allow to pair the device");
+               gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
+               __bt_agent_release_memory();
+               return TRUE;
+       }
+#endif
+
+       reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
+
+       if (reply_temp == NULL) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
-                                            NULL);
+                               NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Class");
-       device_class = value ? g_value_get_uint(value) : 0;
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
+
+       tmp_value = g_variant_lookup_value(reply, "Class", G_VARIANT_TYPE_UINT32);
+       g_variant_get(tmp_value, "u", &device_class);
+       G_VARIANT_UNREF(tmp_value);
 
-       value = g_hash_table_lookup(hash, "Address");
-       address = value ? g_value_get_string(value) : NULL;
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &address);
+       G_VARIANT_UNREF(tmp_value);
        if (!address) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Name");
-       name = value ? g_value_get_string(value) : NULL;
-       if (!name)
-               name = address;
+       tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &name);
+       G_VARIANT_UNREF(tmp_value);
+       if (!name) {
+               BT_DBG("Replacing the name with address");
+               name = g_strdup(address);
+       } else {
+               BT_INFO("Name = %s, Address = %s, Class = 0x%x", name, address, device_class);
+               if (name[0] == '\0') {
+                       g_free(name);
+                       BT_DBG("Name[0]=NULL, Replacing the name with address");
+                       name = g_strdup(address);
+               }
+       }
 
+       __bt_get_auth_info(reply, (char *)auth_info);
        if (_bt_is_device_creating() == TRUE &&
                _bt_is_bonding_device_address(address) == TRUE &&
                __bt_agent_is_auto_response(device_class, address, name)) {
-               /* Use Fixed PIN "0000" for basic pairing*/
+               BT_DBG("0000 Auto Pair");
+               /* Use Fixed PIN "0000" for basic pairing */
                _bt_set_autopair_status_in_bonding_info(TRUE);
                gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, "0000",
                                                                        NULL);
        } else if (__bt_agent_is_hid_keyboard(device_class)) {
+               BT_DBG("HID Keyboard");
                char str_passkey[BT_PASSKEY_MAX_LENGTH + 1] = { 0 };
 
                if (__bt_agent_generate_passkey(str_passkey,
@@ -471,204 +334,224 @@ static gboolean __pincode_request(GapAgent *agent, DBusGProxy *device)
                                                        str_passkey, NULL);
 
                _bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST,
-                                               name, str_passkey, NULL,
+                                               name, auth_info, str_passkey, NULL,
                                                _gap_agent_get_path(agent));
+       } else if (_bt_get_device_pin_code(address, pin_code)
+                               == BLUETOOTH_ERROR_NONE) {
+               BT_DBG("Use stored PIN code(%s)", pin_code);
+               gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, pin_code,
+                                                                       NULL);
+               goto done;
        } else {
-               _bt_launch_system_popup(BT_AGENT_EVENT_PIN_REQUEST, name, NULL,
-                                       NULL, _gap_agent_get_path(agent));
+               BT_DBG("Show Pin entry");
+               _bt_launch_system_popup(BT_AGENT_EVENT_PIN_REQUEST, name, auth_info,
+                                       NULL, NULL, _gap_agent_get_path(agent));
        }
 
 done:
-       g_hash_table_destroy(hash);
+       g_variant_unref(reply);
+       g_variant_unref(reply_temp);
+       g_free(address);
+       g_free(name);
        __bt_agent_release_memory();
-
        BT_DBG("-");
 
        return TRUE;
 }
 
-static gboolean __passkey_request(GapAgent *agent, DBusGProxy *device)
+static gboolean __passkey_request(GapAgentPrivate *agent, GDBusProxy *device)
 {
-       GHashTable *hash = NULL;
-       GValue *value;
-       const gchar *address;
-       const gchar *name;
-       GError *error = NULL;
-
+       gchar *address = NULL;
+       gchar *name = NULL;
+       unsigned char auth_info[5] = {0, };
+       GVariant *reply = NULL;
+       GVariant *reply_temp = NULL;
+       GVariant *tmp_value;
        BT_DBG("+");
 
-       dbus_g_proxy_call(device, "GetAll", &error,
-                               G_TYPE_STRING, BT_DEVICE_INTERFACE,
-                               G_TYPE_INVALID,
-                               dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
-                               G_TYPE_VALUE), &hash, G_TYPE_INVALID);
-       if (error) {
-               BT_ERR("error in GetBasicProperties [%s]\n", error->message);
-               g_error_free(error);
+#ifdef TIZEN_DPM_ENABLE
+       if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
+               BT_ERR("Not allow to pair the device");
+               gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
+               __bt_agent_release_memory();
+               return TRUE;
+       }
+#endif
+
+       reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
+
+       if (reply_temp == NULL) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
                                             NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Address");
-       address = value ? g_value_get_string(value) : NULL;
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
+
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &address);
+       G_VARIANT_UNREF(tmp_value);
        if (!address) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Name");
-       name = value ? g_value_get_string(value) : NULL;
+       tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &name);
+       G_VARIANT_UNREF(tmp_value);
        if (!name)
-               name = address;
+               name = g_strdup(address);
 
-       _bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_REQUEST, name, NULL, NULL,
-                                               _gap_agent_get_path(agent));
+       __bt_get_auth_info(reply, (char *)auth_info);
+
+       _bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_REQUEST, name, auth_info,
+                                               NULL, NULL, _gap_agent_get_path(agent));
 
 done:
+       g_variant_unref(reply);
+       g_variant_unref(reply_temp);
+       g_free(address);
+       g_free(name);
        __bt_agent_release_memory();
-       g_hash_table_destroy(hash);
-       BT_DBG("-");
 
+       BT_DBG("-");
        return TRUE;
 }
 
-static gboolean __display_request(GapAgent *agent, DBusGProxy *device,
+static gboolean __display_request(GapAgentPrivate *agent, GDBusProxy *device,
                                                                guint passkey)
 {
-       GHashTable *hash = NULL;
-       GValue *value;
-       const gchar *address;
-       const gchar *name;
-       GError *error = NULL;
+       gchar *address = NULL;
+       gchar *name = NULL;
+       unsigned char auth_info[5] = {0, };
        char *str_passkey;
+       GVariant *reply = NULL;
+       GVariant *reply_temp = NULL;
+       GVariant *tmp_value = NULL;
 
        BT_DBG("+");
 
-       dbus_g_proxy_call(device, "GetAll", &error,
-                               G_TYPE_STRING, BT_DEVICE_INTERFACE,
-                               G_TYPE_INVALID,
-                               dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
-                               G_TYPE_VALUE), &hash, G_TYPE_INVALID);
-       if (error) {
-               BT_ERR("error in GetBasicProperties [%s]\n", error->message);
-               g_error_free(error);
+       reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
+       if (reply_temp == NULL) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
                                             NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Address");
-       address = value ? g_value_get_string(value) : NULL;
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
+
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &address);
+       G_VARIANT_UNREF(tmp_value);
        if (!address) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Name");
-       name = value ? g_value_get_string(value) : NULL;
+       tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &name);
+       G_VARIANT_UNREF(tmp_value);
        if (!name)
-               name = address;
+               name = g_strdup(address);
+
+       __bt_get_auth_info(reply, (char *)auth_info);
+
+       str_passkey = g_strdup_printf("%06d", passkey);
 
-       str_passkey = g_strdup_printf("%d", passkey);
+       if (passkey_watcher) {
+               GVariant *param = NULL;
 
-       _bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST, name,
-                                               str_passkey, NULL,
+               BT_INFO("Send passkey to %s", passkey_watcher);
+
+               param = g_variant_new("(ss)", address, str_passkey);
+
+               _bt_send_event_to_dest(passkey_watcher, BT_ADAPTER_EVENT,
+                               BLUETOOTH_EVENT_PASSKEY_NOTIFICATION, param);
+       } else {
+               _bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST, name,
+                                               auth_info, str_passkey, NULL,
                                                _gap_agent_get_path(agent));
+       }
 
        g_free(str_passkey);
 
 done:
+       g_variant_unref(reply);
+       g_variant_unref(reply_temp);
+       g_free(address);
+       g_free(name);
        __bt_agent_release_memory();
-       g_hash_table_destroy(hash);
-       BT_DBG("-");
 
+       BT_DBG("-");
        return TRUE;
 }
 
-static gboolean __confirm_request(GapAgent *agent, DBusGProxy *device,
+static gboolean __confirm_request(GapAgentPrivate *agent, GDBusProxy *device,
                                                                guint passkey)
 {
-       GHashTable *hash = NULL;
-       GValue *value;
-       const gchar *address;
-       const gchar *name;
-       GError *error = NULL;
+       gchar *address = NULL;
+       gchar *name = NULL;
+       unsigned char auth_info[5] = {0, };
        char str_passkey[7];
-
+       GVariant *reply_temp = NULL;
+       GVariant *reply = NULL;
+       GVariant *tmp_value;
        BT_DBG("+ passkey[%.6d]", passkey);
 
+#ifdef TIZEN_DPM_ENABLE
+       if (_bt_dpm_get_bluetooth_pairing_state() == DPM_RESTRICTED) {
+               BT_ERR("Not allow to pair the device");
+               gap_agent_reply_confirmation(agent, GAP_AGENT_REJECT, NULL);
+               __bt_agent_release_memory();
+               return TRUE;
+       }
+#endif
+
        snprintf(str_passkey, sizeof(str_passkey), "%.6d", passkey);
 
-       dbus_g_proxy_call(device, "GetAll", &error,
-                               G_TYPE_STRING, BT_DEVICE_INTERFACE,
-                               G_TYPE_INVALID,
-                               dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
-                               G_TYPE_VALUE), &hash, G_TYPE_INVALID);
+       reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
 
-       if (error) {
-               BT_ERR("error in GetBasicProperties [%s]", error->message);
-               g_error_free(error);
+       if (reply_temp == NULL) {
+               BT_ERR("Device doesn't exist");
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
                                             NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Address");
-       address = value ? g_value_get_string(value) : NULL;
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
+
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &address);
+       G_VARIANT_UNREF(tmp_value);
        if (!address) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Name");
-       name = value ? g_value_get_string(value) : NULL;
+       tmp_value = g_variant_lookup_value(reply, "Name", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &name);
+       G_VARIANT_UNREF(tmp_value);
        if (!name)
-               name = address;
-
-#ifdef TIZEN_WEARABLE
-       uint32_t device_class = 0x00;
-       uint32_t major_class;
-
-       value = g_hash_table_lookup(hash, "Class");
-       device_class = value ? g_value_get_uint(value) : 0;
-
-       BT_INFO("COD : 0x%X", device_class);
+               name = g_strdup(address);
+       __bt_get_auth_info(reply, (char *)auth_info);
 
-       major_class = (device_class & 0x1f00) >> 8;
-
-       if (major_class == BLUETOOTH_DEVICE_MAJOR_CLASS_AUDIO) {
-               BT_DBG("Audio device. Launch passkey pop-up");
-               _bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST, name,
-                               str_passkey, NULL, _gap_agent_get_path(agent));
-               goto done;
-       }
-
-       if (__is_reset_required(address)) {
-               BT_INFO("Launch system reset pop-up");
-               _bt_launch_system_popup(BT_AGENT_EVENT_SYSTEM_RESET_REQUEST, name,
-                               NULL, NULL, _gap_agent_get_path(agent));
-       } else {
-               BT_INFO("Launch passkey pop-up");
-               _bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST, name,
-                               str_passkey, NULL, _gap_agent_get_path(agent));
-       }
-#else
+       BT_DBG("LAUNCH SYSPOPUP");
        _bt_launch_system_popup(BT_AGENT_EVENT_PASSKEY_CONFIRM_REQUEST, name,
-                                               str_passkey, NULL,
+                                               auth_info, str_passkey, NULL,
                                                _gap_agent_get_path(agent));
-#endif
 
 done:
+       g_variant_unref(reply);
+       g_variant_unref(reply_temp);
+       g_free(address);
+       g_free(name);
        __bt_agent_release_memory();
-       g_hash_table_destroy(hash);
-
        BT_DBG("-");
 
        return TRUE;
 }
 
-static gboolean __pairing_cancel_request(GapAgent *agent, const char *address)
+static gboolean __pairing_cancel_request(GapAgentPrivate *agent, const char *address)
 {
        BT_DBG("On Going Pairing is cancelled by remote\n");
 
@@ -685,21 +568,20 @@ static gboolean __a2dp_authorize_request_check(void)
        return _bt_is_headset_type_connected(BT_AUDIO_A2DP, NULL);
 }
 
-static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
+static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
                                                        const char *uuid)
 {
-       GHashTable *hash = NULL;
-       GValue *value;
-       const gchar *address;
-       const gchar *name;
+       gchar *address = NULL;
+       gchar *name = NULL;
+       unsigned char auth_info[5] = {0, };
        gboolean trust;
-       gboolean paired;
-#ifdef TIZEN_NETWORK_TETHERING_ENABLE
+       GVariant *reply = NULL;
+       GVariant *reply_temp = NULL;
+       GVariant *tmp_value;
+#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
        bool enabled;
        tethering_h tethering = NULL;
-       int ret = TETHERING_ERROR_NONE;
 #endif
-       GError *error = NULL;
        int result = BLUETOOTH_ERROR_NONE;
        int request_type = BT_AGENT_EVENT_AUTHORIZE_REQUEST;
 
@@ -726,8 +608,10 @@ static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
             !strcasecmp(uuid, HSP_HS_UUID) ||
             !strcasecmp(uuid, A2DP_UUID) ||
             !strcasecmp(uuid, HID_UUID) ||
+            !strcasecmp(uuid, HID_DEVICE_UUID) ||
             !strcasecmp(uuid, SAP_UUID_OLD) ||
             !strcasecmp(uuid, SAP_UUID_NEW) ||
+            !strcasecmp(uuid, IOTIVITY_UUID) ||
             !strcasecmp(uuid, AVRCP_TARGET_UUID)) {
                BT_DBG("Auto accept authorization for audio device (HFP, A2DP, AVRCP) [%s]", uuid);
                gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
@@ -741,7 +625,7 @@ static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
              !strcasecmp(uuid, BNEP_UUID)) {
 
                BT_DBG("Network connection request: %s", uuid);
-#ifdef TIZEN_NETWORK_TETHERING_ENABLE
+#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
                if (nap_connected_device_count >=
                                        BT_PAN_MAX_CONNECTION) {
                        BT_ERR("Max connection exceeded");
@@ -759,9 +643,8 @@ static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
 
                ret = tethering_destroy(tethering);
 
-               if (ret != TETHERING_ERROR_NONE) {
+               if (ret != TETHERING_ERROR_NONE)
                        BT_ERR("Fail to create tethering: %d", ret);
-               }
 
                if (enabled != true) {
                        BT_ERR("BT tethering is not enabled");
@@ -772,7 +655,7 @@ static gboolean __authorize_request(GapAgent *agent, DBusGProxy *device,
                gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
                                              NULL);
                goto done;
-#ifdef TIZEN_NETWORK_TETHERING_ENABLE
+#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
 fail:
                gap_agent_reply_authorize(agent, GAP_AGENT_REJECT,
                      NULL);
@@ -781,55 +664,43 @@ fail:
 #endif
        }
 
-       dbus_g_proxy_call(device, "GetAll", &error,
-                               G_TYPE_STRING, BT_DEVICE_INTERFACE,
-                               G_TYPE_INVALID,
-                               dbus_g_type_get_map("GHashTable", G_TYPE_STRING,
-                               G_TYPE_VALUE), &hash, G_TYPE_INVALID);
-       if (error) {
-               BT_ERR("error in GetBasicProperties [%s]\n", error->message);
-               g_error_free(error);
+       reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
+       if (reply_temp == NULL) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "",
                                             NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Address");
-       address = value ? g_value_get_string(value) : NULL;
+       g_variant_get(reply_temp, "(@a{sv})", &reply); /* Format of reply a{sv}*/
+
+       tmp_value = g_variant_lookup_value(reply, "Address", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &address);
+       G_VARIANT_UNREF(tmp_value);
        if (!address) {
                gap_agent_reply_pin_code(agent, GAP_AGENT_REJECT, "", NULL);
                goto done;
        }
 
-       value = g_hash_table_lookup(hash, "Alias");
-       name = value ? g_value_get_string(value) : NULL;
+       tmp_value = g_variant_lookup_value(reply, "Alias", G_VARIANT_TYPE_STRING);
+       g_variant_get(tmp_value, "s", &name);
+       G_VARIANT_UNREF(tmp_value);
        if (!name)
-               name = address;
+               name = g_strdup(address);
 
-       value = g_hash_table_lookup(hash, "Trusted");
-       trust = value ? g_value_get_boolean(value) : 0;
+       tmp_value = g_variant_lookup_value(reply, "Trusted", G_VARIANT_TYPE_BOOLEAN);
+       g_variant_get(tmp_value, "b", &trust);
+       G_VARIANT_UNREF(tmp_value);
 
-       value = g_hash_table_lookup(hash, "Paired");
-       paired = value ? g_value_get_boolean(value) : 0;
-       if ((paired == FALSE) && (trust == FALSE)) {
-               BT_ERR("No paired & No trusted device");
-               gap_agent_reply_authorize(agent,
-                                             GAP_AGENT_REJECT, NULL);
-               goto done;
-       }
+       __bt_get_auth_info(reply, (char *)auth_info);
 
-       BT_INFO("Authorization request for device [%s] Service:[%s]\n", address,
-                                                                       uuid);
+       BT_INFO("Authorization request for device [%s] Service:[%s]\n", address, uuid);
 
        if (strcasecmp(uuid, OPP_UUID) == 0 &&
             _gap_agent_exist_osp_server(agent, BT_OBEX_SERVER,
                                        NULL) == TRUE) {
                _bt_send_event(BT_OPP_SERVER_EVENT,
-                       BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
-                       DBUS_TYPE_INT32, &result,
-                       DBUS_TYPE_STRING, &address,
-                       DBUS_TYPE_STRING, &name,
-                       DBUS_TYPE_INVALID);
+                               BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
+                               g_variant_new("(iss)", result, address, name));
 
                goto done;
        }
@@ -840,15 +711,12 @@ fail:
                osp_serv = _gap_agent_get_osp_server(agent,
                                                BT_RFCOMM_SERVER, (char *)uuid);
 
-               _bt_send_event(BT_RFCOMM_SERVER_EVENT,
-                       BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
-                       DBUS_TYPE_INT32, &result,
-                       DBUS_TYPE_STRING, &address,
-                       DBUS_TYPE_STRING, &uuid,
-                       DBUS_TYPE_STRING, &name,
-                       DBUS_TYPE_STRING, &osp_serv->path,
-                       DBUS_TYPE_INT16, &osp_serv->fd,
-                       DBUS_TYPE_INVALID);
+               if (osp_serv) {
+                       _bt_send_event(BT_RFCOMM_SERVER_EVENT,
+                               BLUETOOTH_EVENT_RFCOMM_AUTHORIZE,
+                               g_variant_new("(issssn)", result, address, uuid,
+                                               name, osp_serv->path, osp_serv->fd));
+               }
 
                goto done;
        }
@@ -865,20 +733,26 @@ fail:
                gap_agent_reply_authorize(agent,
                                              GAP_AGENT_ACCEPT, NULL);
        } else {
-               _bt_launch_system_popup(request_type, name, NULL, NULL,
+               _bt_launch_system_popup(request_type, name, auth_info, NULL, NULL,
                                                _gap_agent_get_path(agent));
        }
 
 done:
-       __bt_agent_release_memory();
-       g_hash_table_destroy(hash);
+       if (reply)
+               g_variant_unref(reply);
+
+       if (reply_temp)
+               g_variant_unref(reply_temp);
 
+       g_free(name);
+       g_free(address);
+       __bt_agent_release_memory();
        BT_DBG("-");
 
        return TRUE;
 }
 
-static gboolean __authorization_cancel_request(GapAgent *agent,
+static gboolean __authorization_cancel_request(GapAgentPrivate *agent,
                                                        const char *address)
 {
        BT_DBG("On Going Authorization is cancelled by remote\n");
@@ -897,16 +771,16 @@ void _bt_destroy_agent(void *agent)
        if (!agent)
                return;
 
-       _gap_agent_reset_dbus(agent);
+       _gap_agent_reset_dbus((GapAgentPrivate *)agent);
 
-       g_object_unref(agent);
+       g_free(agent);
 }
 
 void* _bt_create_agent(const char *path, gboolean adapter)
 {
        GAP_AGENT_FUNC_CB func_cb;
-       DBusGProxy *adapter_proxy;
-       GapAgentagent;
+       GDBusProxy *adapter_proxy;
+       GapAgentPrivate *agent;
 
        adapter_proxy = _bt_get_adapter_proxy();
        if (!adapter_proxy)
@@ -920,14 +794,15 @@ void* _bt_create_agent(const char *path, gboolean adapter)
        func_cb.pairing_cancel_func = __pairing_cancel_request;
        func_cb.authorization_cancel_func = __authorization_cancel_request;
 
-       agent = _gap_agent_new();
+       /* Allocate memory*/
+       agent = g_new0(GapAgentPrivate, 1);
 
        _gap_agent_setup_dbus(agent, &func_cb, path, adapter_proxy);
 
        if (adapter) {
                if (!_gap_agent_register(agent)) {
                        _bt_destroy_agent(agent);
-                       return NULL;
+                       agent = NULL;
                }
        }
 
@@ -948,6 +823,7 @@ gboolean _bt_agent_register_osp_server(const gint type,
 gboolean _bt_agent_unregister_osp_server(const gint type, const char *uuid)
 {
        void *agent = _bt_get_adapter_agent();
+
        if (!agent)
                return FALSE;
 
@@ -1019,7 +895,7 @@ static gboolean __bt_agent_find_device_by_address_exactname(char *buffer,
                                                        const char *address)
 {
        char *pch;
-       char *last = NULL;
+       char *last;
 
        pch = strtok_r(buffer, "= ,", &last);
 
@@ -1039,7 +915,7 @@ static gboolean __bt_agent_find_device_by_partial_name(char *buffer,
                                                const char *partial_name)
 {
        char *pch;
-       char *last = NULL;
+       char *last;
 
        pch = strtok_r(buffer, "= ,", &last);
 
@@ -1233,3 +1109,17 @@ static int __bt_agent_generate_passkey(char *passkey, int size)
 
        return 0;
 }
+
+int _bt_set_passkey_notification(const char *sender, gboolean enable)
+{
+       BT_INFO("Set passkey notification(sender:%s, %s)",
+                       sender, enable ? "Enable" : "Disable");
+
+       g_free(passkey_watcher);
+       if (enable == TRUE)
+               passkey_watcher = g_strdup(sender);
+       else
+               passkey_watcher = NULL;
+
+       return BLUETOOTH_ERROR_NONE;
+}