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