Add the privilege check for GATT SERVER APIs
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-rfcomm-client.c
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *              http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <dbus/dbus.h>
19 #include <glib.h>
20 #include <dlog.h>
21 #include <string.h>
22 #include <fcntl.h>
23
24 #include <gio/gio.h>
25 #include "bluetooth-api.h"
26 #include "bt-internal-types.h"
27
28 #include "bt-service-common.h"
29 #include "bt-service-event.h"
30 #include "bt-service-util.h"
31 #include "bt-service-rfcomm-client.h"
32 #include "bt-service-rfcomm-server.h"
33
34 typedef struct {
35         int req_id;
36         char *channel;
37         char *address;
38         char *uuid;
39         GDBusProxy *rfcomm_proxy;
40 } rfcomm_function_data_t;
41
42 rfcomm_function_data_t *rfcomm_info;
43 GSList *client_list;
44
45 static int __bt_rfcomm_terminate_client(int socket_fd)
46 {
47         return BLUETOOTH_ERROR_NONE;
48 }
49
50
51 int _bt_rfcomm_connect_using_uuid(int request_id,
52                         bluetooth_device_address_t *device_address,
53                         char *remote_uuid)
54 {
55         return BLUETOOTH_ERROR_NONE;
56 }
57
58 /* Range of the Channel : 0 <= channel <= 30 */
59 int _bt_rfcomm_connect_using_channel(int request_id,
60                         bluetooth_device_address_t *device_address,
61                         char *channel)
62 {
63         return BLUETOOTH_ERROR_NONE;
64 }
65
66 /* Be used in RFCOMM client /server */
67 int _bt_rfcomm_disconnect(int socket_fd)
68 {
69         return __bt_rfcomm_terminate_client(socket_fd);
70 }
71
72 /* Be used in RFCOMM client /server */
73 int _bt_rfcomm_write(int socket_fd, char *buf, int length)
74 {
75         return BLUETOOTH_ERROR_NONE;
76 }
77
78 int _bt_rfcomm_cancel_connect(void)
79 {
80         return BLUETOOTH_ERROR_NONE;
81 }
82
83 int _bt_rfcomm_is_connected(gboolean *connected)
84 {
85         BT_CHECK_PARAMETER(connected, return);
86
87         *connected = (client_list == NULL || g_slist_length(client_list) == 0) ?
88                                         FALSE : TRUE;
89
90         return BLUETOOTH_ERROR_NONE;
91 }
92
93 int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address,
94                                         gboolean *connected)
95 {
96         GSList *l;
97         bt_rfcomm_info_t *client_info;
98         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
99
100         BT_CHECK_PARAMETER(device_address, return);
101         BT_CHECK_PARAMETER(connected, return);
102
103         _bt_convert_addr_type_to_string(address, device_address->addr);
104
105         *connected = FALSE;
106
107         for (l = client_list; l != NULL; l = l->next) {
108                 client_info = l->data;
109
110                 if (client_info == NULL)
111                         continue;
112
113                 if (g_strcmp0(address, client_info->address) == 0) {
114                         *connected = TRUE;
115                         return BLUETOOTH_ERROR_NONE;
116                 }
117         }
118
119         return BLUETOOTH_ERROR_NONE;
120 }
121
122 int _bt_rfcomm_client_disconnect_all(void)
123 {
124         GSList *l;
125         bt_rfcomm_info_t *client_info;
126
127         for (l = client_list; l != NULL; l = l->next) {
128                 client_info = l->data;
129
130                 if (client_info == NULL)
131                         continue;
132
133                 _bt_rfcomm_disconnect(client_info->fd);
134         }
135
136         return BLUETOOTH_ERROR_NONE;
137 }
138