From 4957a5479032cf9b938adf7aecc106e5824b47b6 Mon Sep 17 00:00:00 2001 From: himanshu Date: Wed, 8 Jan 2020 12:44:24 +0530 Subject: [PATCH] Fix bt_device_get_connection_state API for LE connection. Change-Id: I9ca3dd90e6090958a6ccf950d61a972fc1e7eace Signed-off-by: himanshu --- .../services/device/bt-service-bonded-device.c | 23 +++++----- .../services/gatt/bt-service-gatt.c | 52 +++++++++++----------- .../services/include/bt-service-gatt.h | 4 ++ 3 files changed, 41 insertions(+), 38 deletions(-) diff --git a/bt-service-adaptation/services/device/bt-service-bonded-device.c b/bt-service-adaptation/services/device/bt-service-bonded-device.c index 66cd8f9..7f1683e 100644 --- a/bt-service-adaptation/services/device/bt-service-bonded-device.c +++ b/bt-service-adaptation/services/device/bt-service-bonded-device.c @@ -33,6 +33,7 @@ #include "bt-service-core-adapter.h" #include "bt-service-core-device.h" #include "bt-service-device-internal.h" +#include "bt-service-gatt.h" /* OAL headers */ #include @@ -186,9 +187,16 @@ static void __bt_handle_pending_request(int result, int service_function) result = BLUETOOTH_ERROR_NONE; g_array_append_vals(out_param, &(rem_info->connected), sizeof(bluetooth_connected_link_t)); - } else { - BT_DBG("Device not found in paired list"); - result = BLUETOOTH_ERROR_NOT_PAIRED; + } + else if (_bt_find_remote_gatt_client_info(address) || _bt_find_remote_gatt_server_info(address)) { + bluetooth_connected_link_t value = BLUETOOTH_CONNECTED_LINK_LE; + result = BLUETOOTH_ERROR_NONE; + g_array_append_vals(out_param, &(value), + sizeof(bluetooth_connected_link_t)); + } + else { + BT_DBG("Device not found in paired list \n Device not found in the LE devices list"); + result = BLUETOOTH_ERROR_NOT_FOUND; } _bt_service_method_return(req_info->context, out_param, result); @@ -596,8 +604,6 @@ int _bt_is_alias_set(bluetooth_device_address_t *device_address) int _bt_get_connected_link(bluetooth_device_address_t *device_address) { - char address[BT_ADDRESS_STRING_SIZE]; - bt_remote_dev_info_t *rem_info; int request = BT_GET_CONNECTED_LINK_TYPE; BT_DBG("+"); @@ -609,13 +615,6 @@ int _bt_get_connected_link(bluetooth_device_address_t *device_address) return BLUETOOTH_ERROR_NONE; } - _bt_convert_addr_type_to_string(address, device_address->addr); - rem_info = _bt_service_get_remote_dev_info(address); - if (!rem_info) { - BT_ERR("Bonded device not found in the list, return error"); - return BLUETOOTH_ERROR_NOT_PAIRED; - } - g_idle_add(__reply_pending_request, g_memdup(&request, sizeof(int))); BT_DBG("-"); return BLUETOOTH_ERROR_NONE; diff --git a/bt-service-adaptation/services/gatt/bt-service-gatt.c b/bt-service-adaptation/services/gatt/bt-service-gatt.c index 21eb17d..609eb14 100644 --- a/bt-service-adaptation/services/gatt/bt-service-gatt.c +++ b/bt-service-adaptation/services/gatt/bt-service-gatt.c @@ -1329,7 +1329,7 @@ static void __bt_handle_gatt_server_service_deleted(event_gatts_srvc_t *event) } } -static struct gatt_client_info_t *__bt_find_remote_gatt_client_info(char *address) +struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address) { GSList *l; struct gatt_client_info_t *info = NULL; @@ -1365,7 +1365,7 @@ static struct gatt_client_info_t *__bt_find_remote_gatt_client_info_from_conn_id } #ifdef TIZEN_GATT_CLIENT -static struct gatt_server_info_t *__bt_find_remote_gatt_server_info(char *address) +struct gatt_server_info_t *_bt_find_remote_gatt_server_info(char *address) { GSList *l; struct gatt_server_info_t *info = NULL; @@ -1449,7 +1449,7 @@ static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event) /* Check if device is already in connected list */ - conn_info = __bt_find_remote_gatt_client_info(address); + conn_info = _bt_find_remote_gatt_client_info(address); if (!conn_info) { BT_INFO("Conn Info absent: But no need to Send Local GATT Server Connected event to apps"); @@ -1513,7 +1513,7 @@ static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *even BT_INFO("Local GATT Server DisConnected: Remote Client addr[%s] Server Instance [%d] Connection ID [%d]", address, event->server_inst, event->conn_id); /* Remove Connection info */ - conn_info = __bt_find_remote_gatt_client_info(address); + conn_info = _bt_find_remote_gatt_client_info(address); if (conn_info) { BT_INFO("No need to Send Local GATT Server Disconnected event to apps, just remove remote client info"); @@ -1570,7 +1570,7 @@ static void __bt_handle_gatt_server_connection_state(event_gatts_conn_t *event) /* Check if device is already in connected list */ - conn_info = __bt_find_remote_gatt_client_info(address); + conn_info = _bt_find_remote_gatt_client_info(address); if (!conn_info) { param = g_variant_new("(is)", result, address); @@ -1633,7 +1633,7 @@ static void __bt_handle_gatt_server_disconnection_state(event_gatts_conn_t *even param); /* Remove Connection info */ - conn_info = __bt_find_remote_gatt_client_info(address); + conn_info = _bt_find_remote_gatt_client_info(address); if (conn_info) { BT_INFO("Remove GATT client info from List.."); /* Remove info from List */ @@ -2400,7 +2400,7 @@ int _bt_gatt_server_send_indication(char *sender, bluetooth_device_address_t *de } } else { - conn = __bt_find_remote_gatt_client_info(address); + conn = _bt_find_remote_gatt_client_info(address); if (conn) { ret = gatts_send_indication(param->instance_id, param->atrribute_handle, conn->connection_id, data->length, @@ -2465,7 +2465,7 @@ int _bt_request_att_mtu(bluetooth_device_address_t *device_address, _bt_convert_addr_type_to_string(addr, device_address->addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -2500,7 +2500,7 @@ int _bt_get_att_mtu(bluetooth_device_address_t *address, BT_INFO("Get current MTU size for the remote client:DevAddress:[%s]", addr); - conn_info = __bt_find_remote_gatt_client_info(addr); + conn_info = _bt_find_remote_gatt_client_info(addr); if (conn_info) { BT_INFO("GATT Client [%s] is connected, conn Id [%d] Instance ID [%d]", conn_info->addr, conn_info->connection_id, conn_info->instance_id); @@ -3050,7 +3050,7 @@ static void __bt_handle_client_connected(event_gattc_conn_t *event_data) if (result == BLUETOOTH_ERROR_NONE) { /* Check if device is already in connected list */ - conn_info = __bt_find_remote_gatt_server_info(address); + conn_info = _bt_find_remote_gatt_server_info(address); if (!conn_info) { /* Send event to BT-API */ @@ -3128,7 +3128,7 @@ static void __bt_handle_client_disconnected(event_gattc_conn_t *event_data) address, event_data->client_if, event_data->conn_id, event_data->status); /* Remove Connection info */ - conn_info = __bt_find_remote_gatt_server_info(address); + conn_info = _bt_find_remote_gatt_server_info(address); if (conn_info) { param = g_variant_new("(is)", result, address); @@ -4049,7 +4049,7 @@ gboolean _bt_is_remote_gatt_device_connected(bluetooth_device_address_t *address BT_INFO("Check Connected or not for [%s]", addr); /* Check if device is already in connected list */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("Remote GATT Server device [%s] is Connected", conn_info->addr); @@ -4060,7 +4060,7 @@ gboolean _bt_is_remote_gatt_device_connected(bluetooth_device_address_t *address BT_INFO("Remote GATT Server Device [%s] is not Connected", addr); /* Check if device is already in connected list */ - client_info = __bt_find_remote_gatt_client_info(addr); + client_info = _bt_find_remote_gatt_client_info(addr); if (client_info) { BT_INFO("Remote Client device [%s] is Connected", client_info->addr); @@ -4109,7 +4109,7 @@ int _bt_connect_le_device(bluetooth_device_address_t *address, } /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_ERR("GATT Server is already connected.."); g_free(addr); @@ -4163,7 +4163,7 @@ int _bt_gatt_get_primary_services(char *address) } /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(address); + conn_info = _bt_find_remote_gatt_server_info(address); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4209,7 +4209,7 @@ int _bt_gatt_get_all_characteristic(bluetooth_gatt_client_svc_prop_info_t *svc) _bt_convert_addr_type_to_string(addr, svc->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4269,7 +4269,7 @@ int _bt_gatt_get_all_characteristic_properties( _bt_convert_addr_type_to_string(addr, chr->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4332,7 +4332,7 @@ int _bt_gatt_read_characteristic_value( _bt_convert_addr_type_to_string(addr, chr->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4398,7 +4398,7 @@ int _bt_gatt_read_descriptor_value( _bt_convert_addr_type_to_string(addr, desc->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4447,7 +4447,7 @@ int _bt_gatt_acquire_notify(bluetooth_gatt_client_char_prop_info_t *chr, int *fd _bt_convert_addr_type_to_string(addr, chr->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4494,7 +4494,7 @@ int _bt_gatt_acquire_write(bluetooth_gatt_client_char_prop_info_t *chr, int *fd, _bt_convert_addr_type_to_string(addr, chr->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4565,7 +4565,7 @@ int _bt_gatt_write_characteristic_value_by_type( _bt_convert_addr_type_to_string(addr, chr->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4644,7 +4644,7 @@ int _bt_gatt_write_descriptor_value_by_type( _bt_convert_addr_type_to_string(addr, desc->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4701,7 +4701,7 @@ int _bt_gatt_watch_characteristic( _bt_convert_addr_type_to_string(addr, chr->device_address.addr); /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { BT_INFO("GATT Server [%s] is connected, conn Id [%d]", conn_info->addr, conn_info->connection_id); @@ -4768,7 +4768,7 @@ int _bt_disconnect_le_device(bluetooth_device_address_t *address, } } /* Check if remote GATT Server is connected or not */ - conn_info = __bt_find_remote_gatt_server_info(addr); + conn_info = _bt_find_remote_gatt_server_info(addr); if (conn_info) { /* Check if app sent 0 client id for Disconnection, in such case, use default gatt client ID */ if (client_id == 0) { @@ -4783,7 +4783,7 @@ int _bt_disconnect_le_device(bluetooth_device_address_t *address, conn_info->connection_id); } else { /* check if remote client is connected */ - rem_client_conn_info = __bt_find_remote_gatt_client_info(addr); + rem_client_conn_info = _bt_find_remote_gatt_client_info(addr); if (!rem_client_conn_info || client_id != 0) { BT_ERR("GATT device is not connected.."); diff --git a/bt-service-adaptation/services/include/bt-service-gatt.h b/bt-service-adaptation/services/include/bt-service-gatt.h index 97b7690..6c9efc9 100644 --- a/bt-service-adaptation/services/include/bt-service-gatt.h +++ b/bt-service-adaptation/services/include/bt-service-gatt.h @@ -97,6 +97,8 @@ int _bt_get_att_mtu(bluetooth_device_address_t *address, int _bt_gatt_server_acquire_send_response(char *sender, bluetooth_gatt_server_acquire_response_params_t *param, void *); +struct gatt_client_info_t *_bt_find_remote_gatt_client_info(char *address); + #ifdef TIZEN_GATT_CLIENT char * _bt_gatt_get_default_gatt_client_uuid(void); @@ -150,6 +152,8 @@ int _bt_unregister_gatt_client_instance(const char *sender, int client_id); int _bt_request_att_mtu(bluetooth_device_address_t *device_address, unsigned int mtu); +struct gatt_server_info_t *_bt_find_remote_gatt_server_info(char *address); + #endif //int _bt_gatt_server_enable_application(int instance_id); #if 0 -- 2.7.4