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.
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_DPM_ENABLE
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 __rfcomm_remove_conn(info, conn->fd);
203 memset(&disconn_info, 0x00, sizeof(bluetooth_rfcomm_disconnection_t));
204 disconn_info.device_role = RFCOMM_ROLE_SERVER;
205 g_strlcpy(disconn_info.uuid, info->uuid, BLUETOOTH_UUID_STRING_MAX);
206 disconn_info.device_addr = conn->addr;
208 BT_DBG("Disconnected FD [%d]", conn->fd);
209 disconn_info.socket_fd = conn->fd;
211 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DISCONNECTED,
212 BLUETOOTH_ERROR_NONE, &disconn_info,
213 event_info->cb, event_info->user_data);
215 __rfcomm_remove_conn(info, conn->fd);
218 static gboolean __rfcomm_server_disconnect(rfcomm_info_t *info)
220 BT_INFO_C("### Disconnected [RFCOMM Server]");
222 if (g_slist_find(rfcomm_nodes, info) == NULL) {
223 BT_INFO("rfcomm resource is already freed");
227 info->disconnect_idle_id = 0;
229 g_slist_foreach(info->rfcomm_conns,
230 (GFunc)__rfcomm_server_disconnect_conn, info);
236 static gboolean __is_error_by_disconnect(GError *err)
238 return !g_strcmp0(err->message, "Connection reset by peer") ||
239 !g_strcmp0(err->message, "Connection timed out") ||
240 !g_strcmp0(err->message, "Software caused connection abort");
243 static gboolean __data_received_cb(GIOChannel *chan, GIOCondition cond,
248 int result = BLUETOOTH_ERROR_NONE;
249 rfcomm_info_t *info = data;
251 bt_event_info_t *event_info;
252 bluetooth_rfcomm_received_data_t data_r;
253 GIOStatus status = G_IO_STATUS_NORMAL;
257 retv_if(info == NULL, FALSE);
259 fd = g_io_channel_unix_get_fd(chan);
260 if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR)) {
261 BT_ERR_C("RFComm Server disconnected: %d", fd);
263 if (info->disconnect_idle_id > 0) {
264 BT_INFO("Disconnect idle still not process remove source");
265 g_source_remove(info->disconnect_idle_id);
266 info->disconnect_idle_id = 0;
269 conn = __find_rfcomm_conn_with_fd(info, fd);
271 BT_ERR("No Connection info found with FD [%d]", fd);
275 if (conn->disconnected == FALSE) {
277 conn->disconnected = TRUE;
279 __rfcomm_server_disconnect(info);
283 buffer = g_malloc0(BT_RFCOMM_BUFFER_LEN + 1);
285 status = g_io_channel_read_chars(chan, buffer, BT_RFCOMM_BUFFER_LEN,
287 if (status != G_IO_STATUS_NORMAL) {
288 BT_ERR("IO Channel read is failed with %d", status);
294 BT_ERR("IO Channel read error [%s]", err->message);
295 if (status == G_IO_STATUS_ERROR &&
296 __is_error_by_disconnect(err)) {
297 BT_ERR("cond : %d", cond);
300 if (info->disconnect_idle_id > 0) {
301 BT_INFO("Disconnect idle still not process remove source");
302 g_source_remove(info->disconnect_idle_id);
303 info->disconnect_idle_id = 0;
306 conn = __find_rfcomm_conn_with_fd(info, fd);
308 BT_ERR("No Connection info found with FD [%d]", fd);
312 if (conn->disconnected == FALSE) {
314 conn->disconnected = TRUE;
316 __rfcomm_server_disconnect(info);
324 BT_ERR("Length is zero");
326 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
327 if (event_info == NULL) {
332 data_r.socket_fd = fd;
333 data_r.buffer_size = len;
334 data_r.buffer = buffer;
336 _bt_common_event_cb(BLUETOOTH_EVENT_RFCOMM_DATA_RECEIVED,
338 event_info->cb, event_info->user_data);
345 int new_server_connection(const char *path, int fd, bluetooth_device_address_t *addr)
350 bt_event_info_t *event_info;
352 BT_DBG("%s %d", path, fd);
354 info = __find_rfcomm_info_with_path(path);
358 #ifdef TIZEN_DPM_ENABLE
359 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
362 BT_ERR("Not allow to use SPP profile");
365 _bt_convert_addr_type_to_string(addr_str, addr->addr);
366 _bt_disconnect_profile(addr_str, info->uuid, NULL,NULL);
372 conn = g_new0(rfcomm_conn_t, 1);
374 memcpy(&conn->addr, addr, sizeof(bluetooth_device_address_t));
375 info->rfcomm_conns = g_slist_append(info->rfcomm_conns, conn);
377 data_io = g_io_channel_unix_new(conn->fd);
379 g_io_channel_set_encoding(data_io, NULL, NULL);
380 g_io_channel_set_flags(data_io, G_IO_FLAG_NONBLOCK, NULL);
382 conn->watch_id = g_io_add_watch(data_io,
383 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
384 __data_received_cb, info);
386 g_io_channel_unref(data_io);
388 event_info = _bt_event_get_cb_data(BT_RFCOMM_SERVER_EVENT);
390 __connected_cb(info, conn, event_info);
395 static rfcomm_info_t *__register_method()
402 id = __rfcomm_assign_id();
406 path = g_strdup_printf("/org/socket/server/%d/%d", getpid(), id);
408 object_id = _bt_register_new_conn(path, new_server_connection);
410 __rfcomm_delete_id(id);
413 info = g_new0(rfcomm_info_t, 1);
414 info->object_id = (guint)object_id;
418 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
423 static rfcomm_info_t *__register_method_2(const char *path, const char *bus_name)
428 object_id = _bt_register_new_conn_ex(path, bus_name, new_server_connection);
432 info = g_new0(rfcomm_info_t, 1);
433 info->object_id = (guint)object_id;
434 info->path = g_strdup(path);
437 rfcomm_nodes = g_slist_append(rfcomm_nodes, info);
442 void free_rfcomm_conn(rfcomm_conn_t *conn, rfcomm_info_t *info)
444 if (conn->disconnected == FALSE) {
446 conn->disconnected = TRUE;
448 __rfcomm_server_disconnect_conn(conn, info);
451 void free_rfcomm_info(rfcomm_info_t *info)
455 if (info->disconnect_idle_id > 0) {
456 BT_INFO("Disconnect idle still not process remove source");
457 g_source_remove(info->disconnect_idle_id);
458 info->disconnect_idle_id = 0;
461 __rfcomm_delete_id(info->id);
462 _bt_unregister_gdbus(info->object_id);
464 g_slist_foreach(info->rfcomm_conns, (GFunc)free_rfcomm_conn, info);
471 void _bt_rfcomm_server_free_all()
473 BT_DBG("Free all the servers");
475 g_slist_free_full(rfcomm_nodes, (GDestroyNotify)free_rfcomm_info);
480 BT_EXPORT_API int bluetooth_rfcomm_create_socket(const char *uuid)
487 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
490 BT_CHECK_ENABLED(return);
491 BT_CHECK_PARAMETER(uuid, return);
492 BT_INFO("UUID Provided %s", uuid);
494 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_CREATE_SOCKET)
495 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
496 BT_ERR("Don't have a privilege to use this API");
497 return BLUETOOTH_ERROR_PERMISSION_DEINED;
500 #ifdef TIZEN_DPM_ENABLE
501 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
502 BT_ERR("Not allow to use SPP profile");
503 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
508 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
509 info = __register_method();
513 info->uuid = g_strdup(uuid);
514 info->disconnect_idle_id = 0;
519 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
521 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
522 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
524 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_CREATE_SOCKET,
525 in_param1, in_param2, in_param3, in_param4, &out_param);
527 BT_DBG("result: %x", result);
529 if (result == BLUETOOTH_ERROR_NONE)
530 socket_fd = g_array_index(out_param, int, 0);
532 BT_ERR("Fail to send request");
534 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
540 BT_EXPORT_API int bluetooth_rfcomm_create_socket_ex(const char *uuid, const char *bus_name, const char *path)
545 BT_CHECK_ENABLED(return);
546 BT_CHECK_PARAMETER(path, return);
547 BT_INFO("PATH Provided %s", path);
549 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_CREATE_SOCKET_EX)
550 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
551 BT_ERR("Don't have a privilege to use this API");
552 return BLUETOOTH_ERROR_PERMISSION_DEINED;
555 #ifdef TIZEN_DPM_ENABLE
556 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
557 BT_ERR("Not allow to use SPP profile");
558 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
562 BT_INFO("<<<<<<<<< RFCOMM Create socket from app >>>>>>>>>");
563 info = __register_method_2(path, bus_name);
565 return BLUETOOTH_ERROR_IN_PROGRESS;
566 info->uuid = g_strdup(uuid);
567 info->disconnect_idle_id = 0;
569 return BLUETOOTH_ERROR_NONE;
571 return BLUETOOTH_ERROR_NOT_SUPPORT;
576 BT_EXPORT_API int bluetooth_rfcomm_remove_socket(int id)
584 BT_CHECK_ENABLED(return);
586 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET)
587 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
588 BT_ERR("Don't have a privilege to use this API");
589 return BLUETOOTH_ERROR_PERMISSION_DEINED;
593 BT_ERR("Invalid ID");
594 return BLUETOOTH_ERROR_INVALID_PARAM;
598 BT_INFO("RFCOMM Remove socket request from app, ID [%d]", id);
600 info = __find_rfcomm_info_with_id(id);
602 return BLUETOOTH_ERROR_INVALID_PARAM;
604 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
605 _bt_unregister_profile(info->path);
607 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
608 free_rfcomm_info(info);
610 return BLUETOOTH_ERROR_NONE;
613 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
615 g_array_append_vals(in_param1, &id, sizeof(int));
617 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET,
618 in_param1, in_param2, in_param3, in_param4, &out_param);
620 BT_DBG("result: %x", result);
622 if (result == BLUETOOTH_ERROR_NONE)
623 _bt_remove_server(id);
625 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
631 BT_EXPORT_API int bluetooth_rfcomm_remove_socket_ex(const char *uuid)
636 BT_CHECK_ENABLED(return);
638 if (_bt_check_privilege(BT_BLUEZ_SERVICE, BT_RFCOMM_REMOVE_SOCKET)
639 == BLUETOOTH_ERROR_PERMISSION_DEINED) {
640 BT_ERR("Don't have a privilege to use this API");
641 return BLUETOOTH_ERROR_PERMISSION_DEINED;
644 BT_INFO("RFCOMM Remove socket request from app, uuid=[%s]", uuid);
646 info = __find_rfcomm_info_with_uuid(uuid);
648 return BLUETOOTH_ERROR_INVALID_PARAM;
650 _bt_unregister_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid);
651 _bt_unregister_profile(info->path);
653 rfcomm_nodes = g_slist_remove(rfcomm_nodes, info);
654 free_rfcomm_info(info);
656 return BLUETOOTH_ERROR_NONE;
658 return BLUETOOTH_ERROR_NOT_SUPPORT;
662 BT_EXPORT_API int bluetooth_rfcomm_server_disconnect(int socket_fd)
670 BT_INFO("### Disconnect RFCOMM server");
672 BT_ERR("Invalid FD");
673 return BLUETOOTH_ERROR_INVALID_PARAM;
676 info = __find_rfcomm_info_with_fd(socket_fd);
678 return BLUETOOTH_ERROR_INVALID_PARAM;
680 conn = __find_rfcomm_conn_with_fd(info, socket_fd);
682 return BLUETOOTH_ERROR_INVALID_PARAM;
684 if (conn->watch_id == 0 || conn->disconnected)
685 return BLUETOOTH_ERROR_NOT_CONNECTED;
688 conn->disconnected = TRUE;
690 _bt_convert_addr_type_to_string(address, conn->addr.addr);
692 BT_DBG("Address %s", address);
693 _bt_disconnect_profile(address, info->uuid, NULL, NULL);
695 if (info->disconnect_idle_id == 0)
696 info->disconnect_idle_id = g_idle_add(
697 (GSourceFunc)__rfcomm_server_disconnect, info);
700 return BLUETOOTH_ERROR_NONE;
704 BT_CHECK_ENABLED(return);
707 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
709 g_array_append_vals(in_param1, &socket_fd, sizeof(int));
711 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_SOCKET_DISCONNECT,
712 in_param1, in_param2, in_param3, in_param4, &out_param);
714 BT_DBG("result: %x", result);
716 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
722 BT_EXPORT_API gboolean bluetooth_rfcomm_is_server_uuid_available(const char *uuid)
725 gboolean available = TRUE;
726 char uuid_str[BLUETOOTH_UUID_STRING_MAX];
728 retv_if(uuid == NULL, FALSE);
729 retv_if(bluetooth_check_adapter() ==
730 BLUETOOTH_ADAPTER_DISABLED, FALSE);
733 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
735 g_strlcpy(uuid_str, uuid, sizeof(uuid_str));
736 g_array_append_vals(in_param1, uuid_str, BLUETOOTH_UUID_STRING_MAX);
738 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_IS_UUID_AVAILABLE,
739 in_param1, in_param2, in_param3, in_param4, &out_param);
741 BT_DBG("result: %x", result);
743 if (result == BLUETOOTH_ERROR_NONE)
744 available = g_array_index(out_param, gboolean, 0);
746 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
748 BT_DBG("available: %d", available);
753 BT_EXPORT_API int bluetooth_rfcomm_server_is_connected(const bluetooth_device_address_t *device_address, gboolean *connected)
760 BT_CHECK_PARAMETER(device_address, return);
761 BT_CHECK_PARAMETER(connected, return);
765 for (l = rfcomm_nodes; l; l = l->next) {
768 if (info == NULL || info->rfcomm_conns == NULL)
771 for (ll = info->rfcomm_conns; ll; ll = ll->next) {
774 if (memcmp(device_address, &conn->addr,
775 sizeof(bluetooth_device_address_t)))
779 return BLUETOOTH_ERROR_NONE;
783 return BLUETOOTH_ERROR_NONE;
786 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept(int id, int max_pending_connection)
792 gboolean native_service = TRUE;
795 BT_CHECK_ENABLED(return);
797 BT_ERR("Invalid ID");
798 return BLUETOOTH_ERROR_INVALID_PARAM;
801 #ifdef TIZEN_DPM_ENABLE
802 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
803 BT_ERR("Not allow to use SPP profile");
804 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
809 BT_INFO("RFCOMM Listen & accept from app");
811 info = __find_rfcomm_info_with_id(id);
813 return BLUETOOTH_ERROR_INVALID_PARAM;
815 bt_register_profile_info_t profile_info;
818 profile_info.authentication = TRUE;
819 profile_info.authorization = TRUE;
820 profile_info.obj_path = info->path;
821 profile_info.role = NULL;
822 profile_info.service = info->uuid;
823 profile_info.uuid = info->uuid;
825 BT_INFO("uuid %s", profile_info.uuid);
826 result = _bt_register_profile(&profile_info, TRUE);
831 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
833 g_array_append_vals(in_param1, &id, sizeof(int));
834 g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
835 g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
837 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
838 in_param1, in_param2, in_param3, in_param4, &out_param);
840 BT_DBG("result: %x", result);
842 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
848 BT_EXPORT_API int bluetooth_rfcomm_listen_and_accept_ex(const char *uuid,
849 int max_pending_connection,
850 const char *bus_name, const char *path)
855 BT_CHECK_ENABLED(return);
857 #ifdef TIZEN_DPM_ENABLE
858 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
859 BT_ERR("Not allow to use SPP profile");
860 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
864 BT_INFO("RFCOMM Listen & accept from app");
866 info = __find_rfcomm_info_with_uuid(uuid);
868 return BLUETOOTH_ERROR_INVALID_PARAM;
870 bt_register_profile_info_t profile_info;
873 profile_info.authentication = TRUE;
874 profile_info.authorization = TRUE;
875 profile_info.obj_path = info->path;
876 profile_info.role = NULL;
877 profile_info.service = info->uuid;
878 profile_info.uuid = info->uuid;
880 BT_INFO("uuid %s", profile_info.uuid);
881 result = _bt_register_profile_ex(&profile_info, TRUE, bus_name, path);
885 return BLUETOOTH_ERROR_NOT_SUPPORT;
889 BT_EXPORT_API int bluetooth_rfcomm_listen(int id, int max_pending_connection)
895 gboolean native_service = FALSE;
898 BT_CHECK_ENABLED(return);
900 BT_ERR("Invalid ID");
901 return BLUETOOTH_ERROR_INVALID_PARAM;
904 #ifdef TIZEN_DPM_ENABLE
905 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
906 BT_ERR("Not allow to use SPP profile");
907 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
912 BT_INFO("RFCOMM Listen");
914 info = __find_rfcomm_info_with_id(id);
916 return BLUETOOTH_ERROR_INVALID_PARAM;
918 bt_register_profile_info_t profile_info;
921 profile_info.authentication = TRUE;
922 profile_info.authorization = TRUE;
923 profile_info.obj_path = info->path;
924 profile_info.role = NULL;
925 profile_info.service = info->uuid;
926 profile_info.uuid = info->uuid;
927 BT_INFO("UUID %s", info->uuid);
928 BT_INFO("PATH %s", info->path);
929 result = _bt_register_profile_platform(&profile_info, TRUE);
930 if (result != BLUETOOTH_ERROR_NONE)
933 return _bt_register_osp_server_in_agent(BT_RFCOMM_SERVER, info->uuid,
938 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
940 g_array_append_vals(in_param1, &id, sizeof(int));
941 g_array_append_vals(in_param2, &max_pending_connection, sizeof(int));
942 g_array_append_vals(in_param3, &native_service, sizeof(gboolean));
944 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_LISTEN,
945 in_param1, in_param2, in_param3, in_param4, &out_param);
947 BT_DBG("result: %x", result);
949 if (result == BLUETOOTH_ERROR_NONE)
952 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
958 BT_EXPORT_API int bluetooth_rfcomm_accept_connection(int server_fd)
962 BT_CHECK_ENABLED(return);
964 #ifdef TIZEN_DPM_ENABLE
965 if (_bt_check_dpm(BT_DPM_SPP, NULL) == BT_DPM_RESTRICTED) {
966 BT_ERR("Not allow to use SPP profile");
967 return BLUETOOTH_ERROR_DEVICE_POLICY_RESTRICTION;
972 BT_ERR("Invalid FD");
973 return BLUETOOTH_ERROR_INVALID_PARAM;
977 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
979 g_array_append_vals(in_param1, &server_fd, sizeof(int));
981 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_ACCEPT_CONNECTION,
982 in_param1, in_param2, in_param3, in_param4, &out_param);
984 BT_DBG("result: %x", result);
986 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
991 BT_EXPORT_API int bluetooth_rfcomm_reject_connection(int server_fd)
995 BT_CHECK_ENABLED(return);
998 BT_ERR("Invalid FD");
999 return BLUETOOTH_ERROR_INVALID_PARAM;
1005 BT_ALLOC_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);
1007 g_array_append_vals(in_param1, &server_fd, sizeof(int));
1009 result = _bt_send_request(BT_BLUEZ_SERVICE, BT_RFCOMM_REJECT_CONNECTION,
1010 in_param1, in_param2, in_param3, in_param4, &out_param);
1012 BT_DBG("result: %x", result);
1014 BT_FREE_PARAMS(in_param1, in_param2, in_param3, in_param4, out_param);