Add initial source files for ASP daemon
[platform/core/connectivity/asp-manager.git] / src / tech / asp-tech.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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  * Standard headers
19  *****************************************************************************/
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <time.h>
25
26 /*****************************************************************************
27  * System headers
28  *****************************************************************************/
29
30 #include <glib.h>
31 #include<dlog.h>
32
33 /*****************************************************************************
34  * Application Service Platform Daemon headers
35  *****************************************************************************/
36 #include "asp-manager-util.h"
37 #include "asp-service.h"
38 #include "asp-session.h"
39 #include "asp-tech.h"
40
41 /*****************************************************************************
42  * Macros and Typedefs
43  *****************************************************************************/
44
45 /* TODO : define service data structure */
46
47 /*****************************************************************************
48  * Global Variables
49  *****************************************************************************/
50
51 /* TODO : define local memory for service data structure */
52
53 extern asp_tech_ops_s asp_tech_p2p_ops;
54 extern asp_tech_ops_s asp_tech_ble_ops;
55 extern asp_tech_ops_s asp_tech_nfc_ops;
56 extern asp_tech_ops_s asp_tech_infra_ops;
57 extern asp_tech_ops_s asp_tech_nan_ops;
58
59 asp_tech_ops_s *asp_techs[] = {
60                 NULL,
61                 &asp_tech_p2p_ops,
62                 &asp_tech_ble_ops,
63                 &asp_tech_nfc_ops,
64                 &asp_tech_infra_ops,
65                 &asp_tech_nan_ops,
66                 NULL
67 };
68
69 /*****************************************************************************
70  * Local Functions Definition
71  *****************************************************************************/
72
73 void asp_tech_init()
74 {
75         __ASP_LOG_FUNC_ENTER__;
76         int result = 0;
77
78         result = asp_techs[ASP_TECH_P2P]->init();
79         if (result < 0) {
80                 ASP_LOGE("Failed to initialize p2p");
81                 /* TODO : exclude p2p technology */
82         }
83
84
85         result = asp_techs[ASP_TECH_INFRA]->init();
86         if (result < 0) {
87                 ASP_LOGE("Failed to initialize infra");
88                 /* TODO : exclude infra technology */
89         }
90
91         __ASP_LOG_FUNC_EXIT__;
92         return;
93 }
94
95 void asp_tech_deinit()
96 {
97         __ASP_LOG_FUNC_ENTER__;
98         int result = 0;
99
100         result = asp_techs[ASP_TECH_P2P]->deinit();
101         if (result < 0) {
102                 ASP_LOGE("Failed to deinitialize p2p");
103                 /* TODO : exclude p2p technology */
104         }
105
106
107         result = asp_techs[ASP_TECH_INFRA]->deinit();
108         if (result < 0) {
109                 ASP_LOGE("Failed to deinitialize infra");
110                 /* TODO : exclude infra technology */
111         }
112
113         __ASP_LOG_FUNC_EXIT__;
114         return;
115 }
116
117 int asp_tech_advertise(int tech, asp_service_advertise_s *service, int replace)
118 {
119         __ASP_LOG_FUNC_ENTER__;
120         int tech_idx = 0;
121         int i = 0;
122         int result = 0;
123
124         for (i = ASP_TECH_P2P; i != ASP_TECH_MAX; i++) {
125                 tech_idx =  1 << (i - 1);
126                 if (tech & tech_idx) {
127                         ASP_LOGD("Advertise using tech %d", tech);
128                         result = asp_techs[i]->advertise(service, replace);
129                 }
130                 /* TODO */
131                 /* error handling */
132         }
133
134         __ASP_LOG_FUNC_EXIT__;
135         return result;
136 }
137
138 int asp_tech_cancel_advertise(int tech, asp_service_advertise_s *service)
139 {
140         __ASP_LOG_FUNC_ENTER__;
141         int tech_idx = 0;
142         int i = 0;
143         int result = 0;
144
145         for (i = ASP_TECH_P2P; i != ASP_TECH_MAX; i++) {
146                 tech_idx =  1 << (i - 1);
147                 if (tech & tech_idx) {
148                         ASP_LOGD("Cancel advertise using tech %d", tech_idx);
149                         result = asp_techs[i]->cancel_advertise(service);
150                 }
151                 /* TODO */
152                 /* error handling */
153         }
154         __ASP_LOG_FUNC_EXIT__;
155         return result;
156 }
157
158 int asp_tech_seek(int tech, asp_service_seek_s *service)
159 {
160         __ASP_LOG_FUNC_ENTER__;
161         int tech_idx = 0;
162         int i = 0;
163         int result = 0;
164
165         for (i = 1; i != ASP_TECH_MAX; i++) {
166                 tech_idx =  1 << (i - 1);
167                 if (tech & tech_idx) {
168                         ASP_LOGD("Seek service using tech %d", tech_idx);
169                         result = asp_techs[i]->seek(service);
170                 }
171                 /* TODO */
172                 /* error handling */
173         }
174         __ASP_LOG_FUNC_EXIT__;
175         return result;
176 }
177
178 int asp_tech_cancel_seek(int tech, asp_service_seek_s *service)
179 {
180         __ASP_LOG_FUNC_ENTER__;
181         int tech_idx = 0;
182         int i = 0;
183         int result = 0;
184
185         for (i = 1; i != ASP_TECH_MAX; i++) {
186                 tech_idx =  1 << (i - 1);
187                 if (tech & tech_idx) {
188                         ASP_LOGD("Cancel seek service using tech %d", tech_idx);
189                         result = asp_techs[i]->cancel_seek(service);
190                 }
191                 /* TODO */
192                 /* error handling */
193         }
194         __ASP_LOG_FUNC_EXIT__;
195         return result;
196 }
197
198 int asp_tech_connect_session(int tech, asp_connect_session_params *params)
199 {
200         __ASP_LOG_FUNC_ENTER__;
201         int tech_idx = 0;
202         int i = 0;
203         int result = 0;
204
205         for (i = 1; i != ASP_TECH_MAX; i++) {
206                 tech_idx =  1 << (i - 1);
207                 if (tech & tech_idx) {
208                         ASP_LOGD("Connect session using tech %d", tech_idx);
209                         result = asp_techs[i]->connect_session(params);
210                         /* TODO */
211                         /* error handling */
212                         break;
213                 }
214         }
215         __ASP_LOG_FUNC_EXIT__;
216         return result;
217 }
218
219 int asp_tech_confirm_session(int tech, unsigned char *session_mac, int session_id, int confirm, const char *pin)
220 {
221         __ASP_LOG_FUNC_ENTER__;
222         int tech_idx = 0;
223         int i = 0;
224         int result = 0;
225
226         for (i = 1; i != ASP_TECH_MAX; i++) {
227                 tech_idx =  1 << (i - 1);
228                 if (tech & tech_idx) {
229                         ASP_LOGD("Confirm session using tech %d", tech_idx);
230                         result = asp_techs[i]->confirm_session(session_mac, session_id, confirm, pin);
231                         /* TODO */
232                         /* error handling */
233                         break;
234                 }
235         }
236         __ASP_LOG_FUNC_EXIT__;
237         return result;
238 }
239
240 int asp_tech_destroy_connection(int tech)
241 {
242         __ASP_LOG_FUNC_ENTER__;
243         int tech_idx = 0;
244         int i = 0;
245         int result = 0;
246
247         for (i = 1; i != ASP_TECH_MAX; i++) {
248                 tech_idx =  1 << (i - 1);
249                 if (tech & tech_idx) {
250                         ASP_LOGD("Destroy connection using tech %d", tech_idx);
251                         result = asp_techs[i]->destroy_connection();
252                 }
253                 /* TODO */
254                 /* error handling */
255         }
256         __ASP_LOG_FUNC_EXIT__;
257         return result;
258 }