Merge the code from tizen_2.4
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-rfcomm-client.c
1 /*
2  * Bluetooth-frwk
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact:  Hocheol Seo <hocheol.seo@samsung.com>
7  *               Girishashok Joshi <girish.joshi@samsung.com>
8  *               Chanyeol Park <chanyeol.park@samsung.com>
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *              http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  */
23
24 #include <dbus/dbus.h>
25 #include <glib.h>
26 #include <dlog.h>
27 #include <string.h>
28 #include <fcntl.h>
29
30 #include <gio/gio.h>
31 #include "bluetooth-api.h"
32 #include "bt-internal-types.h"
33
34 #include "bt-service-common.h"
35 #include "bt-service-event.h"
36 #include "bt-service-util.h"
37 #include "bt-service-rfcomm-client.h"
38 #include "bt-service-rfcomm-server.h"
39
40 typedef struct {
41         int req_id;
42         char *channel;
43         char *address;
44         char *uuid;
45         GDBusProxy *rfcomm_proxy;
46 } rfcomm_function_data_t;
47
48 rfcomm_function_data_t *rfcomm_info;
49 GSList *client_list;
50
51 static int __bt_rfcomm_terminate_client(int socket_fd)
52 {
53         return BLUETOOTH_ERROR_NONE;
54 }
55
56
57 int _bt_rfcomm_connect_using_uuid(int request_id,
58                         bluetooth_device_address_t *device_address,
59                         char *remote_uuid)
60 {
61         return BLUETOOTH_ERROR_NONE;
62 }
63
64 /* Range of the Channel : 0 <= channel <= 30 */
65 int _bt_rfcomm_connect_using_channel(int request_id,
66                         bluetooth_device_address_t *device_address,
67                         char *channel)
68 {
69         return BLUETOOTH_ERROR_NONE;
70 }
71
72 /* Be used in RFCOMM client /server */
73 int _bt_rfcomm_disconnect(int socket_fd)
74 {
75         return __bt_rfcomm_terminate_client(socket_fd);
76 }
77
78 /* Be used in RFCOMM client /server */
79 int _bt_rfcomm_write(int socket_fd, char *buf, int length)
80 {
81         return BLUETOOTH_ERROR_NONE;
82 }
83
84 int _bt_rfcomm_cancel_connect(void)
85 {
86         return BLUETOOTH_ERROR_NONE;
87 }
88
89 int _bt_rfcomm_is_connected(gboolean *connected)
90 {
91         BT_CHECK_PARAMETER(connected, return);
92
93         *connected = (client_list == NULL || g_slist_length(client_list) == 0) ?
94                                         FALSE : TRUE;
95
96         return BLUETOOTH_ERROR_NONE;
97 }
98
99 int _bt_rfcomm_is_device_connected(bluetooth_device_address_t *device_address,
100                                         gboolean *connected)
101 {
102         GSList *l;
103         bt_rfcomm_info_t *client_info;
104         char address[BT_ADDRESS_STRING_SIZE] = { 0 };
105
106         BT_CHECK_PARAMETER(device_address, return);
107         BT_CHECK_PARAMETER(connected, return);
108
109         _bt_convert_addr_type_to_string(address, device_address->addr);
110
111         *connected = FALSE;
112
113         for (l = client_list; l != NULL; l = l->next) {
114                 client_info = l->data;
115
116                 if (client_info == NULL)
117                         continue;
118
119                 if (g_strcmp0(address, client_info->address) == 0) {
120                         *connected = TRUE;
121                         return BLUETOOTH_ERROR_NONE;
122                 }
123         }
124
125         return BLUETOOTH_ERROR_NONE;
126 }
127
128 int _bt_rfcomm_client_disconnect_all(void)
129 {
130         GSList *l;
131         bt_rfcomm_info_t *client_info;
132
133         for (l = client_list; l != NULL; l = l->next) {
134                 client_info = l->data;
135
136                 if (client_info == NULL)
137                         continue;
138
139                 _bt_rfcomm_disconnect(client_info->fd);
140         }
141
142         return BLUETOOTH_ERROR_NONE;
143 }
144