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 __is_error_by_disconnect(GError *err)
269 return !g_strcmp0(err->message, "Connection reset by peer") ||
270 !g_strcmp0(err->message, "Connection timed out") ||
271 !g_strcmp0(err->message, "Software caused connection abort");
274 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
279 int result = BLUETOOTH_ERROR_NONE;
280 rfcomm_info_t *info = data;
282 bt_event_info_t *event_info;
283 bluetooth_rfcomm_received_data_t data_r;
284 GIOStatus status = G_IO_STATUS_NORMAL;
288 retv_if(info == NULL, FALSE);
290 fd = g_io_channel_unix_get_fd(chan);
291 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
292 BT_ERR_C("RFComm Server disconnected: %d", fd);
294 if (info->disconnect_idle_id > 0) {
295 BT_INFO("Disconnect idle still not process remove source");
296 g_source_remove(info->disconnect_idle_id);
297 info->disconnect_idle_id = 0;
300 conn = __find_rfcomm_conn_with_fd(info, fd);
302 BT_ERR("No Connection info found with FD [%d]", fd);
306 if (conn->disconnected == FALSE) {
308 conn->disconnected = TRUE;
310 __rfcomm_server_disconnect(info);
314 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
316 status = g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
318 if (status != G_IO_STATUS_NORMAL) {
319 BT_ERR("IO Channel read is failed with %d", status);
325 BT_ERR("IO Channel read error [%s]", err->message);
326 if (status == G_IO_STATUS_ERROR &&
327 __is_error_by_disconnect(err)) {
328 BT_ERR("cond : %d", cond);
331 if (info->disconnect_idle_id > 0) {
332 BT_INFO("Disconnect idle still not process remove source");
333 g_source_remove(info->disconnect_idle_id);
334 info->disconnect_idle_id = 0;
337 conn = __find_rfcomm_conn_with_fd(info, fd);
339 BT_ERR("No Connection info found with FD [%d]", fd);
343 if (conn->disconnected == FALSE) {
345 conn->disconnected = TRUE;
347 __rfcomm_server_disconnect(info);
355 BT_ERR("Length is zero");
357 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
358 if (event_info == NULL) {
359 BT_ERR("event_info is NULL. Unable to invoke the callback");
364 data_r.socket_fd = fd;
365 data_r.buffer_size = len;
366 data_r.buffer = buffer;
368 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
370 event_info->cb, event_info->user_data);
372 if (bluetooth_get_battery_monitor_state()) {
374 BT_DBG("Adding rfcomm rx timeout function for battery monitor");
375 rx_tag = g_timeout_add_seconds(BATTERY_MONITOR_RFCOMM_INTERVAL, (GSourceFunc)__rfcomm_record_rx_data, NULL);
385 int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
390 bt_event_info_t *event_info;
392 BT_INFO("%s %d", path, fd);
394 info = __find_rfcomm_info_with_path(path);
396 BT_ERR("rfcomm info is NULL");
400 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
403 BT_ERR("Not allow to use SPP profile");
406 _bt_convert_addr_type_to_string(addr_str, addr->addr);
407 _bt_disconnect_ext_profile(addr_str, info->path);
412 conn = g_new0(rfcomm_conn_t, 1);
414 memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
415 info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
417 data_io = g_io_channel_unix_new(conn->fd);
419 g_io_channel_set_encoding(data_io, NULL, NULL);
420 g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
422 conn->watch_id = g_io_add_watch(data_io,
423 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
424 __data_received_cb, info);
426 g_io_channel_unref(data_io);
428 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
430 __connected_cb(info, conn, event_info);
435 static rfcomm_info_t *__register_method()
442 id = __rfcomm_assign_id();
446 path = g_strdup_printf("/org/socket/server/%d/%d", getpid(), id);
448 object_id = _bt_register_new_conn(path, new_server_connection);
450 __rfcomm_delete_id(id);
454 info = g_new0(rfcomm_info_t, 1);
455 info->object_id = (guint)object_id;
459 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
464 static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
469 object_id = _bt_register_new_conn_ex(path, bus_name, new_server_connection);
473 info = g_new0(rfcomm_info_t, 1);
474 info->object_id = (guint)object_id;
475 info->path = g_strdup(path);
478 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
483 void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
485 if (conn->disconnected == FALSE) {
487 conn->disconnected = TRUE;
489 __rfcomm_server_disconnect_conn(conn, info);
492 void free_rfcomm_info(rfcomm_info_t *info)
496 if (info->disconnect_idle_id > 0) {
497 BT_INFO("Disconnect idle still not process remove source");
498 g_source_remove(info->disconnect_idle_id);
499 info->disconnect_idle_id = 0;
502 __rfcomm_delete_id(info->id);
503 _bt_unregister_gdbus(info->object_id);
505 g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
512 void _bt_rfcomm_server_free_all(void)
514 BT_DBG("Free all the servers");
516 g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
520 void _bt_rfcomm_server_disconnect_all(void)
526 BT_INFO(" ### Disconnect all RFCOMM server connections");
528 for (server = rfcomm_nodes; server; ) {
529 rfcomm_info_t *info = server->data;
531 for (conn = info->rfcomm_conns; conn; conn = conn->next) {
532 rfcomm_conn_t *conn_info = conn->data;
534 if (conn_info == NULL)
537 if (conn_info->watch_id == 0 || conn_info->disconnected)
540 close(conn_info->fd);
541 conn_info->disconnected = TRUE;
543 _bt_convert_addr_type_to_string(addr,
544 conn_info->addr.addr);
545 _bt_disconnect_ext_profile(addr, info->path);
548 server = server->next;
549 __rfcomm_server_disconnect(info);
555 void _bt_rfcomm_server_reset_timer(void)
558 g_source_remove(rx_tag);
566 #define BT_RFCOMM_SERVER_ID_MAX 254
569 char addr[BT_ADDRESS_STRING_SIZE];
573 } rfcomm_remote_client_info_t;
576 char uuid[BLUETOOTH_UUID_STRING_MAX];
580 int max_pending_conn;
581 gboolean auto_accept;
582 char pending_addr[BT_ADDRESS_STRING_SIZE];
584 } rfcomm_server_info_t;
586 static GSList *rfcomm_servers;
587 static gboolean id_used[BT_RFCOMM_SERVER_ID_MAX];
590 int __rfcomm_assign_server_id(void)
594 BT_DBG("latest_id: %d", latest_id);
596 index = latest_id + 1;
598 if (index >= BT_RFCOMM_SERVER_ID_MAX)
601 BT_DBG("index: %d", index);
603 while (id_used[index] == TRUE) {
604 if (index == latest_id) {
605 /* No available ID */
606 BT_ERR("All request ID is used");
612 if (index >= BT_RFCOMM_SERVER_ID_MAX)
617 id_used[index] = TRUE;
619 BT_DBG("Assigned Id: %d", latest_id);
624 void __rfcomm_delete_server_id(int id)
626 ret_if(id >= BT_RFCOMM_SERVER_ID_MAX);
631 /* Next server will use this ID */
635 static rfcomm_server_info_t *__get_rfcomm_server_info_with_uuid(const char *uuid)
642 for (l = rfcomm_servers; l != NULL; l = l->next) {
643 rfcomm_server_info_t *info = l->data;
645 if (!strncasecmp(info->uuid, uuid, strlen(info->uuid)))
652 int _get_rfcomm_server_id(char *uuid, gboolean *auto_accept)
654 rfcomm_server_info_t *server_info;
656 server_info = __get_rfcomm_server_info_with_uuid(uuid);
660 *auto_accept = server_info->auto_accept;
661 return server_info->server_id;
664 static rfcomm_server_info_t *__get_rfcomm_server_info_with_id(int server_id)
668 for (l = rfcomm_servers; l != NULL; l = l->next) {
669 rfcomm_server_info_t *info = l->data;
673 BT_DBG("info->server_fd: %d, sock_fd:%d", info->server_id, server_id);
674 if (info->server_id == server_id)
681 void _bt_rfcomm_server_set_pending_conn(int server_id, char *address)
683 rfcomm_server_info_t *server_info;
689 server_info = __get_rfcomm_server_info_with_id(server_id);
693 g_strlcpy(server_info->pending_addr, address, BT_ADDRESS_STRING_SIZE);
696 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_fd(int sock_fd)
701 for (l = rfcomm_servers; l != NULL; l = l->next) {
702 rfcomm_server_info_t *info = l->data;
707 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
708 rfcomm_remote_client_info_t *client_info = l1->data;
712 if (client_info->sock_fd == sock_fd)
720 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_addr(char *addr)
725 retv_if(NULL == addr, NULL);
727 for (l = rfcomm_servers; l != NULL; l = l->next) {
728 rfcomm_server_info_t *info = l->data;
733 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
734 rfcomm_remote_client_info_t *client_info = l1->data;
738 if (!strncasecmp(client_info->addr, addr, strlen(client_info->addr)))
746 static void __remove_remote_client_info(rfcomm_remote_client_info_t *rem_client)
750 if (rem_client == NULL)
753 if (0 < rem_client->sock_fd) {
754 shutdown(rem_client->sock_fd, SHUT_RDWR);
755 close(rem_client->sock_fd);
758 if (rem_client->watch_id > 0)
759 g_source_remove(rem_client->watch_id);
766 static void __handle_rfcomm_client_disconnected(rfcomm_server_info_t *server_info,
767 rfcomm_remote_client_info_t *rem_client)
769 bluetooth_rfcomm_disconnection_t disconn_info;
770 bt_event_info_t *event_info;
774 if (rem_client == NULL || server_info == NULL)
777 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
778 if (event_info == NULL)
781 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
782 disconn_info.device_role = RFCOMM_ROLE_SERVER;
783 g_strlcpy(disconn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
784 _bt_convert_addr_string_to_type(disconn_info.device_addr.addr, rem_client->addr);
785 BT_DBG("Disconnected FD [%d]", rem_client->sock_fd);
786 disconn_info.socket_fd = rem_client->sock_fd;
788 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
789 BLUETOOTH_ERROR_NONE, &disconn_info,
790 event_info->cb, event_info->user_data);
793 static void __remove_rfcomm_server(rfcomm_server_info_t *info)
795 rfcomm_remote_client_info_t *client_info;
802 rfcomm_servers = g_slist_remove(rfcomm_servers, info);
803 if (info->conn_list) {
805 client_info = info->conn_list->data;
809 info->conn_list = g_slist_remove(info->conn_list, client_info);
810 __handle_rfcomm_client_disconnected(info, client_info);
811 __remove_remote_client_info(client_info);
812 } while (info->conn_list);
815 if (info->server_fd) {
816 shutdown(info->server_fd, SHUT_RDWR);
817 close(info->server_fd);
821 g_source_remove(info->watch_id);
823 __rfcomm_delete_server_id(info->server_id);
829 static void __connected_cb(rfcomm_remote_client_info_t *client_info, bt_event_info_t *event_info)
831 bluetooth_rfcomm_connection_t conn_info;
832 rfcomm_server_info_t *server_info;
834 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
835 ret_if(server_info == NULL);
837 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
838 conn_info.device_role = RFCOMM_ROLE_SERVER;
839 g_strlcpy(conn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
840 conn_info.socket_fd = client_info->sock_fd;
841 _bt_convert_addr_string_to_type(conn_info.device_addr.addr, client_info->addr);
842 conn_info.server_id = server_info->server_id;
844 BT_INFO_C("Connected [RFCOMM Server]");
845 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
846 BLUETOOTH_ERROR_NONE, &conn_info,
847 event_info->cb, event_info->user_data);
850 static int __process_cmsg(struct msghdr *msg)
853 struct cmsghdr *cmsg_ptr = NULL;
855 for (cmsg_ptr = CMSG_FIRSTHDR(msg); cmsg_ptr != NULL;
856 cmsg_ptr = CMSG_NXTHDR(msg, cmsg_ptr)) {
858 if (cmsg_ptr->cmsg_level != SOL_SOCKET)
861 if (cmsg_ptr->cmsg_type == SCM_RIGHTS) {
862 //int *desc = (int *)CMSG_DATA(cmsg_ptr);
864 = ((cmsg_ptr->cmsg_len - CMSG_LEN(0)) / sizeof(int));
867 BT_ERR("ERROR Invalid count of descriptors");
872 memcpy(&sock_fd, CMSG_DATA(cmsg_ptr), sizeof(sock_fd));
873 BT_DBG("Remote client fd: %d", sock_fd);
880 static int __read_incomming_client_connection(
881 int server_fd, char *buf, unsigned int len, int *client_fd)
886 struct cmsghdr cmsgbuf[2 * sizeof(struct cmsghdr) + 4];
889 retv_if(0 > server_fd, -1);
890 retv_if(NULL == client_fd, -1);
892 BT_INFO("server_fd = %d", server_fd);
894 memset(&msg, 0, sizeof(msg));
895 memset(&iv, 0, sizeof(iv));
901 msg.msg_control = cmsgbuf;
902 msg.msg_controllen = sizeof(cmsgbuf);
904 for (retryCount = 0; retryCount < 5; retryCount++) {
905 ret = recvmsg(server_fd, &msg, 0);
906 BT_DBG("recvmsg ret = %d", ret);
907 if (ret < 0 && errno == EINTR)
913 if (ret < 0 && errno == EPIPE) {
914 /* End of stream, server listining stopped */
915 BT_ERR("EOS errno: %d", errno);
920 BT_ERR("Ret errno: %d", errno);
924 if ((msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) {
925 BT_ERR("MSG Flags errno: %d", errno);
929 BT_INFO("Connection received");
930 *client_fd = __process_cmsg(&msg);
932 BT_ERR("Invalid client_fd received");
937 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
942 int result = BLUETOOTH_ERROR_NONE;
943 bt_event_info_t *event_info;
944 bluetooth_rfcomm_received_data_t data_r;
945 GIOStatus status = G_IO_STATUS_NORMAL;
947 rfcomm_remote_client_info_t *client_info = data;
948 rfcomm_server_info_t *server_info;
950 retv_if(client_info == NULL, FALSE);
952 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
954 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
955 BT_ERR_C("RFComm Server disconnected: %d", client_info->sock_fd);
959 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
960 status = g_io_channel_read_chars(chan, buffer,
961 BT_RFCOMM_BUFFER_LEN, &len, &err);
962 if (status != G_IO_STATUS_NORMAL) {
963 BT_ERR("IO Channel read is failed with %d", status);
966 BT_ERR("IO Channel read error [%s]", err->message);
967 if (status == G_IO_STATUS_ERROR &&
968 !g_strcmp0(err->message, "Connection reset by peer")) {
969 BT_ERR("cond : %d", cond);
979 BT_ERR("Length is zero, remote end hang up");
983 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
984 if (event_info == NULL) {
989 data_r.socket_fd = client_info->sock_fd;
990 data_r.buffer_size = len;
991 data_r.buffer = buffer;
993 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
995 event_info->cb, event_info->user_data);
1002 BT_ERR("Failure occured, remove client connection");
1003 server_info->conn_list = g_slist_remove(
1004 server_info->conn_list, client_info);
1005 __handle_rfcomm_client_disconnected(server_info, client_info);
1006 __remove_remote_client_info(client_info);
1010 static gboolean __new_connection_request_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1017 char buf[BLUETOOTH_SOCK_CONNECT_INFO_LEN];
1018 unsigned char addr[BT_ADDRESS_LENGTH_MAX];
1020 bt_event_info_t *event_info;
1022 rfcomm_remote_client_info_t *rem_client;
1023 rfcomm_server_info_t *server_info = data;
1026 BT_ERR("Server info is invalid");
1030 if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
1031 BT_INFO("RFCOMM Server with fd:%d is closed with cond:0x%X",
1032 server_info->server_fd, cond);
1036 BT_INFO("Server fd: %d", server_info->server_fd);
1037 len = __read_incomming_client_connection(
1038 server_info->server_fd, buf, BLUETOOTH_SOCK_CONNECT_INFO_LEN, &client_fd);
1039 BT_DBG("Socket Read len: %d", len);
1041 BT_ERR("Listen stopped");
1043 } else if (len != BLUETOOTH_SOCK_CONNECT_INFO_LEN) {
1044 BT_ERR("Read length is not same as socket info length");
1049 /* Read size of data */
1050 size = buf[len] | (buf[len + 1] << 8);
1053 /* Read bluetooth address */
1054 memcpy(addr, buf + len, BT_ADDRESS_LENGTH_MAX);
1055 len += BT_ADDRESS_LENGTH_MAX;
1058 channel = buf[len] | (buf[len + 1] << 8) |
1059 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1063 status = buf[len] | (buf[len + 1] << 8) |
1064 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1067 BT_DBG("size: %d, channel: %d, status: %d", size, channel, status);
1069 rem_client = g_malloc0(sizeof(rfcomm_remote_client_info_t));
1070 rem_client->sock_fd = client_fd;
1071 rem_client->server_id = server_info->server_id;
1072 _bt_convert_addr_type_to_string(rem_client->addr, addr);
1074 BT_INFO("New client [%s] connection with socket_fd: %d, server_id: %d",
1075 rem_client->addr, rem_client->sock_fd, rem_client->server_id);
1077 io = g_io_channel_unix_new(rem_client->sock_fd);
1078 g_io_channel_set_encoding(io, NULL, NULL);
1079 g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
1080 rem_client->watch_id = g_io_add_watch(io,
1081 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1082 __data_received_cb, rem_client);
1083 g_io_channel_unref(io);
1085 server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
1086 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
1088 __connected_cb(rem_client, event_info);
1093 /* Error occurred, Remove RFCOMM server*/
1094 __remove_rfcomm_server(server_info);
1098 static int __rfcomm_listen(rfcomm_server_info_t *server_info, bool accept)
1101 GUnixFDList *out_fd_list = NULL;
1102 GIOChannel *server_io;
1104 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1107 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1109 if (accept == false) {
1110 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1111 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
1112 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1114 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1115 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN_AND_ACCEPT,
1116 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1119 BT_DBG("result: %x", result);
1120 if (result != BLUETOOTH_ERROR_NONE) {
1121 BT_ERR("Fail to send request");
1123 } else if (NULL == out_fd_list) {
1124 BT_ERR("out_fd_list is NULL");
1125 return BLUETOOTH_ERROR_INTERNAL;
1131 return BLUETOOTH_ERROR_INTERNAL;
1133 fd_list_array = g_unix_fd_list_steal_fds(out_fd_list, &len);
1134 BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
1135 server_info->server_fd = fd_list_array[0];
1136 BT_INFO("Socket fd: %d", server_info->server_fd);
1138 g_free(fd_list_array);
1139 g_object_unref(out_fd_list);
1142 server_io = g_io_channel_unix_new(server_info->server_fd);
1143 g_io_channel_set_encoding(server_io, NULL, NULL);
1144 g_io_channel_set_flags(server_io, G_IO_FLAG_NONBLOCK, NULL);
1145 server_info->watch_id = g_io_add_watch(server_io,
1146 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1147 __new_connection_request_cb, server_info);
1148 g_io_channel_unref(server_io);
1150 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1152 return BLUETOOTH_ERROR_NONE;
1156 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
1158 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1159 rfcomm_info_t *info;
1161 rfcomm_server_info_t *server_info;
1164 BT_CHECK_ENABLED(return);
1165 BT_CHECK_PARAMETER(uuid, return);
1166 BT_INFO("UUID Provided %s", uuid);
1168 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET)
1169 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1170 BT_ERR("Don't have a privilege to use this API");
1171 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1174 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1175 BT_ERR("Not allow to use SPP profile");
1176 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1179 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1180 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1181 info = __register_method();
1185 info->uuid = g_strdup(uuid);
1186 info->disconnect_idle_id = 0;
1189 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1191 server_info = __get_rfcomm_server_info_with_uuid(uuid);
1193 server_info = g_malloc0(sizeof(rfcomm_server_info_t));
1194 g_strlcpy(server_info->uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1195 server_info->server_id = __rfcomm_assign_server_id();
1196 server_info->server_fd = -1;
1197 server_info->watch_id = -1;
1198 server_info->auto_accept = FALSE;
1199 rfcomm_servers = g_slist_append(rfcomm_servers, server_info);
1201 return server_info->server_id;
1205 BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char *bus_name, const char *path)
1207 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1208 rfcomm_info_t *info;
1210 BT_CHECK_ENABLED(return);
1211 BT_CHECK_PARAMETER(path, return);
1212 BT_INFO("PATH Provided %s", path);
1214 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET_EX)
1215 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1216 BT_ERR("Don't have a privilege to use this API");
1217 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1220 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1221 BT_ERR("Not allow to use SPP profile");
1222 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1225 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1226 info = __register_method_2(path, bus_name);
1228 return BLUETOOTH_ERROR_IN_PROGRESS;
1229 info->uuid = g_strdup(uuid);
1230 info->disconnect_idle_id = 0;
1232 return BLUETOOTH_ERROR_NONE;
1234 return BLUETOOTH_ERROR_NOT_SUPPORT;
1239 BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
1241 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1242 rfcomm_info_t *info;
1244 rfcomm_server_info_t *server_info;
1247 BT_CHECK_ENABLED(return);
1249 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1250 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1251 BT_ERR("Don't have a privilege to use this API");
1252 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1256 BT_ERR("Invalid ID");
1257 return BLUETOOTH_ERROR_INVALID_PARAM;
1260 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1261 BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
1263 info = __find_rfcomm_info_with_id(id);
1265 return BLUETOOTH_ERROR_INVALID_PARAM;
1267 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1268 _bt_unregister_profile(info->path);
1270 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1271 free_rfcomm_info(info);
1273 return BLUETOOTH_ERROR_NONE;
1275 BT_INFO("<<<<<<<<< RFCOMM Remove socket request from app, fd=[%d] >>>>>>>>>>>", socket_fd);
1277 server_info = __get_rfcomm_server_info_with_id(id);
1279 BT_ERR("server_info not found for socket_fd: %d", id);
1280 return BLUETOOTH_ERROR_INVALID_PARAM;
1283 __remove_rfcomm_server(server_info);
1285 return BLUETOOTH_ERROR_NONE;
1289 BT_EXPORT_API int bluetooth_rfcomm_remove_socket_ex(const char *uuid)
1291 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1292 rfcomm_info_t *info;
1294 BT_CHECK_ENABLED(return);
1296 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1297 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1298 BT_ERR("Don't have a privilege to use this API");
1299 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1302 BT_INFO("RFCOMM Remove socket request from app, uuid=[%s]", uuid);
1304 info = __find_rfcomm_info_with_uuid(uuid);
1306 return BLUETOOTH_ERROR_INVALID_PARAM;
1308 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1309 _bt_unregister_profile(info->path);
1311 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1312 free_rfcomm_info(info);
1314 return BLUETOOTH_ERROR_NONE;
1316 return BLUETOOTH_ERROR_NOT_SUPPORT;
1320 BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
1322 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1323 rfcomm_info_t *info;
1324 rfcomm_conn_t *conn;
1328 BT_INFO(" ### Disconnect RFCOMM server");
1329 if (socket_fd < 0) {
1330 BT_ERR("Invalid FD");
1331 return BLUETOOTH_ERROR_INVALID_PARAM;
1334 info = __find_rfcomm_info_with_fd(socket_fd);
1336 return BLUETOOTH_ERROR_INVALID_PARAM;
1338 conn = __find_rfcomm_conn_with_fd(info, socket_fd);
1340 return BLUETOOTH_ERROR_INVALID_PARAM;
1342 if (conn->watch_id == 0 || conn->disconnected)
1343 return BLUETOOTH_ERROR_NOT_CONNECTED;
1346 conn->disconnected = TRUE;
1348 _bt_convert_addr_type_to_string(address, conn->addr.addr);
1350 BT_DBG("Address %s", address);
1351 _bt_disconnect_ext_profile(address, info->path);
1353 if (info->disconnect_idle_id == 0)
1354 info->disconnect_idle_id = g_idle_add(
1355 (GSourceFunc)__rfcomm_server_disconnect, info);
1358 return BLUETOOTH_ERROR_NONE;
1360 rfcomm_remote_client_info_t *client_info;
1362 BT_CHECK_ENABLED(return);
1364 BT_INFO(">>>>>>>>RFCOMM server disconnect request from APP>>>>>>>>>");
1365 if (socket_fd < 0) {
1366 BT_ERR("Invalid FD");
1367 return BLUETOOTH_ERROR_INVALID_PARAM;
1370 client_info = __get_rfcomm_rem_client_info_with_fd(socket_fd);
1372 BT_ERR("client_info not found for socket_fd: %d", socket_fd);
1373 return BLUETOOTH_ERROR_NOT_CONNECTED;
1376 if (client_info->sock_fd) {
1377 shutdown(client_info->sock_fd, SHUT_RDWR);
1378 close(client_info->sock_fd);
1379 client_info->sock_fd = -1;
1382 return BLUETOOTH_ERROR_NONE;
1386 BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uuid)
1389 gboolean available = TRUE;
1390 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
1392 retv_if(uuid == NULL, FALSE);
1393 retv_if(bluetooth_check_adapter() ==
1394 BLUETOOTH_ADAPTER_DISABLED, FALSE);
1397 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1399 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
1400 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
1402 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_IS_UUID_AVAILABLE,
1403 in_param1, in_param2, in_param3, in_param4, &out_param);
1405 BT_DBG("result: %x", result);
1407 if (result == BLUETOOTH_ERROR_NONE)
1408 available = g_array_index(out_param, gboolean, 0);
1410 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1412 BT_DBG("available: %d", available);
1417 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
1419 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1422 rfcomm_info_t *info;
1423 rfcomm_conn_t *conn;
1425 char input_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1426 rfcomm_remote_client_info_t *info;
1429 BT_CHECK_PARAMETER(device_address, return);
1430 BT_CHECK_PARAMETER(connected, return);
1434 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1435 for (l = rfcomm_nodes; l; l = l->next) {
1438 if (info == NULL || info->rfcomm_conns == NULL)
1441 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
1444 if (memcmp(device_address, &conn->addr,
1445 sizeof(bluetooth_device_address_t)))
1449 return BLUETOOTH_ERROR_NONE;
1453 return BLUETOOTH_ERROR_NONE;
1455 _bt_convert_addr_type_to_string(input_addr, (unsigned char *)device_address->addr);
1456 info = __get_rfcomm_rem_client_info_with_addr(input_addr);
1460 return BLUETOOTH_ERROR_NONE;
1464 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
1466 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1467 rfcomm_info_t *info;
1469 rfcomm_server_info_t *server_info;
1472 BT_CHECK_ENABLED(return);
1474 BT_ERR("Invalid ID");
1475 return BLUETOOTH_ERROR_INVALID_PARAM;
1478 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1479 BT_ERR("Not allow to use SPP profile");
1480 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1483 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1484 BT_INFO("RFCOMM Listen & accept from app");
1486 info = __find_rfcomm_info_with_id(id);
1488 return BLUETOOTH_ERROR_INVALID_PARAM;
1490 bt_register_profile_info_t profile_info;
1493 profile_info.authentication = TRUE;
1494 profile_info.authorization = TRUE;
1495 profile_info.obj_path = info->path;
1496 profile_info.role = NULL;
1497 profile_info.service = info->uuid;
1498 profile_info.uuid = info->uuid;
1500 BT_INFO("uuid %s", profile_info.uuid);
1501 result = _bt_register_profile(&profile_info, TRUE);
1505 BT_INFO("<<<<<<<<< RFCOMM Listen & accept from app >>>>>>>>>>>");
1507 server_info = __get_rfcomm_server_info_with_id(id);
1509 BT_ERR("server_info not found for id: %d", id);
1510 return BLUETOOTH_ERROR_INVALID_PARAM;
1513 if (server_info->server_fd >= 0) {
1514 BT_ERR("server already listining");
1515 return BLUETOOTH_ERROR_DEVICE_BUSY;
1518 server_info->max_pending_conn = max_pending_connection;
1519 server_info->auto_accept = TRUE;
1521 return __rfcomm_listen(server_info, true);
1525 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
1526 int max_pending_connection,
1527 const char *bus_name, const char *path)
1529 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1530 rfcomm_info_t *info;
1532 BT_CHECK_ENABLED(return);
1534 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1535 BT_ERR("Not allow to use SPP profile");
1536 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1539 BT_INFO("RFCOMM Listen & accept from app");
1541 info = __find_rfcomm_info_with_uuid(uuid);
1543 return BLUETOOTH_ERROR_INVALID_PARAM;
1545 bt_register_profile_info_t profile_info;
1548 profile_info.authentication = TRUE;
1549 profile_info.authorization = TRUE;
1550 profile_info.obj_path = info->path;
1551 profile_info.role = NULL;
1552 profile_info.service = info->uuid;
1553 profile_info.uuid = info->uuid;
1555 BT_INFO("uuid %s", profile_info.uuid);
1556 result = _bt_register_profile_ex(&profile_info, TRUE, bus_name, path);
1560 return BLUETOOTH_ERROR_NOT_SUPPORT;
1564 BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
1566 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1567 rfcomm_info_t *info;
1569 rfcomm_server_info_t *server_info;
1572 BT_CHECK_ENABLED(return);
1574 BT_ERR("Invalid ID");
1575 return BLUETOOTH_ERROR_INVALID_PARAM;
1578 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1579 BT_ERR("Not allow to use SPP profile");
1580 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1583 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1584 BT_INFO("RFCOMM Listen");
1586 info = __find_rfcomm_info_with_id(id);
1588 return BLUETOOTH_ERROR_INVALID_PARAM;
1590 bt_register_profile_info_t profile_info;
1593 profile_info.authentication = TRUE;
1594 profile_info.authorization = TRUE;
1595 profile_info.obj_path = info->path;
1596 profile_info.role = NULL;
1597 profile_info.service = info->uuid;
1598 profile_info.uuid = info->uuid;
1599 BT_INFO("UUID %s", info->uuid);
1600 BT_INFO("PATH %s", info->path);
1601 result = _bt_register_profile_platform(&profile_info, TRUE);
1602 if (result != BLUETOOTH_ERROR_NONE)
1605 return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
1609 BT_INFO("<<<<<<<<< RFCOMM Listen >>>>>>>>>>>");
1611 server_info = __get_rfcomm_server_info_with_id(id);
1613 BT_ERR("server_info not found for id: %d", id);
1614 return BLUETOOTH_ERROR_INVALID_PARAM;
1617 if (server_info->server_fd >= 0) {
1618 BT_ERR("server already listining");
1619 return BLUETOOTH_ERROR_DEVICE_BUSY;
1622 server_info->max_pending_conn = max_pending_connection;
1623 server_info->auto_accept = FALSE;
1624 return __rfcomm_listen(server_info, false);
1628 BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd)
1631 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1633 rfcomm_server_info_t *server_info;
1636 BT_CHECK_ENABLED(return);
1638 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1639 BT_ERR("Not allow to use SPP profile");
1640 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1643 if (server_fd < 0) {
1644 BT_ERR("Invalid FD");
1645 return BLUETOOTH_ERROR_INVALID_PARAM;
1649 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1651 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1652 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1654 server_info = __get_rfcomm_server_info_with_id(server_fd);
1656 BT_ERR("No server with fd: %d", server_fd);
1657 return BLUETOOTH_ERROR_INVALID_PARAM;
1660 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1663 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_ACCEPT_CONNECTION,
1664 in_param1, in_param2, in_param3, in_param4, &out_param);
1666 BT_DBG("result: %x", result);
1668 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1673 BT_EXPORT_API int bluetooth_rfcomm_reject_connection(int server_fd)
1676 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1678 rfcomm_server_info_t *server_info;
1681 BT_CHECK_ENABLED(return);
1683 if (server_fd < 0) {
1684 BT_ERR("Invalid FD");
1685 return BLUETOOTH_ERROR_INVALID_PARAM;
1691 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1693 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1694 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1696 server_info = __get_rfcomm_server_info_with_id(server_fd);
1698 BT_ERR("No server with fd: %d", server_fd);
1699 return BLUETOOTH_ERROR_INVALID_PARAM;
1702 g_array_append_vals(in_param1, server_info->pending_addr, BT_ADDRESS_STRING_SIZE);
1704 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REJECT_CONNECTION,
1705 in_param1, in_param2, in_param3, in_param4, &out_param);
1707 BT_DBG("result: %x", result);
1709 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);