Get local IRK value 16/311716/5
authorSameer Kumar <sameer.kumar@samsung.com>
Fri, 24 May 2024 10:32:37 +0000 (16:02 +0530)
committerSameer Kumar <sameer.kumar@samsung.com>
Tue, 28 May 2024 05:57:59 +0000 (11:27 +0530)
This patch adds support to get local IRK value.

To avoid any conflicts this patch should be merged with bluez
patch: (Change-Id: Iae9293c6d93688d8b9a6672bdaf2261c41668a9f)

Change-Id: Iac2edded057054a98aa3855fe0eb2c97e9346a62
Signed-off-by: Sameer Kumar <sameer.kumar@samsung.com>
13 files changed:
bt-api/bt-adapter.c
bt-api/bt-common.c
bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.c
bt-oal/bluez_hal/src/bt-hal-adapter-dbus-handler.h
bt-oal/bluez_hal/src/bt-hal-bluetooth.c
bt-oal/hardware/bluetooth.h
bt-oal/include/oal-adapter-mgr.h
bt-oal/oal-adapter-mgr.c
bt-service/services/adapter/bt-service-core-adapter.c
bt-service/services/bt-request-handler.c
bt-service/services/include/bt-service-core-adapter.h
include/bluetooth-api.h
include/bt-internal-types.h

index 76ab25e..9b93d07 100644 (file)
@@ -532,6 +532,22 @@ BT_EXPORT_API int bluetooth_start_discovery(unsigned short max_response,
        return result;
 }
 
+BT_EXPORT_API int bluetooth_get_local_irk(bluetooth_irk_t *local_irk)
+{
+       int result;
+       BT_INIT_PARAMS();
+       BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+
+       result = _bt_send_request(BT_BLUEZ_SERVICE, BT_GET_LOCAL_IRK,
+               in_param1, in_param2, in_param3, in_param4, &out_param);
+
+       if (result == BLUETOOTH_ERROR_NONE) {
+               *local_irk = g_array_index(out_param, bluetooth_irk_t, 0);
+       }
+       BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
+       return result;
+}
+
 BT_EXPORT_API int bluetooth_start_custom_discovery(bt_discovery_role_type_t role,
                                                unsigned short max_response,
                                                unsigned short discovery_duration,
index 62252e1..eab2120 100644 (file)
@@ -558,6 +558,7 @@ const char *_bt_convert_service_function_to_string(int function)
                {BT_GET_DISCOVERABLE_MODE, "BT_GET_DISCOVERABLE_MODE"},
                {BT_SET_DISCOVERABLE_MODE, "BT_SET_DISCOVERABLE_MODE"},
                {BT_START_DISCOVERY, "BT_START_DISCOVERY"},
+               {BT_GET_LOCAL_IRK, "BT_GET_LOCAL_IRK"},
                {BT_START_CUSTOM_DISCOVERY, "BT_START_CUSTOM_DISCOVERY"},
                {BT_CANCEL_DISCOVERY, "BT_CANCEL_DISCOVERY"},
                {BT_START_LE_DISCOVERY, "BT_START_LE_DISCOVERY"},
index 190d84f..db5af82 100644 (file)
@@ -503,6 +503,54 @@ int _bt_hal_dbus_start_discovery(gboolean is_custom,
        return BT_STATUS_SUCCESS;
 }
 
+int _bt_hal_dbus_get_local_irk(uint8_t *local_irk)
+{
+       GDBusProxy *proxy;
+       GError *error = NULL;
+       GVariant *result;
+       GVariantIter *iter;
+
+       GByteArray *gp_byte_array = NULL;
+       guint8 g_byte;
+
+       DBG("+");
+
+       proxy = _bt_hal_get_adapter_proxy();
+       if (!proxy) {
+               DBG("_bt_hal_dbus_get_local_irk: Adapter proxy get failed!!!");
+               return BT_STATUS_FAIL;
+       }
+
+       result = g_dbus_proxy_call_sync(proxy,
+                       "GetLocalIrk",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       &error);
+
+       if (!result) {
+               if (error != NULL) {
+                       ERR("GetLocalIrk failed (Error: %s)", error->message);
+                       g_clear_error(&error);
+               } else
+                       ERR("GetLocalIrk failed");
+               return BT_STATUS_FAIL;
+       }
+
+       gp_byte_array = g_byte_array_new();
+       g_variant_get(result, "(ay)", &iter);
+
+       while (g_variant_iter_loop(iter, "y", &g_byte))
+               g_byte_array_append(gp_byte_array, &g_byte, 1);
+
+       memcpy(local_irk, gp_byte_array->data, gp_byte_array->len);
+
+       g_variant_iter_free(iter);
+       g_byte_array_free(gp_byte_array, TRUE);
+       return BT_STATUS_SUCCESS;
+}
+
 int _bt_hal_dbus_stop_discovery(void)
 {
        GDBusProxy *proxy;
index f866662..051462f 100644 (file)
@@ -56,6 +56,8 @@ int _bt_hal_dbus_reset_adapter(void);
 
 int _bt_hal_dbus_start_discovery(gboolean is_custom, bt_disc_role_type_t role);
 
+int _bt_hal_dbus_get_local_irk(uint8_t *irk);
+
 int _bt_hal_dbus_stop_discovery(void);
 
 int _bt_hal_get_adapter_powered_state(uint8_t *state);
index 8741e44..81abc33 100644 (file)
@@ -222,6 +222,11 @@ static int start_discovery(void)
        return _bt_hal_dbus_start_discovery(false, 0x00);
 }
 
+static int get_local_irk(uint8_t *local_irk)
+{
+       return _bt_hal_dbus_get_local_irk(local_irk);
+}
+
 #ifdef  TIZEN_BT_HAL
 static int start_custom_discovery(bt_disc_role_type_t disc_type)
 {
@@ -484,6 +489,7 @@ static const bt_interface_t bluetooth_if = {
        .get_remote_service_record = get_remote_service_record,
        .get_remote_services = get_remote_services,
        .start_discovery = start_discovery,
+       .get_local_irk = get_local_irk,
 #ifdef TIZEN_BT_HAL
        .start_custom_discovery = start_custom_discovery,
 #endif
index 150f60e..af3fefc 100644 (file)
@@ -803,6 +803,9 @@ typedef struct {
        /** Start Discovery */
        int (*start_discovery)(void);
 
+       /** Get Local Irk */
+       int (*get_local_irk)(uint8_t *irk);
+
 #ifdef TIZEN_BT_HAL
        int (*start_custom_discovery)(bt_disc_role_type_t disc_type);
 #endif
index 1d55976..b9819fc 100644 (file)
@@ -227,6 +227,16 @@ oal_status_t adapter_recover(void);
 oal_status_t adapter_start_inquiry(unsigned short duration);
 
 /**
+* @brief Get the local Identity Resolving Key (IRK) value.
+*
+* @return OAL_STATUS_SUCCESS on success, otherwise a non-zero error value.
+* @retval #OAL_STATUS_SUCCESS Successful
+*
+* @pre Bluetooth controller must support this feature.
+*/
+oal_status_t adapter_get_local_irk(uint8_t *local_irk);
+
+/**
  * @brief Stop device discovery
  *
  * @details OAL_EVENT_ADAPTER_INQUIRY_FINISHED will be generated by OAL
index 1abb39d..b65d17f 100644 (file)
@@ -446,6 +446,20 @@ oal_status_t adapter_start_inquiry(unsigned short duration)
        return OAL_STATUS_SUCCESS;
 }
 
+oal_status_t adapter_get_local_irk(uint8_t *local_irk)
+{
+       int ret = OAL_STATUS_SUCCESS;
+       CHECK_OAL_INITIALIZED();
+
+       ret = blued_api->get_local_irk(local_irk);
+       if (ret != BT_STATUS_SUCCESS) {
+               BT_ERR("get property local irk failed, status: %s", status2string(ret));
+               return convert_to_oal_status(ret);
+       }
+
+       return OAL_STATUS_SUCCESS;
+}
+
 oal_status_t adapter_stop_inquiry(void)
 {
        int ret;
index ae91760..7ff904a 100644 (file)
@@ -315,6 +315,19 @@ int _bt_start_discovery(unsigned short max_response,
                                cod_mask, FALSE, 0x00);
 }
 
+int _bt_get_local_irk(uint8_t *local_irk)
+{
+       BT_CHECK_PARAMETER(local_irk, return);
+       int ret = OAL_STATUS_SUCCESS;
+       ret = adapter_get_local_irk(local_irk);
+       if (ret != OAL_STATUS_SUCCESS) {
+               BT_ERR("ret: %d", ret);
+               return _bt_convert_oal_status_to_bt_error(ret);
+       }
+
+       return BLUETOOTH_ERROR_NONE;
+}
+
 int _bt_start_custom_discovery(bt_discovery_role_type_t role)
 {
        return __bt_adapter_state_discovery_request(TRUE, 0, 0, 0, TRUE, role);
index 5a2f90a..fd07afa 100644 (file)
@@ -590,6 +590,19 @@ int __bt_bluez_request(int function_name,
 
                break;
        }
+       case BT_GET_LOCAL_IRK: {
+               uint8_t local_irk[BLUETOOTH_IRK_LENGTH] ;
+               result = _bt_get_local_irk(local_irk);
+
+               if (result == BLUETOOTH_ERROR_NONE) {
+                       bluetooth_irk_t loc_irk;
+                       memcpy(loc_irk.irk, local_irk, BLUETOOTH_IRK_LENGTH);
+                       g_array_append_vals(*out_param1, &loc_irk,
+                                       sizeof(bluetooth_irk_t));
+               }
+
+               break;
+       }
        case BT_START_CUSTOM_DISCOVERY: {
                bt_discovery_role_type_t role;
 
@@ -5843,6 +5856,7 @@ gboolean __bt_service_check_privilege(int function_name,
        case BT_GET_RSSI:
 
        case BT_GET_LOCAL_NAME:
+       case BT_GET_LOCAL_IRK:
        case BT_GET_LOCAL_ADDRESS:
        case BT_GET_LOCAL_VERSION:
        case BT_IS_SERVICE_USED:
index 74d75d3..fc21573 100644 (file)
@@ -59,6 +59,8 @@ int _bt_recover_adapter(void);
 int _bt_start_discovery(unsigned short max_response,
                unsigned short duration, unsigned int cod_mask);
 
+int _bt_get_local_irk(uint8_t *local_irk);
+
 int _bt_start_custom_discovery(bt_discovery_role_type_t role);
 
 int _bt_cancel_discovery(void);
index 1ecd95c..5d7eb3a 100644 (file)
@@ -49,6 +49,7 @@ extern "C" {
 #define BLUETOOTH_SCAN_RESP_DATA_LENGTH_MAX    31 /**< This specifies maximum LE Scan response data length */
 #define BLUETOOTH_MANUFACTURER_DATA_LENGTH_MAX 240 /**< This specifies maximum manufacturer data length */
 #define BLUETOOTH_APPEARANCE_LENGTH 2 /**< This specifies bluetooth device appearance characteristic length */
+#define BLUETOOTH_IRK_LENGTH  16 /**< This specifies bluetooth device IRK length */
 
 #define BLUETOOTH_MAX_SERVICES_FOR_DEVICE      40  /**< This specifies maximum number of services
                                                        a device can support */
@@ -317,6 +318,11 @@ typedef struct {
        char name[BLUETOOTH_DEVICE_NAME_LENGTH_MAX + 1];
 } bluetooth_device_name_t;
 
+
+typedef struct {
+       unsigned char irk[BLUETOOTH_IRK_LENGTH];
+} bluetooth_irk_t;
+
 /**
  * This is Bluetooth manufacturer specific data, maximum size of data is 240 bytes
  */
@@ -8168,6 +8174,23 @@ int bluetooth_is_le_extended_scan_supported(gboolean *is_supported);
 int bluetooth_le_get_maximum_advertising_data_length(gint *data_length);
 
 /**
+ * @fn int bluetooth_get_local_irk(bluetooth_irk_t *irk)
+ * @brief Gets the local Identity Resolving Key (IRK).
+ *
+ * This function is a synchronous call.
+ *
+ * @return     BLUETOOTH_ERROR_NONE - Success \n
+ *             BLUETOOTH_ERROR_NOT_SUPPORT - Not supported \n
+ *             BLUETOOTH_ERROR_INVALID_PARAM - Invalid parameter (NULL buffer) \n
+ *             BLUETOOTH_ERROR_DEVICE_NOT_ENABLED - Adapter is disabled \n
+ *             BLUETOOTH_ERROR_INTERNAL - Internal error \n
+ * @param[out] irk. This structure variable contains the local IRK of the Bluetooth device.
+ *
+ * @remark      None
+ */
+int bluetooth_get_local_irk(bluetooth_irk_t *irk);
+
+/**
  * @fn int bluetooth_l2cap_le_create_socket(int psm)
  * @brief Register l2cap_le socket with a specific PSM
  *
index a5e6c90..49d3db6 100644 (file)
@@ -185,6 +185,7 @@ typedef enum {
        BT_GET_DISCOVERABLE_MODE,
        BT_SET_DISCOVERABLE_MODE,
        BT_START_DISCOVERY,
+       BT_GET_LOCAL_IRK,
        BT_START_CUSTOM_DISCOVERY,
        BT_CANCEL_DISCOVERY,
        BT_START_LE_DISCOVERY,