From: DoHyun Pyun Date: Wed, 8 Apr 2020 07:07:29 +0000 (+0900) Subject: Update the RFCOMM client connection information X-Git-Tag: accepted/tizen/unified/20200414.135759~1^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F52%2F230152%2F3;p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git Update the RFCOMM client connection information Change-Id: Ief091e60d094bc277daad306f3cce906a1607931 Signed-off-by: DoHyun Pyun --- diff --git a/bt-api/bt-common.c b/bt-api/bt-common.c index 2161643..696468a 100644 --- a/bt-api/bt-common.c +++ b/bt-api/bt-common.c @@ -179,6 +179,32 @@ int _bt_common_send_rfcomm_tx_details(int len) return ret; } +int _bt_common_send_rfcomm_conn_info(int role, gboolean connected, int socket_fd) +{ + int result = BLUETOOTH_ERROR_NONE; + + if (bluetooth_get_battery_monitor_state() == 0) { + BT_DBG("Battery monitor state is off"); + return BLUETOOTH_ERROR_NONE; + } + + BT_INIT_PARAMS(); + BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + g_array_append_vals(in_param1, &role, sizeof(int)); + g_array_append_vals(in_param2, &connected, sizeof(gboolean)); + g_array_append_vals(in_param3, &socket_fd, sizeof(int)); + + result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_UPDATE_CONNECTION_INFO, + in_param1, in_param2, in_param3, in_param4, &out_param); + + BT_DBG("result: %x", result); + + BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); + + return result; +} + void _bt_common_event_cb(int event, int result, void *param, void *callback, void *user_data) { diff --git a/bt-api/bt-rfcomm-client.c b/bt-api/bt-rfcomm-client.c index 65c983c..a642e10 100644 --- a/bt-api/bt-rfcomm-client.c +++ b/bt-api/bt-rfcomm-client.c @@ -320,6 +320,10 @@ static void _bt_rfcomm_disconnect_conn_info(rfcomm_conn_info_t *conn_info, if (info->rfcomm_conns == NULL) rfcomm_cb_data_remove(info); + if (_bt_common_send_rfcomm_conn_info(RFCOMM_ROLE_CLIENT, + FALSE, disconn_info.socket_fd) != BLUETOOTH_ERROR_NONE) + BT_ERR("Fail to send the connection info"); + BT_DBG("-"); } @@ -475,6 +479,10 @@ static void __client_connected_cb(rfcomm_cb_data_t *cb_data, char *dev_address, conn_info.socket_fd = conn_list_info->fd; conn_info.server_id = -1; + if (_bt_common_send_rfcomm_conn_info(RFCOMM_ROLE_CLIENT, + TRUE, conn_info.socket_fd) != BLUETOOTH_ERROR_NONE) + BT_ERR("Fail to send the connection info"); + BT_DBG("Connection Result[%d] BT_ADDRESS[%s] UUID[%s] FD[%d]", result, conn_list_info->bt_addr, cb_data->uuid, conn_list_info->fd); _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED, diff --git a/bt-api/bt-rfcomm-server.c b/bt-api/bt-rfcomm-server.c index 1e6e1c6..2ad7d73 100644 --- a/bt-api/bt-rfcomm-server.c +++ b/bt-api/bt-rfcomm-server.c @@ -36,31 +36,6 @@ #define BLUETOOTH_SOCK_CONNECT_INFO_LEN 16 #define BATTERY_MONITOR_RFCOMM_INTERVAL 5 -static int __rfcomm_send_conn_info(gboolean connected, int client_fd) -{ - int result; - - if (bluetooth_get_battery_monitor_state() == 0) { - BT_DBG("Battery monitor state is off"); - return BLUETOOTH_ERROR_NONE; - } - - BT_INIT_PARAMS(); - BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - - g_array_append_vals(in_param1, &connected, sizeof(gboolean)); - g_array_append_vals(in_param2, &client_fd, sizeof(int)); - - result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO, - in_param1, in_param2, in_param3, in_param4, &out_param); - - BT_DBG("result: %x", result); - - BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param); - - return result; -} - #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT static GSList *rfcomm_nodes; @@ -222,7 +197,8 @@ static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn, BT_INFO_C("### Connected [RFCOMM Server]"); - if (__rfcomm_send_conn_info(TRUE, conn_info.socket_fd) != BLUETOOTH_ERROR_NONE) + if (_bt_common_send_rfcomm_conn_info(RFCOMM_ROLE_SERVER, + TRUE, conn_info.socket_fd) != BLUETOOTH_ERROR_NONE) BT_ERR("Fail to send the connection info"); _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED, @@ -262,7 +238,8 @@ static void __rfcomm_server_disconnect_conn(rfcomm_conn_t *conn, BT_INFO("Disconnected FD [%d]", conn->fd); disconn_info.socket_fd = conn->fd; - if (__rfcomm_send_conn_info(FALSE, disconn_info.socket_fd) != BLUETOOTH_ERROR_NONE) + if (_bt_common_send_rfcomm_conn_info(RFCOMM_ROLE_SERVER, + FALSE, disconn_info.socket_fd) != BLUETOOTH_ERROR_NONE) BT_ERR("Fail to send the connection info"); _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED, diff --git a/bt-api/include/bt-common.h b/bt-api/include/bt-common.h index c74baaf..8d69aab 100644 --- a/bt-api/include/bt-common.h +++ b/bt-api/include/bt-common.h @@ -326,6 +326,8 @@ int _bt_common_send_rfcomm_rx_details(int len); int _bt_common_send_rfcomm_tx_details(int len); +int _bt_common_send_rfcomm_conn_info(int role, gboolean connected, int client_fd); + const char *_bt_convert_error_to_string(int error); const char *_bt_convert_service_function_to_string(int function); diff --git a/bt-service-adaptation/services/bt-request-handler.c b/bt-service-adaptation/services/bt-request-handler.c index 4e230df..b8d6b55 100644 --- a/bt-service-adaptation/services/bt-request-handler.c +++ b/bt-service-adaptation/services/bt-request-handler.c @@ -1558,19 +1558,21 @@ int __bt_bluez_request(int function_name, _bt_bm_add_transaction_details(uid, pid, size, TX_DATA); break; } - case BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO: { + case BT_RFCOMM_UPDATE_CONNECTION_INFO: { gboolean connected = FALSE; - int client_fd = -1; + int socket_fd = -1; + int role = RFCOMM_ROLE_SERVER; sender = (char *)g_dbus_method_invocation_get_sender(context); - __bt_service_get_parameters(in_param1, &connected, sizeof(gboolean)); - __bt_service_get_parameters(in_param2, &client_fd, sizeof(int)); + __bt_service_get_parameters(in_param1, &role, sizeof(int)); + __bt_service_get_parameters(in_param2, &connected, sizeof(gboolean)); + __bt_service_get_parameters(in_param3, &socket_fd, sizeof(int)); if (connected == TRUE) - result = _bt_rfcomm_server_conn_added(sender, client_fd); + result = _bt_rfcomm_conn_added(sender, role, socket_fd); else - result = _bt_rfcomm_server_conn_removed(sender, client_fd); + result = _bt_rfcomm_conn_removed(sender, role, socket_fd); break; } @@ -4010,7 +4012,7 @@ gboolean __bt_service_check_privilege(int function_name, case BT_RFCOMM_REMOVE_SOCKET: case BT_RFCOMM_SEND_RX_DETAILS: case BT_RFCOMM_SEND_TX_DETAILS: - case BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO: + case BT_RFCOMM_UPDATE_CONNECTION_INFO: case BT_OPP_PUSH_FILES: case BT_OPP_CANCEL_PUSH: @@ -4417,8 +4419,8 @@ static void __name_owner_changed(GDBusConnection *connection, /* Check if le_scanning app is terminated */ _bt_check_le_scanner_app_termination(name); - /* Check if RFCOMM server is terminated */ - _bt_rfcomm_server_check_termination(name); + /* Check if RFCOMM app is terminated */ + _bt_rfcomm_check_termination(name); } static void __bt_service_bus_acquired_handler(GDBusConnection *connection, diff --git a/bt-service-adaptation/services/include/bt-service-rfcomm.h b/bt-service-adaptation/services/include/bt-service-rfcomm.h index 0f4f9db..66b6750 100644 --- a/bt-service-adaptation/services/include/bt-service-rfcomm.h +++ b/bt-service-adaptation/services/include/bt-service-rfcomm.h @@ -33,9 +33,9 @@ extern "C" { int _bt_rfcomm_connect_using_uuid(bluetooth_device_address_t *device_address, char *remote_uuid); int _bt_rfcomm_connect_using_channel(bluetooth_device_address_t *device_address, char *chan_str); int _bt_rfcomm_socket_listen(char *svc_name, char *uuid, bool accept); -int _bt_rfcomm_server_conn_added(char *svc_name, int client_fd); -int _bt_rfcomm_server_conn_removed(char *svc_name, int client_fd); -void _bt_rfcomm_server_check_termination(const char *name); +int _bt_rfcomm_conn_added(char *svc_name, int role, int socket_fd); +int _bt_rfcomm_conn_removed(char *svc_name, int role, int socket_fd); +void _bt_rfcomm_check_termination(const char *name); #ifdef __cplusplus } diff --git a/bt-service-adaptation/services/rfcomm/bt-service-rfcomm.c b/bt-service-adaptation/services/rfcomm/bt-service-rfcomm.c index 7311d40..a7558ab 100644 --- a/bt-service-adaptation/services/rfcomm/bt-service-rfcomm.c +++ b/bt-service-adaptation/services/rfcomm/bt-service-rfcomm.c @@ -38,10 +38,11 @@ typedef struct { char *sender; - int client_fd; + int role; + int socket_fd; } bt_rfcomm_conn_info_t; -static GSList *server_conn_list = NULL; +static GSList *rfcomm_conn_list = NULL; static void __bt_rfcomm_reply_pending_request(int result, int service_function, void *user_data, unsigned int size) @@ -51,8 +52,9 @@ static void __bt_rfcomm_reply_pending_request(int result, invocation_info_t *req_info; /* Get method invocation context */ - for (l = _bt_get_invocation_list(); l != NULL; l = g_slist_next(l)) { + for (l = _bt_get_invocation_list(); l != NULL; ) { req_info = l->data; + l = g_slist_next(l); if (req_info == NULL || req_info->service_function != service_function) continue; @@ -254,17 +256,18 @@ int _bt_rfcomm_socket_listen(char *svc_name, char *uuid, bool accept) return sock_fd; } -static bt_rfcomm_conn_info_t* __bt_find_server_from_list(const char *sender, int client_fd) +static bt_rfcomm_conn_info_t* __bt_find_conn_from_list(const char *sender, int role, int socket_fd) { GSList *l; bt_rfcomm_conn_info_t *conn_info; retv_if(NULL == sender, NULL); - for (l = server_conn_list; l != NULL; l = g_slist_next(l)) { + for (l = rfcomm_conn_list; l != NULL; l = g_slist_next(l)) { conn_info = l->data; if (g_strcmp0(conn_info->sender, sender) == 0) { - if (client_fd == conn_info->client_fd) + if (socket_fd == conn_info->socket_fd && + role == conn_info->role) return conn_info; } } @@ -272,18 +275,18 @@ static bt_rfcomm_conn_info_t* __bt_find_server_from_list(const char *sender, int return NULL; } -int _bt_rfcomm_server_conn_added(char *svc_name, int client_fd) +int _bt_rfcomm_conn_added(char *svc_name, int role, int socket_fd) { bt_rfcomm_conn_info_t *conn_info = NULL; retv_if(NULL == svc_name, BLUETOOTH_ERROR_INVALID_PARAM); - if (__bt_find_server_from_list(svc_name, client_fd) != NULL) { - BT_ERR("Client fd already exist"); + if (__bt_find_conn_from_list(svc_name, role, socket_fd) != NULL) { + BT_ERR("Socket fd already exist"); return BLUETOOTH_ERROR_INVALID_PARAM; } - BT_INFO("RFCOMM server is connected: [%s], [%d]", svc_name, client_fd); + BT_INFO("RFCOMM is connected: [%s], [%d], [%d]", svc_name, role, socket_fd); conn_info = g_malloc0(sizeof(bt_rfcomm_conn_info_t)); @@ -293,51 +296,53 @@ int _bt_rfcomm_server_conn_added(char *svc_name, int client_fd) _bt_start_connect_time(); conn_info->sender = g_strdup(svc_name); - conn_info->client_fd = client_fd; + conn_info->role = role; + conn_info->socket_fd = socket_fd; - server_conn_list = g_slist_append(server_conn_list, conn_info); + rfcomm_conn_list = g_slist_append(rfcomm_conn_list, conn_info); return BLUETOOTH_ERROR_NONE; } -int _bt_rfcomm_server_conn_removed(char *svc_name, int client_fd) +int _bt_rfcomm_conn_removed(char *svc_name, int role, int socket_fd) { bt_rfcomm_conn_info_t *conn_info = NULL; retv_if(NULL == svc_name, BLUETOOTH_ERROR_INVALID_PARAM); - BT_INFO("RFCOMM server is disconnected: [%s], [%d]", svc_name, client_fd); + BT_INFO("RFCOMM is connected: [%s], [%d], [%d]", svc_name, role, socket_fd); /* Find the first connection */ - conn_info = __bt_find_server_from_list(svc_name, client_fd); + conn_info = __bt_find_conn_from_list(svc_name, role, socket_fd); if (conn_info == NULL) { - BT_ERR("No client fd is in list"); + BT_ERR("No socket fd is in list"); return BLUETOOTH_ERROR_INVALID_PARAM; } _bt_stop_connect_time(); - server_conn_list = g_slist_remove(server_conn_list, conn_info); + rfcomm_conn_list = g_slist_remove(rfcomm_conn_list, conn_info); g_free(conn_info->sender); g_free(conn_info); return BLUETOOTH_ERROR_NONE; } -void _bt_rfcomm_server_check_termination(const char *name) +void _bt_rfcomm_check_termination(const char *name) { GSList *l; bt_rfcomm_conn_info_t *conn_info = NULL; ret_if(NULL == name); - for (l = server_conn_list; l != NULL; ) { + for (l = rfcomm_conn_list; l != NULL; ) { conn_info = l->data; l = g_slist_next(l); if (g_strcmp0(conn_info->sender, name) == 0) { - _bt_rfcomm_server_conn_removed((char *)name, - conn_info->client_fd); + _bt_rfcomm_conn_removed((char *)name, + conn_info->role, + conn_info->socket_fd); } } @@ -345,14 +350,14 @@ void _bt_rfcomm_server_check_termination(const char *name) _bt_unregister_osp_server_in_agent_by_sender(name); } -static void __bt_free_server_conn(bt_rfcomm_conn_info_t *conn_info) +static void __bt_free_rfcomm_conn(bt_rfcomm_conn_info_t *conn_info) { g_free(conn_info->sender); g_free(conn_info); } -void _bt_rfcomm_server_all_conn_removed(void) +void _bt_rfcomm_all_conn_removed(void) { - g_slist_free_full(server_conn_list, (GDestroyNotify)__bt_free_server_conn); - server_conn_list = NULL; + g_slist_free_full(rfcomm_conn_list, (GDestroyNotify)__bt_free_rfcomm_conn); + rfcomm_conn_list = NULL; } diff --git a/include/bt-internal-types.h b/include/bt-internal-types.h index de99945..febada4 100644 --- a/include/bt-internal-types.h +++ b/include/bt-internal-types.h @@ -336,7 +336,7 @@ typedef enum { BT_RFCOMM_REMOVE_SOCKET_EX, BT_RFCOMM_SEND_RX_DETAILS, BT_RFCOMM_SEND_TX_DETAILS, - BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO, + BT_RFCOMM_UPDATE_CONNECTION_INFO, BT_PBAP_CONNECT = BT_FUNC_PBAP_BASE, BT_PBAP_DISCONNECT, BT_PBAP_GET_PHONEBOOK_SIZE,