2 * Copyright (c) 2016 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 /*****************************************************************************
19 *****************************************************************************/
26 /*****************************************************************************
28 *****************************************************************************/
33 /*****************************************************************************
34 * Application Service Platform Daemon headers
35 *****************************************************************************/
36 #include "asp-manager-util.h"
37 #include "asp-service.h"
38 #include "asp-session.h"
41 /*****************************************************************************
43 *****************************************************************************/
45 /* TODO : define service data structure */
47 /*****************************************************************************
49 *****************************************************************************/
51 /* TODO : define local memory for service data structure */
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;
59 asp_tech_ops_s *asp_techs[] = {
69 /*****************************************************************************
70 * Local Functions Definition
71 *****************************************************************************/
75 __ASP_LOG_FUNC_ENTER__;
78 result = asp_techs[ASP_TECH_P2P]->init();
80 ASP_LOGE("Failed to initialize p2p");
81 /* TODO : exclude p2p technology */
84 result = asp_techs[ASP_TECH_INFRA]->init();
86 ASP_LOGE("Failed to initialize infra");
87 /* TODO : exclude infra technology */
90 __ASP_LOG_FUNC_EXIT__;
94 void asp_tech_deinit()
96 __ASP_LOG_FUNC_ENTER__;
99 result = asp_techs[ASP_TECH_P2P]->deinit();
101 ASP_LOGE("Failed to deinitialize p2p");
102 /* TODO : exclude p2p technology */
105 result = asp_techs[ASP_TECH_INFRA]->deinit();
107 ASP_LOGE("Failed to deinitialize infra");
108 /* TODO : exclude infra technology */
111 __ASP_LOG_FUNC_EXIT__;
115 gint32 asp_tech_advertise(gint32 tech, asp_service_advertise_s *service, gint32 replace)
117 __ASP_LOG_FUNC_ENTER__;
122 for (i = ASP_TECH_P2P; i != ASP_TECH_MAX; i++) {
123 tech_idx = 1 << (i - 1);
124 if (tech & tech_idx) {
125 ASP_LOGD("Advertise using tech %d", tech);
126 result = asp_techs[i]->advertise(service, replace);
132 __ASP_LOG_FUNC_EXIT__;
136 gint32 asp_tech_cancel_advertise(gint32 tech, asp_service_advertise_s *service)
138 __ASP_LOG_FUNC_ENTER__;
143 for (i = ASP_TECH_P2P; i != ASP_TECH_MAX; i++) {
144 tech_idx = 1 << (i - 1);
145 if (tech & tech_idx) {
146 ASP_LOGD("Cancel advertise using tech %d", tech_idx);
147 result = asp_techs[i]->cancel_advertise(service);
152 __ASP_LOG_FUNC_EXIT__;
156 gint32 asp_tech_seek(gint32 tech, asp_service_seek_s *service)
158 __ASP_LOG_FUNC_ENTER__;
163 for (i = 1; i != ASP_TECH_MAX; i++) {
164 tech_idx = 1 << (i - 1);
165 if (tech & tech_idx) {
166 ASP_LOGD("Seek service using tech %d", tech_idx);
167 result = asp_techs[i]->seek(service);
172 __ASP_LOG_FUNC_EXIT__;
176 gint32 asp_tech_cancel_seek(gint32 tech, asp_service_seek_s *service)
178 __ASP_LOG_FUNC_ENTER__;
183 for (i = 1; i != ASP_TECH_MAX; i++) {
184 tech_idx = 1 << (i - 1);
185 if (tech & tech_idx) {
186 ASP_LOGD("Cancel seek service using tech %d", tech_idx);
187 result = asp_techs[i]->cancel_seek(service);
192 __ASP_LOG_FUNC_EXIT__;
196 gint32 asp_tech_connect_session(gint32 tech, asp_tech_session_request_params_s *params)
198 __ASP_LOG_FUNC_ENTER__;
203 for (i = 1; i != ASP_TECH_MAX; i++) {
204 tech_idx = 1 << (i - 1);
205 if (tech & tech_idx) {
206 ASP_LOGD("Connect session using tech %d", tech_idx);
207 result = asp_techs[i]->connect_session(params);
213 __ASP_LOG_FUNC_EXIT__;
217 gint32 asp_tech_confirm_session(gint32 tech, const guint8 *session_mac, gint32 session_id, gint32 confirm, guint32 pin)
219 __ASP_LOG_FUNC_ENTER__;
224 for (i = 1; i != ASP_TECH_MAX; i++) {
225 tech_idx = 1 << (i - 1);
226 if (tech & tech_idx) {
227 ASP_LOGD("Confirm session using tech %d", tech_idx);
228 result = asp_techs[i]->confirm_session(session_mac, session_id, confirm, pin);
234 __ASP_LOG_FUNC_EXIT__;
238 gint32 asp_tech_destroy_connection(gint32 tech, const guint8 *peer_id, gint32 peer_id_length)
240 __ASP_LOG_FUNC_ENTER__;
245 for (i = 1; i != ASP_TECH_MAX; i++) {
246 tech_idx = 1 << (i - 1);
247 if (tech & tech_idx) {
248 ASP_LOGD("Destroy connection using tech %d", tech_idx);
249 result = asp_techs[i]->destroy_connection(peer_id, peer_id_length);
254 __ASP_LOG_FUNC_EXIT__;
258 gint32 asp_tech_is_peer_connected(gint32 tech, const guint8 *peer_id, gint32 peer_id_length, gint32 *is_connected)
260 __ASP_LOG_FUNC_ENTER__;
265 for (i = 1; i != ASP_TECH_MAX; i++) {
266 tech_idx = 1 << (i - 1);
267 if (tech & tech_idx) {
268 ASP_LOGD("Is peer connected using tech %d", tech_idx);
269 result = asp_techs[i]->is_peer_connected(peer_id, peer_id_length, is_connected);
274 __ASP_LOG_FUNC_EXIT__;
278 void asp_tech_set_session_request_cb(gint32 tech, asp_tech_session_request_cb cb, gpointer user_data)
280 __ASP_LOG_FUNC_ENTER__;
284 for (i = 1; i != ASP_TECH_MAX; i++) {
285 tech_idx = 1 << (i - 1);
286 if (tech & tech_idx) {
287 ASP_LOGD("Set session_request_cb using tech %d", tech_idx);
288 asp_techs[i]->session_request_cb = cb;
289 asp_techs[i]->session_request_cb_user_data = user_data;
294 __ASP_LOG_FUNC_EXIT__;
298 void asp_tech_set_session_config_request_cb(gint32 tech, asp_tech_session_config_request_cb cb, gpointer user_data)
300 __ASP_LOG_FUNC_ENTER__;
304 for (i = 1; i != ASP_TECH_MAX; i++) {
305 tech_idx = 1 << (i - 1);
306 if (tech & tech_idx) {
307 ASP_LOGD("Set session_config_request_cb using tech %d", tech_idx);
308 asp_techs[i]->session_config_request_cb = cb;
309 asp_techs[i]->session_config_request_cb_user_data = user_data;
314 __ASP_LOG_FUNC_EXIT__;
318 void asp_tech_set_connect_status_cb(gint32 tech, asp_tech_connect_status_cb cb, gpointer user_data)
320 __ASP_LOG_FUNC_ENTER__;
324 for (i = 1; i != ASP_TECH_MAX; i++) {
325 tech_idx = 1 << (i - 1);
326 if (tech & tech_idx) {
327 ASP_LOGD("Set connect_status_cb using tech %d", tech_idx);
328 asp_techs[i]->connect_status_cb = cb;
329 asp_techs[i]->connect_status_cb_user_data = user_data;
334 __ASP_LOG_FUNC_EXIT__;
338 void asp_tech_set_ip_assigned_cb(gint32 tech, asp_tech_ip_assigned_cb cb, gpointer user_data)
340 __ASP_LOG_FUNC_ENTER__;
344 for (i = 1; i != ASP_TECH_MAX; i++) {
345 tech_idx = 1 << (i - 1);
346 if (tech & tech_idx) {
347 ASP_LOGD("Set ip_assigned_cb using tech %d", tech_idx);
348 asp_techs[i]->ip_assigned_cb = cb;
349 asp_techs[i]->ip_assigned_cb_user_data = user_data;
354 __ASP_LOG_FUNC_EXIT__;