4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <dbus/dbus-glib.h>
21 #include <dbus/dbus.h>
25 #include <sys/socket.h>
28 #include "bluetooth-api.h"
29 #include "bt-internal-types.h"
31 #include "bt-service-common.h"
32 #include "bt-service-event.h"
33 #include "bt-service-util.h"
34 #include "bt-service-rfcomm-client.h"
35 #include "bt-service-rfcomm-server.h"
36 #include "bt-service-agent.h"
38 /* Range of RFCOMM server ID : 0 ~ 244 */
39 #define BT_RFCOMM_SERVER_ID_MAX 245
41 #define BT_RFCOMM_PROXY_ADDRESS "x00/bluez/rfcomm"
42 #define BT_RFCOMM_SOCKET_ADDRESS "/bluez/rfcomm"
48 } bt_rfcomm_event_info_t;
51 static int latest_id = -1;
52 static gboolean server_id_used[BT_RFCOMM_SERVER_ID_MAX];
54 int __bt_rfcomm_assign_server_id(void)
58 BT_DBG("latest_id: %d", latest_id);
60 index = latest_id + 1;
62 if (index >= BT_RFCOMM_SERVER_ID_MAX)
65 BT_DBG("index: %d", index);
67 while (server_id_used[index] == TRUE) {
68 if (index == latest_id) {
70 BT_DBG("All request ID is used");
76 if (index >= BT_RFCOMM_SERVER_ID_MAX)
81 server_id_used[index] = TRUE;
83 BT_DBG("Assigned Id: %d", latest_id);
88 void __bt_rfcomm_delete_server_id(int server_id)
90 ret_if(server_id >= BT_RFCOMM_SERVER_ID_MAX);
91 ret_if(server_id < 0);
93 server_id_used[server_id] = FALSE;
95 /* Next server will use this ID */
96 latest_id = server_id - 1;
100 static bt_rfcomm_server_info_t *__bt_rfcomm_get_server_info(int control_fd)
103 bt_rfcomm_server_info_t *server_info;
105 retv_if(control_fd <= 0, NULL);
107 for (l = server_list; l != NULL; l = l->next) {
108 server_info = l->data;
110 if (server_info == NULL)
113 if (control_fd == server_info->control_fd)
120 static bt_rfcomm_server_info_t *__bt_rfcomm_get_server_info_using_data_fd(int data_fd)
123 bt_rfcomm_server_info_t *server_info;
125 retv_if(data_fd <= 0, NULL);
127 for (l = server_list; l != NULL; l = l->next) {
128 server_info = l->data;
130 if (server_info == NULL)
133 if (data_fd == server_info->data_fd)
140 static DBusGProxy *__bt_rfcomm_get_serial_manager_proxy(void)
143 DBusGConnection *g_conn;
148 g_conn = _bt_get_system_gconn();
149 retv_if(g_conn == NULL, NULL);
151 adapter_path = _bt_get_adapter_path();
152 retv_if(adapter_path == NULL, NULL);
154 proxy = dbus_g_proxy_new_for_name(g_conn, BT_BLUEZ_NAME,
155 adapter_path, BT_SERIAL_MANAGER_INTERFACE);
157 g_free(adapter_path);
164 static DBusGProxy *__bt_get_serial_proxy(char *serial_path)
167 DBusGConnection *g_conn;
169 g_conn = _bt_get_system_gconn();
170 retv_if(g_conn == NULL, NULL);
172 proxy = dbus_g_proxy_new_for_name(g_conn, BT_BLUEZ_NAME,
173 serial_path, BT_SERIAL_PROXY_INTERFACE);
178 static char *__bt_rfcomm_get_proxy_address(int server_id)
182 return g_strdup_printf("%s%d",
183 BT_RFCOMM_PROXY_ADDRESS,
187 int __bt_rfcomm_get_socket(int server_id)
191 char *socket_address = NULL;
192 struct sockaddr_un server_addr;
194 retv_if(server_id < 0, -1);
196 socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
197 retv_if(socket_fd < 0, -1);
199 memset(&server_addr, 0, sizeof(server_addr));
200 server_addr.sun_family = PF_UNIX;
202 socket_address = g_strdup_printf("%s%d",
203 BT_RFCOMM_SOCKET_ADDRESS,
206 BT_DBG("socket_address: %s", socket_address);
208 g_strlcpy(server_addr.sun_path + 1, socket_address,
209 sizeof(server_addr.sun_path));
211 if (bind(socket_fd, (struct sockaddr *)&server_addr,
212 sizeof(server_addr)) < 0) {
213 BT_ERR("Can't Bind Sock");
217 BT_DBG("socket_fd = %d", socket_fd);
219 result = _bt_set_socket_non_blocking(socket_fd);
221 if (result != BLUETOOTH_ERROR_NONE) {
222 BT_DBG("Cannot set the tty");
226 g_free(socket_address);
229 g_free(socket_address);
234 int _bt_rfcomm_create_socket(char *sender, char *uuid)
236 DBusGProxy *serial_manager = NULL;
237 DBusGProxy *serial_proxy = NULL;
238 GError *error = NULL;
239 char *proxy_address = NULL;
240 char *serial_path = NULL;
243 bt_rfcomm_server_info_t *server_info;
245 BT_CHECK_PARAMETER(uuid, return);
247 server_id = __bt_rfcomm_assign_server_id();
248 retv_if(server_id < 0, BLUETOOTH_ERROR_INTERNAL);
250 serial_manager = __bt_rfcomm_get_serial_manager_proxy();
251 if (serial_manager == NULL)
254 proxy_address = __bt_rfcomm_get_proxy_address(server_id);
255 if (proxy_address == NULL)
258 dbus_g_proxy_call(serial_manager, "CreateProxy", NULL,
260 G_TYPE_STRING, proxy_address,
262 G_TYPE_STRING, &serial_path,
265 if (serial_path == NULL)
268 BT_DBG("serial_path: %s", serial_path);
270 serial_proxy = __bt_get_serial_proxy(serial_path);
271 if (serial_proxy == NULL)
274 if (!dbus_g_proxy_call(serial_proxy, "Enable", &error,
275 G_TYPE_INVALID, G_TYPE_INVALID)) {
277 BT_ERR("Enable Error: %s\n", error->message);
280 g_object_unref(serial_proxy);
284 socket_fd = __bt_rfcomm_get_socket(server_id);
286 BT_DBG("Can't get socket");
290 server_info = g_malloc0(sizeof(bt_rfcomm_server_info_t));
291 server_info->server_id = server_id;
292 server_info->serial_proxy = serial_proxy;
293 server_info->manager_proxy = serial_manager;
294 server_info->serial_path = g_strdup(serial_path);
295 server_info->uuid = g_strdup(uuid);
296 server_info->sender = g_strdup(sender);
297 server_info->control_fd = socket_fd;
299 server_list = g_slist_append(server_list, server_info);
301 g_free(proxy_address);
305 __bt_rfcomm_delete_server_id(server_id);
306 g_free(proxy_address);
308 if (serial_manager) {
310 dbus_g_proxy_call(serial_manager, "RemoveProxy", NULL,
311 G_TYPE_STRING, serial_path,
315 g_object_unref(serial_manager);
319 g_object_unref(serial_proxy);
321 return BLUETOOTH_ERROR_INTERNAL;
324 static gboolean __bt_rfcomm_server_data_received_cb(GIOChannel *chan,
330 int result = BLUETOOTH_ERROR_NONE;
331 bt_rfcomm_server_info_t *server_info = data;
333 retv_if(server_info == NULL, FALSE);
335 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
336 BT_ERR("Unix server disconnected: %d", server_info->data_fd);
337 _bt_rfcomm_server_disconnect(server_info->data_fd);
341 buffer = g_malloc0(BT_RFCOMM_BUFFER_MAX + 1);
343 if (g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_MAX, &len, NULL) ==
345 BT_ERR("IO Channel read error server");
347 _bt_rfcomm_server_disconnect(server_info->data_fd);
352 BT_ERR("Read failed len=%d, fd=%d\n",
353 len, server_info->data_fd);
355 _bt_rfcomm_server_disconnect(server_info->data_fd);
359 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
360 BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
361 DBUS_TYPE_INT32, &result,
362 DBUS_TYPE_INT16, &server_info->data_fd,
363 DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE,
372 int __bt_rfcomm_server_get_address(bt_rfcomm_server_info_t *server_info)
377 DBusMessageIter reply_iter;
378 DBusMessageIter reply_iter_entry;
379 DBusConnection *conn;
380 const char *property;
382 BT_CHECK_PARAMETER(server_info, return);
384 /* GetInfo Proxy Part */
385 msg = dbus_message_new_method_call(BT_BLUEZ_NAME,
386 server_info->serial_path,
387 BT_SERIAL_PROXY_INTERFACE,
390 retv_if(msg == NULL, BLUETOOTH_ERROR_INTERNAL);
392 dbus_error_init(&error);
394 conn = _bt_get_system_conn();
396 reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &error);
397 dbus_message_unref(msg);
400 BT_ERR("Can't Call GetInfo Proxy");
401 if (dbus_error_is_set(&error)) {
402 BT_ERR("%s", error.message);
403 dbus_error_free(&error);
405 return BLUETOOTH_ERROR_INTERNAL;
408 dbus_message_iter_init(reply, &reply_iter);
410 if (dbus_message_iter_get_arg_type(&reply_iter) != DBUS_TYPE_ARRAY) {
411 BT_ERR("Can't get reply arguments - DBUS_TYPE_ARRAY");
415 dbus_message_iter_recurse(&reply_iter, &reply_iter_entry);
418 while (dbus_message_iter_get_arg_type(&reply_iter_entry) ==
419 DBUS_TYPE_DICT_ENTRY) {
420 DBusMessageIter dict_entry;
421 DBusMessageIter dict_entry_val;
423 dbus_message_iter_recurse(&reply_iter_entry, &dict_entry);
425 dbus_message_iter_get_basic(&dict_entry, &property);
427 if (g_strcmp0("connected", property) == 0) {
430 dbus_message_iter_next(&dict_entry);
431 dbus_message_iter_recurse(&dict_entry, &dict_entry_val);
432 dbus_message_iter_get_basic(&dict_entry_val, &value);
437 /*Parsing the address */
438 dbus_message_iter_next(&reply_iter_entry);
439 dbus_message_iter_recurse(&reply_iter_entry, &dict_entry);
440 dbus_message_iter_get_basic(&dict_entry, &property);
441 BT_DBG("String received...... = %s", property);
443 if (g_strcmp0("address", property) == 0) {
444 if (!dbus_message_iter_next(&dict_entry)) {
445 BT_ERR("Failed getting next dict entry\n");
449 if (dbus_message_iter_get_arg_type(&dict_entry) !=
451 BT_ERR("Failed get arg type varient\n");
455 /*Getting the value of the varient*/
456 dbus_message_iter_recurse(&dict_entry,
459 if (dbus_message_iter_get_arg_type(&dict_entry_val) !=
461 BT_ERR("Failed get arg type string\n");
465 /*get value string address*/
466 dbus_message_iter_get_basic(&dict_entry_val, &property);
468 BT_DBG("Address = %s\n", property);
470 g_free(server_info->remote_address);
471 server_info->remote_address = g_strdup(property);
476 dbus_message_iter_next(&reply_iter_entry);
479 dbus_message_unref(reply);
481 return BLUETOOTH_ERROR_NONE;
484 dbus_message_unref(reply);
485 return BLUETOOTH_ERROR_INTERNAL;
488 static gboolean __bt_rfcomm_server_connected_cb(GIOChannel *chan,
492 bt_rfcomm_server_info_t *server_info;
493 request_info_t *req_info;
496 struct sockaddr_un sock_addr;
497 int result = BLUETOOTH_ERROR_NONE;
499 BT_DBG("rfcomm_server.server_io_channel has %d", cond);
502 retv_if(server_info == NULL, FALSE);
504 if (cond & G_IO_NVAL)
507 if (cond & (G_IO_HUP | G_IO_ERR)) {
508 _bt_rfcomm_remove_socket(server_info->control_fd);
512 memset(&sock_addr, 0, sizeof(struct sockaddr_un));
513 addr_len = sizeof(struct sockaddr_un);
515 client_sock = accept(server_info->control_fd,
516 (struct sockaddr *)&sock_addr,
517 (socklen_t *)&addr_len);
519 if (client_sock < 0) {
520 BT_ERR("Server Accept Error");
524 BT_DBG("Accept Client Sock.(%d)\n", client_sock);
528 if (_bt_set_non_blocking_tty(client_sock) < 0) {
529 /* Even if setting the tty fails we will continue */
530 BT_ERR("Setting the tty properties failed(%d)\n", client_sock);
533 server_info->data_fd = client_sock;
534 server_info->data_io = g_io_channel_unix_new(client_sock);
536 g_io_channel_set_encoding(server_info->data_io, NULL, NULL);
537 g_io_channel_set_flags(server_info->data_io, G_IO_FLAG_NONBLOCK, NULL);
538 g_io_channel_set_close_on_unref(server_info->data_io, TRUE);
540 server_info->data_id =
541 g_io_add_watch(server_info->data_io,
542 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
543 __bt_rfcomm_server_data_received_cb, server_info);
545 g_io_channel_unref(server_info->data_io);
547 __bt_rfcomm_server_get_address(server_info);
549 if (server_info->remote_address == NULL)
550 server_info->remote_address = g_strdup("");
552 if (server_info->server_type == BT_CUSTOM_SERVER) {
557 req_info = _bt_get_request_info(server_info->accept_id);
558 if (req_info == NULL || req_info->context == NULL) {
559 BT_DBG("info is NULL");
563 server_info->accept_id = 0;
564 result = BLUETOOTH_ERROR_NONE;
566 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
567 out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
569 g_array_append_vals(out_param1, &server_info->data_fd,
571 g_array_append_vals(out_param2, &result, sizeof(int));
573 dbus_g_method_return(req_info->context, out_param1, out_param2);
575 g_array_free(out_param1, TRUE);
576 g_array_free(out_param2, TRUE);
578 _bt_delete_request_list(req_info->req_id);
582 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
583 BLUETOOTH_EVENT_RFCOMM_CONNECTED,
584 DBUS_TYPE_INT32, &result,
585 DBUS_TYPE_STRING, &server_info->remote_address,
586 DBUS_TYPE_STRING, &server_info->uuid,
587 DBUS_TYPE_INT16, &server_info->data_fd,
595 int _bt_rfcomm_listen(int socket_fd, int max_pending, gboolean is_native)
598 bt_rfcomm_server_info_t *server_info;
599 GIOChannel *io_channel;
601 server_info = __bt_rfcomm_get_server_info(socket_fd);
602 retv_if(server_info == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
603 retv_if(server_info->control_io != NULL, BLUETOOTH_ERROR_DEVICE_BUSY);
605 if (listen(socket_fd, max_pending) != 0) {
606 BT_DBG("Fail to listen");
607 return BLUETOOTH_ERROR_INTERNAL;
610 io_channel = g_io_channel_unix_new(socket_fd);
611 server_info->control_io = io_channel;
613 g_io_channel_set_close_on_unref(io_channel, TRUE);
614 g_io_channel_set_encoding(io_channel, NULL, NULL);
615 g_io_channel_set_flags(io_channel, G_IO_FLAG_NONBLOCK, NULL);
617 io_id = g_io_add_watch(io_channel,
618 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
619 __bt_rfcomm_server_connected_cb,
622 server_info->control_id = io_id;
623 g_io_channel_unref(io_channel);
625 /* BT_CUSTOM_SERVER / BT_NATIVE_SERVER*/
627 server_info->server_type = BT_NATIVE_SERVER;
629 server_info->server_type = BT_CUSTOM_SERVER;
630 _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER,
634 return BLUETOOTH_ERROR_NONE;
637 int _bt_rfcomm_remove_socket(int socket_fd)
639 bt_rfcomm_server_info_t *server_info;
640 int result = BLUETOOTH_ERROR_NONE;
644 server_info = __bt_rfcomm_get_server_info(socket_fd);
645 retv_if(server_info == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
647 if (server_info->serial_proxy) {
648 if (!dbus_g_proxy_call(server_info->serial_proxy, "Disable",
652 BT_DBG("Fail to disable");
656 if (server_info->manager_proxy && server_info->serial_path) {
657 if (!dbus_g_proxy_call(server_info->manager_proxy,
659 G_TYPE_STRING, server_info->serial_path,
662 BT_DBG("Fail to remove proxy");
666 if (server_info->server_type == BT_CUSTOM_SERVER) {
667 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER,
671 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
672 BLUETOOTH_EVENT_RFCOMM_SERVER_REMOVED,
673 DBUS_TYPE_INT32, &result,
674 DBUS_TYPE_INT16, &server_info->data_fd,
677 _bt_rfcomm_server_disconnect(server_info->data_fd);
679 if (server_info->control_id > 0)
680 g_source_remove(server_info->control_id);
682 if (server_info->control_fd > 0)
683 close(server_info->control_fd);
685 server_list = g_slist_remove(server_list, server_info);
687 __bt_rfcomm_delete_server_id(server_info->server_id);
689 g_free(server_info->serial_path);
690 g_free(server_info->uuid);
691 g_free(server_info->sender);
696 return BLUETOOTH_ERROR_NONE;
699 static int __bt_rfcomm_server_disconnect_cb(void *data)
701 bt_rfcomm_event_info_t *event_info = data;
702 int result = BLUETOOTH_ERROR_NONE;
704 retv_if(event_info == NULL, BLUETOOTH_ERROR_NONE);
705 retv_if(event_info->uuid == NULL, BLUETOOTH_ERROR_NONE);
707 if (event_info->remote_address == NULL)
708 event_info->remote_address = g_strdup("");
710 _bt_send_event(BT_RFCOMM_SERVER_EVENT,
711 BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
712 DBUS_TYPE_INT32, &result,
713 DBUS_TYPE_STRING, &event_info->remote_address,
714 DBUS_TYPE_STRING, &event_info->uuid,
715 DBUS_TYPE_INT16, &event_info->data_fd,
718 g_free(event_info->uuid);
719 g_free(event_info->remote_address);
722 return BLUETOOTH_ERROR_NONE;
725 int _bt_rfcomm_server_disconnect(int data_fd)
727 bt_rfcomm_server_info_t *server_info;
728 bt_rfcomm_event_info_t *event_info;
732 retv_if(data_fd <= 0, BLUETOOTH_ERROR_INVALID_PARAM);
734 server_info = __bt_rfcomm_get_server_info_using_data_fd(data_fd);
735 retv_if(server_info == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
737 if (server_info->data_id > 0)
738 g_source_remove(server_info->data_id);
740 if (server_info->data_fd > 0)
741 close(server_info->data_fd);
743 event_info = g_malloc0(sizeof(bt_rfcomm_event_info_t));
744 event_info->data_fd = server_info->data_fd;
745 event_info->remote_address = g_strdup(server_info->remote_address);
746 event_info->uuid = g_strdup(server_info->uuid);
748 /* Send the disconnected event after return the function */
749 g_idle_add((GSourceFunc)__bt_rfcomm_server_disconnect_cb, event_info);
751 g_free(server_info->remote_address);
752 server_info->remote_address = NULL;
753 server_info->data_fd = -1;
754 server_info->data_id = 0;
755 server_info->data_io = NULL;
759 return BLUETOOTH_ERROR_NONE;
762 /* To support the BOT */
763 int _bt_rfcomm_is_uuid_available(char *uuid, gboolean *available)
766 bt_rfcomm_server_info_t *server_info;
768 BT_CHECK_PARAMETER(uuid, return);
769 BT_CHECK_PARAMETER(available, return);
773 for (l = server_list; l != NULL; l = l->next) {
774 server_info = l->data;
776 if (server_info == NULL)
779 if (g_ascii_strcasecmp(uuid, server_info->uuid) == 0) {
781 return BLUETOOTH_ERROR_NONE;
785 return BLUETOOTH_ERROR_NONE;
788 gboolean __bt_rfcomm_server_accept_timeout_cb(gpointer user_data)
790 bt_rfcomm_server_info_t *server_info;
791 request_info_t *req_info;
794 int result = BLUETOOTH_ERROR_TIMEOUT;
796 server_info = (bt_rfcomm_server_info_t *)user_data;
798 /* Already reply in __bt_rfcomm_server_connected_cb */
799 retv_if(server_info == NULL, FALSE);
800 retv_if(server_info->accept_id == 0, FALSE);
802 req_info = _bt_get_request_info(server_info->accept_id);
803 if (req_info == NULL || req_info->context == NULL) {
804 BT_ERR("info is NULL");
808 server_info->accept_id = 0;
810 out_param1 = g_array_new(FALSE, FALSE, sizeof(gchar));
811 out_param2 = g_array_new(FALSE, FALSE, sizeof(gchar));
813 g_array_append_vals(out_param2, &result, sizeof(int));
815 dbus_g_method_return(req_info->context, out_param1, out_param2);
817 g_array_free(out_param1, TRUE);
818 g_array_free(out_param2, TRUE);
820 _bt_delete_request_list(req_info->req_id);
825 /* To support the BOT */
826 int _bt_rfcomm_accept_connection(int server_fd, int request_id)
828 bt_rfcomm_server_info_t *server_info;
830 server_info = __bt_rfcomm_get_server_info(server_fd);
831 retv_if(server_info == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
832 retv_if(server_info->server_type != BT_CUSTOM_SERVER,
833 BLUETOOTH_ERROR_INVALID_PARAM);
835 if (!_bt_agent_reply_authorize(TRUE))
836 return BLUETOOTH_ERROR_INTERNAL;
838 server_info->accept_id = request_id;
840 g_timeout_add(BT_SERVER_ACCEPT_TIMEOUT,
841 (GSourceFunc)__bt_rfcomm_server_accept_timeout_cb,
844 return BLUETOOTH_ERROR_NONE;
847 /* To support the BOT */
848 int _bt_rfcomm_reject_connection(int server_fd)
850 bt_rfcomm_server_info_t *server_info;
852 server_info = __bt_rfcomm_get_server_info(server_fd);
853 retv_if(server_info == NULL, BLUETOOTH_ERROR_INVALID_PARAM);
854 retv_if(server_info->server_type != BT_CUSTOM_SERVER,
855 BLUETOOTH_ERROR_INVALID_PARAM);
857 if (!_bt_agent_reply_authorize(FALSE))
858 return BLUETOOTH_ERROR_INTERNAL;
860 return BLUETOOTH_ERROR_NONE;
863 bt_rfcomm_server_info_t *_bt_rfcomm_get_server_info_using_uuid(char *uuid)
866 bt_rfcomm_server_info_t *server_info;
868 retv_if(uuid == NULL, NULL);
870 for (l = server_list; l != NULL; l = l->next) {
871 server_info = l->data;
873 if (server_info == NULL)
876 if (g_strcmp0(server_info->uuid, uuid) == 0)
883 int _bt_rfcomm_server_disconnect_all_connection(void)
886 bt_rfcomm_server_info_t *server_info;
888 for (l = server_list; l != NULL; l = l->next) {
889 server_info = l->data;
891 if (server_info == NULL)
894 _bt_rfcomm_disconnect(server_info->data_fd);
897 return BLUETOOTH_ERROR_NONE;
900 int _bt_rfcomm_server_check_existence(gboolean *existence)
902 BT_CHECK_PARAMETER(existence, return);
904 if (server_list && g_slist_length(server_list) > 0) {
910 return BLUETOOTH_ERROR_NONE;
913 int _bt_rfcomm_server_check_termination(char *name)
916 bt_rfcomm_server_info_t *server_info;
918 BT_CHECK_PARAMETER(name, return);
920 for (l = server_list; l != NULL; l = l->next) {
921 server_info = l->data;
923 if (server_info == NULL)
926 if (g_strcmp0(server_info->sender, name) == 0) {
927 _bt_rfcomm_remove_socket(server_info->control_fd);
931 return BLUETOOTH_ERROR_NONE;