2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
21 #include <gio/gunixfdlist.h>
22 #include <sys/socket.h>
25 #include "bluetooth-api.h"
26 #include "bt-internal-types.h"
28 #include "bt-common.h"
29 #include "bt-request-sender.h"
30 #include "bt-event-handler.h"
32 #ifdef TIZEN_FEATURE_BT_DPM
36 #define BLUETOOTH_SOCK_CONNECT_INFO_LEN 16
37 #define BATTERY_MONITOR_RFCOMM_INTERVAL 5
39 static int __rfcomm_send_conn_info(gboolean connected, int client_fd)
43 if (bluetooth_get_battery_monitor_state() == 0) {
44 BT_DBG("Battery monitor state is off");
45 return BLUETOOTH_ERROR_NONE;
49 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
51 g_array_append_vals(in_param1, &connected, sizeof(gboolean));
52 g_array_append_vals(in_param2, &client_fd, sizeof(int));
54 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_SERVER_UPDATE_CONNECTION_INFO,
55 in_param1, in_param2, in_param3, in_param4, &out_param);
57 BT_DBG("result: %x", result);
59 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
64 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
66 static GSList *rfcomm_nodes;
69 bluetooth_device_address_t addr;
72 gboolean disconnected;
81 guint disconnect_idle_id;
84 static unsigned int rx_data = 0;
85 static guint rx_tag = 0;
87 static bool __rfcomm_record_rx_data(void)
90 int ret = _bt_common_send_rfcomm_rx_details(rx_data);
91 if (ret == BLUETOOTH_ERROR_NONE) {
95 BT_ERR("RFCOMM rx data could not be registered");
105 static rfcomm_info_t *__find_rfcomm_info_with_id(int id)
109 for (l = rfcomm_nodes; l != NULL; l = l->next) {
110 rfcomm_info_t *info = l->data;
119 static rfcomm_info_t *__find_rfcomm_info_with_fd(int fd)
124 for (l = rfcomm_nodes; l != NULL; l = l->next) {
125 rfcomm_info_t *info = l->data;
127 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
128 rfcomm_conn_t *conn = ll->data;
130 if (conn && conn->fd == fd)
138 static rfcomm_info_t *__find_rfcomm_info_with_path(const gchar *path)
142 for (l = rfcomm_nodes; l != NULL; l = l->next) {
143 rfcomm_info_t *info = l->data;
145 if (g_ascii_strcasecmp(info->path, path) == 0)
152 static rfcomm_info_t *__find_rfcomm_info_with_uuid(const char *uuid)
156 for (l = rfcomm_nodes; l != NULL; l = l->next) {
157 rfcomm_info_t *info = l->data;
159 if (g_ascii_strcasecmp(info->uuid, uuid) == 0)
166 static rfcomm_conn_t *__find_rfcomm_conn_with_fd(rfcomm_info_t *info,
172 for (l = info->rfcomm_conns; l; l = l->next) {
175 if (conn && conn->fd == fd)
182 static void __rfcomm_remove_conn(rfcomm_info_t *info, int fd)
186 conn = __find_rfcomm_conn_with_fd(info, fd);
190 info->rfcomm_conns = g_slist_remove(info->rfcomm_conns, conn);
192 if (conn->watch_id > 0)
193 g_source_remove(conn->watch_id);
197 gboolean _check_uuid_path(char *path, char *uuid)
199 rfcomm_info_t *info = NULL;
200 info = __find_rfcomm_info_with_path(path);
204 if (g_ascii_strcasecmp(info->uuid, uuid) == 0)
210 static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn,
211 bt_event_info_t *event_info)
213 bluetooth_rfcomm_connection_t conn_info;
215 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
217 conn_info.device_role = RFCOMM_ROLE_SERVER;
218 g_strlcpy(conn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
219 conn_info.socket_fd = conn->fd;
220 conn_info.device_addr = conn->addr;
221 conn_info.server_id = info->id;
223 BT_INFO_C("### Connected [RFCOMM Server]");
225 if (__rfcomm_send_conn_info(TRUE, conn_info.socket_fd) != BLUETOOTH_ERROR_NONE)
226 BT_ERR("Fail to send the connection info");
228 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
229 BLUETOOTH_ERROR_NONE, &conn_info,
230 event_info->cb, event_info->user_data);
233 static void __rfcomm_server_disconnect_conn(rfcomm_conn_t *conn,
236 bluetooth_rfcomm_disconnection_t disconn_info;
237 bt_event_info_t *event_info;
242 if (conn->disconnected == FALSE)
245 if (conn->watch_id > 0) {
246 g_source_remove(conn->watch_id);
250 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
251 if (event_info == NULL) {
252 BT_ERR("event_info is NULL");
253 __rfcomm_remove_conn(info, conn->fd);
257 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
258 disconn_info.device_role = RFCOMM_ROLE_SERVER;
259 g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
260 disconn_info.device_addr = conn->addr;
262 BT_INFO("Disconnected FD [%d]", conn->fd);
263 disconn_info.socket_fd = conn->fd;
265 if (__rfcomm_send_conn_info(FALSE, disconn_info.socket_fd) != BLUETOOTH_ERROR_NONE)
266 BT_ERR("Fail to send the connection info");
268 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
269 BLUETOOTH_ERROR_NONE, &disconn_info,
270 event_info->cb, event_info->user_data);
272 __rfcomm_remove_conn(info, conn->fd);
275 static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
277 BT_INFO_C("### Disconnected [RFCOMM Server]");
279 if (g_slist_find(rfcomm_nodes, info) == NULL) {
280 BT_INFO("rfcomm resource is already freed");
284 info->disconnect_idle_id = 0;
286 g_slist_foreach(info->rfcomm_conns,
287 (GFunc)__rfcomm_server_disconnect_conn, info);
293 static gboolean __is_error_by_disconnect(GError *err)
295 return !g_strcmp0(err->message, "Connection reset by peer") ||
296 !g_strcmp0(err->message, "Connection timed out") ||
297 !g_strcmp0(err->message, "Software caused connection abort");
300 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
305 int result = BLUETOOTH_ERROR_NONE;
306 rfcomm_info_t *info = data;
308 bt_event_info_t *event_info;
309 bluetooth_rfcomm_received_data_t data_r;
310 GIOStatus status = G_IO_STATUS_NORMAL;
314 retv_if(info == NULL, FALSE);
316 fd = g_io_channel_unix_get_fd(chan);
317 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
318 BT_ERR_C("RFComm Server disconnected: %d", fd);
320 if (info->disconnect_idle_id > 0) {
321 BT_INFO("Disconnect idle still not process remove source");
322 g_source_remove(info->disconnect_idle_id);
323 info->disconnect_idle_id = 0;
326 conn = __find_rfcomm_conn_with_fd(info, fd);
328 BT_ERR("No Connection info found with FD [%d]", fd);
332 if (conn->disconnected == FALSE) {
334 conn->disconnected = TRUE;
336 __rfcomm_server_disconnect(info);
340 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
342 status = g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
344 if (status != G_IO_STATUS_NORMAL) {
345 BT_ERR("IO Channel read is failed with %d", status);
351 BT_ERR("IO Channel read error [%s]", err->message);
352 if (status == G_IO_STATUS_ERROR &&
353 __is_error_by_disconnect(err)) {
354 BT_ERR("cond : %d", cond);
357 if (info->disconnect_idle_id > 0) {
358 BT_INFO("Disconnect idle still not process remove source");
359 g_source_remove(info->disconnect_idle_id);
360 info->disconnect_idle_id = 0;
363 conn = __find_rfcomm_conn_with_fd(info, fd);
365 BT_ERR("No Connection info found with FD [%d]", fd);
369 if (conn->disconnected == FALSE) {
371 conn->disconnected = TRUE;
373 __rfcomm_server_disconnect(info);
381 BT_ERR("Length is zero");
383 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
384 if (event_info == NULL) {
385 BT_ERR("event_info is NULL. Unable to invoke the callback");
390 data_r.socket_fd = fd;
391 data_r.buffer_size = len;
392 data_r.buffer = buffer;
394 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
396 event_info->cb, event_info->user_data);
398 if (bluetooth_get_battery_monitor_state()) {
400 BT_INFO("Adding rfcomm rx timeout function for battery monitor");
401 rx_tag = g_timeout_add_seconds(BATTERY_MONITOR_RFCOMM_INTERVAL, (GSourceFunc)__rfcomm_record_rx_data, NULL);
411 int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
416 bt_event_info_t *event_info;
418 BT_INFO("%s %d", path, fd);
420 info = __find_rfcomm_info_with_path(path);
422 BT_ERR("rfcomm info is NULL");
426 #ifdef TIZEN_FEATURE_BT_DPM
427 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
430 BT_ERR("Not allow to use SPP profile");
433 _bt_convert_addr_type_to_string(addr_str, addr->addr);
434 _bt_disconnect_ext_profile(addr_str, info->path);
440 conn = g_new0(rfcomm_conn_t, 1);
442 memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
443 info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
445 data_io = g_io_channel_unix_new(conn->fd);
447 g_io_channel_set_encoding(data_io, NULL, NULL);
448 g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
450 conn->watch_id = g_io_add_watch(data_io,
451 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
452 __data_received_cb, info);
454 g_io_channel_unref(data_io);
456 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
458 __connected_cb(info, conn, event_info);
463 static rfcomm_info_t *__register_method()
470 id = __rfcomm_assign_id();
474 path = g_strdup_printf("/org/socket/server/%d/%d", getpid(), id);
476 object_id = _bt_register_new_conn(path, new_server_connection);
478 __rfcomm_delete_id(id);
481 info = g_new0(rfcomm_info_t, 1);
482 info->object_id = (guint)object_id;
486 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
491 static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
496 object_id = _bt_register_new_conn_ex(path, bus_name, new_server_connection);
500 info = g_new0(rfcomm_info_t, 1);
501 info->object_id = (guint)object_id;
502 info->path = g_strdup(path);
505 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
510 void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
512 if (conn->disconnected == FALSE) {
514 conn->disconnected = TRUE;
516 __rfcomm_server_disconnect_conn(conn, info);
519 void free_rfcomm_info(rfcomm_info_t *info)
523 if (info->disconnect_idle_id > 0) {
524 BT_INFO("Disconnect idle still not process remove source");
525 g_source_remove(info->disconnect_idle_id);
526 info->disconnect_idle_id = 0;
529 __rfcomm_delete_id(info->id);
530 _bt_unregister_gdbus(info->object_id);
532 g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
539 void _bt_rfcomm_server_free_all(void)
541 BT_DBG("Free all the servers");
543 g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
547 void _bt_rfcomm_server_disconnect_all(void)
553 BT_INFO(" ### Disconnect all RFCOMM server connections");
555 for (server = rfcomm_nodes; server; ) {
556 rfcomm_info_t *info = server->data;
558 for (conn = info->rfcomm_conns; conn; conn = conn->next) {
559 rfcomm_conn_t *conn_info = conn->data;
561 if (conn_info == NULL)
564 if (conn_info->watch_id == 0 || conn_info->disconnected)
567 close(conn_info->fd);
568 conn_info->disconnected = TRUE;
570 _bt_convert_addr_type_to_string(addr,
571 conn_info->addr.addr);
572 _bt_disconnect_ext_profile(addr, info->path);
575 server = server->next;
576 __rfcomm_server_disconnect(info);
582 void _bt_rfcomm_server_reset_timer(void)
585 g_source_remove(rx_tag);
593 #define BT_RFCOMM_SERVER_ID_MAX 254
596 char addr[BT_ADDRESS_STRING_SIZE];
600 } rfcomm_remote_client_info_t;
603 char uuid[BLUETOOTH_UUID_STRING_MAX];
607 int max_pending_conn;
608 gboolean auto_accept;
609 char pending_addr[BT_ADDRESS_STRING_SIZE];
611 } rfcomm_server_info_t;
613 static GSList *rfcomm_servers;
614 static gboolean id_used[BT_RFCOMM_SERVER_ID_MAX];
617 int __rfcomm_assign_server_id(void)
621 BT_DBG("latest_id: %d", latest_id);
623 index = latest_id + 1;
625 if (index >= BT_RFCOMM_SERVER_ID_MAX)
628 BT_DBG("index: %d", index);
630 while (id_used[index] == TRUE) {
631 if (index == latest_id) {
632 /* No available ID */
633 BT_ERR("All request ID is used");
639 if (index >= BT_RFCOMM_SERVER_ID_MAX)
644 id_used[index] = TRUE;
646 BT_DBG("Assigned Id: %d", latest_id);
651 void __rfcomm_delete_server_id(int id)
653 ret_if(id >= BT_RFCOMM_SERVER_ID_MAX);
658 /* Next server will use this ID */
662 static rfcomm_server_info_t *__get_rfcomm_server_info_with_uuid(const char *uuid)
669 for (l = rfcomm_servers; l != NULL; l = l->next) {
670 rfcomm_server_info_t *info = l->data;
672 if (!strncasecmp(info->uuid, uuid, strlen(info->uuid)))
679 int _get_rfcomm_server_id(char *uuid, gboolean *auto_accept)
681 rfcomm_server_info_t *server_info;
683 server_info = __get_rfcomm_server_info_with_uuid(uuid);
687 *auto_accept = server_info->auto_accept;
688 return server_info->server_id;
691 static rfcomm_server_info_t *__get_rfcomm_server_info_with_id(int server_id)
695 for (l = rfcomm_servers; l != NULL; l = l->next) {
696 rfcomm_server_info_t *info = l->data;
700 BT_DBG("info->server_fd: %d, sock_fd:%d", info->server_id, server_id);
701 if (info->server_id == server_id)
708 void _bt_rfcomm_server_set_pending_conn(int server_id, char *address)
710 rfcomm_server_info_t *server_info;
716 server_info = __get_rfcomm_server_info_with_id(server_id);
720 g_strlcpy(server_info->pending_addr, address, BT_ADDRESS_STRING_SIZE);
723 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_fd(int sock_fd)
728 for (l = rfcomm_servers; l != NULL; l = l->next) {
729 rfcomm_server_info_t *info = l->data;
734 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
735 rfcomm_remote_client_info_t *client_info = l1->data;
739 if (client_info->sock_fd == sock_fd)
747 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_addr(char *addr)
752 retv_if(NULL == addr, NULL);
754 for (l = rfcomm_servers; l != NULL; l = l->next) {
755 rfcomm_server_info_t *info = l->data;
760 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
761 rfcomm_remote_client_info_t *client_info = l1->data;
765 if (!strncasecmp(client_info->addr, addr, strlen(client_info->addr)))
773 static void __remove_remote_client_info(rfcomm_remote_client_info_t *rem_client)
777 if (rem_client == NULL)
780 if (0 < rem_client->sock_fd) {
781 shutdown(rem_client->sock_fd, SHUT_RDWR);
782 close(rem_client->sock_fd);
785 if (rem_client->watch_id > 0)
786 g_source_remove(rem_client->watch_id);
793 static void __handle_rfcomm_client_disconnected(rfcomm_server_info_t *server_info,
794 rfcomm_remote_client_info_t *rem_client)
796 bluetooth_rfcomm_disconnection_t disconn_info;
797 bt_event_info_t *event_info;
801 if (rem_client == NULL || server_info == NULL)
804 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
805 if (event_info == NULL)
808 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
809 disconn_info.device_role = RFCOMM_ROLE_SERVER;
810 g_strlcpy(disconn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
811 _bt_convert_addr_string_to_type(disconn_info.device_addr.addr, rem_client->addr);
812 BT_DBG("Disconnected FD [%d]", rem_client->sock_fd);
813 disconn_info.socket_fd = rem_client->sock_fd;
815 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
816 BLUETOOTH_ERROR_NONE, &disconn_info,
817 event_info->cb, event_info->user_data);
820 static void __remove_rfcomm_server(rfcomm_server_info_t *info)
822 rfcomm_remote_client_info_t *client_info;
829 rfcomm_servers = g_slist_remove(rfcomm_servers, info);
830 if (info->conn_list) {
832 client_info = info->conn_list->data;
836 info->conn_list = g_slist_remove(info->conn_list, client_info);
837 __handle_rfcomm_client_disconnected(info, client_info);
838 __remove_remote_client_info(client_info);
839 } while (info->conn_list);
842 if (info->server_fd) {
843 shutdown(info->server_fd, SHUT_RDWR);
844 close(info->server_fd);
848 g_source_remove(info->watch_id);
850 __rfcomm_delete_server_id(info->server_id);
856 static void __connected_cb(rfcomm_remote_client_info_t *client_info, bt_event_info_t *event_info)
858 bluetooth_rfcomm_connection_t conn_info;
859 rfcomm_server_info_t *server_info;
861 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
862 ret_if(server_info == NULL);
864 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
865 conn_info.device_role = RFCOMM_ROLE_SERVER;
866 g_strlcpy(conn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
867 conn_info.socket_fd = client_info->sock_fd;
868 _bt_convert_addr_string_to_type(conn_info.device_addr.addr, client_info->addr);
869 conn_info.server_id = server_info->server_id;
871 BT_INFO_C("Connected [RFCOMM Server]");
872 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
873 BLUETOOTH_ERROR_NONE, &conn_info,
874 event_info->cb, event_info->user_data);
877 static int __process_cmsg(struct msghdr *msg)
880 struct cmsghdr *cmsg_ptr = NULL;
882 for (cmsg_ptr = CMSG_FIRSTHDR(msg); cmsg_ptr != NULL;
883 cmsg_ptr = CMSG_NXTHDR(msg, cmsg_ptr)) {
885 if (cmsg_ptr->cmsg_level != SOL_SOCKET)
888 if (cmsg_ptr->cmsg_type == SCM_RIGHTS) {
889 //int *desc = (int *)CMSG_DATA(cmsg_ptr);
891 = ((cmsg_ptr->cmsg_len - CMSG_LEN(0)) / sizeof(int));
894 BT_ERR("ERROR Invalid count of descriptors");
899 memcpy(&sock_fd, CMSG_DATA(cmsg_ptr), sizeof(sock_fd));
900 BT_DBG("Remote client fd: %d", sock_fd);
907 static int __read_incomming_client_connection(
908 int server_fd, char *buf, unsigned int len, int *client_fd)
913 struct cmsghdr cmsgbuf[2 * sizeof(struct cmsghdr) + 4];
916 retv_if(0 > server_fd, -1);
917 retv_if(NULL == client_fd, -1);
919 BT_INFO("server_fd = %d", server_fd);
921 memset(&msg, 0, sizeof(msg));
922 memset(&iv, 0, sizeof(iv));
928 msg.msg_control = cmsgbuf;
929 msg.msg_controllen = sizeof(cmsgbuf);
931 for (retryCount = 0; retryCount < 5; retryCount++) {
932 ret = recvmsg(server_fd, &msg, 0);
933 BT_DBG("recvmsg ret = %d", ret);
934 if (ret < 0 && errno == EINTR)
940 if (ret < 0 && errno == EPIPE) {
941 /* End of stream, server listining stopped */
942 BT_ERR("EOS errno: %d", errno);
947 BT_ERR("Ret errno: %d", errno);
951 if ((msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) {
952 BT_ERR("MSG Flags errno: %d", errno);
956 BT_INFO("Connection received");
957 *client_fd = __process_cmsg(&msg);
959 BT_ERR("Invalid client_fd received");
964 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
969 int result = BLUETOOTH_ERROR_NONE;
970 bt_event_info_t *event_info;
971 bluetooth_rfcomm_received_data_t data_r;
972 GIOStatus status = G_IO_STATUS_NORMAL;
974 rfcomm_remote_client_info_t *client_info = data;
975 rfcomm_server_info_t *server_info;
977 retv_if(client_info == NULL, FALSE);
979 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
981 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
982 BT_ERR_C("RFComm Server disconnected: %d", client_info->sock_fd);
986 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
987 status = g_io_channel_read_chars(chan, buffer,
988 BT_RFCOMM_BUFFER_LEN, &len, &err);
989 if (status != G_IO_STATUS_NORMAL) {
990 BT_ERR("IO Channel read is failed with %d", status);
993 BT_ERR("IO Channel read error [%s]", err->message);
994 if (status == G_IO_STATUS_ERROR &&
995 !g_strcmp0(err->message, "Connection reset by peer")) {
996 BT_ERR("cond : %d", cond);
1006 BT_ERR("Length is zero, remote end hang up");
1010 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
1011 if (event_info == NULL) {
1016 data_r.socket_fd = client_info->sock_fd;
1017 data_r.buffer_size = len;
1018 data_r.buffer = buffer;
1020 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
1022 event_info->cb, event_info->user_data);
1029 BT_ERR("Failure occured, remove client connection");
1030 server_info->conn_list = g_slist_remove(
1031 server_info->conn_list, client_info);
1032 __handle_rfcomm_client_disconnected(server_info, client_info);
1033 __remove_remote_client_info(client_info);
1037 static gboolean __new_connection_request_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1044 char buf[BLUETOOTH_SOCK_CONNECT_INFO_LEN];
1045 unsigned char addr[BT_ADDRESS_LENGTH_MAX];
1047 bt_event_info_t *event_info;
1049 rfcomm_remote_client_info_t *rem_client;
1050 rfcomm_server_info_t *server_info = data;
1053 BT_ERR("Server info is invalid");
1057 if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
1058 BT_INFO("RFCOMM Server with fd:%d is closed with cond:0x%X",
1059 server_info->server_fd, cond);
1063 BT_INFO("Server fd: %d", server_info->server_fd);
1064 len = __read_incomming_client_connection(
1065 server_info->server_fd, buf, BLUETOOTH_SOCK_CONNECT_INFO_LEN, &client_fd);
1066 BT_DBG("Socket Read len: %d", len);
1068 BT_ERR("Listen stopped");
1070 } else if (len != BLUETOOTH_SOCK_CONNECT_INFO_LEN) {
1071 BT_ERR("Read length is not same as socket info length");
1076 /* Read size of data */
1077 size = buf[len] | (buf[len + 1] << 8);
1080 /* Read bluetooth address */
1081 memcpy(addr, buf + len, BT_ADDRESS_LENGTH_MAX);
1082 len += BT_ADDRESS_LENGTH_MAX;
1085 channel = buf[len] | (buf[len + 1] << 8) |
1086 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1090 status = buf[len] | (buf[len + 1] << 8) |
1091 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1094 BT_DBG("size: %d, channel: %d, status: %d", size, channel, status);
1096 rem_client = g_malloc0(sizeof(rfcomm_remote_client_info_t));
1097 rem_client->sock_fd = client_fd;
1098 rem_client->server_id = server_info->server_id;
1099 _bt_convert_addr_type_to_string(rem_client->addr, addr);
1101 BT_INFO("New client [%s] connection with socket_fd: %d, server_id: %d",
1102 rem_client->addr, rem_client->sock_fd, rem_client->server_id);
1104 io = g_io_channel_unix_new(rem_client->sock_fd);
1105 g_io_channel_set_encoding(io, NULL, NULL);
1106 g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
1107 rem_client->watch_id = g_io_add_watch(io,
1108 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1109 __data_received_cb, rem_client);
1110 g_io_channel_unref(io);
1112 server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
1113 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
1115 __connected_cb(rem_client, event_info);
1120 /* Error occurred, Remove RFCOMM server*/
1121 __remove_rfcomm_server(server_info);
1125 static int __rfcomm_listen(rfcomm_server_info_t *server_info, bool accept)
1128 GUnixFDList *out_fd_list = NULL;
1129 GIOChannel *server_io;
1131 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1134 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1136 if (accept == false) {
1137 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1138 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
1139 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1141 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1142 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN_AND_ACCEPT,
1143 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1146 BT_DBG("result: %x", result);
1147 if (result != BLUETOOTH_ERROR_NONE) {
1148 BT_ERR("Fail to send request");
1150 } else if (NULL == out_fd_list) {
1151 BT_ERR("out_fd_list is NULL");
1152 return BLUETOOTH_ERROR_INTERNAL;
1158 return BLUETOOTH_ERROR_INTERNAL;
1160 fd_list_array = g_unix_fd_list_steal_fds(out_fd_list, &len);
1161 BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
1162 server_info->server_fd = fd_list_array[0];
1163 BT_INFO("Socket fd: %d", server_info->server_fd);
1165 g_free(fd_list_array);
1166 g_object_unref(out_fd_list);
1169 server_io = g_io_channel_unix_new(server_info->server_fd);
1170 g_io_channel_set_encoding(server_io, NULL, NULL);
1171 g_io_channel_set_flags(server_io, G_IO_FLAG_NONBLOCK, NULL);
1172 server_info->watch_id = g_io_add_watch(server_io,
1173 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1174 __new_connection_request_cb, server_info);
1175 g_io_channel_unref(server_io);
1177 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1179 return BLUETOOTH_ERROR_NONE;
1183 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
1185 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1186 rfcomm_info_t *info;
1188 rfcomm_server_info_t *server_info;
1191 BT_CHECK_ENABLED(return);
1192 BT_CHECK_PARAMETER(uuid, return);
1193 BT_INFO("UUID Provided %s", uuid);
1195 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET)
1196 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1197 BT_ERR("Don't have a privilege to use this API");
1198 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1201 #ifdef TIZEN_FEATURE_BT_DPM
1202 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1203 BT_ERR("Not allow to use SPP profile");
1204 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1208 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1209 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1210 info = __register_method();
1214 info->uuid = g_strdup(uuid);
1215 info->disconnect_idle_id = 0;
1218 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1220 server_info = __get_rfcomm_server_info_with_uuid(uuid);
1222 server_info = g_malloc0(sizeof(rfcomm_server_info_t));
1223 g_strlcpy(server_info->uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1224 server_info->server_id = __rfcomm_assign_server_id();
1225 server_info->server_fd = -1;
1226 server_info->watch_id = -1;
1227 server_info->auto_accept = FALSE;
1228 rfcomm_servers = g_slist_append(rfcomm_servers, server_info);
1230 return server_info->server_id;
1234 BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char *bus_name, const char *path)
1236 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1237 rfcomm_info_t *info;
1239 BT_CHECK_ENABLED(return);
1240 BT_CHECK_PARAMETER(path, return);
1241 BT_INFO("PATH Provided %s", path);
1243 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET_EX)
1244 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1245 BT_ERR("Don't have a privilege to use this API");
1246 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1249 #ifdef TIZEN_FEATURE_BT_DPM
1250 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1251 BT_ERR("Not allow to use SPP profile");
1252 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1256 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1257 info = __register_method_2(path, bus_name);
1259 return BLUETOOTH_ERROR_IN_PROGRESS;
1260 info->uuid = g_strdup(uuid);
1261 info->disconnect_idle_id = 0;
1263 return BLUETOOTH_ERROR_NONE;
1265 return BLUETOOTH_ERROR_NOT_SUPPORT;
1270 BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
1272 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1273 rfcomm_info_t *info;
1275 rfcomm_server_info_t *server_info;
1278 BT_CHECK_ENABLED(return);
1280 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1281 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1282 BT_ERR("Don't have a privilege to use this API");
1283 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1287 BT_ERR("Invalid ID");
1288 return BLUETOOTH_ERROR_INVALID_PARAM;
1291 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1292 BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
1294 info = __find_rfcomm_info_with_id(id);
1296 return BLUETOOTH_ERROR_INVALID_PARAM;
1298 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1299 _bt_unregister_profile(info->path);
1301 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1302 free_rfcomm_info(info);
1304 return BLUETOOTH_ERROR_NONE;
1306 BT_INFO("<<<<<<<<< RFCOMM Remove socket request from app, fd=[%d] >>>>>>>>>>>", socket_fd);
1308 server_info = __get_rfcomm_server_info_with_id(id);
1310 BT_ERR("server_info not found for socket_fd: %d", id);
1311 return BLUETOOTH_ERROR_INVALID_PARAM;
1314 __remove_rfcomm_server(server_info);
1316 return BLUETOOTH_ERROR_NONE;
1320 BT_EXPORT_API int bluetooth_rfcomm_remove_socket_ex(const char *uuid)
1322 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1323 rfcomm_info_t *info;
1325 BT_CHECK_ENABLED(return);
1327 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1328 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1329 BT_ERR("Don't have a privilege to use this API");
1330 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1333 BT_INFO("RFCOMM Remove socket request from app, uuid=[%s]", uuid);
1335 info = __find_rfcomm_info_with_uuid(uuid);
1337 return BLUETOOTH_ERROR_INVALID_PARAM;
1339 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1340 _bt_unregister_profile(info->path);
1342 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1343 free_rfcomm_info(info);
1345 return BLUETOOTH_ERROR_NONE;
1347 return BLUETOOTH_ERROR_NOT_SUPPORT;
1351 BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
1353 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1354 rfcomm_info_t *info;
1355 rfcomm_conn_t *conn;
1359 BT_INFO(" ### Disconnect RFCOMM server");
1360 if (socket_fd < 0) {
1361 BT_ERR("Invalid FD");
1362 return BLUETOOTH_ERROR_INVALID_PARAM;
1365 info = __find_rfcomm_info_with_fd(socket_fd);
1367 return BLUETOOTH_ERROR_INVALID_PARAM;
1369 conn = __find_rfcomm_conn_with_fd(info, socket_fd);
1371 return BLUETOOTH_ERROR_INVALID_PARAM;
1373 if (conn->watch_id == 0 || conn->disconnected)
1374 return BLUETOOTH_ERROR_NOT_CONNECTED;
1377 conn->disconnected = TRUE;
1379 _bt_convert_addr_type_to_string(address, conn->addr.addr);
1381 BT_DBG("Address %s", address);
1382 _bt_disconnect_ext_profile(address, info->path);
1384 if (info->disconnect_idle_id == 0)
1385 info->disconnect_idle_id = g_idle_add(
1386 (GSourceFunc)__rfcomm_server_disconnect, info);
1389 return BLUETOOTH_ERROR_NONE;
1391 rfcomm_remote_client_info_t *client_info;
1393 BT_CHECK_ENABLED(return);
1395 BT_INFO(">>>>>>>>RFCOMM server disconnect request from APP>>>>>>>>>");
1396 if (socket_fd < 0) {
1397 BT_ERR("Invalid FD");
1398 return BLUETOOTH_ERROR_INVALID_PARAM;
1401 client_info = __get_rfcomm_rem_client_info_with_fd(socket_fd);
1403 BT_ERR("client_info not found for socket_fd: %d", socket_fd);
1404 return BLUETOOTH_ERROR_NOT_CONNECTED;
1407 if (client_info->sock_fd) {
1408 shutdown(client_info->sock_fd, SHUT_RDWR);
1409 close(client_info->sock_fd);
1410 client_info->sock_fd = -1;
1413 return BLUETOOTH_ERROR_NONE;
1417 BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uuid)
1420 gboolean available = TRUE;
1421 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
1423 retv_if(uuid == NULL, FALSE);
1424 retv_if(bluetooth_check_adapter() ==
1425 BLUETOOTH_ADAPTER_DISABLED, FALSE);
1428 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1430 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
1431 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
1433 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_IS_UUID_AVAILABLE,
1434 in_param1, in_param2, in_param3, in_param4, &out_param);
1436 BT_DBG("result: %x", result);
1438 if (result == BLUETOOTH_ERROR_NONE)
1439 available = g_array_index(out_param, gboolean, 0);
1441 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1443 BT_DBG("available: %d", available);
1448 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
1450 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1453 rfcomm_info_t *info;
1454 rfcomm_conn_t *conn;
1456 char input_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1457 rfcomm_remote_client_info_t *info;
1460 BT_CHECK_PARAMETER(device_address, return);
1461 BT_CHECK_PARAMETER(connected, return);
1465 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1466 for (l = rfcomm_nodes; l; l = l->next) {
1469 if (info == NULL || info->rfcomm_conns == NULL)
1472 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
1475 if (memcmp(device_address, &conn->addr,
1476 sizeof(bluetooth_device_address_t)))
1480 return BLUETOOTH_ERROR_NONE;
1484 return BLUETOOTH_ERROR_NONE;
1486 _bt_convert_addr_type_to_string(input_addr, (unsigned char *)device_address->addr);
1487 info = __get_rfcomm_rem_client_info_with_addr(input_addr);
1491 return BLUETOOTH_ERROR_NONE;
1495 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
1497 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1498 rfcomm_info_t *info;
1500 rfcomm_server_info_t *server_info;
1503 BT_CHECK_ENABLED(return);
1505 BT_ERR("Invalid ID");
1506 return BLUETOOTH_ERROR_INVALID_PARAM;
1509 #ifdef TIZEN_FEATURE_BT_DPM
1510 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1511 BT_ERR("Not allow to use SPP profile");
1512 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1516 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1517 BT_INFO("RFCOMM Listen & accept from app");
1519 info = __find_rfcomm_info_with_id(id);
1521 return BLUETOOTH_ERROR_INVALID_PARAM;
1523 bt_register_profile_info_t profile_info;
1526 profile_info.authentication = TRUE;
1527 profile_info.authorization = TRUE;
1528 profile_info.obj_path = info->path;
1529 profile_info.role = NULL;
1530 profile_info.service = info->uuid;
1531 profile_info.uuid = info->uuid;
1533 BT_INFO("uuid %s", profile_info.uuid);
1534 result = _bt_register_profile(&profile_info, TRUE);
1538 BT_INFO("<<<<<<<<< RFCOMM Listen & accept from app >>>>>>>>>>>");
1540 server_info = __get_rfcomm_server_info_with_id(id);
1542 BT_ERR("server_info not found for id: %d", id);
1543 return BLUETOOTH_ERROR_INVALID_PARAM;
1546 if (server_info->server_fd >= 0) {
1547 BT_ERR("server already listining");
1548 return BLUETOOTH_ERROR_DEVICE_BUSY;
1551 server_info->max_pending_conn = max_pending_connection;
1552 server_info->auto_accept = TRUE;
1554 return __rfcomm_listen(server_info, true);
1558 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
1559 int max_pending_connection,
1560 const char *bus_name, const char *path)
1562 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1563 rfcomm_info_t *info;
1565 BT_CHECK_ENABLED(return);
1567 #ifdef TIZEN_FEATURE_BT_DPM
1568 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1569 BT_ERR("Not allow to use SPP profile");
1570 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1574 BT_INFO("RFCOMM Listen & accept from app");
1576 info = __find_rfcomm_info_with_uuid(uuid);
1578 return BLUETOOTH_ERROR_INVALID_PARAM;
1580 bt_register_profile_info_t profile_info;
1583 profile_info.authentication = TRUE;
1584 profile_info.authorization = TRUE;
1585 profile_info.obj_path = info->path;
1586 profile_info.role = NULL;
1587 profile_info.service = info->uuid;
1588 profile_info.uuid = info->uuid;
1590 BT_INFO("uuid %s", profile_info.uuid);
1591 result = _bt_register_profile_ex(&profile_info, TRUE, bus_name, path);
1595 return BLUETOOTH_ERROR_NOT_SUPPORT;
1599 BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
1601 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1602 rfcomm_info_t *info;
1604 rfcomm_server_info_t *server_info;
1607 BT_CHECK_ENABLED(return);
1609 BT_ERR("Invalid ID");
1610 return BLUETOOTH_ERROR_INVALID_PARAM;
1613 #ifdef TIZEN_FEATURE_BT_DPM
1614 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1615 BT_ERR("Not allow to use SPP profile");
1616 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1620 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1621 BT_INFO("RFCOMM Listen");
1623 info = __find_rfcomm_info_with_id(id);
1625 return BLUETOOTH_ERROR_INVALID_PARAM;
1627 bt_register_profile_info_t profile_info;
1630 profile_info.authentication = TRUE;
1631 profile_info.authorization = TRUE;
1632 profile_info.obj_path = info->path;
1633 profile_info.role = NULL;
1634 profile_info.service = info->uuid;
1635 profile_info.uuid = info->uuid;
1636 BT_INFO("UUID %s", info->uuid);
1637 BT_INFO("PATH %s", info->path);
1638 result = _bt_register_profile_platform(&profile_info, TRUE);
1639 if (result != BLUETOOTH_ERROR_NONE)
1642 return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
1646 BT_INFO("<<<<<<<<< RFCOMM Listen >>>>>>>>>>>");
1648 server_info = __get_rfcomm_server_info_with_id(id);
1650 BT_ERR("server_info not found for id: %d", id);
1651 return BLUETOOTH_ERROR_INVALID_PARAM;
1654 if (server_info->server_fd >= 0) {
1655 BT_ERR("server already listining");
1656 return BLUETOOTH_ERROR_DEVICE_BUSY;
1659 server_info->max_pending_conn = max_pending_connection;
1660 server_info->auto_accept = FALSE;
1661 return __rfcomm_listen(server_info, false);
1665 BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd)
1668 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1670 rfcomm_server_info_t *server_info;
1673 BT_CHECK_ENABLED(return);
1675 #ifdef TIZEN_FEATURE_BT_DPM
1676 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1677 BT_ERR("Not allow to use SPP profile");
1678 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1682 if (server_fd < 0) {
1683 BT_ERR("Invalid FD");
1684 return BLUETOOTH_ERROR_INVALID_PARAM;
1688 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1690 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1691 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1693 server_info = __get_rfcomm_server_info_with_id(server_fd);
1695 BT_ERR("No server with fd: %d", server_fd);
1696 return BLUETOOTH_ERROR_INVALID_PARAM;
1699 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1702 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_ACCEPT_CONNECTION,
1703 in_param1, in_param2, in_param3, in_param4, &out_param);
1705 BT_DBG("result: %x", result);
1707 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1712 BT_EXPORT_API int bluetooth_rfcomm_reject_connection(int server_fd)
1715 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1717 rfcomm_server_info_t *server_info;
1720 BT_CHECK_ENABLED(return);
1722 if (server_fd < 0) {
1723 BT_ERR("Invalid FD");
1724 return BLUETOOTH_ERROR_INVALID_PARAM;
1730 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1732 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1733 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1735 server_info = __get_rfcomm_server_info_with_id(server_fd);
1737 BT_ERR("No server with fd: %d", server_fd);
1738 return BLUETOOTH_ERROR_INVALID_PARAM;
1741 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1743 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REJECT_CONNECTION,
1744 in_param1, in_param2, in_param3, in_param4, &out_param);
1746 BT_DBG("result: %x", result);
1748 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);