From 1755422952601943c4ef700ff24203159563afd3 Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Fri, 10 Jan 2020 18:12:15 +0900 Subject: [PATCH] Add new APIs for GATT data batching Change-Id: I219ec233d5c99c0992412c058d8a1e51a5e45970 --- include/bluetooth_internal.h | 75 ++++++++++++++++++++++++++++++++++++++++++++ src/bluetooth-gatt.c | 67 +++++++++++++++++++++++++++++++++++++-- test/bt_unit_test.c | 45 ++++++++++++++++++++++++++ test/bt_unit_test.h | 3 ++ 4 files changed, 188 insertions(+), 2 deletions(-) diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index 2a7539d..5eff9aa 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -4218,6 +4218,81 @@ int bt_hrp_collector_set_connection_state_changed_cb(bt_hrp_collector_h collecto int bt_hrp_collector_unset_connection_state_changed_cb(bt_hrp_collector_h collector); /** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Gets number of available packets to be used as a threshold for GATT data batching. + * @since_tizen 5.5.0.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[out] available_packets The number of available packets to be used as a threshold. + * + * @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 + * + * @see bt_gatt_enable_data_batching() + */ +int bt_gatt_get_data_batching_available_packets(int *available_packets); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Enables GATT data batching. + * @since_tizen 5.5.0.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * @remarks GATT data batching is disabled even if the gatt is disconnected or bt adapter is disabled. + * + * @param[in] remote_address The address of the remote Bluetooth device for which RSSI is to be monitored. + * @param[in] packet_threshold The threshold of packet count for receiving data. + * @param[in] timeout The timeout to flush buffer. + * + * @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_QUOTA_EXCEEDED Quota exceeded + * @retval #BT_ERROR_NOT_ENABLED Not enabled + * @retval #BT_ERROR_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_ALREADY_DONE Already enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_get_data_batching_available_packets() + * @see bt_gatt_disable_data_batching() + */ +int bt_gatt_enable_data_batching(const char *remote_address, int packet_threshold, int timeout); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_GATT_MODULE + * @brief Disables GATT data batching. + * @since_tizen 5.5.0.0 + * @privlevel platform + * @privilege %http://tizen.org/privilege/bluetooth.admin + * + * @param[in] remote_address The address of the remote Bluetooth device for which RSSI is to be monitored. + * + * @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_REMOTE_DEVICE_NOT_CONNECTED Remote device is not connected + * @retval #BT_ERROR_NOT_IN_PROGRESS Not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_PERMISSION_DENIED Permission denied + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @see bt_gatt_enable_data_batching() + */ +int bt_gatt_disable_data_batching(const char *remote_address); + +/** * @} */ diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index 7099add..929be5c 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -20,9 +20,8 @@ #include #include "bluetooth.h" -#include "bluetooth_private.h" #include "bluetooth_internal.h" -#include "bluetooth_type_internal.h" +#include "bluetooth_private.h" #ifdef TIZEN_FEATURE_GATT_RELAY #include "bluetooth-gatt-server-api.h" @@ -901,6 +900,70 @@ int bt_gatt_unset_connection_state_changed_cb(void) } /* LCOV_EXCL_START */ +int bt_gatt_get_data_batching_available_packets(int *available_packets) +{ + int ret; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(available_packets); + + ret = _bt_get_error_code( + bluetooth_get_gatt_data_batching_available_packets(available_packets)); + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + + return ret; +} + +int bt_gatt_enable_data_batching(const char *remote_address, int packet_threshold, int timeout) +{ + int ret; + bluetooth_device_address_t bd_addr = { {0,} }; + + if (packet_threshold <= 0 || packet_threshold > 0x7FFF) { + BT_ERR("Invalid buffer_threshold(%d)", packet_threshold); + return BT_ERROR_INVALID_PARAMETER; + } + if (timeout <= 0 || timeout > 0x7FFF) { + BT_ERR("Invalid timeout(%d)", timeout); + return BT_ERROR_INVALID_PARAMETER; + } + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + _bt_convert_address_to_hex(&bd_addr, remote_address); + + ret = _bt_get_error_code(bluetooth_enable_gatt_data_batching(&bd_addr, + packet_threshold, timeout)); + + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + + return ret; +} + +int bt_gatt_disable_data_batching(const char *remote_address) +{ + int ret; + bluetooth_device_address_t bd_addr = { {0,} }; + + BT_CHECK_GATT_SUPPORT(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(remote_address); + _bt_convert_address_to_hex(&bd_addr, remote_address); + + ret = _bt_get_error_code(bluetooth_disable_gatt_data_batching(&bd_addr)); + + if (ret != BT_ERROR_NONE) + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + + return ret; +} +/* LCOV_EXCL_STOP */ + +/* LCOV_EXCL_START */ static void __bt_gatt_free_descriptor(bt_gatt_h gatt_handle) { bt_gatt_descriptor_s *desc = (bt_gatt_descriptor_s *)gatt_handle; diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 8d8a1b7..88f0826 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -703,6 +703,12 @@ tc_table_t tc_gatt[] = { , BT_UNIT_TEST_FUNCTION_ANCS_NEGATIVE_ACTION}, {"ANCS (Get Noti. Attr.)" , BT_UNIT_TEST_FUNCTION_ANCS_GET_NOTI_ATTR}, + {"bt_gatt_get_available_data_batching_packets" + , BT_UNIT_TEST_FUNCTION_GATT_GET_DATA_BATCHING_AVAILABLE_PACKETS}, + {"bt_gatt_enable_data_batching" + , BT_UNIT_TEST_FUNCTION_GATT_ENABLE_DATA_BATCHING}, + {"bt_gatt_disable_data_batching" + , BT_UNIT_TEST_FUNCTION_GATT_DISABLE_DATA_BATCHING}, {"Select this menu to set parameters and then select the function again." , BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS}, {NULL , 0x0000}, @@ -3459,6 +3465,7 @@ void __bt_gatt_client_write_request_completed_cb(int result, { TC_PRT("[HR]Result : %d", result); } + void _bt_hrp_collector_bsl_read_completed_cb(int result, bt_hrp_collector_h request_handle, bt_body_sensor_location_e location, void *user_data) { @@ -3864,6 +3871,18 @@ int test_set_params(int test_id, char *param) param_type = BT_UNIT_TEST_PARAM_TYPE_STRING; TC_PRT("Input param(%d) type:%s", param_index + 1, param_type); break; + case BT_UNIT_TEST_FUNCTION_GATT_ENABLE_DATA_BATCHING: { + param_count = 2; + switch (param_index) { + case 0: + TC_PRT("Input buffer_threshold (1 ~ 32767)"); + break; + case 1: + TC_PRT("Input timeout (1 ~ 32767)"); + break; + } + break; + } default: TC_PRT("There is no param to set\n"); need_to_set_params = false; @@ -7520,6 +7539,32 @@ int test_input_callback(void *data) break; } + case BT_UNIT_TEST_FUNCTION_GATT_GET_DATA_BATCHING_AVAILABLE_PACKETS: { + int available = 0; + ret = bt_gatt_get_data_batching_available_packets(&available); + TC_PRT("returns %s, (available:%d)\n", __bt_get_error_message(ret), available); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_ENABLE_DATA_BATCHING: { + int packet_threshold = 30; + int timeout = 20; + + if (g_test_param.param_count > 0) { + packet_threshold = atoi(g_test_param.params[0]); + timeout = atoi(g_test_param.params[1]); + + __bt_free_test_param(&g_test_param); + } + + ret = bt_gatt_enable_data_batching(remote_addr, packet_threshold, timeout); + TC_PRT("returns %s, (packet_threshold:%d, timeout:%d)\n", __bt_get_error_message(ret), packet_threshold, timeout); + break; + } + case BT_UNIT_TEST_FUNCTION_GATT_DISABLE_DATA_BATCHING: { + ret = bt_gatt_disable_data_batching(remote_addr); + TC_PRT("returns %s\n", __bt_get_error_message(ret)); + break; + } case BT_UNIT_TEST_FUNCTION_ACTIVATE_FLAG_TO_SET_PARAMETERS: need_to_set_params = true; TC_PRT("Select the function again"); diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h index a7bb745..375a497 100644 --- a/test/bt_unit_test.h +++ b/test/bt_unit_test.h @@ -314,6 +314,9 @@ typedef enum { BT_UNIT_TEST_FUNCTION_GATT_READ_CHARACTERISTIC_VALUE, BT_UNIT_TEST_FUNCTION_GATT_WATCH_CHARACTERISTIC_CHANGES, BT_UNIT_TEST_FUNCTION_GATT_UNWATCH_CHARACTERISTIC_CHANGES, + BT_UNIT_TEST_FUNCTION_GATT_GET_DATA_BATCHING_AVAILABLE_PACKETS, + BT_UNIT_TEST_FUNCTION_GATT_ENABLE_DATA_BATCHING, + BT_UNIT_TEST_FUNCTION_GATT_DISABLE_DATA_BATCHING, BT_UNIT_TEST_FUNCTION_HPS_CLIENT_CREATE = 1, BT_UNIT_TEST_FUNCTION_HPS_CLIENT_DESTROY, BT_UNIT_TEST_FUNCTION_HPS_CLIENT_PRINT_ALL, -- 2.7.4