From 4cdbf05be364972a13d50e5e87d3fb581b3469dd Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Thu, 10 Jan 2019 16:19:41 +0900 Subject: [PATCH] Add new internal API to disconnect device - int bt_device_disconnect(const char *remote_address) Change-Id: Ic5cfbff9428beb6320887e94e967076d760bf2c0 Signed-off-by: Deokhyun Kim --- include/bluetooth_internal.h | 23 +++++++++++++++++++++++ src/bluetooth-device.c | 17 +++++++++++++++++ test/bt_unit_test.c | 8 ++++++++ test/bt_unit_test.h | 1 + 4 files changed, 49 insertions(+) diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 42cc10c..e9a3286 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -815,6 +815,29 @@ int bt_adapter_foreach_profile_connected_devices(const char *profile_uuid, /** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Disconnects a remote Bluetooth device. + * @since_tizen 4.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address The address of the remote Bluetooth device + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_device_set_connection_state_changed_cb() + */ +int bt_device_disconnect(const char *remote_address); + +/** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE * @brief Gets a connection state * @since_tizen @if WEARABLE @else 2.4 @endif * diff --git a/src/bluetooth-device.c b/src/bluetooth-device.c index 9c33d09..18f5392 100644 --- a/src/bluetooth-device.c +++ b/src/bluetooth-device.c @@ -69,6 +69,23 @@ static bt_uuid2svc_table_t uuid2svc_mask[] = { }; +int bt_device_disconnect(const char *remote_address) +{ + bluetooth_device_address_t addr_hex = { {0,} }; + int error_code = BT_ERROR_NONE; + + BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + + _bt_convert_address_to_hex(&addr_hex, remote_address); /* LCOV_EXCL_START */ + error_code = _bt_get_error_code(bluetooth_disconnect_device(&addr_hex)); + if (error_code != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); + + return error_code; +} + int bt_device_create_bond(const char *device_address) { bluetooth_device_address_t addr_hex = { {0,} }; diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 7041e89..5653af8 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -370,6 +370,8 @@ tc_table_t tc_device[] = { , BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_CREATED_CB}, {"bt_device_set_bond_destroyed_cb" , BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_DESTROYED_CB}, + {"bt_device_disconnect" + , BT_UNIT_TEST_FUNCTION_DEVICE_DISCONNECT}, {"bt_device_create_bond" , BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND}, {"bt_device_create_bond_by_type" @@ -5139,6 +5141,12 @@ int test_input_callback(void *data) break; } + case BT_UNIT_TEST_FUNCTION_DEVICE_DISCONNECT: { + ret = bt_device_disconnect(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } + case BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND: { ret = bt_device_create_bond(remote_addr); TC_PRT("returns %s\n", __bt_get_error_message(ret)); diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h index 753b7bd..b096d50 100644 --- a/test/bt_unit_test.h +++ b/test/bt_unit_test.h @@ -148,6 +148,7 @@ typedef enum { BT_UNIT_TEST_FUNCTION_DEVICE_IS_PROFILE_CONNECTED, BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_CREATED_CB, BT_UNIT_TEST_FUNCTION_DEVICE_SET_BOND_DESTROYED_CB, + BT_UNIT_TEST_FUNCTION_DEVICE_DISCONNECT, BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND, BT_UNIT_TEST_FUNCTION_DEVICE_CREATE_BOND_BY_TYPE, BT_UNIT_TEST_FUNCTION_DEVICE_DESTROY_BOND, -- 2.7.4