diff options
author | DoHyun Pyun <dh79.pyun@samsung.com> | 2019-11-08 13:04:29 +0900 |
---|---|---|
committer | DoHyun Pyun <dh79.pyun@samsung.com> | 2019-11-08 13:04:33 +0900 |
commit | d781987b76911ea31c5d1ca0e6a54c7386801f61 (patch) | |
tree | 71215c3f98088da6769d3d2916dbd3f1adcae78b | |
parent | a2d71a24c2a990436c387a87e2f3c23514569dab (diff) | |
parent | cd080d0eed167ff9004afe4d11ad6a3dbae39741 (diff) | |
download | bluetooth-d781987b76911ea31c5d1ca0e6a54c7386801f61.tar.gz bluetooth-d781987b76911ea31c5d1ca0e6a54c7386801f61.tar.bz2 bluetooth-d781987b76911ea31c5d1ca0e6a54c7386801f61.zip |
Merge branch 'tizen' into tizen_5.5submit/tizen_5.5/20191108.040531accepted/tizen/5.5/unified/20191111.105400
Change-Id: I8f12ad952a86ac838fef45a376bf1faf21fc591a
-rw-r--r-- | doc/bluetooth_doc.h | 1 | ||||
-rw-r--r-- | include/bluetooth.h | 2 | ||||
-rw-r--r-- | include/bluetooth_internal.h | 48 | ||||
-rw-r--r-- | include/bluetooth_private.h | 1 | ||||
-rw-r--r-- | include/bluetooth_type.h | 6 | ||||
-rw-r--r-- | include/bluetooth_type_internal.h | 14 | ||||
-rw-r--r-- | src/bluetooth-adapter.c | 68 | ||||
-rw-r--r-- | src/bluetooth-common.c | 7 | ||||
-rw-r--r-- | src/bluetooth-gatt.c | 25 | ||||
-rw-r--r-- | test/bt_unit_test.c | 50 | ||||
-rw-r--r-- | test/bt_unit_test.h | 3 |
11 files changed, 213 insertions, 12 deletions
diff --git a/doc/bluetooth_doc.h b/doc/bluetooth_doc.h index c93303b..47ecf1d 100644 --- a/doc/bluetooth_doc.h +++ b/doc/bluetooth_doc.h @@ -94,6 +94,7 @@ * <tr> * <td>bt_adapter_visibility_mode_changed_cb()</td> * <td>Used to set visibility mode (#bt_adapter_visibility_mode_e). </td> + * <td></td> * </tr> * <tr> * <td>bt_adapter_start_device_discovery()<br> diff --git a/include/bluetooth.h b/include/bluetooth.h index 7f66769..6a50145 100644 --- a/include/bluetooth.h +++ b/include/bluetooth.h @@ -4536,7 +4536,7 @@ int bt_gatt_client_unset_att_mtu_changed_cb(bt_gatt_client_h client); * @retval #BT_ERROR_NOT_SUPPORTED Not supported * * @see bt_gatt_client_characteristic_value_changed_cb() - * @see bt_gatt_client_unset_characteristic_value_change() + * @see bt_gatt_client_unset_characteristic_value_changed_cb() */ int bt_gatt_client_set_characteristic_value_changed_cb(bt_gatt_h characteristic, bt_gatt_client_characteristic_value_changed_cb callback, diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index ebcac01..8956618 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -124,6 +124,36 @@ int bt_adapter_read_battery_info(bt_battery_info_s *data); int bt_adapter_disable(void); /** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Initializes and activates battery monitor + * @since_tizen5.5 + * + * @param[in] callback Address of callback function + * @param[in] user_data user + * + * @pre This function will initialize and activate the battery monitor feature. + * It sets a callback function that will be called when bluetooth adapter + * is disabled. + * + * @see *bt_adapter_disable_battery_cb + */ +int bt_adapter_init_battery_monitor(bt_adapter_disable_battery_cb callback, + void *user_data); + +/** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Deinitializes and disables battery monitor. + * @since_tizen5.5 + * + * @pre This function will disable the battery monitor feature + * and unset the related callback function + * + * @see bt_adapter_init_battery_monitor + * @see *bt_adapter_disable_battery_cb + */ +int bt_adapter_deinit_battery_monitor(); + +/** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE * @brief Recover the local Bluetooth adapter, asynchronously. @@ -498,6 +528,24 @@ int bt_adapter_set_connectable(bool connectable); int bt_adapter_set_manufacturer_data(char *data, int len); /** + * @brief Checks scan filter feature is supported or not. + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_LE_MODULE + * + * @param[out] is_supported The Scan Filter feature support: (@c true = supported , @c false = not supported) + * + * @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 Adapter is not enabled + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * @retval #BT_ERROR_NOT_SUPPORTED Not supported + * + * @pre The state of local Bluetooth must be #BT_ADAPTER_ENABLED. + */ +int bt_adapter_le_is_scan_filter_supported(bool *is_supported); + +/** * @internal * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE * @brief Parse the samsung specific manufacturer data of discovered device. diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index a95b30f..882ed04 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -67,6 +67,7 @@ extern "C" { */ typedef enum { BT_EVENT_STATE_CHANGED = 0x00, /**< Adapter state is changed */ + BT_EVENT_ADAPTER_DISABLED_BATTERY_DATA, /**Notify BT usage data to battery monitor frwk**/ BT_EVENT_LE_STATE_CHANGED, /**< Adapter le state is changed */ BT_EVENT_NAME_CHANGED, /**< Adapter name is changed */ BT_EVENT_VISIBILITY_MODE_CHANGED, /**< Adapter visibility mode is changed */ diff --git a/include/bluetooth_type.h b/include/bluetooth_type.h index 97daa26..03c0206 100644 --- a/include/bluetooth_type.h +++ b/include/bluetooth_type.h @@ -1343,8 +1343,8 @@ typedef void (*bt_socket_connection_requested_cb) (int socket_fd, const char *re * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE * @brief Called when an OPP connection is requested. * - * @details You must call bt_opp_server_accept_connection() if you want to accept. - * Otherwise, you must call bt_opp_server_reject_connection(). + * @details You must call bt_opp_server_accept() if you want to accept. + * Otherwise, you must call bt_opp_server_reject(). * @since_tizen @if WEARABLE 2.3.1 @else 2.3 @endif * @param[in] remote_address The address of remote device * @param[in] user_data The user data passed from the callback registration function @@ -1363,7 +1363,6 @@ typedef void (*bt_opp_server_connection_requested_cb)(const char *remote_address * @param[in] percent The progress in percentage (1 ~ 100) * @param[in] user_data The user data passed from the callback registration function * @see bt_opp_server_accept() - * @see bt_opp_server_accept_connection() */ typedef void (*bt_opp_server_transfer_progress_cb) (const char *file, long long size, int percent, void *user_data); @@ -1377,7 +1376,6 @@ typedef void (*bt_opp_server_transfer_progress_cb) (const char *file, long long * @param[in] size The file size (bytes) * @param[in] user_data The user data passed from the callback registration function * @see bt_opp_server_accept() - * @see bt_opp_server_accept_connection() */ typedef void (*bt_opp_server_transfer_finished_cb) (int result, const char *file, long long size, void *user_data); diff --git a/include/bluetooth_type_internal.h b/include/bluetooth_type_internal.h index 2823237..1eca276 100644 --- a/include/bluetooth_type_internal.h +++ b/include/bluetooth_type_internal.h @@ -337,6 +337,20 @@ typedef void (*bt_adapter_connectable_changed_cb) (int result, bool connectable, void *user_data); /** + * @ingroup CAPI_NETWORK_BLUETOOTH_ADAPTER_MODULE + * @brief Called when adapter is disabled. + * @since_tizen5.5 + * + * @param[in] data Bluetooth session data + * + * @pre This function will be invoked when Bluetooth adapter is disabled + * if you activate the battery monitor feature using bt_adapter_init_battery_monitor + * + * @see bt_adapter_init_battery_monitor + */ +typedef void (*bt_adapter_disable_battery_cb)(bt_battery_info_s *data); + +/** * @ingroup CAPI_NETWORK_BLUETOOTH_OPP_SERVER_MODULE * @brief Called when the push is requested. * @since_tizen @if WEARABLE 2.3.1 @else 2.3 @endif diff --git a/src/bluetooth-adapter.c b/src/bluetooth-adapter.c index 5d9e469..8ceacbf 100644 --- a/src/bluetooth-adapter.c +++ b/src/bluetooth-adapter.c @@ -612,6 +612,39 @@ int bt_adapter_unset_connectable_changed_cb(void) return BT_ERROR_NONE; } +int bt_adapter_init_battery_monitor(bt_adapter_disable_battery_cb callback, + void *user_data) +{ + BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(callback); + + int ret = bluetooth_set_battery_monitor_state(TRUE); + if (ret != BT_ERROR_NONE) { + BT_ERR("Battery monitor could not be activated"); + return BT_ERROR_OPERATION_FAILED; + } + + _bt_set_cb(BT_EVENT_ADAPTER_DISABLED_BATTERY_DATA, callback, user_data); + + return BT_ERROR_NONE; +} + +int bt_adapter_deinit_battery_monitor(void) +{ + BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); + BT_CHECK_INIT_STATUS(); + + int ret = bluetooth_set_battery_monitor_state(FALSE); + if (ret != BT_ERROR_NONE) { + BT_ERR("Battery monitor could not be deactivated"); + return BT_ERROR_OPERATION_FAILED; + } + + _bt_unset_cb(BT_EVENT_ADAPTER_DISABLED_BATTERY_DATA); + return BT_ERROR_NONE; +} + int bt_adapter_get_connectable(bool *connectable) { gboolean is_connectable = FALSE; @@ -1025,6 +1058,7 @@ int bt_adapter_is_discovering(bool *is_discovering) } } +/* LCOV_EXCL_START */ int bt_adapter_le_is_discovering(bool *is_discovering) { int ret = 0; @@ -1044,6 +1078,7 @@ int bt_adapter_le_is_discovering(bool *is_discovering) return ret; /* LCOV_EXCL_LINE */ } } +/* LCOV_EXCL_STOP */ int bt_adapter_get_local_oob_data(unsigned char **hash, unsigned char **randomizer, @@ -2840,13 +2875,14 @@ int bt_adapter_le_start_scan(bt_adapter_le_scan_result_cb cb, void *user_data) BT_CHECK_INPUT_PARAMETER(cb); _bt_le_adapter_init(); - _bt_set_cb(BT_EVENT_LE_SCAN_RESULT_UPDATED, cb, user_data); error_code = _bt_get_error_code(bluetooth_start_le_discovery()); if (error_code != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), - error_code); /* LCOV_EXCL_LINE */ + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); /* LCOV_EXCL_LINE */ + return error_code; } + + _bt_set_cb(BT_EVENT_LE_SCAN_RESULT_UPDATED, cb, user_data); return error_code; } @@ -2859,13 +2895,12 @@ int bt_adapter_le_stop_scan(void) error_code = _bt_get_error_code(bluetooth_stop_le_discovery()); if (error_code != BT_ERROR_NONE) { - BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), - error_code); /* LCOV_EXCL_LINE */ + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), error_code); /* LCOV_EXCL_LINE */ + return error_code; } _bt_unset_cb(BT_EVENT_LE_SCAN_RESULT_UPDATED); _bt_le_adapter_deinit(); - return error_code; } @@ -4144,3 +4179,24 @@ int bt_adapter_le_is_coded_phy_supported(bool *is_supported) return BT_ERROR_NONE; } + +int bt_adapter_le_is_scan_filter_supported(bool *is_supported) +{ + int ret = BT_ERROR_NONE; + gboolean support = FALSE; + + BT_CHECK_ADAPTER_STATUS(); + BT_CHECK_INIT_STATUS(); + BT_CHECK_INPUT_PARAMETER(is_supported); + + ret = _bt_get_error_code(bluetooth_is_scan_filter_supported(&support)); + + if (ret != BT_ERROR_NONE) { + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(ret), ret); + return ret; + } + + *is_supported = support ? true : false; + + return BT_ERROR_NONE; +} diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index d5966fb..c59f074 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -127,6 +127,7 @@ typedef struct { static bt_event2index_table_t event2index[] = { { BLUETOOTH_EVENT_ENABLED, BT_EVENT_STATE_CHANGED }, { BLUETOOTH_EVENT_DISABLED, BT_EVENT_STATE_CHANGED }, + { BLUETOOTH_EVENT_DISABLED_BATTERY_DATA, BT_EVENT_ADAPTER_DISABLED_BATTERY_DATA}, { BLUETOOTH_EVENT_LE_ENABLED, BT_EVENT_LE_STATE_CHANGED }, { BLUETOOTH_EVENT_LE_DISABLED, BT_EVENT_LE_STATE_CHANGED }, { BLUETOOTH_EVENT_LOCAL_NAME_CHANGED, BT_EVENT_NAME_CHANGED }, @@ -1347,7 +1348,11 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us case BLUETOOTH_EVENT_DISABLED: BT_INFO("bt_adapter_state_changed_cb() will be called with BT_ADAPTER_DISABLED"); ((bt_adapter_state_changed_cb) bt_event_slot_container[event_index].callback) - (_bt_get_error_code(param->result), BT_ADAPTER_DISABLED, bt_event_slot_container[event_index].user_data); + (_bt_get_error_code(param->result), BT_ADAPTER_DISABLED, bt_event_slot_container[event_index].user_data); + break; + case BLUETOOTH_EVENT_DISABLED_BATTERY_DATA: + BT_INFO("bt_adapter_disable_battery_cb() will be called"); + ((bt_adapter_disable_battery_cb)bt_event_slot_container[event_index].callback)((bt_battery_info_s *)(param->param_data)); break; case BLUETOOTH_EVENT_LOCAL_NAME_CHANGED: BT_INFO("bt_adapter_name_changed_cb() will be called"); diff --git a/src/bluetooth-gatt.c b/src/bluetooth-gatt.c index a2b1733..1826561 100644 --- a/src/bluetooth-gatt.c +++ b/src/bluetooth-gatt.c @@ -3347,6 +3347,7 @@ int bt_gatt_server_foreach_services(bt_gatt_server_h server, return BT_ERROR_NONE; } +/* LCOV_EXCL_START */ int bt_gatt_server_set_att_mtu_changed_cb(bt_gatt_server_h server, bt_gatt_server_att_mtu_changed_cb callback, void *user_data) { bt_gatt_server_s *server_s = (bt_gatt_server_s *)server; @@ -3384,6 +3385,7 @@ int bt_gatt_server_unset_att_mtu_changed_cb(bt_gatt_server_h server) return BT_ERROR_NONE; } +/* LCOV_EXCL_STOP */ #ifdef TIZEN_GATT_CLIENT int bt_gatt_client_create(const char *remote_address, bt_gatt_client_h *client) @@ -5073,3 +5075,26 @@ int bt_gatt_client_unset_att_mtu_changed_cb(bt_gatt_client_h client) return BT_ERROR_NONE; } + +/* LCOV_EXCL_START */ +int bt_gatt_get_uuid_specification_name(const char *uuid, char **name) +{ + int error_code = BT_ERROR_NONE; + + BT_CHECK_SUPPORTED_FEATURE(BT_FEATURE_COMMON); + BT_CHECK_INPUT_PARAMETER(uuid); + BT_CHECK_INPUT_PARAMETER(name); + + BT_INFO("UUID [%s]", uuid); + + error_code = _bt_get_error_code(bluetooth_get_uuid_name(uuid, name)); + if (error_code != BT_ERROR_NONE) { /* LCOV_EXCL_LINE */ + BT_ERR("%s(0x%08x)", _bt_convert_error_to_string(error_code), /* LCOV_EXCL_LINE */ + error_code); /* LCOV_EXCL_LINE */ + return error_code; /* LCOV_EXCL_LINE */ + } + + BT_INFO("Specification Name [%s]", *name); + return BT_ERROR_NONE; +} +/* LCOV_EXCL_STOP */ diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index ee3c185..dd9229a 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -239,6 +239,10 @@ tc_table_t tc_adapter[] = { , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_REMOTE_OOB_EXT_DATA}, {"bt_adapter_read_battery_info" , BT_UNIT_TEST_FUNCTION_ADAPTER_READ_BATTERY_INFO}, + {"bt_adapter_init_battery_monitor" + , BT_UNIT_TEST_FUNCTION_ADAPTER_INIT_BATTERY_MONITOR}, + {"bt_adapter_deinit_battery_monitor" + , BT_UNIT_TEST_FUNCTION_ADAPTER_DEINIT_BATTERY_MONITOR}, {"bt_adapter_set_visibility_mode_changed_cb" , BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_MODE_CHANGED_CB}, {"bt_adapter_unset_visibility_mode_changed_cb" @@ -643,6 +647,8 @@ tc_table_t tc_gatt[] = { , BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_CUSTOM_VAL}, {"Start Server" , BT_UNIT_TEST_FUNCTION_GATT_START_SERVER}, + {"Get Specification Name from UUID" + , BT_UNIT_TEST_FUNCTION_GATT_GET_SPEC_NAME_FROM_UUID}, {"ANCS (Pair)" , BT_UNIT_TEST_FUNCTION_ANCS_PAIR}, {"ANCS (Watch notification)" @@ -1467,6 +1473,23 @@ void __bt_adapter_state_changed_cb(int result, "ENABLED" : "DISABLED"); } +static void __bt_adapter_disable_battery_cb(bt_battery_info_s *data) +{ + TC_PRT("Battery data: %ld %ld %d %d", data->session_start_time, + data->session_end_time, data->session_scan_time, data->session_connected_time); + if (data->atm_list == NULL) { + TC_PRT("No data transaction in this session"); + return; + } + + TC_PRT("Displaying app-wise transaction details"); + for (GSList *l = data->atm_list; l != NULL; l = g_slist_next(l)) { + bt_battery_app_info_s *t = (bt_battery_app_info_s *)(l->data); + TC_PRT("uid: %ld, pid: %ld, received bytes: %d, sent bytes: %d", + (long int)(t->uid), (long int)(t->pid), t->rx_bytes, t->tx_bytes); + } +} + static void __bt_adapter_device_visibility_mode_changed_cb(int result, bt_adapter_visibility_mode_e visibility_mode, void *user_data) @@ -4243,6 +4266,22 @@ int test_input_callback(void *data) } break; } + case BT_UNIT_TEST_FUNCTION_ADAPTER_INIT_BATTERY_MONITOR: { + int ret = bt_adapter_init_battery_monitor(__bt_adapter_disable_battery_cb, NULL); + if (ret == BLUETOOTH_ERROR_NONE) + TC_PRT("Battery monitor initialized and activated"); + else + TC_PRT("Battery monitor could not be initialized and activated"); + break; + } + case BT_UNIT_TEST_FUNCTION_ADAPTER_DEINIT_BATTERY_MONITOR: { + int ret = bt_adapter_deinit_battery_monitor(); + if (ret == BLUETOOTH_ERROR_NONE) + TC_PRT("Battery monitor deinitialized successfully"); + else + TC_PRT("Battery monitor could not be deinitialized"); + break; + } case BT_UNIT_TEST_FUNCTION_ADAPTER_SET_REMOTE_OOB_EXT_DATA: { char remote_addr[18]; unsigned char *param_data[4]; @@ -6967,6 +7006,17 @@ int test_input_callback(void *data) TC_PRT("bt_gatt_server_register_service : %s\n", __bt_get_error_message(ret)); break; } + case BT_UNIT_TEST_FUNCTION_GATT_GET_SPEC_NAME_FROM_UUID: { + char *name = NULL; + char *uuid = "0000180F-0000-1000-8000-00805F9B34FB"; + ret = bt_gatt_get_uuid_specification_name(uuid, &name); + TC_PRT("bt_gatt_get_uuid_specification_name : %s\n", __bt_get_error_message(ret)); + if (BT_ERROR_NONE == ret) { + TC_PRT("UUID [%s] Specification Name [%s]", uuid, name); + free(name); + } + break; + } case BT_UNIT_TEST_FUNCTION_GATT_SERVER_FOREACH_SERVICES: { #ifdef ARCH64 ret = bt_gatt_server_foreach_services(server, diff --git a/test/bt_unit_test.h b/test/bt_unit_test.h index 2278306..1da019b 100644 --- a/test/bt_unit_test.h +++ b/test/bt_unit_test.h @@ -85,6 +85,8 @@ typedef enum { BT_UNIT_TEST_FUNCTION_ADAPTER_SET_REMOTE_OOB_EXT_DATA, BT_UNIT_TEST_FUNCTION_ADAPTER_REMOVE_REMOTE_OOB_DATA, BT_UNIT_TEST_FUNCTION_ADAPTER_READ_BATTERY_INFO, + BT_UNIT_TEST_FUNCTION_ADAPTER_INIT_BATTERY_MONITOR, + BT_UNIT_TEST_FUNCTION_ADAPTER_DEINIT_BATTERY_MONITOR, BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_MODE_CHANGED_CB, BT_UNIT_TEST_FUNCTION_ADAPTER_UNSET_VISIBILITY_MODE_CHANGED_CB, BT_UNIT_TEST_FUNCTION_ADAPTER_SET_VISIBILITY_DURATION_CHANGED_CB, @@ -274,6 +276,7 @@ BT_UNIT_TEST_FUNCTION_ADAPTER_LE_SET_SCAN_TYPE, BT_UNIT_TEST_FUNCTION_GATT_SERVER_REGISTER_CUSTOM_SVC, BT_UNIT_TEST_FUNCTION_GATT_SERVER_CHANGE_CUSTOM_VAL, BT_UNIT_TEST_FUNCTION_GATT_START_SERVER, + BT_UNIT_TEST_FUNCTION_GATT_GET_SPEC_NAME_FROM_UUID, BT_UNIT_TEST_FUNCTION_ANCS_PAIR, BT_UNIT_TEST_FUNCTION_ANCS_WATCH, BT_UNIT_TEST_FUNCTION_ANCS_POSITIVE_ACTION, |