From 16507791e1620a28bbdd77b41ce3c237a5b47dfe Mon Sep 17 00:00:00 2001 From: Dohyun Pyun Date: Mon, 20 Jun 2022 10:24:25 +0900 Subject: [PATCH] Add the implementation for ADV type for NON connectable IND (0x03) Change-Id: I16a03c9ecb4d1729c30acf47750d285df8f4a537 Signed-off-by: Dohyun Pyun --- include/bluetooth_internal.h | 29 +++++++++++++++++++++++++++++ src/bluetooth-adapter.c | 25 +++++++++++++++++++++++++ tests/test/bt_unit_test.c | 27 +++++++++++++++++++++++++++ tests/test/bt_unit_test.h | 1 + 4 files changed, 82 insertions(+) diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 3532889..c464265 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -1147,6 +1147,35 @@ int bt_adapter_le_set_advertising_custom_tx_power_level(bt_advertiser_h advertis */ int bt_adapter_le_set_advertising_interval(bt_advertiser_h advertiser, int interval_min, int interval_max); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising type directly + * @since_tizen 6.5 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] advertiser The handle of advertiser + * @param[in] type the value is defined in the specification such as + * (0 : ADV_IND, 1 : ADV_DIRECT_IND, 2 : ADV_SCAN_IND, + * 3: ADV_NONCOND_IND, 4: ADV_DIRECT_IND) + * + * @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_NOW_IN_PROGRESS Operation is now in progress + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_type(bt_advertiser_h advertiser, int type); + + /** * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE * @brief Set advertising transport discovery data(TDS) diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index c0cee95..964db07 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -2753,6 +2753,31 @@ int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, } /* LCOV_EXCL_STOP */ +int bt_adapter_le_set_advertising_type(bt_advertiser_h advertiser, + int type) +{ + int error_code = BT_ERROR_NONE; + bt_advertiser_s *__adv = (bt_advertiser_s *)advertiser; + + BT_CHECK_LE_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(advertiser); + + error_code = _bt_get_error_code( + bluetooth_check_privilege_advertising_type()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); /* LCOV_EXCL_LINE */ + return BT_ERROR_PERMISSION_DENIED; /* LCOV_EXCL_LINE */ + } + + BT_INFO("Set advertising type : %d", type); + + __adv->adv_params.type = type; + + return error_code; +} + int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser, bool connectable) { diff --git a/tests/test/bt_unit_test.c b/tests/test/bt_unit_test.c index 2516fb4..607333b 100644 --- a/tests/test/bt_unit_test.c +++ b/tests/test/bt_unit_test.c @@ -322,6 +322,8 @@ tc_table_t tc_adapter_le[] = { , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_FILTER_POLICY}, {"bt_adapter_le_set_advertising_connectable" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE}, + {"bt_adapter_le_set_advertising_type (Non-connectable)" + , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_TYPE}, {"bt_adapter_le_set_advertising_custom_tx_power_level" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CUSTOM_TX_POWER}, {"bt_adapter_le_set_advertising_interval" @@ -3635,6 +3637,10 @@ int test_set_params(int test_id, char *param) param_count = 1; TC_PRT("Input adv type \n (0 : Non-connectable (ADV_SCAN_IND), 1 : Connectable (ADV_IND) "); break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_TYPE: + param_count = 1; + TC_PRT("Input adv type \n (0 : ADV_IND, 1 : ADV_DIRECT_IND, 2 : ADV_SCAN_IND, 3: ADV_NONCOND_IND, 4: ADV_DIRECT_IND"); + break; case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CUSTOM_TX_POWER: param_count = 1; TC_PRT("Input adv Tx power level \n ( 1 ~ -127 dBm) "); @@ -5229,6 +5235,27 @@ int test_input_callback(void *data) TC_PRT("add scan response data [0x%04x]", ret); break; } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_TYPE: { + int type = BT_ADAPTER_LE_ADVERTISING_NON_CONNECTABLE; + + advertiser = advertiser_list[advertiser_index]; + + if (advertiser == NULL) { + ret = bt_adapter_le_create_advertiser(&advertiser); + TC_PRT("created le advertiser(%d)", ret); + advertiser_list[advertiser_index] = advertiser; + } + + if (g_test_param.param_count > 0) { + type = atoi(g_test_param.params[0]); + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_set_advertising_type(advertiser, type); + if (ret != BT_ERROR_NONE) + TC_PRT("add scan response data [0x%04x]", ret); + break; + } case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CUSTOM_TX_POWER: { int tx_power_level = 0; diff --git a/tests/test/bt_unit_test.h b/tests/test/bt_unit_test.h index 3a60323..1d01af0 100644 --- a/tests/test/bt_unit_test.h +++ b/tests/test/bt_unit_test.h @@ -122,6 +122,7 @@ typedef enum { BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_MODE, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_FILTER_POLICY, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_TYPE, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CUSTOM_TX_POWER, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_INTERVAL, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW, -- 2.34.1