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);
453 info = g_new0(rfcomm_info_t, 1);
454 info->object_id = (guint)object_id;
458 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
463 static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
468 object_id = _bt_register_new_conn_ex(path, bus_name, new_server_connection);
472 info = g_new0(rfcomm_info_t, 1);
473 info->object_id = (guint)object_id;
474 info->path = g_strdup(path);
477 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
482 void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
484 if (conn->disconnected == FALSE) {
486 conn->disconnected = TRUE;
488 __rfcomm_server_disconnect_conn(conn, info);
491 void free_rfcomm_info(rfcomm_info_t *info)
495 if (info->disconnect_idle_id > 0) {
496 BT_INFO("Disconnect idle still not process remove source");
497 g_source_remove(info->disconnect_idle_id);
498 info->disconnect_idle_id = 0;
501 __rfcomm_delete_id(info->id);
502 _bt_unregister_gdbus(info->object_id);
504 g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
511 void _bt_rfcomm_server_free_all(void)
513 BT_DBG("Free all the servers");
515 g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
519 void _bt_rfcomm_server_disconnect_all(void)
525 BT_INFO(" ### Disconnect all RFCOMM server connections");
527 for (server = rfcomm_nodes; server; ) {
528 rfcomm_info_t *info = server->data;
530 for (conn = info->rfcomm_conns; conn; conn = conn->next) {
531 rfcomm_conn_t *conn_info = conn->data;
533 if (conn_info == NULL)
536 if (conn_info->watch_id == 0 || conn_info->disconnected)
539 close(conn_info->fd);
540 conn_info->disconnected = TRUE;
542 _bt_convert_addr_type_to_string(addr,
543 conn_info->addr.addr);
544 _bt_disconnect_ext_profile(addr, info->path);
547 server = server->next;
548 __rfcomm_server_disconnect(info);
554 void _bt_rfcomm_server_reset_timer(void)
557 g_source_remove(rx_tag);
565 #define BT_RFCOMM_SERVER_ID_MAX 254
568 char addr[BT_ADDRESS_STRING_SIZE];
572 } rfcomm_remote_client_info_t;
575 char uuid[BLUETOOTH_UUID_STRING_MAX];
579 int max_pending_conn;
580 gboolean auto_accept;
581 char pending_addr[BT_ADDRESS_STRING_SIZE];
583 } rfcomm_server_info_t;
585 static GSList *rfcomm_servers;
586 static gboolean id_used[BT_RFCOMM_SERVER_ID_MAX];
589 int __rfcomm_assign_server_id(void)
593 BT_DBG("latest_id: %d", latest_id);
595 index = latest_id + 1;
597 if (index >= BT_RFCOMM_SERVER_ID_MAX)
600 BT_DBG("index: %d", index);
602 while (id_used[index] == TRUE) {
603 if (index == latest_id) {
604 /* No available ID */
605 BT_ERR("All request ID is used");
611 if (index >= BT_RFCOMM_SERVER_ID_MAX)
616 id_used[index] = TRUE;
618 BT_DBG("Assigned Id: %d", latest_id);
623 void __rfcomm_delete_server_id(int id)
625 ret_if(id >= BT_RFCOMM_SERVER_ID_MAX);
630 /* Next server will use this ID */
634 static rfcomm_server_info_t *__get_rfcomm_server_info_with_uuid(const char *uuid)
641 for (l = rfcomm_servers; l != NULL; l = l->next) {
642 rfcomm_server_info_t *info = l->data;
644 if (!strncasecmp(info->uuid, uuid, strlen(info->uuid)))
651 int _get_rfcomm_server_id(char *uuid, gboolean *auto_accept)
653 rfcomm_server_info_t *server_info;
655 server_info = __get_rfcomm_server_info_with_uuid(uuid);
659 *auto_accept = server_info->auto_accept;
660 return server_info->server_id;
663 static rfcomm_server_info_t *__get_rfcomm_server_info_with_id(int server_id)
667 for (l = rfcomm_servers; l != NULL; l = l->next) {
668 rfcomm_server_info_t *info = l->data;
672 BT_DBG("info->server_fd: %d, sock_fd:%d", info->server_id, server_id);
673 if (info->server_id == server_id)
680 void _bt_rfcomm_server_set_pending_conn(int server_id, char *address)
682 rfcomm_server_info_t *server_info;
688 server_info = __get_rfcomm_server_info_with_id(server_id);
692 g_strlcpy(server_info->pending_addr, address, BT_ADDRESS_STRING_SIZE);
695 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_fd(int sock_fd)
700 for (l = rfcomm_servers; l != NULL; l = l->next) {
701 rfcomm_server_info_t *info = l->data;
706 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
707 rfcomm_remote_client_info_t *client_info = l1->data;
711 if (client_info->sock_fd == sock_fd)
719 static rfcomm_remote_client_info_t *__get_rfcomm_rem_client_info_with_addr(char *addr)
724 retv_if(NULL == addr, NULL);
726 for (l = rfcomm_servers; l != NULL; l = l->next) {
727 rfcomm_server_info_t *info = l->data;
732 for (l1 = info->conn_list; l1 != NULL; l1 = l1->next) {
733 rfcomm_remote_client_info_t *client_info = l1->data;
737 if (!strncasecmp(client_info->addr, addr, strlen(client_info->addr)))
745 static void __remove_remote_client_info(rfcomm_remote_client_info_t *rem_client)
749 if (rem_client == NULL)
752 if (0 < rem_client->sock_fd) {
753 shutdown(rem_client->sock_fd, SHUT_RDWR);
754 close(rem_client->sock_fd);
757 if (rem_client->watch_id > 0)
758 g_source_remove(rem_client->watch_id);
765 static void __handle_rfcomm_client_disconnected(rfcomm_server_info_t *server_info,
766 rfcomm_remote_client_info_t *rem_client)
768 bluetooth_rfcomm_disconnection_t disconn_info;
769 bt_event_info_t *event_info;
773 if (rem_client == NULL || server_info == NULL)
776 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
777 if (event_info == NULL)
780 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
781 disconn_info.device_role = RFCOMM_ROLE_SERVER;
782 g_strlcpy(disconn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
783 _bt_convert_addr_string_to_type(disconn_info.device_addr.addr, rem_client->addr);
784 BT_DBG("Disconnected FD [%d]", rem_client->sock_fd);
785 disconn_info.socket_fd = rem_client->sock_fd;
787 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
788 BLUETOOTH_ERROR_NONE, &disconn_info,
789 event_info->cb, event_info->user_data);
792 static void __remove_rfcomm_server(rfcomm_server_info_t *info)
794 rfcomm_remote_client_info_t *client_info;
801 rfcomm_servers = g_slist_remove(rfcomm_servers, info);
802 if (info->conn_list) {
804 client_info = info->conn_list->data;
808 info->conn_list = g_slist_remove(info->conn_list, client_info);
809 __handle_rfcomm_client_disconnected(info, client_info);
810 __remove_remote_client_info(client_info);
811 } while (info->conn_list);
814 if (info->server_fd) {
815 shutdown(info->server_fd, SHUT_RDWR);
816 close(info->server_fd);
820 g_source_remove(info->watch_id);
822 __rfcomm_delete_server_id(info->server_id);
828 static void __connected_cb(rfcomm_remote_client_info_t *client_info, bt_event_info_t *event_info)
830 bluetooth_rfcomm_connection_t conn_info;
831 rfcomm_server_info_t *server_info;
833 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
834 ret_if(server_info == NULL);
836 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
837 conn_info.device_role = RFCOMM_ROLE_SERVER;
838 g_strlcpy(conn_info.uuid, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
839 conn_info.socket_fd = client_info->sock_fd;
840 _bt_convert_addr_string_to_type(conn_info.device_addr.addr, client_info->addr);
841 conn_info.server_id = server_info->server_id;
843 BT_INFO_C("Connected [RFCOMM Server]");
844 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
845 BLUETOOTH_ERROR_NONE, &conn_info,
846 event_info->cb, event_info->user_data);
849 static int __process_cmsg(struct msghdr *msg)
852 struct cmsghdr *cmsg_ptr = NULL;
854 for (cmsg_ptr = CMSG_FIRSTHDR(msg); cmsg_ptr != NULL;
855 cmsg_ptr = CMSG_NXTHDR(msg, cmsg_ptr)) {
857 if (cmsg_ptr->cmsg_level != SOL_SOCKET)
860 if (cmsg_ptr->cmsg_type == SCM_RIGHTS) {
861 //int *desc = (int *)CMSG_DATA(cmsg_ptr);
863 = ((cmsg_ptr->cmsg_len - CMSG_LEN(0)) / sizeof(int));
866 BT_ERR("ERROR Invalid count of descriptors");
871 memcpy(&sock_fd, CMSG_DATA(cmsg_ptr), sizeof(sock_fd));
872 BT_DBG("Remote client fd: %d", sock_fd);
879 static int __read_incomming_client_connection(
880 int server_fd, char *buf, unsigned int len, int *client_fd)
885 struct cmsghdr cmsgbuf[2 * sizeof(struct cmsghdr) + 4];
888 retv_if(0 > server_fd, -1);
889 retv_if(NULL == client_fd, -1);
891 BT_INFO("server_fd = %d", server_fd);
893 memset(&msg, 0, sizeof(msg));
894 memset(&iv, 0, sizeof(iv));
900 msg.msg_control = cmsgbuf;
901 msg.msg_controllen = sizeof(cmsgbuf);
903 for (retryCount = 0; retryCount < 5; retryCount++) {
904 ret = recvmsg(server_fd, &msg, 0);
905 BT_DBG("recvmsg ret = %d", ret);
906 if (ret < 0 && errno == EINTR)
912 if (ret < 0 && errno == EPIPE) {
913 /* End of stream, server listining stopped */
914 BT_ERR("EOS errno: %d", errno);
919 BT_ERR("Ret errno: %d", errno);
923 if ((msg.msg_flags & (MSG_CTRUNC | MSG_OOB | MSG_ERRQUEUE)) != 0) {
924 BT_ERR("MSG Flags errno: %d", errno);
928 BT_INFO("Connection received");
929 *client_fd = __process_cmsg(&msg);
931 BT_ERR("Invalid client_fd received");
936 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
941 int result = BLUETOOTH_ERROR_NONE;
942 bt_event_info_t *event_info;
943 bluetooth_rfcomm_received_data_t data_r;
944 GIOStatus status = G_IO_STATUS_NORMAL;
946 rfcomm_remote_client_info_t *client_info = data;
947 rfcomm_server_info_t *server_info;
949 retv_if(client_info == NULL, FALSE);
951 server_info = __get_rfcomm_server_info_with_id(client_info->server_id);
953 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
954 BT_ERR_C("RFComm Server disconnected: %d", client_info->sock_fd);
958 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
959 status = g_io_channel_read_chars(chan, buffer,
960 BT_RFCOMM_BUFFER_LEN, &len, &err);
961 if (status != G_IO_STATUS_NORMAL) {
962 BT_ERR("IO Channel read is failed with %d", status);
965 BT_ERR("IO Channel read error [%s]", err->message);
966 if (status == G_IO_STATUS_ERROR &&
967 !g_strcmp0(err->message, "Connection reset by peer")) {
968 BT_ERR("cond : %d", cond);
978 BT_ERR("Length is zero, remote end hang up");
982 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
983 if (event_info == NULL) {
988 data_r.socket_fd = client_info->sock_fd;
989 data_r.buffer_size = len;
990 data_r.buffer = buffer;
992 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
994 event_info->cb, event_info->user_data);
1001 BT_ERR("Failure occured, remove client connection");
1002 server_info->conn_list = g_slist_remove(
1003 server_info->conn_list, client_info);
1004 __handle_rfcomm_client_disconnected(server_info, client_info);
1005 __remove_remote_client_info(client_info);
1009 static gboolean __new_connection_request_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
1016 char buf[BLUETOOTH_SOCK_CONNECT_INFO_LEN];
1017 unsigned char addr[BT_ADDRESS_LENGTH_MAX];
1019 bt_event_info_t *event_info;
1021 rfcomm_remote_client_info_t *rem_client;
1022 rfcomm_server_info_t *server_info = data;
1025 BT_ERR("Server info is invalid");
1029 if (cond & (G_IO_HUP | G_IO_ERR | G_IO_NVAL)) {
1030 BT_INFO("RFCOMM Server with fd:%d is closed with cond:0x%X",
1031 server_info->server_fd, cond);
1035 BT_INFO("Server fd: %d", server_info->server_fd);
1036 len = __read_incomming_client_connection(
1037 server_info->server_fd, buf, BLUETOOTH_SOCK_CONNECT_INFO_LEN, &client_fd);
1038 BT_DBG("Socket Read len: %d", len);
1040 BT_ERR("Listen stopped");
1042 } else if (len != BLUETOOTH_SOCK_CONNECT_INFO_LEN) {
1043 BT_ERR("Read length is not same as socket info length");
1048 /* Read size of data */
1049 size = buf[len] | (buf[len + 1] << 8);
1052 /* Read bluetooth address */
1053 memcpy(addr, buf + len, BT_ADDRESS_LENGTH_MAX);
1054 len += BT_ADDRESS_LENGTH_MAX;
1057 channel = buf[len] | (buf[len + 1] << 8) |
1058 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1062 status = buf[len] | (buf[len + 1] << 8) |
1063 (buf[len + 2] << 16) | (buf[len + 3] << 24);
1066 BT_DBG("size: %d, channel: %d, status: %d", size, channel, status);
1068 rem_client = g_malloc0(sizeof(rfcomm_remote_client_info_t));
1069 rem_client->sock_fd = client_fd;
1070 rem_client->server_id = server_info->server_id;
1071 _bt_convert_addr_type_to_string(rem_client->addr, addr);
1073 BT_INFO("New client [%s] connection with socket_fd: %d, server_id: %d",
1074 rem_client->addr, rem_client->sock_fd, rem_client->server_id);
1076 io = g_io_channel_unix_new(rem_client->sock_fd);
1077 g_io_channel_set_encoding(io, NULL, NULL);
1078 g_io_channel_set_flags(io, G_IO_FLAG_NONBLOCK, NULL);
1079 rem_client->watch_id = g_io_add_watch(io,
1080 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1081 __data_received_cb, rem_client);
1082 g_io_channel_unref(io);
1084 server_info->conn_list = g_slist_append(server_info->conn_list, rem_client);
1085 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
1087 __connected_cb(rem_client, event_info);
1092 /* Error occurred, Remove RFCOMM server*/
1093 __remove_rfcomm_server(server_info);
1097 static int __rfcomm_listen(rfcomm_server_info_t *server_info, bool accept)
1100 GUnixFDList *out_fd_list = NULL;
1101 GIOChannel *server_io;
1103 retv_if(server_info == NULL, BLUETOOTH_ERROR_INTERNAL);
1106 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1108 if (accept == false) {
1109 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1110 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
1111 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1113 g_array_append_vals(in_param1, server_info->uuid, BLUETOOTH_UUID_STRING_MAX);
1114 result = _bt_send_request_with_unix_fd_list(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN_AND_ACCEPT,
1115 in_param1, in_param2, in_param3, in_param4, NULL, &out_param, &out_fd_list);
1118 BT_DBG("result: %x", result);
1119 if (result != BLUETOOTH_ERROR_NONE) {
1120 BT_ERR("Fail to send request");
1122 } else if (NULL == out_fd_list) {
1123 BT_ERR("out_fd_list is NULL");
1124 return BLUETOOTH_ERROR_INTERNAL;
1130 return BLUETOOTH_ERROR_INTERNAL;
1132 fd_list_array = g_unix_fd_list_steal_fds(out_fd_list, &len);
1133 BT_INFO("Num fds in fd_list is : %d, fd_list[0]: %d", len, fd_list_array[0]);
1134 server_info->server_fd = fd_list_array[0];
1135 BT_INFO("Socket fd: %d", server_info->server_fd);
1137 g_free(fd_list_array);
1138 g_object_unref(out_fd_list);
1141 server_io = g_io_channel_unix_new(server_info->server_fd);
1142 g_io_channel_set_encoding(server_io, NULL, NULL);
1143 g_io_channel_set_flags(server_io, G_IO_FLAG_NONBLOCK, NULL);
1144 server_info->watch_id = g_io_add_watch(server_io,
1145 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
1146 __new_connection_request_cb, server_info);
1147 g_io_channel_unref(server_io);
1149 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1151 return BLUETOOTH_ERROR_NONE;
1155 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
1157 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1158 rfcomm_info_t *info;
1160 rfcomm_server_info_t *server_info;
1163 BT_CHECK_ENABLED(return);
1164 BT_CHECK_PARAMETER(uuid, return);
1165 BT_INFO("UUID Provided %s", uuid);
1167 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET)
1168 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1169 BT_ERR("Don't have a privilege to use this API");
1170 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1173 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1174 BT_ERR("Not allow to use SPP profile");
1175 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1178 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1179 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1180 info = __register_method();
1184 info->uuid = g_strdup(uuid);
1185 info->disconnect_idle_id = 0;
1188 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1190 server_info = __get_rfcomm_server_info_with_uuid(uuid);
1192 server_info = g_malloc0(sizeof(rfcomm_server_info_t));
1193 g_strlcpy(server_info->uuid, uuid, BLUETOOTH_UUID_STRING_MAX);
1194 server_info->server_id = __rfcomm_assign_server_id();
1195 server_info->server_fd = -1;
1196 server_info->watch_id = -1;
1197 server_info->auto_accept = FALSE;
1198 rfcomm_servers = g_slist_append(rfcomm_servers, server_info);
1200 return server_info->server_id;
1204 BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char *bus_name, const char *path)
1206 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1207 rfcomm_info_t *info;
1209 BT_CHECK_ENABLED(return);
1210 BT_CHECK_PARAMETER(path, return);
1211 BT_INFO("PATH Provided %s", path);
1213 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_CREATE_SOCKET_EX)
1214 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1215 BT_ERR("Don't have a privilege to use this API");
1216 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1219 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1220 BT_ERR("Not allow to use SPP profile");
1221 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1224 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
1225 info = __register_method_2(path, bus_name);
1227 return BLUETOOTH_ERROR_IN_PROGRESS;
1228 info->uuid = g_strdup(uuid);
1229 info->disconnect_idle_id = 0;
1231 return BLUETOOTH_ERROR_NONE;
1233 return BLUETOOTH_ERROR_NOT_SUPPORT;
1238 BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
1240 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1241 rfcomm_info_t *info;
1243 rfcomm_server_info_t *server_info;
1246 BT_CHECK_ENABLED(return);
1248 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1249 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1250 BT_ERR("Don't have a privilege to use this API");
1251 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1255 BT_ERR("Invalid ID");
1256 return BLUETOOTH_ERROR_INVALID_PARAM;
1259 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1260 BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
1262 info = __find_rfcomm_info_with_id(id);
1264 return BLUETOOTH_ERROR_INVALID_PARAM;
1266 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1267 _bt_unregister_profile(info->path);
1269 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1270 free_rfcomm_info(info);
1272 return BLUETOOTH_ERROR_NONE;
1274 BT_INFO("<<<<<<<<< RFCOMM Remove socket request from app, fd=[%d] >>>>>>>>>>>", socket_fd);
1276 server_info = __get_rfcomm_server_info_with_id(id);
1278 BT_ERR("server_info not found for socket_fd: %d", id);
1279 return BLUETOOTH_ERROR_INVALID_PARAM;
1282 __remove_rfcomm_server(server_info);
1284 return BLUETOOTH_ERROR_NONE;
1288 BT_EXPORT_API int bluetooth_rfcomm_remove_socket_ex(const char *uuid)
1290 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1291 rfcomm_info_t *info;
1293 BT_CHECK_ENABLED(return);
1295 if (_bt_check_privilege(BT_CHECK_PRIVILEGE, BT_RFCOMM_REMOVE_SOCKET)
1296 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
1297 BT_ERR("Don't have a privilege to use this API");
1298 return BLUETOOTH_ERROR_PERMISSION_DEINED;
1301 BT_INFO("RFCOMM Remove socket request from app, uuid=[%s]", uuid);
1303 info = __find_rfcomm_info_with_uuid(uuid);
1305 return BLUETOOTH_ERROR_INVALID_PARAM;
1307 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
1308 _bt_unregister_profile(info->path);
1310 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
1311 free_rfcomm_info(info);
1313 return BLUETOOTH_ERROR_NONE;
1315 return BLUETOOTH_ERROR_NOT_SUPPORT;
1319 BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
1321 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1322 rfcomm_info_t *info;
1323 rfcomm_conn_t *conn;
1327 BT_INFO(" ### Disconnect RFCOMM server");
1328 if (socket_fd < 0) {
1329 BT_ERR("Invalid FD");
1330 return BLUETOOTH_ERROR_INVALID_PARAM;
1333 info = __find_rfcomm_info_with_fd(socket_fd);
1335 return BLUETOOTH_ERROR_INVALID_PARAM;
1337 conn = __find_rfcomm_conn_with_fd(info, socket_fd);
1339 return BLUETOOTH_ERROR_INVALID_PARAM;
1341 if (conn->watch_id == 0 || conn->disconnected)
1342 return BLUETOOTH_ERROR_NOT_CONNECTED;
1345 conn->disconnected = TRUE;
1347 _bt_convert_addr_type_to_string(address, conn->addr.addr);
1349 BT_DBG("Address %s", address);
1350 _bt_disconnect_ext_profile(address, info->path);
1352 if (info->disconnect_idle_id == 0)
1353 info->disconnect_idle_id = g_idle_add(
1354 (GSourceFunc)__rfcomm_server_disconnect, info);
1357 return BLUETOOTH_ERROR_NONE;
1359 rfcomm_remote_client_info_t *client_info;
1361 BT_CHECK_ENABLED(return);
1363 BT_INFO(">>>>>>>>RFCOMM server disconnect request from APP>>>>>>>>>");
1364 if (socket_fd < 0) {
1365 BT_ERR("Invalid FD");
1366 return BLUETOOTH_ERROR_INVALID_PARAM;
1369 client_info = __get_rfcomm_rem_client_info_with_fd(socket_fd);
1371 BT_ERR("client_info not found for socket_fd: %d", socket_fd);
1372 return BLUETOOTH_ERROR_NOT_CONNECTED;
1375 if (client_info->sock_fd) {
1376 shutdown(client_info->sock_fd, SHUT_RDWR);
1377 close(client_info->sock_fd);
1378 client_info->sock_fd = -1;
1381 return BLUETOOTH_ERROR_NONE;
1385 BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uuid)
1388 gboolean available = TRUE;
1389 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
1391 retv_if(uuid == NULL, FALSE);
1392 retv_if(bluetooth_check_adapter() ==
1393 BLUETOOTH_ADAPTER_DISABLED, FALSE);
1396 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1398 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
1399 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
1401 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_IS_UUID_AVAILABLE,
1402 in_param1, in_param2, in_param3, in_param4, &out_param);
1404 BT_DBG("result: %x", result);
1406 if (result == BLUETOOTH_ERROR_NONE)
1407 available = g_array_index(out_param, gboolean, 0);
1409 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1411 BT_DBG("available: %d", available);
1416 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
1418 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1421 rfcomm_info_t *info;
1422 rfcomm_conn_t *conn;
1424 char input_addr[BT_ADDRESS_STRING_SIZE] = { 0 };
1425 rfcomm_remote_client_info_t *info;
1428 BT_CHECK_PARAMETER(device_address, return);
1429 BT_CHECK_PARAMETER(connected, return);
1433 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1434 for (l = rfcomm_nodes; l; l = l->next) {
1437 if (info == NULL || info->rfcomm_conns == NULL)
1440 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
1443 if (memcmp(device_address, &conn->addr,
1444 sizeof(bluetooth_device_address_t)))
1448 return BLUETOOTH_ERROR_NONE;
1452 return BLUETOOTH_ERROR_NONE;
1454 _bt_convert_addr_type_to_string(input_addr, (unsigned char *)device_address->addr);
1455 info = __get_rfcomm_rem_client_info_with_addr(input_addr);
1459 return BLUETOOTH_ERROR_NONE;
1463 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
1465 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1466 rfcomm_info_t *info;
1468 rfcomm_server_info_t *server_info;
1471 BT_CHECK_ENABLED(return);
1473 BT_ERR("Invalid ID");
1474 return BLUETOOTH_ERROR_INVALID_PARAM;
1477 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1478 BT_ERR("Not allow to use SPP profile");
1479 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1482 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1483 BT_INFO("RFCOMM Listen & accept from app");
1485 info = __find_rfcomm_info_with_id(id);
1487 return BLUETOOTH_ERROR_INVALID_PARAM;
1489 bt_register_profile_info_t profile_info;
1492 profile_info.authentication = TRUE;
1493 profile_info.authorization = TRUE;
1494 profile_info.obj_path = info->path;
1495 profile_info.role = NULL;
1496 profile_info.service = info->uuid;
1497 profile_info.uuid = info->uuid;
1499 BT_INFO("uuid %s", profile_info.uuid);
1500 result = _bt_register_profile(&profile_info, TRUE);
1504 BT_INFO("<<<<<<<<< RFCOMM Listen & accept from app >>>>>>>>>>>");
1506 server_info = __get_rfcomm_server_info_with_id(id);
1508 BT_ERR("server_info not found for id: %d", id);
1509 return BLUETOOTH_ERROR_INVALID_PARAM;
1512 if (server_info->server_fd >= 0) {
1513 BT_ERR("server already listining");
1514 return BLUETOOTH_ERROR_DEVICE_BUSY;
1517 server_info->max_pending_conn = max_pending_connection;
1518 server_info->auto_accept = TRUE;
1520 return __rfcomm_listen(server_info, true);
1524 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
1525 int max_pending_connection,
1526 const char *bus_name, const char *path)
1528 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1529 rfcomm_info_t *info;
1531 BT_CHECK_ENABLED(return);
1533 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1534 BT_ERR("Not allow to use SPP profile");
1535 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1538 BT_INFO("RFCOMM Listen & accept from app");
1540 info = __find_rfcomm_info_with_uuid(uuid);
1542 return BLUETOOTH_ERROR_INVALID_PARAM;
1544 bt_register_profile_info_t profile_info;
1547 profile_info.authentication = TRUE;
1548 profile_info.authorization = TRUE;
1549 profile_info.obj_path = info->path;
1550 profile_info.role = NULL;
1551 profile_info.service = info->uuid;
1552 profile_info.uuid = info->uuid;
1554 BT_INFO("uuid %s", profile_info.uuid);
1555 result = _bt_register_profile_ex(&profile_info, TRUE, bus_name, path);
1559 return BLUETOOTH_ERROR_NOT_SUPPORT;
1563 BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
1565 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1566 rfcomm_info_t *info;
1568 rfcomm_server_info_t *server_info;
1571 BT_CHECK_ENABLED(return);
1573 BT_ERR("Invalid ID");
1574 return BLUETOOTH_ERROR_INVALID_PARAM;
1577 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1578 BT_ERR("Not allow to use SPP profile");
1579 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1582 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1583 BT_INFO("RFCOMM Listen");
1585 info = __find_rfcomm_info_with_id(id);
1587 return BLUETOOTH_ERROR_INVALID_PARAM;
1589 bt_register_profile_info_t profile_info;
1592 profile_info.authentication = TRUE;
1593 profile_info.authorization = TRUE;
1594 profile_info.obj_path = info->path;
1595 profile_info.role = NULL;
1596 profile_info.service = info->uuid;
1597 profile_info.uuid = info->uuid;
1598 BT_INFO("UUID %s", info->uuid);
1599 BT_INFO("PATH %s", info->path);
1600 result = _bt_register_profile_platform(&profile_info, TRUE);
1601 if (result != BLUETOOTH_ERROR_NONE)
1604 return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
1608 BT_INFO("<<<<<<<<< RFCOMM Listen >>>>>>>>>>>");
1610 server_info = __get_rfcomm_server_info_with_id(id);
1612 BT_ERR("server_info not found for id: %d", id);
1613 return BLUETOOTH_ERROR_INVALID_PARAM;
1616 if (server_info->server_fd >= 0) {
1617 BT_ERR("server already listining");
1618 return BLUETOOTH_ERROR_DEVICE_BUSY;
1621 server_info->max_pending_conn = max_pending_connection;
1622 server_info->auto_accept = FALSE;
1623 return __rfcomm_listen(server_info, false);
1627 BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd)
1630 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
1632 rfcomm_server_info_t *server_info;
1635 BT_CHECK_ENABLED(return);
1637 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1638 BT_ERR("Not allow to use SPP profile");
1639 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);