Cody sync.: merge tizen 2.4 code from spin git
[platform/core/connectivity/bluetooth-frwk.git] / bt-service / bt-service-rfcomm-server.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-glib.h>
25 //#include <dbus/dbus.h>
26 #include <glib.h>
27 #include <dlog.h>
28 #include <string.h>
29 #include <sys/socket.h>
30 #include <sys/un.h>
31
32 #include "bluetooth-api.h"
33 #include "bt-internal-types.h"
34
35 #include "bt-service-common.h"
36 #include "bt-service-event.h"
37 #include "bt-service-util.h"
38 #include "bt-service-rfcomm-client.h"
39 #include "bt-service-rfcomm-server.h"
40 #include "bt-service-agent.h"
41
42 /* Range of RFCOMM server ID : 0 ~ 244 */
43 #define BT_RFCOMM_SERVER_ID_MAX 245
44
45 #define BT_RFCOMM_PROXY_ADDRESS "x00/bluez/rfcomm"
46 #define BT_RFCOMM_SOCKET_ADDRESS "/bluez/rfcomm"
47
48 typedef struct {
49         int data_fd;
50         char *uuid;
51         char *remote_address;
52 } bt_rfcomm_event_info_t;
53
54 GSList *server_list;
55 bt_rfcomm_server_info_t *_bt_rfcomm_get_server_info_using_uuid(char *uuid)
56 {
57         GSList *l;
58         bt_rfcomm_server_info_t *server_info;
59
60         retv_if(uuid == NULL, NULL);
61
62         for (l = server_list; l != NULL; l = l->next) {
63                 server_info = l->data;
64
65                 if (server_info == NULL)
66                         continue;
67
68                 if (g_strcmp0(server_info->uuid, uuid) == 0)
69                         return server_info;
70         }
71
72         return NULL;
73 }
74
75 int _bt_rfcomm_create_socket(char *sender, char *uuid)
76 {
77         return BLUETOOTH_ERROR_INTERNAL;
78 }
79
80 int __bt_rfcomm_server_get_address(bt_rfcomm_server_info_t *server_info)
81 {
82         return BLUETOOTH_ERROR_NONE;
83 }
84
85 int _bt_rfcomm_listen(int socket_fd, int max_pending, gboolean is_native)
86 {
87         return BLUETOOTH_ERROR_NONE;
88 }
89
90 int _bt_rfcomm_remove_socket(int socket_fd)
91 {
92         return BLUETOOTH_ERROR_NONE;
93 }
94
95 int _bt_rfcomm_server_disconnect(int data_fd)
96 {
97         return BLUETOOTH_ERROR_NONE;
98 }
99
100 /* To support the BOT  */
101 int _bt_rfcomm_is_uuid_available(char *uuid, gboolean *available)
102 {
103         return BLUETOOTH_ERROR_NONE;
104 }
105
106 /* To support the BOT  */
107 int _bt_rfcomm_accept_connection(void)
108 {
109         BT_DBG("+");
110         if (!_bt_agent_reply_authorize(TRUE))
111                 return BLUETOOTH_ERROR_INTERNAL;
112
113         BT_DBG("-");
114         return BLUETOOTH_ERROR_NONE;
115 }
116
117 /* To support the BOT  */
118 int _bt_rfcomm_reject_connection(void)
119 {
120         BT_DBG("+");
121         if (!_bt_agent_reply_authorize(FALSE))
122                 return BLUETOOTH_ERROR_INTERNAL;
123
124         BT_DBG("-");
125         return BLUETOOTH_ERROR_NONE;
126 }
127
128 int _bt_rfcomm_server_disconnect_all_connection(void)
129 {
130         GSList *l;
131         bt_rfcomm_server_info_t *server_info;
132
133         for (l = server_list; l != NULL; l = l->next) {
134                 server_info = l->data;
135
136                 if (server_info == NULL)
137                         continue;
138
139                 _bt_rfcomm_disconnect(server_info->data_fd);
140         }
141
142         return BLUETOOTH_ERROR_NONE;
143 }
144
145 int _bt_rfcomm_server_check_existence(gboolean *existence)
146 {
147         BT_CHECK_PARAMETER(existence, return);
148
149         if (server_list && g_slist_length(server_list) > 0) {
150                 *existence = TRUE;
151         } else {
152                 *existence = FALSE;
153         }
154
155         return BLUETOOTH_ERROR_NONE;
156 }
157
158 int _bt_rfcomm_server_check_termination(char *name)
159 {
160         GSList *l;
161         bt_rfcomm_server_info_t *server_info;
162
163         BT_CHECK_PARAMETER(name, return);
164
165         for (l = server_list; l != NULL; l = l->next) {
166                 server_info = l->data;
167
168                 if (server_info == NULL)
169                         continue;
170
171                 if (g_strcmp0(server_info->sender, name) == 0) {
172                         _bt_rfcomm_remove_socket(server_info->control_fd);
173                 }
174         }
175
176         return BLUETOOTH_ERROR_NONE;
177 }
178
179