Simplify the logic to manage invocation list
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / device / bt-service-core-device.c
index 25ce6c4..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;
@@ -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);
                        }
@@ -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);
                        }
@@ -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);
                        }
@@ -442,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("-");
@@ -467,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("-");
@@ -867,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;
@@ -882,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;
        }
@@ -1729,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;
 }
@@ -1745,7 +1750,7 @@ int _bt_device_get_bonded_device_info(bluetooth_device_address_t *addr)
        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);
        }
 
        return BLUETOOTH_ERROR_NONE;
@@ -1761,7 +1766,7 @@ int _bt_set_alias(bluetooth_device_address_t *device_address, const char *alias)
        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 */
@@ -1815,7 +1820,9 @@ 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)
@@ -1873,10 +1880,7 @@ fail:
                        sizeof(bluetooth_device_info_t));
        __bt_free_bond_info(BT_DEVICE_UNBOND_INFO);
 
-       if (result == OAL_STATUS_NOT_PAIRED)
-               return BLUETOOTH_ERROR_NOT_PAIRED;
-
-       return BLUETOOTH_ERROR_INTERNAL;
+       return _bt_convert_oal_status_to_bt_error(result);
 }
 
 int _bt_cancel_bonding(void)
@@ -1922,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("-");
@@ -2013,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;
 }
@@ -2027,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,
@@ -2051,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;
@@ -2081,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 */
@@ -2110,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("-");
@@ -2132,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("-");
@@ -2152,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("-");
@@ -2169,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);
@@ -2283,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;
@@ -2592,7 +2599,7 @@ 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;
        }
 
@@ -2615,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("-");