From 70f1fe9bb55549ae08f411efddeb351588f8a773 Mon Sep 17 00:00:00 2001 From: Yu Jiung Date: Thu, 9 Mar 2017 10:34:19 +0900 Subject: [PATCH 2/4] Add Header and basic packaging files Change-Id: I4a8076e7ce8cc87533a11651932e15ee31eae67a Signed-off-by: Yu jiung --- CMakeLists.txt | 57 ++ LICENSE | 203 +++++ capi-network-asp.manifest | 5 + doc/asp_doc.h | 53 ++ include/CMakeLists.txt | 21 + include/asp.h | 1817 +++++++++++++++++++++++++++++++++++++++ packaging/capi-network-asp.spec | 97 +++ 7 files changed, 2253 insertions(+) create mode 100755 CMakeLists.txt create mode 100755 LICENSE create mode 100755 capi-network-asp.manifest create mode 100755 doc/asp_doc.h create mode 100755 include/CMakeLists.txt create mode 100755 include/asp.h create mode 100755 packaging/capi-network-asp.spec diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 0000000..84e7537 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,57 @@ +# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# + +############################# Check minimum CMake version ##################### + +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3) +PROJECT(capi-network-asp) + +############################# cmake packages ################################## + +INCLUDE(FindPkgConfig) + +########################## search for packages ################################ + +SET(COMMON_DEPS "dlog glib-2.0 gio-2.0 capi-base-common capi-system-info gio-unix-2.0") +SET(PC_DEPS "capi-base-common") + + +PKG_CHECK_MODULES(ASP_DEPS REQUIRED ${COMMON_DEPS}) + +######################## directory configuration ############################ + +############################# compiler flags ################################## +FOREACH(flag ${ASP_DEPS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2 -g") + +# Don't export symbols by default +ADD_DEFINITIONS("-fvisibility=hidden") +ADD_DEFINITIONS("-DUSE_DLOG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIBDIR}") + +SET(TARGET_ASP "asp") +SET(TARGET_ASP_TEST "asp-test") + + +ADD_SUBDIRECTORY(include) diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..a50093d --- /dev/null +++ b/LICENSE @@ -0,0 +1,203 @@ +Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/capi-network-asp.manifest b/capi-network-asp.manifest new file mode 100755 index 0000000..a76fdba --- /dev/null +++ b/capi-network-asp.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/doc/asp_doc.h b/doc/asp_doc.h new file mode 100755 index 0000000..181feaa --- /dev/null +++ b/doc/asp_doc.h @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#ifndef __TIZEN_NETWORK_ASP_DOC_H__ +#define __TIZEN_NETWORK_ASP_DOC_H__ + + +/** + * @defgroup CAPI_NETWORK_ASP_MODULE Application Service Platform + * @brief Wi-Fi Direct provides API to manage Application Service Platform. + * @ingroup CAPI_NETWORK_FRAMEWORK + * + * @section CAPI_NETWORK_ASP_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_ASP_MODULE_OVERVIEW Overview + * This set of functions is used to manage the settings of Application Service Platform. + * In addition, This set provides functions to discovery and manage sessions using Application Service Platform. + * @section CAPI_NETWORK_ASP_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.wifi\n + * - http://tizen.org/feature/network.wifi.direct\n + * - http://tizen.org/feature/network.wifi.direct.asp\n + * - http://tizen.org/feature/network.wifi.direct.display\n + * - http://tizen.org/feature/network.wifi.direct.service_discovery\n + * + * It is recommended to use feature related code in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using + * @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * To ensure your application is only running on the device with specific features, + * please define the features in your manifest file using the manifest editor in the SDK.\n + * More details on using features in your application can be found in the + * feature element description. + * + */ + + +#endif /* __TIZEN_NETWORK_ASP_DOC_H__ */ diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100755 index 0000000..29e24f0 --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,21 @@ +# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# + +INSTALL(FILES + ${CMAKE_SOURCE_DIR}/include/asp.h + DESTINATION ${INCLUDE_DIR}/asp + ) diff --git a/include/asp.h b/include/asp.h new file mode 100755 index 0000000..ad518cc --- /dev/null +++ b/include/asp.h @@ -0,0 +1,1817 @@ +/* + * + * Copyright (c) 2017 Samsung Electronics Co., Ltd. All rights reserved. + * + * Contact: Sungsik Jang , Dongwook Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * +*/ +#ifndef __TIZEN_NET_ASP_H__ +#define __TIZEN_NET_ASP_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_NETWORK_ASP_MODULE + * @{ + */ + +#ifndef TIZEN_ERROR_ASP +#define TIZEN_ERROR_ASP -0x02F60000 +#endif + +/** + * @brief Enumeration for Application Service Platform (ASP) error code. + * @since_tizen 4.0 + */ +typedef enum { + ASP_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + ASP_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation not permitted(1) */ + ASP_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory(12) */ + ASP_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied(13) */ + ASP_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy(16) */ + ASP_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter(22) */ + ASP_ERROR_CONNECTION_TIME_OUT = TIZEN_ERROR_CONNECTION_TIME_OUT, /**< Connection timed out(110) */ + ASP_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + ASP_ERROR_NOT_INITIALIZED = TIZEN_ERROR_ASP|0x01, /**< Not initialized */ + ASP_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_ASP|0x02, /**< Already initialized */ + ASP_ERROR_COMMUNICATION_FAILED = TIZEN_ERROR_ASP|0x03, /**< I/O error */ + ASP_ERROR_OPERATION_FAILED = TIZEN_ERROR_ASP|0x04, /**< Operation failed */ + ASP_ERROR_IN_PROGRESS = TIZEN_ERROR_ASP|0x05, /**< In progress */ + ASP_ERROR_SERVICE_NOT_FOUND = TIZEN_ERROR_ASP|0x06, /**< Service not found */ + ASP_ERROR_SESSION_NOT_FOUND = TIZEN_ERROR_ASP|0x07, /**< Session not found */ + ASP_ERROR_NETWORK_ROLE_REJECTED = TIZEN_ERROR_ASP|0x08 /**< Requested network role rejected */ +} asp_error_e; + +/** + * @brief Enumeration for Advertise Status event reason. + * @since_tizen 4.0 + */ +typedef enum { + ASP_ADVERT_STATUS_REASON_SUCCESS, /**< Status reason: Success */ + ASP_ADVERT_STATUS_REASON_SERVICE_DUPLICATED, /**< Status reason: Service duplicated */ + ASP_ADVERT_STATUS_REASON_OTHER_FAILURE, /**< Status reason: Other failure */ +} asp_advert_status_reason_e; + +/** + * @brief Enumeration for the Wi-Fi P2P role assignment scheme. + * @since_tizen 4.0 + * @see asp_advert_set_p2p_role_scheme() + * @see asp_advert_get_p2p_role_scheme() + * @see asp_session_set_p2p_role() + * @see asp_session_get_p2p_role() + */ +typedef enum { + ASP_ADVERT_P2P_ROLE_SCHEME_ANY, /**< All roles are acceptable */ + ASP_ADVERT_P2P_ROLE_SCHEME_GO, /**< The interface should assume the GO role */ + ASP_ADVERT_P2P_ROLE_SCHEME_GC, /**< The interface should assume the GC role */ +} asp_advert_p2p_role_scheme_e; + +/** + * @brief Enumeration for service discovery mechanism. + * @since_tizen 4.0 + * @see asp_advert_set_tech() + * @see asp_advert_get_tech() + * @see asp_seek_set_tech() + */ +typedef enum { + ASP_DISCOVERY_TECH_P2P = 1 << 0, /**< Use Wi-Fi P2P for discovery mechanism */ + ASP_DISCOVERY_TECH_BLE = 1 << 1, /**< Use BLE for discovery mechanism */ + ASP_DISCOVERY_TECH_NFC = 1 << 2, /**< Use NFC for discovery mechanism */ + ASP_DISCOVERY_TECH_INFRA = 1 << 3, /**< Use Wi-Fi Infrastructured for discovery mechanism */ + ASP_DISCOVERY_TECH_NAN = 1 << 4, /**< Use Wi-Fi NAN for discovery mechanism */ +} asp_discovery_tech_e; + +/** + * @brief Enumeration for Wi-Fi WPS type. + * @see asp_advert_set_p2p_config_method() + * @see asp_advert_get_p2p_config_method() + * @see asp_session_set_p2p_config_method() + * @see asp_session_get_p2p_config_method() + * @since_tizen 4.0 + */ +typedef enum { + ASP_WPS_TYPE_NONE, /**< No WPS type */ + ASP_WPS_TYPE_DEFAULT, /**< Default WPS type both P2PS and PIN */ + ASP_WPS_TYPE_PIN_BOTH, /**< WPS type PIN code both display and keypad*/ + ASP_WPS_TYPE_PIN_DISPLAY, /**< WPS type display PIN code only*/ + ASP_WPS_TYPE_PIN_KEYPAD, /**< WPS type keypad to input the PIN only*/ +} asp_wps_type_e; + +/** + * @brief Enumeration for Application Service Platform (ASP) Session connect status. + * @since_tizen 4.0 +*/ +typedef enum { + ASP_CONNECT_STATUS_NETWORK_ROLE_REJECTED, /**< Network role rejected */ + ASP_CONNECT_STATUS_CONNECTION_LIMIT_REACHED, /**< The device's connection limit has been reached */ + ASP_CONNECT_STATUS_REQUEST_SENT, /**< Session request sent */ + ASP_CONNECT_STATUS_REQUEST_RECEIVED, /**< Session request received */ + ASP_CONNECT_STATUS_REQUEST_DEFERRED, /**< Session request deferred */ + ASP_CONNECT_STATUS_REQUEST_ACCEPTED, /**< Session request accepted */ + ASP_CONNECT_STATUS_REQUEST_FAILED, /**< Session request failed */ + ASP_CONNECT_STATUS_GROUP_FORMATION_STARTED, /**< Group formation started */ + ASP_CONNECT_STATUS_GROUP_FORMATION_COMPLETED, /**< Group formation completed */ + ASP_CONNECT_STATUS_GROUP_FORMATION_FAILED, /**< Group formation failed*/ +} asp_connect_status_e; + +/** + * @brief Enumeration for Application Service Platform (ASP) general session state. + * @since_tizen 4.0 +*/ +typedef enum { + ASP_SESSION_STATE_ERROR, /**< Session state error*/ + ASP_SESSION_STATE_CLOSED, /**< Session state closed*/ + ASP_SESSION_STATE_INITIATED, /**< Session state initiated*/ + ASP_SESSION_STATE_REQUESTED, /**< Session state requested*/ + ASP_SESSION_STATE_OPEN, /**< Session state open*/ +} asp_session_state_e; + +/** + * @brief Enumeration for Application Service Platform (ASP) session close status. + * @since_tizen 4.0 +*/ +typedef enum { + ASP_SESSION_CLOSE_OK, /**< Session closed without error */ + ASP_SESSION_CLOSE_DISASSOCIATED, /**< Session closed by disassociation (Wi-Fi Direct connection was broken) */ + ASP_SESSION_CLOSE_LOCAL_CLOSE, /**< Session closed with local close */ + ASP_SESSION_CLOSE_REMOTE_CLOSE, /**< Session closed with remote close */ + ASP_SESSION_CLOSE_SYSTEM_FAILURE, /**< Session closed with system failure */ + ASP_SESSION_CLOSE_NO_RESPONSE, /**< Session closed with no response from remote */ +} asp_session_close_status_e; + +/** + * @brief Enumeration for Application Service Platform (ASP) port status. + * @since_tizen 4.0 +*/ +typedef enum { + ASP_PORT_STATUS_LOCAL_PORT_ALLOWED, /**< Incoming connections are allowed on this local port for this ASP session */ + ASP_PORT_STATUS_LOCAL_PORT_BLOCKED, /**< Incoming connections are no longer allowed in the ASP session for this local port */ + ASP_PORT_STATUS_FAILURE, /**< The ASP was unable to set up this local port */ + ASP_PORT_STATUS_REMOTE_PORT_ALLOWED, /**< The remote service has allowed access to the given remote port for the given protocol */ +} asp_port_status_e; + +/** + * @brief Enumeration for service status. + * @since_tizen 4.0 +*/ +typedef enum { + ASP_SERVICE_STATUS_NOT_ADVERTISED , /**< Service status not advertised */ + ASP_SERVICE_STATUS_ADVERTISED, /**< Service status advertised */ +} asp_service_status_e; + +/** + * @brief The advertised service description. + * @since_tizen 4.0 + */ +typedef void *asp_advert_service_h; + +/** + * @brief The searching service description. + * @since_tizen 4.0 + */ +typedef void *asp_seek_service_h; + +/** + * @brief The Application Service Platform (ASP) session description. + * @since_tizen 4.0 + */ +typedef void *asp_session_h; + +/** +* @brief Called when the Application Service Platform (ASP) Service is found. +* @since_tizen 4.0 +* @remarks @a service_mac, @a instance_name and @a service_info are valid only in the callback. +* To use outside the callback, make a copy. +* @param[in] error_code The error code. \n +* #ASP_ERROR_NONE Successful\n +* #ASP_ERROR_OUT_OF_MEMORY Out of memory\n +* #ASP_ERROR_OPERATION_FAILED Operation failed\n +* @param[in] seek_service The seek service which found the current result; +* the handle to the same object for which the search was started +* @param[in] service_mac The P2P device address of the device which provides the service; +* NULL if not available +* @param[in] adv_id The service advertisement ID defined by remote P2P device +* @param[in] config_method The preferred Wi-Fi Simple Config (WSC) configuration method +* @param[in] instance_name The advertised service name defined by the remote P2P device; +* NULL if not available +* @param[in] service_info The advertised service information defined by the remote P2P device; +* NULL if not available +* @param[in] info_size The advertised service information payload size; +* if the information is not available, this is set to -1 +* @param[in] status The status of the service +* @param[in] user_data The user data passed from the callback registration function +* @pre The callback must be registered using asp_seek_set_search_result_cb().\n +* asp_seek_start() must be called to invoke this callback. +* @see asp_seek_set_search_result_cb() +* @see asp_seek_unset_search_result_cb() +* @see asp_seek_start() +*/ +typedef void (*asp_seek_search_result_cb) (int error_code, + asp_seek_service_h seek_service, + const char *service_mac, + unsigned int adv_id, + asp_wps_type_e config_method, + const char *instance_name, + const char *service_info, + int info_size, + unsigned char status, + void *user_data); + +/** +* @brief Called when the status of an advertisement to a service is changed. +* @since_tizen 4.0 +* @param[in] adv_service The service whose status has changed; +* the handle to the same object for which the callback was set +* @param[in] status The status of the service +* @param[in] reason The reason of the state change +* @param[in] user_data The user data passed from the callback registration function +* @pre The callback must be registered using asp_advert_set_status_cb().\n +* asp_advert_start_advertising() and asp_change_service_state() invoke this callback. +* @see asp_advert_set_status_changed_cb() +* @see asp_advert_unset_status_changed_cb() +* @see asp_advert_start_advertising() +*/ +typedef void (*asp_advert_status_changed_cb) (asp_advert_service_h adv_service, + asp_service_status_e status, + asp_advert_status_reason_e reason, + void *user_data); + +/** +* @brief Called when a remote device is attempting to initiate an ASP session. +* @since_tizen 4.0 +* @remarks @a network_config_pin, @a device_name and @a info are valid only in the callback. +* To use outside the callback, make a copy. +* @param[in] error_code The error code.\n +* #ASP_ERROR_NONE Successful\n +* #ASP_ERROR_OUT_OF_MEMORY Out of memory\n +* #ASP_ERROR_OPERATION_FAILED Operation failed\n +* @param[in] adv_service Service descriptor handle provided by the asp_advert_create() +* it is the "original" object not created specifically for the callback +* @param[in] session The session for which the request is made; +* the handle to the same object for which the callback was set +* @param[in] device_name Device name of the remote peer +* @param[in] info The service-specific data payload (up to 144 bytes); +* NULL if not available +* @param[in] info_size The service-specific data payload size (up to 144) +* @param[in] get_network_config_pin (@c true = requires WSC PIN to be entered by +* the asp_session_confirm(), +* @c false = does not require PIN) +* @param[in] network_config_pin The WSC PIN value to be displayed; NULL if not available +* @param[in] user_data The user data passed from the callback registration function +* @pre The callback must be registered using asp_session_set_request_cb(). +* @see asp_session_set_request_cb() +*/ +typedef void (*asp_session_request_cb) (int error_code, + asp_advert_service_h adv_service, + asp_session_h session, + const char *device_name, + const char *info, + int info_size, + bool get_network_config_pin, + const char *network_config_pin, + void *user_data); + +/** +* @brief Called when the Application Service Platform (ASP) has to provide +* a PIN value or collect a PIN value. +* @since_tizen 4.0 +* @remarks @a config_pin is valid only in the callback. +* To use outside the callback, make a copy. +* @param[in] error_code The error code.\n +* #ASP_ERROR_NONE Successful\n +* #ASP_ERROR_OUT_OF_MEMORY Out of memory\n +* #ASP_ERROR_OPERATION_FAILED Operation failed\n +* @param[in] session The session for which the request is made; +* the handle to the same object for which the callback was set +* @param[in] get_pin (@c true = instruct the user to enter the PIN, +* @c false = display the PIN provided in the @a config_pin parameter) +* @param[in] config_pin The WSC PIN value used for setting up; ignored if @a get_pin is @c true +* @param[in] user_data The user data passed from the callback registration function +* @pre The callback must be registered using asp_session_set_config_request_cb().\n +* asp_session_connect() must be called to invoke this callback. +* @see asp_session_set_request_cb() +* @see asp_session_connect() +*/ +typedef void (*asp_session_config_request_cb) (int error_code, + asp_session_h session, + bool get_pin, + const char *config_pin, + void *user_data); + +/** +* @brief Called when the Application Service Platform (ASP) reports progress on group formation. +* @since_tizen 4.0 +* @remarks @a deferred_resp is valid only in the callback. +* To use outside the callback, make a copy. +* @param[in] error_code The error code.\n +* #ASP_ERROR_NONE Successful\n +* #ASP_ERROR_OUT_OF_MEMORY Out of memory\n +* #ASP_ERROR_OPERATION_FAILED Operation failed\n +* @param[in] session The session for which progress is reported; +* the handle to the same object for which the callback was set +* @param[in] status The connection progress status +* @param[in] deferred_resp The service-specific data payload up to 144 bytes +* @param[in] resp_size The service-specific data payload size(up to 144) +* @param[in] user_data The user data passed from the callback registration function +* @pre The callback must be registered using asp_session_set_connect_status_cb() +* @see asp_session_set_connect_status_cb() +*/ +typedef void (*asp_session_connect_status_cb) (int error_code, + asp_session_h session, + asp_connect_status_e status, + const char *deferred_resp, + int resp_size, + void *user_data); + +/** +* @brief Called when the Application Service Platform (ASP) reports the state and status of an ASP session. +* @since_tizen 4.0 +* @remarks @a additional_info is valid only in the callback. +* To use outside the callback, make a copy. +* @param[in] error_code The error code.\n +* #ASP_ERROR_NONE Successful\n +* #ASP_ERROR_OUT_OF_MEMORY Out of memory\n +* #ASP_ERROR_OPERATION_FAILED Operation failed\n +* @param[in] session The session for which status is reported; +* the handle to the same object for which the callback was set +* @param[in] state The session state +* @param[in] additional_info Additional information related to the SessionStatus event +* @param[in] user_data The user data passed from the callback registration function +* @pre The callback must be registered using asp_session_set_status_cb() +* @see asp_session_set_status_cb() +*/ +typedef void (*asp_session_status_cb) (int error_code, + asp_session_h session, + asp_session_state_e state, + const char *additional_info, + void *user_data); + +/** +* @brief Called when the Application Service Platform (ASP) reports the status of the network port on the local and remote end of the ASP session. +* @since_tizen 4.0 +* @remarks @a ip_address is valid only in the callback. +* To use outside the callback, make a copy. +* @param[in] error_code The error code.\n +* #ASP_ERROR_NONE Successful\n +* #ASP_ERROR_OUT_OF_MEMORY Out of memory\n +* #ASP_ERROR_OPERATION_FAILED Operation failed\n +* @param[in] session Application Service Platform session descriptor handle +* @param[in] ip_address The IP address for the port, local or remote +* @param[in] port The port number +* @param[in] proto The IANA protocol number +* @param[in] status The port status +* @param[in] user_data The user data passed from the callback registration function +* @pre The callback must be registered using asp_session_set_port_status_cb() +* @see asp_set_session_port_status_cb() +*/ +typedef void (*asp_session_port_status_cb) (int error_code, + asp_session_h session, + const char *ip_address, + int port, + int proto, + asp_port_status_e status, + void *user_data); + +/** + * @brief Initializes Application Service Platform (ASP). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @return 0 on success, otherwise a negative error value. + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_RESOURCE_BUSY Device or resource busy + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @see asp_deinitialize() + */ +int asp_initialize(void); + +/** + * @brief Deinitializes Application Service Platform (ASP). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @return 0 on success, otherwise a negative error value. + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_COMMUNICATION_FAILED Communication failed + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + */ +int asp_deinitialize(void); + +/** + * @brief Registers the callback function that will be invoked when a service found. + * @since_tizen 4.0 + * @privlevel public + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data passed from the callback registration function + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @post asp_search_result_cb will be called under certain conditions, + * after calling asp_seek_start() + * @see asp_initialize() + * @see asp_seek_unset_search_result_cb() + * @see asp_seek_start() + */ +int asp_seek_set_search_result_cb(asp_seek_search_result_cb cb, void *user_data); + +/** + * @brief Unregisters the callback function that will invoked when a service found. + * @since_tizen 4.0 + * @privlevel public + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_seek_set_search_result_cb() + */ +int asp_seek_unset_search_result_cb(void); + +/** + * @brief Registers the callback function that will invoked when the status of an advertisement to a service is changed. + * @since_tizen 4.0 + * @privlevel public + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data passed from the callback registration function + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @post asp_seek_search_result_cb() will be called under certain conditions, + * after calling asp_seek_start() + * @see asp_initialize() + * @see asp_advert_unset_status_changed_cb() + * @see asp_advert_start_advertising() + */ +int asp_advert_set_status_changed_cb(asp_advert_status_changed_cb cb, + void *user_data); + +/** + * @brief Unregisters the callback function that will invoked when the status of an advertisement to a service is changed. + * @since_tizen 4.0 + * @privlevel public + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_advert_set_status_changed_cb() + */ +int asp_advert_unset_status_changed_cb(void); + +/** + * @brief Registers the callback called when ASP session connection is requested. + * @since_tizen 4.0 + * @privlevel public + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data passed from the callback registration function + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_unset_request_cb() + */ +int asp_session_set_request_cb(asp_session_request_cb cb, void *user_data); + +/** + * @brief Unregisters the callback called ASP when session connection is requested. + * @since_tizen 4.0 + * @privlevel public + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_set_request_cb() + */ +int asp_session_unset_request_cb(void); + +/** + * @brief Registers the callback called when the session configuration is requested. + * @since_tizen 4.0 + * @privlevel public + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data passed from the callback registration function + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_unset_config_request_cb() + * @see asp_session_config_request_cb() + */ +int asp_session_set_config_request_cb(asp_session_config_request_cb cb, + void *user_data); + +/** + * @brief Unregisters the callback called when the session configuration is requested. + * @since_tizen 4.0 + * @privlevel public + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_config_request_cb() + */ +int asp_session_unset_config_request_cb(void); + +/** + * @brief Registers the callback called when the state of the session connection is changed. + * @since_tizen 4.0 + * @privlevel public + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data passed from the callback registration function + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_unset_connection_status_changed_cb() + * @see asp_session_connect_status_cb() + */ +int asp_session_set_connect_status_cb(asp_session_connect_status_cb cb, void *user_data); + +/** + * @brief Unregisters the callback called when the state of the session connection is changed. + * @since_tizen 4.0 + * @privlevel public + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_set_connection_status_changed_cb() + */ +int asp_session_unset_connect_status_cb(void); + +/** + * @brief Registers the callback called when the state of the session is changed. + * @since_tizen 4.0 + * @privlevel public + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data passed from the callback registration function + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_unset_status_cb() + * @see asp_session_status_cb() + */ +int asp_session_set_status_cb(asp_session_status_cb cb, void *user_data); + +/** + * @brief Unregisters the callback called when the state of the session is changed. + * @since_tizen 4.0 + * @privlevel public + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_set_status_cb() + */ +int asp_session_unset_status_cb(void); + +/** + * @brief Registers the callback called when the state of the port is changed. + * @since_tizen 4.0 + * @privlevel public + * @param[in] cb The callback function to invoke + * @param[in] user_data The user data passed from the callback registration function + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_unset_status_cb() + */ +int asp_session_set_port_status_cb(asp_session_port_status_cb cb, void *user_data); + +/** + * @brief Unregisters the callback called when the state of the port is changed. + * @since_tizen 4.0 + * @privlevel public + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_initialize() + * @see asp_session_set_port_status_cb() + */ +int asp_session_unset_port_status_cb(void); + +/** + * @brief Creates the description of a service to be advertised. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] instance_name Service instance name of a service type to be advertised. + * The length of this parameter be 63 byte or less and + * encoding shall be single-byte or multi-byte UTF-8 characters. + * If you want to advertise one of the original P2PS defined services, + * this shall be NULL. + * @param[out] adv_service service descriptor handle + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_advert_destroy() + */ +int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service); + +/** + * @brief Destroys the description of a service to be advertised. + * @details If asp_advert_start_advertising() was called for a service, + * asp_advert_stop_advertising() should be called for it before destroying it. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_create_service() before use + * @see asp_advert_create() + */ +int asp_advert_destroy(asp_advert_service_h adv_service); + +/** + * @brief Sets the service type for a service to be advertised. + * @details Application should set service type after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] service_type The unique type of a particular service. + * this shall be at least 1 character and no more than 15 characters long + * contain only US-ASCII [ANSI.X3.4-1986] letters 'A' - 'Z' and + * 'a' - 'z', digits '0' - '9', and hyphens ('-', ASCII 0x2D or decimal 45) + * contain at least one letter ('A' - 'Z' or 'a' - ‘z') + * not begin or end with a hyphen. If you want to advertise one of the + * original P2PS defined services, this means service name. + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_service_type(asp_advert_service_h adv_service, + char *service_type); + +/** + * @brief Sets auto accept for a service to be advertised. + * @details Application should set service auto accept after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] auto_accept Enables/Disables auto accept based on the value TRUE/FALSE + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_auto_accept(asp_advert_service_h adv_service, + bool auto_accept); + +/** + * @brief Adds the information for a service to be advertised. + * @details Application should set service information after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] key Service-defined key data specified in Section 6 of RFC6763 + * @param[in] value Service-defined value data specified in Section 6 of RFC6763 + * Only one value can be added for a given key. If a value is set for a key, + * and another value was set for the key before, the old value will be + * overwritten with the new one. + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_add_info(asp_advert_service_h adv_service, + const char *key, const char *value); + + +/** + * @brief Sets the information for a service to be advertised. + * @details Application should set service information after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @remarks @a value should not be freed. + * It is recommended to make a copy of it to use. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] key Service-defined key data specified in Section 6 of RFC6763 + * @param[in] length Length of service-defined value data specified in Section 6 of RFC6763 + * @param[in] value Service-defined value data specified in Section 6 of RFC6763 + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_get_info(asp_advert_service_h adv_service, const char *key, + int *length, char **value); + + +/** + * @brief Sets the information for a service to be advertised. + * @details Application should set service information after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] key Service-defined key data specified to be removed + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_remove_info(asp_advert_service_h adv_service, const char *key); + +/** + * @brief Sets the status for a service to be advertised. + * @details Application should set service status after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] status Status of the service: + * (@c 1 = available to use, @c 0 = not available to use, + * @c 2-255 = service specific information) + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_status(asp_advert_service_h adv_service, + unsigned char status); + + +/** + * @brief Sets the discovery mechanism for a service to be advertised. + * @details Application should set discovery mechanism after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] discovery_tech The discovery mechanism; values of + * #asp_discovery_tech_e combined with bitwise 'or' + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_discovery_tech(asp_advert_service_h adv_service, int discovery_tech); + +/** + * @brief Sets the preferred connection for a service to be advertised. + * @details Application should set preferred connection after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] preferred_connection The preferred connection + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_preferred_connection(asp_advert_service_h adv_service, + unsigned char preferred_connection); + +/** + * @brief Sets the Wi-Fi P2P role for a service to be advertised. + * @details Application should set role after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] role The role of the service: \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_ANY - All roles are acceptable \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GO - The receiving interface should assume \n + * the GO role, if it's not possible, #ASP_ERROR_NETWORK_ROLE_REJECTED \n + * is returned \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GC - + * The receiving interface should assume the GC role + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @retval #ASP_ERROR_NETWORK_ROLE_REJECTED Network role rejected + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_p2p_role_scheme(asp_advert_service_h adv_service, + asp_advert_p2p_role_scheme_e role); + +/** + * @brief Gets the Wi-Fi P2P role for a service to be advertised. + * @details Application should Get role after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] role The role of the service: \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_ANY - All roles are acceptable \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GO - The receiving interface should assume \n + * the GO role \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GC - + * The receiving interface should assume the GC role + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_get_p2p_role_scheme(asp_advert_service_h adv_service, + asp_advert_p2p_role_scheme_e *role); + +/** + * @brief Sets the P2P configuration method for a service to be advertised. + * @details Application should set configuration method after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] config_method preferred Wi-Fi Simple Config (WSC) configuration method. + * Default value is ASP_WPS_TYPE_DEFAULT. + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_p2p_config_method(asp_advert_service_h adv_service, + asp_wps_type_e config_method); +/** + * @brief Gets the P2P configuration method for a service to be advertised. + * @details Application should Get configuration method after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] config_method preferred Wi-Fi Simple Config (WSC)configuration method. + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_get_p2p_config_method(asp_advert_service_h adv_service, + asp_wps_type_e *config_method); + +/** + * @brief Sets the service response for an advertised service. + * @details Application should set service response after creating service using + * asp_advert_create() and before advertising service using + * asp_advert_create(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @param[in] rsp_info Specified for a particular service up to 144 bytes. + * You can refer to Wi-Fi Peer-to-Peer Services Technical Specification, + * Wi-Fi Alliance. Available at:http://www.wi-fi.org + * @param[in] length The length of @a rsp_info in bytes, maximum length is 144 + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + */ +int asp_advert_set_p2p_response(asp_advert_service_h adv_service, + char *rsp_info, int length); + +/** + * @brief Starts to advertise a service. + * @details Application should start to advertise after creating service using + * asp_advert_create(). If the service is being advertised, no changes can be made to it. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_create() before use + * @see asp_advert_create() + * @see asp_advert_stop_advertising() + */ +int asp_advert_start_advertising(asp_advert_service_h adv_service); + +/** + * @brief Stops a service advertisement. + * @details Application should cancel to advertise after advertising service using + * asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_start_advertising() before use + * @see asp_advert_start_advertising() + */ +int asp_advert_stop_advertising(asp_advert_service_h adv_service); + +/** + * @brief Changes the advertising service status. + * @details Application should change the advertising service + * status after advertising service using asp_advert_start_advertising(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_create_service() + * @param[in] status Status of the service: + * (@c 1 = available to use, @c 0 = not available to use, + * @c 2-255 = service specific information) + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_advert_start_advertising() before use + * @see asp_advert_start_advertising() + */ +int asp_advert_change_service_status(asp_advert_service_h adv_service, + unsigned char status); + +/** + * @brief Creates the description of a seek operation. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] service_type Service Type of a service being searched. + * this shall be at least 1 character and no more than 15 characters long + * contain only US-ASCII [ANSI.X3.4-1986] letters 'A' - 'Z' and + * 'a' - 'z', digits '0' - '9', and hyphens ('-', ASCII 0x2D or decimal 45) + * contain at least one letter ('A' - 'Z' or 'a' - ‘z') + * not begin or end with a hyphen. If you want to seek one of the + * original P2PS defined services, this means service name. + * @param[out] seek_service Service seek handle + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @pre Application Service Platform (ASP) must be initialized by asp_initialize(). + * @see asp_seek_destroy() + */ +int asp_seek_create(char *service_type, asp_seek_service_h *seek_service); + +/** + * @brief Destroys the description of a seek operation. + * @details If asp_seek_start() was called for a service, + * asp_seek_stop() should be called for it before destroying it. + * asp_seek_stop(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] seek_service Service seek handle provided by the asp_seek_create() + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre A seek service handle must be created with asp_seek_create(). + * @see asp_seek_create + */ +int asp_seek_destroy(asp_seek_service_h seek_service); + +/** + * @brief Adds the information for a service to be sought. + * @details Application should set service information after creating service using + * asp_seek_create() and before seeking service using asp_seek_start(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] seek_service Service descriptor handle provided by the asp_seek_create() + * @param[in] key Service-defined key data to be searched, + * specified in Section 6 of RFC6763 + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_seek_create() before use + * @see asp_seek_create() + */ +int asp_seek_add_info(asp_seek_service_h seek_service, const char *key); + +/** + * @brief Removes the information for a service to be sought. + * @details Application should set service information after creating service using + * asp_seek_create() and before seeking service using asp_seek_start(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] seek_service Service descriptor handle provided by the asp_seek_create() + * @param[in] key Service-defined key data to be searched, + * specified in Section 6 of RFC6763 + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_seek_create() before use + * @see asp_seek_create() + */ +int asp_seek_remove_info(asp_seek_service_h seek_service, const char *key); + +/** + * @brief Sets the discovery mechanism for a service to be sought. + * @details Application should set service information after creating service using + * asp_seek_create() and before seeking service using asp_seek_start(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_seek_create() + * @param[in] discovery_tech The discovery mechanism, values of + * #asp_discovery_tech_e combined with bitiwse 'or' + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_seek_create() before use + * @see asp_seek_create() + */ +int asp_seek_set_discovery_tech(asp_seek_service_h seek_service, int discovery_tech); + +/** + * @brief Sets the preferred connection for a service to be sought. + * @details Application should set service information after creating service using + * asp_seek_create() and before seeking service using asp_seek_start(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] adv_service Service descriptor handle provided by the asp_seek_create() + * @param[in] preferred_connection The preferred connection + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre This API needs asp_seek_create() before use + * @see asp_seek_create() + */ +int asp_seek_set_preferred_connection(asp_seek_service_h seek_service, + unsigned char preferred_connection); + +/** + * @brief Starts to seek services on peer devices. + * @details If the service is currently seeking, no changes can be made to it. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] seek_service Service seek handle provided by the asp_seek_create() + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre A seek service handle must be created with asp_seek_create(). + * @see asp_seek_create() + * @see asp_seek_stop() + */ +int asp_seek_start(asp_seek_service_h seek_service); + +/** + * @brief Stops seeking services. + * @details Application should cancel to seek service after searching service using + * asp_seek_start(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] seek_service Service seek handle provided by the asp_seek_create() + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SERVICE_NOT_FOUND Service not found + * @pre A seek service handle must be created with asp_seek_create(). + * @see asp_seek_start() + */ +int asp_seek_stop(asp_seek_service_h seek_service); + +/** + * @brief Creates a local Application Service Platform (ASP) session. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] service_mac P2P device address of remote P2P device provided by + * asp_seek_search_result_cb() + * @param[in] adv_id The advertisement ID provided by + * asp_seek_search_result_cb() + * @param[in] session ASP session descriptor handle + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @see asp_session_destroy() + */ +int asp_session_create(char *service_mac, unsigned int adv_id, + asp_session_h *session); + +/** + * @brief Destroys a local Application Service Platform (ASP) session. + * @details Application should create session by asp_session_create(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + */ +int asp_session_destroy(asp_session_h session); + +/** + * @brief Gets the session MAC for an Application Service Platform session. + * @details Application should request to connect session by + * asp_session_connect() or receive request by asp_session_request_cb(). + * @remarks @a session_mac should not be freed. + * It is recommended to make a copy of it to use. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * @param[out] session_mac The session MAC is the MAC address of + * P2P device which assigned the session ID + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_connect() before use. + * @see asp_session_connect() + * @see asp_session_request_cb() + */ +int asp_session_get_mac(asp_session_h session, char **session_mac); + +/** + * @brief Gets the ID of an Application Service Platform session. + * @details Application should create local session by + * asp_session_create() or receive request by asp_session_request_cb(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * @param[out] session_id The session ID + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + * @see asp_session_request_cb() + */ +int asp_session_get_id(asp_session_h session, unsigned int *session_id); + +/** + * @brief Sets the information for an Application Service Platform session. + * @details Application should set session_info after creating session by + * asp_session_create() and before requesting to connect + * session by asp_session_connect(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * provided by the asp_session_create() + * @param[in] session_info Detailed information about the session. + * The session_info parameter is defined for each service section + * and up to 144 bytes. You can refer to Wi-Fi Peer-to-Peer Services + * Technical Specification, Wi-Fi Alliance. + * Available at:http://www.wi-fi.org + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + */ +int asp_session_set_info(asp_session_h session, char *session_info); + +/** + * @brief Gets the information for an Application Service Platform session. + * @details Application should get session_info after creating session by + * asp_session_create() and before requesting to connect + * session by asp_session_connect(). + * @remarks @a session_info should not be freed. + * It is recommended to make a copy of it to use. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * provided by the asp_session_create() + * @param[out] session_info detailed information about session + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + */ +int asp_session_get_info(asp_session_h session, char **session_info); + +/** + * @brief Sets the Wi-Fi Direct group role in session. + * @details Application should set role after creating session by + * asp_session_create() and before requesting to connect + * session by asp_session_connect(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * provided by the asp_session_create() + * @param[in] role The role of the service: \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_ANY - All roles are acceptable \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GO - The receiving interface should assume \n + * the GO role, if it's not possible, #ASP_ERROR_NETWORK_ROLE_REJECTED \n + * is returned \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GC - + * The receiving interface should assume the GC role + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @retval #ASP_ERROR_NETWORK_ROLE_REJECTED Network role rejected + * @pre This API needs asp_create_service() before use. + * @see asp_create_session() + */ +int asp_session_set_p2p_role_scheme(asp_session_h session, + asp_advert_p2p_role_scheme_e role); + +/** + * @brief Gets the Wi-Fi Direct group role in session. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * provided by the asp_session_create() + * @param[in] role The role of the service: \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_ANY - All roles are acceptable \n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GO - The receiving interface should assume \n + * the GO role\n + * #ASP_ADVERT_P2P_ROLE_SCHEME_GC - + * The receiving interface should assume the GC role + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + */ +int asp_session_get_p2p_role_scheme(asp_session_h session, + asp_advert_p2p_role_scheme_e *role); + +/** + * @brief Sets the Preferred WSC Configuration method. + * @details Application should set the config method after creating session by + * asp_session_create() and before requesting to connect + * session by asp_session_connect(). + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * provided by the asp_session_create() + * @param[in] config_method Preferred WSC Configuration method. + * Default value is #ASP_WPS_TYPE_DEFAULT. + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + */ +int asp_session_set_p2p_config_method(asp_session_h session, + asp_wps_type_e config_method); + +/** + * @brief Gets the Preferred WSC Configuration method. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * provided by the asp_session_create() + * @param[out] config_method Preferred WSC Configuration method + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + */ +int asp_session_get_p2p_config_method(asp_session_h session, + asp_wps_type_e *config_method); + +/** + * @brief Gets the session close status. + * @details This call is valid only for closed sessions (sessions in the #ASP_SESSION_STATE_CLOSED + * state). If the @a session does not identify a closed session, + * #ASP_ERROR_NOT_PERMITTED is returned. + * @since_tizen 4.0 + * @param[in] session ASP session descriptor handle provided by + * the asp_session_request_cb() callback, + * asp_session_create(), or asp_session_get_handle() + * @param[out] status The session close status + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + */ +int asp_session_get_close_status(asp_session_h session, int *status); + +/** + * @brief Starts to connect the Application Service Platform session. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session Application Service Platform session descriptor handle + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre This API needs asp_session_create() before use. + * @see asp_session_create() + */ +int asp_session_connect(asp_session_h session); + +/** + * @brief Confirms the Application Service Platform(ASP) session request. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session ASP session descriptor handle provided by + * the asp_session_request_cb() callback or + * asp_session_create() if pin is requested. + * @param[in] confirmed (@c true = confirm session, @c false = reject session) + * @param[in] pin If session requests the WSC PIN + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @see asp_advert_start_advertising() + * @see asp_session_create() + */ +int asp_session_confirm(asp_session_h session, bool confirmed, char *pin); + +/** + * @brief Gets the Description of Application Service Platform (ASP) session to be connected. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session_mac The MAC address of the P2P device that assigned + * the value of session_id, as provided by + * the asp_session_request_cb() callback or + * asp_session_create() if pin is requested. + * @param[in] session_id The session ID + * @param[out] session Peer-to-Peer service session descriptor handle + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @see asp_session_create() + */ +int asp_session_get_handle(char *session_mac, unsigned int session_id, + asp_session_h *session); + +/** + * @brief Moves an Application Service Platform (ASP) session from Requested state to the Open state. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session ASP session descriptor handle provided by + * the asp_session_request_cb() callback + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @pre Peer-to-Peer service must be advertised by asp_advert_start_advertising().\n + * Local device should be listening or finding remote P2P device by + * asp_advert_start_advertising() + * @see asp_advert_start_advertising() + */ +int asp_session_set_state_ready(asp_session_h session); + +/** + * @brief Ends an Application Service Platform (ASP) session and releases associated resources. + * @details The ASP may tear down the underlying ASP P2P group + * if not other ASP sessions are using it. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session ASP session descriptor handle provided by + * the asp_session_request_cb() callback or + * asp_session_create() + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @see asp_session_create() + * @see asp_session_request_cb() + */ +int asp_session_close(asp_session_h session); + +/** + * @brief Requests that incoming connections be allowed on a given port. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session ASP session descriptor handle provided by + * the asp_session_request_cb() callback or + * asp_session_create() + * @param[in] ip_address The IP address on which the port is being used + * @param[in] port The port number + * @param[in] proto The IANA protocol number + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @see asp_session_create() + * @see asp_session_request_cb() + */ +int asp_session_bind_port(asp_session_h session, char *ip_address, + int port, int proto); + +/** + * @brief Indicates that the service is no longer utilizing the port in the ASP session. + * @since_tizen 4.0 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] session ASP session descriptor handle provided by + * the asp_session_request_cb() callback or + * asp_session_create() + * @param[in] ip_address The IP address on which the port is being used + * @param[in] port The port number + * @param[in] proto The IANA protocol number + * @return 0 on success, otherwise a negative error value + * @retval #ASP_ERROR_NONE Successful + * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted + * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory + * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied + * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ASP_ERROR_NOT_SUPPORTED Not supported + * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized + * @retval #ASP_ERROR_OPERATION_FAILED Operation failed + * @retval #ASP_ERROR_SESSION_NOT_FOUND Session not found + * @see asp_session_create() + * @see asp_session_request_cb() + */ +int asp_session_release_port(asp_session_h session, char *ip_address, + int port, int proto); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_NET_ASP_H__ */ + diff --git a/packaging/capi-network-asp.spec b/packaging/capi-network-asp.spec new file mode 100755 index 0000000..bd20e08 --- /dev/null +++ b/packaging/capi-network-asp.spec @@ -0,0 +1,97 @@ +%define file_transfer_test yes + +Name: capi-network-asp +Summary: An Application Service Platform(ASP) libraries in Native API +Version: 0.0.9 +Release: 1 +Group: Network & Connectivity/API +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz + +BuildRequires: cmake +BuildRequires: pkgconfig(gobject-2.0) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-info) +%if "%{file_transfer_test}" == "yes" +BuildRequires: pkgconfig(libtzplatform-config) +BuildRequires: pkgconfig(libxml-2.0) +BuildRequires: pkgconfig(libsoup-2.4) +BuildRequires: pkgconfig(gssdp-1.0) +BuildRequires: pkgconfig(gupnp-1.0) +%endif + +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description +Application Service Platform(ASP) library in Tizen C API + +%package devel +Summary: An Application Service Platform(ASP) in Native API (Development) +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} +Requires: capi-base-common-devel + +%description devel +An Application Service Platform(ASP) library in Tizen CAPI (Shared Library) (Development) + +%package test +Summary: ASP - ASP test binaries + +%description test +Test Application for Application Service Platform(ASP) + +%prep +%setup -q +chmod 644 %{SOURCE0} + +%ifarch %{arm} +export ARCH=arm +%else +export ARCH=i586 +%endif + +%build +%if 0%{?sec_build_binary_debug_enable} +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" +%endif + + +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +%cmake . \ +%if "%{file_transfer_test}" == "yes" + -DTZ_SYS_RO_ETC=%{TZ_SYS_RO_ETC} \ + -DFILE_TRANSFER_TEST=1 \ +%endif + -DCMAKE_BUILD_TYPE=%{?build_type} \ + -DCMAKE_VERBOSE_MAKEFILE=ON \ + -DLIB_DIR:PATH=%{_libdir} \ + -DBIN_DIR:PATH=%{_bindir} \ + -DINCLUDE_DIR:PATH=%{_includedir} \ + -DLOCAL_STATE_DIR:PATH=%{_localstatedir} \ + -DDATA_ROOT_DIR:PATH=%{_datadir} \ + -DFULLVER=%{version} \ + -DMAJORVER=${MAJORVER} +make %{?jobs:-j%jobs} + +%install +rm -rf %{buildroot} +%make_install + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%manifest capi-network-asp.manifest +%license LICENSE +%defattr(-,root,root,-) + +%files devel +%defattr(-,root,root,-) +%{_includedir}/asp/*.h -- 2.7.4 From 117a7450e954258a4ce6aae8655f6e3f8e997515 Mon Sep 17 00:00:00 2001 From: Jiung Yu Date: Wed, 19 Apr 2017 14:46:35 +0900 Subject: [PATCH 3/4] Add set/get values implementation and test file for that Change-Id: I72d414213066d1b533b3cea1cec372ed237a302b Signed-off-by: Yu jiung --- CMakeLists.txt | 3 + asp-test.manifest | 5 + packaging/capi-network-asp.spec | 9 +- pkgconfig/CMakeLists.txt | 24 + pkgconfig/asp.pc.in | 11 + src/CMakeLists.txt | 45 + src/asp-client.c | 3260 +++++++++++++++++++++++++++++++++++++++ src/asp-dbus.c | 193 +++ src/include/asp-client.h | 140 ++ src/include/asp-dbus.h | 78 + src/include/asp-log.h | 66 + src/include/asp-util.h | 67 + test/CMakeLists.txt | 40 + test/asp-test.c | 1828 ++++++++++++++++++++++ 14 files changed, 5768 insertions(+), 1 deletion(-) create mode 100755 asp-test.manifest create mode 100755 pkgconfig/CMakeLists.txt create mode 100755 pkgconfig/asp.pc.in create mode 100755 src/CMakeLists.txt create mode 100644 src/asp-client.c create mode 100644 src/asp-dbus.c create mode 100755 src/include/asp-client.h create mode 100755 src/include/asp-dbus.h create mode 100755 src/include/asp-log.h create mode 100755 src/include/asp-util.h create mode 100755 test/CMakeLists.txt create mode 100644 test/asp-test.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 84e7537..65b33ec 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,3 +55,6 @@ SET(TARGET_ASP_TEST "asp-test") ADD_SUBDIRECTORY(include) +ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(pkgconfig) +ADD_SUBDIRECTORY(test) diff --git a/asp-test.manifest b/asp-test.manifest new file mode 100755 index 0000000..50eefc9 --- /dev/null +++ b/asp-test.manifest @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/packaging/capi-network-asp.spec b/packaging/capi-network-asp.spec index bd20e08..f2aeec7 100755 --- a/packaging/capi-network-asp.spec +++ b/packaging/capi-network-asp.spec @@ -1,4 +1,4 @@ -%define file_transfer_test yes +%define file_transfer_test no Name: capi-network-asp Summary: An Application Service Platform(ASP) libraries in Native API @@ -91,7 +91,14 @@ rm -rf %{buildroot} %manifest capi-network-asp.manifest %license LICENSE %defattr(-,root,root,-) +%{_libdir}/*.so* %files devel %defattr(-,root,root,-) +%{_libdir}/pkgconfig/*.pc %{_includedir}/asp/*.h +%{_libdir}/*.so + +%files test +%manifest asp-test.manifest +%attr(755,root,root) %{_bindir}/asp-test diff --git a/pkgconfig/CMakeLists.txt b/pkgconfig/CMakeLists.txt new file mode 100755 index 0000000..d41df87 --- /dev/null +++ b/pkgconfig/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# + +CONFIGURE_FILE(asp.pc.in asp.pc @ONLY) + +INSTALL(FILES + ${CMAKE_BINARY_DIR}/pkgconfig/asp.pc + DESTINATION + ${LIB_DIR}/pkgconfig + ) diff --git a/pkgconfig/asp.pc.in b/pkgconfig/asp.pc.in new file mode 100755 index 0000000..f643d4e --- /dev/null +++ b/pkgconfig/asp.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +libdir=@LIB_DIR@ +includedir=${prefix}/include + +Name: asp +Description: asp package +Version: @VERSION@ +Requires: capi-base-common +Libs: -L${libdir} -lasp +Cflags: -I${includedir}/asp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100755 index 0000000..50b66b2 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,45 @@ +# Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# @file CMakeLists.txt +# +SET(ASP_PATH ${PROJECT_SOURCE_DIR}/src) + +INCLUDE_DIRECTORIES( + ${CMAKE_SOURCE_DIR}/include + ${ASP_PATH}/include + ) + +SET(ASP_SOURCES + ${ASP_PATH}/asp-client.c + ${ASP_PATH}/asp-dbus.c + ) + +ADD_DEFINITIONS("-fvisibility=default") + +ADD_LIBRARY(${TARGET_ASP} SHARED ${ASP_SOURCES}) + +SET_TARGET_PROPERTIES( + ${TARGET_ASP} + PROPERTIES + SOVERSION ${MAJORVER} + VERSION ${FULLVER} + ) + +TARGET_LINK_LIBRARIES(${TARGET_ASP} + ${ASP_DEPS_LIBRARIES} + dl + ) + +INSTALL(TARGETS ${TARGET_ASP} DESTINATION ${LIB_DIR}) diff --git a/src/asp-client.c b/src/asp-client.c new file mode 100644 index 0000000..135b5dd --- /dev/null +++ b/src/asp-client.c @@ -0,0 +1,3260 @@ +/* + * Application Service Platform(ASP) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file implements Application Service Platform(ASP) user library. + * + * @file asp-client.c + * @author Jiung Yu (jiung.yu@samsung.com) + * @version 0.1 + */ + + +/***************************************************************************** + * Standard headers + *****************************************************************************/ +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +/***************************************************************************** + * System headers + *****************************************************************************/ +#include + +/***************************************************************************** + * Application Service Platform(ASP) library headers + *****************************************************************************/ +#include "asp.h" + +#include "asp-client.h" +#include "asp-dbus.h" +#include "asp-log.h" +#include "asp-util.h" + +/***************************************************************************** + * Macros and Typedefs + *****************************************************************************/ + +/***************************************************************************** + * Global Variables + *****************************************************************************/ +static __thread asp_client_info_s g_client_info = { + .is_registered = FALSE, + + .seek_search_result_cb = NULL, + .advert_status_changed_cb = NULL, + .session_request_cb = NULL, + .session_config_request_cb = NULL, + .session_connect_status_cb = NULL, + .session_status_cb = NULL, + .session_port_status_cb = NULL, + + .user_data_for_cb_seek_search_result = NULL, + .user_data_for_cb_advert_status_changed = NULL, + .user_data_for_cb_session_request = NULL, + .user_data_for_cb_session_config_request = NULL, + .user_data_for_cb_session_connect_status = NULL, + .user_data_for_cb_session_status = NULL, + .user_data_for_cb_session_port_status = NULL +}; + +static __thread GList *asp_adverts = NULL; +static __thread GList *asp_seeks = NULL; +static __thread GList *asp_sessions = NULL; + +/***************************************************************************** + * Local Functions Definition + *****************************************************************************/ + +static int _txt_to_mac(char *txt, unsigned char *mac) +{ + int i = 0; + + for (;;) { + mac[i++] = (char)strtoul(txt, &txt, 16); + if (i == MACADDR_LEN || !*txt++) + break; + } + + if (i != MACADDR_LEN) + return -1; + + ASP_LOGD("Converted MAC address [" MACSECSTR "]", + MAC2SECSTR(mac)); + return 0; +} + +static int __asp_err_string_to_enum(const char *error) +{ + if (NULL != strstr(error, "NoReply")) + return ASP_ERROR_COMMUNICATION_FAILED; + else if (NULL != strstr(error, "PermissionDenied")) + return ASP_ERROR_PERMISSION_DENIED; + else if (NULL != strstr(error, "MEM_ERR")) + return ASP_ERROR_OUT_OF_MEMORY; + else if (NULL != strstr(error, "INVALID_PARAM")) + return ASP_ERROR_INVALID_PARAMETER; + else if (NULL != strstr(error, "OPER_FAILED")) + return ASP_ERROR_OPERATION_FAILED; + else if (NULL != strstr(error, "NO_SERVICE")) + return ASP_ERROR_SERVICE_NOT_FOUND; + else if (NULL != strstr(error, "NO_SESSION")) + return ASP_ERROR_SESSION_NOT_FOUND; + else + return ASP_ERROR_OPERATION_FAILED; +} + +static char* __asp_create_service_info_from_g_variant(GVariant *variant) +{ + GVariantIter *iter = NULL; + GVariant* var = NULL; + gchar *key = NULL; + gchar *value = NULL; + gchar *info = NULL; + int offset = 0; + int len = 0; + gsize value_len = 0; + + info = (gchar*)g_try_malloc0(ASP_SERVICE_INFO_MAX_LEN + 1); + if (!info) + return NULL; + + g_variant_get(variant, "a{sv}", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + value = g_variant_dup_string(var, &value_len); + len = strlen(key) + value_len + 2; + snprintf(info + offset, len + 1, "%s=%s,", key, value); + offset += len; + g_free(value); + } + + return info; +} + +void asp_process_seek_search_result(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters) +{ + __ASP_LOG_FUNC_START__; + + asp_client_info_s *client = &g_client_info; + + GVariantIter *iter = NULL; + GVariant *var = NULL; + const char *key = NULL; + const char *str = NULL; + unsigned int search_id = 0; + const char *service_mac = NULL; + unsigned int advertisement_id = 0; + unsigned int config_method = 0; + char *instance_name = NULL; + char *service_info = NULL; + unsigned char status = 0; + int error_code = ASP_ERROR_NONE; + + if (!client->seek_search_result_cb) { + ASP_LOGE("search_result_cb is NULL!!"); + return; + } + + if (!parameters) { + __ASP_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(a{sv})", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "search_id")) { + g_variant_get(var, "u", &search_id); + } else if (!g_strcmp0(key, "service_mac")) { + g_variant_get(var, "&s", &str); + service_mac = g_strndup(str, MACSTR_LEN); + } else if (!g_strcmp0(key, "adv_id")) { + g_variant_get(var, "u", &advertisement_id); + } else if (!g_strcmp0(key, "config_method")) { + g_variant_get(var, "u", &config_method); + } else if (!g_strcmp0(key, "instance_name")) { + g_variant_get(var, "&s", &str); + instance_name = g_strdup(str); + } else if (!g_strcmp0(key, "service_info")) { + service_info = __asp_create_service_info_from_g_variant(var); + ASP_LOGD("Service Info: %s", service_info); + } else if (!g_strcmp0(key, "service_status")) { + g_variant_get(var, "y", &status); + } else { + ;/* Do Nothing */ + } + } + + //TODO :client->search_result_cb + g_variant_iter_free(iter); + + __ASP_LOG_FUNC_END__; + return; +} + +void asp_process_advert_status_changed(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters) +{ + __ASP_LOG_FUNC_START__; + + asp_client_info_s *client = &g_client_info; + unsigned int advertisement_id = 0; + unsigned char status = 0; + int reason = 0; + + if (!client->advert_status_changed_cb) { + ASP_LOGE("search_result_cb is NULL!!"); + return; + } + + if (!parameters) { + __ASP_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(uyi)", &advertisement_id, &status, &reason); + + //TODO :client->advert_status_changed_cb + + __ASP_LOG_FUNC_END__; + return; +} + +int __handle_session_request(unsigned int adv_id, char *session_mac, + unsigned int session_id, char *session_info) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + asp_client_session_s *session = NULL; + GList *temp = NULL; + int res = 0; + + for (temp = g_list_first(asp_adverts); + temp != NULL; temp = g_list_next(temp)) { + service = temp->data; + if (service != NULL && service->adv_id == adv_id) + break; + service = NULL; + } + + if (service == NULL) { + ASP_LOGD("No matched local service"); + __ASP_LOG_FUNC_END__; + return -1; + } + + if (service->auto_accept == FALSE) { + ASP_LOGD("Don't accept request automatically"); + __ASP_LOG_FUNC_END__; + return 0; + + } + + ASP_LOGD("Process auto accept service"); + + temp = NULL; + for (temp = g_list_first(asp_sessions); + temp != NULL; temp = g_list_next(temp)) { + session = temp->data; + if (session != NULL && session->session_id == session_id && + memcmp(session->session_mac, session_mac, MACSTR_LEN) == 0) + break; + session = NULL; + } + + if (session == NULL) { + //TODO :asp_get_session + //res = asp_get_session(session_mac, session_id, (void **)&session); + if (res < 0) { + ASP_LOGE("asp_get_session failed"); + __ASP_LOG_FUNC_END__; + return -1; + } + + if (session_info) + session->session_information = g_strdup(session_info); + asp_sessions = g_list_prepend(asp_sessions, session); + } + + //TODO :asp_confirm_session + //asp_confirm_session(session, TRUE, NULL); + ASP_LOGD("asp_confirm_session"); + __ASP_LOG_FUNC_END__; + return -1; +} + +void asp_process_session_request(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters) +{ + __ASP_LOG_FUNC_START__; + + asp_client_info_s *client = &g_client_info; + + GVariantIter *iter = NULL; + GVariant *var = NULL; + const char *key = NULL; + const char *str = NULL; + unsigned int adv_id = 0; + char *session_mac = NULL; + char * device_name = NULL; + unsigned int session_id = 0; + char *session_info = NULL; + gboolean get_network_config_pin = FALSE; + char *network_config_pin = NULL; + int error_code = ASP_ERROR_NONE; + + if (!client->session_request_cb) { + ASP_LOGE("session_request_cb is NULL!!"); + return; + } + + if (!parameters) { + ASP_LOGE("parameters is NULL!!"); + __ASP_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(a{sv})", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "adv_id")) { + g_variant_get(var, "u", &adv_id); + } else if (!g_strcmp0(key, "session_id")) { + g_variant_get(var, "u", &session_id); + } else if (!g_strcmp0(key, "session_mac")) { + g_variant_get(var, "&s", &str); + session_mac = g_strndup(str, MACSTR_LEN); + } else if (!g_strcmp0(key, "device_name")) { + g_variant_get(var, "&s", &str); + device_name = g_strdup(str); + } else if (!g_strcmp0(key, "session_info")) { + g_variant_get(var, "&s", &str); + session_info = g_strdup(str); + } else if (!g_strcmp0(key, "get_pin")) { + g_variant_get(var, "b", &get_network_config_pin); + } else if (!g_strcmp0(key, "pin")) { + g_variant_get(var, "&s", &str); + network_config_pin = g_strdup(str); + } else { + ;/* Do Nothing */ + } + } + + if (__handle_session_request(adv_id, session_mac, + session_id, session_info) == 0) { + //TODO :client->session_request_cb + } else { + g_free(session_mac); + g_free(session_info); + g_free(device_name); + g_free(network_config_pin); + } + g_variant_iter_free(iter); + + __ASP_LOG_FUNC_END__; + return; +} + +void asp_process_session_config_request(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters) +{ + __ASP_LOG_FUNC_START__; + + asp_client_info_s *client = &g_client_info; + + GVariantIter *iter = NULL; + GVariant *var = NULL; + const char *key = NULL; + const char *str = NULL; + unsigned int session_id = 0; + gboolean get_pin = false; + const char *config_pin = NULL; + int error_code = ASP_ERROR_NONE; + + if (!client->session_config_request_cb) { + ASP_LOGE("session_config_request_cb is NULL!!"); + return; + } + + if (!parameters) { + __ASP_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(a{sv})", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "session_id")) { + g_variant_get(var, "u", &session_id); + } else if (!g_strcmp0(key, "get_pin")) { + g_variant_get(var, "b", &get_pin); + } else if (!g_strcmp0(key, "pin")) { + g_variant_get(var, "&s", &str); + config_pin = g_strdup(str); + } else { + ;/* Do Nothing */ + } + } + + //TODO :client->session_config_request_cb + g_variant_iter_free(iter); + + __ASP_LOG_FUNC_END__; + return; +} + +void asp_process_session_connect_status(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters) +{ + __ASP_LOG_FUNC_START__; + + asp_client_info_s *client = &g_client_info; + + GVariantIter *iter = NULL; + GVariant *var = NULL; + const char *key = NULL; + const char *str = NULL; + const char *session_mac = NULL; + unsigned int session_id = 0; + int status = 0; + char *deferred_resp = NULL; + int error_code = ASP_ERROR_NONE; + + if (!client->session_connect_status_cb) { + ASP_LOGE("connect_status_cb is NULL!!"); + return; + } + + if (!parameters) { + __ASP_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(a{sv})", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "session_id")) { + g_variant_get(var, "u", &session_id); + } else if (!g_strcmp0(key, "session_mac")) { + g_variant_get(var, "&s", &str); + session_mac = g_strndup(str, MACSTR_LEN); + } else if (!g_strcmp0(key, "status")) { + g_variant_get(var, "i", &status); + } else if (!g_strcmp0(key, "deferred_resp")) { + g_variant_get(var, "&s", &str); + deferred_resp = g_strdup(str); + } else { + ;/* Do Nothing */ + } + } + + //TODO :client->session_connect_status_cb + g_variant_iter_free(iter); + + __ASP_LOG_FUNC_END__; + return; +} + +void asp_process_session_status(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters) +{ + __ASP_LOG_FUNC_START__; + + asp_client_info_s *client = &g_client_info; + + GVariantIter *iter = NULL; + GVariant *var = NULL; + const char *key = NULL; + const char *str = NULL; + const char *session_mac = NULL; + unsigned int session_id = 0; + int state = 0; + int status = 0; + char *requested_info = NULL; + int error_code = ASP_ERROR_NONE; + + if (!client->session_status_cb) { + ASP_LOGE("session_status_cb is NULL!!"); + return; + } + + if (!parameters) { + __ASP_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(a{sv})", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "session_id")) { + g_variant_get(var, "u", &session_id); + } else if (!g_strcmp0(key, "session_mac")) { + g_variant_get(var, "&s", &str); + session_mac = g_strndup(str, MACSTR_LEN); + } else if (!g_strcmp0(key, "state")) { + g_variant_get(var, "i", &state); + } else if (!g_strcmp0(key, "status")) { + g_variant_get(var, "i", &status); + } else if (!g_strcmp0(key, "requested_info")) { + g_variant_get(var, "&s", &str); + requested_info = g_strdup(str); + } else { + ;/* Do Nothing */ + } + } + + //TODO :client->session_status_cb + + __ASP_LOG_FUNC_END__; + return; +} + +void asp_process_session_port_status(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters) +{ + __ASP_LOG_FUNC_START__; + + asp_client_info_s *client = &g_client_info; + + GVariantIter *iter = NULL; + GVariant *var = NULL; + const char *key = NULL; + const char *str = NULL; + const char *session_mac = NULL; + const char *ip_address = NULL; + unsigned int session_id = 0; + int port = 0; + int proto = 0; + int status = 0; + int error_code = ASP_ERROR_NONE; + + if (!client->session_port_status_cb) { + ASP_LOGE("port_status_cb is NULL!!"); + return; + } + + if (!parameters) { + __ASP_LOG_FUNC_END__; + return; + } + + g_variant_get(parameters, "(a{sv})", &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "session_id")) { + g_variant_get(var, "u", &session_id); + } else if (!g_strcmp0(key, "session_mac")) { + g_variant_get(var, "&s", &str); + session_mac = g_strndup(str, MACSTR_LEN); + } else if (!g_strcmp0(key, "ip_address")) { + g_variant_get(var, "&s", &ip_address); + } else if (!g_strcmp0(key, "port")) { + g_variant_get(var, "i", &port); + } else if (!g_strcmp0(key, "proto")) { + g_variant_get(var, "i", &proto); + } else if (!g_strcmp0(key, "status")) { + g_variant_get(var, "i", &status); + } else { + ;/* Do Nothing */ + } + } + + //TODO :client->session_port_status_cb + + __ASP_LOG_FUNC_END__; + return; +} + +int asp_initialize(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == TRUE) { + ASP_LOGW("Warning!!! Already registered\nUpdate user data and callback!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_ALREADY_INITIALIZED; + } + + if (asp_dbus_init() == FALSE) { + ASP_LOGW("Failed to initialize dbus"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } + + g_client_info.is_registered = TRUE; + + /* Initialize callbacks */ + g_client_info.seek_search_result_cb = NULL; + g_client_info.advert_status_changed_cb = NULL; + + g_client_info.session_request_cb = NULL; + g_client_info.session_config_request_cb = NULL; + g_client_info.session_connect_status_cb = NULL; + g_client_info.session_status_cb = NULL; + g_client_info.session_port_status_cb = NULL; + + g_client_info.user_data_for_cb_seek_search_result = NULL; + g_client_info.user_data_for_cb_advert_status_changed = NULL; + + g_client_info.user_data_for_cb_session_request = NULL; + g_client_info.user_data_for_cb_session_config_request = NULL; + g_client_info.user_data_for_cb_session_connect_status = NULL; + g_client_info.user_data_for_cb_session_status = NULL; + g_client_info.user_data_for_cb_session_port_status = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_deinitialize(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is already deregistered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + asp_dbus_deinit(); + + g_client_info.seek_search_result_cb = NULL; + g_client_info.advert_status_changed_cb = NULL; + + g_client_info.session_request_cb = NULL; + g_client_info.session_config_request_cb = NULL; + g_client_info.session_connect_status_cb = NULL; + g_client_info.session_status_cb = NULL; + g_client_info.session_port_status_cb = NULL; + + g_client_info.user_data_for_cb_seek_search_result = NULL; + g_client_info.user_data_for_cb_advert_status_changed = NULL; + + g_client_info.user_data_for_cb_session_request = NULL; + g_client_info.user_data_for_cb_session_config_request = NULL; + g_client_info.user_data_for_cb_session_connect_status = NULL; + g_client_info.user_data_for_cb_session_status = NULL; + g_client_info.user_data_for_cb_session_port_status = NULL; + + g_client_info.is_registered = FALSE; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} +int asp_seek_set_search_result_cb(asp_seek_search_result_cb cb, void *user_data) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (!cb) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.seek_search_result_cb = cb; + g_client_info.user_data_for_cb_seek_search_result = user_data; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_seek_unset_search_result_cb(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized.\n"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.seek_search_result_cb = NULL; + g_client_info.user_data_for_cb_seek_search_result = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_set_status_changed_cb(asp_advert_status_changed_cb cb, void *user_data) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (!cb) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.advert_status_changed_cb = cb; + g_client_info.user_data_for_cb_advert_status_changed = user_data; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_unset_status_changed_cb(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized.\n"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.advert_status_changed_cb = NULL; + g_client_info.user_data_for_cb_advert_status_changed = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_set_request_cb(asp_session_request_cb cb, void *user_data) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (!cb) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_request_cb = cb; + g_client_info.user_data_for_cb_session_request = user_data; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_unset_request_cb(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized.\n"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_request_cb = NULL; + g_client_info.user_data_for_cb_session_request = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_set_config_request_cb(asp_session_config_request_cb cb, void *user_data) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (!cb) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_config_request_cb = cb; + g_client_info.user_data_for_cb_session_config_request = user_data; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_unset_config_request_cb(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized.\n"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_config_request_cb = NULL; + g_client_info.user_data_for_cb_session_config_request = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_set_connect_status_cb(asp_session_connect_status_cb cb, void *user_data) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (!cb) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_connect_status_cb = cb; + g_client_info.user_data_for_cb_session_connect_status = user_data; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +int asp_session_unset_connect_status_cb(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized.\n"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_connect_status_cb = NULL; + g_client_info.user_data_for_cb_session_connect_status = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_set_status_cb(asp_session_status_cb cb, void *user_data) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (!cb) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_status_cb = cb; + g_client_info.user_data_for_cb_session_status = user_data; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +int asp_session_unset_status_cb(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized.\n"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_status_cb = NULL; + g_client_info.user_data_for_cb_session_status = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_set_port_status_cb(asp_session_port_status_cb cb, void *user_data) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (!cb) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_port_status_cb = cb; + g_client_info.user_data_for_cb_session_port_status = user_data; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_session_unset_port_status_cb(void) +{ + __ASP_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is not initialized.\n"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + g_client_info.session_port_status_cb = NULL; + g_client_info.user_data_for_cb_session_port_status = NULL; + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +typedef void (*free_func)(void *); + +static void __free_advert(void *advert) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + service = (asp_client_advert_s *)advert; + if (service == NULL) { + ASP_LOGE("invalid parameter"); + __ASP_LOG_FUNC_END__; + return; + } + + g_free(service->instance_name); + g_free(service->serivce_name); + g_free(service->service_type); + g_free(service->rsp_info); + g_hash_table_destroy(service->service_info_map); + g_free(service); + service = NULL; + __ASP_LOG_FUNC_END__; + return; +} + +static void __free_seek(void *seek) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + + service = (asp_client_seek_s *)seek; + if (service == NULL) { + ASP_LOGE("invalid parameter"); + __ASP_LOG_FUNC_END__; + return; + } + + g_free(service->serivce_name); + g_free(service->service_type); + g_free(service->rsp_info); + g_hash_table_destroy(service->service_info_map); + g_free(service); + service = NULL; + __ASP_LOG_FUNC_END__; + return; +} + +static void __free_session(void *session) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + + service = (asp_client_session_s *)session; + if (service == NULL) { + ASP_LOGE("invalid parameter"); + __ASP_LOG_FUNC_END__; + return; + } + + g_free(service->session_information); + g_free(service->deferred_session_response); + g_free(service); + service = NULL; + __ASP_LOG_FUNC_END__; + return; +} + +static asp_client_advert_s *__get_advert(void *handle) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + GList *temp = NULL; + + if (asp_adverts == NULL) { + __ASP_LOG_FUNC_END__; + return NULL; + } + + ASP_LOGD("service [%p]", handle); + + temp = g_list_first(asp_adverts); + for (temp = g_list_first(asp_adverts); temp != NULL; temp = g_list_next(temp)) { + service = temp->data; + + ASP_LOGD("temp [%p]", service); + if (service != NULL && service == handle) + break; + service = NULL; + } + __ASP_LOG_FUNC_END__; + return service; +} + +static asp_client_seek_s *__get_seek(void *handle) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + GList *temp = NULL; + + if (asp_seeks == NULL) { + __ASP_LOG_FUNC_END__; + return NULL; + } + + ASP_LOGD("service [%p]", handle); + + temp = g_list_first(asp_seeks); + for (temp = g_list_first(asp_seeks); temp != NULL; temp = g_list_next(temp)) { + service = temp->data; + + ASP_LOGD("temp [%p]", service); + if (service != NULL && service == handle) + break; + service = NULL; + } + __ASP_LOG_FUNC_END__; + return service; +} + +static asp_client_session_s *__get_session(void *handle) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + GList *temp = NULL; + + if (asp_sessions == NULL) { + + __ASP_LOG_FUNC_END__; + return NULL; + } + + ASP_LOGD("service [%p]", handle); + + temp = g_list_first(asp_sessions); + for (temp = g_list_first(asp_sessions); temp != NULL; temp = g_list_next(temp)) { + service = temp->data; + + ASP_LOGD("temp [%p]", service); + if (service != NULL && service == handle) + break; + service = NULL; + } + __ASP_LOG_FUNC_END__; + return service; +} + +static int __remove_advert(void *handle) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + service = __get_advert(handle); + + if (service == NULL) { + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } else { + asp_adverts = g_list_remove(asp_adverts, handle); + __free_advert(service); + } + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +static int __remove_seek(void *handle) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + service = __get_seek(handle); + + if (service == NULL) { + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } else { + asp_seeks = g_list_remove(asp_seeks, handle); + __free_seek(service); + } + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +static int __remove_session(void *handle) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + service = __get_session(handle); + + if (service == NULL) { + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } else { + asp_sessions = g_list_remove(asp_sessions, handle); + __free_session(service); + } + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL Param [handle]!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = (asp_client_advert_s *)g_try_malloc0(sizeof(asp_client_advert_s)); + if (!service) { + ASP_LOGE("malloc() failed!!!."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OUT_OF_MEMORY; + } + ASP_LOGD("service [%p]", service); + + if (instance_name) { + ASP_LOGD("instance_name = [%s]", instance_name); + service->instance_name = g_strdup(instance_name); + if (!service->instance_name) { + ASP_LOGE("malloc() failed!!!."); + __ASP_LOG_FUNC_END__; + g_free(service); + return ASP_ERROR_OUT_OF_MEMORY; + } + } + asp_adverts = g_list_prepend(asp_adverts, service); + + /* TODO : consider the case if target arch is 64bit. */ + /* TODO : Make asp enable support for other methods. */ + /* Default : ASP */ + service->auto_accept = 0; + service->config_method = 1; + service->status = 0; + service->role = 1; + service->service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + service->adv_id = (unsigned int)service & 0xffffffff; + *adv_service = (asp_advert_service_h)service; + ASP_LOGD("asp_advert_create() SUCCESS"); + + ASP_LOGD("advert handler [%p]", *adv_service); + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_advert_destroy(asp_advert_service_h adv_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + g_hash_table_remove_all(service->service_info_map); + res = __remove_advert((void *)service); + if (res != ASP_ERROR_NONE) { + __ASP_LOG_FUNC_END__; + return res; + } + + ASP_LOGD("asp_destory_advertise_handle() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +int asp_advert_set_service_type(asp_advert_service_h adv_service, + char *service_type) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + char *type = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service || !service_type) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + type = g_strdup(service_type); + if (!type) { + ASP_LOGE("malloc() failed!!!."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } + g_free(service->service_type); + service->service_type = type; + + ASP_LOGD("asp_advert_set_service_type() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_set_auto_accept(asp_advert_service_h adv_service, + bool auto_accept) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->auto_accept = auto_accept; + + ASP_LOGD("asp_advert_set_auto_accept() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_add_info(asp_advert_service_h adv_service, + const char *key, const char *value) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service || !key) { + ASP_LOGE("NULL value!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + /* TODO: add advertised info */ + g_hash_table_replace(service->service_info_map, g_strdup(key), g_strdup(value)); + + ASP_LOGD("asp_advert_add_info() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_get_info(asp_advert_service_h adv_service, const char *key, + int *length, char **value) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + char *ret_val = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service || !key) { + ASP_LOGE("NULL value!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + /* TODO: get advertised info */ + ret_val = g_hash_table_lookup(service->service_info_map, key); + if (ret_val == NULL) { + ASP_LOGD("value is NULL"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; + } + + *value = g_strdup(ret_val); + *length = strlen(ret_val); + + ASP_LOGD("asp_advert_get_info() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_remove_info(asp_advert_service_h adv_service, const char *key) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service || !key) { + ASP_LOGE("NULL value!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + /* TODO: remove advertised info */ + g_hash_table_remove(service->service_info_map, key); + + ASP_LOGD("asp_advert_remove_info() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_set_status(asp_advert_service_h adv_service, + unsigned char status) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->status = status; + + ASP_LOGD("asp_advert_set_status() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_set_discovery_tech(asp_advert_service_h adv_service, int discovery_tech) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + if (!((discovery_tech & ASP_DISCOVERY_TECH_P2P) | + (discovery_tech & ASP_DISCOVERY_TECH_NFC) | + (discovery_tech & ASP_DISCOVERY_TECH_BLE) | + (discovery_tech & ASP_DISCOVERY_TECH_INFRA) | + (discovery_tech & ASP_DISCOVERY_TECH_NAN))) { + ASP_LOGE("invalid parameter!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->discovery_tech = discovery_tech; + + ASP_LOGD("asp_advert_set_discovery_tech() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_set_preferred_connection(asp_advert_service_h adv_service, + unsigned char preferred_connection) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->preferred_connection = preferred_connection; + + ASP_LOGD("asp_advert_set_preferred_connection() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_set_p2p_role_scheme(asp_advert_service_h adv_service, + asp_advert_p2p_role_scheme_e role) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->role = role; + + ASP_LOGD("asp_advert_set_p2p_role_scheme() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_get_p2p_role_scheme(asp_advert_service_h adv_service, + asp_advert_p2p_role_scheme_e *role) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service || !role) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + *role = service->role; + + ASP_LOGD("asp_advert_get_p2p_role_scheme() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +int asp_advert_set_p2p_config_method(asp_advert_service_h adv_service, + asp_wps_type_e config_method) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (config_method > ASP_WPS_TYPE_PIN_KEYPAD) { + ASP_LOGE("config_method is larger than expected"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->config_method = config_method; + + ASP_LOGD("asp_advert_set_p2p_config_method() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_get_p2p_config_method(asp_advert_service_h adv_service, + asp_wps_type_e *config_method) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service || !config_method) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + *config_method = service->config_method; + + ASP_LOGD("asp_advert_get_p2p_config_method() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_advert_set_p2p_response(asp_advert_service_h adv_service, + char *rsp_info, int length) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + char *info = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + /* TODO fit the rsp info for length */ + if (length <= 0 || length > 144) { + ASP_LOGE("invalid length!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (!adv_service || !rsp_info) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + info = g_strdup(rsp_info); + if (!info) { + ASP_LOGE("malloc() failed!!!."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } + g_free(service->rsp_info); + service->rsp_info = info; + + ASP_LOGD("asp_advert_set_p2p_response() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +static GVariant* __g_hash_keys_to_g_variant(GHashTable *hash) +{ + GVariantBuilder builder; + + __ASP_LOG_FUNC_START__; + g_variant_builder_init(&builder, G_VARIANT_TYPE("as")); +/* g_variant_builder_open(&builder, G_VARIANT_TYPE("a{sv}")); */ + + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init(&iter, hash); + while (g_hash_table_iter_next(&iter, &key, &value)) { + + ASP_LOGE("key [%s]", key); + g_variant_builder_add(&builder, "s", key); + } + +/* g_variant_builder_close(&builder); */ + __ASP_LOG_FUNC_END__; + return g_variant_builder_end(&builder); +} + +static GVariant* __g_hash_table_to_g_variant(GHashTable *hash) +{ + GVariantBuilder builder; + + __ASP_LOG_FUNC_START__; + g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}")); + + GHashTableIter iter; + gpointer key, value; + + g_hash_table_iter_init(&iter, hash); + while (g_hash_table_iter_next(&iter, &key, &value)) + g_variant_builder_add(&builder, "{sv}", key, g_variant_new_string(value)); + + __ASP_LOG_FUNC_END__; + return g_variant_builder_end(&builder); +} + +int asp_advert_start_advertising(asp_advert_service_h adv_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "adv_id", g_variant_new("u", service->adv_id)); + g_variant_builder_add(builder, "{sv}", "discovery_tech", g_variant_new("i", service->discovery_tech)); + g_variant_builder_add(builder, "{sv}", "preferred_connection", g_variant_new("y", service->preferred_connection)); + g_variant_builder_add(builder, "{sv}", "auto_accept", g_variant_new("i", service->auto_accept)); + g_variant_builder_add(builder, "{sv}", "status", g_variant_new("y", service->status)); + g_variant_builder_add(builder, "{sv}", "role", g_variant_new("y", service->role)); + g_variant_builder_add(builder, "{sv}", "config_method", g_variant_new("u", service->config_method)); + + if (service->instance_name) /* This can be NULL if this is ASP 1.0 service */ + g_variant_builder_add(builder, "{sv}", "instance_name", g_variant_new("s", service->instance_name)); + if (service->service_type) /* This can be NULL if Instance name is UUID */ + g_variant_builder_add(builder, "{sv}", "service_type", g_variant_new("s", service->service_type)); + if (g_hash_table_size(service->service_info_map) > 0) + g_variant_builder_add(builder, "{sv}", "service_info", __g_hash_table_to_g_variant(service->service_info_map)); + if (service->rsp_info) + g_variant_builder_add(builder, "{sv}", "rsp_info", g_variant_new("s", service->rsp_info)); + params = g_variant_new("(a{sv})", builder); + g_variant_builder_unref(builder); + ASP_LOGI("service type (%s) adv ID (%u)", service->service_type, service->adv_id); + + reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE, + "AdvertiseService", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_advert_stop_advertising(asp_advert_service_h adv_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + params = g_variant_new("(ui)", service->adv_id, service->discovery_tech); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE, + "CancelAdvertiseService", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_advert_change_service_status(asp_advert_service_h adv_service, + unsigned char status) +{ + __ASP_LOG_FUNC_START__; + asp_client_advert_s *service = NULL; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!adv_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", adv_service); + + service = __get_advert((void *)adv_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "adv_id", g_variant_new("u", service->adv_id)); + g_variant_builder_add(builder, "{sv}", "auto_accept", g_variant_new("i", service->auto_accept)); + service->status = status; + g_variant_builder_add(builder, "{sv}", "status", g_variant_new("y", service->status)); + g_variant_builder_add(builder, "{sv}", "role", g_variant_new("y", service->role)); + g_variant_builder_add(builder, "{sv}", "config_method", g_variant_new("u", service->config_method)); + + if (service->instance_name) /* This can be NULL if this is ASP 1.0 service */ + g_variant_builder_add(builder, "{sv}", "instance_name", g_variant_new("s", service->instance_name)); + if (service->service_type) /* This can be NULL if Instance name is UUID */ + g_variant_builder_add(builder, "{sv}", "service_type", g_variant_new("s", service->service_type)); + if (g_hash_table_size(service->service_info_map) > 0) + g_variant_builder_add(builder, "{sv}", "service_info", __g_hash_keys_to_g_variant(service->service_info_map)); + if (service->rsp_info) + g_variant_builder_add(builder, "{sv}", "rsp_info", g_variant_new("s", service->rsp_info)); + + params = g_variant_new("(a{sv})", builder); + g_variant_builder_unref(builder); + ASP_LOGI("service type (%s) adv ID (%u)", service->service_type, service->adv_id); + + reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE, + "ServiceChangeStatus", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_seek_create(char *service_type, asp_seek_service_h *seek_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!service_type || strlen(service_type) == 0) { + ASP_LOGE("NULL Param [service_type]!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service_type = [%s]", service_type); + + if (!seek_service) { + ASP_LOGE("NULL Param [handle]!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = (asp_client_seek_s *)g_try_malloc0(sizeof(asp_client_seek_s)); + if (!service) { + ASP_LOGE("malloc() failed!!!."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OUT_OF_MEMORY; + } + ASP_LOGD("service [%p]", service); + + service->service_type = g_strdup(service_type); + if (!service->service_type) { + ASP_LOGE("malloc() failed!!!."); + g_free(service); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OUT_OF_MEMORY; + } + + service->service_info_map = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + asp_seeks = g_list_prepend(asp_seeks, service); + + *seek_service = (asp_seek_service_h)service; + ASP_LOGD("asp_create_seek_handle() SUCCESS"); + + ASP_LOGD("seek handler [%p]", *seek_service); + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_seek_destroy(asp_seek_service_h seek_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!seek_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", seek_service); + + service = __get_seek((void *)seek_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + g_hash_table_remove_all(service->service_info_map); + res = __remove_seek((void *)service); + if (res != ASP_ERROR_NONE) { + __ASP_LOG_FUNC_END__; + return res; + } + + ASP_LOGD("asp_seek_destroy() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_seek_add_info(asp_seek_service_h seek_service, const char *key) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!seek_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", seek_service); + + service = __get_seek((void *)seek_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + g_hash_table_replace(service->service_info_map, g_strdup(key), NULL); + + ASP_LOGD("service info [%d]", g_hash_table_size(service->service_info_map)); + ASP_LOGD("asp_add_seek_info() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; + +} + +int asp_seek_remove_info(asp_seek_service_h seek_service, const char *key) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!seek_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", seek_service); + + service = __get_seek((void *)seek_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + /* TODO: remove seek info */ + g_hash_table_remove(service->service_info_map, key); + + ASP_LOGD("asp_remove_seek_info() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; + +} + +int asp_seek_set_discovery_tech(asp_seek_service_h seek_service, int discovery_tech) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + if (!((discovery_tech & ASP_DISCOVERY_TECH_P2P) | + (discovery_tech & ASP_DISCOVERY_TECH_NFC) | + (discovery_tech & ASP_DISCOVERY_TECH_BLE) | + (discovery_tech & ASP_DISCOVERY_TECH_INFRA) | + (discovery_tech & ASP_DISCOVERY_TECH_NAN))) { + ASP_LOGE("invalid parameter!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (!seek_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", seek_service); + + service = __get_seek((void *)seek_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->discovery_tech = discovery_tech; + + ASP_LOGD("asp_set_seeking_tech() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + +int asp_seek_set_preferred_connection(asp_seek_service_h seek_service, + unsigned char preferred_connection) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!seek_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", seek_service); + + service = __get_seek((void *)seek_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + service->preferred_connection = preferred_connection; + + ASP_LOGD("asp_set_seeking_preferred_connection() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +int asp_seek_start(asp_seek_service_h seek_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!seek_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", seek_service); + + service = __get_seek((void *)seek_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SERVICE_NOT_FOUND; + } + + ASP_LOGD("service info [%d]", g_hash_table_size(service->service_info_map)); + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "discovery_tech", g_variant_new("i", service->discovery_tech)); + g_variant_builder_add(builder, "{sv}", "preferred_connection", g_variant_new("y", service->preferred_connection)); + g_variant_builder_add(builder, "{sv}", "service_type", g_variant_new("s", service->service_type)); + if (g_hash_table_size(service->service_info_map) > 0) { + ASP_LOGE("Service info"); + g_variant_builder_add(builder, "{sv}", "service_info", __g_hash_keys_to_g_variant(service->service_info_map)); + } + + params = g_variant_new("(a{sv})", builder); + g_variant_builder_unref(builder); + ASP_LOGI("service name (%s)", service->serivce_name); + + reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE, + "SeekService", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(it)", &ret, &(service->search_id)); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_seek_stop(asp_seek_service_h seek_service) +{ + __ASP_LOG_FUNC_START__; + asp_client_seek_s *service = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!seek_service) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_seek((void *)seek_service); + if (service == NULL) { + ASP_LOGE("Service NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } + ASP_LOGD("service_type = [%s]", service->service_type); + + params = g_variant_new("(ti)", service->search_id, service->discovery_tech); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SERVICE_INTERFACE, + "CancelSeekService", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_session_create(char *service_mac, unsigned int adv_id, asp_session_h* session) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!service_mac || strlen(service_mac) != (MACSTR_LEN -1)) { + ASP_LOGE("Invalid Param [service_mac]!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + if (adv_id == 0 || !session) { + ASP_LOGE("NULL Param [session]!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = (asp_client_session_s *)g_try_malloc0(sizeof(asp_client_session_s)); + if (!service) { + ASP_LOGE("malloc() failed!!!."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OUT_OF_MEMORY; + } + ASP_LOGD("service [%p]", service); + + service->advertisement_id = adv_id; + g_strlcpy(service->service_mac, service_mac, MACSTR_LEN); + + asp_sessions = g_list_prepend(asp_sessions, service); + + /* Session ID will be generated by asp-manager */ + *session = (asp_session_h)service; + ASP_LOGD("asp_session_create() SUCCESS"); + + ASP_LOGD("service [%p]", *session); + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_destroy(asp_session_h session) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session) { + ASP_LOGE("NULL handler!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", session); + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + res = __remove_session((void *)service); + if (res != ASP_ERROR_NONE) { + __ASP_LOG_FUNC_END__; + return res; + } + + ASP_LOGD("asp_session_destroy() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NONE; +} + + +int asp_session_get_mac(asp_session_h session, char **session_mac) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session || !session_mac) { + ASP_LOGE("Invalid parameter!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", session); + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + *session_mac = g_strndup(service->session_mac, MACSTR_LEN - 1); + if (*session_mac == NULL) { + ASP_LOGE("g_strndup failed"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } + + ASP_LOGD("asp_session_get_mac() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + + +int asp_session_get_id(asp_session_h session, unsigned int *session_id) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session || !session_id) { + ASP_LOGE("Invalid parameter!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + ASP_LOGD("service [%p]", session); + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + *session_id = service->session_id; + + ASP_LOGD("asp_session_get_id() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_set_info(asp_session_h session, char *service_info) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + char *info = NULL; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!service_info || !session) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + info = g_strdup(service_info); + if (!info) { + ASP_LOGE("malloc() failed!!!."); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } + g_free(service->session_information); + service->session_information = info; + + ASP_LOGD("asp_session_set_info() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_get_info(asp_session_h session, char **service_info) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session || !service_info) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + if (service->session_information) + *service_info = g_strdup(service->session_information); + + ASP_LOGD("asp_session_get_info() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_set_p2p_role_scheme(asp_session_h session, + asp_advert_p2p_role_scheme_e role) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!role || !session) { + ASP_LOGE("Invalid parameters"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + service->network_role = role; + + ASP_LOGD("asp_session_set_p2p_role_scheme() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_get_p2p_role_scheme(asp_session_h session, + asp_advert_p2p_role_scheme_e *role) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!role || !session) { + ASP_LOGE("Invalid parameters"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + *role = service->network_role; + + ASP_LOGD("asp_session_get_p2p_role_scheme() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_set_p2p_config_method(asp_session_h session, + asp_wps_type_e config_method) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session) { + ASP_LOGE("Invalid parameter"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + if (config_method < ASP_WPS_TYPE_DEFAULT || + config_method > ASP_WPS_TYPE_PIN_KEYPAD) { + ASP_LOGE("network_config is invalid"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service->network_config = config_method; + + ASP_LOGD("asp_session_set_p2p_config_method() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_get_p2p_config_method(asp_session_h session, + asp_wps_type_e *config_method) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!config_method || !session) { + ASP_LOGE("Invalid parameters"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + *config_method = service->network_config; + + ASP_LOGD("asp_session_get_p2p_config_method() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} + +int asp_session_get_close_status(asp_session_h session, int *status) +{ + __ASP_LOG_FUNC_START__; + asp_client_session_s *service = NULL; + int res = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!status || !session) { + ASP_LOGE("Invalid parameters"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + *status = service->state; + + ASP_LOGD("asp_session_get_close_status() SUCCESS"); + + __ASP_LOG_FUNC_END__; + return res; +} +int asp_session_connect(asp_session_h session) +{ + __ASP_LOG_FUNC_START__; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + asp_client_session_s *service = NULL; + const char *str = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "service_mac", g_variant_new("s", service->service_mac)); + g_variant_builder_add(builder, "{sv}", "adv_id", g_variant_new("u", service->advertisement_id)); + g_variant_builder_add(builder, "{sv}", "role", g_variant_new("y", service->network_config)); + g_variant_builder_add(builder, "{sv}", "config_method", g_variant_new("u", service->network_config)); + if (service->session_information) + g_variant_builder_add(builder, "{sv}", "session _info", g_variant_new("s", service->session_information)); + + params = g_variant_new("(a{sv})", builder); + g_variant_builder_unref(builder); + + reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE, + "ConnectSession", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(iu&s)", &ret, &(service->session_id), &str); + if (str != NULL) + memcpy(service->session_mac, str, strlen(str)); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_session_confirm(asp_session_h session, bool confirmed, char *pin) +{ + __ASP_LOG_FUNC_START__; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + asp_client_session_s *service = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "session_mac", g_variant_new("s", service->session_mac)); + g_variant_builder_add(builder, "{sv}", "session_id", g_variant_new("u", service->session_id)); + g_variant_builder_add(builder, "{sv}", "confirmed", g_variant_new("i", confirmed)); + if (pin) + g_variant_builder_add(builder, "{sv}", "pin", g_variant_new("s", pin)); + params = g_variant_new("(a{sv})", builder); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE, + "ConfirmSession", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_session_get_handle(char *session_mac, unsigned int session_id, + asp_session_h *session) + +{ + __ASP_LOG_FUNC_START__; + GVariant *params = NULL; + GVariantIter *iter = NULL; + GError *error = NULL; + GVariant *reply = NULL; + asp_client_session_s *service = NULL; + char *key = NULL; + GVariant *var = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session_mac || !session) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + params = g_variant_new("(su)", session_mac, session_id); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE, + "GetSession", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + if (!reply) { + ASP_LOGE("reply is NULL!!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_OPERATION_FAILED; + } + + service = (asp_client_session_s *)g_try_malloc0(sizeof(asp_client_session_s)); + if (!service) { + ASP_LOGE("malloc() failed!!!."); + g_variant_unref(reply); + return ASP_ERROR_OUT_OF_MEMORY; + } + ASP_LOGD("service [%p]", service); + g_strlcpy(service->session_mac, session_mac, MACSTR_LEN); + service->session_id = session_id; + + g_variant_get(reply, "(ia{sv})", &ret, &iter); + while (g_variant_iter_loop(iter, "{sv}", &key, &var)) { + if (!g_strcmp0(key, "adv_id")) { + g_variant_get(var, "u", &(service->advertisement_id)); +/* + } else if (!g_strcmp0(key, "session_id")) { + g_variant_get(var, "u", &(service->session_id)); + } else if (!g_strcmp0(key, "session_mac")) { + g_variant_get(var, "&s", &str); + g_strlcpy(service->session_mac, str, MACSTR_LEN); + } else if (!g_strcmp0(key, "state")) { + g_variant_get(var, "i", &(service->state)); + } else if (!g_strcmp0(key, "session_info")) { + g_variant_get(var, "&s", &str); +*/ + } else { + /* TODO: additional params. */ + ;/* Do Nothing */ + } + } + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + *session = service; + asp_sessions = g_list_prepend(asp_sessions, service); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_session_set_state_ready(asp_session_h session) + +{ + __ASP_LOG_FUNC_START__; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + asp_client_session_s *service = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + return ASP_ERROR_SESSION_NOT_FOUND; + } + + params = g_variant_new("(su)", service->session_mac, service->session_id); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE, + "SetSessionReady", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_session_close(asp_session_h session) + +{ + __ASP_LOG_FUNC_START__; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + asp_client_session_s *service = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + return ASP_ERROR_SESSION_NOT_FOUND; + } + + params = g_variant_new("(su)", service->session_mac, service->session_id); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE, + "CloseSession", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_session_bind_port(asp_session_h session, char *ip_address, + int port, int proto) +{ + __ASP_LOG_FUNC_START__; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + asp_client_session_s *service = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session || !ip_address) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "session_mac", g_variant_new("s", service->session_mac)); + g_variant_builder_add(builder, "{sv}", "session_id", g_variant_new("u", service->session_id)); + g_variant_builder_add(builder, "{sv}", "ip_address", g_variant_new("s", ip_address)); + g_variant_builder_add(builder, "{sv}", "port", g_variant_new("i", port)); + g_variant_builder_add(builder, "{sv}", "proto", g_variant_new("i", proto)); + params = g_variant_new("(a{sv})", builder); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE, + "BoundPort", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} + +int asp_session_release_port(asp_session_h session, char *ip_address, + int port, int proto) +{ + __ASP_LOG_FUNC_START__; + GVariantBuilder *builder = NULL; + GVariant *params = NULL; + GError *error = NULL; + GVariant *reply = NULL; + asp_client_session_s *service = NULL; + int ret = ASP_ERROR_NONE; + + CHECK_FEATURE_SUPPORTED(TIZEN_FEATURE_ASP); + + if (g_client_info.is_registered == false) { + ASP_LOGE("Client is NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_NOT_INITIALIZED; + } + + if (!session || !ip_address) { + ASP_LOGE("NULL Param!"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_INVALID_PARAMETER; + } + + service = __get_session((void *)session); + if (service == NULL) { + ASP_LOGE("Session NOT registered"); + __ASP_LOG_FUNC_END__; + return ASP_ERROR_SESSION_NOT_FOUND; + } + + builder = g_variant_builder_new(G_VARIANT_TYPE("a{sv}")); + g_variant_builder_add(builder, "{sv}", "session_mac", g_variant_new("s", service->session_mac)); + g_variant_builder_add(builder, "{sv}", "session_id", g_variant_new("u", service->session_id)); + g_variant_builder_add(builder, "{sv}", "ip_address", g_variant_new("s", ip_address)); + g_variant_builder_add(builder, "{sv}", "port", g_variant_new("i", port)); + g_variant_builder_add(builder, "{sv}", "proto", g_variant_new("i", proto)); + params = g_variant_new("(a{sv})", builder); + reply = asp_dbus_method_call_sync(ASP_DAEMON_SESSION_INTERFACE, + "ReleasePort", params, &error); + if (error != NULL) { + ASP_LOGE("asp_dbus_method_call_sync() failed." + "error [%d: %s]", error->code, error->message); + ret = __asp_err_string_to_enum(error->message); + g_error_free(error); + __ASP_LOG_FUNC_END__; + return ret; + } + + g_variant_get(reply, "(i)", &ret); + g_variant_unref(reply); + + ASP_LOGD("%s() return : [%d]", __func__, ret); + + __ASP_LOG_FUNC_END__; + return ret; +} diff --git a/src/asp-dbus.c b/src/asp-dbus.c new file mode 100644 index 0000000..7a08e6e --- /dev/null +++ b/src/asp-dbus.c @@ -0,0 +1,193 @@ +/* + * Application Service Platform(ASP) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file implements asp dbus utility functions. + * + * @file asp-dbus.c + * @author Jiung Yu (jiung.yu@samsung.com) + * @version 0.1 + */ + +#include "asp.h" + +#include "asp-dbus.h" +#include "asp-log.h" +#include "asp-util.h" +#include "asp-client.h" + +const char *service_path = ASP_DAEMON_SERVICE_PATH; +const char *session_path = ASP_DAEMON_SESSION_PATH; + +typedef struct { + GDBusConnection *connection; + guint signal_subscribe_id; +} gdbus_connection_data; + +static gdbus_connection_data gdbus_conn = {NULL, 0}; + +static struct { + const char *interface; + const char *member; + void (*function) (GDBusConnection *connection, + const gchar *object_path, + GVariant *parameters); +} asp_dbus_signal_map[] = { + { + ASP_DAEMON_SERVICE_INTERFACE, + "SearchResult", + asp_process_seek_search_result + }, + { + ASP_DAEMON_SERVICE_INTERFACE, + "AdvertiseStatusChanged", + asp_process_advert_status_changed + }, + { + ASP_DAEMON_SESSION_INTERFACE, + "SessionRequest", + asp_process_session_request + }, + { + ASP_DAEMON_SESSION_INTERFACE, + "SessionConfigRequest", + asp_process_session_config_request + }, + { + ASP_DAEMON_SESSION_INTERFACE, + "ConnectStatus", + asp_process_session_connect_status + }, + { + ASP_DAEMON_SESSION_INTERFACE, + "SessionStatus", + asp_process_session_status + }, + { + ASP_DAEMON_SESSION_INTERFACE, + "PortStatus", + asp_process_session_port_status + }, + { + NULL, + NULL, + NULL + } +}; + +static void _asp_dbus_signal_cb(GDBusConnection *connection, + const gchar *sender, const gchar *object_path, + const gchar *interface, const gchar *signal, + GVariant *parameters, gpointer user_data) +{ + int i = 0; + + ASP_LOGD("Signal Name [%s]", signal); + DBUS_DEBUG_VARIANT(parameters); + + for (i = 0; asp_dbus_signal_map[i].member != NULL; i++) { + if (!g_strcmp0(signal, asp_dbus_signal_map[i].member) && + !g_strcmp0(interface, asp_dbus_signal_map[i].interface) && + asp_dbus_signal_map[i].function != NULL) { + asp_dbus_signal_map[i].function(connection, object_path, parameters); + break; + } + } +} + +GVariant *asp_dbus_method_call_sync_debug(const char* interface_name, + const char* method, + GVariant *params, + GError **error, + const char *calling_func) +{ + GVariant *reply = NULL; + const char *object_path = NULL; + + if (gdbus_conn.connection == NULL) { + ASP_LOGE("GDBusconnection is NULL"); + return reply; + } + + ASP_LOGD("[%s][%s.%s]", calling_func, interface_name, method); + DBUS_DEBUG_VARIANT(params); + + if (g_strcmp0(ASP_DAEMON_SERVICE_INTERFACE, interface_name) == 0) + object_path = service_path; + else + object_path = session_path; + + reply = g_dbus_connection_call_sync(gdbus_conn.connection, + ASP_DAEMON_SERVICE, /* bus name */ + object_path, /* object path */ + interface_name, /* interface name */ + method, /* method name */ + params, /* GVariant *params */ + NULL, /* reply_type */ + G_DBUS_CALL_FLAGS_NONE, /* flags */ + ASP_DBUS_REPLY_TIMEOUT_SYNC, /* timeout */ + NULL, /* cancellable */ + error); /* error */ + DBUS_DEBUG_VARIANT(reply); + return reply; +} + +gboolean asp_dbus_init(void) +{ + GError *Error = NULL; + GDBusConnection *connection = NULL; + + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &Error); + if (connection == NULL) { + ASP_LOGE("Failed to get connection, Error[%s]", Error->message); + g_error_free(Error); + return FALSE; + } + + gdbus_conn.connection = connection; + + /* subscribe signal handler */ + gdbus_conn.signal_subscribe_id = g_dbus_connection_signal_subscribe(connection, + + ASP_DAEMON_SERVICE, /* bus name */ + NULL, /* interface */ + NULL, /* member */ + NULL, /* object_path */ + NULL, /* arg0 */ + G_DBUS_SIGNAL_FLAGS_NONE, + _asp_dbus_signal_cb, + NULL, + NULL); + ASP_LOGD("Subscribed dbus signals [%d]", gdbus_conn.signal_subscribe_id); + return TRUE; +} + +void asp_dbus_deinit(void) +{ + if (gdbus_conn.connection == NULL) + return; + + /* unsubscribe signal handler */ + g_dbus_connection_signal_unsubscribe(gdbus_conn.connection, gdbus_conn.signal_subscribe_id); + gdbus_conn.signal_subscribe_id = 0; + + /* unref gdbus connection */ + g_object_unref(gdbus_conn.connection); + gdbus_conn.connection = NULL; +} diff --git a/src/include/asp-client.h b/src/include/asp-client.h new file mode 100755 index 0000000..2abeb43 --- /dev/null +++ b/src/include/asp-client.h @@ -0,0 +1,140 @@ +/* + * Application Service Platform(ASP) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file declares definitions, macros and structures. + * + * @file asp-client.h + * @author Yu Jiung (jiung.yu@samsung.com) + * @version 0.1 + */ + +#ifndef __ASP_CLIENT_H__ +#define __ASP_CLIENT_H__ + +#include + +#define MACADDR_LEN 6 +#define MACSTR_LEN 18 +#define ASP_SERVICE_INFO_MAX_LEN 200 + +/** + * Application Service Platform(ASP) advertise data structure + */ +typedef struct { + unsigned int adv_id; + long long unsigned search_id; + int auto_accept; + int discovery_tech; + unsigned char preferred_connection; + + unsigned char status; + unsigned char role; + unsigned int config_method; + unsigned char tran_id; + + char *instance_name; + char *serivce_name; + char *service_type; + GHashTable *service_info_map; + char *rsp_info; +} asp_client_advert_s; + +/** + * Application Service Platform(ASP) seek data structure + */ +typedef struct { + unsigned int adv_id; + long long unsigned search_id; + int auto_accept; + int discovery_tech; + unsigned char preferred_connection; + + unsigned char status; + unsigned char role; + unsigned int config_method; + unsigned char tran_id; + + char *serivce_name; + char *service_type; + GHashTable *service_info_map; + char *rsp_info; +} asp_client_seek_s; + +/** + * Application Service Platform(ASP) session data structure + */ +typedef struct { + char session_mac[MACSTR_LEN]; /* the MAC address of the P2P device that generated the session ID */ + unsigned int session_id; + char service_mac[MACSTR_LEN]; + unsigned int advertisement_id; + int network_config; + int network_role; + int port; + int state; + int persist; + char *session_information; + + /* session information for each local setting */ + int service_role; + int is_incomming; + unsigned char local_ip[4]; + char *deferred_session_response; +} asp_client_session_s; + +typedef struct { + bool is_registered; + + asp_seek_search_result_cb seek_search_result_cb; + asp_advert_status_changed_cb advert_status_changed_cb; + + asp_session_request_cb session_request_cb; + asp_session_config_request_cb session_config_request_cb; + asp_session_connect_status_cb session_connect_status_cb; + asp_session_status_cb session_status_cb; + asp_session_port_status_cb session_port_status_cb; + + void *user_data_for_cb_seek_search_result; + void *user_data_for_cb_advert_status_changed; + + void *user_data_for_cb_session_request; + void *user_data_for_cb_session_config_request; + void *user_data_for_cb_session_connect_status; + void *user_data_for_cb_session_status; + void *user_data_for_cb_session_port_status; +} asp_client_info_s; + +void asp_process_seek_search_result(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters); +void asp_process_advert_status_changed(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters); + +void asp_process_session_request(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters); +void asp_process_session_config_request(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters); +void asp_process_session_connect_status(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters); +void asp_process_session_status(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters); +void asp_process_session_port_status(GDBusConnection *connection, + const gchar *object_path, GVariant *parameters); + +#endif /** __ASP_CLIENT_H__ */ diff --git a/src/include/asp-dbus.h b/src/include/asp-dbus.h new file mode 100755 index 0000000..013df35 --- /dev/null +++ b/src/include/asp-dbus.h @@ -0,0 +1,78 @@ +/* + * Application Service Platform(ASP) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file declares Application Service Platform DBus utility functions. + * + * @file asp-dbus.h + * @author Jiung Yu (jiung.yu.com) + * @version 0.1 + */ + +#ifndef __ASP_DBUS_H__ +#define __ASP_DBUS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#define ASP_DAEMON_SERVICE "net.asp" +#define ASP_DAEMON_PATH "/net/asp" +#define ASP_DAEMON_SERVICE_PATH ASP_DAEMON_PATH "/service" +#define ASP_DAEMON_SESSION_PATH ASP_DAEMON_PATH "/session" +#define ASP_DAEMON_INTERFACE ASP_DAEMON_SERVICE +#define ASP_DAEMON_SERVICE_INTERFACE ASP_DAEMON_SERVICE ".service" +#define ASP_DAEMON_SESSION_INTERFACE ASP_DAEMON_SERVICE ".session" + +#define ASP_DBUS_REPLY_TIMEOUT_SYNC 5 * 1000 +#define DBUS_OBJECT_PATH_MAX 150 + +#define asp_dbus_method_call_sync(interface_name, method, params, error) \ + asp_dbus_method_call_sync_debug(interface_name, method, params, error, __func__) + +#define DBUS_DEBUG_VARIANT(parameters) \ + do {\ + gchar *parameters_debug_str = NULL;\ + if (parameters)\ + parameters_debug_str = g_variant_print(parameters, TRUE);\ + ASP_LOGD("signal params [%s]", parameters_debug_str ? parameters_debug_str : "NULL");\ + g_free(parameters_debug_str);\ + } while (0) + +gboolean asp_dbus_is_pending_call_used(void); + +gboolean asp_dbus_init(void); + +void asp_dbus_deinit(void); + +GVariant *asp_dbus_method_call_sync_debug(const char* interface_name, + const char* method, + GVariant *params, + GError **error, + const char *calling_func); + +int asp_dbus_unpack_ay(unsigned char *dst, GVariant *src, int size); + +#ifdef __cplusplus +} +#endif + +#endif /* __ASP_DBUS_H__ */ diff --git a/src/include/asp-log.h b/src/include/asp-log.h new file mode 100755 index 0000000..09c2aff --- /dev/null +++ b/src/include/asp-log.h @@ -0,0 +1,66 @@ +/* + * Application Service Platform(ASP) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file declares macros for logging. + * + * @file asp-log.h + * @author Jiung Yu (jiung.yu.com) + * @version 0.1 + */ + +#ifndef __ASP_LOG_H__ +#define __ASP_LOG_H__ + +#ifdef USE_DLOG +#include + +#undef LOG_TAG +#define LOG_TAG "CAPI_NETWORK_ASP" + +#define ASP_LOGV(format, args...) LOGV(format, ##args) +#define ASP_LOGD(format, args...) LOGD(format, ##args) +#define ASP_LOGI(format, args...) LOGI(format, ##args) +#define ASP_LOGW(format, args...) LOGW(format, ##args) +#define ASP_LOGE(format, args...) LOGE(format, ##args) +#define ASP_LOGF(format, args...) LOGF(format, ##args) + +#define ASP_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) +#define ASP_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) + +#define __ASP_LOG_FUNC_START__ LOGV("Enter") +#define __ASP_LOG_FUNC_END__ LOGV("Quit") + +#else /** _DLOG_UTIL */ + +#define ASP_LOGV(format, args...) +#define ASP_LOGD(format, args...) +#define ASP_LOGI(format, args...) +#define ASP_LOGW(format, args...) +#define ASP_LOGE(format, args...) +#define ASP_LOGF(format, args...) + +#define __ASP_LOG_FUNC_START__ +#define __ASP_LOG_FUNC_END__ + +#define ASP_SECLOGI(format, args...) +#define ASP_SECLOGD(format, args...) + +#endif /** _DLOG_UTIL */ +#endif /** __ASP_LOG_H__ */ diff --git a/src/include/asp-util.h b/src/include/asp-util.h new file mode 100755 index 0000000..e5dd6ff --- /dev/null +++ b/src/include/asp-util.h @@ -0,0 +1,67 @@ +/* + * Application Service Platform(ASP) + * + * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/** + * This file declares macros for usefuls. + * + * @file asp-util.h + * @author Jiung Yu (jiung.yu.com) + * @version 0.1 + */ + +#ifndef __ASP_UTIL_H__ +#define __ASP_UTIL_H__ + +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" +#define IP2STR(a) (a)[0], (a)[1], (a)[2], (a)[3] +#define IPSTR "%d.%d.%d.%d" +#define MAC2SECSTR(a) (a)[0], (a)[4], (a)[5] +#define MACSECSTR "%02x:%02x:%02x" +#define IP2SECSTR(a) (a)[0], (a)[3] +#define IPSECSTR "%d..%d" + +#define MACSTR_LEN 18 +#define MACADDR_LEN 6 +#define IP_LEN 6 +#define IPSTR_LEN 16 +#define WPS_PIN_LEN 8 + +#define TIZEN_FEATURE_P2PS "tizen.org/feature/network.asp" + +#if 0 +#define CHECK_FEATURE_SUPPORTED(feature_name)\ + do {\ + bool feature_supported = FALSE;\ + if (!system_info_get_platform_bool(feature_name, &feature_supported)) {\ + if (feature_supported == FALSE) {\ + LOGE("%s feature is disabled", feature_name);\ + return P2PS_ERROR_NOT_SUPPORTED;\ + } \ + } else {\ + LOGE("Error - Feature getting from System Info");\ + return P2PS_ERROR_OPERATION_FAILED;\ + } \ + } while (0) + +#else +#define CHECK_FEATURE_SUPPORTED(feature_name) +#endif + +#endif /** __ASP_UTIL_H__ */ diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 0000000..41c5ed5 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,40 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(asp-test C) + +IF(FILE_TRANSFER_TEST) + SET(ASP_TEST_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/file_transfer/include) + SET(FILE_TRANSFER_REQUIRED_PKGS libxml-2.0 libsoup-2.4 gssdp-1.0 gupnp-1.0 libtzplatform-config) + ADD_DEFINITIONS(-DFILE_TRANSFER_TEST) + aux_source_directory(./file_transfer sources) +ENDIF(FILE_TRANSFER_TEST) + +SET(ASP_TEST_INCLUDE_DIR ${ASP_TEST_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/../include) +INCLUDE_DIRECTORIES(${ASP_TEST_INCLUDE_DIR}) + +INCLUDE(FindPkgConfig) +pkg_check_modules(TARGET_ASP_TEST REQUIRED capi-base-common glib-2.0 ${FILE_TRANSFER_REQUIRED_PKGS}) +FOREACH(flag ${TARGET_ASP_TEST_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") + MESSAGE(${flag}) +ENDFOREACH() + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE") + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + SET(ASP_TEST_SRCS ${ASP_TEST_SRCS} ${src}) +ENDFOREACH() + +ADD_EXECUTABLE(${PROJECT_NAME} ${ASP_TEST_SRCS}) +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie") +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${TARGET_ASP} ${TARGET_ASP_TEST_LDFLAGS}) +INSTALL(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION ${BIN_DIR}) + +IF(FILE_TRANSFER_TEST) +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/files/device.xml.in ${CMAKE_SOURCE_DIR}/files/device.xml @ONLY) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/device.xml DESTINATION ${TZ_SYS_RO_ETC}/file-transfer) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/files/FileTransfer1.xml DESTINATION ${TZ_SYS_RO_ETC}/file-transfer) +ENDIF(FILE_TRANSFER_TEST) + diff --git a/test/asp-test.c b/test/asp-test.c new file mode 100644 index 0000000..79dcde9 --- /dev/null +++ b/test/asp-test.c @@ -0,0 +1,1828 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + + +#define RESET_COLOR "\e[m" +#define MAKE_RED "\e[31m" +#define MAKE_GREEN "\e[32m" + +#define __FUNC_ENTER__ printf("%s() entering...\n", __func__) +#define __FUNC_EXIT__ printf("%s() leaving...\n", __func__) + +#define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] +#define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x" + +#define MAX_ADVERTISE 255 +#define MAX_SEEK 255 +#define MAX_SESSION 255 + +static const char *print_error(int err_type) +{ + switch (err_type) { + case ASP_ERROR_NONE: + return "NONE"; + case ASP_ERROR_NOT_PERMITTED: + return "NOT_PERMITTED"; + case ASP_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case ASP_ERROR_PERMISSION_DENIED: + return "PERMISSION_DENIED"; + case ASP_ERROR_RESOURCE_BUSY: + return "RESOURCE_BUSY"; + case ASP_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case ASP_ERROR_CONNECTION_TIME_OUT: + return "CONNECTION_TIME_OUT"; + case ASP_ERROR_NOT_SUPPORTED: + return "NOT_SUPPORTED"; + case ASP_ERROR_NOT_INITIALIZED: + return "NOT_INITIALIZED"; + case ASP_ERROR_ALREADY_INITIALIZED: + return "ALREADY_INITIALIZED"; + case ASP_ERROR_COMMUNICATION_FAILED: + return "COMMUNICATION_FAILED"; + case ASP_ERROR_OPERATION_FAILED: + return "ASP_ERROR_OPERATION_FAILED"; + case ASP_ERROR_IN_PROGRESS: + return "IN_PROGRESS"; + case ASP_ERROR_SERVICE_NOT_FOUND: + return "SERVICE_NOT_FOUND"; + case ASP_ERROR_SESSION_NOT_FOUND: + return "SESSION_NOT_FOUND"; + case ASP_ERROR_NETWORK_ROLE_REJECTED: + return "NETWORK_ROLE_REJECTED"; + default: + return "UNKNOWN"; + } +} + +static const char* print_advert_status_reason(asp_advert_status_reason_e reason) +{ + switch (reason) { + case ASP_ADVERT_STATUS_REASON_SUCCESS: + return "ASP_ADVERT_STATUS_REASON_SUCCESS"; + case ASP_ADVERT_STATUS_REASON_SERVICE_DUPLICATED: + return "ASP_ADVERT_STATUS_REASON_SERVICE_DUPLICATED"; + case ASP_ADVERT_STATUS_REASON_OTHER_FAILURE: + return "ASP_ADVERT_STATUS_REASON_OTHER_FAILURE"; + default: + return"UNKNOWN"; + } +} + +static const char* print_p2p_role_scheme(asp_advert_p2p_role_scheme_e role) +{ + switch (role) { + case ASP_ADVERT_P2P_ROLE_SCHEME_ANY: + return "ASP_ADVERT_P2P_ROLE_SCHEME_ANY"; + case ASP_ADVERT_P2P_ROLE_SCHEME_GO: + return "ASP_ADVERT_P2P_ROLE_SCHEME_GO"; + case ASP_ADVERT_P2P_ROLE_SCHEME_GC: + return "ASP_ADVERT_P2P_ROLE_SCHEME_GC"; + default: + return"UNKNOWN"; + } +} + +static const char* print_session_connect_status(int status) +{ + switch (status) { + case ASP_CONNECT_STATUS_NETWORK_ROLE_REJECTED: + return "ASP_CONNECT_STATUS_NETWORK_ROLE_REJECTED"; + case ASP_CONNECT_STATUS_CONNECTION_LIMIT_REACHED: + return "ASP_CONNECT_STATUS_CONNECTION_LIMIT_REACHED"; + case ASP_CONNECT_STATUS_REQUEST_SENT: + return "ASP_CONNECT_STATUS_REQUEST_SENT"; + case ASP_CONNECT_STATUS_REQUEST_RECEIVED: + return "ASP_CONNECT_STATUS_REQUEST_RECEIVED"; + case ASP_CONNECT_STATUS_REQUEST_DEFERRED: + return "ASP_CONNECT_STATUS_REQUEST_DEFERRED"; + case ASP_CONNECT_STATUS_REQUEST_ACCEPTED: + return "ASP_CONNECT_STATUS_REQUEST_ACCEPTED"; + case ASP_CONNECT_STATUS_REQUEST_FAILED: + return "ASP_CONNECT_STATUS_REQUEST_FAILED"; + case ASP_CONNECT_STATUS_GROUP_FORMATION_STARTED: + return "ASP_CONNECT_STATUS_GROUP_FORMATION_STARTED"; + case ASP_CONNECT_STATUS_GROUP_FORMATION_COMPLETED: + return "ASP_CONNECT_STATUS_GROUP_FORMATION_COMPLETED"; + case ASP_CONNECT_STATUS_GROUP_FORMATION_FAILED: + return "ASP_CONNECT_STATUS_GROUP_FORMATION_FAILED"; + default: + return"UNKNOWN"; + } +} + +static const char* print_session_state(int session_state) +{ + switch (session_state) { + case ASP_SESSION_STATE_ERROR: + return "ASP_SESSION_STATE_ERROR"; + case ASP_SESSION_STATE_CLOSED: + return "ASP_SESSION_STATE_CLOSED"; + case ASP_SESSION_STATE_INITIATED: + return "ASP_SESSION_STATE_INITIATED"; + case ASP_SESSION_STATE_REQUESTED: + return "ASP_SESSION_STATE_REQUESTED"; + case ASP_SESSION_STATE_OPEN: + return "ASP_SESSION_STATE_OPEN"; + default: + return"UNKNOWN"; + } +} + +static const char* print_session_close_state(int state) +{ + switch (state) { + case ASP_SESSION_CLOSE_OK: + return "ASP_SESSION_CLOSE_OK"; + case ASP_SESSION_CLOSE_DISASSOCIATED: + return "ASP_SESSION_CLOSE_DISASSOCIATED"; + case ASP_SESSION_CLOSE_LOCAL_CLOSE: + return "ASP_SESSION_CLOSE_LOCAL_CLOSE"; + case ASP_SESSION_CLOSE_REMOTE_CLOSE: + return "ASP_SESSION_CLOSE_REMOTE_CLOSE"; + case ASP_SESSION_CLOSE_SYSTEM_FAILURE: + return "ASP_SESSION_CLOSE_SYSTEM_FAILURE"; + case ASP_SESSION_CLOSE_NO_RESPONSE: + return "ASP_SESSION_CLOSE_NO_RESPONSE"; + default: + return"UNKNOWN"; + } +} + +static const char* print_port_status(int status) +{ + switch (status) { + case ASP_PORT_STATUS_LOCAL_PORT_ALLOWED: + return "ASP_PORT_STATUS_LOCAL_PORT_ALLOWED"; + case ASP_PORT_STATUS_LOCAL_PORT_BLOCKED: + return "ASP_PORT_STATUS_LOCAL_PORT_BLOCKED"; + case ASP_PORT_STATUS_FAILURE: + return "ASP_PORT_STATUS_FAILURE"; + case ASP_PORT_STATUS_REMOTE_PORT_ALLOWED: + return "ASP_PORT_STATUS_REMOTE_PORT_ALLOWED"; + + default: + return"UNKNOWN"; + } +} + +static const char* print_service_status(int status) +{ + switch (status) { + case ASP_SERVICE_STATUS_NOT_ADVERTISED: + return "ASP_SERVICE_STATUS_NOT_ADVERTISED"; + case ASP_SERVICE_STATUS_ADVERTISED: + return "ASP_SERVICE_STATUS_ADVERTISED"; + + default: + return"UNKNOWN"; + } +} + +enum { + CMD_QUIT, + CMD_FULL_MENU, + + CMD_INITIALIZE, + CMD_DEINITIALIZE, + + CMD_SEEK_SET_SEARCH_RESULT_CB, + CMD_SEEK_UNSET_SEARCH_RESULT_CB, + CMD_ADVERT_SET_STATUS_CHANGED_CB, + CMD_ADVERT_UNSET_STATUS_CHANGED_CB, + CMD_SESSION_SET_REQUEST_CB, + CMD_SESSION_UNSET_REQUST_CB, + CMD_SESSION_SET_CONFIG_REQUEST_CB, + CMD_SESSION_UNSET_CONFIG_REQUEST_CB, + CMD_SESSION_SET_CONNECT_STATUS_CB, + CMD_SESSION_UNSET_CONNECT_STATUS_CB, + CMD_SESSION_SET_STATUS_CB, + CMD_SESSION_UNSET_STATUS_CB, + CMD_SESSION_SET_PORT_STATUS_CB, + CMD_SESSION_UNSET_PORT_STATUS_CB, + + CMD_ADVERT_CREATE, + CMD_ADVERT_DESTROY, + + CMD_ADVERT_SET_SERVICE_TYPE, + CMD_ADVERT_SET_AUTO_ACCEPT, + CMD_ADVERT_ADD_INFO, + CMD_ADVERT_GET_INFO, + CMD_ADVERT_REMOVE_INFO, + CMD_ADVERT_SET_STATUS, + CMD_ADVERT_SET_DISCOVERY_TECH, + CMD_ADVERT_SET_PREF_CONN, + CMD_ADVERT_SET_P2P_ROLE, + CMD_ADVERT_GET_P2P_ROLE, + CMD_ADVERT_SET_P2P_CONFIG, + CMD_ADVERT_GET_P2P_CONFIG, + CMD_ADVERT_SET_P2P_RSP, + + CMD_ADVERT_START, + CMD_ADVERT_STOP, + CMD_ADVERT_CHANGE, + + CMD_SEEK_CREATE, + CMD_SEEK_DESTROY, + + CMD_SEEK_ADD_INFO, + CMD_SEEK_REMOVE_INFO, + CMD_SEEK_SET_DISCOVERY_TECH, + CMD_SEEK_SET_PREF_CONN, + + CMD_SEEK_START, + CMD_SEEK_STOP, + + CMD_SESSION_CREATE, + CMD_SESSION_DESTROY, + + CMD_SESSION_GET_MAC, + CMD_SESSION_GET_ID, + + CMD_SESSION_SET_INFO, + CMD_SESSION_GET_INFO, + + CMD_SESSION_SET_P2P_ROLE_SCHEME, + CMD_SESSION_GET_P2P_ROLE_SCHEME, + + CMD_SESSION_SET_P2P_CONFIG_METHOD, + CMD_SESSION_GET_P2P_CONFIG_METHOD, + + CMD_SESSION_GET_CLOSE_STATUS, + + CMD_SESSION_CONNECT, + CMD_SESSOIN_CONFIRM, + CMD_SESSION_GET_HANDLE, + CMD_SESSION_SET_STATE_READY, + CMD_SESSION_CLOSE, + CMD_SESSION_BIND_PORT, + CMD_SESSION_RELEASE_PORT, + + CMD_INVALID = 255, +}; + +typedef struct { + int cmd; + char* menu_str; +} menu_str_s; + +menu_str_s g_menu_str[] = { + { CMD_QUIT, "CMD_QUIT" }, + { CMD_FULL_MENU, "CMD_FULL_MENU" }, + { CMD_INITIALIZE, "CMD_INITIALIZE" }, + { CMD_DEINITIALIZE, "CMD_DEINITIALIZE" }, + + {CMD_SEEK_SET_SEARCH_RESULT_CB, "CMD_SEEK_SET_SEARCH_RESULT_CB"}, + {CMD_SEEK_UNSET_SEARCH_RESULT_CB, "CMD_SEEK_UNSET_SEARCH_RESULT_CB"}, + {CMD_ADVERT_SET_STATUS_CHANGED_CB, "CMD_ADVERT_SET_STATUS_CHANGED_CB"}, + {CMD_ADVERT_UNSET_STATUS_CHANGED_CB, "CMD_ADVERT_UNSET_STATUS_CHANGED_CB"}, + {CMD_SESSION_SET_REQUEST_CB, "CMD_SESSION_SET_REQUEST_CB"}, + {CMD_SESSION_UNSET_REQUST_CB, "CMD_SESSION_UNSET_REQUST_CB"}, + {CMD_SESSION_SET_CONFIG_REQUEST_CB, "CMD_SESSION_SET_CONFIG_REQUEST_CB"}, + {CMD_SESSION_UNSET_CONFIG_REQUEST_CB, "CMD_SESSION_UNSET_CONFIG_REQUEST_CB"}, + {CMD_SESSION_SET_CONNECT_STATUS_CB, "CMD_SESSION_SET_CONNECT_STATUS_CB"}, + {CMD_SESSION_UNSET_CONNECT_STATUS_CB, "CMD_SESSION_UNSET_CONNECT_STATUS_CB"}, + {CMD_SESSION_SET_STATUS_CB, "CMD_SESSION_SET_STATUS_CB"}, + {CMD_SESSION_UNSET_STATUS_CB, "CMD_SESSION_UNSET_STATUS_CB"}, + {CMD_SESSION_SET_PORT_STATUS_CB, "CMD_SESSION_SET_PORT_STATUS_CB"}, + {CMD_SESSION_UNSET_PORT_STATUS_CB, "CMD_SESSION_UNSET_PORT_STATUS_CB"}, + + {CMD_ADVERT_CREATE, "CMD_ADVERT_CREATE"}, + {CMD_ADVERT_DESTROY, "CMD_ADVERT_DESTROY"}, + + {CMD_ADVERT_SET_SERVICE_TYPE, "CMD_ADVERT_SET_SERVICE_TYPE"}, + {CMD_ADVERT_SET_AUTO_ACCEPT, "CMD_ADVERT_SET_AUTO_ACCEPT"}, + {CMD_ADVERT_ADD_INFO, "CMD_ADVERT_ADD_INFO"}, + {CMD_ADVERT_GET_INFO, "CMD_ADVERT_GET_INFO"}, + {CMD_ADVERT_REMOVE_INFO, "CMD_ADVERT_REMOVE_INFO"}, + {CMD_ADVERT_SET_STATUS, "CMD_ADVERT_SET_STATUS"}, + {CMD_ADVERT_SET_DISCOVERY_TECH, "CMD_ADVERT_SET_DISCOVERY_TECH"}, + {CMD_ADVERT_SET_PREF_CONN, "CMD_ADVERT_SET_PREF_CONN"}, + {CMD_ADVERT_SET_P2P_ROLE, "CMD_ADVERT_SET_P2P_ROLE"}, + {CMD_ADVERT_GET_P2P_ROLE, "CMD_ADVERT_GET_P2P_ROLE"}, + {CMD_ADVERT_SET_P2P_CONFIG, "CMD_ADVERT_SET_P2P_CONFIG"}, + {CMD_ADVERT_GET_P2P_CONFIG, "CMD_ADVERT_GET_P2P_CONFIG"}, + {CMD_ADVERT_SET_P2P_RSP, "CMD_ADVERT_SET_P2P_RSP"}, + + {CMD_ADVERT_START, "CMD_ADVERT_START"}, + {CMD_ADVERT_STOP, "CMD_ADVERT_STOP"}, + {CMD_ADVERT_CHANGE, "CMD_ADVERT_CHANGE"}, + + {CMD_SEEK_CREATE, "CMD_SEEK_CREATE"}, + {CMD_SEEK_DESTROY, "CMD_SEEK_DESTROY"}, + + {CMD_SEEK_ADD_INFO, "CMD_SEEK_ADD_INFO"}, + {CMD_SEEK_REMOVE_INFO, "CMD_SEEK_REMOVE_INFO"}, + {CMD_SEEK_SET_DISCOVERY_TECH, "CMD_SEEK_SET_DISCOVERY_TECH"}, + {CMD_SEEK_SET_PREF_CONN, "CMD_SEEK_SET_PREF_CONN"}, + + {CMD_SEEK_START, "CMD_SEEK_START"}, + {CMD_SEEK_STOP, "CMD_SEEK_STOP"}, + + {CMD_SESSION_CREATE, "CMD_SESSION_CREATE"}, + {CMD_SESSION_DESTROY, "CMD_SESSION_DESTROY"}, + + {CMD_SESSION_GET_MAC, "CMD_SESSION_GET_MAC"}, + {CMD_SESSION_GET_ID, "CMD_SESSION_GET_ID"}, + + {CMD_SESSION_SET_INFO, "CMD_SESSION_SET_INFO"}, + {CMD_SESSION_GET_INFO, "CMD_SESSION_GET_INFO"}, + + {CMD_SESSION_SET_P2P_ROLE_SCHEME, "CMD_SESSION_SET_P2P_ROLE_SCHEME"}, + {CMD_SESSION_GET_P2P_ROLE_SCHEME, "CMD_SESSION_GET_P2P_ROLE_SCHEME"}, + + {CMD_SESSION_SET_P2P_CONFIG_METHOD, "CMD_SESSION_SET_P2P_CONFIG_METHOD"}, + {CMD_SESSION_GET_P2P_CONFIG_METHOD, "CMD_SESSION_GET_P2P_CONFIG_METHOD"}, + + {CMD_SESSION_GET_CLOSE_STATUS, "CMD_SESSION_GET_CLOSE_STATUS"}, + + {CMD_SESSION_CONNECT, "CMD_SESSION_CONNECT"}, + {CMD_SESSOIN_CONFIRM, "CMD_SESSOIN_CONFIRM"}, + {CMD_SESSION_GET_HANDLE, "CMD_SESSION_GET_HANDLE"}, + {CMD_SESSION_SET_STATE_READY, "CMD_SESSION_SET_STATE_READY"}, + {CMD_SESSION_CLOSE, "CMD_SESSION_CLOSE"}, + {CMD_SESSION_BIND_PORT, "CMD_SESSION_BIND_PORT"}, + {CMD_SESSION_RELEASE_PORT, "CMD_SESSION_RELEASE_PORT"}, + + { -1, NULL }, }; + +struct appdata { + GMainLoop* main_loop; +}; + +struct appdata* g_test_appdata; + +static asp_advert_service_h local_advert = NULL; +static asp_seek_service_h local_seek = NULL; +static asp_session_h local_session = NULL; + +struct appdata* get_appdata() +{ + return g_test_appdata; +} + +void set_appdata(struct appdata* p) +{ + g_test_appdata = p; +} + +static inline void prt_help(const char *cmd) +{ + printf("%s -t [dest ID]\n", cmd); + printf(" -u [my ID]\n"); + printf(" -p [passwd]\n"); + printf(" -a [alias]\n"); +} + +static int get_param(int argc, char **argv, struct appdata *ad) +{ + printf("Parsing argument...\n"); + int opt; + while ((opt = getopt(argc, argv, "t:u:p:a:")) != -1) { + printf("Parsing argument...:%c\n", opt); + switch (opt) { + case 't': + default: + prt_help(argv[0]); + return -1; + } + } + + printf("Argument: \n"); + + return 0; +} + +void usage() +{ + printf("Call Test Program\n"); + printf(" %d: quit\n", CMD_QUIT); + printf(" %d: Full menu\n", CMD_FULL_MENU); +} + +char* cmd_transform(char*str) +{ + int i, j; + int len; + static char static_buffer[255]; + + if (str == NULL) + return ""; + + len = strlen(str); + if (len == 0) + return ""; + + /* remove "CMD_" */ + /* lower char */ + /* replance "_" to space */ + for (i = 0, j = 4; i < len; i++, j++) { + + if (str[j] >= 'A' && str[j] <= 'Z') + static_buffer[i] = str[j] + 'a' - 'A'; + else if (str[j] == '_') + static_buffer[i] = ' '; + else + static_buffer[i] = str[j]; + } + static_buffer[j] = '\0'; + + return static_buffer; +} + +void usage_full() +{ + int i; + printf("Call Test Program\n"); + + for (i = 0; g_menu_str[i].cmd != -1; i++) { + if (i%3 == 0) + printf("\n"); + if (i == 2 || i == 4 || i == 6 || i == 12 || i == 17 || + i == 20 || i == 24 || i == 26 || i == 28 || i == 36) + printf(MAKE_GREEN); + printf(" %02d: %-32s ", g_menu_str[i].cmd, + cmd_transform(g_menu_str[i].menu_str)); + if (i == 2 || i == 4 || i == 6 || i == 12 || i == 17 || + i == 20 || i == 24 || i == 26 || i == 28 || i == 36) + printf(RESET_COLOR); + + } + printf("\n"); +} + +int is_digit(const char* str) +{ + int len; + int i; + + if (str == NULL) + return -1; + + if (strlen(str) == 0) + return -1; + + len = strlen(str); + for (i = 0; i < len; i++) { + if (str[i] < '0' || str[i] > '9') + return -2; + } + + return 0; +} + +void seek_search_result_cb(int error_code, + asp_seek_service_h seek_service, + const char *service_mac, + unsigned int adv_id, + asp_wps_type_e config_method, + const char *instance_name, + const char *service_info, + int info_size, + unsigned char status, + void *user_data) +{ + return; +} + +void advert_status_changed_cb(asp_advert_service_h adv_service, + asp_service_status_e status, + asp_advert_status_reason_e reason, + void *user_data) +{ + return; +} + +void session_request_cb(int error_code, + asp_advert_service_h adv_service, + asp_session_h session, + const char *device_name, + const char *info, + int info_size, + bool get_network_config_pin, + const char *network_config_pin, + void *user_data) +{ + return; +} + +void session_config_request_cb(int error_code, + asp_session_h session, + bool get_pin, + const char *config_pin, + void *user_data) +{ + return; +} + +void session_connect_status_cb(int error_code, + asp_session_h session, + asp_connect_status_e status, + const char *deferred_resp, + int resp_size, + void *user_data) +{ + return; +} + +void session_status_cb(int error_code, + asp_session_h session, + asp_session_state_e state, + const char *additional_info, + void *user_data) +{ + return; +} + +void session_port_status_cb(int error_code, + asp_session_h session, + const char *ip_address, + int port, + int proto, + asp_port_status_e status, + void *user_data) +{ + return; +} + +int init_asp_client(struct appdata *ad) +{ + __FUNC_ENTER__; + int ret; + + ret = asp_initialize(); + printf("asp_initialize() result=[%d]\n", ret); + + ret = asp_seek_set_search_result_cb(seek_search_result_cb, (void*)ad); + printf("asp_seek_set_search_result_cb result=[%d]\n", ret); + + ret = asp_advert_set_status_changed_cb(advert_status_changed_cb, (void*)ad); + printf("asp_advert_set_status_changed_cb result=[%d]\n", ret); + + ret = asp_session_set_request_cb(session_request_cb, (void*)ad); + printf("asp_session_set_request_cb result=[%d]\n", ret); + + ret = asp_session_set_config_request_cb(session_config_request_cb, (void*)ad); + printf("asp_session_set_config_request_cb result=[%d]\n", ret); + + ret = asp_session_set_connect_status_cb(session_connect_status_cb, (void*)ad); + printf("asp_session_set_connect_status_cb result=[%d]\n", ret); + + ret = asp_session_set_status_cb(session_status_cb, (void*)ad); + printf("asp_session_set_status_cb result=[%d]\n", ret); + + ret = asp_session_set_port_status_cb(session_port_status_cb, (void*)ad); + printf("asp_session_set_port_status_cb result=[%d]\n", ret); + + __FUNC_EXIT__; + return ret; +} + +void test_full_menu() +{ + usage_full(); + + return; +} + +void test_quit() +{ + struct appdata *ad = get_appdata(ad); + + printf("Bye\n"); + g_main_loop_quit(ad->main_loop); + + return; +} + +void test_init() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = init_asp_client(ad); + printf("init_asp_client() result=[%d]\n", ret); + + return; +} + +void test_deinit() +{ + int ret = 0; + + ret = asp_deinitialize(); + printf("asp_deinitialize() result=[%d]\n", ret); +} + +void test_asp_seek_set_search_result_cb() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = asp_seek_set_search_result_cb(seek_search_result_cb, ad); + printf("asp_seek_set_search_result_cb() result=[%d]\n", ret); + + return; + +} +void test_asp_seek_unset_search_result_cb() +{ + int ret = 0; + + ret = asp_seek_unset_search_result_cb(); + printf("asp_seek_unset_search_result_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_advert_set_status_changed_cb() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = asp_advert_set_status_changed_cb(advert_status_changed_cb, ad); + printf("asp_advert_unset_status_changed_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_advert_unset_status_changed_cb() +{ + int ret = 0; + + ret = asp_advert_unset_status_changed_cb(); + printf("asp_advert_unset_status_changed_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_set_request_cb() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = asp_session_set_request_cb(session_request_cb, ad); + printf("asp_session_set_request_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_unset_request_cb() +{ + int ret = 0; + + ret = asp_session_unset_request_cb(); + printf("asp_session_unset_request_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_set_config_request_cb() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = asp_session_set_config_request_cb(session_config_request_cb, ad); + printf("asp_session_set_config_request_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_unset_config_request_cb() +{ + int ret = 0; + + ret = asp_session_unset_config_request_cb(); + printf("asp_session_unset_config_request_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_set_connect_status_cb() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = asp_session_set_connect_status_cb(session_connect_status_cb, ad); + printf("asp_session_set_connect_status_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_unset_connect_status_cb() +{ + int ret = 0; + + ret = asp_session_unset_connect_status_cb(); + printf("asp_session_unset_connect_status_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_set_status_cb() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = asp_session_set_status_cb(session_status_cb, ad); + printf("asp_session_set_status_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_unset_status_cb() +{ + int ret = 0; + + ret = asp_session_unset_status_cb(); + printf("asp_session_unset_status_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_set_port_status_cb() +{ + struct appdata *ad = get_appdata(ad); + int ret = 0; + + ret = asp_session_set_port_status_cb(session_port_status_cb, ad); + printf("asp_session_set_port_status_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_session_unset_port_status_cb() +{ + int ret = 0; + + ret = asp_session_unset_connect_status_cb(); + printf("asp_session_unset_connect_status_cb() result=[%d]\n", ret); + + return; +} + +void test_asp_advert_create() +{ + char instance_name[64] = {0, }; + int ret = 0; + + printf("Input instance :\n"); + if (scanf(" %64[^\n]s", instance_name) < 0) + return; + + if (strlen(instance_name) <= 0) { + printf("invalid instance_name !!\n"); + return; + } + + printf("instance_name: [%s]\n", instance_name); + ret = asp_advert_create(instance_name, &local_advert); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_create"RESET_COLOR"\n"); + printf("local_advert [%p]\n", local_advert); + } else { + printf(MAKE_RED"asp_advert_create : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_destroy() +{ + int ret = 0; + + ret = asp_advert_destroy(local_advert); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_destroy"RESET_COLOR"\n"); + local_advert = NULL; + } else { + printf(MAKE_RED"asp_advert_destroy : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_service_type() +{ + char service_type[256] = {0, }; + int ret = 0; + + printf("Input advertise_type :\n"); + if (scanf(" %256[^\n]s", service_type) < 0) + return; + + if (strlen(service_type) <= 0) { + printf("invalid advertise_type !!\n"); + return; + } + + printf("service_type: [%s]\n", service_type); + ret = asp_advert_set_service_type(local_advert, service_type); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_service_type"RESET_COLOR"\n");; + } else { + printf(MAKE_RED"asp_advert_set_service_type : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_auto_accept() +{ + int auto_accept = 0; + int ret = 0; + + printf("Enter ASP service auto accept : \n"); + if (scanf("%d", &auto_accept) < 0) + return; + + ret = asp_advert_set_auto_accept(local_advert, auto_accept); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_auto_accept"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_set_auto_accept : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_add_info() +{ + char key[256] = {0, }; + char value[256] = {0, }; + int ret = 0; + + printf("Enter ASP service information key :\n"); + if (scanf(" %256[^\n]s", key) < 0) + return; + printf("Enter ASP service information value :\n"); + if (scanf(" %256[^\n]s", value) < 0) + return; + + ret = asp_advert_add_info(local_advert, key, value); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_add_info"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_add_info : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_get_info() +{ + int length = 0; + char key[256] = {0, }; + char *value = NULL; + int ret = 0; + + printf("Enter ASP service information key :\n"); + if (scanf(" %256[^\n]s", key) < 0) + return; + + ret = asp_advert_get_info(local_advert, key, + &length, &value); + if (ret == ASP_ERROR_NONE) { + if(value != NULL) + printf(MAKE_GREEN"value [%s]"RESET_COLOR"\n", value); + printf(MAKE_GREEN"asp_advert_get_info"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_get_info : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_remove_info() +{ + char key[256] = {0, }; + int ret = 0; + + printf("Enter ASP service information key :\n"); + if (scanf(" %256[^\n]s", key) < 0) + return; + + ret = asp_advert_remove_info(local_advert, key); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_remove_info"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_remove_info : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_status() +{ + unsigned char status = 0; + int ret = 0; + + printf("Enter ASP service status : \n"); + printf("1 = available to use\n"); + printf("0 = not available to use\n"); + if (scanf("%hhu", &status) < 0) + return; + + ret = asp_advert_set_status(local_advert, status); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_status"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_set_status : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_discovery_tech() +{ + int tech = 0; + int ret = 0; + + printf("Enter ASP advertising tech : \n"); + printf("Please enter logical OR value of below techs\n"); + printf("ASP_DISCOVERY_TECH_P2P = 0x01\n"); + printf("ASP_DISCOVERY_TECH_BLE = 0x02\n"); + printf("ASP_DISCOVERY_TECH_NFC = 0x04\n"); + printf("ASP_DISCOVERY_TECH_INFRA = 0x08\n"); + printf("ASP_DISCOVERY_TECH_NAN = 0x10\n"); + if (scanf("%d", &tech) < 0) + return; + + ret = asp_advert_set_discovery_tech(local_advert, tech); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_discovery_tech"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_set_discovery_tech : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_preferred_connection() +{ + unsigned char pref = 0; + int ret = 0; + + printf("Enter ASP advertising preferred connection : \n"); + if (scanf("%hhu", &pref) < 0) + return; + + ret = asp_advert_set_preferred_connection(local_advert, pref); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_preferred_connection"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_set_preferred_connection : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_p2p_role_scheme() +{ + unsigned char role = 0; + int ret = 0; + + printf("Enter ASP p2p service role : "); + printf("0 = Don't care\n"); + printf("1 = The receiving interface shall be the GO\n"); + if (scanf("%hhu", &role) < 0) + return; + + ret = asp_advert_set_p2p_role_scheme(local_advert, role); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_p2p_role_scheme"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_set_p2p_role_scheme : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_get_p2p_role_scheme() +{ + asp_advert_p2p_role_scheme_e role = 0; + int ret = 0; + + + ret = asp_advert_get_p2p_role_scheme(local_advert, &role); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_get_p2p_role_scheme"RESET_COLOR"\n"); + printf(MAKE_GREEN"role [%d]"RESET_COLOR"\n", (int)role); + } else { + printf(MAKE_RED"asp_advert_get_p2p_role_scheme : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_p2p_config_method() +{ + unsigned int config_method = 0; + int ret = 0; + + printf("Enter ASP service p2p config method : \n"); + printf("1 = P2Ps default configuration or WSC PIN\n"); + printf("2 = WSC PIN method both display and keypad\n"); + printf("3 = WSC PIN method only display\n"); + printf("4 = WSC PIN method only keypad\n"); + if (scanf(" %d", &config_method) < 0) + return; + + ret = asp_advert_set_p2p_config_method(local_advert, config_method); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_p2p_config_method"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_set_p2p_config_method : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_get_p2p_config_method() +{ + unsigned int config_method = 0; + int ret = 0; + + ret = asp_advert_get_p2p_config_method(local_advert, &config_method); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_get_p2p_config_method [%u] "RESET_COLOR"\n", config_method); + } else { + printf(MAKE_RED"asp_advert_get_p2p_config_method : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_set_p2p_response() +{ + char service_rsp[256] = {0, }; + int ret = 0; + + printf("Input service_rsp :\n"); + if (scanf(" %256[^\n]s", service_rsp) < 0) + return; + + if (strlen(service_rsp) <= 0) + return; + + printf("service_info: [%s]\n", service_rsp); + ret = asp_advert_set_p2p_response(local_advert, service_rsp, strlen(service_rsp)); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_set_p2p_response"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_set_p2p_response : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_start_advertising() +{ + int ret = 0; + + ret = asp_advert_start_advertising(local_advert); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_start_advertising"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_start_advertising : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_stop_advertising() +{ + int ret = 0; + + ret = asp_advert_stop_advertising(local_advert); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_start_advertising"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_start_advertising : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_advert_change_service_status() +{ + unsigned char status = 0; + int ret = 0; + + ret = asp_advert_change_service_status(local_advert, status); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_advert_change_service_status"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_advert_change_service_status : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_create() +{ + char service_type[64] = {0, }; + int ret = 0; + + printf("Input service_type :\n"); + if (scanf(" %64[^\n]s", service_type) < 0) + return; + + if (strlen(service_type) <= 0) + return; + + printf("service_type: [%s]\n", service_type); + ret = asp_seek_create(service_type, &local_seek); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_create"RESET_COLOR"\n"); + printf("seek handle [%p]\n", local_seek); + } else { + printf(MAKE_RED"asp_seek_create : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_destroy() +{ + int ret = 0; + + ret = asp_seek_destroy(local_seek); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_destroy"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_seek_destroy : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_add_info() +{ + char key[256] = {0, }; + int ret = 0; + + printf("Enter ASP service information key :\n"); + if (scanf(" %256[^\n]s", key) < 0) + return; + + ret = asp_seek_add_info(local_seek, key); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_add_info"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_seek_add_info : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_remove_info() +{ + char key[256] = {0, }; + int ret = 0; + + printf("Enter ASP service information key :\n"); + if (scanf(" %256[^\n]s", key) < 0) + return; + + ret= asp_seek_remove_info(local_seek, key); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_remove_info"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_seek_remove_info : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_set_discovery_tech() +{ + int tech = 0; + int ret = 0; + + printf("Enter ASP seeking tech : \n"); + printf("Please enter logical OR value of below techs\n"); + printf("ASP_DISCOVERY_TECH_P2P = 0x01\n"); + printf("ASP_DISCOVERY_TECH_BLE = 0x02\n"); + printf("ASP_DISCOVERY_TECH_NFC = 0x04\n"); + printf("ASP_DISCOVERY_TECH_INFRA = 0x08\n"); + printf("ASP_DISCOVERY_TECH_NAN = 0x10\n"); + if (scanf("%d", &tech) < 0) + return; + + ret = asp_seek_set_discovery_tech(local_seek, tech); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_set_discovery_tech"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_seek_set_discovery_tech : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_set_preferred_connection() +{ + unsigned char pref = 0; + int ret = 0; + + printf("Enter ASP seeking preferred connection : \n"); + if (scanf("%hhu", &pref) < 0) + return; + + ret = asp_seek_set_preferred_connection(local_seek, pref); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_set_preferred_connection"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_seek_set_preferred_connection : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_start() +{ + int ret = 0; + + ret = asp_seek_start(local_seek); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_start"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_seek_start : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_seek_stop() +{ + int ret = 0; + + ret = asp_seek_stop(local_seek); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_seek_stop"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_seek_stop : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_create() +{ + int ret = 0; + + char *mac_addr = NULL; + unsigned int adv_id = 0; + + printf("\nEnter advertise id: "); + if (scanf("%u", &adv_id) < 1) + return; + + printf("\nEnter target address: "); + if (scanf("%18ms", &mac_addr) < 1) + return; + + ret = asp_session_create(mac_addr, adv_id, &local_session); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_create"RESET_COLOR"\n"); + printf("session id [%p]", local_session); + } else { + printf(MAKE_RED"asp_session_create : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_destroy() +{ + int ret = 0; + + ret = asp_session_destroy(local_session); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_destroy"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_destroy : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_get_mac() +{ + char *session_mac = NULL; + int ret = 0; + + ret = asp_session_get_mac(local_session, &session_mac); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_get_mac"RESET_COLOR"\n"); + printf("session_mac [%s]", session_mac); + } else { + printf(MAKE_RED"asp_session_get_mac : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_get_id() +{ + unsigned int session_id = 0; + int ret = 0; + + ret = asp_session_get_id(local_session, &session_id); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_get_id"RESET_COLOR"\n"); + printf("session_info [%u]", session_id); + } else { + printf(MAKE_RED"asp_session_get_id : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_set_info() +{ + char *session_info = NULL; + int ret = 0; + + printf("\nEnter session_info: "); + if (scanf("%128ms", &session_info) < 1) + return; + + ret = asp_session_set_info(local_session, session_info); + g_free(session_info); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_set_info"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_set_info : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_get_info() +{ + char *session_info = NULL; + int ret = 0; + + ret = asp_session_get_info(local_session, &session_info); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_get_info"RESET_COLOR"\n"); + printf("session_info [%s]", session_info); + } else { + printf(MAKE_RED"asp_session_get_info : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_set_p2p_role_scheme() +{ + int role = ASP_ADVERT_P2P_ROLE_SCHEME_ANY; + int ret = 0; + + printf("\nEnter network role: "); + printf("\n0 = Don't care"); + printf("\n1 = shall be the GO\n"); + if (scanf("%d", &role) < 1) + return; + + ret = asp_session_set_p2p_role_scheme(local_session, + (asp_advert_p2p_role_scheme_e)role); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_set_p2p_role_scheme"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_set_p2p_role_scheme : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_get_p2p_role_scheme() +{ + asp_advert_p2p_role_scheme_e role; + int ret = 0; + + ret = asp_session_get_p2p_role_scheme(local_session, &role); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_get_p2p_role_scheme"RESET_COLOR"\n"); + printf("network role [%u]", role); + } else { + printf(MAKE_RED"asp_session_get_p2p_role_scheme : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_set_p2p_config_method() +{ + int config_method = ASP_WPS_TYPE_NONE; + int ret = 0; + + printf("\nEnter network config: "); + printf("\n1 = P2Ps default configuration or WSC PIN\n"); + printf("\n2 = WSC PIN method only\n"); + if (scanf("%d", &config_method) < 1) + return; + + ret = asp_session_set_p2p_config_method(local_session, + (asp_wps_type_e)config_method); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_set_p2p_config_method"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_set_p2p_config_method : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_get_p2p_config_method() +{ + asp_wps_type_e config_method = 0; + int ret = 0; + + ret = asp_session_get_p2p_config_method(local_session, &config_method); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_get_p2p_config_method"RESET_COLOR"\n"); + printf("network config [%d]", config_method); + } else { + printf(MAKE_RED"asp_session_get_p2p_config_method : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_get_close_status() +{ + int status = 0; + int ret = 0; + + ret = asp_session_get_close_status(local_session, &status); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_get_close_status"RESET_COLOR"\n"); + printf("close status [%d]", status); + } else { + printf(MAKE_RED"asp_session_get_close_status : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_connect() +{ + int ret = 0; + + ret = asp_session_connect(local_session); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_connect"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_connect : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + return; +} + +void test_asp_session_confirm() +{ + int confirmed = 0; + int ret = 0; + + printf("\nEnter confirm : "); + if (scanf("%d", &confirmed) < 1) + return; + + ret = asp_session_confirm(local_session, confirmed, NULL); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_confirm"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_confirm : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_get_handle() +{ + char *mac_addr = NULL; + unsigned int session_id = 0; + int ret = 0; + + + printf("\nEnter target address: "); + if (scanf("%17ms", &mac_addr) < 1) + return; + + printf("\nEnter session id: "); + if (scanf("%u", &session_id) < 1) + return; + + ret = asp_session_get_handle(mac_addr, session_id, &local_session); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_get_handle"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_get_handle : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_set_state_ready() +{ + int ret = 0; + + ret = asp_session_set_state_ready(local_session); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_set_state_ready"RESET_COLOR"\n"); + local_session = NULL; + } else { + printf(MAKE_RED"asp_session_set_state_ready : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_close() +{ + int ret = 0; + + ret = asp_session_close(local_session); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_close"RESET_COLOR"\n"); + local_session = NULL; + } else { + printf(MAKE_RED"asp_session_close : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_bind_port() +{ + int ret = 0; + + char *ip_address = NULL; + int port = 0; + int proto = 0; + + printf("\nEnter IP address: "); + if (scanf("%17ms", &ip_address) < 1) + return; + + printf("\nEnter port: "); + if (scanf("%i", &port) < 1) + return; + + printf("\nEnter proto: "); + if (scanf("%i", &proto) < 1) + return; + + ret = asp_session_bind_port(local_session, ip_address, port, proto); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_bind_port"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_bind_port : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +void test_asp_session_release_port() +{ + int ret = 0; + + char *ip_address = NULL; + int port = 0; + int proto = 0; + + printf("\nEnter IP address: "); + if (scanf("%17ms", &ip_address) < 1) + return; + + printf("\nEnter port: "); + if (scanf("%i", &port) < 1) + return; + + printf("\nEnter proto: "); + if (scanf("%i", &proto) < 1) + return; + + ret = asp_session_release_port(local_session, ip_address, port, proto); + if (ret == ASP_ERROR_NONE) { + printf(MAKE_GREEN"asp_session_release_port"RESET_COLOR"\n"); + } else { + printf(MAKE_RED"asp_session_release_port : %s ", print_error(ret)); + printf(RESET_COLOR"\n"); + } + + return; +} + +typedef void (*test_func)(void); + +typedef struct { + int cmd; + test_func func; +} menu_func_s; + +menu_func_s g_menu_func[] = { + {CMD_QUIT, test_quit }, + {CMD_FULL_MENU, test_full_menu}, + {CMD_INITIALIZE, test_init }, + {CMD_DEINITIALIZE, test_deinit}, + + {CMD_SEEK_SET_SEARCH_RESULT_CB, test_asp_seek_set_search_result_cb}, + {CMD_SEEK_UNSET_SEARCH_RESULT_CB, test_asp_seek_unset_search_result_cb}, + {CMD_ADVERT_SET_STATUS_CHANGED_CB, test_asp_advert_set_status_changed_cb}, + {CMD_ADVERT_UNSET_STATUS_CHANGED_CB, test_asp_advert_unset_status_changed_cb}, + {CMD_SESSION_SET_REQUEST_CB, test_asp_session_set_request_cb}, + {CMD_SESSION_UNSET_REQUST_CB, test_asp_session_unset_request_cb}, + {CMD_SESSION_SET_CONFIG_REQUEST_CB, test_asp_session_set_config_request_cb}, + {CMD_SESSION_UNSET_CONFIG_REQUEST_CB, test_asp_session_unset_config_request_cb}, + {CMD_SESSION_SET_CONNECT_STATUS_CB, test_asp_session_set_connect_status_cb}, + {CMD_SESSION_UNSET_CONNECT_STATUS_CB, test_asp_session_unset_connect_status_cb}, + {CMD_SESSION_SET_STATUS_CB, test_asp_session_set_status_cb}, + {CMD_SESSION_UNSET_STATUS_CB, test_asp_session_unset_status_cb}, + {CMD_SESSION_SET_PORT_STATUS_CB, test_asp_session_set_port_status_cb}, + {CMD_SESSION_UNSET_PORT_STATUS_CB, test_asp_session_unset_port_status_cb}, + + {CMD_ADVERT_CREATE, test_asp_advert_create}, + {CMD_ADVERT_DESTROY, test_asp_advert_destroy}, + + {CMD_ADVERT_SET_SERVICE_TYPE, test_asp_advert_set_service_type}, + {CMD_ADVERT_SET_AUTO_ACCEPT, test_asp_advert_set_auto_accept}, + {CMD_ADVERT_ADD_INFO, test_asp_advert_add_info}, + {CMD_ADVERT_GET_INFO, test_asp_advert_get_info}, + {CMD_ADVERT_REMOVE_INFO, test_asp_advert_remove_info}, + {CMD_ADVERT_SET_STATUS, test_asp_advert_set_status}, + {CMD_ADVERT_SET_DISCOVERY_TECH, test_asp_advert_set_discovery_tech}, + {CMD_ADVERT_SET_PREF_CONN, test_asp_advert_set_preferred_connection}, + {CMD_ADVERT_SET_P2P_ROLE, test_asp_advert_set_p2p_role_scheme}, + {CMD_ADVERT_GET_P2P_ROLE, test_asp_advert_get_p2p_role_scheme}, + {CMD_ADVERT_SET_P2P_CONFIG, test_asp_advert_set_p2p_config_method}, + {CMD_ADVERT_GET_P2P_CONFIG, test_asp_advert_get_p2p_config_method}, + {CMD_ADVERT_SET_P2P_RSP, test_asp_advert_set_p2p_response}, + + {CMD_ADVERT_START, test_asp_advert_start_advertising}, + {CMD_ADVERT_STOP, test_asp_advert_stop_advertising}, + {CMD_ADVERT_CHANGE, test_asp_advert_change_service_status}, + + {CMD_SEEK_CREATE, test_asp_seek_create}, + {CMD_SEEK_DESTROY, test_asp_seek_destroy}, + + {CMD_SEEK_ADD_INFO, test_asp_seek_add_info}, + {CMD_SEEK_REMOVE_INFO, test_asp_seek_remove_info}, + {CMD_SEEK_SET_DISCOVERY_TECH, test_asp_seek_set_discovery_tech}, + {CMD_SEEK_SET_PREF_CONN, test_asp_seek_set_preferred_connection}, + + {CMD_SEEK_START, test_asp_seek_start}, + {CMD_SEEK_STOP, test_asp_seek_stop}, + + {CMD_SESSION_CREATE, test_asp_session_create}, + {CMD_SESSION_DESTROY, test_asp_session_destroy}, + + {CMD_SESSION_GET_MAC, test_asp_session_get_mac}, + {CMD_SESSION_GET_ID, test_asp_session_get_id}, + + {CMD_SESSION_SET_INFO, test_asp_session_set_info}, + {CMD_SESSION_GET_INFO, test_asp_session_get_info}, + + {CMD_SESSION_SET_P2P_ROLE_SCHEME, test_asp_session_set_p2p_role_scheme}, + {CMD_SESSION_GET_P2P_ROLE_SCHEME, test_asp_session_get_p2p_role_scheme}, + + {CMD_SESSION_SET_P2P_CONFIG_METHOD, test_asp_session_set_p2p_config_method}, + {CMD_SESSION_GET_P2P_CONFIG_METHOD, test_asp_session_get_p2p_config_method}, + + {CMD_SESSION_GET_CLOSE_STATUS, test_asp_session_get_close_status}, + + {CMD_SESSION_CONNECT, test_asp_session_connect}, + {CMD_SESSOIN_CONFIRM, test_asp_session_confirm}, + {CMD_SESSION_GET_HANDLE, test_asp_session_get_handle}, + {CMD_SESSION_SET_STATE_READY, test_asp_session_set_state_ready}, + {CMD_SESSION_CLOSE, test_asp_session_close}, + {CMD_SESSION_BIND_PORT, test_asp_session_bind_port}, + {CMD_SESSION_RELEASE_PORT, test_asp_session_release_port}, + + { -1, NULL }, }; + +void process_input(const char *input, gpointer user_data) +{ + int cmd = -1; + + cmd = strtol(input, NULL, 0); + if (is_digit(input) < 0 || strlen(input) == 0 || errno == ERANGE || errno + == EINVAL) + cmd = CMD_INVALID; + + printf("cmd=[%d]\n", cmd); + g_menu_func[cmd].func(); +} + +static gboolean test_terminal_read_std_input(GIOChannel * source, + GIOCondition condition, gpointer user_data) +{ + int fd = 0; + + static char buf[1024]; + int n; + + errno = 0; + n = read(fd, buf, 1024); + + buf[n - 1] = '\0'; /* remove new line... */ + if (n == 0) + printf("Error: read() from stdin returns 0.\n"); + else if (n < 0) + printf("input: read, err\n"); + else + printf("\n\n"); + + process_input(buf, user_data); + + return TRUE; +} + +int main(int argc, char **argv) +{ + GMainLoop *main_loop; + + struct appdata *ad = NULL; + +#if !GLIB_CHECK_VERSION(2, 36, 0) + g_type_init(); +#endif + + main_loop = g_main_loop_new(NULL, FALSE); + + ad = (struct appdata*)malloc(sizeof(struct appdata)); + + set_appdata(ad); + ad->main_loop = main_loop; + + int r = get_param(argc, argv, ad); + if (r) + return -1; + + + int std_input_fd = 0; + GIOChannel *gio2 = g_io_channel_unix_new(std_input_fd); + g_io_add_watch(gio2, G_IO_IN, (GIOFunc) test_terminal_read_std_input, ad); + g_io_channel_unref(gio2); + + usage_full(); + + g_main_loop_run(main_loop); + + return 0; +} -- 2.7.4 From bcce52379e10615bd1b2a8c4f7d34307a25f6c46 Mon Sep 17 00:00:00 2001 From: Jiung Yu Date: Thu, 20 Apr 2017 18:02:20 +0900 Subject: [PATCH 4/4] ACR-896 continued Change-Id: Id5ecc7868ae727fbf384c411d1574531b5f140b5 Signed-off-by: Yu jiung --- include/asp.h | 142 +++++----------------------------------------------------- 1 file changed, 11 insertions(+), 131 deletions(-) diff --git a/include/asp.h b/include/asp.h index ad518cc..adfa94e 100755 --- a/include/asp.h +++ b/include/asp.h @@ -86,9 +86,8 @@ typedef enum { /** * @brief Enumeration for service discovery mechanism. * @since_tizen 4.0 - * @see asp_advert_set_tech() - * @see asp_advert_get_tech() - * @see asp_seek_set_tech() + * @see asp_advert_set_discovery_tech() + * @see asp_seek_set_discovery_tech() */ typedef enum { ASP_DISCOVERY_TECH_P2P = 1 << 0, /**< Use Wi-Fi P2P for discovery mechanism */ @@ -172,7 +171,7 @@ typedef enum { * @since_tizen 4.0 */ typedef enum { - ASP_SERVICE_STATUS_NOT_ADVERTISED , /**< Service status not advertised */ + ASP_SERVICE_STATUS_NOT_ADVERTISED, /**< Service status not advertised */ ASP_SERVICE_STATUS_ADVERTISED, /**< Service status advertised */ } asp_service_status_e; @@ -392,8 +391,6 @@ typedef void (*asp_session_port_status_cb) (int error_code, /** * @brief Initializes Application Service Platform (ASP). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @return 0 on success, otherwise a negative error value. * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_RESOURCE_BUSY Device or resource busy @@ -407,7 +404,6 @@ int asp_initialize(void); /** * @brief Deinitializes Application Service Platform (ASP). * @since_tizen 4.0 - * @privlevel public * @privilege http://tizen.org/privilege/wifidirect * @return 0 on success, otherwise a negative error value. * @retval #ASP_ERROR_NONE Successful @@ -423,7 +419,6 @@ int asp_deinitialize(void); /** * @brief Registers the callback function that will be invoked when a service found. * @since_tizen 4.0 - * @privlevel public * @param[in] cb The callback function to invoke * @param[in] user_data The user data passed from the callback registration function * @return 0 on success, otherwise a negative error value @@ -443,7 +438,6 @@ int asp_seek_set_search_result_cb(asp_seek_search_result_cb cb, void *user_data) /** * @brief Unregisters the callback function that will invoked when a service found. * @since_tizen 4.0 - * @privlevel public * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_SUPPORTED Not supported @@ -457,7 +451,6 @@ int asp_seek_unset_search_result_cb(void); /** * @brief Registers the callback function that will invoked when the status of an advertisement to a service is changed. * @since_tizen 4.0 - * @privlevel public * @param[in] cb The callback function to invoke * @param[in] user_data The user data passed from the callback registration function * @return 0 on success, otherwise a negative error value @@ -478,7 +471,6 @@ int asp_advert_set_status_changed_cb(asp_advert_status_changed_cb cb, /** * @brief Unregisters the callback function that will invoked when the status of an advertisement to a service is changed. * @since_tizen 4.0 - * @privlevel public * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_SUPPORTED Not supported @@ -492,7 +484,6 @@ int asp_advert_unset_status_changed_cb(void); /** * @brief Registers the callback called when ASP session connection is requested. * @since_tizen 4.0 - * @privlevel public * @param[in] cb The callback function to invoke * @param[in] user_data The user data passed from the callback registration function * @return 0 on success, otherwise a negative error value @@ -509,7 +500,6 @@ int asp_session_set_request_cb(asp_session_request_cb cb, void *user_data); /** * @brief Unregisters the callback called ASP when session connection is requested. * @since_tizen 4.0 - * @privlevel public * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_SUPPORTED Not supported @@ -523,7 +513,6 @@ int asp_session_unset_request_cb(void); /** * @brief Registers the callback called when the session configuration is requested. * @since_tizen 4.0 - * @privlevel public * @param[in] cb The callback function to invoke * @param[in] user_data The user data passed from the callback registration function * @return 0 on success, otherwise a negative error value @@ -542,7 +531,6 @@ int asp_session_set_config_request_cb(asp_session_config_request_cb cb, /** * @brief Unregisters the callback called when the session configuration is requested. * @since_tizen 4.0 - * @privlevel public * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_SUPPORTED Not supported @@ -556,7 +544,6 @@ int asp_session_unset_config_request_cb(void); /** * @brief Registers the callback called when the state of the session connection is changed. * @since_tizen 4.0 - * @privlevel public * @param[in] cb The callback function to invoke * @param[in] user_data The user data passed from the callback registration function * @return 0 on success, otherwise a negative error value @@ -574,7 +561,6 @@ int asp_session_set_connect_status_cb(asp_session_connect_status_cb cb, void *us /** * @brief Unregisters the callback called when the state of the session connection is changed. * @since_tizen 4.0 - * @privlevel public * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_SUPPORTED Not supported @@ -588,7 +574,6 @@ int asp_session_unset_connect_status_cb(void); /** * @brief Registers the callback called when the state of the session is changed. * @since_tizen 4.0 - * @privlevel public * @param[in] cb The callback function to invoke * @param[in] user_data The user data passed from the callback registration function * @return 0 on success, otherwise a negative error value @@ -606,7 +591,6 @@ int asp_session_set_status_cb(asp_session_status_cb cb, void *user_data); /** * @brief Unregisters the callback called when the state of the session is changed. * @since_tizen 4.0 - * @privlevel public * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_SUPPORTED Not supported @@ -620,7 +604,6 @@ int asp_session_unset_status_cb(void); /** * @brief Registers the callback called when the state of the port is changed. * @since_tizen 4.0 - * @privlevel public * @param[in] cb The callback function to invoke * @param[in] user_data The user data passed from the callback registration function * @return 0 on success, otherwise a negative error value @@ -636,7 +619,6 @@ int asp_session_set_port_status_cb(asp_session_port_status_cb cb, void *user_dat /** * @brief Unregisters the callback called when the state of the port is changed. * @since_tizen 4.0 - * @privlevel public * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_SUPPORTED Not supported @@ -650,8 +632,7 @@ int asp_session_unset_port_status_cb(void); /** * @brief Creates the description of a service to be advertised. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect + * @remarks The @a adv_service should be released using asp_advert_destroy(). * @param[in] instance_name Service instance name of a service type to be advertised. * The length of this parameter be 63 byte or less and * encoding shall be single-byte or multi-byte UTF-8 characters. @@ -662,7 +643,6 @@ int asp_session_unset_port_status_cb(void); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -677,14 +657,11 @@ int asp_advert_create(char *instance_name, asp_advert_service_h *adv_service); * @details If asp_advert_start_advertising() was called for a service, * asp_advert_stop_advertising() should be called for it before destroying it. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -701,8 +678,6 @@ int asp_advert_destroy(asp_advert_service_h adv_service); * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] service_type The unique type of a particular service. * this shall be at least 1 character and no more than 15 characters long @@ -715,7 +690,6 @@ int asp_advert_destroy(asp_advert_service_h adv_service); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -733,15 +707,12 @@ int asp_advert_set_service_type(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] auto_accept Enables/Disables auto accept based on the value TRUE/FALSE * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -759,8 +730,6 @@ int asp_advert_set_auto_accept(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] key Service-defined key data specified in Section 6 of RFC6763 * @param[in] value Service-defined value data specified in Section 6 of RFC6763 @@ -771,7 +740,6 @@ int asp_advert_set_auto_accept(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -789,11 +757,9 @@ int asp_advert_add_info(asp_advert_service_h adv_service, * @details Application should set service information after creating service using * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). + * @since_tizen 4.0 * @remarks @a value should not be freed. * It is recommended to make a copy of it to use. - * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] key Service-defined key data specified in Section 6 of RFC6763 * @param[in] length Length of service-defined value data specified in Section 6 of RFC6763 @@ -802,7 +768,6 @@ int asp_advert_add_info(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -821,15 +786,12 @@ int asp_advert_get_info(asp_advert_service_h adv_service, const char *key, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] key Service-defined key data specified to be removed * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -846,8 +808,6 @@ int asp_advert_remove_info(asp_advert_service_h adv_service, const char *key); * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] status Status of the service: * (@c 1 = available to use, @c 0 = not available to use, @@ -856,7 +816,6 @@ int asp_advert_remove_info(asp_advert_service_h adv_service, const char *key); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -875,8 +834,6 @@ int asp_advert_set_status(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] discovery_tech The discovery mechanism; values of * #asp_discovery_tech_e combined with bitwise 'or' @@ -884,7 +841,6 @@ int asp_advert_set_status(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -901,15 +857,12 @@ int asp_advert_set_discovery_tech(asp_advert_service_h adv_service, int discover * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] preferred_connection The preferred connection * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -927,8 +880,6 @@ int asp_advert_set_preferred_connection(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] role The role of the service: \n * #ASP_ADVERT_P2P_ROLE_SCHEME_ANY - All roles are acceptable \n @@ -941,7 +892,6 @@ int asp_advert_set_preferred_connection(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -960,8 +910,6 @@ int asp_advert_set_p2p_role_scheme(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] role The role of the service: \n * #ASP_ADVERT_P2P_ROLE_SCHEME_ANY - All roles are acceptable \n @@ -973,7 +921,6 @@ int asp_advert_set_p2p_role_scheme(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -991,8 +938,6 @@ int asp_advert_get_p2p_role_scheme(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] config_method preferred Wi-Fi Simple Config (WSC) configuration method. * Default value is ASP_WPS_TYPE_DEFAULT. @@ -1000,7 +945,6 @@ int asp_advert_get_p2p_role_scheme(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1017,15 +961,12 @@ int asp_advert_set_p2p_config_method(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_start_advertising(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] config_method preferred Wi-Fi Simple Config (WSC)configuration method. * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1043,8 +984,6 @@ int asp_advert_get_p2p_config_method(asp_advert_service_h adv_service, * asp_advert_create() and before advertising service using * asp_advert_create(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_advert_create() * @param[in] rsp_info Specified for a particular service up to 144 bytes. * You can refer to Wi-Fi Peer-to-Peer Services Technical Specification, @@ -1054,7 +993,6 @@ int asp_advert_get_p2p_config_method(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1142,9 +1080,8 @@ int asp_advert_change_service_status(asp_advert_service_h adv_service, /** * @brief Creates the description of a seek operation. + * @remarks The @a seek_service should be released using asp_seek_destroy(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] service_type Service Type of a service being searched. * this shall be at least 1 character and no more than 15 characters long * contain only US-ASCII [ANSI.X3.4-1986] letters 'A' - 'Z' and @@ -1157,7 +1094,6 @@ int asp_advert_change_service_status(asp_advert_service_h adv_service, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1173,14 +1109,11 @@ int asp_seek_create(char *service_type, asp_seek_service_h *seek_service); * asp_seek_stop() should be called for it before destroying it. * asp_seek_stop(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] seek_service Service seek handle provided by the asp_seek_create() * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1197,7 +1130,6 @@ int asp_seek_destroy(asp_seek_service_h seek_service); * asp_seek_create() and before seeking service using asp_seek_start(). * @since_tizen 4.0 * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] seek_service Service descriptor handle provided by the asp_seek_create() * @param[in] key Service-defined key data to be searched, * specified in Section 6 of RFC6763 @@ -1205,7 +1137,6 @@ int asp_seek_destroy(asp_seek_service_h seek_service); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1221,8 +1152,6 @@ int asp_seek_add_info(asp_seek_service_h seek_service, const char *key); * @details Application should set service information after creating service using * asp_seek_create() and before seeking service using asp_seek_start(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] seek_service Service descriptor handle provided by the asp_seek_create() * @param[in] key Service-defined key data to be searched, * specified in Section 6 of RFC6763 @@ -1230,7 +1159,6 @@ int asp_seek_add_info(asp_seek_service_h seek_service, const char *key); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1246,16 +1174,13 @@ int asp_seek_remove_info(asp_seek_service_h seek_service, const char *key); * @details Application should set service information after creating service using * asp_seek_create() and before seeking service using asp_seek_start(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] adv_service Service descriptor handle provided by the asp_seek_create() * @param[in] discovery_tech The discovery mechanism, values of - * #asp_discovery_tech_e combined with bitiwse 'or' + * #asp_discovery_tech_e combined with bitwise 'or' * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1271,15 +1196,12 @@ int asp_seek_set_discovery_tech(asp_seek_service_h seek_service, int discovery_t * @details Application should set service information after creating service using * asp_seek_create() and before seeking service using asp_seek_start(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect - * @param[in] adv_service Service descriptor handle provided by the asp_seek_create() + * @param[in] seek_service Service descriptor handle provided by the asp_seek_create() * @param[in] preferred_connection The preferred connection * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1340,8 +1262,7 @@ int asp_seek_stop(asp_seek_service_h seek_service); /** * @brief Creates a local Application Service Platform (ASP) session. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect + * @remarks The @a session should be released using asp_session_destroy(). * @param[in] service_mac P2P device address of remote P2P device provided by * asp_seek_search_result_cb() * @param[in] adv_id The advertisement ID provided by @@ -1351,7 +1272,6 @@ int asp_seek_stop(asp_seek_service_h seek_service); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1365,14 +1285,11 @@ int asp_session_create(char *service_mac, unsigned int adv_id, * @brief Destroys a local Application Service Platform (ASP) session. * @details Application should create session by asp_session_create(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1387,11 +1304,9 @@ int asp_session_destroy(asp_session_h session); * @brief Gets the session MAC for an Application Service Platform session. * @details Application should request to connect session by * asp_session_connect() or receive request by asp_session_request_cb(). + * @since_tizen 4.0 * @remarks @a session_mac should not be freed. * It is recommended to make a copy of it to use. - * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * @param[out] session_mac The session MAC is the MAC address of * P2P device which assigned the session ID @@ -1399,7 +1314,6 @@ int asp_session_destroy(asp_session_h session); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1416,15 +1330,12 @@ int asp_session_get_mac(asp_session_h session, char **session_mac); * @details Application should create local session by * asp_session_create() or receive request by asp_session_request_cb(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * @param[out] session_id The session ID * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1442,8 +1353,6 @@ int asp_session_get_id(asp_session_h session, unsigned int *session_id); * asp_session_create() and before requesting to connect * session by asp_session_connect(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * provided by the asp_session_create() * @param[in] session_info Detailed information about the session. @@ -1455,7 +1364,6 @@ int asp_session_get_id(asp_session_h session, unsigned int *session_id); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1471,11 +1379,9 @@ int asp_session_set_info(asp_session_h session, char *session_info); * @details Application should get session_info after creating session by * asp_session_create() and before requesting to connect * session by asp_session_connect(). + * @since_tizen 4.0 * @remarks @a session_info should not be freed. * It is recommended to make a copy of it to use. - * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * provided by the asp_session_create() * @param[out] session_info detailed information about session @@ -1483,7 +1389,6 @@ int asp_session_set_info(asp_session_h session, char *session_info); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1500,8 +1405,6 @@ int asp_session_get_info(asp_session_h session, char **session_info); * asp_session_create() and before requesting to connect * session by asp_session_connect(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * provided by the asp_session_create() * @param[in] role The role of the service: \n @@ -1515,7 +1418,6 @@ int asp_session_get_info(asp_session_h session, char **session_info); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1531,8 +1433,6 @@ int asp_session_set_p2p_role_scheme(asp_session_h session, /** * @brief Gets the Wi-Fi Direct group role in session. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * provided by the asp_session_create() * @param[in] role The role of the service: \n @@ -1545,7 +1445,6 @@ int asp_session_set_p2p_role_scheme(asp_session_h session, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1563,8 +1462,6 @@ int asp_session_get_p2p_role_scheme(asp_session_h session, * asp_session_create() and before requesting to connect * session by asp_session_connect(). * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * provided by the asp_session_create() * @param[in] config_method Preferred WSC Configuration method. @@ -1573,7 +1470,6 @@ int asp_session_get_p2p_role_scheme(asp_session_h session, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1588,8 +1484,6 @@ int asp_session_set_p2p_config_method(asp_session_h session, /** * @brief Gets the Preferred WSC Configuration method. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session Application Service Platform session descriptor handle * provided by the asp_session_create() * @param[out] config_method Preferred WSC Configuration method @@ -1597,7 +1491,6 @@ int asp_session_set_p2p_config_method(asp_session_h session, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1622,7 +1515,6 @@ int asp_session_get_p2p_config_method(asp_session_h session, * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1679,8 +1571,6 @@ int asp_session_confirm(asp_session_h session, bool confirmed, char *pin); /** * @brief Gets the Description of Application Service Platform (ASP) session to be connected. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session_mac The MAC address of the P2P device that assigned * the value of session_id, as provided by * the asp_session_request_cb() callback or @@ -1691,7 +1581,6 @@ int asp_session_confirm(asp_session_h session, bool confirmed, char *pin); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1705,15 +1594,12 @@ int asp_session_get_handle(char *session_mac, unsigned int session_id, /** * @brief Moves an Application Service Platform (ASP) session from Requested state to the Open state. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session ASP session descriptor handle provided by * the asp_session_request_cb() callback * @return 0 on success, otherwise a negative error value * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1754,8 +1640,6 @@ int asp_session_close(asp_session_h session); /** * @brief Requests that incoming connections be allowed on a given port. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session ASP session descriptor handle provided by * the asp_session_request_cb() callback or * asp_session_create() @@ -1766,7 +1650,6 @@ int asp_session_close(asp_session_h session); * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized @@ -1781,8 +1664,6 @@ int asp_session_bind_port(asp_session_h session, char *ip_address, /** * @brief Indicates that the service is no longer utilizing the port in the ASP session. * @since_tizen 4.0 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect * @param[in] session ASP session descriptor handle provided by * the asp_session_request_cb() callback or * asp_session_create() @@ -1793,7 +1674,6 @@ int asp_session_bind_port(asp_session_h session, char *ip_address, * @retval #ASP_ERROR_NONE Successful * @retval #ASP_ERROR_NOT_PERMITTED Operation not permitted * @retval #ASP_ERROR_OUT_OF_MEMORY Out of memory - * @retval #ASP_ERROR_PERMISSION_DENIED Permission denied * @retval #ASP_ERROR_INVALID_PARAMETER Invalid parameter * @retval #ASP_ERROR_NOT_SUPPORTED Not supported * @retval #ASP_ERROR_NOT_INITIALIZED Not initialized -- 2.7.4