Add the internal API for LE OOB pairing 08/124908/1
authorDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 13 Apr 2017 04:20:59 +0000 (13:20 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Thu, 13 Apr 2017 04:20:59 +0000 (13:20 +0900)
For LE OOB pairing, we need to set the remote device's LE address type
and 256 hash and 256 randomizer.

Change-Id: Ic84ef752ccd8c97c3eedfbb66947ea6e38b4f95d
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
include/bluetooth_internal.h
src/bluetooth-adapter.c
test/bt_unit_test.c
test/bt_unit_test.h

index da22eb0..a7c7027 100644 (file)
@@ -758,6 +758,38 @@ int bt_adapter_le_enable_privacy(bool enable_privacy);
 
 /**
  * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE
+ * @brief Sets the Hash and Randmoizer value, synchronously for LE OOB pairing.
+ * @since_tizen 4.0
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/bluetooth.admin
+ *
+ * @param[in] remote_address Remote device address
+ * @param[in] address_type Remote device address type
+ * @param[in] hash256 The P-256 hash value received via OOB from remote device
+ * @param[in] randomizer256 The P-256 randomizer value received via OOB from remote device
+ * @param[in] hash256_len The length of @a hash256
+ * @param[in] randomizer256_len The length of @a randomizer256
+ * @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
+ *
+ * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED.
+ * @pre The Bluetooth service must be initialized with bt_initialize().
+ * @see bt_initialize()
+ */
+int bt_adapter_le_set_remote_oob_ext_data(const char *remote_address,
+               bt_device_address_type_e address_type,
+               const unsigned char *hash256, const unsigned char *randomizer256,
+               int hash256_len, int randomizer256_len);
+
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE
  * @brief Set advertising filter policy to use white list
  * @since_tizen 2.4
  * @privlevel public
index 04079eb..606172d 100644 (file)
@@ -1111,6 +1111,7 @@ int bt_adapter_set_remote_oob_data(const char *remote_address,
        }
 
        ret = _bt_get_error_code(bluetooth_oob_add_remote_data(&addr_hex,
+                                       BLUETOOTH_BDADDR_BREDR,
                                        &oob_data)); /* LCOV_EXCL_STOP */
        if (BT_ERROR_NONE != ret) { /* LCOV_EXCL_LINE */
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret),
@@ -1215,7 +1216,51 @@ int bt_adapter_set_remote_oob_ext_data(const char *remote_address,
                oob_data.randomizer256_len = len;
        }
 
-       ret = _bt_get_error_code(bluetooth_oob_add_remote_data(&addr_hex, &oob_data));
+       ret = _bt_get_error_code(bluetooth_oob_add_remote_data(&addr_hex,
+                               BLUETOOTH_BDADDR_BREDR, &oob_data));
+       if (BT_ERROR_NONE != ret)
+               BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
+
+       return ret;
+}
+
+int bt_adapter_le_set_remote_oob_ext_data(const char *remote_address,
+               bt_device_address_type_e address_type,
+               const unsigned char *hash256, const unsigned char *randomizer256,
+               int hash256_len, int randomizer256_len)
+{
+       int ret = BT_ERROR_NONE;
+       bluetooth_device_address_t addr_hex = { {0,} };
+       bt_oob_data_t oob_data = { {0},};
+       bluetooth_bdaddr_type_e addr_type = BLUETOOTH_BDADDR_LE_PUBLIC;
+       int len;
+
+       BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON);
+       BT_CHECK_INIT_STATUS();
+       BT_CHECK_INPUT_PARAMETER(remote_address);
+
+       if (!hash256 || !randomizer256)
+               return BT_ERROR_INVALID_PARAMETER;
+
+       _bt_convert_address_to_hex(&addr_hex, remote_address);
+
+       if (hash256 && randomizer256) {
+               len = hash256_len < BLUETOOTH_OOB_DATA_LENGTH ?
+                       hash256_len : BLUETOOTH_OOB_DATA_LENGTH;
+               memcpy(oob_data.hash256, hash256, len);
+               oob_data.hash256_len = len;
+
+               len = randomizer256_len < BLUETOOTH_OOB_DATA_LENGTH ?
+                       randomizer256_len : BLUETOOTH_OOB_DATA_LENGTH;
+               memcpy(oob_data.randomizer256, randomizer256, len);
+               oob_data.randomizer256_len = len;
+       }
+
+       addr_type = (address_type == BT_DEVICE_PUBLIC_ADDRESS) ?
+                                       BLUETOOTH_BDADDR_LE_PUBLIC : BLUETOOTH_BDADDR_LE_RANDOM;
+
+       ret = _bt_get_error_code(bluetooth_oob_add_remote_data(&addr_hex,
+                               addr_type, &oob_data));
        if (BT_ERROR_NONE != ret)
                BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret);
 
index 60e6cf4..0e11664 100644 (file)
@@ -319,6 +319,8 @@ tc_table_t tc_adapter_le[] = {
                , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_CLEAR_WHITE_LIST},
        {"bt_adapter_le_enable_privacy"
                , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE_PRIVACY},
+       {"bt_adapter_le_set_remote_oob_ext_data"
+                       , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_REMOTE_OOB_EXT_DATA},
        {"Register scan filter (Device Address)"
                , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_ADDRESS},
        {"Register scan filter (Service UUID)"
@@ -3467,6 +3469,37 @@ int test_set_params(int test_id, char *param)
                        break;
                }
 
+               case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_REMOTE_OOB_EXT_DATA: {
+                       if (param_index == 0) {
+                               g_test_param.param_count = 3;
+                               g_test_param.params = g_malloc0(sizeof(char*) * g_test_param.param_count);
+                               param_type = BT_UNIT_TEST_PARAM_TYPE_STRING;
+                       }
+
+                       if (param_index > 0) {
+                               int len = strlen(param);
+                               g_test_param.params[param_index - 1] = g_malloc0(len);
+                               param[len - 1] = '\0';
+                               strncpy(g_test_param.params[param_index - 1], param, len);
+                       }
+
+                       if (param_index == g_test_param.param_count) {
+                               need_to_set_params = false;
+#ifdef ARCH64
+                               test_input_callback((void *)(uintptr_t)test_id);
+#else
+                               test_input_callback((void *)test_id);
+#endif
+                               param_index = 0;
+                               return 0;
+                       }
+
+                       TC_PRT("Input param(%d) type:%s", param_index + 1, param_type);
+                       param_index++;
+
+                       break;
+
+               }
                default:
                        TC_PRT("There is no param to set\n");
                        need_to_set_params = false;
@@ -5665,6 +5698,54 @@ int test_input_callback(void *data)
                        break;
                }
 
+               case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_REMOTE_OOB_EXT_DATA: {
+                       char remote_addr[18];
+                       unsigned char *data[2];
+                       int len[2];
+                       int i;
+                       char tmp[3];
+                       long val;
+                       bt_device_address_type_e addr_type = BT_DEVICE_PUBLIC_ADDRESS;
+
+                       if (g_test_param.param_count != 3) {
+                               TC_PRT("Input parameter first!");
+                               break;
+                       }
+
+                       g_strlcpy(remote_addr, g_test_param.params[0],
+                                       sizeof(remote_addr));
+
+                       for (i = 0; i < 2; i++) {
+                               len[i] = strlen(g_test_param.params[i + 1]) / 2;
+                               data[i] = g_malloc0(len[i]);
+                       }
+
+                       for (i = 0; i < 2; i++) {
+                               int j;
+
+                               printf("Data[%d] : ", i);
+                               for (j = 0; j < len[i]; j++) {
+                                       g_strlcpy(tmp, g_test_param.params[i + 1] + 2 * j, sizeof(tmp));
+                                       val = strtol(tmp, NULL, 16);
+                                       data[i][j] = val;
+                                       printf("%02x", data[i][j]);
+                               }
+                               printf("\n");
+                       }
+
+                       ret = bt_adapter_le_set_remote_oob_ext_data(remote_addr,
+                                       addr_type,
+                                       data[0], data[1], len[0], len[1]);
+
+                       __bt_free_test_param(&g_test_param);
+
+                       for (i = 0; i < 2; i++)
+                               g_free(data[i]);
+
+                       TC_PRT("returns %s\n", __bt_get_error_message(ret));
+                       break;
+               }
+
                case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_ADDRESS: {
                        bt_scan_filter_h scan_filter;
 
index d2295dc..35a06a5 100644 (file)
@@ -118,6 +118,7 @@ typedef enum {
        BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REMOVE_WHITE_LIST,
        BT_UNIT_TEST_FUNCTION_ADAPTER_LE_CLEAR_WHITE_LIST,
        BT_UNIT_TEST_FUNCTION_ADAPTER_LE_ENABLE_PRIVACY,
+       BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_REMOTE_OOB_EXT_DATA,
        BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_DEVICE_ADDRESS,
        BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_UUID,
        BT_UNIT_TEST_FUNCTION_ADAPTER_LE_REGISTER_SCAN_FILTER_SERVICE_SOLICITATION_UUID,