Get local IRK value 17/311717/5
authorSameer Kumar <sameer.kumar@samsung.com>
Fri, 24 May 2024 10:15:45 +0000 (15:45 +0530)
committerSameer Kumar <sameer.kumar@samsung.com>
Tue, 28 May 2024 05:55:48 +0000 (11:25 +0530)
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 <sameer.kumar@samsung.com>
include/bluetooth_internal.h
src/bluetooth-adapter.c
tests/test/bt_unit_test.c
tests/test/bt_unit_test.h

index 42c720acc86c3629c4f1b8a1355ceb81fad625b9..6d2a9b5be279dd49bdf26ae078ad965029874d53 100644 (file)
@@ -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 9.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
index dc73ab3fe9b42cc9df29f7c29d4817330dfe726d..671d7ce8dbf1cfcfbbf049f4f06472fc9d54e9f0 100644 (file)
@@ -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;
index 2b178e8af05eaf656620a5d9648fb92879187485..42313251c98e87b5b7a42fa87b4b6f462c6cf55e 100644 (file)
@@ -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"
@@ -4633,6 +4635,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);
index d5a1dbaad5603b430315b190aed43e774dccd37c..6574c4e5fb041644d756f0a0d69836521482676f 100644 (file)
@@ -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,