Simplify the logic to manage invocation list
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / device / bt-service-core-device.c
index d0ce179..cabb572 100644 (file)
@@ -56,7 +56,9 @@
 #include <oal-adapter-mgr.h>
 #include <oal-device-mgr.h>
 
+#if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
 #define MAX_BOND_RETRY_COUNT 3
+#endif
 #define BT_PASSKEY_MAX_LENGTH 4
 
 #define BT_LE_CONN_PARAM_DEFAULT_SUPERVISION_TIMEOUT    6000    /* msec */
@@ -133,7 +135,9 @@ typedef enum {
 
 /* BT device bond state variable */
 static bt_bond_state_e bt_device_bond_state;
+#if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
 static int bond_retry_count;
+#endif
 
 static char *passkey_watcher;
 static GSList *pin_info_list = NULL;
@@ -248,7 +252,7 @@ void __bt_device_handle_pending_requests(int result, int service_function,
                                BT_ERR("Unexpected: Info request pending for a different address!!");
                                return;
                        } else {
-                               BT_INFO("Found info request addr [%s]", (char*)req_info->user_data);
+                               BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
                                bt_sdp_info_t sdp_info;
 
                                memset(&sdp_info, 0x00, sizeof(bt_sdp_info_t));
@@ -258,7 +262,6 @@ void __bt_device_handle_pending_requests(int result, int service_function,
                                g_array_append_vals(out_param, &sdp_info, sizeof(bt_sdp_info_t));
                                _bt_service_method_return(req_info->context, out_param, result);
 
-                               g_free(req_info->user_data);
                                _bt_free_info_from_invocation_list(req_info);
                                g_array_free(out_param, TRUE);
                        }
@@ -270,7 +273,7 @@ void __bt_device_handle_pending_requests(int result, int service_function,
                                BT_ERR("Unexpected: Info request pending for a different address!!");
                                return;
                        } else {
-                               BT_INFO("Found info request addr [%s]", (char*)req_info->user_data);
+                               BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
                                bluetooth_device_info_t dev_info;
                                memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
                                _bt_convert_addr_string_to_type(dev_info.device_address.addr,
@@ -280,7 +283,6 @@ void __bt_device_handle_pending_requests(int result, int service_function,
                                                sizeof(bluetooth_device_info_t));
                                _bt_service_method_return(req_info->context, out_param, result);
 
-                               g_free(req_info->user_data);
                                _bt_free_info_from_invocation_list(req_info);
                                g_array_free(out_param, TRUE);
                        }
@@ -292,7 +294,7 @@ void __bt_device_handle_pending_requests(int result, int service_function,
                                BT_ERR("Unexpected: Info request pending for a different address!!");
                                return;
                        } else {
-                               BT_INFO("Found info request addr [%s]", (char*)req_info->user_data);
+                               BT_DBG("Found info request addr [%s]", (char*)req_info->user_data);
                                bluetooth_device_address_t dev_addr;
                                _bt_convert_addr_string_to_type(dev_addr.addr, address);
                                out_param = g_array_new(FALSE, FALSE, sizeof(gchar));
@@ -300,7 +302,6 @@ void __bt_device_handle_pending_requests(int result, int service_function,
                                                sizeof(bluetooth_device_address_t));
                                _bt_service_method_return(req_info->context, out_param, result);
 
-                               g_free(req_info->user_data);
                                _bt_free_info_from_invocation_list(req_info);
                                g_array_free(out_param, TRUE);
                        }
@@ -311,7 +312,7 @@ void __bt_device_handle_pending_requests(int result, int service_function,
                        break;
                }
        }
-       BT_INFO("-");
+       BT_DBG("-");
 }
 
 /*
@@ -324,7 +325,6 @@ static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_d
 {
        bt_remote_dev_info_t *rem_info = NULL;
 
-       BT_DBG("+");
        rem_info = g_malloc0(sizeof(bt_remote_dev_info_t));
        _bt_copy_remote_dev(rem_info, &(oal_dev_props->device_info));
 
@@ -349,13 +349,13 @@ static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_d
 
        /* a. Check if bonding is on-going, if yes, we MUST update the bonding device properties */
        if (trigger_bond_info  && !strcmp(trigger_bond_info->addr, rem_info->address)) {
-               BT_INFO("Bonding is ongoing, try update properties");
+               BT_DBG("Bonding is ongoing, try update properties");
                if (!trigger_bond_info->dev_info ||
                                (!trigger_bond_info->dev_info->name &&
                                 !trigger_bond_info->dev_info->alias) ||
                                        !trigger_bond_info->dev_info->address ||
                                                trigger_bond_info->dev_info->uuid_count == 0) {
-                       BT_INFO("Complete data is not present, Assigning rem_info");
+                       BT_DBG("Complete data is not present, Assigning rem_info");
                        if (!trigger_bond_info->dev_info)
                                trigger_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
                        _bt_copy_remote_dev_info(trigger_bond_info->dev_info, rem_info);
@@ -364,13 +364,13 @@ static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_d
                BT_DBG("Bonding dev addr has matched with remote dev properties address [%s]", rem_info->address);
                __bt_handle_ongoing_bond(trigger_bond_info->dev_info, FALSE);
        } else if (incoming_bond_info && !g_strcmp0(incoming_bond_info->addr, rem_info->address)) {
-               BT_INFO("Incoming Bond is ongoing, try update properties");
+               BT_DBG("Incoming Bond is ongoing, try update properties");
                if (!incoming_bond_info->dev_info ||
                                (!incoming_bond_info->dev_info->name &&
                                 !incoming_bond_info->dev_info->alias) ||
                                        !incoming_bond_info->dev_info->address ||
                                                incoming_bond_info->dev_info->uuid_count == 0) {
-                       BT_INFO("Complete data is not present, Assigning rem_info");
+                       BT_DBG("Complete data is not present, Assigning rem_info");
                        if (!incoming_bond_info->dev_info)
                                incoming_bond_info->dev_info = g_malloc0(sizeof(bt_remote_dev_info_t));
                        _bt_copy_remote_dev_info(incoming_bond_info->dev_info, rem_info);
@@ -403,7 +403,6 @@ static void __bt_device_remote_properties_callback(event_dev_properties_t *oal_d
        }
 
        _bt_free_remote_dev(rem_info);
-       BT_DBG("-");
 }
 
 static int __get_oal_trusted_profile(bluetooth_trusted_profile_t profile)
@@ -444,7 +443,7 @@ int _bt_set_trust_profile(bluetooth_device_address_t *addr,
        result = device_set_trust_profile(&bd_addr, oal_profile, trust);
        if (result != OAL_STATUS_SUCCESS) {
                BT_ERR("device_set_trust_profile error: [%d]", result);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
        BT_DBG("-");
@@ -469,7 +468,7 @@ int _bt_get_trust_profile(bluetooth_device_address_t *addr,
        result = device_get_trust_profile(&bd_addr, oal_profile, trust);
        if (result != OAL_STATUS_SUCCESS) {
                BT_ERR("device_set_trust_profile error: [%d]", result);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
        BT_DBG("-");
@@ -605,25 +604,25 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
 
        _bt_convert_addr_type_to_string(address, auth_event->address.addr);
 
-       BT_INFO("service_d: %d", service_d);
+       BT_DBG("service_d: %d", service_d);
 
        switch (service_d) {
        case HID_SERVICE_ID:
-               BT_INFO("Incoming HID Profile conn Req from device addr [%s]", address);
+               BT_DBG("Incoming HID Profile conn Req from device addr [%s]", address);
                break;
        case A2DP_SERVICE_ID:
-               BT_INFO("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
+               BT_DBG("Incoming A2DP(Remote Sink) profile conn Req from device addr [%s]", address);
                _bt_a2dp_src_handle_incoming_authorization(address, service_d);
                return;
        case A2DP_SRC_SERVICE_ID:
-               BT_INFO("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
+               BT_DBG("Incoming A2DP(Remote Source) Profile conn Req from device addr [%s]", address);
                _bt_a2dp_sink_handle_incoming_authorization(address, service_d);
                break;
        case AVRCP_SERVICE_ID:
-               BT_INFO("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
+               BT_DBG("Incoming AVRCP (Remote) Profile conn Req from device addr [%s]", address);
                break;
        case AVRCP_CT_SERVICE_ID:
-               BT_INFO("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
+               BT_DBG("Incoming AVRCP (Controller) Profile conn Req from device addr [%s]", address);
                break;
 #ifdef TIZEN_FEATURE_BT_OBEX
        case OPP_SERVICE_ID: {
@@ -637,7 +636,7 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
 
                name = g_strdup(address);
 
-               BT_INFO("Incoming OPP conn Req from device addr [%s]", address);
+               BT_DBG("Incoming OPP conn Req from device addr [%s]", address);
                _bt_obex_server_set_pending_conn_auth_device_addr(address);
                param = g_variant_new("(iss)", BLUETOOTH_ERROR_NONE, address, name);
                _bt_send_event(BT_OPP_SERVER_EVENT,
@@ -647,28 +646,28 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
        }
 #endif
        case HSP_SERVICE_ID:
-               BT_INFO("Incoming HSP_SERVICE_ID conn Req from device addr [%s]", address);
+               BT_DBG("Incoming HSP_SERVICE_ID conn Req from device addr [%s]", address);
                break;
        case HFP_SERVICE_ID:
-               BT_INFO("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
+               BT_DBG("Incoming HFP_SERVICE_ID conn Req from device addr [%s]", address);
                break;
        case SAP_SERVICE_ID:
-               BT_INFO("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
+               BT_DBG("Incoming SAP_SERVICE_ID conn Req from device addr [%s]", address);
                break;
        case HSP_HS_SERVICE_ID:
-               BT_INFO("Incoming HSP_HS_SERVICE_ID conn Req from device addr [%s]", address);
+               BT_DBG("Incoming HSP_HS_SERVICE_ID conn Req from device addr [%s]", address);
                break;
        case HFP_HS_SERVICE_ID:
-               BT_INFO("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
+               BT_DBG("Incoming HFP_HS_SERVICE_ID conn Req from device addr [%s]", address);
                break;
 #ifdef TIZEN_BT_HAL
        case IOTIVITY_SERVICE_ID:
-               BT_INFO("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
+               BT_DBG("Incoming IOTIVITY_SERVICE_ID conn Req from device addr [%s]", address);
                break;
 #endif
        default:
                /* For now, reject authorization for any service apart from above switch cases */
-               BT_INFO("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_d, address);
+               BT_DBG("Incoming Profile conn req with service ID [%d] from device addr [%s]", service_d, address);
                res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, FALSE, FALSE);
                if (res != OAL_STATUS_SUCCESS)
                        BT_ERR("authorize_response: %d", res);
@@ -680,7 +679,6 @@ static void __bt_device_authorization_request_callback(event_dev_authorize_req_t
        res = device_reply_auth_request((bt_address_t*)&auth_event->address, service_d, TRUE, FALSE);
        if (res != OAL_STATUS_SUCCESS)
                BT_ERR("authorize_response: %d", res);
-       BT_INFO("-");
 }
 
 static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboolean incoming_bond)
@@ -729,7 +727,7 @@ static void __bt_handle_ongoing_bond(bt_remote_dev_info_t *remote_dev_info, gboo
                                BLUETOOTH_EVENT_BONDING_FINISHED,
                                param);
                BT_PERMANENT_LOG("Paired %s", remote_dev_info->address + 12);
-               BT_INFO_C("### Paired %s", remote_dev_info->address);
+               BT_INFO_C("### Paired %s", remote_dev_info->address + 12);
                if (incoming_bond) {
                        __bt_free_bond_info(BT_DEVICE_INCOMING_BOND_INFO);
                } else {
@@ -802,7 +800,6 @@ static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr)
                return;
        }
 
-       BT_INFO("Bonding successfully completed");
        /* Bonding state will be cleaned up & BONDING FINISHED EVENT
           will be sent only when Properties are fetched from stack
           Till that time lets not free trigger_bond_info.
@@ -814,7 +811,7 @@ static void __bt_device_handle_bond_completion_event(bt_address_t *bd_addr)
                        trigger_bond_info->addr);
 
        if (_bt_device_get_bonded_device_info(&dev_addr) == BLUETOOTH_ERROR_NONE) {
-               BT_DBG("BOnded device info query posted to stack successfully");
+               BT_DBG("Bonded device info query posted to stack successfully");
                __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_BOND_DEVICE,
                                trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
        } else {
@@ -840,13 +837,11 @@ static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr)
 {
        char address[BT_ADDRESS_STRING_SIZE];
 
-       BT_INFO("+");
-
        _bt_convert_addr_type_to_string(address, bd_addr->addr);
        _bt_service_remove_device_from_bonded_list(address);
 
        if (trigger_unbond_info) {
-               BT_INFO("Bond removal request successfully handled, return DBUS and send event");
+               BT_DBG("Bond removal request successfully handled, return DBUS and send event");
                GVariant *param = NULL;
                __bt_device_handle_pending_requests(BLUETOOTH_ERROR_NONE, BT_UNBOND_DEVICE,
                                trigger_unbond_info->addr, BT_ADDRESS_STRING_SIZE);
@@ -861,7 +856,6 @@ static void __bt_device_handle_bond_removal_event(bt_address_t *bd_addr)
                BT_ERR("Bonding was removed");
                __bt_device_handle_bond_state();
        }
-       BT_INFO("-");
 }
 
 static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_fail_event)
@@ -874,6 +868,7 @@ static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_f
        case OAL_STATUS_RMT_DEVICE_DOWN:
        {
                if (trigger_bond_info) {
+#if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
                        BT_INFO("OAL_STATUS_RMT_DEVICE_DOWN:Lets retry bonding!! retry count [%d]",
                                        bond_retry_count);
                        int ret = OAL_STATUS_SUCCESS;
@@ -889,13 +884,16 @@ static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_f
                                } else
                                        bond_retry_count++;
                        } else {
+#endif
                                BT_ERR("Create Bond failed MAX_BOND_RETRY_COUNT TIMES!!");
                                __bt_device_handle_pending_requests(BLUETOOTH_ERROR_INTERNAL, BT_BOND_DEVICE,
                                                trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
                                __bt_free_bond_info(BT_DEVICE_BOND_INFO);
                                __bt_free_pairing_info(&trigger_pairing_info);
+#if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
                                bond_retry_count = 0;
                        }
+#endif
                }
                break;
        }
@@ -924,6 +922,18 @@ static void __bt_device_handle_bond_failed_event(event_dev_bond_failed_t* bond_f
                __bt_free_pairing_info(&trigger_pairing_info);
                break;
        }
+       case OAL_STATUS_ALREADY_CONNECT:
+       {
+               int result = BLUETOOTH_ERROR_ALREADY_CONNECT;
+               BT_INFO("OAL_STATUS_ALREADY_CONNECT");
+
+               if (trigger_bond_info) {
+                       __bt_device_handle_pending_requests(result, BT_BOND_DEVICE,
+                               trigger_bond_info->addr, BT_ADDRESS_STRING_SIZE);
+                       __bt_free_bond_info(BT_DEVICE_BOND_INFO);
+               }
+               break;
+       }
        case OAL_STATUS_INTERNAL_ERROR:
        {
                BT_INFO("OAL_STATUS_INTERNAL_ERROR");
@@ -1062,24 +1072,22 @@ static void __bt_device_event_handler(int event_type, gpointer event_data)
                break;
        }
        case OAL_EVENT_DEVICE_ACL_CONNECTED: {
-               BT_INFO("ACL Connected event Received");
-               event_dev_conn_status_t* param = event_data;
-               __bt_device_acl_state_changed_callback(param, TRUE, 0);
+               BT_DBG("ACL Connected event Received");
+               __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 0);
                break;
        }
        case OAL_EVENT_DEVICE_ACL_DISCONNECTED: {
-               BT_INFO("ACL Disconnected event Received");
+               BT_DBG("ACL Disconnected event Received");
                __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 0);
                break;
        }
        case OAL_EVENT_DEVICE_LE_CONNECTED: {
-               BT_INFO("LE Connected event Received");
-               event_dev_conn_status_t* param = event_data;
-               __bt_device_acl_state_changed_callback(param, TRUE, 1);
+               BT_DBG("LE Connected event Received");
+               __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, TRUE, 1);
                break;
        }
        case OAL_EVENT_DEVICE_LE_DISCONNECTED: {
-               BT_INFO("LE Disconnected event Received");
+               BT_DBG("LE Disconnected event Received");
                __bt_device_acl_state_changed_callback((event_dev_conn_status_t *)event_data, FALSE, 1);
                break;
        }
@@ -1468,42 +1476,11 @@ static void __bt_device_ssp_consent_callback(remote_device_t* dev_info)
        BT_DBG("-");
 }
 
-static int __bt_oal_status_to_bt_error(int oal_status)
-{
-        int ret = 0;
-
-       switch (oal_status) {
-       case OAL_STATUS_SUCCESS:
-               ret = BLUETOOTH_ERROR_NONE;
-               break;
-       case OAL_STATUS_CONN_TIMEOUT:
-       case OAL_STATUS_LINK_LOSS:
-               BT_INFO("Connection Timeout");
-               ret = BLUETOOTH_ERROR_CONNECTION_TIMEOUT;
-               break;
-#ifdef TIZEN_BT_HAL
-       case OAL_STATUS_CONN_TERM_LOCAL_HOST:
-               ret = BLUETOOTH_ERROR_LOCAL_HOST_TERM;
-               break;
-       case OAL_STATUS_CONN_TERM_RMT_HOST:
-               ret = BLUETOOTH_ERROR_REMOTE_USER_TERM;
-               break;
-#endif
-       case OAL_STATUS_INTERNAL_ERROR:
-               ret = BLUETOOTH_ERROR_INTERNAL;
-               break;
-       default:
-               ret = BLUETOOTH_ERROR_INTERNAL;
-               break;
-       }
-       return ret;
-}
-
 static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_event,
                gboolean connected, unsigned char type)
 {
        gchar address[BT_ADDRESS_STR_LEN];
-       int result = BLUETOOTH_ERROR_NONE;
+       int disc_reason = 0;
        GVariant *param = NULL;
        bt_device_conn_info_t conn_info;
 
@@ -1511,22 +1488,21 @@ static void __bt_device_acl_state_changed_callback(event_dev_conn_status_t *acl_
 
        _bt_logging_connection(connected, type);
 
-       result = __bt_oal_status_to_bt_error(acl_event->status);
-       BT_DBG("Result [0x%x]", result);
+       disc_reason = acl_event->status;
 
        if (connected) {
-               param = g_variant_new("(isy)", result, address, type);
+               BT_PERMANENT_LOG("Connected %s %s", !type ? "EDR" : "LE", address + 12);
+               param = g_variant_new("(isy)", BLUETOOTH_ERROR_NONE, address, type);
                _bt_send_event(BT_DEVICE_EVENT,
                                BLUETOOTH_EVENT_DEVICE_CONNECTED,
                                param);
        } else {
-               param = g_variant_new("(isyi)", result, address, type, dbfw_rssi);
+               BT_PERMANENT_LOG("Disconnected %s(%d) %s", !type ? "EDR" : "LE",  disc_reason, address + 12);
+               param = g_variant_new("(isyi)", disc_reason, address, type, dbfw_rssi);
                _bt_send_event(BT_DEVICE_EVENT,
                                BLUETOOTH_EVENT_DEVICE_DISCONNECTED,
                                param);
        }
-       BT_PERMANENT_LOG("%sonnected %s %s",
-               connected ? "C" : "Disc", !type ? "EDR" : "LE", address + 12);
 
        conn_info.connected = connected;
        conn_info.type = type;
@@ -1712,7 +1688,7 @@ static void __bt_free_service_search_info(bt_service_search_info_data_t **p_info
 
 static int __bt_device_handle_bond_state(void)
 {
-       BT_INFO("Current Bond state: %d", bt_device_bond_state);
+       BT_DBG("Current Bond state: %d", bt_device_bond_state);
        int ret = OAL_STATUS_INTERNAL_ERROR;
 
        switch (bt_device_bond_state) {
@@ -1758,7 +1734,7 @@ static int __bt_device_handle_bond_state(void)
        }
 
        if (ret != OAL_STATUS_SUCCESS)
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(ret);
        else
                return BLUETOOTH_ERROR_NONE;
 }
@@ -1768,18 +1744,15 @@ int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr)
        int result;
        bt_address_t bd_addr;
 
-       BT_DBG("+");
-
        retv_if(!addr, BLUETOOTH_ERROR_INVALID_PARAM);
 
        memcpy(bd_addr.addr, addr, BLUETOOTH_ADDRESS_LENGTH);
        result = device_query_attributes(&bd_addr);
        if (result != OAL_STATUS_SUCCESS) {
                BT_ERR("device_query_attributes error: [%d]", result);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
-       BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -1788,20 +1761,18 @@ int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias)
        int ret;
        char address[BT_ADDRESS_STRING_SIZE];
 
-       BT_DBG("+");
        BT_CHECK_PARAMETER(alias, return);
 
        ret = device_set_alias((bt_address_t *)device_address, (char *)alias);
        if (ret != OAL_STATUS_SUCCESS) {
                BT_ERR("device_set_alias: %d", ret);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(ret);
        }
 
        /* Update local cache */
        _bt_convert_addr_type_to_string(address, device_address->addr);
        _bt_update_remote_dev_property(address, DEV_PROP_ALIAS, (void *)alias);
 
-       BT_DBG("-");
        return BLUETOOTH_ERROR_NONE;
 }
 
@@ -1812,7 +1783,6 @@ int _bt_bond_device(bluetooth_device_address_t *device_address,
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
        bluetooth_device_info_t dev_info;
        const char *stack_name = NULL;
-       BT_DBG("+");
 
        retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
@@ -1850,13 +1820,14 @@ int _bt_bond_device(bluetooth_device_address_t *device_address,
                bt_device_bond_state = BT_DEVICE_BOND_STATE_REMOVE_BONDING;
        }
 
+#if !defined(TIZEN_PROFILE_WEARABLE) && !defined(TIZEN_PROFILE_IOT)
        bond_retry_count = 0;
+#endif
        result = __bt_device_handle_bond_state();
 
        if (result != BLUETOOTH_ERROR_NONE)
                goto fail;
 
-       BT_DBG("-");
        return result;
 
 fail:
@@ -1868,7 +1839,6 @@ fail:
                        sizeof(bluetooth_device_info_t));
        __bt_free_bond_info(BT_DEVICE_BOND_INFO);
 
-       BT_DBG("-");
        return result;
 }
 
@@ -1878,7 +1848,6 @@ int _bt_unbond_device(bluetooth_device_address_t *device_address,
        int result = OAL_STATUS_SUCCESS;
        char address[BT_ADDRESS_STRING_SIZE] = { 0 };
        bluetooth_device_info_t dev_info;
-       BT_INFO("+");
 
        retv_if(device_address == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
 
@@ -1900,7 +1869,7 @@ int _bt_unbond_device(bluetooth_device_address_t *device_address,
        if (result != OAL_STATUS_SUCCESS)
                goto fail;
 
-       return result;
+       return BLUETOOTH_ERROR_NONE;
 
 fail:
        memset(&dev_info, 0x00, sizeof(bluetooth_device_info_t));
@@ -1911,7 +1880,7 @@ fail:
                        sizeof(bluetooth_device_info_t));
        __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
 
-       return result;
+       return _bt_convert_oal_status_to_bt_error(result);
 }
 
 int _bt_cancel_bonding(void)
@@ -1957,7 +1926,7 @@ int _bt_passkey_reply(const char *passkey, gboolean cnfm_reply)
 
        if (ret != OAL_STATUS_SUCCESS) {
                BT_ERR("_bt_device_handle_passkey_reply: err [%d]", ret);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(ret);
        }
 
        BT_INFO("-");
@@ -2048,7 +2017,7 @@ int _bt_search_device(bluetooth_device_address_t *device_address)
        if (result != OAL_STATUS_SUCCESS) {
                BT_ERR("Device Service Search Failed..: %d", result);
                __bt_free_service_search_info(&service_search_info);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
        return BLUETOOTH_ERROR_NONE;
 }
@@ -2062,7 +2031,7 @@ int _bt_cancel_search_device(void)
 
        if (ret != OAL_STATUS_SUCCESS) {
                BT_ERR("SDP Cancel request failed [%d]", ret);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(ret);
        }
 
        __bt_device_handle_pending_requests(BLUETOOTH_ERROR_CANCEL_BY_USER, BT_SEARCH_SERVICE,
@@ -2086,7 +2055,7 @@ int _bt_set_authorization(bluetooth_device_address_t *device_address,
        ret = device_set_authorized((bt_address_t*)device_address, authorize);
        if (ret != OAL_STATUS_SUCCESS) {
                BT_ERR("device_set_authorized: %d", ret);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(ret);
        }
 
        return BLUETOOTH_ERROR_NONE;
@@ -2116,6 +2085,9 @@ gboolean _bt_is_device_connected(bluetooth_device_address_t *device_address, int
        case BT_PROFILE_CONN_HSP:
                svc_id = HFP_HS_SERVICE_ID; /* Remote is HFP HF Unit */
                break;
+       case BT_PROFILE_CONN_HFG:
+               svc_id = HFP_SERVICE_ID; /* Remote is HFP AG Unit */
+               break;
 #ifdef TIZEN_GATT_CLIENT
        case BT_PROFILE_CONN_GATT:
                return _bt_is_remote_gatt_device_connected(device_address); /* Remote is GATT client or Server */
@@ -2145,7 +2117,7 @@ int _bt_rfcomm_reply_conn_authorization(char *address, gboolean reply)
        res = device_reply_auth_request(&bd_addr, 0, reply, FALSE);
        if (res != OAL_STATUS_SUCCESS) {
                BT_ERR("authorize_response: %d", res);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(res);
        }
 
        BT_DBG("-");
@@ -2167,7 +2139,7 @@ int _bt_enable_rssi(bluetooth_device_address_t *addr, int link_type,
                        low_threshold, in_range_threshold, high_threshold);
        if (result != OAL_STATUS_SUCCESS) {
                BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
        BT_DBG("-");
@@ -2187,7 +2159,7 @@ int _bt_get_rssi_strength(bluetooth_device_address_t *addr, int link_type)
        result = device_get_connected_link_rssi_strength(&bd_addr, link_type);
        if (result != OAL_STATUS_SUCCESS) {
                BT_ERR("device_get_connected_link_rssi_strength error: [%d]", result);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
        BT_DBG("-");
@@ -2204,7 +2176,7 @@ int _bt_set_passkey_notification(const char *sender, gboolean enable)
        result = device_enable_gap_auth_notifications(OAL_PASSKEY_DISPLAY, enable);
        if (OAL_STATUS_SUCCESS != result) {
                BT_ERR("device_enable_gap_auth_notifications error: [%d]", result);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
        g_free(passkey_watcher);
@@ -2318,7 +2290,7 @@ int _bt_device_get_ida(bluetooth_device_address_t *device_address, bluetooth_dev
 
        if (result != OAL_STATUS_SUCCESS) {
                BT_ERR("device_get_ida Failed %d", result);
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
        return result;
@@ -2428,8 +2400,6 @@ int _bt_add_le_conn_param_info(const char *address, const char *sender,
        bt_le_conn_param_t *param = NULL;
        bt_le_conn_param_t *data = NULL;
 
-       BT_DBG("+");
-
        if (!address || !sender)
                return BLUETOOTH_ERROR_INVALID_PARAM;
 
@@ -2480,7 +2450,7 @@ static int __bt_le_set_conn_parameter(const char *address,
        max = interval_max / BT_LE_CONN_INTERVAL_SPLIT;
        to = time_out / BT_LE_CONN_TO_SPLIT;
 
-       BT_INFO("updating: Min interval: %d, Max interval: %d, Latency: %d, Supervision timeout: %d",
+       BT_DBG("updating: Min interval: %d, Max interval: %d, Latency: %d, Supervision timeout: %d",
                        min, max, latency, to);
 
        _bt_convert_addr_string_to_type(dev_addr.addr, address);
@@ -2562,7 +2532,7 @@ int _bt_le_connection_update(const char *sender,
 
        BT_CHECK_PARAMETER(device_address, return);
 
-       BT_INFO("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
+       BT_DBG("Sender %s, Min interval: %f, Max interval: %f, Latency: %u, Supervision timeout: %u",
                        sender, interval_min, interval_max, latency, time_out);
 
        if (interval_min > interval_max ||
@@ -2602,7 +2572,7 @@ int _bt_le_connection_update(const char *sender,
 
        dev = __bt_get_le_connected_dev_info(address);
        if (dev == NULL) {
-               BT_DBG("device not found in the list");
+               BT_ERR("device not found in the list");
                ret = BLUETOOTH_ERROR_NOT_CONNECTED;
                goto fail;
        }
@@ -2629,11 +2599,10 @@ update:
        if (ret != OAL_STATUS_SUCCESS) {
                _bt_remove_le_conn_param_info(address, sender);
                BT_DBG("fail to update the LE connection parameter");
-               ret = BLUETOOTH_ERROR_INTERNAL;
+               ret = _bt_convert_oal_status_to_bt_error(ret);
                goto fail;
        }
 
-       BT_DBG("updated LE connection parameter");
        dev->interval_min = interval_min;
        dev->interval_max = interval_max;
 
@@ -2653,7 +2622,7 @@ int _bt_disconnect_device(bluetooth_device_address_t *device_address)
        result = device_disconnect((bt_address_t *)device_address);
        if (result != OAL_STATUS_SUCCESS) {
                BT_DBG("Failed to disconnect device");
-               return BLUETOOTH_ERROR_INTERNAL;
+               return _bt_convert_oal_status_to_bt_error(result);
        }
 
        BT_DBG("-");
@@ -2707,8 +2676,6 @@ static gboolean __bt_ignore_auto_pairing_request(const char *address)
                return FALSE;
        }
 
-       BT_DBG("Buffer = %s\n", buffer);
-
        lines = g_strsplit_set(buffer, BT_AGENT_NEW_LINE, 0);
        g_free(buffer);