From ca015575834785fba1981b4183960046d55e1103 Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Mon, 23 Dec 2019 16:28:31 +0900 Subject: [PATCH] Get RSSI when link loss occurs Change-Id: I71fbd0106e9443178293af6b849ecb2ce28ab65b Signed-off-by: Deokhyun Kim --- include/bluetooth_internal.h | 18 ++++++++++++++++++ include/bluetooth_private.h | 2 ++ src/bluetooth-common.c | 11 ++++++++++- src/bluetooth-device.c | 13 +++++++++++++ test/bt_unit_test.c | 6 +++++- 5 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/bluetooth_internal.h b/include/bluetooth_internal.h index c349656..dd57933 100644 --- a/include/bluetooth_internal.h +++ b/include/bluetooth_internal.h @@ -1226,6 +1226,24 @@ int bt_device_set_trusted_profile_cb(bt_device_trusted_profiles_cb callback, voi int bt_device_unset_trusted_profile_cb(void); /** + * @internal + * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE + * @brief Gets the rssi value when link loss occurs. + * @since_tizen 6.0 + * + * @remarks This function should be called in bt_device_connection_state_changed_cb + * when the device is disconnected + * + * @param[out] progress Link loss rssi + * @retval #BT_ERROR_NONE Successful + * @retval #BT_ERROR_OPERATION_FAILED Operation failed + * + * @see bt_device_set_connection_state_changed_cb() + * @see bt_device_connection_state_changed_cb() + */ +int bt_device_get_link_loss_rssi(int *rssi); + +/** * @deprecated Deprecated since 4.0. Use bt_gatt_client_request_att_mtu_change instead. * @ingroup CAPI_NETWORK_BLUETOOTH_DEVICE_MODULE * @brief Request to change ATT MTU value diff --git a/include/bluetooth_private.h b/include/bluetooth_private.h index 18976d8..0a75fea 100644 --- a/include/bluetooth_private.h +++ b/include/bluetooth_private.h @@ -711,6 +711,8 @@ int _bt_get_bt_device_info_s(bt_device_info_s **dest_dev, bluetooth_device_info_ int _bt_get_ad_data_by_type(char *in_data, int in_len, char in_type, char **data, int *data_len); +int _bt_get_link_loss_rssi(void); + /** * @internal * @brief Free bt_device_info_s. diff --git a/src/bluetooth-common.c b/src/bluetooth-common.c index d535ecd..8671857 100644 --- a/src/bluetooth-common.c +++ b/src/bluetooth-common.c @@ -33,6 +33,7 @@ static bool is_initialized = false; static bool is_le_initialized = false; +static int dbfw_rssi; static bt_event_sig_event_slot_s bt_event_slot_container[BT_EVENT_MAX] = { {NULL, NULL}, }; @@ -608,6 +609,11 @@ int _bt_get_ad_data_by_type(char *in_data, int in_len, } /* LCOV_EXCL_STOP */ +int _bt_get_link_loss_rssi(void) +{ + return dbfw_rssi; +} + int _bt_convert_address_to_string(char **addr_str, bluetooth_device_address_t *addr_hex) { char address[18] = { 0, }; @@ -835,8 +841,10 @@ static int __bt_get_bt_device_connection_info_s(bt_device_connection_info_s **de (*dest)->disconn_reason = BT_DEVICE_DISCONNECT_REASON_UNKNOWN; break; } - BT_INFO("Disconnected reason to app [0x%x]", (*dest)->disconn_reason); + + dbfw_rssi = source->rssi; + return BT_ERROR_NONE; } @@ -1602,6 +1610,7 @@ static void __bt_event_proxy(int event, bluetooth_event_param_t *param, void *us ((bt_device_connection_state_changed_cb)bt_event_slot_container[event_index].callback) (false, conn_info, bt_event_slot_container[event_index].user_data); __bt_free_bt_device_connection_info_s(conn_info); + dbfw_rssi = 0; } break; case BLUETOOTH_EVENT_RSSI_ENABLED: diff --git a/src/bluetooth-device.c b/src/bluetooth-device.c index 3de6a4c..631ef41 100644 --- a/src/bluetooth-device.c +++ b/src/bluetooth-device.c @@ -933,4 +933,17 @@ int bt_device_le_set_data_length_change_cb( return BT_ERROR_NONE; } + +int bt_device_get_link_loss_rssi(int *rssi) +{ + BT_CHECK_INPUT_PARAMETER(rssi); + + int value = _bt_get_link_loss_rssi(); + if (value == 0) + return BT_ERROR_OPERATION_FAILED; + + *rssi = value; + return BT_ERROR_NONE; +} + /* LCOV_EXCL_STOP */ diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 8cf14fa..1d859b8 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -2144,8 +2144,12 @@ void __bt_device_connection_state_changed_cb(bool connected, TC_PRT("__bt_device_connection_state_changed_cb [%d]", connected); TC_PRT("address [%s]", conn_info->remote_address); TC_PRT("link type [%d]", conn_info->link); - if (!connected) + if (!connected) { + int rssi; TC_PRT("disconnection reason [%d]", conn_info->disconn_reason); + if (bt_device_get_link_loss_rssi(&rssi) == BT_ERROR_NONE) + TC_PRT("RSSI = %d", rssi); + } } void __bt_device_att_mtu_changed_cb(int result, bt_device_att_mtu_info_s *mtu_info, void *user_data) -- 2.7.4