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"
33 #define BLUETOOTH_SOCK_CONNECT_INFO_LEN 16
34 #define BATTERY_MONITOR_RFCOMM_INTERVAL 5
36 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
38 static GSList *rfcomm_nodes;
41 bluetooth_device_address_t addr;
44 gboolean disconnected;
53 guint disconnect_idle_id;
56 static unsigned int rx_data = 0;
57 static guint rx_tag = 0;
59 static bool __rfcomm_record_rx_data(void)
62 int ret = _bt_common_send_rfcomm_rx_details(rx_data);
63 if (ret == BLUETOOTH_ERROR_NONE) {
67 BT_ERR("RFCOMM rx data could not be registered");
77 static rfcomm_info_t *__find_rfcomm_info_with_id(int id)
81 for (l = rfcomm_nodes; l != NULL; l = l->next) {
82 rfcomm_info_t *info = l->data;
91 static rfcomm_info_t *__find_rfcomm_info_with_fd(int fd)
96 for (l = rfcomm_nodes; l != NULL; l = l->next) {
97 rfcomm_info_t *info = l->data;
99 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
100 rfcomm_conn_t *conn = ll->data;
102 if (conn && conn->fd == fd)
110 static rfcomm_info_t *__find_rfcomm_info_with_path(const gchar *path)
114 for (l = rfcomm_nodes; l != NULL; l = l->next) {
115 rfcomm_info_t *info = l->data;
117 if (g_ascii_strcasecmp(info->path, path) == 0)
124 static rfcomm_info_t *__find_rfcomm_info_with_uuid(const char *uuid)
128 for (l = rfcomm_nodes; l != NULL; l = l->next) {
129 rfcomm_info_t *info = l->data;
131 if (g_ascii_strcasecmp(info->uuid, uuid) == 0)
138 static rfcomm_conn_t *__find_rfcomm_conn_with_fd(rfcomm_info_t *info,
144 for (l = info->rfcomm_conns; l; l = l->next) {
147 if (conn && conn->fd == fd)
154 static void __rfcomm_remove_conn(rfcomm_info_t *info, int fd)
158 conn = __find_rfcomm_conn_with_fd(info, fd);
162 info->rfcomm_conns = g_slist_remove(info->rfcomm_conns, conn);
164 if (conn->watch_id > 0)
165 g_source_remove(conn->watch_id);
169 gboolean _check_uuid_path(char *path, char *uuid)
171 rfcomm_info_t *info = NULL;
172 info = __find_rfcomm_info_with_path(path);
176 if (g_ascii_strcasecmp(info->uuid, uuid) == 0)
182 static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn,
183 bt_event_info_t *event_info)
185 bluetooth_rfcomm_connection_t conn_info;
187 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
189 conn_info.device_role = RFCOMM_ROLE_SERVER;
190 g_strlcpy(conn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
191 conn_info.socket_fd = conn->fd;
192 conn_info.device_addr = conn->addr;
193 conn_info.server_id = info->id;
195 BT_INFO_C("### Connected [RFCOMM Server]");
197 if (_bt_common_send_rfcomm_conn_info(RFCOMM_ROLE_SERVER,
198 TRUE, conn_info.socket_fd) != BLUETOOTH_ERROR_NONE)
199 BT_ERR("Fail to send the connection info");
201 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
202 BLUETOOTH_ERROR_NONE, &conn_info,
203 event_info->cb, event_info->user_data);
206 static void __rfcomm_server_disconnect_conn(rfcomm_conn_t *conn,
209 bluetooth_rfcomm_disconnection_t disconn_info;
210 bt_event_info_t *event_info;
215 if (conn->disconnected == FALSE)
218 if (conn->watch_id > 0) {
219 g_source_remove(conn->watch_id);
223 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
224 if (event_info == NULL) {
225 BT_ERR("event_info is NULL");
226 __rfcomm_remove_conn(info, conn->fd);
230 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
231 disconn_info.device_role = RFCOMM_ROLE_SERVER;
232 g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
233 disconn_info.device_addr = conn->addr;
235 BT_INFO("Disconnected FD [%d]", conn->fd);
236 disconn_info.socket_fd = conn->fd;
238 if (_bt_common_send_rfcomm_conn_info(RFCOMM_ROLE_SERVER,
239 FALSE, disconn_info.socket_fd) != BLUETOOTH_ERROR_NONE)
240 BT_ERR("Fail to send the connection info");
242 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
243 BLUETOOTH_ERROR_NONE, &disconn_info,
244 event_info->cb, event_info->user_data);
246 __rfcomm_remove_conn(info, conn->fd);
249 static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
251 BT_INFO_C("### Disconnected [RFCOMM Server]");
253 if (g_slist_find(rfcomm_nodes, info) == NULL) {
254 BT_INFO("rfcomm resource is already freed");
258 info->disconnect_idle_id = 0;
260 g_slist_foreach(info->rfcomm_conns,
261 (GFunc)__rfcomm_server_disconnect_conn, info);
267 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
272 int result = BLUETOOTH_ERROR_NONE;
273 rfcomm_info_t *info = data;
275 bt_event_info_t *event_info;
276 bluetooth_rfcomm_received_data_t data_r;
277 GIOStatus status = G_IO_STATUS_NORMAL;
281 retv_if(info == NULL, FALSE);
283 fd = g_io_channel_unix_get_fd(chan);
284 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
285 BT_ERR_C("RFComm Server disconnected: %d", fd);
287 if (info->disconnect_idle_id > 0) {
288 BT_INFO("Disconnect idle still not process remove source");
289 g_source_remove(info->disconnect_idle_id);
290 info->disconnect_idle_id = 0;
293 conn = __find_rfcomm_conn_with_fd(info, fd);
295 BT_ERR("No Connection info found with FD [%d]", fd);
299 if (conn->disconnected == FALSE) {
301 conn->disconnected = TRUE;
303 __rfcomm_server_disconnect(info);
307 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
308 status = g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
310 if (status != G_IO_STATUS_NORMAL) {
311 BT_ERR("IO Channel read is failed with %d(%s)", status, _bt_print_gio_status(status));
314 if (status == G_IO_STATUS_AGAIN)
318 BT_ERR("IO Channel read error [%s]", err->message);
322 if (info->disconnect_idle_id > 0) {
323 BT_INFO("Disconnect idle still not process remove source");
324 g_source_remove(info->disconnect_idle_id);
325 info->disconnect_idle_id = 0;
328 conn = __find_rfcomm_conn_with_fd(info, fd);
330 BT_ERR("No Connection info found with FD [%d]", fd);
334 if (conn->disconnected == FALSE) {
336 conn->disconnected = TRUE;
338 __rfcomm_server_disconnect(info);
343 BT_ERR("Length is zero");
345 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
346 if (event_info == NULL) {
347 BT_ERR("event_info is NULL. Unable to invoke the callback");
352 data_r.socket_fd = fd;
353 data_r.buffer_size = len;
354 data_r.buffer = buffer;
356 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
358 event_info->cb, event_info->user_data);
360 if (bluetooth_get_battery_monitor_state()) {
362 BT_DBG("Adding rfcomm rx timeout function for battery monitor");
363 rx_tag = g_timeout_add_seconds(BATTERY_MONITOR_RFCOMM_INTERVAL, (GSourceFunc)__rfcomm_record_rx_data, NULL);
373 int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
378 bt_event_info_t *event_info;
380 BT_INFO("%s %d", path, fd);
382 info = __find_rfcomm_info_with_path(path);
384 BT_ERR("rfcomm info is NULL");
388 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
391 BT_ERR("Not allow to use SPP profile");
394 _bt_convert_addr_type_to_string(addr_str, addr->addr);
395 _bt_disconnect_ext_profile(addr_str, info->path);
400 conn = g_new0(rfcomm_conn_t, 1);
402 memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
403 info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
405 data_io = g_io_channel_unix_new(conn->fd);
407 g_io_channel_set_encoding(data_io, NULL, NULL);
408 g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
410 conn->watch_id = g_io_add_watch(data_io,
411 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
412 __data_received_cb, info);
414 g_io_channel_unref(data_io);
416 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
418 __connected_cb(info, conn, event_info);
423 static rfcomm_info_t *__register_method()
430 id = __rfcomm_assign_id();
434 path = g_strdup_printf("/org/socket/server/%d/%d", getpid(), id);
436 object_id = _bt_register_new_conn(path, new_server_connection);
438 __rfcomm_delete_id(id);
442 info = g_new0(rfcomm_info_t, 1);
443 info->object_id = (guint)object_id;
447 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
452 static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
457 object_id = _bt_register_new_conn_ex(path, bus_name, new_server_connection);
461 info = g_new0(rfcomm_info_t, 1);
462 info->object_id = (guint)object_id;
463 info->path = g_strdup(path);
466 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
471 void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
473 if (conn->disconnected == FALSE) {
475 conn->disconnected = TRUE;
477 __rfcomm_server_disconnect_conn(conn, info);
480 void free_rfcomm_info(rfcomm_info_t *info)
484 if (info->disconnect_idle_id > 0) {
485 BT_INFO("Disconnect idle still not process remove source");
486 g_source_remove(info->disconnect_idle_id);
487 info->disconnect_idle_id = 0;
490 __rfcomm_delete_id(info->id);
491 _bt_unregister_gdbus(info->object_id);
493 g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
500 void _bt_rfcomm_server_free_all(void)
502 BT_DBG("Free all the servers");
504 g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
508 void _bt_rfcomm_server_disconnect_all(void)
514 BT_INFO(" ### Disconnect all RFCOMM server connections");
516 for (server = rfcomm_nodes; server; ) {
517 rfcomm_info_t *info = server->data;
519 for (conn = info->rfcomm_conns; conn; conn = conn->next) {
520 rfcomm_conn_t *conn_info = conn->data;
522 if (conn_info == NULL)
525 if (conn_info->watch_id == 0 || conn_info->disconnected)
528 close(conn_info->fd);
529 conn_info->disconnected = TRUE;
531 _bt_convert_addr_type_to_string(addr,
532 conn_info->addr.addr);
533 _bt_disconnect_ext_profile(addr, info->path);
536 server = server->next;
537 __rfcomm_server_disconnect(info);
543 void _bt_rfcomm_server_reset_timer(void)
546 g_source_remove(rx_tag);
554 #define BT_RFCOMM_SERVER_ID_MAX 254
557 char addr[BT_ADDRESS_STRING_SIZE];
561 } rfcomm_remote_client_info_t;
564 char uuid[BLUETOOTH_UUID_STRING_MAX];
568 int max_pending_conn;
569 gboolean auto_accept;
570 char pending_addr[BT_ADDRESS_STRING_SIZE];
572 } rfcomm_server_info_t;
574 static GSList *rfcomm_servers;
575 static gboolean id_used[BT_RFCOMM_SERVER_ID_MAX];
578 int __rfcomm_assign_server_id(void)
582 BT_DBG("latest_id: %d", latest_id);
584 index = latest_id + 1;
586 if (index >= BT_RFCOMM_SERVER_ID_MAX)
589 BT_DBG("index: %d", index);
591 while (id_used[index] == TRUE) {
592 if (index == latest_id) {
593 /* No available ID */
594 BT_ERR("All request ID is used");
600 if (index >= BT_RFCOMM_SERVER_ID_MAX)
605 id_used[index] = TRUE;
607 BT_DBG("Assigned Id: %d", latest_id);
612 void __rfcomm_delete_server_id(int id)
614 ret_if(id >= BT_RFCOMM_SERVER_ID_MAX);
619 /* Next server will use this ID */
623 static rfcomm_server_info_t *__get_rfcomm_server_info_with_uuid(const char *uuid)
630 for (l = rfcomm_servers; l != NULL; l = l->next) {
631 rfcomm_server_info_t *info = l->data;
633 if (!strncasecmp(info->uuid, uuid, strlen(info->uuid)))
640 int _get_rfcomm_server_id(char *uuid, gboolean *auto_accept)
642 rfcomm_server_info_t *server_info;
644 server_info = __get_rfcomm_server_info_with_uuid(uuid);
648 *auto_accept = server_info->auto_accept;
649 return server_info->server_id;
652 static rfcomm_server_info_t *__get_rfcomm_server_info_with_id(int server_id)
656 for (l = rfcomm_servers; l != NULL; l = l->next) {
657 rfcomm_server_info_t *info = l->data;
661 BT_DBG("info->server_fd: %d, sock_fd:%d", info->server_id, server_id);
662 if (info->server_id == server_id)
669 void _bt_rfcomm_server_set_pending_conn(int server_id, char *address)
671 rfcomm_server_info_t *server_info;
677 server_info = __get_rfcomm_server_info_with_id(server_id);
681 g_strlcpy(server_info->pending_addr, address, BT_ADDRESS_STRING_SIZE);
684 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_fd(int sock_fd)
689 for (l = rfcomm_servers; l != NULL; l = l->next) {
690 rfcomm_server_info_t *info = l->data;
695 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
696 rfcomm_remote_client_info_t *client_info = l1->data;
700 if (client_info->sock_fd == sock_fd)
708 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_addr(char *addr)
713 retv_if(NULL == addr, NULL);
715 for (l = rfcomm_servers; l != NULL; l = l->next) {
716 rfcomm_server_info_t *info = l->data;
721 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
722 rfcomm_remote_client_info_t *client_info = l1->data;
726 if (!strncasecmp(client_info->addr, addr, strlen(client_info->addr)))
734 static void __remove_remote_client_info(rfcomm_remote_client_info_t *rem_client)
738 if (rem_client == NULL)
741 if (0 < rem_client->sock_fd) {
742 shutdown(rem_client->sock_fd, SHUT_RDWR);
743 close(rem_client->sock_fd);
746 if (rem_client->watch_id > 0)
747 g_source_remove(rem_client->watch_id);
754 static void __handle_rfcomm_client_disconnected(rfcomm_server_info_t *server_info,
755 rfcomm_remote_client_info_t *rem_client)
757 bluetooth_rfcomm_disconnection_t disconn_info;
758 bt_event_info_t *event_info;
762 if (rem_client == NULL || server_info == NULL)
765 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
766 if (event_info == NULL)
769 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
770 disconn_info.device_role = RFCOMM_ROLE_SERVER;
771 g_strlcpy(disconn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
772 _bt_convert_addr_string_to_type(disconn_info.device_addr.addr, rem_client->addr);
773 BT_DBG("Disconnected FD [%d]", rem_client->sock_fd);
774 disconn_info.socket_fd = rem_client->sock_fd;
776 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
777 BLUETOOTH_ERROR_NONE, &disconn_info,
778 event_info->cb, event_info->user_data);
781 static void __remove_rfcomm_server(rfcomm_server_info_t *info)
783 rfcomm_remote_client_info_t *client_info;
790 rfcomm_servers = g_slist_remove(rfcomm_servers, info);
791 if (info->conn_list) {
793 client_info = info->conn_list->data;
797 info->conn_list = g_slist_remove(info->conn_list, client_info);
798 __handle_rfcomm_client_disconnected(info, client_info);
799 __remove_remote_client_info(client_info);
800 } while (info->conn_list);
803 if (info->server_fd) {
804 shutdown(info->server_fd, SHUT_RDWR);
805 close(info->server_fd);
809 g_source_remove(info->watch_id);
811 __rfcomm_delete_server_id(info->server_id);
817 static void __connected_cb(rfcomm_remote_client_info_t *client_info, bt_event_info_t *event_info)
819 bluetooth_rfcomm_connection_t conn_info;
820 rfcomm_server_info_t *server_info;
822 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
823 ret_if(server_info == NULL);
825 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
826 conn_info.device_role = RFCOMM_ROLE_SERVER;
827 g_strlcpy(conn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
828 conn_info.socket_fd = client_info->sock_fd;
829 _bt_convert_addr_string_to_type(conn_info.device_addr.addr, client_info->addr);
830 conn_info.server_id = server_info->server_id;
832 BT_INFO_C("Connected [RFCOMM Server]");
833 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
834 BLUETOOTH_ERROR_NONE, &conn_info,
835 event_info->cb, event_info->user_data);
838 static int __process_cmsg(struct msghdr *msg)
841 struct cmsghdr *cmsg_ptr = NULL;
843 for (cmsg_ptr = CMSG_FIRSTHDR(msg); cmsg_ptr != NULL;
844 cmsg_ptr = CMSG_NXTHDR(msg, cmsg_ptr)) {
846 if (cmsg_ptr->cmsg_level != SOL_SOCKET)
849 if (cmsg_ptr->cmsg_type == SCM_RIGHTS) {
850 //int *desc = (int *)CMSG_DATA(cmsg_ptr);
852 = ((cmsg_ptr->cmsg_len - CMSG_LEN(0)) / sizeof(int));
855 BT_ERR("ERROR Invalid count of descriptors");
860 memcpy(&sock_fd, CMSG_DATA(cmsg_ptr), sizeof(sock_fd));
861 BT_DBG("Remote client fd: %d", sock_fd);
868 static int __read_incomming_client_connection(
869 int server_fd, char *buf, unsigned int len, int *client_fd)
874 struct cmsghdr cmsgbuf[2 * sizeof(struct cmsghdr) + 4];
877 retv_if(0 > server_fd, -1);
878 retv_if(NULL == client_fd, -1);
880 BT_INFO("server_fd = %d", server_fd);
882 memset(&msg, 0, sizeof(msg));
883 memset(&iv, 0, sizeof(iv));
889 msg.msg_control = cmsgbuf;
890 msg.msg_controllen = sizeof(cmsgbuf);
892 for (retryCount = 0; retryCount < 5; retryCount++) {
893 ret = recvmsg(server_fd, &msg, 0);
894 BT_DBG("recvmsg ret = %d", ret);
895 if (ret < 0 && errno == EINTR)
901 if (ret < 0 && errno == EPIPE) {
902 /* End of stream, server listining stopped */
903 BT_ERR("EOS errno: %d", errno);
908 BT_ERR("Ret errno: %d", errno);
912 if ((msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) {
913 BT_ERR("MSG Flags errno: %d", errno);
917 BT_INFO("Connection received");
918 *client_fd = __process_cmsg(&msg);
920 BT_ERR("Invalid client_fd received");
925 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
930 int result = BLUETOOTH_ERROR_NONE;
931 bt_event_info_t *event_info;
932 bluetooth_rfcomm_received_data_t data_r;
933 GIOStatus status = G_IO_STATUS_NORMAL;
935 rfcomm_remote_client_info_t *client_info = data;
936 rfcomm_server_info_t *server_info;
938 retv_if(client_info == NULL, FALSE);
940 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
942 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
943 BT_ERR_C("RFComm Server disconnected: %d", client_info->sock_fd);
947 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
948 status = g_io_channel_read_chars(chan, buffer,
949 BT_RFCOMM_BUFFER_LEN, &len, &err);
950 if (status != G_IO_STATUS_NORMAL) {
951 BT_ERR("IO Channel read is failed with %d(%s)", status, _bt_print_gio_status(status));
954 if (status == G_IO_STATUS_AGAIN)
958 BT_ERR("IO Channel read error [%s]", err->message);
965 BT_ERR("Length is zero, remote end hang up");
969 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
970 if (event_info == NULL) {
975 data_r.socket_fd = client_info->sock_fd;
976 data_r.buffer_size = len;
977 data_r.buffer = buffer;
979 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
981 event_info->cb, event_info->user_data);
988 BT_ERR("Failure occured, remove client connection");
989 server_info->conn_list = g_slist_remove(
990 server_info->conn_list, client_info);
991 __handle_rfcomm_client_disconnected(server_info, client_info);
992 __remove_remote_client_info(client_info);
996 static gboolean __new_connection_request_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1003 char buf[BLUETOOTH_SOCK_CONNECT_INFO_LEN];
1004 unsigned char addr[BT_ADDRESS_LENGTH_MAX];
1006 bt_event_info_t *event_info;
1008 rfcomm_remote_client_info_t *rem_client;
1009 rfcomm_server_info_t *server_info = data;
1012 BT_ERR("Server info is invalid");
1016 if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
1017 BT_INFO("RFCOMM Server with fd:%d is closed with cond:0x%X",
1018 server_info->server_fd, cond);
1022 BT_INFO("Server fd: %d", server_info->server_fd);
1023 len = __read_incomming_client_connection(
1024 server_info->server_fd, buf, BLUETOOTH_SOCK_CONNECT_INFO_LEN, &client_fd);
1025 BT_DBG("Socket Read len: %d", len);
1027 BT_ERR("Listen stopped");
1029 } else if (len != BLUETOOTH_SOCK_CONNECT_INFO_LEN) {
1030 BT_ERR("Read length is not same as socket info length");
1035 /* Read size of data */
1036 size = buf[len] | (buf[len + 1] << 8);
1039 /* Read bluetooth address */
1040 memcpy(addr, buf + len, BT_ADDRESS_LENGTH_MAX);
1041 len += BT_ADDRESS_LENGTH_MAX;
1044 channel = buf[len] | (buf[len + 1] << 8) |
1045 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1049 status = buf[len] | (buf[len + 1] << 8) |
1050 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1053 BT_DBG("size: %d, channel: %d, status: %d", size, channel, status);
1055 rem_client = g_malloc0(sizeof(rfcomm_remote_client_info_t));
1056 rem_client->sock_fd = client_fd;
1057 rem_client->server_id = server_info->server_id;
1058 _bt_convert_addr_type_to_string(rem_client->addr, addr);
1060 BT_INFO("New client [%s] connection with socket_fd: %d, server_id: %d",
1061 rem_client->addr, rem_client->sock_fd, rem_client->server_id);
1063 io = g_io_channel_unix_new(rem_client->sock_fd);
1064 g_io_channel_set_encoding(io, NULL, NULL);
1065 g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
1066 rem_client->watch_id = g_io_add_watch(io,
1067 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1068 __data_received_cb, rem_client);
1069 g_io_channel_unref(io);
1071 server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
1072 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
1074 __connected_cb(rem_client, event_info);
1079 /* Error occurred, Remove RFCOMM server*/
1080 __remove_rfcomm_server(server_info);
1084 static int __rfcomm_listen(rfcomm_server_info_t *server_info, bool accept)
1087 GUnixFDList *out_fd_list = NULL;
1088 GIOChannel *server_io;
1090 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1093 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1095 if (accept == false) {
1096 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1097 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
1098 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1100 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1101 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN_AND_ACCEPT,
1102 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1105 BT_DBG("result: %x", result);
1106 if (result != BLUETOOTH_ERROR_NONE) {
1107 BT_ERR("Fail to send request");
1109 } else if (NULL == out_fd_list) {
1110 BT_ERR("out_fd_list is NULL");
1111 return BLUETOOTH_ERROR_INTERNAL;
1117 return BLUETOOTH_ERROR_INTERNAL;
1119 fd_list_array = g_unix_fd_list_steal_fds(out_fd_list, &len);
1120 BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
1121 server_info->server_fd = fd_list_array[0];
1122 BT_INFO("Socket fd: %d", server_info->server_fd);
1124 g_free(fd_list_array);
1125 g_object_unref(out_fd_list);
1128 server_io = g_io_channel_unix_new(server_info->server_fd);
1129 g_io_channel_set_encoding(server_io, NULL, NULL);
1130 g_io_channel_set_flags(server_io, G_IO_FLAG_NONBLOCK, NULL);
1131 server_info->watch_id = g_io_add_watch(server_io,
1132 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1133 __new_connection_request_cb, server_info);
1134 g_io_channel_unref(server_io);
1136 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1138 return BLUETOOTH_ERROR_NONE;
1142 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
1144 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1145 rfcomm_info_t *info;
1147 rfcomm_server_info_t *server_info;
1150 BT_CHECK_ENABLED(return);
1151 BT_CHECK_PARAMETER(uuid, return);
1152 BT_INFO("UUID Provided %s", uuid);
1154 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET)
1155 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1156 BT_ERR("Don't have a privilege to use this API");
1157 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1160 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1161 BT_ERR("Not allow to use SPP profile");
1162 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1165 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1166 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1167 info = __register_method();
1171 info->uuid = g_strdup(uuid);
1172 info->disconnect_idle_id = 0;
1175 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1177 server_info = __get_rfcomm_server_info_with_uuid(uuid);
1179 server_info = g_malloc0(sizeof(rfcomm_server_info_t));
1180 g_strlcpy(server_info->uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1181 server_info->server_id = __rfcomm_assign_server_id();
1182 server_info->server_fd = -1;
1183 server_info->watch_id = -1;
1184 server_info->auto_accept = FALSE;
1185 rfcomm_servers = g_slist_append(rfcomm_servers, server_info);
1187 return server_info->server_id;
1191 BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char *bus_name, const char *path)
1193 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1194 rfcomm_info_t *info;
1196 BT_CHECK_ENABLED(return);
1197 BT_CHECK_PARAMETER(path, return);
1198 BT_INFO("PATH Provided %s", path);
1200 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET_EX)
1201 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1202 BT_ERR("Don't have a privilege to use this API");
1203 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1206 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1207 BT_ERR("Not allow to use SPP profile");
1208 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1211 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1212 info = __register_method_2(path, bus_name);
1214 return BLUETOOTH_ERROR_IN_PROGRESS;
1215 info->uuid = g_strdup(uuid);
1216 info->disconnect_idle_id = 0;
1218 return BLUETOOTH_ERROR_NONE;
1220 return BLUETOOTH_ERROR_NOT_SUPPORT;
1225 BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
1227 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1228 rfcomm_info_t *info;
1230 rfcomm_server_info_t *server_info;
1233 BT_CHECK_ENABLED(return);
1235 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1236 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1237 BT_ERR("Don't have a privilege to use this API");
1238 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1242 BT_ERR("Invalid ID");
1243 return BLUETOOTH_ERROR_INVALID_PARAM;
1246 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1247 BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
1249 info = __find_rfcomm_info_with_id(id);
1251 return BLUETOOTH_ERROR_INVALID_PARAM;
1253 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1254 _bt_unregister_profile(info->path);
1256 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1257 free_rfcomm_info(info);
1259 return BLUETOOTH_ERROR_NONE;
1261 BT_INFO("<<<<<<<<< RFCOMM Remove socket request from app, fd=[%d] >>>>>>>>>>>", socket_fd);
1263 server_info = __get_rfcomm_server_info_with_id(id);
1265 BT_ERR("server_info not found for socket_fd: %d", id);
1266 return BLUETOOTH_ERROR_INVALID_PARAM;
1269 __remove_rfcomm_server(server_info);
1271 return BLUETOOTH_ERROR_NONE;
1275 BT_EXPORT_API int bluetooth_rfcomm_remove_socket_ex(const char *uuid)
1277 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1278 rfcomm_info_t *info;
1280 BT_CHECK_ENABLED(return);
1282 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1283 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1284 BT_ERR("Don't have a privilege to use this API");
1285 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1288 BT_INFO("RFCOMM Remove socket request from app, uuid=[%s]", uuid);
1290 info = __find_rfcomm_info_with_uuid(uuid);
1292 return BLUETOOTH_ERROR_INVALID_PARAM;
1294 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1295 _bt_unregister_profile(info->path);
1297 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1298 free_rfcomm_info(info);
1300 return BLUETOOTH_ERROR_NONE;
1302 return BLUETOOTH_ERROR_NOT_SUPPORT;
1306 BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
1308 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1309 rfcomm_info_t *info;
1310 rfcomm_conn_t *conn;
1314 BT_INFO(" ### Disconnect RFCOMM server");
1315 if (socket_fd < 0) {
1316 BT_ERR("Invalid FD");
1317 return BLUETOOTH_ERROR_INVALID_PARAM;
1320 info = __find_rfcomm_info_with_fd(socket_fd);
1322 return BLUETOOTH_ERROR_INVALID_PARAM;
1324 conn = __find_rfcomm_conn_with_fd(info, socket_fd);
1326 return BLUETOOTH_ERROR_INVALID_PARAM;
1328 if (conn->watch_id == 0 || conn->disconnected)
1329 return BLUETOOTH_ERROR_NOT_CONNECTED;
1332 conn->disconnected = TRUE;
1334 _bt_convert_addr_type_to_string(address, conn->addr.addr);
1336 BT_DBG("Address %s", address);
1337 _bt_disconnect_ext_profile(address, info->path);
1339 if (info->disconnect_idle_id == 0)
1340 info->disconnect_idle_id = g_idle_add(
1341 (GSourceFunc)__rfcomm_server_disconnect, info);
1344 return BLUETOOTH_ERROR_NONE;
1346 rfcomm_remote_client_info_t *client_info;
1348 BT_CHECK_ENABLED(return);
1350 BT_INFO(">>>>>>>>RFCOMM server disconnect request from APP>>>>>>>>>");
1351 if (socket_fd < 0) {
1352 BT_ERR("Invalid FD");
1353 return BLUETOOTH_ERROR_INVALID_PARAM;
1356 client_info = __get_rfcomm_rem_client_info_with_fd(socket_fd);
1358 BT_ERR("client_info not found for socket_fd: %d", socket_fd);
1359 return BLUETOOTH_ERROR_NOT_CONNECTED;
1362 if (client_info->sock_fd) {
1363 shutdown(client_info->sock_fd, SHUT_RDWR);
1364 close(client_info->sock_fd);
1365 client_info->sock_fd = -1;
1368 return BLUETOOTH_ERROR_NONE;
1372 BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uuid)
1375 gboolean available = TRUE;
1376 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
1378 retv_if(uuid == NULL, FALSE);
1379 retv_if(bluetooth_check_adapter() ==
1380 BLUETOOTH_ADAPTER_DISABLED, FALSE);
1383 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1385 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
1386 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
1388 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_IS_UUID_AVAILABLE,
1389 in_param1, in_param2, in_param3, in_param4, &out_param);
1391 BT_DBG("result: %x", result);
1393 if (result == BLUETOOTH_ERROR_NONE)
1394 available = g_array_index(out_param, gboolean, 0);
1396 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1398 BT_DBG("available: %d", available);
1403 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
1405 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1408 rfcomm_info_t *info;
1409 rfcomm_conn_t *conn;
1411 char input_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1412 rfcomm_remote_client_info_t *info;
1415 BT_CHECK_PARAMETER(device_address, return);
1416 BT_CHECK_PARAMETER(connected, return);
1420 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1421 for (l = rfcomm_nodes; l; l = l->next) {
1424 if (info == NULL || info->rfcomm_conns == NULL)
1427 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
1430 if (memcmp(device_address, &conn->addr,
1431 sizeof(bluetooth_device_address_t)))
1435 return BLUETOOTH_ERROR_NONE;
1439 return BLUETOOTH_ERROR_NONE;
1441 _bt_convert_addr_type_to_string(input_addr, (unsigned char *)device_address->addr);
1442 info = __get_rfcomm_rem_client_info_with_addr(input_addr);
1446 return BLUETOOTH_ERROR_NONE;
1450 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
1452 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1453 rfcomm_info_t *info;
1455 rfcomm_server_info_t *server_info;
1458 BT_CHECK_ENABLED(return);
1460 BT_ERR("Invalid ID");
1461 return BLUETOOTH_ERROR_INVALID_PARAM;
1464 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1465 BT_ERR("Not allow to use SPP profile");
1466 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1469 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1470 BT_INFO("RFCOMM Listen & accept from app");
1472 #ifdef TIZEN_FEATURE_BT_CONTAINER
1473 if (access(CONTAINER_FILE, F_OK) == 0) {
1474 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_LISTEN_AND_ACCEPT)
1475 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1476 BT_ERR("Don't have a privilege to use this API");
1477 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1482 info = __find_rfcomm_info_with_id(id);
1484 return BLUETOOTH_ERROR_INVALID_PARAM;
1486 bt_register_profile_info_t profile_info;
1489 profile_info.authentication = TRUE;
1490 profile_info.authorization = TRUE;
1491 profile_info.obj_path = info->path;
1492 profile_info.role = NULL;
1493 profile_info.service = info->uuid;
1494 profile_info.uuid = info->uuid;
1496 BT_INFO("uuid %s", profile_info.uuid);
1497 result = _bt_register_profile(&profile_info, TRUE);
1501 BT_INFO("<<<<<<<<< RFCOMM Listen & accept from app >>>>>>>>>>>");
1503 server_info = __get_rfcomm_server_info_with_id(id);
1505 BT_ERR("server_info not found for id: %d", id);
1506 return BLUETOOTH_ERROR_INVALID_PARAM;
1509 if (server_info->server_fd >= 0) {
1510 BT_ERR("server already listining");
1511 return BLUETOOTH_ERROR_DEVICE_BUSY;
1514 server_info->max_pending_conn = max_pending_connection;
1515 server_info->auto_accept = TRUE;
1517 return __rfcomm_listen(server_info, true);
1521 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
1522 int max_pending_connection,
1523 const char *bus_name, const char *path)
1525 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1526 rfcomm_info_t *info;
1528 BT_CHECK_ENABLED(return);
1530 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1531 BT_ERR("Not allow to use SPP profile");
1532 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1535 BT_INFO("RFCOMM Listen & accept from app");
1537 #ifdef TIZEN_FEATURE_BT_CONTAINER
1538 if (access(CONTAINER_FILE, F_OK) == 0) {
1539 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_LISTEN)
1540 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1541 BT_ERR("Don't have a privilege to use this API");
1542 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1547 info = __find_rfcomm_info_with_uuid(uuid);
1549 return BLUETOOTH_ERROR_INVALID_PARAM;
1551 bt_register_profile_info_t profile_info;
1554 profile_info.authentication = TRUE;
1555 profile_info.authorization = TRUE;
1556 profile_info.obj_path = info->path;
1557 profile_info.role = NULL;
1558 profile_info.service = info->uuid;
1559 profile_info.uuid = info->uuid;
1561 BT_INFO("uuid %s", profile_info.uuid);
1562 result = _bt_register_profile_ex(&profile_info, TRUE, bus_name, path);
1566 return BLUETOOTH_ERROR_NOT_SUPPORT;
1570 BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
1572 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1573 rfcomm_info_t *info;
1575 rfcomm_server_info_t *server_info;
1578 BT_CHECK_ENABLED(return);
1580 BT_ERR("Invalid ID");
1581 return BLUETOOTH_ERROR_INVALID_PARAM;
1584 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1585 BT_ERR("Not allow to use SPP profile");
1586 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1589 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1590 BT_INFO("RFCOMM Listen");
1592 #ifdef TIZEN_FEATURE_BT_CONTAINER
1593 if (access(CONTAINER_FILE, F_OK) == 0) {
1594 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_LISTEN)
1595 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1596 BT_ERR("Don't have a privilege to use this API");
1597 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1602 info = __find_rfcomm_info_with_id(id);
1604 return BLUETOOTH_ERROR_INVALID_PARAM;
1606 bt_register_profile_info_t profile_info;
1609 profile_info.authentication = TRUE;
1610 profile_info.authorization = TRUE;
1611 profile_info.obj_path = info->path;
1612 profile_info.role = NULL;
1613 profile_info.service = info->uuid;
1614 profile_info.uuid = info->uuid;
1615 BT_INFO("UUID %s", info->uuid);
1616 BT_INFO("PATH %s", info->path);
1617 result = _bt_register_profile_platform(&profile_info, TRUE);
1618 if (result != BLUETOOTH_ERROR_NONE)
1621 return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
1625 BT_INFO("<<<<<<<<< RFCOMM Listen >>>>>>>>>>>");
1627 server_info = __get_rfcomm_server_info_with_id(id);
1629 BT_ERR("server_info not found for id: %d", id);
1630 return BLUETOOTH_ERROR_INVALID_PARAM;
1633 if (server_info->server_fd >= 0) {
1634 BT_ERR("server already listining");
1635 return BLUETOOTH_ERROR_DEVICE_BUSY;
1638 server_info->max_pending_conn = max_pending_connection;
1639 server_info->auto_accept = FALSE;
1640 return __rfcomm_listen(server_info, false);
1644 BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd)
1647 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1649 rfcomm_server_info_t *server_info;
1652 BT_CHECK_ENABLED(return);
1654 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1655 BT_ERR("Not allow to use SPP profile");
1656 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1659 if (server_fd < 0) {
1660 BT_ERR("Invalid FD");
1661 return BLUETOOTH_ERROR_INVALID_PARAM;
1665 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1667 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1668 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1670 server_info = __get_rfcomm_server_info_with_id(server_fd);
1672 BT_ERR("No server with fd: %d", server_fd);
1673 return BLUETOOTH_ERROR_INVALID_PARAM;
1676 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1679 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_ACCEPT_CONNECTION,
1680 in_param1, in_param2, in_param3, in_param4, &out_param);
1682 BT_DBG("result: %x", result);
1684 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1689 BT_EXPORT_API int bluetooth_rfcomm_reject_connection(int server_fd)
1692 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1694 rfcomm_server_info_t *server_info;
1697 BT_CHECK_ENABLED(return);
1699 if (server_fd < 0) {
1700 BT_ERR("Invalid FD");
1701 return BLUETOOTH_ERROR_INVALID_PARAM;
1707 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1709 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1710 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1712 server_info = __get_rfcomm_server_info_with_id(server_fd);
1714 BT_ERR("No server with fd: %d", server_fd);
1715 return BLUETOOTH_ERROR_INVALID_PARAM;
1718 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1720 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REJECT_CONNECTION,
1721 in_param1, in_param2, in_param3, in_param4, &out_param);
1723 BT_DBG("result: %x", result);
1725 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);