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