From: anuj.bhumiya Date: Tue, 3 Nov 2020 10:11:15 +0000 (+0530) Subject: Add api to set advertising interval X-Git-Tag: accepted/tizen/unified/20201111.124823^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ccc93d7fe7ef69b3a18d7cd7140bb2b612df7491;p=platform%2Fcore%2Fapi%2Fbluetooth.git Add api to set advertising interval This api provides a way to set advertising intervals for a particular advertising instance. Change-Id: I9d2164d156e21694f68154b611a0fdbabe50b171 Signed-off-by: anuj.bhumiya --- diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 7a36318..16d1c17 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -1123,6 +1123,31 @@ int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, bt_a int bt_adapter_le_set_advertising_custom_tx_power_level(bt_advertiser_h advertiser, int tx_power_level); /** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * @brief Set advertising intervals to set custom advertising intervals (min & max) + * @since_tizen 6.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] advertiser The handle of advertiser + * @param[in] interval_min The minimum LE advertising interval, in 0.625ms unit + * @param[in] interval_max The maximum LE advertising interval, in 0.625ms unit + * Valid range for interval_min and interval_max is from 32(20ms) to 16,384(10.24sec) + * The interval_min shall be less than or equal to the interval_max + * + * @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_PERMISSION_DENIED Permission denied + * + * @pre The Bluetooth service must be initialized with bt_initialize(). + * + * @see bt_adapter_le_start_advertising_new() + */ +int bt_adapter_le_set_advertising_interval(bt_advertiser_h advertiser, int interval_min, int interval_max); + +/** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE * @brief Retrieves the address of the devices connected with the specific profile. diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index 8bf6212..f71fb0d 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -301,6 +301,8 @@ typedef struct { bt_adapter_le_advertising_filter_policy_e filter_policy; bt_adapter_le_advertising_type_e type; int tx_power_level; + int advertising_interval_min; + int advertising_interval_max; } bt_adapter_le_advertising_parameters_s; typedef struct { diff --git a/include/bluetooth_type.h b/include/bluetooth_type.h index b177251..2327f43 100644 --- a/include/bluetooth_type.h +++ b/include/bluetooth_type.h @@ -159,7 +159,8 @@ typedef enum { typedef enum { BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED, /**< Balanced advertising mode */ BT_ADAPTER_LE_ADVERTISING_MODE_LOW_LATENCY, /**< Low latency advertising mode */ - BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY /**< Low energy advertising mode */ + BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY, /**< Low energy advertising mode */ + BT_ADAPTER_LE_ADVERTISING_MODE_CUSTOM /**< Custom mode to set advertising parameters */ } bt_adapter_le_advertising_mode_e; /** diff --git a/include/bluetooth_type_internal.h b/include/bluetooth_type_internal.h index 1ba2757..b21591e 100644 --- a/include/bluetooth_type_internal.h +++ b/include/bluetooth_type_internal.h @@ -28,6 +28,10 @@ extern "C" /* This variable will be added into bt_service_class_t in tizen 4.0 */ #define BT_SC_MAP_SERVICE_MASK 0x00800000 /**< MAP service class */ +/* Macro for advertising interval */ +#define BT_LE_ADV_INTERVAL_MIN 32 /* equals to 20msec, minimun allowed interval */ +#define BT_LE_ADV_INTERVAL_MAX 16384 /* equals to 10.24sec, maximum allowed interval */ + /** * @file bluetooth_type_internal.h */ diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index 5ff36a5..1fd8423 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -27,6 +27,7 @@ #include "bluetooth.h" #include "bluetooth_internal.h" #include "bluetooth_private.h" +#include "bluetooth_type_internal.h" #define BT_CHECK_LE_SUPPORT() \ { \ @@ -40,6 +41,7 @@ BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_LE_5_0); \ } + static bt_scan_filter_h pxp_linkloss_alert_filter; static bt_scan_filter_h pxp_immediate_alert_filter; static bt_scan_filter_h pxp_signal_loss_filter; @@ -2553,7 +2555,8 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, bluetooth_advertising_data_t adv = { {0} }; bluetooth_scan_resp_data_t resp = { {0} }; bluetooth_advertising_params_t param; - float interval = 500; + int min_interval = 800; /* Default interval, 500msec in 0.625msec units */ + int max_interval = 800; /* Default interval, 500msec in 0.625msec units */ BT_CHECK_LE_SUPPORT(); BT_CHECK_INIT_STATUS(); @@ -2586,14 +2589,18 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser, } if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_BALANCED) - interval = 500; + min_interval = max_interval = 800; /* equals to 500msec */ else if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_LOW_LATENCY) - interval = 150; + min_interval = max_interval = 240; /* equals to 150msec */ else if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_LOW_ENERGY) - interval = 1000; + min_interval = max_interval = 1600; /* equals to 1000msec*/ + else if (__adv->adv_params.mode == BT_ADAPTER_LE_ADVERTISING_MODE_CUSTOM) { + min_interval = __adv->adv_params.advertising_interval_min; + max_interval = __adv->adv_params.advertising_interval_max; + } - param.interval_min = interval; - param.interval_max = interval; + param.interval_min = min_interval; + param.interval_max = max_interval; param.filter_policy = __adv->adv_params.filter_policy; param.type = __adv->adv_params.type; param.tx_power_level = __adv->adv_params.tx_power_level; @@ -2744,6 +2751,36 @@ int bt_adapter_le_set_advertising_custom_tx_power_level(bt_advertiser_h advertis } /* LCOV_EXCL_STOP */ +int bt_adapter_le_set_advertising_interval(bt_advertiser_h advertiser, + int interval_min, int interval_max) +{ + 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); + + if (interval_min < BT_LE_ADV_INTERVAL_MIN || + interval_max > BT_LE_ADV_INTERVAL_MAX || + interval_min > interval_max) + return BT_ERROR_INVALID_PARAMETER; + + error_code = _bt_get_error_code( + bluetooth_check_privilege_advertising_parameter()); + if (error_code != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), + error_code); + return BT_ERROR_PERMISSION_DENIED; + } + __adv->adv_params.mode = BT_ADAPTER_LE_ADVERTISING_MODE_CUSTOM; + + __adv->adv_params.advertising_interval_min = interval_min; + __adv->adv_params.advertising_interval_max = interval_max; + + return error_code; +} + /* LCOV_EXCL_START */ int bt_adapter_le_enable_privacy(bool enable_privacy) { diff --git a/tests/test/bt_unit_test.c b/tests/test/bt_unit_test.c index b926a99..4607f03 100644 --- a/tests/test/bt_unit_test.c +++ b/tests/test/bt_unit_test.c @@ -324,6 +324,8 @@ tc_table_t tc_adapter_le[] = { , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CONNECTABLE}, {"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" + , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_INTERVAL}, {"bt_adapter_le_start_advertising_new" , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW}, {"bt_adapter_le_stop_advertising" @@ -3636,6 +3638,17 @@ int test_set_params(int test_id, char *param) param_count = 1; TC_PRT("Input adv Tx power level \n ( 1 ~ -127 dBm) "); break; + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_INTERVAL: + param_count = 2; + switch (param_index) { + case 0: + TC_PRT("Input advertising_interval_min (32(20ms) ~ 16384(10240ms))"); + break; + case 1: + TC_PRT("Input advertising_interval_max (32(20ms) ~ 16384(10240ms))"); + break; + } + break; case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING: param_count = 1; TC_PRT("Input adv slot id \n (Default is 0, Maximum is 2) "); @@ -5224,6 +5237,30 @@ int test_input_callback(void *data) TC_PRT("set Tx power level [0x%04x]", ret); break; } + case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_INTERVAL: { + int interval_min = 0; + int interval_max = 0; + + 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) { + interval_min = atoi(g_test_param.params[0]); + interval_max = atoi(g_test_param.params[1]); + __bt_free_test_param(&g_test_param); + } + + ret = bt_adapter_le_set_advertising_interval(advertiser, interval_min, interval_max); + if (ret != BT_ERROR_NONE) + TC_PRT("set advertising interval : %s \n", __bt_get_error_message(ret)); + else TC_PRT("advertising interval updated : %s \n", __bt_get_error_message(ret)); + break; + } case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW: { bt_adapter_le_advertising_state_changed_cb cb; @@ -5245,7 +5282,7 @@ int test_input_callback(void *data) ret = bt_adapter_le_start_advertising_new(advertiser, cb, NULL); if (ret < BT_ERROR_NONE) - TC_PRT("failed with [0x%04x]", ret); + TC_PRT("failed with : %s \n", __bt_get_error_message(ret)); break; } case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING: { diff --git a/tests/test/bt_unit_test.h b/tests/test/bt_unit_test.h index cf1d9bf..3a60323 100644 --- a/tests/test/bt_unit_test.h +++ b/tests/test/bt_unit_test.h @@ -123,6 +123,7 @@ typedef enum { 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_CUSTOM_TX_POWER, + BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_INTERVAL, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING, BT_UNIT_TEST_FUNCTION_ADAPTER_LE_STOP_ADVERTISING,