2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
21 #include <gio/gunixfdlist.h>
22 #include <sys/socket.h>
25 #include "bluetooth-api.h"
26 #include "bt-internal-types.h"
28 #include "bt-common.h"
29 #include "bt-request-sender.h"
30 #include "bt-event-handler.h"
32 #ifdef TIZEN_FEATURE_BT_DPM
36 #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 rfcomm_info_t *__find_rfcomm_info_with_id(int id)
60 for (l = rfcomm_nodes; l != NULL; l = l->next) {
61 rfcomm_info_t *info = l->data;
70 static rfcomm_info_t *__find_rfcomm_info_with_fd(int fd)
75 for (l = rfcomm_nodes; l != NULL; l = l->next) {
76 rfcomm_info_t *info = l->data;
78 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
79 rfcomm_conn_t *conn = ll->data;
81 if (conn && conn->fd == fd)
89 static rfcomm_info_t *__find_rfcomm_info_with_path(const gchar *path)
93 for (l = rfcomm_nodes; l != NULL; l = l->next) {
94 rfcomm_info_t *info = l->data;
96 if (g_strcmp0(info->path, path) == 0)
103 static rfcomm_info_t *__find_rfcomm_info_with_uuid(const char *uuid)
107 for (l = rfcomm_nodes; l != NULL; l = l->next) {
108 rfcomm_info_t *info = l->data;
110 if (g_strcmp0(info->uuid, uuid) == 0)
117 static rfcomm_conn_t *__find_rfcomm_conn_with_fd(rfcomm_info_t *info,
123 for (l = info->rfcomm_conns; l; l = l->next) {
126 if (conn && conn->fd == fd)
133 static void __rfcomm_remove_conn(rfcomm_info_t *info, int fd)
137 conn = __find_rfcomm_conn_with_fd(info, fd);
141 info->rfcomm_conns = g_slist_remove(info->rfcomm_conns, conn);
143 if (conn->watch_id > 0)
144 g_source_remove(conn->watch_id);
148 gboolean _check_uuid_path(char *path, char *uuid)
150 rfcomm_info_t *info = NULL;
151 info = __find_rfcomm_info_with_path(path);
155 if (strcmp(info->uuid, uuid) == 0)
161 static void __connected_cb(rfcomm_info_t *info, rfcomm_conn_t *conn,
162 bt_event_info_t *event_info)
164 bluetooth_rfcomm_connection_t conn_info;
166 memset(&conn_info, 0x00, sizeof(bluetooth_rfcomm_connection_t));
168 conn_info.device_role = RFCOMM_ROLE_SERVER;
169 g_strlcpy(conn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
170 conn_info.socket_fd = conn->fd;
171 conn_info.device_addr = conn->addr;
172 conn_info.server_id = info->id;
174 BT_INFO_C("### Connected [RFCOMM Server]");
175 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_CONNECTED,
176 BLUETOOTH_ERROR_NONE, &conn_info,
177 event_info->cb, event_info->user_data);
180 static void __rfcomm_server_disconnect_conn(rfcomm_conn_t *conn,
183 bluetooth_rfcomm_disconnection_t disconn_info;
184 bt_event_info_t *event_info;
189 if (conn->disconnected == FALSE)
192 if (conn->watch_id > 0) {
193 g_source_remove(conn->watch_id);
197 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
198 if (event_info == NULL) {
199 BT_ERR("event_info is NULL");
200 __rfcomm_remove_conn(info, conn->fd);
204 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
205 disconn_info.device_role = RFCOMM_ROLE_SERVER;
206 g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
207 disconn_info.device_addr = conn->addr;
209 BT_INFO("Disconnected FD [%d]", conn->fd);
210 disconn_info.socket_fd = conn->fd;
212 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
213 BLUETOOTH_ERROR_NONE, &disconn_info,
214 event_info->cb, event_info->user_data);
216 __rfcomm_remove_conn(info, conn->fd);
219 static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
221 BT_INFO_C("### Disconnected [RFCOMM Server]");
223 if (g_slist_find(rfcomm_nodes, info) == NULL) {
224 BT_INFO("rfcomm resource is already freed");
228 info->disconnect_idle_id = 0;
230 g_slist_foreach(info->rfcomm_conns,
231 (GFunc)__rfcomm_server_disconnect_conn, info);
237 static gboolean __is_error_by_disconnect(GError *err)
239 return !g_strcmp0(err->message, "Connection reset by peer") ||
240 !g_strcmp0(err->message, "Connection timed out") ||
241 !g_strcmp0(err->message, "Software caused connection abort");
244 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
249 int result = BLUETOOTH_ERROR_NONE;
250 rfcomm_info_t *info = data;
252 bt_event_info_t *event_info;
253 bluetooth_rfcomm_received_data_t data_r;
254 GIOStatus status = G_IO_STATUS_NORMAL;
258 retv_if(info == NULL, FALSE);
260 fd = g_io_channel_unix_get_fd(chan);
261 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
262 BT_ERR_C("RFComm Server disconnected: %d", fd);
264 if (info->disconnect_idle_id > 0) {
265 BT_INFO("Disconnect idle still not process remove source");
266 g_source_remove(info->disconnect_idle_id);
267 info->disconnect_idle_id = 0;
270 conn = __find_rfcomm_conn_with_fd(info, fd);
272 BT_ERR("No Connection info found with FD [%d]", fd);
276 if (conn->disconnected == FALSE) {
278 conn->disconnected = TRUE;
280 __rfcomm_server_disconnect(info);
284 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
286 status = g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
288 if (status != G_IO_STATUS_NORMAL) {
289 BT_ERR("IO Channel read is failed with %d", status);
295 BT_ERR("IO Channel read error [%s]", err->message);
296 if (status == G_IO_STATUS_ERROR &&
297 __is_error_by_disconnect(err)) {
298 BT_ERR("cond : %d", cond);
301 if (info->disconnect_idle_id > 0) {
302 BT_INFO("Disconnect idle still not process remove source");
303 g_source_remove(info->disconnect_idle_id);
304 info->disconnect_idle_id = 0;
307 conn = __find_rfcomm_conn_with_fd(info, fd);
309 BT_ERR("No Connection info found with FD [%d]", fd);
313 if (conn->disconnected == FALSE) {
315 conn->disconnected = TRUE;
317 __rfcomm_server_disconnect(info);
325 BT_ERR("Length is zero");
327 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
328 if (event_info == NULL) {
329 BT_ERR("event_info is NULL. Unable to invoke the callback");
334 data_r.socket_fd = fd;
335 data_r.buffer_size = len;
336 data_r.buffer = buffer;
338 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
340 event_info->cb, event_info->user_data);
347 int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
352 bt_event_info_t *event_info;
354 BT_INFO("%s %d", path, fd);
356 info = __find_rfcomm_info_with_path(path);
358 BT_ERR("rfcomm info is NULL");
362 #ifdef TIZEN_FEATURE_BT_DPM
363 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
366 BT_ERR("Not allow to use SPP profile");
369 _bt_convert_addr_type_to_string(addr_str, addr->addr);
370 _bt_disconnect_profile(addr_str, info->uuid, NULL, NULL);
376 conn = g_new0(rfcomm_conn_t, 1);
378 memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
379 info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
381 data_io = g_io_channel_unix_new(conn->fd);
383 g_io_channel_set_encoding(data_io, NULL, NULL);
384 g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
386 conn->watch_id = g_io_add_watch(data_io,
387 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
388 __data_received_cb, info);
390 g_io_channel_unref(data_io);
392 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
394 __connected_cb(info, conn, event_info);
399 static rfcomm_info_t *__register_method()
406 id = __rfcomm_assign_id();
410 path = g_strdup_printf("/org/socket/server/%d/%d", getpid(), id);
412 object_id = _bt_register_new_conn(path, new_server_connection);
414 __rfcomm_delete_id(id);
417 info = g_new0(rfcomm_info_t, 1);
418 info->object_id = (guint)object_id;
422 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
427 static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
432 object_id = _bt_register_new_conn_ex(path, bus_name, new_server_connection);
436 info = g_new0(rfcomm_info_t, 1);
437 info->object_id = (guint)object_id;
438 info->path = g_strdup(path);
441 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
446 void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
448 if (conn->disconnected == FALSE) {
450 conn->disconnected = TRUE;
452 __rfcomm_server_disconnect_conn(conn, info);
455 void free_rfcomm_info(rfcomm_info_t *info)
459 if (info->disconnect_idle_id > 0) {
460 BT_INFO("Disconnect idle still not process remove source");
461 g_source_remove(info->disconnect_idle_id);
462 info->disconnect_idle_id = 0;
465 __rfcomm_delete_id(info->id);
466 _bt_unregister_gdbus(info->object_id);
468 g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
475 void _bt_rfcomm_server_free_all(void)
477 BT_DBG("Free all the servers");
479 g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
483 void _bt_rfcomm_server_disconnect_all(void)
489 BT_INFO("### Disconnect all RFCOMM server connections");
491 for (server = rfcomm_nodes; server; ) {
492 rfcomm_info_t *info = server->data;
494 for (conn = info->rfcomm_conns; conn; conn = conn->next) {
495 rfcomm_conn_t *conn_info = conn->data;
497 if (conn_info == NULL)
500 if (conn_info->watch_id == 0 || conn_info->disconnected)
503 close(conn_info->fd);
504 conn_info->disconnected = TRUE;
506 _bt_convert_addr_type_to_string(addr,
507 conn_info->addr.addr);
508 _bt_disconnect_profile(addr, info->uuid, NULL, NULL);
511 server = server->next;
512 __rfcomm_server_disconnect(info);
519 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
521 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
526 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
529 BT_CHECK_ENABLED(return);
530 BT_CHECK_PARAMETER(uuid, return);
531 BT_INFO("UUID Provided %s", uuid);
533 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_CREATE_SOCKET)
534 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
535 BT_ERR("Don't have a privilege to use this API");
536 return BLUETOOTH_ERROR_PERMISSION_DEINED;
539 #ifdef TIZEN_FEATURE_BT_DPM
540 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
541 BT_ERR("Not allow to use SPP profile");
542 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
546 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
547 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
548 info = __register_method();
552 info->uuid = g_strdup(uuid);
553 info->disconnect_idle_id = 0;
558 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
560 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
561 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
563 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_CREATE_SOCKET,
564 in_param1, in_param2, in_param3, in_param4, &out_param);
566 BT_DBG("result: %x", result);
568 if (result == BLUETOOTH_ERROR_NONE)
569 socket_fd = g_array_index(out_param, int, 0);
571 BT_ERR("Fail to send request");
573 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
579 BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char *bus_name, const char *path)
581 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
584 BT_CHECK_ENABLED(return);
585 BT_CHECK_PARAMETER(path, return);
586 BT_INFO("PATH Provided %s", path);
588 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_CREATE_SOCKET_EX)
589 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
590 BT_ERR("Don't have a privilege to use this API");
591 return BLUETOOTH_ERROR_PERMISSION_DEINED;
594 #ifdef TIZEN_FEATURE_BT_DPM
595 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
596 BT_ERR("Not allow to use SPP profile");
597 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
601 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
602 info = __register_method_2(path, bus_name);
604 return BLUETOOTH_ERROR_IN_PROGRESS;
605 info->uuid = g_strdup(uuid);
606 info->disconnect_idle_id = 0;
608 return BLUETOOTH_ERROR_NONE;
610 return BLUETOOTH_ERROR_NOT_SUPPORT;
615 BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
617 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
623 BT_CHECK_ENABLED(return);
625 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET)
626 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
627 BT_ERR("Don't have a privilege to use this API");
628 return BLUETOOTH_ERROR_PERMISSION_DEINED;
632 BT_ERR("Invalid ID");
633 return BLUETOOTH_ERROR_INVALID_PARAM;
636 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
637 BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
639 info = __find_rfcomm_info_with_id(id);
641 return BLUETOOTH_ERROR_INVALID_PARAM;
643 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
644 _bt_unregister_profile(info->path);
646 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
647 free_rfcomm_info(info);
649 return BLUETOOTH_ERROR_NONE;
652 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
654 g_array_append_vals(in_param1, &id, sizeof(int));
656 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET,
657 in_param1, in_param2, in_param3, in_param4, &out_param);
659 BT_DBG("result: %x", result);
661 if (result == BLUETOOTH_ERROR_NONE)
662 _bt_remove_server(id);
664 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
670 BT_EXPORT_API int bluetooth_rfcomm_remove_socket_ex(const char *uuid)
672 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
675 BT_CHECK_ENABLED(return);
677 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET)
678 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
679 BT_ERR("Don't have a privilege to use this API");
680 return BLUETOOTH_ERROR_PERMISSION_DEINED;
683 BT_INFO("RFCOMM Remove socket request from app, uuid=[%s]", uuid);
685 info = __find_rfcomm_info_with_uuid(uuid);
687 return BLUETOOTH_ERROR_INVALID_PARAM;
689 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
690 _bt_unregister_profile(info->path);
692 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
693 free_rfcomm_info(info);
695 return BLUETOOTH_ERROR_NONE;
697 return BLUETOOTH_ERROR_NOT_SUPPORT;
701 BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
703 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
709 BT_INFO("### Disconnect RFCOMM server");
711 BT_ERR("Invalid FD");
712 return BLUETOOTH_ERROR_INVALID_PARAM;
715 info = __find_rfcomm_info_with_fd(socket_fd);
717 return BLUETOOTH_ERROR_INVALID_PARAM;
719 conn = __find_rfcomm_conn_with_fd(info, socket_fd);
721 return BLUETOOTH_ERROR_INVALID_PARAM;
723 if (conn->watch_id == 0 || conn->disconnected)
724 return BLUETOOTH_ERROR_NOT_CONNECTED;
727 conn->disconnected = TRUE;
729 _bt_convert_addr_type_to_string(address, conn->addr.addr);
731 BT_DBG("Address %s", address);
732 _bt_disconnect_profile(address, info->uuid, NULL, NULL);
734 if (info->disconnect_idle_id == 0)
735 info->disconnect_idle_id = g_idle_add(
736 (GSourceFunc)__rfcomm_server_disconnect, info);
739 return BLUETOOTH_ERROR_NONE;
743 BT_CHECK_ENABLED(return);
746 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
748 g_array_append_vals(in_param1, &socket_fd, sizeof(int));
750 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_SOCKET_DISCONNECT,
751 in_param1, in_param2, in_param3, in_param4, &out_param);
753 BT_DBG("result: %x", result);
755 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
761 BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uuid)
764 gboolean available = TRUE;
765 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
767 retv_if(uuid == NULL, FALSE);
768 retv_if(bluetooth_check_adapter() ==
769 BLUETOOTH_ADAPTER_DISABLED, FALSE);
772 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
774 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
775 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
777 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_IS_UUID_AVAILABLE,
778 in_param1, in_param2, in_param3, in_param4, &out_param);
780 BT_DBG("result: %x", result);
782 if (result == BLUETOOTH_ERROR_NONE)
783 available = g_array_index(out_param, gboolean, 0);
785 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
787 BT_DBG("available: %d", available);
792 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
799 BT_CHECK_PARAMETER(device_address, return);
800 BT_CHECK_PARAMETER(connected, return);
804 for (l = rfcomm_nodes; l; l = l->next) {
807 if (info == NULL || info->rfcomm_conns == NULL)
810 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
813 if (memcmp(device_address, &conn->addr,
814 sizeof(bluetooth_device_address_t)))
818 return BLUETOOTH_ERROR_NONE;
822 return BLUETOOTH_ERROR_NONE;
825 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
827 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
831 gboolean native_service = TRUE;
834 BT_CHECK_ENABLED(return);
836 BT_ERR("Invalid ID");
837 return BLUETOOTH_ERROR_INVALID_PARAM;
840 #ifdef TIZEN_FEATURE_BT_DPM
841 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
842 BT_ERR("Not allow to use SPP profile");
843 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
847 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
848 BT_INFO("RFCOMM Listen & accept from app");
850 info = __find_rfcomm_info_with_id(id);
852 return BLUETOOTH_ERROR_INVALID_PARAM;
854 bt_register_profile_info_t profile_info;
857 profile_info.authentication = TRUE;
858 profile_info.authorization = TRUE;
859 profile_info.obj_path = info->path;
860 profile_info.role = NULL;
861 profile_info.service = info->uuid;
862 profile_info.uuid = info->uuid;
864 BT_INFO("uuid %s", profile_info.uuid);
865 result = _bt_register_profile(&profile_info, TRUE);
870 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
872 g_array_append_vals(in_param1, &id, sizeof(int));
873 g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
874 g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
876 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
877 in_param1, in_param2, in_param3, in_param4, &out_param);
879 BT_DBG("result: %x", result);
881 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
887 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
888 int max_pending_connection,
889 const char *bus_name, const char *path)
891 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
894 BT_CHECK_ENABLED(return);
896 #ifdef TIZEN_FEATURE_BT_DPM
897 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
898 BT_ERR("Not allow to use SPP profile");
899 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
903 BT_INFO("RFCOMM Listen & accept from app");
905 info = __find_rfcomm_info_with_uuid(uuid);
907 return BLUETOOTH_ERROR_INVALID_PARAM;
909 bt_register_profile_info_t profile_info;
912 profile_info.authentication = TRUE;
913 profile_info.authorization = TRUE;
914 profile_info.obj_path = info->path;
915 profile_info.role = NULL;
916 profile_info.service = info->uuid;
917 profile_info.uuid = info->uuid;
919 BT_INFO("uuid %s", profile_info.uuid);
920 result = _bt_register_profile_ex(&profile_info, TRUE, bus_name, path);
924 return BLUETOOTH_ERROR_NOT_SUPPORT;
928 BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
930 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
934 gboolean native_service = FALSE;
937 BT_CHECK_ENABLED(return);
939 BT_ERR("Invalid ID");
940 return BLUETOOTH_ERROR_INVALID_PARAM;
943 #ifdef TIZEN_FEATURE_BT_DPM
944 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
945 BT_ERR("Not allow to use SPP profile");
946 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
950 #ifdef TIZEN_FEATURE_BT_RFCOMM_DIRECT
951 BT_INFO("RFCOMM Listen");
953 info = __find_rfcomm_info_with_id(id);
955 return BLUETOOTH_ERROR_INVALID_PARAM;
957 bt_register_profile_info_t profile_info;
960 profile_info.authentication = TRUE;
961 profile_info.authorization = TRUE;
962 profile_info.obj_path = info->path;
963 profile_info.role = NULL;
964 profile_info.service = info->uuid;
965 profile_info.uuid = info->uuid;
966 BT_INFO("UUID %s", info->uuid);
967 BT_INFO("PATH %s", info->path);
968 result = _bt_register_profile_platform(&profile_info, TRUE);
969 if (result != BLUETOOTH_ERROR_NONE)
972 return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
977 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
979 g_array_append_vals(in_param1, &id, sizeof(int));
980 g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
981 g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
983 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
984 in_param1, in_param2, in_param3, in_param4, &out_param);
986 BT_DBG("result: %x", result);
988 if (result == BLUETOOTH_ERROR_NONE)
991 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
997 BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd)
1001 BT_CHECK_ENABLED(return);
1003 #ifdef TIZEN_FEATURE_BT_DPM
1004 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
1005 BT_ERR("Not allow to use SPP profile");
1006 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
1010 if (server_fd < 0) {
1011 BT_ERR("Invalid FD");
1012 return BLUETOOTH_ERROR_INVALID_PARAM;
1016 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1018 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1020 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_ACCEPT_CONNECTION,
1021 in_param1, in_param2, in_param3, in_param4, &out_param);
1023 BT_DBG("result: %x", result);
1025 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1030 BT_EXPORT_API int bluetooth_rfcomm_reject_connection(int server_fd)
1034 BT_CHECK_ENABLED(return);
1036 if (server_fd < 0) {
1037 BT_ERR("Invalid FD");
1038 return BLUETOOTH_ERROR_INVALID_PARAM;
1044 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1046 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1048 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REJECT_CONNECTION,
1049 in_param1, in_param2, in_param3, in_param4, &out_param);
1051 BT_DBG("result: %x", result);
1053 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);