2 * Application Service Platform(ASP)
4 * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 * This file implements Application Service Platform(ASP) user library.
24 * @author Jiung Yu (jiung.yu@samsung.com)
29 /*****************************************************************************
31 *****************************************************************************/
38 #include <sys/socket.h>
43 #include <sys/ioctl.h>
45 #include <linux/unistd.h>
53 /*****************************************************************************
55 *****************************************************************************/
56 #include <system_info.h>
58 /*****************************************************************************
59 * Application Service Platform(ASP) library headers
60 *****************************************************************************/
63 #include "asp-client.h"
68 /*****************************************************************************
70 *****************************************************************************/
72 /*****************************************************************************
74 *****************************************************************************/
75 static __thread asp_client_info_s g_client_info = {
76 .is_registered = FALSE,
78 .seek_search_result_cb = NULL,
79 .advert_status_changed_cb = NULL,
80 .session_request_cb = NULL,
81 .session_config_request_cb = NULL,
82 .session_connect_status_cb = NULL,
83 .session_status_cb = NULL,
84 .session_port_status_cb = NULL,
86 .user_data_for_cb_seek_search_result = NULL,
87 .user_data_for_cb_advert_status_changed = NULL,
88 .user_data_for_cb_session_request = NULL,
89 .user_data_for_cb_session_config_request = NULL,
90 .user_data_for_cb_session_connect_status = NULL,
91 .user_data_for_cb_session_status = NULL,
92 .user_data_for_cb_session_port_status = NULL
95 static __thread GList *asp_adverts = NULL;
96 static __thread GList *asp_seeks = NULL;
97 static __thread GList *asp_sessions = NULL;
99 /*****************************************************************************
100 * Local Functions Definition
101 *****************************************************************************/
103 static int _txt_to_mac(char *txt, unsigned char *mac)
108 mac[i++] = (char)strtoul(txt, &txt, 16);
109 if (i == MACADDR_LEN || !*txt++)
113 if (i != MACADDR_LEN)
116 ASP_LOGD("Converted MAC address [" MACSECSTR "]",
121 static int __asp_err_string_to_enum(const char *error)
123 if (NULL != strstr(error, "NoReply"))
124 return ASP_ERROR_COMMUNICATION_FAILED;
125 else if (NULL != strstr(error, "PermissionDenied"))
126 return ASP_ERROR_PERMISSION_DENIED;
127 else if (NULL != strstr(error, "MEM_ERR"))
128 return ASP_ERROR_OUT_OF_MEMORY;
129 else if (NULL != strstr(error, "INVALID_PARAM"))
130 return ASP_ERROR_INVALID_PARAMETER;
131 else if (NULL != strstr(error, "OPER_FAILED"))
132 return ASP_ERROR_OPERATION_FAILED;
133 else if (NULL != strstr(error, "NO_SERVICE"))
134 return ASP_ERROR_SERVICE_NOT_FOUND;
135 else if (NULL != strstr(error, "NO_SESSION"))
136 return ASP_ERROR_SESSION_NOT_FOUND;
138 return ASP_ERROR_OPERATION_FAILED;
141 static char* __asp_create_service_info_from_g_variant(GVariant *variant)
143 GVariantIter *iter = NULL;
144 GVariant* var = NULL;
152 info = (gchar*)g_try_malloc0(ASP_SERVICE_INFO_MAX_LEN + 1);
156 g_variant_get(variant, "a{sv}", &iter);
157 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
158 value = g_variant_dup_string(var, &value_len);
159 len = strlen(key) + value_len + 2;
160 snprintf(info + offset, len + 1, "%s=%s,", key, value);
168 void asp_process_seek_search_result(GDBusConnection *connection,
169 const gchar *object_path, GVariant *parameters)
171 __ASP_LOG_FUNC_START__;
173 asp_client_info_s *client = &g_client_info;
175 GVariantIter *iter = NULL;
176 GVariant *var = NULL;
177 const char *key = NULL;
178 const char *str = NULL;
179 unsigned int search_id = 0;
180 const char *service_mac = NULL;
181 unsigned int advertisement_id = 0;
182 unsigned int config_method = 0;
183 char *instance_name = NULL;
184 char *service_info = NULL;
185 unsigned char status = 0;
186 int error_code = ASP_ERROR_NONE;
188 if (!client->seek_search_result_cb) {
189 ASP_LOGE("search_result_cb is NULL!!");
194 __ASP_LOG_FUNC_END__;
198 g_variant_get(parameters, "(a{sv})", &iter);
199 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
200 if (!g_strcmp0(key, "search_id")) {
201 g_variant_get(var, "u", &search_id);
202 } else if (!g_strcmp0(key, "service_mac")) {
203 g_variant_get(var, "&s", &str);
204 service_mac = g_strndup(str, MACSTR_LEN);
205 } else if (!g_strcmp0(key, "adv_id")) {
206 g_variant_get(var, "u", &advertisement_id);
207 } else if (!g_strcmp0(key, "config_method")) {
208 g_variant_get(var, "u", &config_method);
209 } else if (!g_strcmp0(key, "instance_name")) {
210 g_variant_get(var, "&s", &str);
211 instance_name = g_strdup(str);
212 } else if (!g_strcmp0(key, "service_info")) {
213 service_info = __asp_create_service_info_from_g_variant(var);
214 ASP_LOGD("Service Info: %s", service_info);
215 } else if (!g_strcmp0(key, "service_status")) {
216 g_variant_get(var, "y", &status);
222 //TODO :client->search_result_cb
223 g_variant_iter_free(iter);
225 __ASP_LOG_FUNC_END__;
229 void asp_process_advert_status_changed(GDBusConnection *connection,
230 const gchar *object_path, GVariant *parameters)
232 __ASP_LOG_FUNC_START__;
234 asp_client_info_s *client = &g_client_info;
235 unsigned int advertisement_id = 0;
236 unsigned char status = 0;
239 if (!client->advert_status_changed_cb) {
240 ASP_LOGE("search_result_cb is NULL!!");
245 __ASP_LOG_FUNC_END__;
249 g_variant_get(parameters, "(uyi)", &advertisement_id, &status, &reason);
251 //TODO :client->advert_status_changed_cb
253 __ASP_LOG_FUNC_END__;
257 int __handle_session_request(unsigned int adv_id, char *session_mac,
258 unsigned int session_id, char *session_info)
260 __ASP_LOG_FUNC_START__;
261 asp_client_advert_s *service = NULL;
262 asp_client_session_s *session = NULL;
266 for (temp = g_list_first(asp_adverts);
267 temp != NULL; temp = g_list_next(temp)) {
268 service = temp->data;
269 if (service != NULL && service->adv_id == adv_id)
274 if (service == NULL) {
275 ASP_LOGD("No matched local service");
276 __ASP_LOG_FUNC_END__;
280 if (service->auto_accept == FALSE) {
281 ASP_LOGD("Don't accept request automatically");
282 __ASP_LOG_FUNC_END__;
287 ASP_LOGD("Process auto accept service");
290 for (temp = g_list_first(asp_sessions);
291 temp != NULL; temp = g_list_next(temp)) {
292 session = temp->data;
293 if (session != NULL && session->session_id == session_id &&
294 memcmp(session->session_mac, session_mac, MACSTR_LEN) == 0)
299 if (session == NULL) {
300 //TODO :asp_get_session
301 //res = asp_get_session(session_mac, session_id, (void **)&session);
303 ASP_LOGE("asp_get_session failed");
304 __ASP_LOG_FUNC_END__;
309 session->session_information = g_strdup(session_info);
310 asp_sessions = g_list_prepend(asp_sessions, session);
313 //TODO :asp_confirm_session
314 //asp_confirm_session(session, TRUE, NULL);
315 ASP_LOGD("asp_confirm_session");
316 __ASP_LOG_FUNC_END__;
320 void asp_process_session_request(GDBusConnection *connection,
321 const gchar *object_path, GVariant *parameters)
323 __ASP_LOG_FUNC_START__;
325 asp_client_info_s *client = &g_client_info;
327 GVariantIter *iter = NULL;
328 GVariant *var = NULL;
329 const char *key = NULL;
330 const char *str = NULL;
331 unsigned int adv_id = 0;
332 char *session_mac = NULL;
333 char * device_name = NULL;
334 unsigned int session_id = 0;
335 char *session_info = NULL;
336 gboolean get_network_config_pin = FALSE;
337 char *network_config_pin = NULL;
338 int error_code = ASP_ERROR_NONE;
340 if (!client->session_request_cb) {
341 ASP_LOGE("session_request_cb is NULL!!");
346 ASP_LOGE("parameters is NULL!!");
347 __ASP_LOG_FUNC_END__;
351 g_variant_get(parameters, "(a{sv})", &iter);
352 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
353 if (!g_strcmp0(key, "adv_id")) {
354 g_variant_get(var, "u", &adv_id);
355 } else if (!g_strcmp0(key, "session_id")) {
356 g_variant_get(var, "u", &session_id);
357 } else if (!g_strcmp0(key, "session_mac")) {
358 g_variant_get(var, "&s", &str);
359 session_mac = g_strndup(str, MACSTR_LEN);
360 } else if (!g_strcmp0(key, "device_name")) {
361 g_variant_get(var, "&s", &str);
362 device_name = g_strdup(str);
363 } else if (!g_strcmp0(key, "session_info")) {
364 g_variant_get(var, "&s", &str);
365 session_info = g_strdup(str);
366 } else if (!g_strcmp0(key, "get_pin")) {
367 g_variant_get(var, "b", &get_network_config_pin);
368 } else if (!g_strcmp0(key, "pin")) {
369 g_variant_get(var, "&s", &str);
370 network_config_pin = g_strdup(str);
376 if (__handle_session_request(adv_id, session_mac,
377 session_id, session_info) == 0) {
378 //TODO :client->session_request_cb
381 g_free(session_info);
383 g_free(network_config_pin);
385 g_variant_iter_free(iter);
387 __ASP_LOG_FUNC_END__;
391 void asp_process_session_config_request(GDBusConnection *connection,
392 const gchar *object_path, GVariant *parameters)
394 __ASP_LOG_FUNC_START__;
396 asp_client_info_s *client = &g_client_info;
398 GVariantIter *iter = NULL;
399 GVariant *var = NULL;
400 const char *key = NULL;
401 const char *str = NULL;
402 unsigned int session_id = 0;
403 gboolean get_pin = false;
404 const char *config_pin = NULL;
405 int error_code = ASP_ERROR_NONE;
407 if (!client->session_config_request_cb) {
408 ASP_LOGE("session_config_request_cb is NULL!!");
413 __ASP_LOG_FUNC_END__;
417 g_variant_get(parameters, "(a{sv})", &iter);
418 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
419 if (!g_strcmp0(key, "session_id")) {
420 g_variant_get(var, "u", &session_id);
421 } else if (!g_strcmp0(key, "get_pin")) {
422 g_variant_get(var, "b", &get_pin);
423 } else if (!g_strcmp0(key, "pin")) {
424 g_variant_get(var, "&s", &str);
425 config_pin = g_strdup(str);
431 //TODO :client->session_config_request_cb
432 g_variant_iter_free(iter);
434 __ASP_LOG_FUNC_END__;
438 void asp_process_session_connect_status(GDBusConnection *connection,
439 const gchar *object_path, GVariant *parameters)
441 __ASP_LOG_FUNC_START__;
443 asp_client_info_s *client = &g_client_info;
445 GVariantIter *iter = NULL;
446 GVariant *var = NULL;
447 const char *key = NULL;
448 const char *str = NULL;
449 const char *session_mac = NULL;
450 unsigned int session_id = 0;
452 char *deferred_resp = NULL;
453 int error_code = ASP_ERROR_NONE;
455 if (!client->session_connect_status_cb) {
456 ASP_LOGE("connect_status_cb is NULL!!");
461 __ASP_LOG_FUNC_END__;
465 g_variant_get(parameters, "(a{sv})", &iter);
466 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
467 if (!g_strcmp0(key, "session_id")) {
468 g_variant_get(var, "u", &session_id);
469 } else if (!g_strcmp0(key, "session_mac")) {
470 g_variant_get(var, "&s", &str);
471 session_mac = g_strndup(str, MACSTR_LEN);
472 } else if (!g_strcmp0(key, "status")) {
473 g_variant_get(var, "i", &status);
474 } else if (!g_strcmp0(key, "deferred_resp")) {
475 g_variant_get(var, "&s", &str);
476 deferred_resp = g_strdup(str);
482 //TODO :client->session_connect_status_cb
483 g_variant_iter_free(iter);
485 __ASP_LOG_FUNC_END__;
489 void asp_process_session_status(GDBusConnection *connection,
490 const gchar *object_path, GVariant *parameters)
492 __ASP_LOG_FUNC_START__;
494 asp_client_info_s *client = &g_client_info;
496 GVariantIter *iter = NULL;
497 GVariant *var = NULL;
498 const char *key = NULL;
499 const char *str = NULL;
500 const char *session_mac = NULL;
501 unsigned int session_id = 0;
504 char *requested_info = NULL;
505 int error_code = ASP_ERROR_NONE;
507 if (!client->session_status_cb) {
508 ASP_LOGE("session_status_cb is NULL!!");
513 __ASP_LOG_FUNC_END__;
517 g_variant_get(parameters, "(a{sv})", &iter);
518 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
519 if (!g_strcmp0(key, "session_id")) {
520 g_variant_get(var, "u", &session_id);
521 } else if (!g_strcmp0(key, "session_mac")) {
522 g_variant_get(var, "&s", &str);
523 session_mac = g_strndup(str, MACSTR_LEN);
524 } else if (!g_strcmp0(key, "state")) {
525 g_variant_get(var, "i", &state);
526 } else if (!g_strcmp0(key, "status")) {
527 g_variant_get(var, "i", &status);
528 } else if (!g_strcmp0(key, "requested_info")) {
529 g_variant_get(var, "&s", &str);
530 requested_info = g_strdup(str);
536 //TODO :client->session_status_cb
538 __ASP_LOG_FUNC_END__;
542 void asp_process_session_port_status(GDBusConnection *connection,
543 const gchar *object_path, GVariant *parameters)
545 __ASP_LOG_FUNC_START__;
547 asp_client_info_s *client = &g_client_info;
549 GVariantIter *iter = NULL;
550 GVariant *var = NULL;
551 const char *key = NULL;
552 const char *str = NULL;
553 const char *session_mac = NULL;
554 const char *ip_address = NULL;
555 unsigned int session_id = 0;
559 int error_code = ASP_ERROR_NONE;
561 if (!client->session_port_status_cb) {
562 ASP_LOGE("port_status_cb is NULL!!");
567 __ASP_LOG_FUNC_END__;
571 g_variant_get(parameters, "(a{sv})", &iter);
572 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
573 if (!g_strcmp0(key, "session_id")) {
574 g_variant_get(var, "u", &session_id);
575 } else if (!g_strcmp0(key, "session_mac")) {
576 g_variant_get(var, "&s", &str);
577 session_mac = g_strndup(str, MACSTR_LEN);
578 } else if (!g_strcmp0(key, "ip_address")) {
579 g_variant_get(var, "&s", &ip_address);
580 } else if (!g_strcmp0(key, "port")) {
581 g_variant_get(var, "i", &port);
582 } else if (!g_strcmp0(key, "proto")) {
583 g_variant_get(var, "i", &proto);
584 } else if (!g_strcmp0(key, "status")) {
585 g_variant_get(var, "i", &status);
591 //TODO :client->session_port_status_cb
593 __ASP_LOG_FUNC_END__;
597 int asp_initialize(void)
599 __ASP_LOG_FUNC_START__;
601 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
603 if (g_client_info.is_registered == TRUE) {
604 ASP_LOGW("Warning!!! Already registered\nUpdate user data and callback!");
605 __ASP_LOG_FUNC_END__;
606 return ASP_ERROR_ALREADY_INITIALIZED;
609 if (asp_dbus_init() == FALSE) {
610 ASP_LOGW("Failed to initialize dbus");
611 __ASP_LOG_FUNC_END__;
612 return ASP_ERROR_OPERATION_FAILED;
615 g_client_info.is_registered = TRUE;
617 /* Initialize callbacks */
618 g_client_info.seek_search_result_cb = NULL;
619 g_client_info.advert_status_changed_cb = NULL;
621 g_client_info.session_request_cb = NULL;
622 g_client_info.session_config_request_cb = NULL;
623 g_client_info.session_connect_status_cb = NULL;
624 g_client_info.session_status_cb = NULL;
625 g_client_info.session_port_status_cb = NULL;
627 g_client_info.user_data_for_cb_seek_search_result = NULL;
628 g_client_info.user_data_for_cb_advert_status_changed = NULL;
630 g_client_info.user_data_for_cb_session_request = NULL;
631 g_client_info.user_data_for_cb_session_config_request = NULL;
632 g_client_info.user_data_for_cb_session_connect_status = NULL;
633 g_client_info.user_data_for_cb_session_status = NULL;
634 g_client_info.user_data_for_cb_session_port_status = NULL;
636 __ASP_LOG_FUNC_END__;
637 return ASP_ERROR_NONE;
640 int asp_deinitialize(void)
642 __ASP_LOG_FUNC_START__;
644 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
646 if (g_client_info.is_registered == false) {
647 ASP_LOGE("Client is already deregistered");
648 __ASP_LOG_FUNC_END__;
649 return ASP_ERROR_NOT_INITIALIZED;
654 g_client_info.seek_search_result_cb = NULL;
655 g_client_info.advert_status_changed_cb = NULL;
657 g_client_info.session_request_cb = NULL;
658 g_client_info.session_config_request_cb = NULL;
659 g_client_info.session_connect_status_cb = NULL;
660 g_client_info.session_status_cb = NULL;
661 g_client_info.session_port_status_cb = NULL;
663 g_client_info.user_data_for_cb_seek_search_result = NULL;
664 g_client_info.user_data_for_cb_advert_status_changed = NULL;
666 g_client_info.user_data_for_cb_session_request = NULL;
667 g_client_info.user_data_for_cb_session_config_request = NULL;
668 g_client_info.user_data_for_cb_session_connect_status = NULL;
669 g_client_info.user_data_for_cb_session_status = NULL;
670 g_client_info.user_data_for_cb_session_port_status = NULL;
672 g_client_info.is_registered = FALSE;
674 __ASP_LOG_FUNC_END__;
675 return ASP_ERROR_NONE;
677 int asp_seek_set_search_result_cb(asp_seek_search_result_cb cb, void *user_data)
679 __ASP_LOG_FUNC_START__;
681 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
684 ASP_LOGE("Invalid parameter");
685 __ASP_LOG_FUNC_END__;
686 return ASP_ERROR_INVALID_PARAMETER;
689 if (g_client_info.is_registered == false) {
690 ASP_LOGE("Client is not initialized.");
691 __ASP_LOG_FUNC_END__;
692 return ASP_ERROR_NOT_INITIALIZED;
695 g_client_info.seek_search_result_cb = cb;
696 g_client_info.user_data_for_cb_seek_search_result = user_data;
698 __ASP_LOG_FUNC_END__;
699 return ASP_ERROR_NONE;
702 int asp_seek_unset_search_result_cb(void)
704 __ASP_LOG_FUNC_START__;
706 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
708 if (g_client_info.is_registered == false) {
709 ASP_LOGE("Client is not initialized.\n");
710 __ASP_LOG_FUNC_END__;
711 return ASP_ERROR_NOT_INITIALIZED;
714 g_client_info.seek_search_result_cb = NULL;
715 g_client_info.user_data_for_cb_seek_search_result = NULL;
717 __ASP_LOG_FUNC_END__;
718 return ASP_ERROR_NONE;
721 int asp_advert_set_status_changed_cb(asp_advert_status_changed_cb cb, void *user_data)
723 __ASP_LOG_FUNC_START__;
725 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
728 ASP_LOGE("Invalid parameter");
729 __ASP_LOG_FUNC_END__;
730 return ASP_ERROR_INVALID_PARAMETER;
733 if (g_client_info.is_registered == false) {
734 ASP_LOGE("Client is not initialized.");
735 __ASP_LOG_FUNC_END__;
736 return ASP_ERROR_NOT_INITIALIZED;
739 g_client_info.advert_status_changed_cb = cb;
740 g_client_info.user_data_for_cb_advert_status_changed = user_data;
742 __ASP_LOG_FUNC_END__;
743 return ASP_ERROR_NONE;
746 int asp_advert_unset_status_changed_cb(void)
748 __ASP_LOG_FUNC_START__;
750 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
752 if (g_client_info.is_registered == false) {
753 ASP_LOGE("Client is not initialized.\n");
754 __ASP_LOG_FUNC_END__;
755 return ASP_ERROR_NOT_INITIALIZED;
758 g_client_info.advert_status_changed_cb = NULL;
759 g_client_info.user_data_for_cb_advert_status_changed = NULL;
761 __ASP_LOG_FUNC_END__;
762 return ASP_ERROR_NONE;
765 int asp_session_set_request_cb(asp_session_request_cb cb, void *user_data)
767 __ASP_LOG_FUNC_START__;
769 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
772 ASP_LOGE("Invalid parameter");
773 __ASP_LOG_FUNC_END__;
774 return ASP_ERROR_INVALID_PARAMETER;
777 if (g_client_info.is_registered == false) {
778 ASP_LOGE("Client is not initialized.");
779 __ASP_LOG_FUNC_END__;
780 return ASP_ERROR_NOT_INITIALIZED;
783 g_client_info.session_request_cb = cb;
784 g_client_info.user_data_for_cb_session_request = user_data;
786 __ASP_LOG_FUNC_END__;
787 return ASP_ERROR_NONE;
790 int asp_session_unset_request_cb(void)
792 __ASP_LOG_FUNC_START__;
794 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
796 if (g_client_info.is_registered == false) {
797 ASP_LOGE("Client is not initialized.\n");
798 __ASP_LOG_FUNC_END__;
799 return ASP_ERROR_NOT_INITIALIZED;
802 g_client_info.session_request_cb = NULL;
803 g_client_info.user_data_for_cb_session_request = NULL;
805 __ASP_LOG_FUNC_END__;
806 return ASP_ERROR_NONE;
809 int asp_session_set_config_request_cb(asp_session_config_request_cb cb, void *user_data)
811 __ASP_LOG_FUNC_START__;
813 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
816 ASP_LOGE("Invalid parameter");
817 __ASP_LOG_FUNC_END__;
818 return ASP_ERROR_INVALID_PARAMETER;
821 if (g_client_info.is_registered == false) {
822 ASP_LOGE("Client is not initialized.");
823 __ASP_LOG_FUNC_END__;
824 return ASP_ERROR_NOT_INITIALIZED;
827 g_client_info.session_config_request_cb = cb;
828 g_client_info.user_data_for_cb_session_config_request = user_data;
830 __ASP_LOG_FUNC_END__;
831 return ASP_ERROR_NONE;
834 int asp_session_unset_config_request_cb(void)
836 __ASP_LOG_FUNC_START__;
838 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
840 if (g_client_info.is_registered == false) {
841 ASP_LOGE("Client is not initialized.\n");
842 __ASP_LOG_FUNC_END__;
843 return ASP_ERROR_NOT_INITIALIZED;
846 g_client_info.session_config_request_cb = NULL;
847 g_client_info.user_data_for_cb_session_config_request = NULL;
849 __ASP_LOG_FUNC_END__;
850 return ASP_ERROR_NONE;
853 int asp_session_set_connect_status_cb(asp_session_connect_status_cb cb, void *user_data)
855 __ASP_LOG_FUNC_START__;
857 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
860 ASP_LOGE("Invalid parameter");
861 __ASP_LOG_FUNC_END__;
862 return ASP_ERROR_INVALID_PARAMETER;
865 if (g_client_info.is_registered == false) {
866 ASP_LOGE("Client is not initialized.");
867 __ASP_LOG_FUNC_END__;
868 return ASP_ERROR_NOT_INITIALIZED;
871 g_client_info.session_connect_status_cb = cb;
872 g_client_info.user_data_for_cb_session_connect_status = user_data;
874 __ASP_LOG_FUNC_END__;
875 return ASP_ERROR_NONE;
879 int asp_session_unset_connect_status_cb(void)
881 __ASP_LOG_FUNC_START__;
883 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
885 if (g_client_info.is_registered == false) {
886 ASP_LOGE("Client is not initialized.\n");
887 __ASP_LOG_FUNC_END__;
888 return ASP_ERROR_NOT_INITIALIZED;
891 g_client_info.session_connect_status_cb = NULL;
892 g_client_info.user_data_for_cb_session_connect_status = NULL;
894 __ASP_LOG_FUNC_END__;
895 return ASP_ERROR_NONE;
898 int asp_session_set_status_cb(asp_session_status_cb cb, void *user_data)
900 __ASP_LOG_FUNC_START__;
902 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
905 ASP_LOGE("Invalid parameter");
906 __ASP_LOG_FUNC_END__;
907 return ASP_ERROR_INVALID_PARAMETER;
910 if (g_client_info.is_registered == false) {
911 ASP_LOGE("Client is not initialized.");
912 __ASP_LOG_FUNC_END__;
913 return ASP_ERROR_NOT_INITIALIZED;
916 g_client_info.session_status_cb = cb;
917 g_client_info.user_data_for_cb_session_status = user_data;
919 __ASP_LOG_FUNC_END__;
920 return ASP_ERROR_NONE;
924 int asp_session_unset_status_cb(void)
926 __ASP_LOG_FUNC_START__;
928 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
930 if (g_client_info.is_registered == false) {
931 ASP_LOGE("Client is not initialized.\n");
932 __ASP_LOG_FUNC_END__;
933 return ASP_ERROR_NOT_INITIALIZED;
936 g_client_info.session_status_cb = NULL;
937 g_client_info.user_data_for_cb_session_status = NULL;
939 __ASP_LOG_FUNC_END__;
940 return ASP_ERROR_NONE;
943 int asp_session_set_port_status_cb(asp_session_port_status_cb cb, void *user_data)
945 __ASP_LOG_FUNC_START__;
947 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
950 ASP_LOGE("Invalid parameter");
951 __ASP_LOG_FUNC_END__;
952 return ASP_ERROR_INVALID_PARAMETER;
955 if (g_client_info.is_registered == false) {
956 ASP_LOGE("Client is not initialized.");
957 __ASP_LOG_FUNC_END__;
958 return ASP_ERROR_NOT_INITIALIZED;
961 g_client_info.session_port_status_cb = cb;
962 g_client_info.user_data_for_cb_session_port_status = user_data;
964 __ASP_LOG_FUNC_END__;
965 return ASP_ERROR_NONE;
968 int asp_session_unset_port_status_cb(void)
970 __ASP_LOG_FUNC_START__;
972 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
974 if (g_client_info.is_registered == false) {
975 ASP_LOGE("Client is not initialized.\n");
976 __ASP_LOG_FUNC_END__;
977 return ASP_ERROR_NOT_INITIALIZED;
980 g_client_info.session_port_status_cb = NULL;
981 g_client_info.user_data_for_cb_session_port_status = NULL;
983 __ASP_LOG_FUNC_END__;
984 return ASP_ERROR_NONE;
987 typedef void (*free_func)(void *);
989 static void __free_advert(void *advert)
991 __ASP_LOG_FUNC_START__;
992 asp_client_advert_s *service = NULL;
994 service = (asp_client_advert_s *)advert;
995 if (service == NULL) {
996 ASP_LOGE("invalid parameter");
997 __ASP_LOG_FUNC_END__;
1001 g_free(service->instance_name);
1002 g_free(service->serivce_name);
1003 g_free(service->service_type);
1004 g_free(service->rsp_info);
1005 g_hash_table_destroy(service->service_info_map);
1008 __ASP_LOG_FUNC_END__;
1012 static void __free_seek(void *seek)
1014 __ASP_LOG_FUNC_START__;
1015 asp_client_seek_s *service = NULL;
1017 service = (asp_client_seek_s *)seek;
1018 if (service == NULL) {
1019 ASP_LOGE("invalid parameter");
1020 __ASP_LOG_FUNC_END__;
1024 g_free(service->serivce_name);
1025 g_free(service->service_type);
1026 g_free(service->rsp_info);
1027 g_hash_table_destroy(service->service_info_map);
1030 __ASP_LOG_FUNC_END__;
1034 static void __free_session(void *session)
1036 __ASP_LOG_FUNC_START__;
1037 asp_client_session_s *service = NULL;
1039 service = (asp_client_session_s *)session;
1040 if (service == NULL) {
1041 ASP_LOGE("invalid parameter");
1042 __ASP_LOG_FUNC_END__;
1046 g_free(service->session_information);
1047 g_free(service->deferred_session_response);
1050 __ASP_LOG_FUNC_END__;
1054 static asp_client_advert_s *__get_advert(void *handle)
1056 __ASP_LOG_FUNC_START__;
1057 asp_client_advert_s *service = NULL;
1060 if (asp_adverts == NULL) {
1061 __ASP_LOG_FUNC_END__;
1065 ASP_LOGD("service [%p]", handle);
1067 temp = g_list_first(asp_adverts);
1068 for (temp = g_list_first(asp_adverts); temp != NULL; temp = g_list_next(temp)) {
1069 service = temp->data;
1071 ASP_LOGD("temp [%p]", service);
1072 if (service != NULL && service == handle)
1076 __ASP_LOG_FUNC_END__;
1080 static asp_client_seek_s *__get_seek(void *handle)
1082 __ASP_LOG_FUNC_START__;
1083 asp_client_seek_s *service = NULL;
1086 if (asp_seeks == NULL) {
1087 __ASP_LOG_FUNC_END__;
1091 ASP_LOGD("service [%p]", handle);
1093 temp = g_list_first(asp_seeks);
1094 for (temp = g_list_first(asp_seeks); temp != NULL; temp = g_list_next(temp)) {
1095 service = temp->data;
1097 ASP_LOGD("temp [%p]", service);
1098 if (service != NULL && service == handle)
1102 __ASP_LOG_FUNC_END__;
1106 static asp_client_session_s *__get_session(void *handle)
1108 __ASP_LOG_FUNC_START__;
1109 asp_client_session_s *service = NULL;
1112 if (asp_sessions == NULL) {
1114 __ASP_LOG_FUNC_END__;
1118 ASP_LOGD("service [%p]", handle);
1120 temp = g_list_first(asp_sessions);
1121 for (temp = g_list_first(asp_sessions); temp != NULL; temp = g_list_next(temp)) {
1122 service = temp->data;
1124 ASP_LOGD("temp [%p]", service);
1125 if (service != NULL && service == handle)
1129 __ASP_LOG_FUNC_END__;
1133 static int __remove_advert(void *handle)
1135 __ASP_LOG_FUNC_START__;
1136 asp_client_advert_s *service = NULL;
1137 service = __get_advert(handle);
1139 if (service == NULL) {
1140 __ASP_LOG_FUNC_END__;
1141 return ASP_ERROR_OPERATION_FAILED;
1143 asp_adverts = g_list_remove(asp_adverts, handle);
1144 __free_advert(service);
1147 __ASP_LOG_FUNC_END__;
1148 return ASP_ERROR_NONE;
1151 static int __remove_seek(void *handle)
1153 __ASP_LOG_FUNC_START__;
1154 asp_client_seek_s *service = NULL;
1155 service = __get_seek(handle);
1157 if (service == NULL) {
1158 __ASP_LOG_FUNC_END__;
1159 return ASP_ERROR_OPERATION_FAILED;
1161 asp_seeks = g_list_remove(asp_seeks, handle);
1162 __free_seek(service);
1165 __ASP_LOG_FUNC_END__;
1166 return ASP_ERROR_NONE;
1169 static int __remove_session(void *handle)
1171 __ASP_LOG_FUNC_START__;
1172 asp_client_session_s *service = NULL;
1173 service = __get_session(handle);
1175 if (service == NULL) {
1176 __ASP_LOG_FUNC_END__;
1177 return ASP_ERROR_OPERATION_FAILED;
1179 asp_sessions = g_list_remove(asp_sessions, handle);
1180 __free_session(service);
1183 __ASP_LOG_FUNC_END__;
1184 return ASP_ERROR_NONE;
1188 int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service)
1190 __ASP_LOG_FUNC_START__;
1191 asp_client_advert_s *service = NULL;
1192 int res = ASP_ERROR_NONE;
1194 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1196 if (g_client_info.is_registered == false) {
1197 ASP_LOGE("Client is NOT registered");
1198 __ASP_LOG_FUNC_END__;
1199 return ASP_ERROR_NOT_INITIALIZED;
1203 ASP_LOGE("NULL Param [handle]!");
1204 __ASP_LOG_FUNC_END__;
1205 return ASP_ERROR_INVALID_PARAMETER;
1208 service = (asp_client_advert_s *)g_try_malloc0(sizeof(asp_client_advert_s));
1210 ASP_LOGE("malloc() failed!!!.");
1211 __ASP_LOG_FUNC_END__;
1212 return ASP_ERROR_OUT_OF_MEMORY;
1214 ASP_LOGD("service [%p]", service);
1216 if (instance_name) {
1217 ASP_LOGD("instance_name = [%s]", instance_name);
1218 service->instance_name = g_strdup(instance_name);
1219 if (!service->instance_name) {
1220 ASP_LOGE("malloc() failed!!!.");
1221 __ASP_LOG_FUNC_END__;
1223 return ASP_ERROR_OUT_OF_MEMORY;
1226 asp_adverts = g_list_prepend(asp_adverts, service);
1228 /* TODO : consider the case if target arch is 64bit. */
1229 /* TODO : Make asp enable support for other methods. */
1231 service->auto_accept = 0;
1232 service->config_method = 1;
1233 service->status = 0;
1235 service->service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
1236 service->adv_id = (unsigned int)service & 0xffffffff;
1237 *adv_service = (asp_advert_service_h)service;
1238 ASP_LOGD("asp_advert_create() SUCCESS");
1240 ASP_LOGD("advert handler [%p]", *adv_service);
1241 __ASP_LOG_FUNC_END__;
1245 int asp_advert_destroy(asp_advert_service_h adv_service)
1247 __ASP_LOG_FUNC_START__;
1248 asp_client_advert_s *service = NULL;
1249 int res = ASP_ERROR_NONE;
1251 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1253 if (g_client_info.is_registered == false) {
1254 ASP_LOGE("Client is NOT registered");
1255 __ASP_LOG_FUNC_END__;
1256 return ASP_ERROR_NOT_INITIALIZED;
1260 ASP_LOGE("NULL handler!");
1261 __ASP_LOG_FUNC_END__;
1262 return ASP_ERROR_INVALID_PARAMETER;
1264 ASP_LOGD("service [%p]", adv_service);
1266 service = __get_advert((void *)adv_service);
1267 if (service == NULL) {
1268 ASP_LOGE("Service NOT registered");
1269 __ASP_LOG_FUNC_END__;
1270 return ASP_ERROR_SERVICE_NOT_FOUND;
1273 g_hash_table_remove_all(service->service_info_map);
1274 res = __remove_advert((void *)service);
1275 if (res != ASP_ERROR_NONE) {
1276 __ASP_LOG_FUNC_END__;
1280 ASP_LOGD("asp_destory_advertise_handle() SUCCESS");
1282 __ASP_LOG_FUNC_END__;
1283 return ASP_ERROR_NONE;
1287 int asp_advert_set_service_type(asp_advert_service_h adv_service,
1290 __ASP_LOG_FUNC_START__;
1291 asp_client_advert_s *service = NULL;
1294 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1296 if (g_client_info.is_registered == false) {
1297 ASP_LOGE("Client is NOT registered");
1298 __ASP_LOG_FUNC_END__;
1299 return ASP_ERROR_NOT_INITIALIZED;
1302 if (!adv_service || !service_type) {
1303 ASP_LOGE("NULL handler!");
1304 __ASP_LOG_FUNC_END__;
1305 return ASP_ERROR_INVALID_PARAMETER;
1307 ASP_LOGD("service [%p]", adv_service);
1309 service = __get_advert((void *)adv_service);
1310 if (service == NULL) {
1311 ASP_LOGE("Service NOT registered");
1312 __ASP_LOG_FUNC_END__;
1313 return ASP_ERROR_SERVICE_NOT_FOUND;
1315 type = g_strdup(service_type);
1317 ASP_LOGE("malloc() failed!!!.");
1318 __ASP_LOG_FUNC_END__;
1319 return ASP_ERROR_OPERATION_FAILED;
1321 g_free(service->service_type);
1322 service->service_type = type;
1324 ASP_LOGD("asp_advert_set_service_type() SUCCESS");
1326 __ASP_LOG_FUNC_END__;
1327 return ASP_ERROR_NONE;
1330 int asp_advert_set_auto_accept(asp_advert_service_h adv_service,
1333 __ASP_LOG_FUNC_START__;
1334 asp_client_advert_s *service = NULL;
1336 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1338 if (g_client_info.is_registered == false) {
1339 ASP_LOGE("Client is NOT registered");
1340 __ASP_LOG_FUNC_END__;
1341 return ASP_ERROR_NOT_INITIALIZED;
1345 ASP_LOGE("NULL handler!");
1346 __ASP_LOG_FUNC_END__;
1347 return ASP_ERROR_INVALID_PARAMETER;
1349 ASP_LOGD("service [%p]", adv_service);
1351 service = __get_advert((void *)adv_service);
1352 if (service == NULL) {
1353 ASP_LOGE("Service NOT registered");
1354 __ASP_LOG_FUNC_END__;
1355 return ASP_ERROR_SERVICE_NOT_FOUND;
1357 service->auto_accept = auto_accept;
1359 ASP_LOGD("asp_advert_set_auto_accept() SUCCESS");
1361 __ASP_LOG_FUNC_END__;
1362 return ASP_ERROR_NONE;
1365 int asp_advert_add_info(asp_advert_service_h adv_service,
1366 const char *key, const char *value)
1368 __ASP_LOG_FUNC_START__;
1369 asp_client_advert_s *service = NULL;
1371 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1373 if (g_client_info.is_registered == false) {
1374 ASP_LOGE("Client is NOT registered");
1375 __ASP_LOG_FUNC_END__;
1376 return ASP_ERROR_NOT_INITIALIZED;
1379 if (!adv_service || !key) {
1380 ASP_LOGE("NULL value!");
1381 __ASP_LOG_FUNC_END__;
1382 return ASP_ERROR_INVALID_PARAMETER;
1384 ASP_LOGD("service [%p]", adv_service);
1386 service = __get_advert((void *)adv_service);
1387 if (service == NULL) {
1388 ASP_LOGE("Service NOT registered");
1389 __ASP_LOG_FUNC_END__;
1390 return ASP_ERROR_SERVICE_NOT_FOUND;
1392 /* TODO: add advertised info */
1393 g_hash_table_replace(service->service_info_map, g_strdup(key), g_strdup(value));
1395 ASP_LOGD("asp_advert_add_info() SUCCESS");
1397 __ASP_LOG_FUNC_END__;
1398 return ASP_ERROR_NONE;
1401 int asp_advert_get_info(asp_advert_service_h adv_service, const char *key,
1402 int *length, char **value)
1404 __ASP_LOG_FUNC_START__;
1405 asp_client_advert_s *service = NULL;
1406 char *ret_val = NULL;
1408 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1410 if (g_client_info.is_registered == false) {
1411 ASP_LOGE("Client is NOT registered");
1412 __ASP_LOG_FUNC_END__;
1413 return ASP_ERROR_NOT_INITIALIZED;
1416 if (!adv_service || !key) {
1417 ASP_LOGE("NULL value!");
1418 __ASP_LOG_FUNC_END__;
1419 return ASP_ERROR_INVALID_PARAMETER;
1421 ASP_LOGD("service [%p]", adv_service);
1423 service = __get_advert((void *)adv_service);
1424 if (service == NULL) {
1425 ASP_LOGE("Service NOT registered");
1426 __ASP_LOG_FUNC_END__;
1427 return ASP_ERROR_SERVICE_NOT_FOUND;
1429 /* TODO: get advertised info */
1430 ret_val = g_hash_table_lookup(service->service_info_map, key);
1431 if (ret_val == NULL) {
1432 ASP_LOGD("value is NULL");
1433 __ASP_LOG_FUNC_END__;
1434 return ASP_ERROR_NONE;
1437 *value = g_strdup(ret_val);
1438 *length = strlen(ret_val);
1440 ASP_LOGD("asp_advert_get_info() SUCCESS");
1442 __ASP_LOG_FUNC_END__;
1443 return ASP_ERROR_NONE;
1446 int asp_advert_remove_info(asp_advert_service_h adv_service, const char *key)
1448 __ASP_LOG_FUNC_START__;
1449 asp_client_advert_s *service = NULL;
1451 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1453 if (g_client_info.is_registered == false) {
1454 ASP_LOGE("Client is NOT registered");
1455 __ASP_LOG_FUNC_END__;
1456 return ASP_ERROR_NOT_INITIALIZED;
1459 if (!adv_service || !key) {
1460 ASP_LOGE("NULL value!");
1461 __ASP_LOG_FUNC_END__;
1462 return ASP_ERROR_INVALID_PARAMETER;
1464 ASP_LOGD("service [%p]", adv_service);
1466 service = __get_advert((void *)adv_service);
1467 if (service == NULL) {
1468 ASP_LOGE("Service NOT registered");
1469 __ASP_LOG_FUNC_END__;
1470 return ASP_ERROR_SERVICE_NOT_FOUND;
1472 /* TODO: remove advertised info */
1473 g_hash_table_remove(service->service_info_map, key);
1475 ASP_LOGD("asp_advert_remove_info() SUCCESS");
1477 __ASP_LOG_FUNC_END__;
1478 return ASP_ERROR_NONE;
1481 int asp_advert_set_status(asp_advert_service_h adv_service,
1482 unsigned char status)
1484 __ASP_LOG_FUNC_START__;
1485 asp_client_advert_s *service = NULL;
1487 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1489 if (g_client_info.is_registered == false) {
1490 ASP_LOGE("Client is NOT registered");
1491 __ASP_LOG_FUNC_END__;
1492 return ASP_ERROR_NOT_INITIALIZED;
1496 ASP_LOGE("NULL handler!");
1497 __ASP_LOG_FUNC_END__;
1498 return ASP_ERROR_INVALID_PARAMETER;
1500 ASP_LOGD("service [%p]", adv_service);
1502 service = __get_advert((void *)adv_service);
1503 if (service == NULL) {
1504 ASP_LOGE("Service NOT registered");
1505 __ASP_LOG_FUNC_END__;
1506 return ASP_ERROR_SERVICE_NOT_FOUND;
1508 service->status = status;
1510 ASP_LOGD("asp_advert_set_status() SUCCESS");
1512 __ASP_LOG_FUNC_END__;
1513 return ASP_ERROR_NONE;
1516 int asp_advert_set_discovery_tech(asp_advert_service_h adv_service, int discovery_tech)
1518 __ASP_LOG_FUNC_START__;
1519 asp_client_advert_s *service = NULL;
1521 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1523 if (g_client_info.is_registered == false) {
1524 ASP_LOGE("Client is NOT registered");
1525 __ASP_LOG_FUNC_END__;
1526 return ASP_ERROR_NOT_INITIALIZED;
1528 if (!((discovery_tech & ASP_DISCOVERY_TECH_P2P) |
1529 (discovery_tech & ASP_DISCOVERY_TECH_NFC) |
1530 (discovery_tech & ASP_DISCOVERY_TECH_BLE) |
1531 (discovery_tech & ASP_DISCOVERY_TECH_INFRA) |
1532 (discovery_tech & ASP_DISCOVERY_TECH_NAN))) {
1533 ASP_LOGE("invalid parameter!");
1534 __ASP_LOG_FUNC_END__;
1535 return ASP_ERROR_INVALID_PARAMETER;
1539 ASP_LOGE("NULL handler!");
1540 __ASP_LOG_FUNC_END__;
1541 return ASP_ERROR_INVALID_PARAMETER;
1543 ASP_LOGD("service [%p]", adv_service);
1545 service = __get_advert((void *)adv_service);
1546 if (service == NULL) {
1547 ASP_LOGE("Service NOT registered");
1548 __ASP_LOG_FUNC_END__;
1549 return ASP_ERROR_SERVICE_NOT_FOUND;
1551 service->discovery_tech = discovery_tech;
1553 ASP_LOGD("asp_advert_set_discovery_tech() SUCCESS");
1555 __ASP_LOG_FUNC_END__;
1556 return ASP_ERROR_NONE;
1559 int asp_advert_set_preferred_connection(asp_advert_service_h adv_service,
1560 unsigned char preferred_connection)
1562 __ASP_LOG_FUNC_START__;
1563 asp_client_advert_s *service = NULL;
1565 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1567 if (g_client_info.is_registered == false) {
1568 ASP_LOGE("Client is NOT registered");
1569 __ASP_LOG_FUNC_END__;
1570 return ASP_ERROR_NOT_INITIALIZED;
1574 ASP_LOGE("NULL handler!");
1575 __ASP_LOG_FUNC_END__;
1576 return ASP_ERROR_INVALID_PARAMETER;
1578 ASP_LOGD("service [%p]", adv_service);
1580 service = __get_advert((void *)adv_service);
1581 if (service == NULL) {
1582 ASP_LOGE("Service NOT registered");
1583 __ASP_LOG_FUNC_END__;
1584 return ASP_ERROR_SERVICE_NOT_FOUND;
1586 service->preferred_connection = preferred_connection;
1588 ASP_LOGD("asp_advert_set_preferred_connection() SUCCESS");
1590 __ASP_LOG_FUNC_END__;
1591 return ASP_ERROR_NONE;
1594 int asp_advert_set_p2p_role_scheme(asp_advert_service_h adv_service,
1595 asp_advert_p2p_role_scheme_e role)
1597 __ASP_LOG_FUNC_START__;
1598 asp_client_advert_s *service = NULL;
1600 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1602 if (g_client_info.is_registered == false) {
1603 ASP_LOGE("Client is NOT registered");
1604 __ASP_LOG_FUNC_END__;
1605 return ASP_ERROR_NOT_INITIALIZED;
1609 ASP_LOGE("NULL handler!");
1610 __ASP_LOG_FUNC_END__;
1611 return ASP_ERROR_INVALID_PARAMETER;
1613 ASP_LOGD("service [%p]", adv_service);
1615 service = __get_advert((void *)adv_service);
1616 if (service == NULL) {
1617 ASP_LOGE("Service NOT registered");
1618 __ASP_LOG_FUNC_END__;
1619 return ASP_ERROR_SERVICE_NOT_FOUND;
1621 service->role = role;
1623 ASP_LOGD("asp_advert_set_p2p_role_scheme() SUCCESS");
1625 __ASP_LOG_FUNC_END__;
1626 return ASP_ERROR_NONE;
1629 int asp_advert_get_p2p_role_scheme(asp_advert_service_h adv_service,
1630 asp_advert_p2p_role_scheme_e *role)
1632 __ASP_LOG_FUNC_START__;
1633 asp_client_advert_s *service = NULL;
1635 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1637 if (g_client_info.is_registered == false) {
1638 ASP_LOGE("Client is NOT registered");
1639 __ASP_LOG_FUNC_END__;
1640 return ASP_ERROR_NOT_INITIALIZED;
1643 if (!adv_service || !role) {
1644 ASP_LOGE("NULL handler!");
1645 __ASP_LOG_FUNC_END__;
1646 return ASP_ERROR_INVALID_PARAMETER;
1648 ASP_LOGD("service [%p]", adv_service);
1650 service = __get_advert((void *)adv_service);
1651 if (service == NULL) {
1652 ASP_LOGE("Service NOT registered");
1653 __ASP_LOG_FUNC_END__;
1654 return ASP_ERROR_SERVICE_NOT_FOUND;
1656 *role = service->role;
1658 ASP_LOGD("asp_advert_get_p2p_role_scheme() SUCCESS");
1660 __ASP_LOG_FUNC_END__;
1661 return ASP_ERROR_NONE;
1665 int asp_advert_set_p2p_config_method(asp_advert_service_h adv_service,
1666 asp_wps_type_e config_method)
1668 __ASP_LOG_FUNC_START__;
1669 asp_client_advert_s *service = NULL;
1671 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1673 if (g_client_info.is_registered == false) {
1674 ASP_LOGE("Client is NOT registered");
1675 __ASP_LOG_FUNC_END__;
1676 return ASP_ERROR_NOT_INITIALIZED;
1680 ASP_LOGE("NULL handler!");
1681 __ASP_LOG_FUNC_END__;
1682 return ASP_ERROR_INVALID_PARAMETER;
1685 if (config_method > ASP_WPS_TYPE_PIN_KEYPAD) {
1686 ASP_LOGE("config_method is larger than expected");
1687 __ASP_LOG_FUNC_END__;
1688 return ASP_ERROR_INVALID_PARAMETER;
1690 ASP_LOGD("service [%p]", adv_service);
1692 service = __get_advert((void *)adv_service);
1693 if (service == NULL) {
1694 ASP_LOGE("Service NOT registered");
1695 __ASP_LOG_FUNC_END__;
1696 return ASP_ERROR_SERVICE_NOT_FOUND;
1698 service->config_method = config_method;
1700 ASP_LOGD("asp_advert_set_p2p_config_method() SUCCESS");
1702 __ASP_LOG_FUNC_END__;
1703 return ASP_ERROR_NONE;
1706 int asp_advert_get_p2p_config_method(asp_advert_service_h adv_service,
1707 asp_wps_type_e *config_method)
1709 __ASP_LOG_FUNC_START__;
1710 asp_client_advert_s *service = NULL;
1712 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1714 if (g_client_info.is_registered == false) {
1715 ASP_LOGE("Client is NOT registered");
1716 __ASP_LOG_FUNC_END__;
1717 return ASP_ERROR_NOT_INITIALIZED;
1720 if (!adv_service || !config_method) {
1721 ASP_LOGE("NULL handler!");
1722 __ASP_LOG_FUNC_END__;
1723 return ASP_ERROR_INVALID_PARAMETER;
1726 ASP_LOGD("service [%p]", adv_service);
1728 service = __get_advert((void *)adv_service);
1729 if (service == NULL) {
1730 ASP_LOGE("Service NOT registered");
1731 __ASP_LOG_FUNC_END__;
1732 return ASP_ERROR_SERVICE_NOT_FOUND;
1735 *config_method = service->config_method;
1737 ASP_LOGD("asp_advert_get_p2p_config_method() SUCCESS");
1739 __ASP_LOG_FUNC_END__;
1740 return ASP_ERROR_NONE;
1743 int asp_advert_set_p2p_response(asp_advert_service_h adv_service,
1744 char *rsp_info, int length)
1746 __ASP_LOG_FUNC_START__;
1747 asp_client_advert_s *service = NULL;
1750 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1752 if (g_client_info.is_registered == false) {
1753 ASP_LOGE("Client is NOT registered");
1754 __ASP_LOG_FUNC_END__;
1755 return ASP_ERROR_NOT_INITIALIZED;
1757 /* TODO fit the rsp info for length */
1758 if (length <= 0 || length > 144) {
1759 ASP_LOGE("invalid length!");
1760 __ASP_LOG_FUNC_END__;
1761 return ASP_ERROR_INVALID_PARAMETER;
1764 if (!adv_service || !rsp_info) {
1765 ASP_LOGE("NULL handler!");
1766 __ASP_LOG_FUNC_END__;
1767 return ASP_ERROR_INVALID_PARAMETER;
1769 ASP_LOGD("service [%p]", adv_service);
1771 service = __get_advert((void *)adv_service);
1772 if (service == NULL) {
1773 ASP_LOGE("Service NOT registered");
1774 __ASP_LOG_FUNC_END__;
1775 return ASP_ERROR_SERVICE_NOT_FOUND;
1778 info = g_strdup(rsp_info);
1780 ASP_LOGE("malloc() failed!!!.");
1781 __ASP_LOG_FUNC_END__;
1782 return ASP_ERROR_OPERATION_FAILED;
1784 g_free(service->rsp_info);
1785 service->rsp_info = info;
1787 ASP_LOGD("asp_advert_set_p2p_response() SUCCESS");
1789 __ASP_LOG_FUNC_END__;
1790 return ASP_ERROR_NONE;
1794 static GVariant* __g_hash_keys_to_g_variant(GHashTable *hash)
1796 GVariantBuilder builder;
1798 __ASP_LOG_FUNC_START__;
1799 g_variant_builder_init(&builder, G_VARIANT_TYPE("as"));
1800 /* g_variant_builder_open(&builder, G_VARIANT_TYPE("a{sv}")); */
1802 GHashTableIter iter;
1803 gpointer key, value;
1805 g_hash_table_iter_init(&iter, hash);
1806 while (g_hash_table_iter_next(&iter, &key, &value)) {
1808 ASP_LOGE("key [%s]", key);
1809 g_variant_builder_add(&builder, "s", key);
1812 /* g_variant_builder_close(&builder); */
1813 __ASP_LOG_FUNC_END__;
1814 return g_variant_builder_end(&builder);
1817 static GVariant* __g_hash_table_to_g_variant(GHashTable *hash)
1819 GVariantBuilder builder;
1821 __ASP_LOG_FUNC_START__;
1822 g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
1824 GHashTableIter iter;
1825 gpointer key, value;
1827 g_hash_table_iter_init(&iter, hash);
1828 while (g_hash_table_iter_next(&iter, &key, &value))
1829 g_variant_builder_add(&builder, "{sv}", key, g_variant_new_string(value));
1831 __ASP_LOG_FUNC_END__;
1832 return g_variant_builder_end(&builder);
1835 int asp_advert_start_advertising(asp_advert_service_h adv_service)
1837 __ASP_LOG_FUNC_START__;
1838 asp_client_advert_s *service = NULL;
1839 GVariantBuilder *builder = NULL;
1840 GVariant *params = NULL;
1841 GError *error = NULL;
1842 GVariant *reply = NULL;
1843 int ret = ASP_ERROR_NONE;
1845 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1847 if (g_client_info.is_registered == false) {
1848 ASP_LOGE("Client is NOT registered");
1849 __ASP_LOG_FUNC_END__;
1850 return ASP_ERROR_NOT_INITIALIZED;
1854 ASP_LOGE("NULL handler!");
1855 __ASP_LOG_FUNC_END__;
1856 return ASP_ERROR_INVALID_PARAMETER;
1858 ASP_LOGD("service [%p]", adv_service);
1860 service = __get_advert((void *)adv_service);
1861 if (service == NULL) {
1862 ASP_LOGE("Service NOT registered");
1863 __ASP_LOG_FUNC_END__;
1864 return ASP_ERROR_SERVICE_NOT_FOUND;
1867 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1868 g_variant_builder_add(builder, "{sv}", "adv_id", g_variant_new("u", service->adv_id));
1869 g_variant_builder_add(builder, "{sv}", "discovery_tech", g_variant_new("i", service->discovery_tech));
1870 g_variant_builder_add(builder, "{sv}", "preferred_connection", g_variant_new("y", service->preferred_connection));
1871 g_variant_builder_add(builder, "{sv}", "auto_accept", g_variant_new("i", service->auto_accept));
1872 g_variant_builder_add(builder, "{sv}", "status", g_variant_new("y", service->status));
1873 g_variant_builder_add(builder, "{sv}", "role", g_variant_new("y", service->role));
1874 g_variant_builder_add(builder, "{sv}", "config_method", g_variant_new("u", service->config_method));
1876 if (service->instance_name) /* This can be NULL if this is ASP 1.0 service */
1877 g_variant_builder_add(builder, "{sv}", "instance_name", g_variant_new("s", service->instance_name));
1878 if (service->service_type) /* This can be NULL if Instance name is UUID */
1879 g_variant_builder_add(builder, "{sv}", "service_type", g_variant_new("s", service->service_type));
1880 if (g_hash_table_size(service->service_info_map) > 0)
1881 g_variant_builder_add(builder, "{sv}", "service_info", __g_hash_table_to_g_variant(service->service_info_map));
1882 if (service->rsp_info)
1883 g_variant_builder_add(builder, "{sv}", "rsp_info", g_variant_new("s", service->rsp_info));
1884 params = g_variant_new("(a{sv})", builder);
1885 g_variant_builder_unref(builder);
1886 ASP_LOGI("service type (%s) adv ID (%u)", service->service_type, service->adv_id);
1888 reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE,
1889 "AdvertiseService", params, &error);
1890 if (error != NULL) {
1891 ASP_LOGE("asp_dbus_method_call_sync() failed."
1892 "error [%d: %s]", error->code, error->message);
1893 ret = __asp_err_string_to_enum(error->message);
1894 g_error_free(error);
1895 __ASP_LOG_FUNC_END__;
1899 g_variant_get(reply, "(i)", &ret);
1900 g_variant_unref(reply);
1902 ASP_LOGD("%s() return : [%d]", __func__, ret);
1904 __ASP_LOG_FUNC_END__;
1908 int asp_advert_stop_advertising(asp_advert_service_h adv_service)
1910 __ASP_LOG_FUNC_START__;
1911 asp_client_advert_s *service = NULL;
1912 GVariant *params = NULL;
1913 GError *error = NULL;
1914 GVariant *reply = NULL;
1915 int ret = ASP_ERROR_NONE;
1917 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1919 if (g_client_info.is_registered == false) {
1920 ASP_LOGE("Client is NOT registered");
1921 __ASP_LOG_FUNC_END__;
1922 return ASP_ERROR_NOT_INITIALIZED;
1926 ASP_LOGE("NULL handler!");
1927 __ASP_LOG_FUNC_END__;
1928 return ASP_ERROR_INVALID_PARAMETER;
1930 ASP_LOGD("service [%p]", adv_service);
1932 service = __get_advert((void *)adv_service);
1933 if (service == NULL) {
1934 ASP_LOGE("Service NOT registered");
1935 __ASP_LOG_FUNC_END__;
1936 return ASP_ERROR_SERVICE_NOT_FOUND;
1939 params = g_variant_new("(ui)", service->adv_id, service->discovery_tech);
1940 reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE,
1941 "CancelAdvertiseService", params, &error);
1942 if (error != NULL) {
1943 ASP_LOGE("asp_dbus_method_call_sync() failed."
1944 "error [%d: %s]", error->code, error->message);
1945 ret = __asp_err_string_to_enum(error->message);
1946 g_error_free(error);
1947 __ASP_LOG_FUNC_END__;
1951 g_variant_get(reply, "(i)", &ret);
1952 g_variant_unref(reply);
1954 ASP_LOGD("%s() return : [%d]", __func__, ret);
1956 __ASP_LOG_FUNC_END__;
1960 int asp_advert_change_service_status(asp_advert_service_h adv_service,
1961 unsigned char status)
1963 __ASP_LOG_FUNC_START__;
1964 asp_client_advert_s *service = NULL;
1965 GVariantBuilder *builder = NULL;
1966 GVariant *params = NULL;
1967 GError *error = NULL;
1968 GVariant *reply = NULL;
1969 int ret = ASP_ERROR_NONE;
1971 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
1973 if (g_client_info.is_registered == false) {
1974 ASP_LOGE("Client is NOT registered");
1975 __ASP_LOG_FUNC_END__;
1976 return ASP_ERROR_NOT_INITIALIZED;
1980 ASP_LOGE("NULL handler!");
1981 __ASP_LOG_FUNC_END__;
1982 return ASP_ERROR_INVALID_PARAMETER;
1984 ASP_LOGD("service [%p]", adv_service);
1986 service = __get_advert((void *)adv_service);
1987 if (service == NULL) {
1988 ASP_LOGE("Service NOT registered");
1989 __ASP_LOG_FUNC_END__;
1990 return ASP_ERROR_SERVICE_NOT_FOUND;
1993 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
1994 g_variant_builder_add(builder, "{sv}", "adv_id", g_variant_new("u", service->adv_id));
1995 g_variant_builder_add(builder, "{sv}", "auto_accept", g_variant_new("i", service->auto_accept));
1996 service->status = status;
1997 g_variant_builder_add(builder, "{sv}", "status", g_variant_new("y", service->status));
1998 g_variant_builder_add(builder, "{sv}", "role", g_variant_new("y", service->role));
1999 g_variant_builder_add(builder, "{sv}", "config_method", g_variant_new("u", service->config_method));
2001 if (service->instance_name) /* This can be NULL if this is ASP 1.0 service */
2002 g_variant_builder_add(builder, "{sv}", "instance_name", g_variant_new("s", service->instance_name));
2003 if (service->service_type) /* This can be NULL if Instance name is UUID */
2004 g_variant_builder_add(builder, "{sv}", "service_type", g_variant_new("s", service->service_type));
2005 if (g_hash_table_size(service->service_info_map) > 0)
2006 g_variant_builder_add(builder, "{sv}", "service_info", __g_hash_keys_to_g_variant(service->service_info_map));
2007 if (service->rsp_info)
2008 g_variant_builder_add(builder, "{sv}", "rsp_info", g_variant_new("s", service->rsp_info));
2010 params = g_variant_new("(a{sv})", builder);
2011 g_variant_builder_unref(builder);
2012 ASP_LOGI("service type (%s) adv ID (%u)", service->service_type, service->adv_id);
2014 reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE,
2015 "ServiceChangeStatus", params, &error);
2016 if (error != NULL) {
2017 ASP_LOGE("asp_dbus_method_call_sync() failed."
2018 "error [%d: %s]", error->code, error->message);
2019 ret = __asp_err_string_to_enum(error->message);
2020 g_error_free(error);
2021 __ASP_LOG_FUNC_END__;
2025 g_variant_get(reply, "(i)", &ret);
2026 g_variant_unref(reply);
2028 ASP_LOGD("%s() return : [%d]", __func__, ret);
2030 __ASP_LOG_FUNC_END__;
2034 int asp_seek_create(char *service_type, asp_seek_service_h *seek_service)
2036 __ASP_LOG_FUNC_START__;
2037 asp_client_seek_s *service = NULL;
2038 int res = ASP_ERROR_NONE;
2040 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2042 if (g_client_info.is_registered == false) {
2043 ASP_LOGE("Client is NOT registered");
2044 __ASP_LOG_FUNC_END__;
2045 return ASP_ERROR_NOT_INITIALIZED;
2048 if (!service_type || strlen(service_type) == 0) {
2049 ASP_LOGE("NULL Param [service_type]!");
2050 __ASP_LOG_FUNC_END__;
2051 return ASP_ERROR_INVALID_PARAMETER;
2053 ASP_LOGD("service_type = [%s]", service_type);
2055 if (!seek_service) {
2056 ASP_LOGE("NULL Param [handle]!");
2057 __ASP_LOG_FUNC_END__;
2058 return ASP_ERROR_INVALID_PARAMETER;
2061 service = (asp_client_seek_s *)g_try_malloc0(sizeof(asp_client_seek_s));
2063 ASP_LOGE("malloc() failed!!!.");
2064 __ASP_LOG_FUNC_END__;
2065 return ASP_ERROR_OUT_OF_MEMORY;
2067 ASP_LOGD("service [%p]", service);
2069 service->service_type = g_strdup(service_type);
2070 if (!service->service_type) {
2071 ASP_LOGE("malloc() failed!!!.");
2073 __ASP_LOG_FUNC_END__;
2074 return ASP_ERROR_OUT_OF_MEMORY;
2077 service->service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
2078 asp_seeks = g_list_prepend(asp_seeks, service);
2080 *seek_service = (asp_seek_service_h)service;
2081 ASP_LOGD("asp_create_seek_handle() SUCCESS");
2083 ASP_LOGD("seek handler [%p]", *seek_service);
2084 __ASP_LOG_FUNC_END__;
2088 int asp_seek_destroy(asp_seek_service_h seek_service)
2090 __ASP_LOG_FUNC_START__;
2091 asp_client_seek_s *service = NULL;
2092 int res = ASP_ERROR_NONE;
2094 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2096 if (g_client_info.is_registered == false) {
2097 ASP_LOGE("Client is NOT registered");
2098 __ASP_LOG_FUNC_END__;
2099 return ASP_ERROR_NOT_INITIALIZED;
2102 if (!seek_service) {
2103 ASP_LOGE("NULL handler!");
2104 __ASP_LOG_FUNC_END__;
2105 return ASP_ERROR_INVALID_PARAMETER;
2107 ASP_LOGD("service [%p]", seek_service);
2109 service = __get_seek((void *)seek_service);
2110 if (service == NULL) {
2111 ASP_LOGE("Service NOT registered");
2112 __ASP_LOG_FUNC_END__;
2113 return ASP_ERROR_SERVICE_NOT_FOUND;
2116 g_hash_table_remove_all(service->service_info_map);
2117 res = __remove_seek((void *)service);
2118 if (res != ASP_ERROR_NONE) {
2119 __ASP_LOG_FUNC_END__;
2123 ASP_LOGD("asp_seek_destroy() SUCCESS");
2125 __ASP_LOG_FUNC_END__;
2126 return ASP_ERROR_NONE;
2129 int asp_seek_add_info(asp_seek_service_h seek_service, const char *key)
2131 __ASP_LOG_FUNC_START__;
2132 asp_client_seek_s *service = NULL;
2133 int res = ASP_ERROR_NONE;
2135 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2137 if (g_client_info.is_registered == false) {
2138 ASP_LOGE("Client is NOT registered");
2139 __ASP_LOG_FUNC_END__;
2140 return ASP_ERROR_NOT_INITIALIZED;
2143 if (!seek_service) {
2144 ASP_LOGE("NULL handler!");
2145 __ASP_LOG_FUNC_END__;
2146 return ASP_ERROR_INVALID_PARAMETER;
2148 ASP_LOGD("service [%p]", seek_service);
2150 service = __get_seek((void *)seek_service);
2151 if (service == NULL) {
2152 ASP_LOGE("Service NOT registered");
2153 __ASP_LOG_FUNC_END__;
2154 return ASP_ERROR_SERVICE_NOT_FOUND;
2157 g_hash_table_replace(service->service_info_map, g_strdup(key), NULL);
2159 ASP_LOGD("service info [%d]", g_hash_table_size(service->service_info_map));
2160 ASP_LOGD("asp_add_seek_info() SUCCESS");
2162 __ASP_LOG_FUNC_END__;
2167 int asp_seek_remove_info(asp_seek_service_h seek_service, const char *key)
2169 __ASP_LOG_FUNC_START__;
2170 asp_client_seek_s *service = NULL;
2171 int res = ASP_ERROR_NONE;
2173 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2175 if (g_client_info.is_registered == false) {
2176 ASP_LOGE("Client is NOT registered");
2177 __ASP_LOG_FUNC_END__;
2178 return ASP_ERROR_NOT_INITIALIZED;
2181 if (!seek_service) {
2182 ASP_LOGE("NULL handler!");
2183 __ASP_LOG_FUNC_END__;
2184 return ASP_ERROR_INVALID_PARAMETER;
2186 ASP_LOGD("service [%p]", seek_service);
2188 service = __get_seek((void *)seek_service);
2189 if (service == NULL) {
2190 ASP_LOGE("Service NOT registered");
2191 __ASP_LOG_FUNC_END__;
2192 return ASP_ERROR_SERVICE_NOT_FOUND;
2195 /* TODO: remove seek info */
2196 g_hash_table_remove(service->service_info_map, key);
2198 ASP_LOGD("asp_remove_seek_info() SUCCESS");
2200 __ASP_LOG_FUNC_END__;
2205 int asp_seek_set_discovery_tech(asp_seek_service_h seek_service, int discovery_tech)
2207 __ASP_LOG_FUNC_START__;
2208 asp_client_seek_s *service = NULL;
2210 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2212 if (g_client_info.is_registered == false) {
2213 ASP_LOGE("Client is NOT registered");
2214 __ASP_LOG_FUNC_END__;
2215 return ASP_ERROR_NOT_INITIALIZED;
2217 if (!((discovery_tech & ASP_DISCOVERY_TECH_P2P) |
2218 (discovery_tech & ASP_DISCOVERY_TECH_NFC) |
2219 (discovery_tech & ASP_DISCOVERY_TECH_BLE) |
2220 (discovery_tech & ASP_DISCOVERY_TECH_INFRA) |
2221 (discovery_tech & ASP_DISCOVERY_TECH_NAN))) {
2222 ASP_LOGE("invalid parameter!");
2223 __ASP_LOG_FUNC_END__;
2224 return ASP_ERROR_INVALID_PARAMETER;
2227 if (!seek_service) {
2228 ASP_LOGE("NULL handler!");
2229 __ASP_LOG_FUNC_END__;
2230 return ASP_ERROR_INVALID_PARAMETER;
2232 ASP_LOGD("service [%p]", seek_service);
2234 service = __get_seek((void *)seek_service);
2235 if (service == NULL) {
2236 ASP_LOGE("Service NOT registered");
2237 __ASP_LOG_FUNC_END__;
2238 return ASP_ERROR_SERVICE_NOT_FOUND;
2240 service->discovery_tech = discovery_tech;
2242 ASP_LOGD("asp_set_seeking_tech() SUCCESS");
2244 __ASP_LOG_FUNC_END__;
2245 return ASP_ERROR_NONE;
2248 int asp_seek_set_preferred_connection(asp_seek_service_h seek_service,
2249 unsigned char preferred_connection)
2251 __ASP_LOG_FUNC_START__;
2252 asp_client_seek_s *service = NULL;
2254 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2256 if (g_client_info.is_registered == false) {
2257 ASP_LOGE("Client is NOT registered");
2258 __ASP_LOG_FUNC_END__;
2259 return ASP_ERROR_NOT_INITIALIZED;
2262 if (!seek_service) {
2263 ASP_LOGE("NULL handler!");
2264 __ASP_LOG_FUNC_END__;
2265 return ASP_ERROR_INVALID_PARAMETER;
2267 ASP_LOGD("service [%p]", seek_service);
2269 service = __get_seek((void *)seek_service);
2270 if (service == NULL) {
2271 ASP_LOGE("Service NOT registered");
2272 __ASP_LOG_FUNC_END__;
2273 return ASP_ERROR_SERVICE_NOT_FOUND;
2275 service->preferred_connection = preferred_connection;
2277 ASP_LOGD("asp_set_seeking_preferred_connection() SUCCESS");
2279 __ASP_LOG_FUNC_END__;
2280 return ASP_ERROR_NONE;
2284 int asp_seek_start(asp_seek_service_h seek_service)
2286 __ASP_LOG_FUNC_START__;
2287 asp_client_seek_s *service = NULL;
2288 GVariantBuilder *builder = NULL;
2289 GVariant *params = NULL;
2290 GError *error = NULL;
2291 GVariant *reply = NULL;
2292 int ret = ASP_ERROR_NONE;
2294 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2296 if (g_client_info.is_registered == false) {
2297 ASP_LOGE("Client is NOT registered");
2298 __ASP_LOG_FUNC_END__;
2299 return ASP_ERROR_NOT_INITIALIZED;
2302 if (!seek_service) {
2303 ASP_LOGE("NULL handler!");
2304 __ASP_LOG_FUNC_END__;
2305 return ASP_ERROR_INVALID_PARAMETER;
2307 ASP_LOGD("service [%p]", seek_service);
2309 service = __get_seek((void *)seek_service);
2310 if (service == NULL) {
2311 ASP_LOGE("Service NOT registered");
2312 __ASP_LOG_FUNC_END__;
2313 return ASP_ERROR_SERVICE_NOT_FOUND;
2316 ASP_LOGD("service info [%d]", g_hash_table_size(service->service_info_map));
2317 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
2318 g_variant_builder_add(builder, "{sv}", "discovery_tech", g_variant_new("i", service->discovery_tech));
2319 g_variant_builder_add(builder, "{sv}", "preferred_connection", g_variant_new("y", service->preferred_connection));
2320 g_variant_builder_add(builder, "{sv}", "service_type", g_variant_new("s", service->service_type));
2321 if (g_hash_table_size(service->service_info_map) > 0) {
2322 ASP_LOGE("Service info");
2323 g_variant_builder_add(builder, "{sv}", "service_info", __g_hash_keys_to_g_variant(service->service_info_map));
2326 params = g_variant_new("(a{sv})", builder);
2327 g_variant_builder_unref(builder);
2328 ASP_LOGI("service name (%s)", service->serivce_name);
2330 reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE,
2331 "SeekService", params, &error);
2332 if (error != NULL) {
2333 ASP_LOGE("asp_dbus_method_call_sync() failed."
2334 "error [%d: %s]", error->code, error->message);
2335 ret = __asp_err_string_to_enum(error->message);
2336 g_error_free(error);
2337 __ASP_LOG_FUNC_END__;
2341 g_variant_get(reply, "(it)", &ret, &(service->search_id));
2342 g_variant_unref(reply);
2344 ASP_LOGD("%s() return : [%d]", __func__, ret);
2346 __ASP_LOG_FUNC_END__;
2350 int asp_seek_stop(asp_seek_service_h seek_service)
2352 __ASP_LOG_FUNC_START__;
2353 asp_client_seek_s *service = NULL;
2354 GVariant *params = NULL;
2355 GError *error = NULL;
2356 GVariant *reply = NULL;
2357 int ret = ASP_ERROR_NONE;
2359 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2361 if (g_client_info.is_registered == false) {
2362 ASP_LOGE("Client is NOT registered");
2363 __ASP_LOG_FUNC_END__;
2364 return ASP_ERROR_NOT_INITIALIZED;
2367 if (!seek_service) {
2368 ASP_LOGE("NULL handler!");
2369 __ASP_LOG_FUNC_END__;
2370 return ASP_ERROR_INVALID_PARAMETER;
2373 service = __get_seek((void *)seek_service);
2374 if (service == NULL) {
2375 ASP_LOGE("Service NOT registered");
2376 __ASP_LOG_FUNC_END__;
2377 return ASP_ERROR_OPERATION_FAILED;
2379 ASP_LOGD("service_type = [%s]", service->service_type);
2381 params = g_variant_new("(ti)", service->search_id, service->discovery_tech);
2382 reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE,
2383 "CancelSeekService", params, &error);
2384 if (error != NULL) {
2385 ASP_LOGE("asp_dbus_method_call_sync() failed."
2386 "error [%d: %s]", error->code, error->message);
2387 ret = __asp_err_string_to_enum(error->message);
2388 g_error_free(error);
2389 __ASP_LOG_FUNC_END__;
2393 g_variant_get(reply, "(i)", &ret);
2394 g_variant_unref(reply);
2396 ASP_LOGD("%s() return : [%d]", __func__, ret);
2398 __ASP_LOG_FUNC_END__;
2402 int asp_session_create(char *service_mac, unsigned int adv_id, asp_session_h* session)
2404 __ASP_LOG_FUNC_START__;
2405 asp_client_session_s *service = NULL;
2406 int res = ASP_ERROR_NONE;
2408 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2410 if (g_client_info.is_registered == false) {
2411 ASP_LOGE("Client is NOT registered");
2412 __ASP_LOG_FUNC_END__;
2413 return ASP_ERROR_NOT_INITIALIZED;
2416 if (!service_mac || strlen(service_mac) != (MACSTR_LEN -1)) {
2417 ASP_LOGE("Invalid Param [service_mac]!");
2418 __ASP_LOG_FUNC_END__;
2419 return ASP_ERROR_INVALID_PARAMETER;
2422 if (adv_id == 0 || !session) {
2423 ASP_LOGE("NULL Param [session]!");
2424 __ASP_LOG_FUNC_END__;
2425 return ASP_ERROR_INVALID_PARAMETER;
2428 service = (asp_client_session_s *)g_try_malloc0(sizeof(asp_client_session_s));
2430 ASP_LOGE("malloc() failed!!!.");
2431 __ASP_LOG_FUNC_END__;
2432 return ASP_ERROR_OUT_OF_MEMORY;
2434 ASP_LOGD("service [%p]", service);
2436 service->advertisement_id = adv_id;
2437 g_strlcpy(service->service_mac, service_mac, MACSTR_LEN);
2439 asp_sessions = g_list_prepend(asp_sessions, service);
2441 /* Session ID will be generated by asp-manager */
2442 *session = (asp_session_h)service;
2443 ASP_LOGD("asp_session_create() SUCCESS");
2445 ASP_LOGD("service [%p]", *session);
2446 __ASP_LOG_FUNC_END__;
2450 int asp_session_destroy(asp_session_h session)
2452 __ASP_LOG_FUNC_START__;
2453 asp_client_session_s *service = NULL;
2454 int res = ASP_ERROR_NONE;
2456 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2458 if (g_client_info.is_registered == false) {
2459 ASP_LOGE("Client is NOT registered");
2460 __ASP_LOG_FUNC_END__;
2461 return ASP_ERROR_NOT_INITIALIZED;
2465 ASP_LOGE("NULL handler!");
2466 __ASP_LOG_FUNC_END__;
2467 return ASP_ERROR_INVALID_PARAMETER;
2469 ASP_LOGD("service [%p]", session);
2471 service = __get_session((void *)session);
2472 if (service == NULL) {
2473 ASP_LOGE("Session NOT registered");
2474 __ASP_LOG_FUNC_END__;
2475 return ASP_ERROR_SESSION_NOT_FOUND;
2478 res = __remove_session((void *)service);
2479 if (res != ASP_ERROR_NONE) {
2480 __ASP_LOG_FUNC_END__;
2484 ASP_LOGD("asp_session_destroy() SUCCESS");
2486 __ASP_LOG_FUNC_END__;
2487 return ASP_ERROR_NONE;
2491 int asp_session_get_mac(asp_session_h session, char **session_mac)
2493 __ASP_LOG_FUNC_START__;
2494 asp_client_session_s *service = NULL;
2495 int res = ASP_ERROR_NONE;
2497 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2499 if (g_client_info.is_registered == false) {
2500 ASP_LOGE("Client is NOT registered");
2501 __ASP_LOG_FUNC_END__;
2502 return ASP_ERROR_NOT_INITIALIZED;
2505 if (!session || !session_mac) {
2506 ASP_LOGE("Invalid parameter!");
2507 __ASP_LOG_FUNC_END__;
2508 return ASP_ERROR_INVALID_PARAMETER;
2510 ASP_LOGD("service [%p]", session);
2512 service = __get_session((void *)session);
2513 if (service == NULL) {
2514 ASP_LOGE("Session NOT registered");
2515 __ASP_LOG_FUNC_END__;
2516 return ASP_ERROR_SESSION_NOT_FOUND;
2519 *session_mac = g_strndup(service->session_mac, MACSTR_LEN - 1);
2520 if (*session_mac == NULL) {
2521 ASP_LOGE("g_strndup failed");
2522 __ASP_LOG_FUNC_END__;
2523 return ASP_ERROR_OPERATION_FAILED;
2526 ASP_LOGD("asp_session_get_mac() SUCCESS");
2528 __ASP_LOG_FUNC_END__;
2533 int asp_session_get_id(asp_session_h session, unsigned int *session_id)
2535 __ASP_LOG_FUNC_START__;
2536 asp_client_session_s *service = NULL;
2537 int res = ASP_ERROR_NONE;
2539 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2541 if (g_client_info.is_registered == false) {
2542 ASP_LOGE("Client is NOT registered");
2543 __ASP_LOG_FUNC_END__;
2544 return ASP_ERROR_NOT_INITIALIZED;
2547 if (!session || !session_id) {
2548 ASP_LOGE("Invalid parameter!");
2549 __ASP_LOG_FUNC_END__;
2550 return ASP_ERROR_INVALID_PARAMETER;
2552 ASP_LOGD("service [%p]", session);
2554 service = __get_session((void *)session);
2555 if (service == NULL) {
2556 ASP_LOGE("Session NOT registered");
2557 __ASP_LOG_FUNC_END__;
2558 return ASP_ERROR_SESSION_NOT_FOUND;
2561 *session_id = service->session_id;
2563 ASP_LOGD("asp_session_get_id() SUCCESS");
2565 __ASP_LOG_FUNC_END__;
2569 int asp_session_set_info(asp_session_h session, char *service_info)
2571 __ASP_LOG_FUNC_START__;
2572 asp_client_session_s *service = NULL;
2573 int res = ASP_ERROR_NONE;
2576 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2578 if (g_client_info.is_registered == false) {
2579 ASP_LOGE("Client is NOT registered");
2580 __ASP_LOG_FUNC_END__;
2581 return ASP_ERROR_NOT_INITIALIZED;
2584 if (!service_info || !session) {
2585 ASP_LOGE("NULL Param!");
2586 __ASP_LOG_FUNC_END__;
2587 return ASP_ERROR_INVALID_PARAMETER;
2590 service = __get_session((void *)session);
2591 if (service == NULL) {
2592 ASP_LOGE("Session NOT registered");
2593 __ASP_LOG_FUNC_END__;
2594 return ASP_ERROR_SESSION_NOT_FOUND;
2597 info = g_strdup(service_info);
2599 ASP_LOGE("malloc() failed!!!.");
2600 __ASP_LOG_FUNC_END__;
2601 return ASP_ERROR_OPERATION_FAILED;
2603 g_free(service->session_information);
2604 service->session_information = info;
2606 ASP_LOGD("asp_session_set_info() SUCCESS");
2608 __ASP_LOG_FUNC_END__;
2612 int asp_session_get_info(asp_session_h session, char **service_info)
2614 __ASP_LOG_FUNC_START__;
2615 asp_client_session_s *service = NULL;
2616 int res = ASP_ERROR_NONE;
2618 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2620 if (g_client_info.is_registered == false) {
2621 ASP_LOGE("Client is NOT registered");
2622 __ASP_LOG_FUNC_END__;
2623 return ASP_ERROR_NOT_INITIALIZED;
2626 if (!session || !service_info) {
2627 ASP_LOGE("NULL Param!");
2628 __ASP_LOG_FUNC_END__;
2629 return ASP_ERROR_INVALID_PARAMETER;
2632 service = __get_session((void *)session);
2633 if (service == NULL) {
2634 ASP_LOGE("Session NOT registered");
2635 __ASP_LOG_FUNC_END__;
2636 return ASP_ERROR_SESSION_NOT_FOUND;
2639 if (service->session_information)
2640 *service_info = g_strdup(service->session_information);
2642 ASP_LOGD("asp_session_get_info() SUCCESS");
2644 __ASP_LOG_FUNC_END__;
2648 int asp_session_set_p2p_role_scheme(asp_session_h session,
2649 asp_advert_p2p_role_scheme_e role)
2651 __ASP_LOG_FUNC_START__;
2652 asp_client_session_s *service = NULL;
2653 int res = ASP_ERROR_NONE;
2655 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2657 if (g_client_info.is_registered == false) {
2658 ASP_LOGE("Client is NOT registered");
2659 __ASP_LOG_FUNC_END__;
2660 return ASP_ERROR_NOT_INITIALIZED;
2663 if (!role || !session) {
2664 ASP_LOGE("Invalid parameters");
2665 __ASP_LOG_FUNC_END__;
2666 return ASP_ERROR_INVALID_PARAMETER;
2669 service = __get_session((void *)session);
2670 if (service == NULL) {
2671 ASP_LOGE("Session NOT registered");
2672 __ASP_LOG_FUNC_END__;
2673 return ASP_ERROR_SESSION_NOT_FOUND;
2676 service->network_role = role;
2678 ASP_LOGD("asp_session_set_p2p_role_scheme() SUCCESS");
2680 __ASP_LOG_FUNC_END__;
2684 int asp_session_get_p2p_role_scheme(asp_session_h session,
2685 asp_advert_p2p_role_scheme_e *role)
2687 __ASP_LOG_FUNC_START__;
2688 asp_client_session_s *service = NULL;
2689 int res = ASP_ERROR_NONE;
2691 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2693 if (g_client_info.is_registered == false) {
2694 ASP_LOGE("Client is NOT registered");
2695 __ASP_LOG_FUNC_END__;
2696 return ASP_ERROR_NOT_INITIALIZED;
2699 if (!role || !session) {
2700 ASP_LOGE("Invalid parameters");
2701 __ASP_LOG_FUNC_END__;
2702 return ASP_ERROR_INVALID_PARAMETER;
2705 service = __get_session((void *)session);
2706 if (service == NULL) {
2707 ASP_LOGE("Session NOT registered");
2708 __ASP_LOG_FUNC_END__;
2709 return ASP_ERROR_SESSION_NOT_FOUND;
2712 *role = service->network_role;
2714 ASP_LOGD("asp_session_get_p2p_role_scheme() SUCCESS");
2716 __ASP_LOG_FUNC_END__;
2720 int asp_session_set_p2p_config_method(asp_session_h session,
2721 asp_wps_type_e config_method)
2723 __ASP_LOG_FUNC_START__;
2724 asp_client_session_s *service = NULL;
2725 int res = ASP_ERROR_NONE;
2727 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2729 if (g_client_info.is_registered == false) {
2730 ASP_LOGE("Client is NOT registered");
2731 __ASP_LOG_FUNC_END__;
2732 return ASP_ERROR_NOT_INITIALIZED;
2736 ASP_LOGE("Invalid parameter");
2737 __ASP_LOG_FUNC_END__;
2738 return ASP_ERROR_INVALID_PARAMETER;
2741 service = __get_session((void *)session);
2742 if (service == NULL) {
2743 ASP_LOGE("Session NOT registered");
2744 __ASP_LOG_FUNC_END__;
2745 return ASP_ERROR_SESSION_NOT_FOUND;
2748 if (config_method < ASP_WPS_TYPE_DEFAULT ||
2749 config_method > ASP_WPS_TYPE_PIN_KEYPAD) {
2750 ASP_LOGE("network_config is invalid");
2751 __ASP_LOG_FUNC_END__;
2752 return ASP_ERROR_INVALID_PARAMETER;
2755 service->network_config = config_method;
2757 ASP_LOGD("asp_session_set_p2p_config_method() SUCCESS");
2759 __ASP_LOG_FUNC_END__;
2763 int asp_session_get_p2p_config_method(asp_session_h session,
2764 asp_wps_type_e *config_method)
2766 __ASP_LOG_FUNC_START__;
2767 asp_client_session_s *service = NULL;
2768 int res = ASP_ERROR_NONE;
2770 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2772 if (g_client_info.is_registered == false) {
2773 ASP_LOGE("Client is NOT registered");
2774 __ASP_LOG_FUNC_END__;
2775 return ASP_ERROR_NOT_INITIALIZED;
2778 if (!config_method || !session) {
2779 ASP_LOGE("Invalid parameters");
2780 __ASP_LOG_FUNC_END__;
2781 return ASP_ERROR_INVALID_PARAMETER;
2784 service = __get_session((void *)session);
2785 if (service == NULL) {
2786 ASP_LOGE("Session NOT registered");
2787 __ASP_LOG_FUNC_END__;
2788 return ASP_ERROR_SESSION_NOT_FOUND;
2791 *config_method = service->network_config;
2793 ASP_LOGD("asp_session_get_p2p_config_method() SUCCESS");
2795 __ASP_LOG_FUNC_END__;
2799 int asp_session_get_close_status(asp_session_h session, int *status)
2801 __ASP_LOG_FUNC_START__;
2802 asp_client_session_s *service = NULL;
2803 int res = ASP_ERROR_NONE;
2805 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2807 if (g_client_info.is_registered == false) {
2808 ASP_LOGE("Client is NOT registered");
2809 __ASP_LOG_FUNC_END__;
2810 return ASP_ERROR_NOT_INITIALIZED;
2813 if (!status || !session) {
2814 ASP_LOGE("Invalid parameters");
2815 __ASP_LOG_FUNC_END__;
2816 return ASP_ERROR_INVALID_PARAMETER;
2819 service = __get_session((void *)session);
2820 if (service == NULL) {
2821 ASP_LOGE("Session NOT registered");
2822 __ASP_LOG_FUNC_END__;
2823 return ASP_ERROR_SESSION_NOT_FOUND;
2826 *status = service->state;
2828 ASP_LOGD("asp_session_get_close_status() SUCCESS");
2830 __ASP_LOG_FUNC_END__;
2833 int asp_session_connect(asp_session_h session)
2835 __ASP_LOG_FUNC_START__;
2836 GVariantBuilder *builder = NULL;
2837 GVariant *params = NULL;
2838 GError *error = NULL;
2839 GVariant *reply = NULL;
2840 asp_client_session_s *service = NULL;
2841 const char *str = NULL;
2842 int ret = ASP_ERROR_NONE;
2844 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2846 if (g_client_info.is_registered == false) {
2847 ASP_LOGE("Client is NOT registered");
2848 __ASP_LOG_FUNC_END__;
2849 return ASP_ERROR_NOT_INITIALIZED;
2853 ASP_LOGE("NULL Param!");
2854 __ASP_LOG_FUNC_END__;
2855 return ASP_ERROR_INVALID_PARAMETER;
2858 service = __get_session((void *)session);
2859 if (service == NULL) {
2860 ASP_LOGE("Session NOT registered");
2861 __ASP_LOG_FUNC_END__;
2862 return ASP_ERROR_SESSION_NOT_FOUND;
2865 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
2866 g_variant_builder_add(builder, "{sv}", "service_mac", g_variant_new("s", service->service_mac));
2867 g_variant_builder_add(builder, "{sv}", "adv_id", g_variant_new("u", service->advertisement_id));
2868 g_variant_builder_add(builder, "{sv}", "role", g_variant_new("y", service->network_config));
2869 g_variant_builder_add(builder, "{sv}", "config_method", g_variant_new("u", service->network_config));
2870 if (service->session_information)
2871 g_variant_builder_add(builder, "{sv}", "session _info", g_variant_new("s", service->session_information));
2873 params = g_variant_new("(a{sv})", builder);
2874 g_variant_builder_unref(builder);
2876 reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE,
2877 "ConnectSession", params, &error);
2878 if (error != NULL) {
2879 ASP_LOGE("asp_dbus_method_call_sync() failed."
2880 "error [%d: %s]", error->code, error->message);
2881 ret = __asp_err_string_to_enum(error->message);
2882 g_error_free(error);
2883 __ASP_LOG_FUNC_END__;
2887 g_variant_get(reply, "(iu&s)", &ret, &(service->session_id), &str);
2889 memcpy(service->session_mac, str, strlen(str));
2890 g_variant_unref(reply);
2892 ASP_LOGD("%s() return : [%d]", __func__, ret);
2894 __ASP_LOG_FUNC_END__;
2898 int asp_session_confirm(asp_session_h session, bool confirmed, char *pin)
2900 __ASP_LOG_FUNC_START__;
2901 GVariantBuilder *builder = NULL;
2902 GVariant *params = NULL;
2903 GError *error = NULL;
2904 GVariant *reply = NULL;
2905 asp_client_session_s *service = NULL;
2906 int ret = ASP_ERROR_NONE;
2908 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2910 if (g_client_info.is_registered == false) {
2911 ASP_LOGE("Client is NOT registered");
2912 __ASP_LOG_FUNC_END__;
2913 return ASP_ERROR_NOT_INITIALIZED;
2917 ASP_LOGE("NULL Param!");
2918 __ASP_LOG_FUNC_END__;
2919 return ASP_ERROR_INVALID_PARAMETER;
2922 service = __get_session((void *)session);
2923 if (service == NULL) {
2924 ASP_LOGE("Session NOT registered");
2925 __ASP_LOG_FUNC_END__;
2926 return ASP_ERROR_SESSION_NOT_FOUND;
2929 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
2930 g_variant_builder_add(builder, "{sv}", "session_mac", g_variant_new("s", service->session_mac));
2931 g_variant_builder_add(builder, "{sv}", "session_id", g_variant_new("u", service->session_id));
2932 g_variant_builder_add(builder, "{sv}", "confirmed", g_variant_new("i", confirmed));
2934 g_variant_builder_add(builder, "{sv}", "pin", g_variant_new("s", pin));
2935 params = g_variant_new("(a{sv})", builder);
2936 reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE,
2937 "ConfirmSession", params, &error);
2938 if (error != NULL) {
2939 ASP_LOGE("asp_dbus_method_call_sync() failed."
2940 "error [%d: %s]", error->code, error->message);
2941 ret = __asp_err_string_to_enum(error->message);
2942 g_error_free(error);
2943 __ASP_LOG_FUNC_END__;
2947 g_variant_get(reply, "(i)", &ret);
2948 g_variant_unref(reply);
2950 ASP_LOGD("%s() return : [%d]", __func__, ret);
2952 __ASP_LOG_FUNC_END__;
2956 int asp_session_get_handle(char *session_mac, unsigned int session_id,
2957 asp_session_h *session)
2960 __ASP_LOG_FUNC_START__;
2961 GVariant *params = NULL;
2962 GVariantIter *iter = NULL;
2963 GError *error = NULL;
2964 GVariant *reply = NULL;
2965 asp_client_session_s *service = NULL;
2967 GVariant *var = NULL;
2968 int ret = ASP_ERROR_NONE;
2970 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
2972 if (g_client_info.is_registered == false) {
2973 ASP_LOGE("Client is NOT registered");
2974 __ASP_LOG_FUNC_END__;
2975 return ASP_ERROR_NOT_INITIALIZED;
2978 if (!session_mac || !session) {
2979 ASP_LOGE("NULL Param!");
2980 __ASP_LOG_FUNC_END__;
2981 return ASP_ERROR_INVALID_PARAMETER;
2984 params = g_variant_new("(su)", session_mac, session_id);
2985 reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE,
2986 "GetSession", params, &error);
2987 if (error != NULL) {
2988 ASP_LOGE("asp_dbus_method_call_sync() failed."
2989 "error [%d: %s]", error->code, error->message);
2990 ret = __asp_err_string_to_enum(error->message);
2991 g_error_free(error);
2992 __ASP_LOG_FUNC_END__;
2997 ASP_LOGE("reply is NULL!!");
2998 __ASP_LOG_FUNC_END__;
2999 return ASP_ERROR_OPERATION_FAILED;
3002 service = (asp_client_session_s *)g_try_malloc0(sizeof(asp_client_session_s));
3004 ASP_LOGE("malloc() failed!!!.");
3005 g_variant_unref(reply);
3006 return ASP_ERROR_OUT_OF_MEMORY;
3008 ASP_LOGD("service [%p]", service);
3009 g_strlcpy(service->session_mac, session_mac, MACSTR_LEN);
3010 service->session_id = session_id;
3012 g_variant_get(reply, "(ia{sv})", &ret, &iter);
3013 while (g_variant_iter_loop(iter, "{sv}", &key, &var)) {
3014 if (!g_strcmp0(key, "adv_id")) {
3015 g_variant_get(var, "u", &(service->advertisement_id));
3017 } else if (!g_strcmp0(key, "session_id")) {
3018 g_variant_get(var, "u", &(service->session_id));
3019 } else if (!g_strcmp0(key, "session_mac")) {
3020 g_variant_get(var, "&s", &str);
3021 g_strlcpy(service->session_mac, str, MACSTR_LEN);
3022 } else if (!g_strcmp0(key, "state")) {
3023 g_variant_get(var, "i", &(service->state));
3024 } else if (!g_strcmp0(key, "session_info")) {
3025 g_variant_get(var, "&s", &str);
3028 /* TODO: additional params. */
3032 g_variant_unref(reply);
3034 ASP_LOGD("%s() return : [%d]", __func__, ret);
3036 asp_sessions = g_list_prepend(asp_sessions, service);
3038 __ASP_LOG_FUNC_END__;
3042 int asp_session_set_state_ready(asp_session_h session)
3045 __ASP_LOG_FUNC_START__;
3046 GVariant *params = NULL;
3047 GError *error = NULL;
3048 GVariant *reply = NULL;
3049 asp_client_session_s *service = NULL;
3050 int ret = ASP_ERROR_NONE;
3052 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
3054 if (g_client_info.is_registered == false) {
3055 ASP_LOGE("Client is NOT registered");
3056 __ASP_LOG_FUNC_END__;
3057 return ASP_ERROR_NOT_INITIALIZED;
3061 ASP_LOGE("NULL Param!");
3062 __ASP_LOG_FUNC_END__;
3063 return ASP_ERROR_INVALID_PARAMETER;
3066 service = __get_session((void *)session);
3067 if (service == NULL) {
3068 ASP_LOGE("Session NOT registered");
3069 return ASP_ERROR_SESSION_NOT_FOUND;
3072 params = g_variant_new("(su)", service->session_mac, service->session_id);
3073 reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE,
3074 "SetSessionReady", params, &error);
3075 if (error != NULL) {
3076 ASP_LOGE("asp_dbus_method_call_sync() failed."
3077 "error [%d: %s]", error->code, error->message);
3078 ret = __asp_err_string_to_enum(error->message);
3079 g_error_free(error);
3080 __ASP_LOG_FUNC_END__;
3084 g_variant_get(reply, "(i)", &ret);
3085 g_variant_unref(reply);
3087 ASP_LOGD("%s() return : [%d]", __func__, ret);
3089 __ASP_LOG_FUNC_END__;
3093 int asp_session_close(asp_session_h session)
3096 __ASP_LOG_FUNC_START__;
3097 GVariant *params = NULL;
3098 GError *error = NULL;
3099 GVariant *reply = NULL;
3100 asp_client_session_s *service = NULL;
3101 int ret = ASP_ERROR_NONE;
3103 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
3105 if (g_client_info.is_registered == false) {
3106 ASP_LOGE("Client is NOT registered");
3107 __ASP_LOG_FUNC_END__;
3108 return ASP_ERROR_NOT_INITIALIZED;
3112 ASP_LOGE("NULL Param!");
3113 __ASP_LOG_FUNC_END__;
3114 return ASP_ERROR_INVALID_PARAMETER;
3117 service = __get_session((void *)session);
3118 if (service == NULL) {
3119 ASP_LOGE("Session NOT registered");
3120 return ASP_ERROR_SESSION_NOT_FOUND;
3123 params = g_variant_new("(su)", service->session_mac, service->session_id);
3124 reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE,
3125 "CloseSession", params, &error);
3126 if (error != NULL) {
3127 ASP_LOGE("asp_dbus_method_call_sync() failed."
3128 "error [%d: %s]", error->code, error->message);
3129 ret = __asp_err_string_to_enum(error->message);
3130 g_error_free(error);
3131 __ASP_LOG_FUNC_END__;
3135 g_variant_get(reply, "(i)", &ret);
3136 g_variant_unref(reply);
3138 ASP_LOGD("%s() return : [%d]", __func__, ret);
3140 __ASP_LOG_FUNC_END__;
3144 int asp_session_bind_port(asp_session_h session, char *ip_address,
3145 int port, int proto)
3147 __ASP_LOG_FUNC_START__;
3148 GVariantBuilder *builder = NULL;
3149 GVariant *params = NULL;
3150 GError *error = NULL;
3151 GVariant *reply = NULL;
3152 asp_client_session_s *service = NULL;
3153 int ret = ASP_ERROR_NONE;
3155 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
3157 if (g_client_info.is_registered == false) {
3158 ASP_LOGE("Client is NOT registered");
3159 __ASP_LOG_FUNC_END__;
3160 return ASP_ERROR_NOT_INITIALIZED;
3163 if (!session || !ip_address) {
3164 ASP_LOGE("NULL Param!");
3165 __ASP_LOG_FUNC_END__;
3166 return ASP_ERROR_INVALID_PARAMETER;
3169 service = __get_session((void *)session);
3170 if (service == NULL) {
3171 ASP_LOGE("Session NOT registered");
3172 __ASP_LOG_FUNC_END__;
3173 return ASP_ERROR_SESSION_NOT_FOUND;
3176 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
3177 g_variant_builder_add(builder, "{sv}", "session_mac", g_variant_new("s", service->session_mac));
3178 g_variant_builder_add(builder, "{sv}", "session_id", g_variant_new("u", service->session_id));
3179 g_variant_builder_add(builder, "{sv}", "ip_address", g_variant_new("s", ip_address));
3180 g_variant_builder_add(builder, "{sv}", "port", g_variant_new("i", port));
3181 g_variant_builder_add(builder, "{sv}", "proto", g_variant_new("i", proto));
3182 params = g_variant_new("(a{sv})", builder);
3183 reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE,
3184 "BoundPort", params, &error);
3185 if (error != NULL) {
3186 ASP_LOGE("asp_dbus_method_call_sync() failed."
3187 "error [%d: %s]", error->code, error->message);
3188 ret = __asp_err_string_to_enum(error->message);
3189 g_error_free(error);
3190 __ASP_LOG_FUNC_END__;
3194 g_variant_get(reply, "(i)", &ret);
3195 g_variant_unref(reply);
3197 ASP_LOGD("%s() return : [%d]", __func__, ret);
3199 __ASP_LOG_FUNC_END__;
3203 int asp_session_release_port(asp_session_h session, char *ip_address,
3204 int port, int proto)
3206 __ASP_LOG_FUNC_START__;
3207 GVariantBuilder *builder = NULL;
3208 GVariant *params = NULL;
3209 GError *error = NULL;
3210 GVariant *reply = NULL;
3211 asp_client_session_s *service = NULL;
3212 int ret = ASP_ERROR_NONE;
3214 CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP);
3216 if (g_client_info.is_registered == false) {
3217 ASP_LOGE("Client is NOT registered");
3218 __ASP_LOG_FUNC_END__;
3219 return ASP_ERROR_NOT_INITIALIZED;
3222 if (!session || !ip_address) {
3223 ASP_LOGE("NULL Param!");
3224 __ASP_LOG_FUNC_END__;
3225 return ASP_ERROR_INVALID_PARAMETER;
3228 service = __get_session((void *)session);
3229 if (service == NULL) {
3230 ASP_LOGE("Session NOT registered");
3231 __ASP_LOG_FUNC_END__;
3232 return ASP_ERROR_SESSION_NOT_FOUND;
3235 builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}"));
3236 g_variant_builder_add(builder, "{sv}", "session_mac", g_variant_new("s", service->session_mac));
3237 g_variant_builder_add(builder, "{sv}", "session_id", g_variant_new("u", service->session_id));
3238 g_variant_builder_add(builder, "{sv}", "ip_address", g_variant_new("s", ip_address));
3239 g_variant_builder_add(builder, "{sv}", "port", g_variant_new("i", port));
3240 g_variant_builder_add(builder, "{sv}", "proto", g_variant_new("i", proto));
3241 params = g_variant_new("(a{sv})", builder);
3242 reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE,
3243 "ReleasePort", params, &error);
3244 if (error != NULL) {
3245 ASP_LOGE("asp_dbus_method_call_sync() failed."
3246 "error [%d: %s]", error->code, error->message);
3247 ret = __asp_err_string_to_enum(error->message);
3248 g_error_free(error);
3249 __ASP_LOG_FUNC_END__;
3253 g_variant_get(reply, "(i)", &ret);
3254 g_variant_unref(reply);
3256 ASP_LOGD("%s() return : [%d]", __func__, ret);
3258 __ASP_LOG_FUNC_END__;