Implement interface to set advertise Tx power level 80/211080/3 accepted/tizen/unified/20190801.025403 submit/tizen/20190730.223540
authorinjun.yang <injun.yang@samsung.com>
Tue, 23 Oct 2018 00:57:06 +0000 (09:57 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 30 Jul 2019 02:23:05 +0000 (11:23 +0900)
[Model] All
[BinType] AP
[Customer] OPEN

[Issue#] N/A
[Request] Internal
[Occurrence Version] N/A

[Problem] n/a
[Cause & Measure] Support API to set advertise Tx power level
[Checking Method] n/a

[Team] Basic Connection
[Developer] Injun Yang
[Solution company] Samsung
[Change Type] Specification change

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

index 7dc3a10..697addb 100644 (file)
@@ -824,6 +824,34 @@ int bt_adapter_le_set_remote_oob_ext_data(const char *remote_address,
  */
 int bt_adapter_le_set_advertising_filter_policy(bt_advertiser_h advertiser, bt_adapter_le_advertising_filter_policy_e filter_policy);
 
+
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE
+ * @brief Set advertise Tx power level to control the transmission power level for the advertising
+ * @since_tizen 5.5
+ * @privlevel platform
+ * @privilege %http://tizen.org/privilege/bluetooth.admin
+ *
+ * @param[in] advertiser The handle of advertiser
+ * @param[in] tx_power_level Transmission power level of advertising. The valid range is [-127 ~ 1]
+ *                     Recommended values are bt_adapter_le_advertising_tx_power_level_e
+ *
+ * @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()
+ * @see bt_adapter_le_advertising_tx_power_level_e
+ */
+int bt_adapter_le_set_advertising_custom_tx_power_level(bt_advertiser_h advertiser, int tx_power_level);
+
 /**
  * @internal
  * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE
index ae9d0da..a856bb1 100644 (file)
@@ -274,6 +274,7 @@ typedef struct {
        bt_adapter_le_advertising_mode_e mode;
        bt_adapter_le_advertising_filter_policy_e filter_policy;
        bt_adapter_le_advertising_type_e type;
+       int tx_power_level;
 } bt_adapter_le_advertising_parameters_s;
 
 typedef struct {
index e52cd6b..f2fe5dc 100644 (file)
@@ -1236,6 +1236,18 @@ typedef void (*bt_hrp_collector_connection_state_changed_cb)
                (int result, const char *remote_address, bt_hrp_collector_h collector,
                  bool connected, void *user_data);
 
+/**
+ * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE
+ * @brief  Enumerations of the Bluetooth advertising Tx power level.
+ * @since_tizen 5.5
+ */
+typedef enum {
+       BT_ADAPTER_LE_ADVERTISING_TX_POWER_HIGH = 1,  /**< High transmission power level */
+       BT_ADAPTER_LE_ADVERTISING_TX_POWER_MEDIUM = -7,  /**< Medium transmission power level */
+       BT_ADAPTER_LE_ADVERTISING_TX_POWER_LOW = -15,  /**< Low transmission power level */
+       BT_ADAPTER_LE_ADVERTISING_TX_POWER_ULTRA_LOW = -23  /**< Lowst transmission power level */
+} bt_adapter_le_advertising_tx_power_level_e;
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index 9a959c8..8d12f69 100644 (file)
@@ -2371,6 +2371,7 @@ int bt_adapter_le_start_advertising_new(bt_advertiser_h advertiser,
        param.interval_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;
        error_code = bluetooth_set_custom_advertising(__adv->handle,
                                        TRUE, &param);
 
@@ -2494,6 +2495,31 @@ int bt_adapter_le_set_advertising_connectable(bt_advertiser_h advertiser,
 }
 
 /* LCOV_EXCL_START */
+int bt_adapter_le_set_advertising_custom_tx_power_level(bt_advertiser_h advertiser,
+                                                       int tx_power_level)
+{
+       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_parameter());
+       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 */
+       }
+
+       __adv->adv_params.tx_power_level = tx_power_level;
+
+       return error_code;
+}
+/* LCOV_EXCL_STOP */
+
+/* LCOV_EXCL_START */
 int bt_adapter_le_enable_privacy(bool enable_privacy)
 {
        int error_code = BT_ERROR_NONE;
index 852773c..2dd71ef 100644 (file)
@@ -311,6 +311,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_custom_tx_power_level"
+               , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_ADVERTISING_CUSTOM_TX_POWER},
        {"bt_adapter_le_start_advertising_new"
                , BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW},
        {"bt_adapter_le_stop_advertising"
@@ -3436,6 +3438,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_CUSTOM_TX_POWER:
+                       param_count = 1;
+                       TC_PRT("Input adv Tx power level \n ( 1 ~ -127 dBm) ");
+                       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) ");
@@ -4799,6 +4805,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_CUSTOM_TX_POWER: {
+                       int tx_power_level = 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) {
+                               tx_power_level = atoi(g_test_param.params[0]);
+                               __bt_free_test_param(&g_test_param);
+                       }
+
+                       ret = bt_adapter_le_set_advertising_custom_tx_power_level(advertiser, tx_power_level);
+                       if (ret != BT_ERROR_NONE)
+                               TC_PRT("set Tx power level [0x%04x]", ret);
+                       break;
+               }
                case BT_UNIT_TEST_FUNCTION_ADAPTER_LE_START_ADVERTISING_NEW: {
                        bt_adapter_le_advertising_state_changed_cb cb;
 
index 58ebf9a..1d1dbef 100644 (file)
@@ -117,6 +117,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_CUSTOM_TX_POWER,
        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,