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 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
41 static GSList *rfcomm_nodes;
44 bluetooth_device_address_t addr;
47 gboolean disconnected;
56 guint disconnect_idle_id;
59 static unsigned int rx_data = 0;
60 static guint rx_tag = 0;
62 static bool __rfcomm_record_rx_data(void)
65 if (bluetooth_get_battery_monitor_state()) {
67 int ret = _bt_common_send_rfcomm_rx_details(rx_data);
68 if (ret == BLUETOOTH_ERROR_NONE) {
73 BT_ERR("RFCOMM rx data could not be registered");
81 static rfcomm_info_t *__find_rfcomm_info_with_id(int id)
85 for (l = rfcomm_nodes; l != NULL; l = l->next) {
86 rfcomm_info_t *info = l->data;
95 static rfcomm_info_t *__find_rfcomm_info_with_fd(int fd)
100 for (l = rfcomm_nodes; l != NULL; l = l->next) {
101 rfcomm_info_t *info = l->data;
103 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
104 rfcomm_conn_t *conn = ll->data;
106 if (conn && conn->fd == fd)
114 static rfcomm_info_t *__find_rfcomm_info_with_path(const gchar *path)
118 for (l = rfcomm_nodes; l != NULL; l = l->next) {
119 rfcomm_info_t *info = l->data;
121 if (g_ascii_strcasecmp(info->path, path) == 0)
128 static rfcomm_info_t *__find_rfcomm_info_with_uuid(const char *uuid)
132 for (l = rfcomm_nodes; l != NULL; l = l->next) {
133 rfcomm_info_t *info = l->data;
135 if (g_ascii_strcasecmp(info->uuid, uuid) == 0)
142 static rfcomm_conn_t *__find_rfcomm_conn_with_fd(rfcomm_info_t *info,
148 for (l = info->rfcomm_conns; l; l = l->next) {
151 if (conn && conn->fd == fd)
158 static void __rfcomm_remove_conn(rfcomm_info_t *info, int fd)
162 conn = __find_rfcomm_conn_with_fd(info, fd);
166 info->rfcomm_conns = g_slist_remove(info->rfcomm_conns, conn);
168 if (conn->watch_id > 0)
169 g_source_remove(conn->watch_id);
173 gboolean _check_uuid_path(char *path, char *uuid)
175 rfcomm_info_t *info = NULL;
176 info = __find_rfcomm_info_with_path(path);
180 if (g_ascii_strcasecmp(info->uuid, uuid) == 0)
186 static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn,
187 bt_event_info_t *event_info)
189 bluetooth_rfcomm_connection_t conn_info;
191 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
193 conn_info.device_role = RFCOMM_ROLE_SERVER;
194 g_strlcpy(conn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
195 conn_info.socket_fd = conn->fd;
196 conn_info.device_addr = conn->addr;
197 conn_info.server_id = info->id;
199 BT_INFO_C("### Connected [RFCOMM Server]");
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 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
239 BLUETOOTH_ERROR_NONE, &disconn_info,
240 event_info->cb, event_info->user_data);
242 __rfcomm_remove_conn(info, conn->fd);
245 static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
247 BT_INFO_C("### Disconnected [RFCOMM Server]");
249 if (g_slist_find(rfcomm_nodes, info) == NULL) {
250 BT_INFO("rfcomm resource is already freed");
254 info->disconnect_idle_id = 0;
256 g_slist_foreach(info->rfcomm_conns,
257 (GFunc)__rfcomm_server_disconnect_conn, info);
263 static gboolean __is_error_by_disconnect(GError *err)
265 return !g_strcmp0(err->message, "Connection reset by peer") ||
266 !g_strcmp0(err->message, "Connection timed out") ||
267 !g_strcmp0(err->message, "Software caused connection abort");
270 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
275 int result = BLUETOOTH_ERROR_NONE;
276 rfcomm_info_t *info = data;
278 bt_event_info_t *event_info;
279 bluetooth_rfcomm_received_data_t data_r;
280 GIOStatus status = G_IO_STATUS_NORMAL;
284 retv_if(info == NULL, FALSE);
286 fd = g_io_channel_unix_get_fd(chan);
287 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
288 BT_ERR_C("RFComm Server disconnected: %d", fd);
290 if (info->disconnect_idle_id > 0) {
291 BT_INFO("Disconnect idle still not process remove source");
292 g_source_remove(info->disconnect_idle_id);
293 info->disconnect_idle_id = 0;
296 conn = __find_rfcomm_conn_with_fd(info, fd);
298 BT_ERR("No Connection info found with FD [%d]", fd);
302 if (conn->disconnected == FALSE) {
304 conn->disconnected = TRUE;
306 __rfcomm_server_disconnect(info);
310 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
312 status = g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
314 if (status != G_IO_STATUS_NORMAL) {
315 BT_ERR("IO Channel read is failed with %d", status);
321 BT_ERR("IO Channel read error [%s]", err->message);
322 if (status == G_IO_STATUS_ERROR &&
323 __is_error_by_disconnect(err)) {
324 BT_ERR("cond : %d", cond);
327 if (info->disconnect_idle_id > 0) {
328 BT_INFO("Disconnect idle still not process remove source");
329 g_source_remove(info->disconnect_idle_id);
330 info->disconnect_idle_id = 0;
333 conn = __find_rfcomm_conn_with_fd(info, fd);
335 BT_ERR("No Connection info found with FD [%d]", fd);
339 if (conn->disconnected == FALSE) {
341 conn->disconnected = TRUE;
343 __rfcomm_server_disconnect(info);
351 BT_ERR("Length is zero");
353 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
354 if (event_info == NULL) {
355 BT_ERR("event_info is NULL. Unable to invoke the callback");
360 data_r.socket_fd = fd;
361 data_r.buffer_size = len;
362 data_r.buffer = buffer;
364 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
366 event_info->cb, event_info->user_data);
368 if (bluetooth_get_battery_monitor_state()) {
370 BT_INFO("Adding rfcomm rx timeout function for battery monitor");
371 rx_tag = g_timeout_add_seconds(BATTERY_MONITOR_RFCOMM_INTERVAL, (GSourceFunc)__rfcomm_record_rx_data, NULL);
381 int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
386 bt_event_info_t *event_info;
388 BT_INFO("%s %d", path, fd);
390 info = __find_rfcomm_info_with_path(path);
392 BT_ERR("rfcomm info is NULL");
396 #ifdef TIZEN_FEATURE_BT_DPM
397 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
400 BT_ERR("Not allow to use SPP profile");
403 _bt_convert_addr_type_to_string(addr_str, addr->addr);
404 _bt_disconnect_ext_profile(addr_str, info->path);
410 conn = g_new0(rfcomm_conn_t, 1);
412 memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
413 info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
415 data_io = g_io_channel_unix_new(conn->fd);
417 g_io_channel_set_encoding(data_io, NULL, NULL);
418 g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
420 conn->watch_id = g_io_add_watch(data_io,
421 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
422 __data_received_cb, info);
424 g_io_channel_unref(data_io);
426 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
428 __connected_cb(info, conn, event_info);
433 static rfcomm_info_t *__register_method()
440 id = __rfcomm_assign_id();
444 path = g_strdup_printf("/org/socket/server/%d/%d", getpid(), id);
446 object_id = _bt_register_new_conn(path, new_server_connection);
448 __rfcomm_delete_id(id);
451 info = g_new0(rfcomm_info_t, 1);
452 info->object_id = (guint)object_id;
456 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
461 static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
466 object_id = _bt_register_new_conn_ex(path, bus_name, new_server_connection);
470 info = g_new0(rfcomm_info_t, 1);
471 info->object_id = (guint)object_id;
472 info->path = g_strdup(path);
475 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
480 void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
482 if (conn->disconnected == FALSE) {
484 conn->disconnected = TRUE;
486 __rfcomm_server_disconnect_conn(conn, info);
489 void free_rfcomm_info(rfcomm_info_t *info)
493 if (info->disconnect_idle_id > 0) {
494 BT_INFO("Disconnect idle still not process remove source");
495 g_source_remove(info->disconnect_idle_id);
496 info->disconnect_idle_id = 0;
499 __rfcomm_delete_id(info->id);
500 _bt_unregister_gdbus(info->object_id);
502 g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
509 void _bt_rfcomm_server_free_all(void)
511 BT_DBG("Free all the servers");
513 g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
517 void _bt_rfcomm_server_disconnect_all(void)
523 BT_INFO(" ### Disconnect all RFCOMM server connections");
525 for (server = rfcomm_nodes; server; ) {
526 rfcomm_info_t *info = server->data;
528 for (conn = info->rfcomm_conns; conn; conn = conn->next) {
529 rfcomm_conn_t *conn_info = conn->data;
531 if (conn_info == NULL)
534 if (conn_info->watch_id == 0 || conn_info->disconnected)
537 close(conn_info->fd);
538 conn_info->disconnected = TRUE;
540 _bt_convert_addr_type_to_string(addr,
541 conn_info->addr.addr);
542 _bt_disconnect_ext_profile(addr, info->path);
545 server = server->next;
546 __rfcomm_server_disconnect(info);
553 #define BT_RFCOMM_SERVER_ID_MAX 254
556 char addr[BT_ADDRESS_STRING_SIZE];
560 } rfcomm_remote_client_info_t;
563 char uuid[BLUETOOTH_UUID_STRING_MAX];
567 int max_pending_conn;
568 gboolean auto_accept;
569 char pending_addr[BT_ADDRESS_STRING_SIZE];
571 } rfcomm_server_info_t;
573 static GSList *rfcomm_servers;
574 static gboolean id_used[BT_RFCOMM_SERVER_ID_MAX];
577 int __rfcomm_assign_server_id(void)
581 BT_DBG("latest_id: %d", latest_id);
583 index = latest_id + 1;
585 if (index >= BT_RFCOMM_SERVER_ID_MAX)
588 BT_DBG("index: %d", index);
590 while (id_used[index] == TRUE) {
591 if (index == latest_id) {
592 /* No available ID */
593 BT_ERR("All request ID is used");
599 if (index >= BT_RFCOMM_SERVER_ID_MAX)
604 id_used[index] = TRUE;
606 BT_DBG("Assigned Id: %d", latest_id);
611 void __rfcomm_delete_server_id(int id)
613 ret_if(id >= BT_RFCOMM_SERVER_ID_MAX);
618 /* Next server will use this ID */
622 static rfcomm_server_info_t *__get_rfcomm_server_info_with_uuid(const char *uuid)
629 for (l = rfcomm_servers; l != NULL; l = l->next) {
630 rfcomm_server_info_t *info = l->data;
632 if (!strncasecmp(info->uuid, uuid, strlen(info->uuid)))
639 int _get_rfcomm_server_id(char *uuid, gboolean *auto_accept)
641 rfcomm_server_info_t *server_info;
643 server_info = __get_rfcomm_server_info_with_uuid(uuid);
647 *auto_accept = server_info->auto_accept;
648 return server_info->server_id;
651 static rfcomm_server_info_t *__get_rfcomm_server_info_with_id(int server_id)
655 for (l = rfcomm_servers; l != NULL; l = l->next) {
656 rfcomm_server_info_t *info = l->data;
660 BT_DBG("info->server_fd: %d, sock_fd:%d", info->server_id, server_id);
661 if (info->server_id == server_id)
668 void _bt_rfcomm_server_set_pending_conn(int server_id, char *address)
670 rfcomm_server_info_t *server_info;
676 server_info = __get_rfcomm_server_info_with_id(server_id);
680 g_strlcpy(server_info->pending_addr, address, BT_ADDRESS_STRING_SIZE);
683 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_fd(int sock_fd)
688 for (l = rfcomm_servers; l != NULL; l = l->next) {
689 rfcomm_server_info_t *info = l->data;
694 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
695 rfcomm_remote_client_info_t *client_info = l1->data;
699 if (client_info->sock_fd == sock_fd)
707 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_addr(char *addr)
712 retv_if(NULL == addr, NULL);
714 for (l = rfcomm_servers; l != NULL; l = l->next) {
715 rfcomm_server_info_t *info = l->data;
720 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
721 rfcomm_remote_client_info_t *client_info = l1->data;
725 if (!strncasecmp(client_info->addr, addr, strlen(client_info->addr)))
733 static void __remove_remote_client_info(rfcomm_remote_client_info_t *rem_client)
737 if (rem_client == NULL)
740 if (0 < rem_client->sock_fd) {
741 shutdown(rem_client->sock_fd, SHUT_RDWR);
742 close(rem_client->sock_fd);
745 if (rem_client->watch_id > 0)
746 g_source_remove(rem_client->watch_id);
753 static void __handle_rfcomm_client_disconnected(rfcomm_server_info_t *server_info,
754 rfcomm_remote_client_info_t *rem_client)
756 bluetooth_rfcomm_disconnection_t disconn_info;
757 bt_event_info_t *event_info;
761 if (rem_client == NULL || server_info == NULL)
764 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
765 if (event_info == NULL)
768 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
769 disconn_info.device_role = RFCOMM_ROLE_SERVER;
770 g_strlcpy(disconn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
771 _bt_convert_addr_string_to_type(disconn_info.device_addr.addr, rem_client->addr);
772 BT_DBG("Disconnected FD [%d]", rem_client->sock_fd);
773 disconn_info.socket_fd = rem_client->sock_fd;
775 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
776 BLUETOOTH_ERROR_NONE, &disconn_info,
777 event_info->cb, event_info->user_data);
780 static void __remove_rfcomm_server(rfcomm_server_info_t *info)
782 rfcomm_remote_client_info_t *client_info;
789 rfcomm_servers = g_slist_remove(rfcomm_servers, info);
790 if (info->conn_list) {
792 client_info = info->conn_list->data;
796 info->conn_list = g_slist_remove(info->conn_list, client_info);
797 __handle_rfcomm_client_disconnected(info, client_info);
798 __remove_remote_client_info(client_info);
799 } while (info->conn_list);
802 if (info->server_fd) {
803 shutdown(info->server_fd, SHUT_RDWR);
804 close(info->server_fd);
808 g_source_remove(info->watch_id);
810 __rfcomm_delete_server_id(info->server_id);
816 static void __connected_cb(rfcomm_remote_client_info_t *client_info, bt_event_info_t *event_info)
818 bluetooth_rfcomm_connection_t conn_info;
819 rfcomm_server_info_t *server_info;
821 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
822 ret_if(server_info == NULL);
824 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
825 conn_info.device_role = RFCOMM_ROLE_SERVER;
826 g_strlcpy(conn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
827 conn_info.socket_fd = client_info->sock_fd;
828 _bt_convert_addr_string_to_type(conn_info.device_addr.addr, client_info->addr);
829 conn_info.server_id = server_info->server_id;
831 BT_INFO_C("Connected [RFCOMM Server]");
832 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
833 BLUETOOTH_ERROR_NONE, &conn_info,
834 event_info->cb, event_info->user_data);
837 static int __process_cmsg(struct msghdr *msg)
840 struct cmsghdr *cmsg_ptr = NULL;
842 for (cmsg_ptr = CMSG_FIRSTHDR(msg); cmsg_ptr != NULL;
843 cmsg_ptr = CMSG_NXTHDR(msg, cmsg_ptr)) {
845 if (cmsg_ptr->cmsg_level != SOL_SOCKET)
848 if (cmsg_ptr->cmsg_type == SCM_RIGHTS) {
849 //int *desc = (int *)CMSG_DATA(cmsg_ptr);
851 = ((cmsg_ptr->cmsg_len - CMSG_LEN(0)) / sizeof(int));
854 BT_ERR("ERROR Invalid count of descriptors");
859 memcpy(&sock_fd, CMSG_DATA(cmsg_ptr), sizeof(sock_fd));
860 BT_DBG("Remote client fd: %d", sock_fd);
867 static int __read_incomming_client_connection(
868 int server_fd, char *buf, unsigned int len, int *client_fd)
873 struct cmsghdr cmsgbuf[2 * sizeof(struct cmsghdr) + 4];
876 retv_if(0 > server_fd, -1);
877 retv_if(NULL == client_fd, -1);
879 BT_INFO("server_fd = %d", server_fd);
881 memset(&msg, 0, sizeof(msg));
882 memset(&iv, 0, sizeof(iv));
888 msg.msg_control = cmsgbuf;
889 msg.msg_controllen = sizeof(cmsgbuf);
891 for (retryCount = 0; retryCount < 5; retryCount++) {
892 ret = recvmsg(server_fd, &msg, 0);
893 BT_DBG("recvmsg ret = %d", ret);
894 if (ret < 0 && errno == EINTR)
900 if (ret < 0 && errno == EPIPE) {
901 /* End of stream, server listining stopped */
902 BT_ERR("EOS errno: %d", errno);
907 BT_ERR("Ret errno: %d", errno);
911 if ((msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) {
912 BT_ERR("MSG Flags errno: %d", errno);
916 BT_INFO("Connection received");
917 *client_fd = __process_cmsg(&msg);
919 BT_ERR("Invalid client_fd received");
924 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
929 int result = BLUETOOTH_ERROR_NONE;
930 bt_event_info_t *event_info;
931 bluetooth_rfcomm_received_data_t data_r;
932 GIOStatus status = G_IO_STATUS_NORMAL;
934 rfcomm_remote_client_info_t *client_info = data;
935 rfcomm_server_info_t *server_info;
937 retv_if(client_info == NULL, FALSE);
939 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
941 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
942 BT_ERR_C("RFComm Server disconnected: %d", client_info->sock_fd);
946 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
947 status = g_io_channel_read_chars(chan, buffer,
948 BT_RFCOMM_BUFFER_LEN, &len, &err);
949 if (status != G_IO_STATUS_NORMAL) {
950 BT_ERR("IO Channel read is failed with %d", status);
953 BT_ERR("IO Channel read error [%s]", err->message);
954 if (status == G_IO_STATUS_ERROR &&
955 !g_strcmp0(err->message, "Connection reset by peer")) {
956 BT_ERR("cond : %d", cond);
966 BT_ERR("Length is zero, remote end hang up");
970 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
971 if (event_info == NULL) {
976 data_r.socket_fd = client_info->sock_fd;
977 data_r.buffer_size = len;
978 data_r.buffer = buffer;
980 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
982 event_info->cb, event_info->user_data);
989 BT_ERR("Failure occured, remove client connection");
990 server_info->conn_list = g_slist_remove(
991 server_info->conn_list, client_info);
992 __handle_rfcomm_client_disconnected(server_info, client_info);
993 __remove_remote_client_info(client_info);
997 static gboolean __new_connection_request_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1004 char buf[BLUETOOTH_SOCK_CONNECT_INFO_LEN];
1005 unsigned char addr[BT_ADDRESS_LENGTH_MAX];
1007 bt_event_info_t *event_info;
1009 rfcomm_remote_client_info_t *rem_client;
1010 rfcomm_server_info_t *server_info = data;
1013 BT_ERR("Server info is invalid");
1017 if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
1018 BT_INFO("RFCOMM Server with fd:%d is closed with cond:0x%X",
1019 server_info->server_fd, cond);
1023 BT_INFO("Server fd: %d", server_info->server_fd);
1024 len = __read_incomming_client_connection(
1025 server_info->server_fd, buf, BLUETOOTH_SOCK_CONNECT_INFO_LEN, &client_fd);
1026 BT_DBG("Socket Read len: %d", len);
1028 BT_ERR("Listen stopped");
1030 } else if (len != BLUETOOTH_SOCK_CONNECT_INFO_LEN) {
1031 BT_ERR("Read length is not same as socket info length");
1036 /* Read size of data */
1037 size = buf[len] | (buf[len + 1] << 8);
1040 /* Read bluetooth address */
1041 memcpy(addr, buf + len, BT_ADDRESS_LENGTH_MAX);
1042 len += BT_ADDRESS_LENGTH_MAX;
1045 channel = buf[len] | (buf[len + 1] << 8) |
1046 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1050 status = buf[len] | (buf[len + 1] << 8) |
1051 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1054 BT_DBG("size: %d, channel: %d, status: %d", size, channel, status);
1056 rem_client = g_malloc0(sizeof(rfcomm_remote_client_info_t));
1057 rem_client->sock_fd = client_fd;
1058 rem_client->server_id = server_info->server_id;
1059 _bt_convert_addr_type_to_string(rem_client->addr, addr);
1061 BT_INFO("New client [%s] connection with socket_fd: %d, server_id: %d",
1062 rem_client->addr, rem_client->sock_fd, rem_client->server_id);
1064 io = g_io_channel_unix_new(rem_client->sock_fd);
1065 g_io_channel_set_encoding(io, NULL, NULL);
1066 g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
1067 rem_client->watch_id = g_io_add_watch(io,
1068 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1069 __data_received_cb, rem_client);
1070 g_io_channel_unref(io);
1072 server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
1073 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
1075 __connected_cb(rem_client, event_info);
1080 /* Error occurred, Remove RFCOMM server*/
1081 __remove_rfcomm_server(server_info);
1085 static int __rfcomm_listen(rfcomm_server_info_t *server_info, bool accept)
1088 GUnixFDList *out_fd_list = NULL;
1089 GIOChannel *server_io;
1091 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1094 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1096 if (accept == false) {
1097 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1098 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
1099 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1101 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1102 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN_AND_ACCEPT,
1103 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1106 BT_DBG("result: %x", result);
1107 if (result != BLUETOOTH_ERROR_NONE) {
1108 BT_ERR("Fail to send request");
1110 } else if (NULL == out_fd_list) {
1111 BT_ERR("out_fd_list is NULL");
1112 return BLUETOOTH_ERROR_INTERNAL;
1118 return BLUETOOTH_ERROR_INTERNAL;
1120 fd_list_array = g_unix_fd_list_steal_fds(out_fd_list, &len);
1121 BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
1122 server_info->server_fd = fd_list_array[0];
1123 BT_INFO("Socket fd: %d", server_info->server_fd);
1125 g_free(fd_list_array);
1126 g_object_unref(out_fd_list);
1129 server_io = g_io_channel_unix_new(server_info->server_fd);
1130 g_io_channel_set_encoding(server_io, NULL, NULL);
1131 g_io_channel_set_flags(server_io, G_IO_FLAG_NONBLOCK, NULL);
1132 server_info->watch_id = g_io_add_watch(server_io,
1133 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1134 __new_connection_request_cb, server_info);
1135 g_io_channel_unref(server_io);
1137 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1139 return BLUETOOTH_ERROR_NONE;
1143 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
1145 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1146 rfcomm_info_t *info;
1148 rfcomm_server_info_t *server_info;
1151 BT_CHECK_ENABLED(return);
1152 BT_CHECK_PARAMETER(uuid, return);
1153 BT_INFO("UUID Provided %s", uuid);
1155 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET)
1156 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1157 BT_ERR("Don't have a privilege to use this API");
1158 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1161 #ifdef TIZEN_FEATURE_BT_DPM
1162 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1163 BT_ERR("Not allow to use SPP profile");
1164 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1168 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1169 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1170 info = __register_method();
1174 info->uuid = g_strdup(uuid);
1175 info->disconnect_idle_id = 0;
1178 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1180 server_info = __get_rfcomm_server_info_with_uuid(uuid);
1182 server_info = g_malloc0(sizeof(rfcomm_server_info_t));
1183 g_strlcpy(server_info->uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1184 server_info->server_id = __rfcomm_assign_server_id();
1185 server_info->server_fd = -1;
1186 server_info->watch_id = -1;
1187 server_info->auto_accept = FALSE;
1188 rfcomm_servers = g_slist_append(rfcomm_servers, server_info);
1190 return server_info->server_id;
1194 BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char *bus_name, const char *path)
1196 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1197 rfcomm_info_t *info;
1199 BT_CHECK_ENABLED(return);
1200 BT_CHECK_PARAMETER(path, return);
1201 BT_INFO("PATH Provided %s", path);
1203 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET_EX)
1204 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1205 BT_ERR("Don't have a privilege to use this API");
1206 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1209 #ifdef TIZEN_FEATURE_BT_DPM
1210 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1211 BT_ERR("Not allow to use SPP profile");
1212 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1216 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1217 info = __register_method_2(path, bus_name);
1219 return BLUETOOTH_ERROR_IN_PROGRESS;
1220 info->uuid = g_strdup(uuid);
1221 info->disconnect_idle_id = 0;
1223 return BLUETOOTH_ERROR_NONE;
1225 return BLUETOOTH_ERROR_NOT_SUPPORT;
1230 BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
1232 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1233 rfcomm_info_t *info;
1235 rfcomm_server_info_t *server_info;
1238 BT_CHECK_ENABLED(return);
1240 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1241 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1242 BT_ERR("Don't have a privilege to use this API");
1243 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1247 BT_ERR("Invalid ID");
1248 return BLUETOOTH_ERROR_INVALID_PARAM;
1251 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1252 BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
1254 info = __find_rfcomm_info_with_id(id);
1256 return BLUETOOTH_ERROR_INVALID_PARAM;
1258 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1259 _bt_unregister_profile(info->path);
1261 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1262 free_rfcomm_info(info);
1264 return BLUETOOTH_ERROR_NONE;
1266 BT_INFO("<<<<<<<<< RFCOMM Remove socket request from app, fd=[%d] >>>>>>>>>>>", socket_fd);
1268 server_info = __get_rfcomm_server_info_with_id(id);
1270 BT_ERR("server_info not found for socket_fd: %d", id);
1271 return BLUETOOTH_ERROR_INVALID_PARAM;
1274 __remove_rfcomm_server(server_info);
1276 return BLUETOOTH_ERROR_NONE;
1280 BT_EXPORT_API int bluetooth_rfcomm_remove_socket_ex(const char *uuid)
1282 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1283 rfcomm_info_t *info;
1285 BT_CHECK_ENABLED(return);
1287 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1288 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1289 BT_ERR("Don't have a privilege to use this API");
1290 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1293 BT_INFO("RFCOMM Remove socket request from app, uuid=[%s]", uuid);
1295 info = __find_rfcomm_info_with_uuid(uuid);
1297 return BLUETOOTH_ERROR_INVALID_PARAM;
1299 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1300 _bt_unregister_profile(info->path);
1302 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1303 free_rfcomm_info(info);
1305 return BLUETOOTH_ERROR_NONE;
1307 return BLUETOOTH_ERROR_NOT_SUPPORT;
1311 BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
1313 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1314 rfcomm_info_t *info;
1315 rfcomm_conn_t *conn;
1319 BT_INFO(" ### Disconnect RFCOMM server");
1320 if (socket_fd < 0) {
1321 BT_ERR("Invalid FD");
1322 return BLUETOOTH_ERROR_INVALID_PARAM;
1325 info = __find_rfcomm_info_with_fd(socket_fd);
1327 return BLUETOOTH_ERROR_INVALID_PARAM;
1329 conn = __find_rfcomm_conn_with_fd(info, socket_fd);
1331 return BLUETOOTH_ERROR_INVALID_PARAM;
1333 if (conn->watch_id == 0 || conn->disconnected)
1334 return BLUETOOTH_ERROR_NOT_CONNECTED;
1337 conn->disconnected = TRUE;
1339 _bt_convert_addr_type_to_string(address, conn->addr.addr);
1341 BT_DBG("Address %s", address);
1342 _bt_disconnect_ext_profile(address, info->path);
1344 if (info->disconnect_idle_id == 0)
1345 info->disconnect_idle_id = g_idle_add(
1346 (GSourceFunc)__rfcomm_server_disconnect, info);
1349 return BLUETOOTH_ERROR_NONE;
1351 rfcomm_remote_client_info_t *client_info;
1353 BT_CHECK_ENABLED(return);
1355 BT_INFO(">>>>>>>>RFCOMM server disconnect request from APP>>>>>>>>>");
1356 if (socket_fd < 0) {
1357 BT_ERR("Invalid FD");
1358 return BLUETOOTH_ERROR_INVALID_PARAM;
1361 client_info = __get_rfcomm_rem_client_info_with_fd(socket_fd);
1363 BT_ERR("client_info not found for socket_fd: %d", socket_fd);
1364 return BLUETOOTH_ERROR_NOT_CONNECTED;
1367 if (client_info->sock_fd) {
1368 shutdown(client_info->sock_fd, SHUT_RDWR);
1369 close(client_info->sock_fd);
1370 client_info->sock_fd = -1;
1373 return BLUETOOTH_ERROR_NONE;
1377 BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uuid)
1380 gboolean available = TRUE;
1381 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
1383 retv_if(uuid == NULL, FALSE);
1384 retv_if(bluetooth_check_adapter() ==
1385 BLUETOOTH_ADAPTER_DISABLED, FALSE);
1388 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1390 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
1391 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
1393 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_IS_UUID_AVAILABLE,
1394 in_param1, in_param2, in_param3, in_param4, &out_param);
1396 BT_DBG("result: %x", result);
1398 if (result == BLUETOOTH_ERROR_NONE)
1399 available = g_array_index(out_param, gboolean, 0);
1401 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1403 BT_DBG("available: %d", available);
1408 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
1410 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1413 rfcomm_info_t *info;
1414 rfcomm_conn_t *conn;
1416 char input_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1417 rfcomm_remote_client_info_t *info;
1420 BT_CHECK_PARAMETER(device_address, return);
1421 BT_CHECK_PARAMETER(connected, return);
1425 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1426 for (l = rfcomm_nodes; l; l = l->next) {
1429 if (info == NULL || info->rfcomm_conns == NULL)
1432 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
1435 if (memcmp(device_address, &conn->addr,
1436 sizeof(bluetooth_device_address_t)))
1440 return BLUETOOTH_ERROR_NONE;
1444 return BLUETOOTH_ERROR_NONE;
1446 _bt_convert_addr_type_to_string(input_addr, (unsigned char *)device_address->addr);
1447 info = __get_rfcomm_rem_client_info_with_addr(input_addr);
1451 return BLUETOOTH_ERROR_NONE;
1455 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
1457 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1458 rfcomm_info_t *info;
1460 rfcomm_server_info_t *server_info;
1463 BT_CHECK_ENABLED(return);
1465 BT_ERR("Invalid ID");
1466 return BLUETOOTH_ERROR_INVALID_PARAM;
1469 #ifdef TIZEN_FEATURE_BT_DPM
1470 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1471 BT_ERR("Not allow to use SPP profile");
1472 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1476 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1477 BT_INFO("RFCOMM Listen & accept from app");
1479 info = __find_rfcomm_info_with_id(id);
1481 return BLUETOOTH_ERROR_INVALID_PARAM;
1483 bt_register_profile_info_t profile_info;
1486 profile_info.authentication = TRUE;
1487 profile_info.authorization = TRUE;
1488 profile_info.obj_path = info->path;
1489 profile_info.role = NULL;
1490 profile_info.service = info->uuid;
1491 profile_info.uuid = info->uuid;
1493 BT_INFO("uuid %s", profile_info.uuid);
1494 result = _bt_register_profile(&profile_info, TRUE);
1498 BT_INFO("<<<<<<<<< RFCOMM Listen & accept from app >>>>>>>>>>>");
1500 server_info = __get_rfcomm_server_info_with_id(id);
1502 BT_ERR("server_info not found for id: %d", id);
1503 return BLUETOOTH_ERROR_INVALID_PARAM;
1506 if (server_info->server_fd >= 0) {
1507 BT_ERR("server already listining");
1508 return BLUETOOTH_ERROR_DEVICE_BUSY;
1511 server_info->max_pending_conn = max_pending_connection;
1512 server_info->auto_accept = TRUE;
1514 return __rfcomm_listen(server_info, true);
1518 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
1519 int max_pending_connection,
1520 const char *bus_name, const char *path)
1522 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1523 rfcomm_info_t *info;
1525 BT_CHECK_ENABLED(return);
1527 #ifdef TIZEN_FEATURE_BT_DPM
1528 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1529 BT_ERR("Not allow to use SPP profile");
1530 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1534 BT_INFO("RFCOMM Listen & accept from app");
1536 info = __find_rfcomm_info_with_uuid(uuid);
1538 return BLUETOOTH_ERROR_INVALID_PARAM;
1540 bt_register_profile_info_t profile_info;
1543 profile_info.authentication = TRUE;
1544 profile_info.authorization = TRUE;
1545 profile_info.obj_path = info->path;
1546 profile_info.role = NULL;
1547 profile_info.service = info->uuid;
1548 profile_info.uuid = info->uuid;
1550 BT_INFO("uuid %s", profile_info.uuid);
1551 result = _bt_register_profile_ex(&profile_info, TRUE, bus_name, path);
1555 return BLUETOOTH_ERROR_NOT_SUPPORT;
1559 BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
1561 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1562 rfcomm_info_t *info;
1564 rfcomm_server_info_t *server_info;
1567 BT_CHECK_ENABLED(return);
1569 BT_ERR("Invalid ID");
1570 return BLUETOOTH_ERROR_INVALID_PARAM;
1573 #ifdef TIZEN_FEATURE_BT_DPM
1574 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1575 BT_ERR("Not allow to use SPP profile");
1576 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1580 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1581 BT_INFO("RFCOMM Listen");
1583 info = __find_rfcomm_info_with_id(id);
1585 return BLUETOOTH_ERROR_INVALID_PARAM;
1587 bt_register_profile_info_t profile_info;
1590 profile_info.authentication = TRUE;
1591 profile_info.authorization = TRUE;
1592 profile_info.obj_path = info->path;
1593 profile_info.role = NULL;
1594 profile_info.service = info->uuid;
1595 profile_info.uuid = info->uuid;
1596 BT_INFO("UUID %s", info->uuid);
1597 BT_INFO("PATH %s", info->path);
1598 result = _bt_register_profile_platform(&profile_info, TRUE);
1599 if (result != BLUETOOTH_ERROR_NONE)
1602 return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
1606 BT_INFO("<<<<<<<<< RFCOMM Listen >>>>>>>>>>>");
1608 server_info = __get_rfcomm_server_info_with_id(id);
1610 BT_ERR("server_info not found for id: %d", id);
1611 return BLUETOOTH_ERROR_INVALID_PARAM;
1614 if (server_info->server_fd >= 0) {
1615 BT_ERR("server already listining");
1616 return BLUETOOTH_ERROR_DEVICE_BUSY;
1619 server_info->max_pending_conn = max_pending_connection;
1620 server_info->auto_accept = FALSE;
1621 return __rfcomm_listen(server_info, false);
1625 BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd)
1628 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1630 rfcomm_server_info_t *server_info;
1633 BT_CHECK_ENABLED(return);
1635 #ifdef TIZEN_FEATURE_BT_DPM
1636 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1637 BT_ERR("Not allow to use SPP profile");
1638 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1642 if (server_fd < 0) {
1643 BT_ERR("Invalid FD");
1644 return BLUETOOTH_ERROR_INVALID_PARAM;
1648 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1650 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1651 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1653 server_info = __get_rfcomm_server_info_with_id(server_fd);
1655 BT_ERR("No server with fd: %d", server_fd);
1656 return BLUETOOTH_ERROR_INVALID_PARAM;
1659 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1662 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_ACCEPT_CONNECTION,
1663 in_param1, in_param2, in_param3, in_param4, &out_param);
1665 BT_DBG("result: %x", result);
1667 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1672 BT_EXPORT_API int bluetooth_rfcomm_reject_connection(int server_fd)
1675 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1677 rfcomm_server_info_t *server_info;
1680 BT_CHECK_ENABLED(return);
1682 if (server_fd < 0) {
1683 BT_ERR("Invalid FD");
1684 return BLUETOOTH_ERROR_INVALID_PARAM;
1690 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1692 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1693 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1695 server_info = __get_rfcomm_server_info_with_id(server_fd);
1697 BT_ERR("No server with fd: %d", server_fd);
1698 return BLUETOOTH_ERROR_INVALID_PARAM;
1701 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1703 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REJECT_CONNECTION,
1704 in_param1, in_param2, in_param3, in_param4, &out_param);
1706 BT_DBG("result: %x", result);
1708 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);