#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;
BT_INFO_C("### Connected [RFCOMM Server]");
+ if (__rfcomm_send_conn_info(TRUE, conn_info.socket_fd) != BLUETOOTH_ERROR_NONE)
+ BT_ERR("Fail to send the connection info");
+
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
BLUETOOTH_ERROR_NONE, &conn_info,
event_info->cb, event_info->user_data);
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)
+ BT_ERR("Fail to send the connection info");
+
_bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
BLUETOOTH_ERROR_NONE, &disconn_info,
event_info->cb, event_info->user_data);
BT_DBG("Sending details to bluetooth battery monitor: %ld, %ld, %d", (long int)uid, (long int)pid, size);
_bt_bm_add_transaction_details(uid, pid, size, TX_DATA);
break;
- }
+ }
+ case BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO: {
+ gboolean connected = FALSE;
+ int client_fd = -1;
+
+ 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));
+
+ if (connected == TRUE)
+ result = _bt_rfcomm_server_conn_added(sender, client_fd);
+ else
+ result = _bt_rfcomm_server_conn_removed(sender, client_fd);
+
+ break;
+ }
case BT_AUDIO_SELECT_ROLE: {
bluetooth_audio_role_t role;
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_OPP_PUSH_FILES:
case BT_OPP_CANCEL_PUSH:
/* 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);
}
static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
void _bt_bm_remove_scan_app(bt_bm_scan_type_e type, uid_t uid, pid_t pid);
+void _bt_start_connect_time(void);
+
+void _bt_stop_connect_time(void);
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
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);
#ifdef __cplusplus
}
#include "bt-service-common.h"
#include "bt-service-rfcomm.h"
#include "bt-service-socket.h"
+#include "bt-service-battery-monitor.h"
+
+typedef struct {
+ char *sender;
+ int client_fd;
+} bt_rfcomm_conn_info_t;
+
+static GSList *server_conn_list = NULL;
static void __bt_rfcomm_reply_pending_request(int result,
int service_function, void *user_data, unsigned int size)
BT_DBG("-");
return sock_fd;
}
+
+static bt_rfcomm_conn_info_t* __bt_find_server_from_list(const char *sender, int client_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)) {
+ conn_info = l->data;
+ if (g_strcmp0(conn_info->sender, sender) == 0) {
+ if (client_fd == conn_info->client_fd)
+ return conn_info;
+ }
+ }
+
+ return NULL;
+}
+
+int _bt_rfcomm_server_conn_added(char *svc_name, int client_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");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
+
+ BT_INFO("RFCOMM server is connected: [%s], [%d]", svc_name, client_fd);
+
+ conn_info = g_malloc0(sizeof(bt_rfcomm_conn_info_t));
+
+ if (conn_info == NULL)
+ return BLUETOOTH_ERROR_MEMORY_ALLOCATION;
+
+ _bt_start_connect_time();
+
+ conn_info->sender = g_strdup(svc_name);
+ conn_info->client_fd = client_fd;
+
+ server_conn_list = g_slist_append(server_conn_list, conn_info);
+
+ return BLUETOOTH_ERROR_NONE;
+}
+
+int _bt_rfcomm_server_conn_removed(char *svc_name, int client_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);
+
+ /* Find the first connection */
+ conn_info = __bt_find_server_from_list(svc_name, client_fd);
+
+ if (conn_info == NULL) {
+ BT_ERR("No client fd is in list");
+ return BLUETOOTH_ERROR_INVALID_PARAM;
+ }
+
+ _bt_stop_connect_time();
+
+ server_conn_list = g_slist_remove(server_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)
+{
+ GSList *l;
+ bt_rfcomm_conn_info_t *conn_info = NULL;
+
+ ret_if(NULL == name);
+
+ for (l = server_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);
+ }
+ }
+}
+
+static void __bt_free_server_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)
+{
+ g_slist_free_full(server_conn_list, (GDestroyNotify)__bt_free_server_conn);
+ server_conn_list = NULL;
+}
BT_RFCOMM_CREATE_SOCKET_EX,
BT_RFCOMM_REMOVE_SOCKET_EX,
BT_RFCOMM_SEND_RX_DETAILS,
- BT_RFCOMM_SEND_TX_DETAILS,
+ BT_RFCOMM_SEND_TX_DETAILS,
+ BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO,
BT_PBAP_CONNECT = BT_FUNC_PBAP_BASE,
BT_PBAP_DISCONNECT,
BT_PBAP_GET_PHONEBOOK_SIZE,