From: Sameer Kumar Date: Fri, 24 May 2024 10:15:45 +0000 (+0530) Subject: Get local IRK value X-Git-Tag: accepted/tizen/8.0/unified/20241218.155803^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_8.0;p=platform%2Fcore%2Fapi%2Fbluetooth.git Get local IRK value This patch adds support to get local IRK value. To avoid any conflicts this patch should be merged with framework patch: (Change-Id: Iac2edded057054a98aa3855fe0eb2c97e9346a62) Change-Id: Ia5c1841d135a13af76fbd43036d75dfdd16f3253 Signed-off-by: Sameer Kumar --- diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index c04e89e..c67aa29 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -1226,6 +1226,27 @@ int bt_adapter_le_set_advertising_transport_discovery_data(bt_advertiser_h adver int bt_adapter_foreach_profile_connected_devices(const char *profile_uuid, bt_adapter_profile_connected_devices_cb callback, void *user_data); +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Gets the irk of local Bluetooth adapter. + * @since_tizen 7.0 + * + * @remarks The local_irk must be released with free() by you. + * @param[out] local_irk The irk of local Bluetooth adapter + * + * @return 0 on success, otherwise a negative error value. + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * @retval #BT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #BT_ERROR_NOT_INITIALIZED Not initialized + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_OUT_OF_MEMORY Out of memory + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_get_local_irk(unsigned char **local_irk); + /** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index 4ed21aa..4bb03a6 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -1077,6 +1077,32 @@ int bt_adapter_start_device_discovery(void) return error_code; } +int bt_adapter_get_local_irk(unsigned char **local_irk) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); + BT_CHECK_INPUT_PARAMETER(local_irk); + BT_CHECK_INIT_STATUS(); + bluetooth_irk_t loc_irk = { {0} }; + error_code = _bt_get_error_code(bluetooth_get_local_irk(&loc_irk)); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + return error_code; + } + + *local_irk = (unsigned char *)malloc(sizeof(loc_irk.irk)); + if (*local_irk == NULL) { + BT_ERR("Memory allocation failed"); + return BT_ERROR_OUT_OF_MEMORY; + } + + memcpy(*local_irk, loc_irk.irk, sizeof(loc_irk.irk)); + + return BT_ERROR_NONE; +} + int bt_adapter_stop_device_discovery(void) { int error_code = BT_ERROR_NONE; diff --git a/tests/test/bt_unit_test.c b/tests/test/bt_unit_test.c index 825a43a..acd8be7 100644 --- a/tests/test/bt_unit_test.c +++ b/tests/test/bt_unit_test.c @@ -218,6 +218,8 @@ tc_table_t tc_adapter[] = { , BT_UNIT_TEST_FUNCTION_ADAPTER_STOP_DEVICE_DISCOVERY}, {"bt_adapter_is_discovering" , BT_UNIT_TEST_FUNCTION_ADAPTER_IS_DISCOVERING}, + {"bt_adapter_get_local_irk" + , BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_IRK}, {"bt_adapter_foreach_bonded_device" , BT_UNIT_TEST_FUNCTION_ADAPTER_FOREACH_BONDED_DEVICE}, {"bt_adapter_foreach_profile_connected_devices" @@ -4628,6 +4630,21 @@ int test_input_callback(void *data) break; } + case BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_IRK: { + unsigned char* irk = NULL; + ret = bt_adapter_get_local_irk(&irk); + if (ret < BT_ERROR_NONE) + { + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + } + else + { + TC_PRT("Local IRK: "); + for (int i = 0; i < 16; i++) + TC_PRT("%02x", irk[i]); + } + break; + } case BT_UNIT_TEST_FUNCTION_ADAPTER_FOREACH_BONDED_DEVICE: { ret = bt_adapter_foreach_bonded_device( __bt_adapter_bonded_device_cb, NULL); diff --git a/tests/test/bt_unit_test.h b/tests/test/bt_unit_test.h index d36a168..c428123 100644 --- a/tests/test/bt_unit_test.h +++ b/tests/test/bt_unit_test.h @@ -71,6 +71,7 @@ typedef enum { BT_UNIT_TEST_FUNCTION_ADAPTER_START_DEVICE_DISCOVERY, BT_UNIT_TEST_FUNCTION_ADAPTER_STOP_DEVICE_DISCOVERY, BT_UNIT_TEST_FUNCTION_ADAPTER_IS_DISCOVERING, + BT_UNIT_TEST_FUNCTION_ADAPTER_GET_LOCAL_IRK, BT_UNIT_TEST_FUNCTION_ADAPTER_FOREACH_BONDED_DEVICE, BT_UNIT_TEST_FUNCTION_ADAPTER_FOREACH_PROFILE_CONNECTED_DEVICES, BT_UNIT_TEST_FUNCTION_ADAPTER_GET_BONDED_DEVICE_INFO,