Ignore vconfkey value change for AVC mode on
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-agent.c
index 82fdb13..d231908 100644 (file)
@@ -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.
 #include <string.h>
 #include <malloc.h>
 #include <stacktrim.h>
-
-#if defined(LIBNOTIFY_SUPPORT)
-#include "bt-popup.h"
-#elif defined(LIBNOTIFICATION_SUPPORT)
-#include "bt-service-agent-notification.h"
-#else
 #include <syspopup_caller.h>
-#endif
-
 #include <vconf.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
@@ -103,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;
@@ -112,13 +105,8 @@ static gboolean __bt_agent_system_popup_timer_cb(gpointer user_data)
        retv_if(user_data == NULL, FALSE);
 
        ++retry_count;
-#if defined(LIBNOTIFY_SUPPORT)
-        ret = notify_launch(b);
-#elif defined(LIBNOTIFICATION_SUPPORT)
-        ret = notification_launch(b);
-#else
-        ret = syspopup_launch("bt-syspopup", b);
-#endif
+
+       ret = syspopup_launch("bt-syspopup", b);
        if (ret < 0) {
                BT_ERR("Sorry! Can't launch popup, ret=%d, Re-try[%d] time..",
                                                        ret, retry_count);
@@ -137,193 +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(GDBusProxy *proxy,
-               GAsyncResult *res, gpointer user_data)
-{
-       GError *err = NULL;
-       GVariant *value;
-
-       value = g_dbus_proxy_call_finish(proxy, res, &err);
-       if (value == NULL) {
-               BT_ERR("Error: Unbond Failed");
-               if (err) {
-                       BT_ERR("errCode[%x], message[%s]\n", err->code, err->message);
-                       g_clear_error(&err);
-               }
-               return;
-       }
-       g_variant_unref(value);
-       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++) {
-               GDBusProxy *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;
-               }
-
-               g_dbus_proxy_call(adapter_proxy,
-                               "UnpairDevice", g_variant_new("o", device_path),
-                               G_DBUS_CALL_FLAGS_NONE, -1, NULL,
-                               (GAsyncReadyCallback)__bt_unbond_cb, NULL);
-
-               BT_INFO("unbonding %s is requested", addr);
-
-               g_array_free(device_list, TRUE);
-               return TRUE;
-       }
-
-       g_array_free(device_list, TRUE);
-       return FALSE;
-}
-
-static void __bt_popup_event_filter(GDBusConnection *connection,
-               const gchar *sender_name,
-               const gchar *object_path,
-               const gchar *interface_name,
-               const gchar *signal_name,
-               GVariant *parameters,
-               gpointer user_data)
-{
-       BT_DBG("Sender Name[%s] Object Path[%s] Interface[%s] Signal[%s]",
-                       sender_name, object_path, interface_name, signal_name);
-
-       if (g_strcmp0(interface_name, "User.Bluetooth.syspopup") == 0 &&
-                       g_strcmp0(signal_name, "ResetResponse") == 0) {
-               int response;
-
-               g_variant_get(parameters, "(i)", &response);
-               BT_DBG("response = %d", response);
-       }
-}
-
-int __bt_service_subscribe_popup(GDBusConnection *conn,
-               gboolean subscribe)
-{
-       static guint subs_interface_added_id = 0;
-
-       if (conn == NULL)
-               return BLUETOOTH_ERROR_INVALID_PARAM;
-
-       if (subscribe) {
-               if (subs_interface_added_id == 0) {
-                       subs_interface_added_id = g_dbus_connection_signal_subscribe(conn,
-                                       NULL, "User.Bluetooth.syspopup", "ResetResponse", NULL, NULL, 0,
-                                       __bt_popup_event_filter, NULL, NULL);
-               }
-       } else {
-               if (subs_interface_added_id > 0) {
-                       g_dbus_connection_signal_unsubscribe(conn,
-                                       subs_interface_added_id);
-                       subs_interface_added_id = 0;
-               }
-       }
-       return BLUETOOTH_ERROR_NONE;
-}
-
-static void  __bt_register_popup_event_signal(void)
-{
-       GDBusConnection *conn;
-
-       BT_DBG("+\n");
-
-       conn = _bt_get_system_gconn();
-       if (conn == NULL)
-               return;
-
-       __bt_service_subscribe_popup(conn, TRUE);
-
-       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)
@@ -339,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);
@@ -353,11 +158,6 @@ int _bt_launch_system_popup(bt_agent_event_type_t event_type,
                                                sizeof(event_str));
                break;
 
-       case BT_AGENT_EVENT_PASSKEY_AUTO_ACCEPTED:
-               g_strlcpy(event_str, "passkey-auto-accepted",
-                                               sizeof(event_str));
-               break;
-
        case BT_AGENT_EVENT_PASSKEY_REQUEST:
                g_strlcpy(event_str, "passkey-request", sizeof(event_str));
                break;
@@ -402,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;
@@ -422,9 +215,7 @@ int _bt_launch_system_popup(bt_agent_event_type_t event_type,
 
        bundle_add(b, "event-type", event_str);
 
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
        ret = syspopup_launch("bt-syspopup", b);
-#endif
        if (0 > ret) {
                BT_ERR("Popup launch failed...retry %d", ret);
 
@@ -463,14 +254,25 @@ static GVariant *__bt_service_getall(GDBusProxy *device, const char *interface)
 static gboolean __pincode_request(GapAgentPrivate *agent, GDBusProxy *device)
 {
        uint32_t device_class;
-       const gchar *address;
-       const gchar *name;
+       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) {
@@ -479,13 +281,7 @@ static gboolean __pincode_request(GapAgentPrivate *agent, GDBusProxy *device)
                goto done;
        }
 
-#ifdef AUTO_ACCEPT
-       gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, "0000",
-                                                                               NULL);
-       goto done;
-#endif
-
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       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);
@@ -502,9 +298,19 @@ static gboolean __pincode_request(GapAgentPrivate *agent, GDBusProxy *device)
        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;
+       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)) {
@@ -528,17 +334,25 @@ static gboolean __pincode_request(GapAgentPrivate *agent, GDBusProxy *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_DBG("Show Pin entry");
-               _bt_launch_system_popup(BT_AGENT_EVENT_PIN_REQUEST, name, NULL,
-                                       NULL, _gap_agent_get_path(agent));
+               _bt_launch_system_popup(BT_AGENT_EVENT_PIN_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();
        BT_DBG("-");
 
@@ -547,13 +361,23 @@ done:
 
 static gboolean __passkey_request(GapAgentPrivate *agent, GDBusProxy *device)
 {
-       const gchar *address;
-       const gchar *name;
+       gchar *address = NULL;
+       gchar *name = NULL;
+       unsigned char auth_info[5] = {0, };
        GVariant *reply = NULL;
        GVariant *reply_temp = NULL;
        GVariant *tmp_value;
        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) {
@@ -562,15 +386,9 @@ static gboolean __passkey_request(GapAgentPrivate *agent, GDBusProxy *device)
                goto done;
        }
 
-#ifdef AUTO_ACCEPT
-       gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, "0000",
-                                                                               NULL);
-       goto done;
-#endif
-
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       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);
+       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) {
@@ -582,14 +400,18 @@ static gboolean __passkey_request(GapAgentPrivate *agent, GDBusProxy *device)
        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();
 
        BT_DBG("-");
@@ -599,8 +421,9 @@ done:
 static gboolean __display_request(GapAgentPrivate *agent, GDBusProxy *device,
                                                                guint passkey)
 {
-       const gchar *address;
-       const gchar *name;
+       gchar *address = NULL;
+       gchar *name = NULL;
+       unsigned char auth_info[5] = {0, };
        char *str_passkey;
        GVariant *reply = NULL;
        GVariant *reply_temp = NULL;
@@ -615,15 +438,9 @@ static gboolean __display_request(GapAgentPrivate *agent, GDBusProxy *device,
                goto done;
        }
 
-#ifdef AUTO_ACCEPT
-       gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, "0000",
-                                                                               NULL);
-       goto done;
-#endif
-
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       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);
+       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) {
@@ -635,19 +452,34 @@ static gboolean __display_request(GapAgentPrivate *agent, GDBusProxy *device,
        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("%d", passkey);
+       str_passkey = g_strdup_printf("%06d", passkey);
 
-       _bt_launch_system_popup(BT_AGENT_EVENT_KEYBOARD_PASSKEY_REQUEST, name,
-                                               str_passkey, NULL,
+       if (passkey_watcher) {
+               GVariant *param = 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();
 
        BT_DBG("-");
@@ -657,14 +489,24 @@ done:
 static gboolean __confirm_request(GapAgentPrivate *agent, GDBusProxy *device,
                                                                guint passkey)
 {
-       const gchar *address;
-       const gchar *name;
+       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);
 
        reply_temp = __bt_service_getall(device, BT_DEVICE_INTERFACE);
@@ -676,15 +518,9 @@ static gboolean __confirm_request(GapAgentPrivate *agent, GDBusProxy *device,
                goto done;
        }
 
-#ifdef AUTO_ACCEPT
-       gap_agent_reply_pin_code(agent, GAP_AGENT_ACCEPT, str_passkey,
-                                                                               NULL);
-       goto done;
-#endif
-
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       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);
+       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) {
@@ -692,50 +528,23 @@ static gboolean __confirm_request(GapAgentPrivate *agent, GDBusProxy *device,
                goto done;
        }
 
-       tmp_value = g_variant_lookup_value (reply, "Name", G_VARIANT_TYPE_STRING);
+       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);
 
-#ifdef TIZEN_WEARABLE
-       uint32_t device_class = 0x00;
-       uint32_t major_class;
-
-       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);
-
-       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_AUTO_ACCEPTED, name,
-                               str_passkey, NULL, _gap_agent_get_path(agent));
-
-               gap_agent_reply_confirmation(agent, GAP_AGENT_ACCEPT, NULL);
-       }
-#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();
        BT_DBG("-");
 
@@ -745,9 +554,8 @@ done:
 static gboolean __pairing_cancel_request(GapAgentPrivate *agent, const char *address)
 {
        BT_DBG("On Going Pairing is cancelled by remote\n");
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
+
        syspopup_destroy_all();
-#endif
 
        __bt_agent_release_memory();
 
@@ -763,14 +571,14 @@ static gboolean __a2dp_authorize_request_check(void)
 static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
                                                        const char *uuid)
 {
-       const gchar *address;
-       const gchar *name;
+       gchar *address = NULL;
+       gchar *name = NULL;
+       unsigned char auth_info[5] = {0, };
        gboolean trust;
-       gboolean paired;
        GVariant *reply = NULL;
        GVariant *reply_temp = NULL;
        GVariant *tmp_value;
-#ifdef TIZEN_NETWORK_TETHERING_ENABLE
+#ifdef TIZEN_FEATURE_NETWORK_TETHERING_ENABLE
        bool enabled;
        tethering_h tethering = NULL;
 #endif
@@ -779,12 +587,6 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *device,
 
        BT_DBG("+");
 
-#ifdef AUTO_ACCEPT
-       gap_agent_reply_authorize(agent, GAP_AGENT_ACCEPT,
-                                         NULL);
-       goto done;
-#endif
-
        /* Check if already Media connection exsist */
        if (!strcasecmp(uuid, A2DP_UUID)) {
                gboolean ret = FALSE;
@@ -806,8 +608,10 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *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,
@@ -821,7 +625,7 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *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");
@@ -839,9 +643,8 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *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");
@@ -852,7 +655,7 @@ static gboolean __authorize_request(GapAgentPrivate *agent, GDBusProxy *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);
@@ -868,9 +671,9 @@ fail:
                goto done;
        }
 
-       g_variant_get(reply_temp,"(@a{sv})", &reply); /* Format of reply a{sv}*/
+       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);
+       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) {
@@ -882,21 +685,13 @@ fail:
        g_variant_get(tmp_value, "s", &name);
        G_VARIANT_UNREF(tmp_value);
        if (!name)
-               name = address;
+               name = g_strdup(address);
 
        tmp_value = g_variant_lookup_value(reply, "Trusted", G_VARIANT_TYPE_BOOLEAN);
        g_variant_get(tmp_value, "b", &trust);
        G_VARIANT_UNREF(tmp_value);
 
-       tmp_value = g_variant_lookup_value(reply, "Paired", G_VARIANT_TYPE_BOOLEAN);
-       g_variant_get(tmp_value, "b", &paired);
-       G_VARIANT_UNREF(tmp_value);
-       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);
 
@@ -905,7 +700,7 @@ fail:
                                        NULL) == TRUE) {
                _bt_send_event(BT_OPP_SERVER_EVENT,
                                BLUETOOTH_EVENT_OBEX_SERVER_CONNECTION_AUTHORIZE,
-                               g_variant_new("iss", result, address, name));
+                               g_variant_new("(iss)", result, address, name));
 
                goto done;
        }
@@ -916,10 +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,
-                       g_variant_new("issssn", result, address, uuid,
-                                       name, osp_serv->path, osp_serv->fd));
+               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;
        }
@@ -936,13 +733,19 @@ 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:
-       g_variant_unref(reply);
-       g_variant_unref(reply_temp);
+       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("-");
 
@@ -956,9 +759,7 @@ static gboolean __authorization_cancel_request(GapAgentPrivate *agent,
 
        gap_agent_reply_authorize(agent, GAP_AGENT_CANCEL, NULL);
 
-#if !defined(LIBNOTIFY_SUPPORT) && !defined(LIBNOTIFICATION_SUPPORT)
        syspopup_destroy_all();
-#endif
 
        __bt_agent_release_memory();
 
@@ -1160,12 +961,6 @@ static gboolean __bt_agent_is_device_blacklist(const char *address,
        rewind(fp);
 
        buffer = g_malloc0(sizeof(char) * size);
-       /* Fix : NULL_RETURNS */
-       if (buffer == NULL) {
-               BT_ERR("Fail to allocate memory");
-               fclose(fp);
-               return FALSE;
-       }
        result = fread((char *)buffer, 1, size, fp);
        fclose(fp);
        if (result != size) {
@@ -1314,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;
+}