From 36819142176d259999aeaa9356c66638959b29c6 Mon Sep 17 00:00:00 2001 From: Yu Jiung Date: Fri, 19 Jun 2015 11:47:56 +0900 Subject: [PATCH] [capi-network-wifi-diret]Merge Tizen 2.4 for sync Change-Id: I1ac445c8ed4de84b932ffb2a2830d526453db639 Signed-off-by: Yu jiung --- AUTHORS | 3 + CMakeLists.txt | 72 +- LICENSE.APLv2 | 202 ++ capi-network-wifi-direct.manifest | 5 + capi-network-wifi-direct.pc.in | 14 - debian/README | 0 debian/capi-network-wifi-direct-dev.install | 4 - debian/capi-network-wifi-direct-dev.postinst | 1 - debian/capi-network-wifi-direct.postinst | 1 - debian/changelog | 88 - debian/compat | 1 - debian/control | 21 - debian/rules | 64 - include/wifi-direct-internal.h | 78 + include/wifi-direct.h | 381 +- packaging/capi-network-wifi-direct.changes | 6 - packaging/capi-network-wifi-direct.manifest | 5 - packaging/capi-network-wifi-direct.spec | 87 +- src/CMakeLists.txt | 121 + src/capi-network-wifi-direct.pc.in | 12 + src/include/wifi-direct-client-proxy.h | 128 + src/include/wifi-direct-ipc.h | 316 ++ src/wifi-direct-client-proxy.c | 4880 ++++++++++++++++++++++++++ test-wifi-direct.manifest | 11 + test/CMakeLists.txt | 48 + test/test-wifi-direct.c | 2754 +++++++++++++++ 26 files changed, 8932 insertions(+), 371 deletions(-) create mode 100644 AUTHORS mode change 100755 => 100644 CMakeLists.txt create mode 100644 LICENSE.APLv2 create mode 100644 capi-network-wifi-direct.manifest delete mode 100755 capi-network-wifi-direct.pc.in delete mode 100644 debian/README delete mode 100644 debian/capi-network-wifi-direct-dev.install delete mode 100644 debian/capi-network-wifi-direct-dev.postinst delete mode 100644 debian/capi-network-wifi-direct.postinst delete mode 100644 debian/changelog delete mode 100644 debian/compat delete mode 100755 debian/control delete mode 100755 debian/rules create mode 100644 include/wifi-direct-internal.h mode change 100644 => 100755 include/wifi-direct.h delete mode 100644 packaging/capi-network-wifi-direct.changes delete mode 100644 packaging/capi-network-wifi-direct.manifest mode change 100755 => 100644 packaging/capi-network-wifi-direct.spec create mode 100644 src/CMakeLists.txt create mode 100755 src/capi-network-wifi-direct.pc.in create mode 100755 src/include/wifi-direct-client-proxy.h create mode 100755 src/include/wifi-direct-ipc.h create mode 100755 src/wifi-direct-client-proxy.c create mode 100755 test-wifi-direct.manifest create mode 100755 test/CMakeLists.txt create mode 100644 test/test-wifi-direct.c diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..1929bb3 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Dongwook Lee +Sungsik Jang +Gibyoung Kim \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100755 new mode 100644 index 5f488a7..33b4ef5 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,70 +1,14 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) -SET(fw_name "capi-network-wifi-direct") +PROJECT(wifi-direct C) -PROJECT(${fw_name}) - -SET(CMAKE_INSTALL_PREFIX /usr) -SET(PREFIX ${CMAKE_INSTALL_PREFIX}) - -SET(INC_DIR include) -INCLUDE_DIRECTORIES(${INC_DIR}) +#SET(PREFIX $(CMAKE_INSTALL_PREFIX)) +SET(prefix "/usr") +SET(EXEC_PREFIX "\${prefix}") +SET(LIBDIR "\${prefix}/lib") +SET(INCLUDEDIR "\${prefix}/include") SET(dependents "capi-base-common") SET(pc_dependents "capi-base-common") -INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_name} REQUIRED ${dependents}) - -IF("${ARCH}" STREQUAL "arm") - ADD_DEFINITIONS("-DTARGET") -ENDIF("${ARCH}" STREQUAL "arm") - -INSTALL( - DIRECTORY ${INC_DIR}/ DESTINATION include/network - FILES_MATCHING - PATTERN "*_private.h" EXCLUDE - PATTERN "${INC_DIR}/*.h" - ) - -SET(PC_NAME ${fw_name}) -SET(PC_REQUIRED ${pc_dependents}) -SET(PC_LDFLAGS -lwifi-direct) - -CONFIGURE_FILE( - ${fw_name}.pc.in - ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc - @ONLY -) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) - -IF(UNIX) - -ADD_CUSTOM_TARGET (distclean @echo cleaning for source distribution) -ADD_CUSTOM_COMMAND( - DEPENDS clean - COMMENT "distribution clean" - COMMAND find - ARGS . - -not -name config.cmake -and \( - -name tester.c -or - -name Testing -or - -name CMakeFiles -or - -name cmake.depends -or - -name cmake.check_depends -or - -name CMakeCache.txt -or - -name cmake.check_cache -or - -name *.cmake -or - -name Makefile -or - -name core -or - -name core.* -or - -name gmon.out -or - -name install_manifest.txt -or - -name *.pc -or - -name *~ \) - | grep -v TC | xargs rm -rf - TARGET distclean - VERBATIM -) - -ENDIF(UNIX) - +ADD_SUBDIRECTORY(src) +ADD_SUBDIRECTORY(test) diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/LICENSE.APLv2 @@ -0,0 +1,202 @@ + + 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-wifi-direct.manifest b/capi-network-wifi-direct.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/capi-network-wifi-direct.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/capi-network-wifi-direct.pc.in b/capi-network-wifi-direct.pc.in deleted file mode 100755 index 3db6030..0000000 --- a/capi-network-wifi-direct.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -# Package Information for pkg-config - -prefix=@PREFIX@ -exec_prefix=/usr -libdir=@LIB_INSTALL_DIR@ -includedir=/usr/include/network - -Name: @PC_NAME@ -Description: @PACKAGE_DESCRIPTION@ -Version: @VERSION@ -Requires: @PC_REQUIRED@ -Libs: -L${libdir} @PC_LDFLAGS@ -Cflags: -I${includedir} - diff --git a/debian/README b/debian/README deleted file mode 100644 index e69de29..0000000 diff --git a/debian/capi-network-wifi-direct-dev.install b/debian/capi-network-wifi-direct-dev.install deleted file mode 100644 index 761a28b..0000000 --- a/debian/capi-network-wifi-direct-dev.install +++ /dev/null @@ -1,4 +0,0 @@ -/usr/include/* -/usr/include/*/* -/usr/lib/pkgconfig/*.pc - diff --git a/debian/capi-network-wifi-direct-dev.postinst b/debian/capi-network-wifi-direct-dev.postinst deleted file mode 100644 index 1a24852..0000000 --- a/debian/capi-network-wifi-direct-dev.postinst +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh diff --git a/debian/capi-network-wifi-direct.postinst b/debian/capi-network-wifi-direct.postinst deleted file mode 100644 index 1a24852..0000000 --- a/debian/capi-network-wifi-direct.postinst +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index bdc8b3a..0000000 --- a/debian/changelog +++ /dev/null @@ -1,88 +0,0 @@ -capi-network-wifi-direct (0.0.4-3) unstable; urgency=low - - * Implementation of wifi_direct_get_device_name / wifi_direct_set_device_name - * Implementation of persistent mode - * Git: framework/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.4-3 - - -- Gibyoung Kim Tue, 11 Dec 2012 17:56:12 +0900 - -capi-network-wifi-direct (0.0.4-2) unstable; urgency=low - - * Update from private - * Git: framework/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.4-2 - - -- Gibyoung Kim Fri, 23 Nov 2012 17:32:45 +0900 - -capi-network-wifi-direct (0.0.4-1) unstable; urgency=low - - * Applied SMACK manifest - * Git: framework/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.4-1 - - -- Sungsik Jang Fri, 21 Sep 2012 13:26:57 +0900 - -capi-network-wifi-direct (0.0.3-1) unstable; urgency=low - - * tagging "tizen_build" - * Git: slp-source.sec.samsung.net:slp/framework/api/wifi-direct - * Tag: tizen_build - - -- Sungsik Jang Mon, 13 Aug 2012 15:49:40 +0900 - -capi-network-wifi-direct (0.0.3-1) unstable; urgency=low - - * added new CAPIs for OSP - * Git: slp-source.sec.samsung.net:slp/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.3-1 - - -- Sungsik Jang Fri, 01 Jun 2012 16:58:40 +0900 - -capi-network-wifi-direct (0.0.2-1) unstable; urgency=low - - * added new CAPI for bada - * Git: slp-source.sec.samsung.net:slp/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.2-1 - - -- Sungsik Jang Wed, 09 May 2012 13:55:22 +0900 - -capi-network-wifi-direct (0.0.1-5) unstable; urgency=low - - * Remove dependent package of pc - * Git: slp-source.sec.samsung.net:slp/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.1-5 - - -- ByungWoo Lee Thu, 03 May 2012 19:17:00 +0900 - -capi-network-wifi-direct (0.0.1-4) unstable; urgency=low - - * Add dependent package of dev package - * Git: slp-source.sec.samsung.net:slp/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.1-4 - - -- ByungWoo Lee Fri, 30 Mar 2012 11:31:10 +0900 - -capi-network-wifi-direct (0.0.1-3) unstable; urgency=low - - * Modified build script for dependent package - * Git: slp-source.sec.samsung.net:slp/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.1-3 - - -- Sungsik Jang Wed, 21 Mar 2012 17:09:14 +0900 - -capi-network-wifi-direct (0.0.1-2) unstable; urgency=low - - * Modified build script for dependent package - * Git: slp-source.sec.samsung.net:slp/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.1-2 - - -- Sungsik Jang Tue, 20 Mar 2012 14:36:49 +0900 - -capi-network-wifi-direct (0.0.1-1) unstable; urgency=low - - * Initial upload : WiFi-Direct API - * Git: slp-source.sec.samsung.net:slp/api/wifi-direct - * Tag: capi-network-wifi-direct_0.0.1-1 - - -- Sungsik Jang Fri, 17 Feb 2012 16:33:16 +0900 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100755 index ad4ce47..0000000 --- a/debian/control +++ /dev/null @@ -1,21 +0,0 @@ -Source: capi-network-wifi-direct -Section: libs -Priority: extra -Maintainer: Dongwook Lee , Sungsik Jang -Build-Depends: debhelper (>= 5), capi-base-common-dev - -Package: capi-network-wifi-direct -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, libwifi-direct -Description: A Network WiFi-Direct Library in Tizen C API - -Package: capi-network-wifi-direct-dev -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-wifi-direct (= ${Source-Version}), capi-base-common-dev -Description: A Network WiFi-Direct Library in Tizen C API (DEV) - -Package: capi-network-wifi-direct-dbg -Architecture: any -Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-wifi-direct (= ${Source-Version}) -Description: A Network WiFi-Direct Library in Tizen C API (DBG) - diff --git a/debian/rules b/debian/rules deleted file mode 100755 index af6171e..0000000 --- a/debian/rules +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/make -f - -CFLAGS = -Wall -g - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif -CMAKE_ROOT_DIR ?= $(CURDIR) -CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp - -configure: configure-stamp -configure-stamp: - dh_testdir - mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. - touch configure-stamp - - -build: build-stamp -build-stamp: configure-stamp - dh_testdir - cd $(CMAKE_BUILD_DIR) && $(MAKE) - touch $@ - -clean: - cd $(CMAKE_ROOT_DIR) - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - rm -f `find . -name *.pc` - rm -rf $(CMAKE_BUILD_DIR) - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - -binary-indep: build install - -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp - dh_installman - dh_link - dh_fixperms - dh_makeshlibs - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure - diff --git a/include/wifi-direct-internal.h b/include/wifi-direct-internal.h new file mode 100644 index 0000000..17483a1 --- /dev/null +++ b/include/wifi-direct-internal.h @@ -0,0 +1,78 @@ +/* + * Copyiright (c) 2011-2013 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 __WIFI_DIRECT_INTERNAL_H__ +#define __WIFI_DIRECT_INTERNAL_H__ + +/** + * @file wifi-direct-internal.h + * @brief This file declares has API of the wifi-direct library + */ + +#include "wifi-direct.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @brief Rejects the connection request from other device now in progress. + * @since_tizen 2.3 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address The MAC address of rejected device + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + */ +int wifi_direct_reject_connection(char *mac_address); + +/** + * @brief Accepts a connection requested from PEER. + * @since_tizen 2.3 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address MAC Address of the PEER. + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_reject_connection() + */ +int wifi_direct_accept_connection(char *mac_address); + + +#ifdef __cplusplus +} +#endif + + +#endif /* __WIFI_DIRECT_INTERNAL_H_*/ diff --git a/include/wifi-direct.h b/include/wifi-direct.h old mode 100644 new mode 100755 index 6db713b..701108c --- a/include/wifi-direct.h +++ b/include/wifi-direct.h @@ -1,19 +1,23 @@ /* -* Copyright (c) 2011 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. + * wifi-direct + * + * Copyright (c) 2012 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_WIFI_DIRECT_H__ #define __TIZEN_NET_WIFI_DIRECT_H__ @@ -229,6 +233,18 @@ typedef enum { } wifi_direct_service_type_e; /** +* @brief Enumeration for Wi-Fi Display device type. +* @since_tizen 2.4 +*/ +typedef enum { + WIFI_DIRECT_DISPLAY_TYPE_SOURCE, /**< Configure as WFD Source*/ + WIFI_DIRECT_DISPLAY_TYPE_PRISINK, /**< Configure as WFD Primary Sink */ + WIFI_DIRECT_DISPLAY_TYPE_SECSINK, /**< Configure as WFD Secondary Sink */ + WIFI_DIRECT_DISPLAY_TYPE_DUAL, /**< Configure as WFD Dual Role */ + WIFI_DIRECT_DISPLAY_TYPE_MAX, +} wifi_direct_display_type_e; + +/** * @brief Enumeration for Wi-Fi Direct service Discovery state. * @since_tizen 2.3 */ @@ -253,6 +269,7 @@ typedef enum { /** * @brief Wi-Fi Direct buffer structure to store result of peer discovery. * @since_tizen 2.3 + * @remarks You can use APIs for wifi-direct display function instead of is_miracast_device value which is deprecated since 2.4. */ typedef struct { @@ -278,6 +295,7 @@ typedef struct /** * @brief Wi-Fi Direct buffer structure to store information of connected peer. * @since_tizen 2.3 + * @remarks You can use APIs for wifi-direct display function instead of is_miracast_device value which is deprecated since 2.4. */ typedef struct { @@ -290,7 +308,7 @@ typedef struct wifi_direct_primary_device_type_e primary_device_type; /**< Primary category of device */ wifi_direct_secondary_device_type_e secondary_device_type; /**< Sub category of device */ unsigned int service_count; /**< The number of Registered services */ - char **service_list; /**< Is a wifi display device */ + char **service_list; /**< The list of registered services */ bool is_miracast_device; /**< Is a wifi display device */ } wifi_direct_connected_peer_info_s; @@ -413,7 +431,6 @@ typedef void (*wifi_direct_service_state_changed_cb) (int error_code, * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported - * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized * @see wifi_direct_deinitialize() */ int wifi_direct_initialize(void); @@ -426,7 +443,6 @@ int wifi_direct_initialize(void); * @return 0 on success, otherwise a negative error value. * @retval #WIFI_DIRECT_ERROR_NONE Successful * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted - * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). @@ -624,7 +640,7 @@ int wifi_direct_set_service_state_changed_cb(wifi_direct_service_state_changed_c * @see wifi_direct_initialize() * @see wifi_direct_set_service_state_changed_cb() */ -int wifi_direct_unset_service_state_changed_cb(); +int wifi_direct_unset_service_state_changed_cb(void); /** * @brief Activates the Wi-Fi Direct service, asynchronous. @@ -813,7 +829,7 @@ int wifi_direct_foreach_discovered_peers(wifi_direct_discovered_peer_cb callback * @see wifi_direct_disconnect_all() * @see wifi_direct_connection_state_changed_cb() */ -int wifi_direct_connect(const char *mac_address); +int wifi_direct_connect(char *mac_address); /** * @brief Cancels the connection now in progress. @@ -832,23 +848,6 @@ int wifi_direct_connect(const char *mac_address); int wifi_direct_cancel_connection(char *mac_address); /** - * @internal - * @brief Rejects the connection request from other device now in progress. - * @since_tizen 2.3 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect - * @param[in] mac_address The MAC address of rejected device - * @retval #WIFI_DIRECT_ERROR_NONE Successful - * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed - * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed - * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted - * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported - * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized - * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy - */ -int wifi_direct_reject_connection(char *mac_address); - -/** * @brief Disconnects all connected links to peers, asynchronous. * @since_tizen 2.3 * @privlevel public @@ -890,7 +889,7 @@ int wifi_direct_disconnect_all(void); * @see wifi_direct_disconnect() * @see wifi_direct_connection_state_changed_cb() */ -int wifi_direct_disconnect(const char *mac_address); +int wifi_direct_disconnect(char *mac_address); /** * @brief Called repeatedly when you get the information of connected peers. @@ -1064,22 +1063,6 @@ int wifi_direct_set_device_name(const char *device_name); int wifi_direct_get_device_name(char** device_name); /** - * @brief Sets SSID(Service Set Identifier) of local device - DEPRECATED. - * @param[in] ssid The SSID - * @return 0 on success, otherwise a negative error value. - * @retval #WIFI_DIRECT_ERROR_NONE Successful - * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed - * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed - * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted - * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized - * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy - * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). - * @see wifi_direct_initialize() - */ -int wifi_direct_set_ssid(const char* ssid); - -/** * @brief Gets SSID(Service Set Identifier) of a local device. * @since_tizen 2.3 * @privlevel public @@ -1318,30 +1301,6 @@ int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e *type) int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type); /** - * @internal - * @brief Accepts a connection requested from PEER. - * @since_tizen 2.3 - * @privlevel public - * @privilege http://tizen.org/privilege/wifidirect - * @param[in] mac_address MAC Address of the PEER. - * @return 0 on success, otherwise a negative error value. - * @retval #WIFI_DIRECT_ERROR_NONE Successful - * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed - * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed - * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted - * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported - * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized - * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy - * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). - * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). - * @see wifi_direct_initialize() - * @see wifi_direct_activate() - * @see wifi_direct_reject_connection() - */ -int wifi_direct_accept_connection(char *mac_address); - -/** * @brief Set the WPS config PBC as prefered method for connection. * @since_tizen 2.3 * @privlevel public @@ -1602,6 +1561,52 @@ int wifi_direct_set_max_clients(int max); */ int wifi_direct_get_max_clients(int *max); +/** + * @brief Sets or updates Wi-Fi Protected Access (WPA) password. When creating Wi-Fi Direct Group, this password will be used. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param passphrase new wpa password to set. Application must set the new password before. + * @remarks a peer can connect to this group as Wi-Fi Infrastructured mode with a passphrase. + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitteddfasf + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_get_passphrase() + */ +int wifi_direct_set_passphrase(const char *passphrase); + +/** + * @brief Gets the Wi-Fi Protected Access (WPA) password when creating Wi-Fi Direct Group. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[out] passphrase Pointer to store wpa password. Application must free this memory. + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_set_passphrase() + */ +int wifi_direct_get_passphrase(char **passphrase); /** * @brief Gets the operating channel. @@ -1655,24 +1660,28 @@ int wifi_direct_set_autoconnection_mode(bool mode); */ int wifi_direct_is_autoconnection_mode(bool *mode); - /** - * @brief Gets the own group channel. - * @param[out] channel The own group channel - * @return 0 on success, otherwise a negative error value. + * @brief Allows a device to connect automatically. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address Device MAC address to allow autoconnection + * @return 0 on success, otherwise a negative error value * @retval #WIFI_DIRECT_ERROR_NONE Successful - * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy * @pre Wi-Fi Direct service must be initialized by wifi_direct_initialize(). + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). * @see wifi_direct_initialize() + * @see wifi_direct_activate() */ -int wifi_direct_get_own_group_channel(int* channel); +int wifi_direct_set_autoconnection_peer(char *mac_address); /** * @brief Enables the persistent group. @@ -1894,7 +1903,7 @@ int wifi_direct_init_miracast(bool enable); * @privilege http://tizen.org/privilege/wifidirect * @param[in] mac_address The MAC address of peer to get * @param[out] peer_info The peer information to be passed - * @return 0 on success, otherwise a negative error value. + * @return 0 on success, otherwise a negative error value * @retval #WIFI_DIRECT_ERROR_NONE Successful * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed @@ -1909,6 +1918,210 @@ int wifi_direct_init_miracast(bool enable); */ int wifi_direct_get_peer_info(char *mac_address, wifi_direct_discovered_peer_info_s **peer_info); +/** + * @brief Enables Wi-Fi Display (WFD) functionality and initialize the various variables required for WFD. + * @details Starts listen in only assigned channel.Device will be discoverable only in assigned listen channel. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate() + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_deinit_display() + * @see wifi_direct_set_display() + */ +int wifi_direct_init_display(void); + +/** + * @brief This API shall disable Wi-Fi Display functionality & disable the support of WFD Information Element (IE). + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_NOT_SUPPORTED Not supported + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate() + * And enable Wi-Fi Display by wifi_direct_init_display(). + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_init_display() + * @see wifi_direct_set_display() + */ +int wifi_direct_deinit_display(void); + +/** + * @brief Sets the Wi-Fi Display parameters for the WFD IE of local device. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] type WFD Device Type: define the Role of WFD device like source or sink + * @param[in] port Specifies Session Management Control Port number. It should be 2 bytes (0~65535) + * @param[in] hdcp CP support bit: (@c 1 = enable the hdcp support, @c 0 = disable the hdcp support) + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate() + * And enable Wi-Fi Display by wifi_direct_init_display(). + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_init_display() + * @see wifi_direct_deinit_display() + */ +int wifi_direct_set_display(wifi_direct_display_type_e type, int port, int hdcp); + +/** + * @brief Sets the Wi-Fi Display Session Availability + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] availability Wi-Fi Display Session Availability + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate() + * And enable Wi-Fi Display by wifi_direct_display_init(). + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_init_display() + * @see wifi_direct_deinit_display() + */ +int wifi_direct_set_display_availability(bool availability); + +/** + * @brief Gets the information of a peer's Wi-Fi Display device type. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address MAC Address of the PEER + * @param[out] type The information of a peer's Wi-Fi Display device type + * @if there's Wi-Fi Direct information, this will be NULL + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_initialize() + * @see wifi_direct_activate() + * @see wifi_direct_foreach_discovered_peers() + */ +int wifi_direct_get_peer_display_type(char *mac_address, wifi_direct_display_type_e *type); + +/** + * @brief Gets the information of a peer's Wi-Fi Display session availability. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address MAC Address of the PEER + * @param[out] availability The information of a peer's Wi-Fi Display session availability + * @if there's Wi-Fi Direct information, this will be NULL + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_activate() + * @see wifi_direct_foreach_discovered_peers() + */ +int wifi_direct_get_peer_display_availability(char *mac_address, bool *availability); + +/** + * @brief Gets the information of a peer's Wi-Fi Display HDCP support. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address MAC Address of the PEER + * @param[out] hdcp The information of a peer's Wi-Fi Display HDCP support + * @if there's Wi-Fi Direct information, this will be NULL + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_activate() + * @see wifi_direct_foreach_discovered_peers() + */ +int wifi_direct_get_peer_display_hdcp(char *mac_address, int *hdcp); + +/** + * @brief Gets the information of a peer's Wi-Fi Display RTSP control port. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address MAC Address of the PEER + * @param[out] port The information of a peer's Wi-Fi Display RTSP control port + * @if there's Wi-Fi Direct information, this will be NULL + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_activate() + * @see wifi_direct_foreach_discovered_peers() + */ +int wifi_direct_get_peer_display_port(char *mac_address, int *port); + +/** + * @brief Gets the information of a peer's Wi-Fi Display max throughput. + * @since_tizen 2.4 + * @privlevel public + * @privilege http://tizen.org/privilege/wifidirect + * @param[in] mac_address MAC Address of the PEER + * @param[out] throughput The information of a peer's Wi-Fi Display max throughput (Mbps) + * @if there's Wi-Fi Direct information, this will be NULL + * @return 0 on success, otherwise a negative error value + * @retval #WIFI_DIRECT_ERROR_NONE Successful + * @retval #WIFI_DIRECT_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_DIRECT_ERROR_OPERATION_FAILED Operation failed + * @retval #WIFI_DIRECT_ERROR_COMMUNICATION_FAILED Communication failed + * @retval #WIFI_DIRECT_ERROR_NOT_PERMITTED Operation not permitted + * @retval #WIFI_DIRECT_ERROR_NOT_INITIALIZED Not initialized + * @retval #WIFI_DIRECT_ERROR_RESOURCE_BUSY Device or resource busy + * @pre Wi-Fi Direct service must be activated by wifi_direct_activate(). + * @see wifi_direct_activate() + * @see wifi_direct_foreach_discovered_peers() + */ +int wifi_direct_get_peer_display_throughput(char *mac_address, int *throughput); /** * @} diff --git a/packaging/capi-network-wifi-direct.changes b/packaging/capi-network-wifi-direct.changes deleted file mode 100644 index 4e30904..0000000 --- a/packaging/capi-network-wifi-direct.changes +++ /dev/null @@ -1,6 +0,0 @@ -* Thu May 30 2013 Baptiste DURAND accepted/tizen/20130529.180805@21ad47f -- Fix hardcoded path in pc file - -* Wed May 29 2013 Anas Nashif accepted/tizen/20130520.100855@afb2ebe -- Fixed build and remove hardcoding of libdir - diff --git a/packaging/capi-network-wifi-direct.manifest b/packaging/capi-network-wifi-direct.manifest deleted file mode 100644 index 017d22d..0000000 --- a/packaging/capi-network-wifi-direct.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/capi-network-wifi-direct.spec b/packaging/capi-network-wifi-direct.spec old mode 100755 new mode 100644 index c50cc00..6ece0ea --- a/packaging/capi-network-wifi-direct.spec +++ b/packaging/capi-network-wifi-direct.spec @@ -1,49 +1,100 @@ Name: capi-network-wifi-direct Summary: Network WiFi-Direct library in Tizen CAPI -Version: 0.0.4 -Release: 3 -Group: API/C API +Version: 1.2.33 +Release: 1 +Group: Network & Connectivity/Wireless License: Apache-2.0 Source0: %{name}-%{version}.tar.gz -Source1001: capi-network-wifi-direct.manifest -BuildRequires: pkgconfig(dbus-glib-1) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig +BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(capi-system-info) BuildRequires: cmake +BuildRequires: gettext-devel %description -WiFi-Direct library (Shared Library) +wifi direct library (Shared Library) -%package devel -Summary: WiFi-Direct library (Shared Library) (Developement) -Group: Development/API +%package devel +Summary: Wifi Direct Library (Shared Library) (Development) +Group: Development/Libraries +Requires: %{name} = %{version}-%{release} Requires: capi-base-common-devel -BuildRequires: pkgconfig(wifi-direct) %description devel -WiFi-Direct library (Shared Library) (Developement) +wifi direct library (Shared Library) (Development) + +%description + +%package -n test-wifi-direct +Summary: Test Application for Wi-Fi Direct +Group: TO_BE_FILLED +Requires: %{name} = %{version}-%{release} + +%description -n test-wifi-direct +Test Application for Wi-Fi Direct %prep %setup -q -cp %{SOURCE1001} . + +%ifarch %{arm} +export ARCH=arm +%else +export ARCH=i586 +%endif %build -%cmake . -make %{?jobs:-j%jobs} +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" +export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" + +cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \ +%if "%{?tizen_profile_name}" == "wearable" + -DTIZEN_FEATURE_SERVICE_DISCOVERY=0 \ + -DTIZEN_FEATURE_WIFI_DISPLAY=0 \ +%else +%if "%{?tizen_profile_name}" == "mobile" + -DTIZEN_FEATURE_SERVICE_DISCOVERY=1 \ + -DTIZEN_FEATURE_WIFI_DISPLAY=1 \ +%else +%if "%{?tizen_profile_name}" == "tv" + -DTIZEN_TV=1 \ +%endif +%endif +%endif + . + +make %{?jobs:-j%jobs} %install +rm -rf %{buildroot} %make_install +#%__strip %{buildroot}%{_libdir}/libwifi-direct.so.0.0 + +mkdir -p %{buildroot}/usr/share/license +cp %{_builddir}/%{buildsubdir}/LICENSE.APLv2 %{buildroot}/usr/share/license/%{name} %post -p /sbin/ldconfig %postun -p /sbin/ldconfig + %files -%manifest %{name}.manifest +%manifest capi-network-wifi-direct.manifest +%defattr(-,root,root,-) +%{_libdir}/libwifi-direct.so +%{_libdir}/libwifi-direct.so.0 +%{_libdir}/libwifi-direct.so.0.0 +/usr/share/license/%{name} %files devel -%manifest %{name}.manifest %defattr(-,root,root,-) -%{_libdir}/pkgconfig/*.pc -%{_includedir}/*/*.h +%{_libdir}/pkgconfig/capi-network-wifi-direct.pc +%{_includedir}/wifi-direct/wifi-direct.h +%files -n test-wifi-direct +%manifest test-wifi-direct.manifest +%defattr(4755,app,app,4755) +%{_bindir}/test-wifi-direct diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..08b315d --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,121 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(wifi-direct C) + +# Global setting +SET(VERSION 0.0) + +MACRO(GET_TARGET_PROPERTY_WITH_DEFAULT _variable _target _property _default_value) + GET_TARGET_PROPERTY (${_variable} ${_target} ${_property}) + IF (${_variable} MATCHES NOTFOUND) + SET (${_variable} ${_default_value}) + ENDIF (${_variable} MATCHES NOTFOUND) +ENDMACRO (GET_TARGET_PROPERTY_WITH_DEFAULT) + +MACRO(CREATE_LIBTOOL_FILE _target _install_DIR) + GET_TARGET_PROPERTY(_target_location ${_target} LOCATION) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_static_lib ${_target} STATIC_LIB "") + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dependency_libs ${_target} LT_DEPENDENCY_LIBS "") + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_current ${_target} LT_VERSION_CURRENT 0) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_age ${_target} LT_VERSION_AGE 0) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_revision ${_target} LT_VERSION_REVISION 0) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_installed ${_target} LT_INSTALLED yes) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_shouldnotlink ${_target} LT_SHOULDNOTLINK yes) + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlopen ${_target} LT_DLOPEN "") + GET_TARGET_PROPERTY_WITH_DEFAULT(_target_dlpreopen ${_target} LT_DLPREOPEN "") + GET_FILENAME_COMPONENT(_laname ${_target_location} NAME_WE) + GET_FILENAME_COMPONENT(_soname ${_target_location} NAME) + SET(_laname2 ${_laname}.la) + SET(_laname ${PROJECT_BINARY_DIR}/${_laname}.la) + FILE(WRITE ${_laname} "# ${_laname2} - a libtool library file\n") + FILE(APPEND ${_laname} "# Generated by CMake ${CMAKE_VERSION} (like GNU libtool)\n") + FILE(APPEND ${_laname} "\n# Please DO NOT delete this file!\n# It is necessary for linking the library with libtool.\n\n" ) + FILE(APPEND ${_laname} "# The name that we can dlopen(3).\n") + FILE(APPEND ${_laname} "dlname='${_soname}'\n\n") + FILE(APPEND ${_laname} "# Names of this library.\n") + FILE(APPEND ${_laname} "library_names='${_soname}.${_target_current}.${_target_age}.${_target_revision} ${_soname}.${_target_current} ${_soname}'\n\n") + FILE(APPEND ${_laname} "# The name of the static archive.\n") + FILE(APPEND ${_laname} "old_library='${_target_static_lib}'\n\n") + FILE(APPEND ${_laname} "# Libraries that this one depends upon.\n") + FILE(APPEND ${_laname} "dependency_libs='${_target_dependency_libs}'\n\n") + FILE(APPEND ${_laname} "# Names of additional weak libraries provided by this library\n") + FILE(APPEND ${_laname} "weak_library_names=\n\n") + FILE(APPEND ${_laname} "# Version information for ${_laname2}.\n") + FILE(APPEND ${_laname} "current=${_target_current}\n") + FILE(APPEND ${_laname} "age=${_target_age}\n") + FILE(APPEND ${_laname} "revision=${_target_revision}\n\n") + FILE(APPEND ${_laname} "# Is this an already installed library?\n") + FILE(APPEND ${_laname} "installed=${_target_installed}\n\n") + FILE(APPEND ${_laname} "# Should we warn about portability when linking against -modules?\n") + FILE(APPEND ${_laname} "shouldnotlink=${_target_shouldnotlink}\n\n") + FILE(APPEND ${_laname} "# Files to dlopen/dlpreopen\n") + FILE(APPEND ${_laname} "dlopen='${_target_dlopen}'\n") + FILE(APPEND ${_laname} "dlpreopen='${_target_dlpreopen}'\n\n") + FILE(APPEND ${_laname} "# Directory that this library needs to be installed in:\n") + FILE(APPEND ${_laname} "libdir='${CMAKE_INSTALL_PREFIX}${_install_DIR}'\n") + INSTALL( FILES ${_laname} DESTINATION ${CMAKE_INSTALL_PREFIX}${_install_DIR}) +ENDMACRO(CREATE_LIBTOOL_FILE) + +# Build type : Release +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +# Set required packages +INCLUDE(FindPkgConfig) +pkg_check_modules(pkgs REQUIRED vconf glib-2.0 gio-2.0 gthread-2.0 dlog capi-system-info) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src/include) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -lpthread -g -DUSE_DLOG") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g -DUSE_DLOG") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") + MESSAGE("add -DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DEXPORT_API=\"__attribute__((visibility(\\\"default\\\")))\" ") +IF(TIZEN_FEATURE_SERVICE_DISCOVERY) + ADD_DEFINITIONS(-DTIZEN_FEATURE_SERVICE_DISCOVERY) + SET(FEATURES "${FEATURES} -DTIZEN_FEATURE_SERVICE_DISCOVERY") +ENDIF(TIZEN_FEATURE_SERVICE_DISCOVERY) +IF(TIZEN_FEATURE_WIFI_DISPLAY) + ADD_DEFINITIONS(-DTIZEN_FEATURE_WIFI_DISPLAY) + SET(FEATURES "${FEATURES} -DTIZEN_FEATURE_WIFI_DISPLAY") +ENDIF(TIZEN_FEATURE_WIFI_DISPLAY) +IF(TIZEN_TV) + ADD_DEFINITIONS(" -DTIZEN_TV") + MESSAGE("add -DTIZEN_TV") +ENDIF(TIZEN_TV) + +# Linker flags +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +# Build +SET(SRCS + wifi-direct-client-proxy.c +) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${VERSION} SOVERSION 0) +CREATE_LIBTOOL_FILE(${PROJECT_NAME} /lib) + +# pkgconfig file +CONFIGURE_FILE(capi-network-wifi-direct.pc.in capi-network-wifi-direct.pc @ONLY) + +# Install +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION lib COMPONENT Runtime) +INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/wifi-direct.h DESTINATION include/wifi-direct) +INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/capi-network-wifi-direct.pc DESTINATION lib/pkgconfig) + diff --git a/src/capi-network-wifi-direct.pc.in b/src/capi-network-wifi-direct.pc.in new file mode 100755 index 0000000..5e5a3aa --- /dev/null +++ b/src/capi-network-wifi-direct.pc.in @@ -0,0 +1,12 @@ +prefix=@prefix@ +exec_prefix=@prefix@ +libdir=@prefix@/lib +includedir=@prefix@/include +features=@FEATURES@ + +Name: wifi-direct +Description: Wi-Fi Direct Library +Version: @VERSION@ +Libs: -L${libdir} -lwifi-direct +Cflags: -I${includedir} -I${includedir}/wifi-direct ${features} + diff --git a/src/include/wifi-direct-client-proxy.h b/src/include/wifi-direct-client-proxy.h new file mode 100755 index 0000000..0475bb0 --- /dev/null +++ b/src/include/wifi-direct-client-proxy.h @@ -0,0 +1,128 @@ +/* + * libwifi-direct + * + * Copyright (c) 2012 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 __WIFI_DIRECT_CLIENT_PROXY_H_ +#define __WIFI_DIRECT_CLIENT_PROXY_H_ + +#ifdef USE_DLOG +#include + +#undef LOG_TAG +#define LOG_TAG "WIFI_DIRECT" + +#define WDC_LOGV(format, args...) LOGV(format, ##args) +#define WDC_LOGD(format, args...) LOGD(format, ##args) +#define WDC_LOGI(format, args...) LOGI(format, ##args) +#define WDC_LOGW(format, args...) LOGW(format, ##args) +#define WDC_LOGE(format, args...) LOGE(format, ##args) +#define WDC_LOGF(format, args...) LOGF(format, ##args) + +#define WDC_SECLOGI(format, args...) SECURE_LOG(LOG_INFO, LOG_TAG, format, ##args) +#define WDC_SECLOGD(format, args...) SECURE_LOG(LOG_DEBUG, LOG_TAG, format, ##args) + +#define __WDC_LOG_FUNC_START__ LOGV("Enter") +#define __WDC_LOG_FUNC_END__ LOGV("Quit") + +#else /** _DLOG_UTIL */ + +#define WDC_LOGV(format, args...) +#define WDC_LOGD(format, args...) +#define WDC_LOGI(format, args...) +#define WDC_LOGW(format, args...) +#define WDC_LOGE(format, args...) +#define WDC_LOGF(format, args...) + +#define __WDC_LOG_FUNC_START__ +#define __WDC_LOG_FUNC_END__ + +#define WDC_SECLOGI(format, args...) +#define WDC_SECLOGD(format, args...) + +#endif /** _DLOG_UTIL */ + +#define NETCONFIG_SERVICE "net.netconfig" +#define NETCONFIG_WIFI_INTERFACE "net.netconfig.wifi" +#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi" +#define NETCONFIG_WIFI_LAUNCHDIRECT "LaunchDirect" +#define DBUS_REPLY_TIMEOUT (120 * 1000) + +#define SOCK_FD_MIN 3 +#define WIFI_DIRECT_WPA_LEN 64 +#define MACSTR_LEN 18 +#define MACADDR_LEN 6 +#define IPSTR_LEN 16 +#define WFD_SOCK_FILE_PATH "/tmp/wfd_client_socket" + +#define WIFIDIRECT_FEATURE "http://tizen.org/feature/network.wifi.direct" +#define WIFIDIRECT_DISPLAY_FEATURE "http://tizen.org/feature/network.wifi.direct.display" +#define WIFIDIRECT_SERVICE_DISCOVERY_FEATURE "http://tizen.org/feature/network.wifi.direct.service_discovery" + +#if !defined TIZEN_TV +#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 WIFI_DIRECT_ERROR_NOT_SUPPORTED;\ + }\ + } else {\ + LOGE("Error - Feature getting from System Info");\ + return WIFI_DIRECT_ERROR_OPERATION_FAILED;\ + }\ + }while(0) + +#else +#define CHECK_FEATURE_SUPPORTED(feature_name) +#endif + +typedef struct +{ + bool is_registered; + int client_id; + int sync_sockfd; + int async_sockfd; + int g_client_info; + int g_source_id; + wifi_direct_device_state_changed_cb activation_cb; + wifi_direct_discovery_state_chagned_cb discover_cb; + wifi_direct_connection_state_changed_cb connection_cb; + wifi_direct_client_ip_address_assigned_cb ip_assigned_cb; + wifi_direct_peer_found_cb peer_found_cb; + + void *user_data_for_cb_activation; + void *user_data_for_cb_discover; + void *user_data_for_cb_connection; + void *user_data_for_cb_ip_assigned; + void *user_data_for_cb_peer_found; + void *user_data_for_cb_device_name; + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + wifi_direct_service_state_changed_cb service_cb; + void *user_data_for_cb_service; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + pthread_mutex_t mutex; +} wifi_direct_client_info_s; + +extern char *wfd_debug_print(char *file, int line, char *format, ...); + +#endif /** __WIFI_DIRECT_CLIENT_PROXY_H_ */ diff --git a/src/include/wifi-direct-ipc.h b/src/include/wifi-direct-ipc.h new file mode 100755 index 0000000..7107288 --- /dev/null +++ b/src/include/wifi-direct-ipc.h @@ -0,0 +1,316 @@ +/* + * wifi-direct + * + * Copyright (c) 2012 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 __WIFI_DIRECT_INTERNAL_H_ +#define __WIFI_DIRECT_INTERNAL_H_ + +#define true 1 +#define false 0 + +#define WFD_INVALID_ID -1 + +#ifndef O_NONBLOCK +#define O_NONBLOCK O_NDELAY +#endif /** O_NONBLOCK */ + + +#ifndef _UINT32_TYPE_H_ +#define _UINT32_TYPE_H_ +typedef unsigned int uint32; +#endif /** _UINT32_TYPE_H_ */ + +typedef unsigned int ipv4_addr_t; + +#ifndef TRUE +#define TRUE 1 +#endif /** TRUE */ + +#ifndef FALSE +#define FALSE 0 +#endif /** FALSE */ + +#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 WIFI_DIRECT_MAX_SSID_LEN 32 +#define WIFI_DIRECT_MAX_DEVICE_NAME_LEN 32 +#define WIFI_DIRECT_WPS_PIN_LEN 8 +#define WIFI_DIRECT_MAC_ADDRESS_INFO_FILE "/opt/etc/.mac.info" +#define WIFI_DIRECT_MAX_SERVICES_LEN 1024 +#define WIFI_DIRECT_MAX_SERVICE_NAME_LEN 256 + +#define VCONFKEY_IFNAME "memory/private/wifi_direct_manager/p2p_ifname" +#define VCONFKEY_LOCAL_IP "memory/private/wifi_direct_manager/p2p_local_ip" +#define VCONFKEY_SUBNET_MASK "memory/private/wifi_direct_manager/p2p_subnet_mask" +#define VCONFKEY_GATEWAY "memory/private/wifi_direct_manager/p2p_gateway" + +typedef enum +{ + WIFI_DIRECT_CMD_INVALID, + WIFI_DIRECT_CMD_REGISTER, + WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET, + WIFI_DIRECT_CMD_DEREGISTER, + WIFI_DIRECT_CMD_GET_LINK_STATUS, + WIFI_DIRECT_CMD_ACTIVATE, + WIFI_DIRECT_CMD_DEACTIVATE, + WIFI_DIRECT_CMD_START_DISCOVERY, + WIFI_DIRECT_CMD_START_DISCOVERY_SPECIFIC_CHANNEL, + WIFI_DIRECT_CMD_CANCEL_DISCOVERY, + WIFI_DIRECT_CMD_IS_LISTENING_ONLY, // 10 + WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT, + + WIFI_DIRECT_CMD_CONNECT, + WIFI_DIRECT_CMD_SEND_CONNECT_REQ, + WIFI_DIRECT_CMD_CANCEL_CONNECT, // deprecated + WIFI_DIRECT_CMD_CANCEL_CONNECTION, + WIFI_DIRECT_CMD_REJECT_CONNECTION, + WIFI_DIRECT_CMD_DISCONNECT, + WIFI_DIRECT_CMD_DISCONNECT_ALL, + WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO, + + WIFI_DIRECT_CMD_CREATE_GROUP, // 20 + WIFI_DIRECT_CMD_DESTROY_GROUP, + WIFI_DIRECT_CMD_IS_GROUPOWNER, + WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP, + + WIFI_DIRECT_CMD_GET_SSID, + WIFI_DIRECT_CMD_SET_SSID, + WIFI_DIRECT_CMD_GET_IP_ADDR, + WIFI_DIRECT_CMD_GET_MAC_ADDR, + WIFI_DIRECT_CMD_GET_CONFIG, + WIFI_DIRECT_CMD_SET_CONFIG, + + WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON, // 30 + WIFI_DIRECT_CMD_SET_WPS_PIN, + WIFI_DIRECT_CMD_GET_WPS_PIN, + WIFI_DIRECT_CMD_GENERATE_WPS_PIN, + WIFI_DIRECT_CMD_SET_WPA, + WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE, + WIFI_DIRECT_CMD_GET_LOCAL_WPS_MODE, + WIFI_DIRECT_CMD_GET_REQ_WPS_MODE, + WIFI_DIRECT_CMD_SET_REQ_WPS_MODE, + + WIFI_DIRECT_CMD_SET_GO_INTENT, + WIFI_DIRECT_CMD_GET_GO_INTENT, // 40 + WIFI_DIRECT_CMD_SET_MAX_CLIENT, + WIFI_DIRECT_CMD_GET_MAX_CLIENT, + WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE, + WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE, + WIFI_DIRECT_CMD_IS_DISCOVERABLE, + + WIFI_DIRECT_CMD_GET_OPERATING_CHANNEL, + WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP, + WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP, + WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP, + WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO, // 50 + WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP, + WIFI_DIRECT_CMD_GET_DEVICE_NAME, + WIFI_DIRECT_CMD_SET_DEVICE_NAME, + + WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL, + WIFI_DIRECT_CMD_GET_PEER_INFO, + WIFI_DIRECT_CMD_SET_PASSPHRASE, + WIFI_DIRECT_CMD_GET_PASSPHRASE, + WIFI_DIRECT_CMD_SET_AUTOCONNECTION_PEER, + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + WIFI_DIRECT_CMD_REGISTER_LOCAL_SERVICE, + WIFI_DIRECT_CMD_DEREGISTER_LOCAL_SERVICE, + WIFI_DIRECT_CMD_START_SERVICE_DISCOVERY, + WIFI_DIRECT_CMD_CANCEL_SERVICE_DISCOVERY, //60 + + WIFI_DIRECT_CMD_REGISTER_SERVICE, + WIFI_DIRECT_CMD_DEREGISTER_SERVICE, +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + WIFI_DIRECT_CMD_INIT_MIRACAST, + WIFI_DIRECT_CMD_INIT_DISPLAY, + WIFI_DIRECT_CMD_DEINIT_DISPLAY, + WIFI_DIRECT_CMD_SET_DISPLAY, + WIFI_DIRECT_CMD_SET_DISPLAY_AVAILABILITY, + WIFI_DIRECT_CMD_GET_PEER_DISPLAY_TYPE, + WIFI_DIRECT_CMD_GET_PEER_DISPLAY_AVAILABILITY, + WIFI_DIRECT_CMD_GET_PEER_DISPLAY_HDCP, + WIFI_DIRECT_CMD_GET_PEER_DISPLAY_PORT, + WIFI_DIRECT_CMD_GET_PEER_DISPLAY_THROUGHPUT, +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ + + + + WIFI_DIRECT_CMD_MAX +} wifi_direct_cmd_e; + +/** + * Wi-Fi Direct client event for IPC + */ +typedef enum +{ + WIFI_DIRECT_CLI_EVENT_INVALID = -1, /**< */ + + WIFI_DIRECT_CLI_EVENT_ACTIVATION, /**< */ + WIFI_DIRECT_CLI_EVENT_DEACTIVATION, /**< */ + + WIFI_DIRECT_CLI_EVENT_DISCOVER_START, /**< 80211 scan*/ + WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY, /**< listen only mode*/ + WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN, /**< search, listen*/ + WIFI_DIRECT_CLI_EVENT_DISCOVER_END, /**< */ + WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS, /**< */ + + WIFI_DIRECT_CLI_EVENT_CONNECTION_START, /**< */ + WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ, /**< */ + WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP, /**< */ + WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ, /**< */ + + WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP, /**< */ + WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND, /**< */ + WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND, /**< */ + + WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP, /**< */ + WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP, /**< */ + + WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND, /**< */ + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED, + WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND, + WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINISHED, +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + WIFI_DIRECT_CLI_EVENT_MAX, +} wfd_client_event_e; + +/** + * Wi-Fi Direct configuration data structure for IPC + */ +typedef struct +{ + char device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1]; + int channel; + wifi_direct_wps_type_e wps_config; + int max_clients; + bool hide_SSID; + int group_owner_intent; + bool want_persistent_group; + bool listen_only; + bool auto_connection; + wifi_direct_primary_device_type_e primary_dev_type; + wifi_direct_secondary_device_type_e secondary_dev_type; +} wfd_config_data_s; + + +/** + * Wi-Fi Direct buffer structure to store result of peer discovery for IPC + */ +typedef struct +{ + char device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1]; + unsigned char mac_address[6]; + unsigned char intf_address[6]; + int channel; + bool is_connected; + bool is_group_owner; + bool is_persistent_go; + unsigned int category; + unsigned int subcategory; + + unsigned int services; + + unsigned int wps_device_pwd_id; + unsigned int wps_cfg_methods; + + bool is_wfd_device; + +} wfd_discovery_entry_s; + + +/** + * Wi-Fi Direct buffer structure to store information of connected peer + */ +typedef struct +{ + char device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1]; + unsigned char ip_address[4]; + unsigned char mac_address[6]; + unsigned char intf_address[6]; + int channel; + bool is_p2p; + unsigned short category; + unsigned short subcategory; + + unsigned int services; + + bool is_wfd_device; + +} wfd_connected_peer_info_s; + +typedef struct +{ + int network_id; + char ssid[WIFI_DIRECT_MAX_SSID_LEN + 1]; + unsigned char go_mac_address[6]; +} wfd_persistent_group_info_s; + +typedef struct +{ + int int1; + int int2; + int int3; + unsigned char mac_addr[6]; +} wifi_direct_client_request_data_s; + + +typedef struct +{ + wifi_direct_cmd_e cmd; + int client_id; + unsigned int cmd_data_len; + wifi_direct_client_request_data_s data; +} wifi_direct_client_request_s; + +typedef struct +{ + wifi_direct_cmd_e cmd; + wifi_direct_error_e result; + int client_id; + int param1; + char param2[64]; + char param3[32]; + int data_length; +} wifi_direct_client_response_s; + +typedef struct +{ + wfd_client_event_e event; + wifi_direct_error_e error; + int type; + char param1[64]; + char param2[256]; +} wifi_direct_client_noti_s; + + +#endif /* __WIFI_DIRECT_INTERNAL_H_ */ diff --git a/src/wifi-direct-client-proxy.c b/src/wifi-direct-client-proxy.c new file mode 100755 index 0000000..ba5fd12 --- /dev/null +++ b/src/wifi-direct-client-proxy.c @@ -0,0 +1,4880 @@ +/* + * libwifi-direct + * + * Copyright (c) 2012 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. + * + */ + + +/***************************************************************************** + * 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 +#include + +/***************************************************************************** + * Wi-Fi Direct Service headers + *****************************************************************************/ +#include "wifi-direct.h" +#include "wifi-direct-internal.h" +#include "wifi-direct-client-proxy.h" +#include "wifi-direct-ipc.h" + +/***************************************************************************** + * Macros and Typedefs + *****************************************************************************/ + +/***************************************************************************** + * Global Variables + *****************************************************************************/ +wifi_direct_client_info_s g_client_info = { + .is_registered = FALSE, + .client_id = -1, + .sync_sockfd = -1, + .async_sockfd = -1, + .activation_cb = NULL, + .discover_cb = NULL, + .connection_cb = NULL, + .ip_assigned_cb = NULL, + .peer_found_cb = NULL, + .user_data_for_cb_activation = NULL, + .user_data_for_cb_discover = NULL, + .user_data_for_cb_connection = NULL, + .user_data_for_cb_ip_assigned = NULL, + .user_data_for_cb_peer_found = NULL, + .user_data_for_cb_device_name = NULL, +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + .service_cb = NULL, + .user_data_for_cb_service = NULL, +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + .mutex = PTHREAD_MUTEX_INITIALIZER +}; + +/***************************************************************************** + * Local Functions Definition + *****************************************************************************/ + +#ifdef __NR_gettid +pid_t gettid(void) +{ + return syscall(__NR_gettid); +} +#else +#error "__NR_gettid is not defined, please include linux/unistd.h" +#endif + +static wifi_direct_client_info_s *__wfd_get_control() +{ + return &g_client_info; +} + +static void __wfd_reset_control() +{ + + if (g_client_info.g_source_id > 0) + g_source_remove(g_client_info.g_source_id); + g_client_info.g_source_id = -1; + + // Protect standard input / output / error + if (g_client_info.sync_sockfd > 0) + close(g_client_info.sync_sockfd); + g_client_info.sync_sockfd = -1; + + if (g_client_info.async_sockfd > 0) + close(g_client_info.async_sockfd); + g_client_info.async_sockfd = -1; + + g_client_info.is_registered = FALSE; + + // Initialize callbacks + g_client_info.activation_cb = NULL; + g_client_info.discover_cb = NULL; + g_client_info.connection_cb = NULL; + g_client_info.ip_assigned_cb = NULL; + g_client_info.peer_found_cb = NULL; + g_client_info.user_data_for_cb_activation = NULL; + g_client_info.user_data_for_cb_discover = NULL; + g_client_info.user_data_for_cb_connection = NULL; + g_client_info.user_data_for_cb_ip_assigned = NULL; + g_client_info.user_data_for_cb_peer_found = NULL; + g_client_info.user_data_for_cb_device_name = NULL; + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + g_client_info.service_cb = NULL; + g_client_info.user_data_for_cb_service= NULL; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + + pthread_mutex_destroy(&g_client_info.mutex); +} + +static int macaddr_atoe(char *p, unsigned char mac[]) +{ + int i = 0; + + for (;;) { + mac[i++] = (char) strtoul(p, &p, 16); + if (!*p++ || i == 6) + break; + } + + return (i == 6); +} + +static char *__wfd_print_event(wfd_client_event_e event) +{ + switch (event) + { + case WIFI_DIRECT_CLI_EVENT_INVALID: + return "WIFI_DIRECT_CLI_EVENT_INVALID"; + break; + case WIFI_DIRECT_CLI_EVENT_ACTIVATION: + return "ACTIVATION"; + break; + case WIFI_DIRECT_CLI_EVENT_DEACTIVATION: + return "DEACTIVATION"; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START: + return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START"; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY: + return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY"; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN: + return "WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN"; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_END: + return "WIFI_DIRECT_CLI_EVENT_DISCOVER_END"; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS: + return "WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS"; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_START: + return "WIFI_DIRECT_CLI_EVENT_CONNECTION_START"; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ: + return "WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ"; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP: + return "WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP"; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ: + return "WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ"; + break; + case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP: + return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP"; + break; + case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND: + return "WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND"; + break; + case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND: + return "WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND"; + break; + case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP: + return "WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP"; + break; + case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP: + return "WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP"; + break; + case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND: + return "WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND"; + break; +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND: + return "WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND"; + break; + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED: + return "WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED"; + break; + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINISHED: + return "WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINSIHED"; + break; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + default: + return "WIFI_DIRECT_CLI_EVENT_unknown"; + break; + } +} + +static char *__wfd_print_error(wifi_direct_error_e error) +{ + switch (error) + { + case WIFI_DIRECT_ERROR_NONE: + return "WIFI_DIRECT_ERROR_NONE"; + case WIFI_DIRECT_ERROR_NOT_PERMITTED: + return "WIFI_DIRECT_ERROR_NOT_PERMITTED"; + case WIFI_DIRECT_ERROR_OUT_OF_MEMORY: + return "WIFI_DIRECT_ERROR_OUT_OF_MEMORY"; + case WIFI_DIRECT_ERROR_PERMISSION_DENIED: + return "WIFI_DIRECT_ERROR_PERMISSION_DENIED"; + case WIFI_DIRECT_ERROR_RESOURCE_BUSY: + return "WIFI_DIRECT_ERROR_RESOURCE_BUSY"; + case WIFI_DIRECT_ERROR_INVALID_PARAMETER: + return "WIFI_DIRECT_ERROR_INVALID_PARAMETER"; + case WIFI_DIRECT_ERROR_NOT_INITIALIZED: + return "WIFI_DIRECT_ERROR_NOT_INITIALIZED"; + case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED: + return "WIFI_DIRECT_ERROR_COMMUNICATION_FAILED"; + case WIFI_DIRECT_ERROR_WIFI_USED: + return "WIFI_DIRECT_ERROR_WIFI_USED"; + case WIFI_DIRECT_ERROR_MOBILE_AP_USED: + return "WIFI_DIRECT_ERROR_MOBILE_AP_USED"; + case WIFI_DIRECT_ERROR_CONNECTION_FAILED: + return "WIFI_DIRECT_ERROR_CONNECTION_FAILED"; + case WIFI_DIRECT_ERROR_AUTH_FAILED: + return "WIFI_DIRECT_ERROR_AUTH_FAILED"; + case WIFI_DIRECT_ERROR_OPERATION_FAILED: + return "WIFI_DIRECT_ERROR_OPERATION_FAILED"; + case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT: + return "WIFI_DIRECT_ERROR_TOO_MANY_CLIENT"; + case WIFI_DIRECT_ERROR_ALREADY_INITIALIZED: + return "WIFI_DIRECT_ERROR_ALREADY_INITIALIZED"; + default: + WDC_LOGE("Invalid error value: [%d]", error); + return "Invalid error"; + } +} + +static int __wfd_convert_client_event(wfd_client_event_e event) +{ + __WDC_LOG_FUNC_START__; + + switch (event) + { + case WIFI_DIRECT_CLI_EVENT_ACTIVATION: + return WIFI_DIRECT_DEVICE_STATE_ACTIVATED; + break; + case WIFI_DIRECT_CLI_EVENT_DEACTIVATION: + return WIFI_DIRECT_DEVICE_STATE_DEACTIVATED; + break; + + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY: + return WIFI_DIRECT_ONLY_LISTEN_STARTED; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START: + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN: + return WIFI_DIRECT_DISCOVERY_STARTED; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS: + return WIFI_DIRECT_DISCOVERY_FOUND; + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_END: + return WIFI_DIRECT_DISCOVERY_FINISHED; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ: + return WIFI_DIRECT_CONNECTION_REQ; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ: + return WIFI_DIRECT_CONNECTION_WPS_REQ; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_START: + return WIFI_DIRECT_CONNECTION_IN_PROGRESS; + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP: + return WIFI_DIRECT_CONNECTION_RSP; + break; + case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP: + return WIFI_DIRECT_DISCONNECTION_RSP; + break; + case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND: + return WIFI_DIRECT_DISCONNECTION_IND; + break; + case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND: + return WIFI_DIRECT_DISASSOCIATION_IND; + break; + case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP: + return WIFI_DIRECT_GROUP_CREATED; + break; + case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP: + return WIFI_DIRECT_GROUP_DESTROYED; + break; +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND: + return WIFI_DIRECT_SERVICE_DISCOVERY_FOUND; + break; + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED: + return WIFI_DIRECT_SERVICE_DISCOVERY_STARTED; + break; + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINISHED: + return WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED; + break; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + default: + WDC_LOGE("Invalid event : [%d]", event); + break; + } + + __WDC_LOG_FUNC_END__; + return -1; +} + +char *__wfd_client_print_cmd(wifi_direct_cmd_e cmd) +{ + switch (cmd) + { + case WIFI_DIRECT_CMD_REGISTER: + return "WIFI_DIRECT_CMD_REGISTER"; + case WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET: + return "WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET"; + case WIFI_DIRECT_CMD_DEREGISTER: + return "WIFI_DIRECT_CMD_DEREGISTER"; + case WIFI_DIRECT_CMD_ACTIVATE: + return "WIFI_DIRECT_CMD_ACTIVATE"; + case WIFI_DIRECT_CMD_DEACTIVATE: + return "WIFI_DIRECT_CMD_DEACTIVATE"; + case WIFI_DIRECT_CMD_START_DISCOVERY: + return "WIFI_DIRECT_CMD_START_DISCOVERY"; + case WIFI_DIRECT_CMD_START_DISCOVERY_SPECIFIC_CHANNEL: + return "WIFI_DIRECT_CMD_START_DISCOVERY_SPECIFIC_CHANNEL"; + case WIFI_DIRECT_CMD_CANCEL_DISCOVERY: + return "WIFI_DIRECT_CMD_CANCEL_DISCOVERY"; + case WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT: + return "WIFI_DIRECT_CMD_GET_DISCOVERY_RESULT"; + case WIFI_DIRECT_CMD_GET_LINK_STATUS: + return "WIFI_DIRECT_CMD_GET_LINK_STATUS"; + case WIFI_DIRECT_CMD_CONNECT: + return "WIFI_DIRECT_CMD_CONNECT"; + case WIFI_DIRECT_CMD_CANCEL_CONNECT: + return "WIFI_DIRECT_CMD_CANCEL_CONNECT"; + case WIFI_DIRECT_CMD_CANCEL_CONNECTION: + return "WIFI_DIRECT_CMD_CANCEL_CONNECTION"; + case WIFI_DIRECT_CMD_REJECT_CONNECTION: + return "WIFI_DIRECT_CMD_REJECT_CONNECTION"; + case WIFI_DIRECT_CMD_DISCONNECT_ALL: + return "WIFI_DIRECT_CMD_DISCONNECT_ALL"; + case WIFI_DIRECT_CMD_CREATE_GROUP: + return "WIFI_DIRECT_CMD_CREATE_GROUP"; + case WIFI_DIRECT_CMD_IS_GROUPOWNER: + return "WIFI_DIRECT_CMD_IS_GROUPOWNER"; + case WIFI_DIRECT_CMD_GET_SSID: + return "WIFI_DIRECT_CMD_GET_SSID"; + case WIFI_DIRECT_CMD_SET_SSID: + return "WIFI_DIRECT_CMD_SET_SSID"; + case WIFI_DIRECT_CMD_GET_IP_ADDR: + return "WIFI_DIRECT_CMD_GET_IP_ADDR"; + case WIFI_DIRECT_CMD_GET_CONFIG: + return "WIFI_DIRECT_CMD_GET_CONFIG"; + case WIFI_DIRECT_CMD_SET_CONFIG: + return "WIFI_DIRECT_CMD_SET_CONFIG"; + case WIFI_DIRECT_CMD_SEND_CONNECT_REQ: + return "WIFI_DIRECT_CMD_SEND_CONNECT_REQ"; + case WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON: + return "WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON"; + case WIFI_DIRECT_CMD_SET_WPS_PIN: + return "WIFI_DIRECT_CMD_SET_WPS_PIN"; + case WIFI_DIRECT_CMD_GET_WPS_PIN: + return "WIFI_DIRECT_CMD_GET_WPS_PIN"; + case WIFI_DIRECT_CMD_GENERATE_WPS_PIN: + return "WIFI_DIRECT_CMD_GENERATE_WPS_PIN"; + case WIFI_DIRECT_CMD_SET_WPA: + return "WIFI_DIRECT_CMD_SET_WPA"; + case WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE: + return "WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE"; + case WIFI_DIRECT_CMD_GET_LOCAL_WPS_MODE: + return "WIFI_DIRECT_CMD_GET_LOCAL_WPS_MODE"; + case WIFI_DIRECT_CMD_SET_REQ_WPS_MODE: + return "WIFI_DIRECT_CMD_SET_REQ_WPS_MODE"; + case WIFI_DIRECT_CMD_GET_REQ_WPS_MODE: + return "WIFI_DIRECT_CMD_GET_REQ_WPS_MODE"; + case WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO: + return "WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO"; + case WIFI_DIRECT_CMD_DESTROY_GROUP: + return "WIFI_DIRECT_CMD_DESTROY_GROUP"; + case WIFI_DIRECT_CMD_DISCONNECT: + return "WIFI_DIRECT_CMD_DISCONNECT"; + case WIFI_DIRECT_CMD_SET_GO_INTENT: + return "WIFI_DIRECT_CMD_SET_GO_INTENT"; + case WIFI_DIRECT_CMD_GET_GO_INTENT: + return "WIFI_DIRECT_CMD_GET_GO_INTENT"; + case WIFI_DIRECT_CMD_GET_MAC_ADDR: + return "WIFI_DIRECT_CMD_GET_MAC_ADDR"; + case WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP: + return "WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP"; + case WIFI_DIRECT_CMD_SET_MAX_CLIENT: + return "WIFI_DIRECT_CMD_SET_MAX_CLIENT"; + case WIFI_DIRECT_CMD_GET_MAX_CLIENT: + return "WIFI_DIRECT_CMD_GET_MAX_CLIENT"; + case WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE: + return "WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE"; + case WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE: + return "WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE"; + case WIFI_DIRECT_CMD_IS_DISCOVERABLE: + return "WIFI_DIRECT_CMD_IS_DISCOVERABLE"; + case WIFI_DIRECT_CMD_IS_LISTENING_ONLY: + return "WIFI_DIRECT_CMD_IS_LISTENING_ONLY"; + case WIFI_DIRECT_CMD_GET_OPERATING_CHANNEL: + return "WIFI_DIRECT_CMD_GET_OPERATING_CHANNEL"; + case WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP: + return "WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP"; + case WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP: + return "WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP"; + case WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP: + return "WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP"; + case WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO: + return "WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO"; + case WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP: + return "WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP"; + case WIFI_DIRECT_CMD_GET_DEVICE_NAME: + return "WIFI_DIRECT_CMD_GET_DEVICE_NAME"; + case WIFI_DIRECT_CMD_SET_DEVICE_NAME: + return "WIFI_DIRECT_CMD_SET_DEVICE_NAME"; + case WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL: + return "WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL"; + case WIFI_DIRECT_CMD_GET_PEER_INFO: + return "WIFI_DIRECT_CMD_GET_PEER_INFO"; + + case WIFI_DIRECT_CMD_SET_PASSPHRASE: + return "WIFI_DIRECT_CMD_SET_PASSPHRASE"; + case WIFI_DIRECT_CMD_GET_PASSPHRASE: + return "WIFI_DIRECT_CMD_GET_PASSPHRASE"; + case WIFI_DIRECT_CMD_SET_AUTOCONNECTION_PEER: + return "WIFI_DIRECT_CMD_SET_AUTOCONNECTION_PEER"; + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + case WIFI_DIRECT_CMD_REGISTER_LOCAL_SERVICE: + return "WIFI_DIRECT_CMD_REGISTER_LOCAL_SERVICE"; + case WIFI_DIRECT_CMD_DEREGISTER_LOCAL_SERVICE: + return "WIFI_DIRECT_CMD_DEREGISTER_LOCAL_SERVICE"; + case WIFI_DIRECT_CMD_START_SERVICE_DISCOVERY: + return "WIFI_DIRECT_CMD_START_SERVICE_DISCOVERY"; + case WIFI_DIRECT_CMD_CANCEL_SERVICE_DISCOVERY: + return "WIFI_DIRECT_CMD_CANCEL_SERVICE_DISCOVERY"; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + case WIFI_DIRECT_CMD_INIT_MIRACAST: + return "WIFI_DIRECT_CMD_INIT_MIRACAST"; + case WIFI_DIRECT_CMD_INIT_DISPLAY: + return "WIFI_DIRECT_CMD_INIT_DISPLAY"; + case WIFI_DIRECT_CMD_DEINIT_DISPLAY: + return "WIFI_DIRECT_CMD_DEINIT_DISPLAY"; + case WIFI_DIRECT_CMD_SET_DISPLAY: + return "WIFI_DIRECT_CMD_SET_DISPLAY"; + case WIFI_DIRECT_CMD_SET_DISPLAY_AVAILABILITY: + return "WIFI_DIRECT_CMD_SET_DISPLAY_AVAILABILITY"; + case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_TYPE: + return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_TYPE"; + case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_AVAILABILITY: + return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_AVAILABILITY"; + case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_HDCP: + return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_HDCP"; + case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_PORT: + return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_PORT"; + case WIFI_DIRECT_CMD_GET_PEER_DISPLAY_THROUGHPUT: + return "WIFI_DIRECT_CMD_GET_PEER_DISPLAY_THROUGHPUT"; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ + default: + return "WIFI_DIRECT_CMD_INVALID"; + + } +} + +static int __wfd_client_check_socket(int sock, int timeout) +{ + struct pollfd p_fd; + int res = 0; + + if (sock < 0 || timeout < 0) { + WDC_LOGE("Invalid parameter"); + return -1; + } + + p_fd.fd = sock; + p_fd.events = POLLIN | POLLERR | POLLHUP | POLLNVAL; + res = poll((struct pollfd *) &p_fd, 1, timeout); + + if (res < 0) { + WDC_LOGE("Polling error from socket[%d]. [%s]", sock, strerror(errno)); + return -1; + } else if (res == 0) { + WDC_LOGD( "poll timeout. socket is busy"); + return 1; + } else { + if (p_fd.revents & POLLERR) { + WDC_LOGE("Error! POLLERR from socket[%d]", sock); + return -1; + } else if (p_fd.revents & POLLHUP) { + WDC_LOGE("Error! POLLHUP from socket[%d]", sock); + return -1; + } else if (p_fd.revents & POLLNVAL) { + WDC_LOGE("Error! POLLNVAL from socket[%d]", sock); + return -1; + } else if (p_fd.revents & POLLIN) { + WDC_LOGD("POLLIN from socket [%d]", sock); + return 0; + } + } + + WDC_LOGD("Unknown poll event [%d]", p_fd.revents); + return -1; +} + +static int __wfd_client_write_socket(int sockfd, void *data, int data_len) +{ + __WDC_LOG_FUNC_START__; + int wbytes = 0; + + if (sockfd < 0 || !data || data_len <= 0) { + WDC_LOGE("Invalid parameter"); + __WDC_LOG_FUNC_END__; + return -1; + } + + WDC_LOGD("Write [%d] bytes to socket [%d].", data_len, sockfd); + wbytes = write(sockfd, (char*) data, data_len); + if (wbytes <= 0) { + WDC_LOGE("Error!!! writing to the socket. Error = %s", strerror(errno)); + __WDC_LOG_FUNC_END__; + return -1; + } + + __WDC_LOG_FUNC_END__; + return 0; +} + +static int __wfd_client_read_socket(int sockfd, char *data, int data_len) +{ + __WDC_LOG_FUNC_START__; + int rbytes = 0; + int total_rbytes = 0; + int res = 0; + + if (sockfd < 0) { + WDC_LOGE("Error!!! Invalid socket FD [%d]", sockfd); + __WDC_LOG_FUNC_END__; + return -1; + } + + if (!data || data_len <= 0) { + WDC_LOGE("Error!!! Invalid parameter"); + __WDC_LOG_FUNC_END__; + return -1; + } + + res = __wfd_client_check_socket(sockfd, 10000); + if (res < 0) { + WDC_LOGE("Socket error"); + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } else if (res > 0) { + WDC_LOGE("Socket is busy"); + return WIFI_DIRECT_ERROR_RESOURCE_BUSY; + } + + while(data_len) { + rbytes = read(sockfd, data, data_len); + if (rbytes <= 0) { + WDC_LOGE("Failed to read socket[%d] [%s]", sockfd, strerror(errno)); + return -1; + } + total_rbytes += rbytes; + data += rbytes; + data_len -= rbytes; + } + + __WDC_LOG_FUNC_END__; + return total_rbytes; +} + +static int __wfd_client_send_request(int sockfd, wifi_direct_client_request_s *req, + wifi_direct_client_response_s *rsp) +{ + __WDC_LOG_FUNC_START__; + int res = 0; + + if (!req || !rsp || sockfd < 0) { + WDC_LOGE("Invalid parameter"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + pthread_mutex_lock(&g_client_info.mutex); + res = __wfd_client_write_socket(sockfd, req, sizeof(wifi_direct_client_request_s)); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("Succeeded to send request [%d: %s]", req->cmd, __wfd_client_print_cmd(req->cmd)); + + res = __wfd_client_read_socket(sockfd, (char*) rsp, sizeof(wifi_direct_client_response_s)); + pthread_mutex_unlock(&g_client_info.mutex); + if (res <= 0) { + WDC_LOGE("Failed to read socket [%d]", res); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp->cmd != req->cmd) { + WDC_LOGE("Invalid resp [%d], Original request [%d]", rsp->cmd, req->cmd); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp->result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Result received [%s]", __wfd_print_error(rsp->result)); + __WDC_LOG_FUNC_END__; + return rsp->result; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +static gboolean __wfd_client_process_event(GIOChannel *source, + GIOCondition condition, + gpointer data) +{ + wfd_client_event_e event = WIFI_DIRECT_CLI_EVENT_INVALID; + wifi_direct_client_info_s *client = __wfd_get_control(); + int sockfd = client->async_sockfd; + wifi_direct_client_noti_s client_noti; + wifi_direct_error_e error = WIFI_DIRECT_ERROR_NONE; + char param1[64] = { 0, }; + char param2[256] = { 0, }; +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + int service_type; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + int res = 0; + + memset(&client_noti, 0, sizeof(wifi_direct_client_noti_s)); + + // 1.Read socket + res = __wfd_client_read_socket(sockfd, (char*) &client_noti, + sizeof(wifi_direct_client_noti_s)); + if (res <= 0) { + WDC_LOGE("Error!!! Reading Async Event[%d]", sockfd); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return false; + } + WDC_LOGD( "Received Event is [%d,%s], error[%d]", client_noti.event, + __wfd_print_event(client_noti.event), client_noti.error); + + event = client_noti.event; + error = client_noti.error; +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + service_type = client_noti.type; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + memcpy(param1, client_noti.param1, sizeof(client_noti.param1)); + memcpy(param2, client_noti.param2, sizeof(client_noti.param2)); + + + // 2. dispatch event + switch (event) { + case WIFI_DIRECT_CLI_EVENT_ACTIVATION: + case WIFI_DIRECT_CLI_EVENT_DEACTIVATION: + if (!client->activation_cb) { + WDC_LOGE("activation_cb is NULL!!"); + break; + } + client->activation_cb(error, + (wifi_direct_device_state_e) __wfd_convert_client_event(event), + client->user_data_for_cb_activation); + break; + case WIFI_DIRECT_CLI_EVENT_DISCOVER_FOUND_PEERS: + if (client->peer_found_cb) { + client->peer_found_cb(error, + (wifi_direct_discovery_state_e) __wfd_convert_client_event(event), + param1, client->user_data_for_cb_discover); + } + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START: + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_LISTEN_ONLY: + case WIFI_DIRECT_CLI_EVENT_DISCOVER_START_SEARCH_LISTEN: + case WIFI_DIRECT_CLI_EVENT_DISCOVER_END: + if (!client->discover_cb) { + WDC_LOGE("discover_cb is NULL!!"); + break; + } + client->discover_cb(error, + (wifi_direct_discovery_state_e) __wfd_convert_client_event(event), + client->user_data_for_cb_discover); + break; + case WIFI_DIRECT_CLI_EVENT_CONNECTION_START: + case WIFI_DIRECT_CLI_EVENT_CONNECTION_REQ: + case WIFI_DIRECT_CLI_EVENT_CONNECTION_RSP: + case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_RSP: + case WIFI_DIRECT_CLI_EVENT_CONNECTION_WPS_REQ: + case WIFI_DIRECT_CLI_EVENT_DISCONNECTION_IND: + case WIFI_DIRECT_CLI_EVENT_DISASSOCIATION_IND: + case WIFI_DIRECT_CLI_EVENT_GROUP_CREATE_RSP: + case WIFI_DIRECT_CLI_EVENT_GROUP_DESTROY_RSP: + if (!client->connection_cb) { + WDC_LOGE("connection_cb is NULL!!"); + break; + } + client->connection_cb(error, + (wifi_direct_connection_state_e) __wfd_convert_client_event(event), + param1, client->user_data_for_cb_connection); + break; + + // ToDo: Handling IP lease event... + case WIFI_DIRECT_CLI_EVENT_IP_LEASED_IND: + if (!client->ip_assigned_cb) { + WDC_LOGE("ip_assigned_cb is NULL!!"); + break; + } + char *ifname = NULL; + ifname = vconf_get_str(VCONFKEY_IFNAME); + if (!ifname) { + WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_IFNAME); + break; + } + WDC_LOGD("VCONFKEY_IFNAME(%s) : %s", VCONFKEY_IFNAME, ifname); + client->ip_assigned_cb(param1, param2, ifname, + client->user_data_for_cb_ip_assigned); + free(ifname); + break; + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_STARTED: + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FOUND: + case WIFI_DIRECT_CLI_EVENT_SERVICE_DISCOVERY_FINISHED: + if (!client->service_cb) { + WDC_LOGE("service_cb is NULL!!\n"); + break; + } + client->service_cb(error, + (wifi_direct_service_discovery_state_e) __wfd_convert_client_event(event), + (wifi_direct_service_type_e) service_type, param2, param1, client->user_data_for_cb_service); + break; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + default: + break; + } + + __WDC_LOG_FUNC_END__; + + return TRUE; +} + +void __wfd_client_print_entry_list(wfd_discovery_entry_s *list, int num) +{ + int i = 0; + + WDC_LOGD("------------------------------------------"); + for (i = 0; i < num; i++) + { + WDC_LOGD("== Peer index : %d ==", i); + WDC_LOGD("is Group Owner ? %s", list[i].is_group_owner ? "YES" : "NO"); + WDC_LOGD("device_name : %s", list[i].device_name); + WDC_LOGD("MAC address : "MACSECSTR, MAC2SECSTR(list[i].mac_address)); + WDC_LOGD("wps cfg method : %x", list[i].wps_cfg_methods); + WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory); + WDC_LOGD("Listen channel: %d", list[i].channel); + } + WDC_LOGD("------------------------------------------"); +} + +void __wfd_client_print_connected_peer_info(wfd_connected_peer_info_s *list, int num) +{ + int i = 0; + + WDC_LOGD("------------------------------------------\n"); + for (i = 0; i < num; i++) { + WDC_LOGD("== Peer index : %d ==\n", i); + WDC_LOGD("device_name : %s\n", list[i].device_name); + WDC_LOGD("Device MAC : " MACSECSTR "\n", MAC2SECSTR(list[i].mac_address)); + WDC_LOGD("Device Type: %d - %d", list[i].category, list[i].subcategory); + WDC_LOGD("channel : %d\n", list[i].channel); + WDC_LOGD("IP ["IPSECSTR"]\n", IP2SECSTR(list[i].ip_address)); + } + WDC_LOGD("------------------------------------------\n"); +} + +void __wfd_client_print_persistent_group_info(wfd_persistent_group_info_s *list, int num) +{ + int i = 0; + + WDC_LOGD("------------------------------------------\n"); + for (i = 0; i < num; i++) { + WDC_LOGD("== Persistent Group index : %d ==", i); + WDC_LOGD("ssid : %s", list[i].ssid); + WDC_LOGD("GO MAC : " MACSECSTR, MAC2SECSTR(list[i].go_mac_address)); + } + WDC_LOGD("------------------------------------------\n"); +} + +static int __wfd_client_async_event_init(int clientid) +{ + __WDC_LOG_FUNC_START__; + int sockfd = 0; + struct sockaddr_un saddr; + wifi_direct_client_request_s req; + int res = 0; + + sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sockfd < 0) { + WDC_LOGE("Failed to async socket[%s]", strerror(errno)); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("Succeeded to create async socket[%d]", sockfd); + + memset(&saddr, 0, sizeof(saddr)); + saddr.sun_family = AF_UNIX; + g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), WFD_SOCK_FILE_PATH); + + WDC_LOGD("Connecting to server socket to register async socket [%d]", sockfd); + res = connect(sockfd, (struct sockaddr *) &saddr, sizeof(saddr)); + if (res < 0) { + WDC_LOGE("Error!!! connecting to server socket. Error = [%s].", strerror(errno)); + close(sockfd); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + + req.cmd = WIFI_DIRECT_CMD_INIT_ASYNC_SOCKET; + req.client_id = clientid; + + res = __wfd_client_write_socket(sockfd, &req, sizeof(wifi_direct_client_request_s)); + if (res < WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Failed to write to socket[%s]", strerror(errno)); + WDC_LOGE("Error!!! [%s]", __wfd_print_error(res)); + close(sockfd); + __WDC_LOG_FUNC_END__; + return res; + } + g_client_info.async_sockfd = sockfd; + + WDC_LOGE("Async socket is created= %d", sockfd); + + return sockfd; +} + +static int __wfd_client_launch_server_dbus(void) +{ + GDBusConnection *netconfig_bus = NULL; + GError *g_error = NULL; + +#if !GLIB_CHECK_VERSION(2,36,0) + g_type_init(); +#endif + netconfig_bus = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &g_error); + if (netconfig_bus == NULL) { + if(g_error != NULL) { + WDC_LOGE("Couldn't connect to system bus " + "error [%d: %s]", g_error->code, g_error->message); + g_error_free(g_error); + } + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + g_dbus_connection_call_sync(netconfig_bus, + NETCONFIG_SERVICE, + NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, + NETCONFIG_WIFI_LAUNCHDIRECT, + NULL, + NULL, + G_DBUS_CALL_FLAGS_NONE, + DBUS_REPLY_TIMEOUT, + NULL, + &g_error); + + if(g_error !=NULL) { + WDC_LOGE("g_dbus_connection_call_sync() failed" + "error [%d: %s]", g_error->code, g_error->message); + g_error_free(g_error); + return WIFI_DIRECT_ERROR_PERMISSION_DENIED; + } + + g_object_unref(netconfig_bus); + + WDC_LOGD("Successfully launched wfd-manager"); + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_initialize(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + struct sockaddr_un saddr; + wifi_direct_client_request_s req; + wifi_direct_client_response_s resp; + int retry_count = 10; + int sockfd = 0; + bool wifi_direct_enable; + int res = 0; + + if (g_client_info.is_registered == TRUE) { + WDC_LOGW("Warning!!! Already registered\nUpdate user data and callback!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_ALREADY_INITIALIZED; + } + +/*TEMP: Hawk-P Tizen TV Platform does not support security check*/ +#if !defined TIZEN_TV + res = system_info_get_platform_bool("tizen.org/feature/network.wifi.direct", &wifi_direct_enable); + if (res < 0) { + WDC_LOGE("Failed to get sys info"); + __WDC_LOG_FUNC_END__; + return res; + } + if(!wifi_direct_enable) { + WDC_LOGE("Wi-Fi Direct not supported"); + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; + } + +#endif + sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sockfd < 0) { + WDC_LOGE("Error!!! creating sync socket[%s]", strerror(errno)); + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("Created sync socket [%d]", sockfd); + + memset(&saddr, 0, sizeof(saddr)); + saddr.sun_family = AF_UNIX; + g_snprintf(saddr.sun_path, sizeof(saddr.sun_path), WFD_SOCK_FILE_PATH); + + WDC_LOGD("Connecting to server socket to register sync socket [%d]", sockfd); + while (retry_count > 0) { + res = connect(sockfd, (struct sockaddr*) &saddr, sizeof(saddr)); + if (!res){ + WDC_LOGD("Succeeded to connect to server socket[%s]", strerror(errno)); + break; + } + + WDC_LOGD("Launching wfd-server..\n"); + res = __wfd_client_launch_server_dbus(); + if (res != WIFI_DIRECT_ERROR_NONE) + WDC_LOGE("Failed to send dbus msg[%s]", strerror(errno)); + retry_count--; + + /* wait a little before retrying the next socket connection */ + usleep(150000); + } + + if (res < 0) { + WDC_LOGE("Failed to connect to wfd-manager socket[%s]", strerror(errno)); + close(sockfd); + __WDC_LOG_FUNC_END__; + return res; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&resp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_REGISTER; + req.client_id = gettid(); + WDC_LOGD("Client ID = %d", req.client_id); + + res = __wfd_client_send_request(sockfd, &req, &resp); + if (res < 0) { + WDC_LOGE("Failed to register client"); + close(sockfd); + __WDC_LOG_FUNC_END__; + return res; + } + g_client_info.sync_sockfd = sockfd; + g_client_info.client_id = resp.client_id; + g_client_info.is_registered = TRUE; + + int async_sockfd = -1; + async_sockfd = __wfd_client_async_event_init(g_client_info.client_id); + if (async_sockfd < 0) { + WDC_LOGE("Failed to create async socket \n"); + close(sockfd); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + g_client_info.async_sockfd = async_sockfd; + + GIOChannel *gio = g_io_channel_unix_new(g_client_info.async_sockfd); + int g_source_id = g_io_add_watch(gio, G_IO_IN | G_IO_ERR | G_IO_HUP, + (GIOFunc) __wfd_client_process_event, NULL); + g_io_channel_unref(gio); + + g_client_info.g_source_id = g_source_id; + + // Initialize callbacks + g_client_info.activation_cb = NULL; + g_client_info.discover_cb = NULL; + g_client_info.connection_cb = NULL; + g_client_info.ip_assigned_cb = NULL; + + g_client_info.peer_found_cb = NULL; + g_client_info.user_data_for_cb_activation = NULL; + g_client_info.user_data_for_cb_discover = NULL; + g_client_info.user_data_for_cb_connection = NULL; + g_client_info.user_data_for_cb_ip_assigned = NULL; + g_client_info.user_data_for_cb_peer_found = NULL; + g_client_info.user_data_for_cb_device_name = NULL; + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + g_client_info.service_cb = NULL; + g_client_info.user_data_for_cb_service= NULL; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_deinitialize(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is already deregistered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.activation_cb = NULL; + g_client_info.discover_cb = NULL; + g_client_info.connection_cb = NULL; + g_client_info.ip_assigned_cb = NULL; + g_client_info.peer_found_cb = NULL; + g_client_info.user_data_for_cb_activation = NULL; + g_client_info.user_data_for_cb_discover = NULL; + g_client_info.user_data_for_cb_connection = NULL; + g_client_info.user_data_for_cb_ip_assigned = NULL; + g_client_info.user_data_for_cb_peer_found = NULL; + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + g_client_info.service_cb = NULL; + g_client_info.user_data_for_cb_service = NULL; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_DEREGISTER; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res < 0) + WDC_LOGD("Failed to deinitialize. But continue deinitialization"); + else + WDC_LOGD("Deinit Successfull"); + + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_set_device_state_changed_cb(wifi_direct_device_state_changed_cb cb, + void *user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (!cb) { + WDC_LOGE("Invalid parameter"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.activation_cb = cb; + g_client_info.user_data_for_cb_activation = user_data; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_unset_device_state_changed_cb(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.activation_cb = NULL; + g_client_info.user_data_for_cb_activation = NULL; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int +wifi_direct_set_discovery_state_changed_cb(wifi_direct_discovery_state_chagned_cb cb, + void *user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (!cb) { + WDC_LOGE("Callback is NULL.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.discover_cb = cb; + g_client_info.user_data_for_cb_discover = user_data; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_unset_discovery_state_changed_cb(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.discover_cb = NULL; + g_client_info.user_data_for_cb_discover = NULL; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int +wifi_direct_set_peer_found_cb(wifi_direct_peer_found_cb cb, + void *user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (!cb) { + WDC_LOGE("Callback is NULL.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.peer_found_cb = cb; + g_client_info.user_data_for_cb_peer_found = user_data; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_unset_peer_found_cb(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.peer_found_cb = NULL; + g_client_info.user_data_for_cb_peer_found = NULL; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_service_state_changed_cb +(wifi_direct_service_state_changed_cb cb, void *user_data) +{ +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE); + + if (!cb) { + WDC_LOGE("Callback is NULL."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.service_cb = cb; + g_client_info.user_data_for_cb_service = user_data; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ +} + + +int wifi_direct_unset_service_state_changed_cb(void) +{ +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.service_cb = NULL; + g_client_info.user_data_for_cb_service = NULL; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ +} + +int wifi_direct_set_connection_state_changed_cb(wifi_direct_connection_state_changed_cb cb, + void *user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (!cb) { + WDC_LOGE("Callback is NULL.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized.\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.connection_cb = cb; + g_client_info.user_data_for_cb_connection = user_data; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_unset_connection_state_changed_cb(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.connection_cb = NULL; + g_client_info.user_data_for_cb_connection = NULL; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_set_client_ip_address_assigned_cb(wifi_direct_client_ip_address_assigned_cb cb, + void* user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (!cb) { + WDC_LOGE("Callback is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.ip_assigned_cb = cb; + g_client_info.user_data_for_cb_ip_assigned = user_data; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_unset_client_ip_address_assigned_cb(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (g_client_info.is_registered == false) { + WDC_LOGE("Client is not initialized"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + g_client_info.ip_assigned_cb = NULL; + g_client_info.user_data_for_cb_ip_assigned = NULL; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_activate(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_ACTIVATE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_activate() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_deactivate(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_DEACTIVATE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_deactivate() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_start_discovery(bool listen_only, int timeout) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (timeout < 0) { + WDC_LOGE("Nagative value. Param [timeout]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_START_DISCOVERY; + req.client_id = g_client_info.client_id; + req.data.int1 = listen_only; + req.data.int2 = timeout; + WDC_LOGE("listen only (%d) timeout (%d)", listen_only, timeout); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_start_discovery() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_start_discovery_specific_channel(bool listen_only, int timeout, wifi_direct_discovery_channel_e channel) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (timeout < 0) { + WDC_LOGE("Nagative value. Param [timeout]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_START_DISCOVERY_SPECIFIC_CHANNEL; + req.client_id = g_client_info.client_id; + req.data.int1 = timeout; + req.data.int2 = channel; + + WDC_LOGD("timeout (%d) channel (%d)", timeout, channel); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_start_discovery_specific_channel() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_cancel_discovery(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_CANCEL_DISCOVERY; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_cancel_discovery() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY +static char **get_service_list(char *services, unsigned int *count) +{ + __WDC_LOG_FUNC_START__; + char **result = NULL; + char *pos1 = NULL; + char *pos2 = NULL; + unsigned int cnt = 0; + unsigned int i = 0; + unsigned int j = 0; + + if (!count || !services || (services && strlen(services) <= 0)) { + WDC_LOGE("Invalid parameters."); + __WDC_LOG_FUNC_END__; + return NULL; + } + + pos1 = services; + pos2 = g_strdup(services); + + pos1 = strtok (pos1,",\n"); + while (pos1) { + cnt++; + pos1 = strtok (NULL, ",\n"); + } + WDC_LOGD("Total Service Count = %d", cnt); + + if (cnt > 0) { + result = (char**) g_try_malloc0_n(cnt, sizeof(char *)); + if (!result) { + WDC_LOGE("Failed to allocate memory for result"); + g_free(pos2); + return NULL; + } + pos2 = strtok (pos2,",\n"); + while (pos2 != NULL) { + char *s = strchr(pos2, ' '); + if (s) { + *s = '\0'; + result[i++] = strdup(pos2); + pos2 = strtok (NULL, ",\n"); + } + } + } + + g_free(pos1); + g_free(pos2); + + if (cnt == i) { + *count = cnt; + return result; + } else { + *count = 0; + if (result) { + for (j=0; j 1023) { + WDC_LOGE("Discovered peer number restricted by 255(real number:%d)", num); + num_tmp = num -1023; + num = 1023; + } + + if (num > 0) { + buff = (wfd_discovery_entry_s*) g_try_malloc0_n(num, sizeof (wfd_discovery_entry_s)); + if (!buff) { + WDC_LOGE("Failed to alloc memory"); + pthread_mutex_unlock(&g_client_info.mutex); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, + num * sizeof(wfd_discovery_entry_s)); + if (num_tmp) { + WDC_LOGD("Rest data should be read out"); + buff_tmp = (wfd_discovery_entry_s*) g_try_malloc0_n(num_tmp, sizeof (wfd_discovery_entry_s)); + if (buff_tmp) { + __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff_tmp, + num_tmp * sizeof(wfd_discovery_entry_s)); + g_free(buff_tmp); + } + } + pthread_mutex_unlock(&g_client_info.mutex); + if (res <= 0) { + free(buff); + WDC_LOGE("Failed to read socket"); + __wfd_reset_control(); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + __wfd_client_print_entry_list(buff, num); + WDC_LOGD("wifi_direct_foreach_discovered_peers() SUCCESS"); + + wifi_direct_discovered_peer_info_s *peer_list; + + for (i = 0; i < num; i++) { + peer_list = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s)); + peer_list->device_name = g_strndup(buff[i].device_name, WIFI_DIRECT_MAX_DEVICE_NAME_LEN+1); + peer_list->mac_address = (char*) g_try_malloc0(MACSTR_LEN); + g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address)); + peer_list->interface_address = (char*) g_try_malloc0(MACSTR_LEN); + g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].intf_address)); + peer_list->channel = buff[i].channel; + peer_list->is_connected = buff[i].is_connected; + peer_list->is_group_owner = buff[i].is_group_owner; + peer_list->is_persistent_group_owner = buff[i].is_persistent_go; + peer_list->primary_device_type = buff[i].category; + peer_list->secondary_device_type = buff[i].subcategory; + peer_list->supported_wps_types= buff[i].wps_cfg_methods; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + peer_list->is_miracast_device = buff[i].is_wfd_device; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ + + if (!cb(peer_list, user_data)) + break; + } + + g_free(buff); + } else { + pthread_mutex_unlock(&g_client_info.mutex); + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_connect(char *mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("mac_addr is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_CONNECT; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_connect() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_cancel_connection(char *mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) + || (g_client_info.client_id == WFD_INVALID_ID)) + { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("mac_addr is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_CANCEL_CONNECTION; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, req.data.mac_addr); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_cancel_connect() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_reject_connection(char *mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("mac_addr is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_REJECT_CONNECTION; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, req.data.mac_addr); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGE("wifi_direct_reject_connection() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_disconnect_all(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_DISCONNECT_ALL; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGE("wifi_direct_disconnect_all() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_disconnect(char *mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("mac_address is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_DISCONNECT; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, 6); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGE("wifi_direct_disconnect() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; + +} + +int wifi_direct_accept_connection(char *mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("mac_addr is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SEND_CONNECT_REQ; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, 6); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGE("wifi_direct_connect() SUCCESS \n"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_foreach_connected_peers(wifi_direct_connected_peer_cb cb, + void *user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + int i; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!cb) { + WDC_LOGE("NULL Param [callback]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_CONNECTED_PEERS_INFO; + req.client_id = g_client_info.client_id; + + pthread_mutex_lock(&g_client_info.mutex); + res = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd)); + + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + if (res <= 0) { + WDC_LOGE("Failed to read socket [%d]", res); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.cmd != req.cmd) { + WDC_LOGE("Invalid resp [%d]", rsp.cmd); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result)); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + + short num = rsp.param1; + wfd_connected_peer_info_s *buff = NULL; + + WDC_LOGD("Num of connected peers = %d", (int) rsp.param1); + + if (num > 8 || num < 1) { + WDC_LOGE("Invalid number of connected peer(%d)", num); + buff = (wfd_connected_peer_info_s*) g_try_malloc0_n(num, sizeof(wfd_connected_peer_info_s)); + if (!buff) { + WDC_LOGE("malloc() failed!!!"); + pthread_mutex_unlock(&g_client_info.mutex); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + res= __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, + num * sizeof(wfd_connected_peer_info_s)); + pthread_mutex_unlock(&g_client_info.mutex); + } else if (num < 1) { + WDC_LOGE("Invalid number of connected peer(%d)", num); + pthread_mutex_unlock(&g_client_info.mutex); + } else { + buff = (wfd_connected_peer_info_s*) g_try_malloc0_n(num, sizeof(wfd_connected_peer_info_s)); + if (!buff) { + WDC_LOGE("malloc() failed!!!"); + pthread_mutex_unlock(&g_client_info.mutex); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + res= __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, + num * sizeof(wfd_connected_peer_info_s)); + pthread_mutex_unlock(&g_client_info.mutex); + if (res <= 0) { + free(buff); + WDC_LOGE("socket read error"); + __wfd_reset_control(); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + __wfd_client_print_connected_peer_info(buff, num); + WDC_LOGD("wifi_direct_foreach_connected_peers() SUCCESS"); + + wifi_direct_connected_peer_info_s *peer_list = NULL; + + for (i = 0; i < num; i++) { + peer_list = (wifi_direct_connected_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_connected_peer_info_s)); + peer_list->device_name = g_strdup(buff[i].device_name); + peer_list->ip_address= (char*) g_try_malloc0(IPSTR_LEN); + g_snprintf(peer_list->ip_address, IPSTR_LEN, IPSTR, IP2STR(buff[i].ip_address)); + peer_list->mac_address = (char*) calloc(1, MACSTR_LEN); + g_snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address)); + peer_list->interface_address = (char*) g_try_malloc0( MACSTR_LEN); + g_snprintf(peer_list->interface_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].intf_address)); + peer_list->p2p_supported = buff[i].is_p2p; + peer_list->primary_device_type = buff[i].category; + peer_list->secondary_device_type = buff[i].subcategory; + peer_list->channel = buff[i].channel; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + peer_list->is_miracast_device = buff[i].is_wfd_device; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ + + if (!cb(peer_list, user_data)) + break; + } + g_free(buff); + buff = NULL; + } + g_free(buff); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_create_group(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_CREATE_GROUP; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGE("wifi_direct_create_group() SUCCESS \n"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_destroy_group(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_DESTROY_GROUP; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGE("wifi_direct_destroy_group() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_is_group_owner(bool *owner) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!owner) { + WDC_LOGE("NULL Param [owner]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_IS_GROUPOWNER; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_is_group_owner() SUCCESS"); + *owner = (bool) rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_is_autonomous_group(bool *autonomous_group) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!autonomous_group) { + WDC_LOGE("NULL Param [autonomous_group]!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_IS_AUTONOMOUS_GROUP; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_is_autonomous_group() SUCCESS"); + *autonomous_group = (bool) rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_set_group_owner_intent(int intent) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (intent < 0 || intent > 15) { + WDC_LOGE("Invalid Param : intent[%d]", intent); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_GO_INTENT; + req.client_id = g_client_info.client_id; + req.data.int1 = intent; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_set_group_owner_intent() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_group_owner_intent(int *intent) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!intent) { + WDC_LOGE("Invalid Parameter"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_GO_INTENT; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("int wifi_direct_get_group_owner_intent() intent[%d] SUCCESS", rsp.param1); + *intent = rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_max_clients(int max) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + WDC_LOGD("max client [%d]\n", max); + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_MAX_CLIENT; + req.client_id = g_client_info.client_id; + req.data.int1 = max; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("int wifi_direct_set_max_clients() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_max_clients(int *max) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!max) { + WDC_LOGE("Invalid Parameter"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_MAX_CLIENT; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("int wifi_direct_get_max_clients() max_client[%d] SUCCESS", rsp.param1); + *max = rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_operating_channel(int *channel) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!channel) { + WDC_LOGE("NULL Param [channel]!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_OPERATING_CHANNEL; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("channel = [%d]", (int) rsp.param1); + *channel = rsp.param1; + + __WDC_LOG_FUNC_END__; + + return WIFI_DIRECT_ERROR_NONE; + +} + +int wifi_direct_activate_pushbutton(void) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_activate_pushbutton() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_wps_pin(char *pin) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int status = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!pin) { + WDC_LOGE("NULL Param [pin]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + WDC_LOGE("pin = [%s]\n", pin); + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_WPS_PIN; + req.client_id = g_client_info.client_id; + req.cmd_data_len = WIFI_DIRECT_WPS_PIN_LEN+1; + + pthread_mutex_lock(&g_client_info.mutex); + status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("writing msg hdr is success!\n"); + + status = __wfd_client_write_socket(g_client_info.sync_sockfd, pin, + WIFI_DIRECT_WPS_PIN_LEN); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + pthread_mutex_unlock(&g_client_info.mutex); + if (status <= 0) { + WDC_LOGE("Error!!! reading socket, status = %d", status); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.cmd != req.cmd) { + WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGD("Error!!! Result received = %d", rsp.result); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_get_wps_pin(char **pin) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + char la_pin[WIFI_DIRECT_WPS_PIN_LEN + 1] = { 0, }; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_WPS_PIN; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_wps_pin() SUCCESS"); + g_strlcpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN +1); + *pin = g_strdup(la_pin); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_supported_wps_mode(int *wps_mode) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!wps_mode) { + WDC_LOGE("NULL Param [wps_mode]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("Supported wps config = [%d]", (int) rsp.param1); + *wps_mode = rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_foreach_supported_wps_types(wifi_direct_supported_wps_type_cb cb, void* user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!cb) { + WDC_LOGE("NULL Param [callback]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_SUPPORTED_WPS_MODE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("Supported wps config = [%d]", (int) rsp.param1); + + int wps_mode; + bool result = TRUE; + + wps_mode = rsp.param1; + if (wps_mode & WIFI_DIRECT_WPS_TYPE_PBC) + result = cb(WIFI_DIRECT_WPS_TYPE_PBC, user_data); + if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)) + result = cb(WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, user_data); + if ((result == true) && (wps_mode & WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD)) + result = cb(WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD, user_data); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_local_wps_type(wifi_direct_wps_type_e *type) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type == NULL) { + WDC_LOGE("NULL Param [type]!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_LOCAL_WPS_MODE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_wps_type() SUCCESS"); + *type = rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_req_wps_type(wifi_direct_wps_type_e type) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type == WIFI_DIRECT_WPS_TYPE_PBC || + type == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY || + type == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD) { + WDC_LOGD("Param wps_mode [%d]", type); + } else { + WDC_LOGE("Invalid Param [wps_mode]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_REQ_WPS_MODE; + req.client_id = g_client_info.client_id; + req.data.int1 = type; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_set_req_wps_type() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_req_wps_type(wifi_direct_wps_type_e *type) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type == NULL) { + WDC_LOGE("NULL Param [type]!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_REQ_WPS_MODE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_req_wps_type() SUCCESS"); + *type = rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_ssid(char **ssid) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + char la_ssid[WIFI_DIRECT_MAX_SSID_LEN + 1] = { 0, }; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!ssid) { + WDC_LOGE("NULL Param [ssid]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_SSID; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_ssid() %s SUCCESS", rsp.param2); + g_strlcpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN + 1); + *ssid = g_strdup(la_ssid); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_device_name(char **device_name) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + char la_device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1] = { 0, }; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!device_name) { + WDC_LOGE("NULL Param [device_name]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_DEVICE_NAME; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_device_name() %s SUCCESS \n", rsp.param2); + g_strlcpy(la_device_name, rsp.param2, WIFI_DIRECT_MAX_DEVICE_NAME_LEN + 1); + *device_name = g_strdup(la_device_name); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_device_name(const char *device_name) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int status = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!device_name) { + WDC_LOGE("NULL Param [device_name]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + WDC_LOGE("device_name = [%s]", device_name); + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_DEVICE_NAME; + req.client_id = g_client_info.client_id; + + pthread_mutex_lock(&g_client_info.mutex); + status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD( "writing msg hdr is success!\n"); + + status = __wfd_client_write_socket(g_client_info.sync_sockfd, (void*) device_name, + WIFI_DIRECT_MAX_DEVICE_NAME_LEN); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + pthread_mutex_unlock(&g_client_info.mutex); + if (status <= 0) { + WDC_LOGE("Error!!! reading socket, status = %d", status); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } else { + if (rsp.cmd == WIFI_DIRECT_CMD_SET_DEVICE_NAME) { + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! Result received = %d", rsp.result); + WDC_LOGE("Error!!! [%s]", __wfd_print_error(rsp.result)); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + } else { + WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_network_interface_name(char **name) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_state_e status = 0; + char *get_str = NULL; + int result; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!name) { + WDC_LOGE("NULL Param [name]!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + result = wifi_direct_get_state(&status); + WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]\n", status, result); + + if (status < WIFI_DIRECT_STATE_CONNECTED) { + WDC_LOGE("Device is not connected!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + + get_str = vconf_get_str(VCONFKEY_IFNAME); + if (!get_str) { + WDC_LOGD( "vconf (%s) value is NULL!!!\n", VCONFKEY_IFNAME); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + WDC_LOGD( "VCONFKEY_IFNAME(%s) : %s\n", VCONFKEY_IFNAME, get_str); + *name = g_strdup(get_str); + g_free(get_str); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_ip_address(char **ip_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = 0; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!ip_address) { + WDC_LOGE("NULL Param [ip_address]!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_IP_ADDR; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + *ip_address = g_strdup(rsp.param2); + WDC_LOGD("IP address = [%s]", *ip_address); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_subnet_mask(char **subnet_mask) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_state_e status = 0; + char *get_str = NULL; + int result; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!subnet_mask) { + WDC_LOGE("NULL Param [subnet_mask]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + result = wifi_direct_get_state(&status); + WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]", status, result); + if( status < WIFI_DIRECT_STATE_CONNECTED) { + WDC_LOGE("Device is not connected!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + + get_str = vconf_get_str(VCONFKEY_SUBNET_MASK); + if (!get_str) { + WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_SUBNET_MASK); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + WDC_LOGD("VCONFKEY_SUBNET_MASK(%s) : %s", VCONFKEY_SUBNET_MASK, get_str); + *subnet_mask = g_strdup(get_str); + g_free(get_str); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_gateway_address(char **gateway_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_state_e status = 0; + char *get_str = NULL; + int result; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!gateway_address) { + WDC_LOGE("NULL Param [gateway_address]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + result = wifi_direct_get_state(&status); + WDC_LOGD("wifi_direct_get_state() state=[%d], result=[%d]", status, result); + if(status < WIFI_DIRECT_STATE_CONNECTED) { + WDC_LOGE("Device is not connected!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + + get_str = vconf_get_str(VCONFKEY_GATEWAY); + if (!get_str) { + WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_GATEWAY); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + WDC_LOGD("VCONFKEY_GATEWAY(%s) : %s", VCONFKEY_GATEWAY, get_str); + *gateway_address = g_strdup(get_str); + g_free(get_str); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_mac_address(char **mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("NULL Param [mac_address]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_MAC_ADDR; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + *mac_address = g_strdup(rsp.param2); + WDC_SECLOGD("MAC address = [%s]", *mac_address); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_get_state(wifi_direct_state_e *state) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if (!state) { + WDC_LOGE("NULL Param [state]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_LINK_STATUS; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("Link Status = %d", (int) rsp.param1); + *state = (wifi_direct_state_e) rsp.param1; + + /* for CAPI : there is no WIFI_DIRECT_STATE_GROUP_OWNER type in CAPI */ + if(*state == WIFI_DIRECT_STATE_GROUP_OWNER) + *state = WIFI_DIRECT_STATE_CONNECTED; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_is_discoverable(bool* discoverable) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!discoverable) { + WDC_LOGE("NULL Param [discoverable]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_IS_DISCOVERABLE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_is_discoverable() SUCCESS"); + *discoverable = (bool) rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_is_listening_only(bool* listen_only) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!listen_only) { + WDC_LOGE("NULL Param [listen_only]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_IS_LISTENING_ONLY; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_is_listening_only() SUCCESS"); + *listen_only = (bool) rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_get_primary_device_type(wifi_direct_primary_device_type_e* type) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if (!type) { + WDC_LOGE("NULL Param [type]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + WDC_LOGD("Current primary_dev_type [%d]", WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE); + *type = WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_secondary_device_type(wifi_direct_secondary_device_type_e* type) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (NULL == type) { + WDC_LOGE("NULL Param [type]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + WDC_LOGD("Current second_dev_type [%d]", WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL); + *type = WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL; // smart phone dual mode (wifi and cellular) + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_autoconnection_mode(bool mode) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_AUTOCONNECTION_MODE; + req.client_id = g_client_info.client_id; + req.data.int1 = mode; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_is_autoconnection_mode(bool *mode) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mode) { + WDC_LOGE("NULL Param [mode]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_IS_AUTOCONNECTION_MODE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_is_autoconnection_mode() SUCCESS"); + *mode = (bool) rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; + +} + + +int wifi_direct_set_persistent_group_enabled(bool enabled) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + if (enabled == true) + req.cmd = WIFI_DIRECT_CMD_ACTIVATE_PERSISTENT_GROUP; + else + req.cmd = WIFI_DIRECT_CMD_DEACTIVATE_PERSISTENT_GROUP; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_set_persistent_group_enabled() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + + +int wifi_direct_is_persistent_group_enabled(bool *enabled) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!enabled) { + WDC_LOGE("NULL Param [enabled]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_IS_PERSISTENT_GROUP; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_is_persistent_group_enabled() SUCCESS"); + *enabled = (bool) rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_foreach_persistent_groups(wifi_direct_persistent_group_cb cb, + void* user_data) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + int i; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!cb) { + WDC_LOGE("NULL Param [callback]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PERSISTENT_GROUP_INFO; + req.client_id = g_client_info.client_id; + + pthread_mutex_lock(&g_client_info.mutex); + res = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, sizeof(wifi_direct_client_request_s)); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd)); + + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + if (res <= 0) { + WDC_LOGE("Failed to read socket [%d]", res); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.cmd != req.cmd) { + WDC_LOGE("Invalid resp [%d]", rsp.cmd); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result)); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + + short num = rsp.param1; + short num_tmp = 0; + wfd_persistent_group_info_s *buff = NULL; + wfd_persistent_group_info_s *buff_tmp = NULL; + + WDC_LOGD("Num of persistent groups = %d", (int) rsp.param1); + + if (num > 1023) { + WDC_LOGE("Discovered peer number restricted by 255(real number:%d)", num); + num_tmp = num -1023; + num = 1023; + } + + if (num > 0) { + buff = (wfd_persistent_group_info_s *) g_try_malloc0_n(num, sizeof(wfd_persistent_group_info_s)); + if (!buff) { + WDC_LOGE("malloc() failed!!!."); + pthread_mutex_unlock(&g_client_info.mutex); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, + num * sizeof(wfd_persistent_group_info_s)); + if (num_tmp) { + WDC_LOGD("Rest data should be read out"); + buff_tmp = (wfd_persistent_group_info_s*) calloc(num_tmp, sizeof (wfd_persistent_group_info_s)); + if (buff_tmp) { + __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff_tmp, + num_tmp * sizeof(wfd_persistent_group_info_s)); + g_free(buff_tmp); + } + } + pthread_mutex_unlock(&g_client_info.mutex); + if (res <= 0){ + free(buff); + WDC_LOGE("socket read error."); + __wfd_reset_control(); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + __wfd_client_print_persistent_group_info(buff, num); + WDC_LOGD("wifi_direct_foreach_persistent_groups() SUCCESS"); + + char *ssid; + char *go_mac_address; + + for (i = 0; i < num; i++) { + ssid = g_strndup(buff[i].ssid, WIFI_DIRECT_MAX_SSID_LEN+1); + if (!ssid) { + WDC_LOGD("Failed to copy ssid"); + break; + } + go_mac_address = (char*) g_try_malloc0(MACSTR_LEN); + if (!go_mac_address) { + WDC_LOGD("Failed to allocate memory for GO MAC address"); + g_free(ssid); + g_free(buff); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + g_snprintf(go_mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].go_mac_address)); + + res = cb(go_mac_address, ssid, user_data); + g_free(ssid); + ssid = NULL; + g_free(go_mac_address); + go_mac_address = NULL; + if (!res) + break; + } + g_free(buff); + + } else { + pthread_mutex_unlock(&g_client_info.mutex); + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_remove_persistent_group(char *mac_address, const char *ssid) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + wfd_persistent_group_info_s persistent_group_info; + int status = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address || !ssid) { + WDC_LOGE("NULL Param"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_REMOVE_PERSISTENT_GROUP; + req.client_id = g_client_info.client_id; + + pthread_mutex_lock(&g_client_info.mutex); + status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("writing msg hdr is success!"); + + g_strlcpy(persistent_group_info.ssid, ssid, WIFI_DIRECT_MAX_SSID_LEN + 1); + macaddr_atoe(mac_address, persistent_group_info.go_mac_address); + + status = __wfd_client_write_socket(g_client_info.sync_sockfd, &persistent_group_info, + sizeof(wfd_persistent_group_info_s)); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + pthread_mutex_unlock(&g_client_info.mutex); + if (status <= 0) { + WDC_LOGE("Error!!! reading socket, status = %d", status); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.cmd !=req.cmd) { + WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGD("Error!!! Result received = %d", rsp.result); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_p2poem_loglevel(int increase_log_level) +{ + __WDC_LOG_FUNC_START__; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_OEM_LOGLEVEL; + req.client_id = g_client_info.client_id; + if (increase_log_level == 0) + req.data.int1 = false; + else + req.data.int1 = true; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_start_service_discovery(char *mac_address, + wifi_direct_service_type_e type) +{ +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE); + + unsigned char la_mac_addr[MACADDR_LEN] = {0, }; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL && + type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) { + WDC_LOGD("Param service_type [%d]", type); + } else { + WDC_LOGE("Invalid Param [type]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_START_SERVICE_DISCOVERY; + req.client_id = g_client_info.client_id; + req.data.int1 = type; + if (mac_address) + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ +} + + +int wifi_direct_cancel_service_discovery(char *mac_address, + wifi_direct_service_type_e type) +{ +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE); + + unsigned char la_mac_addr[MACADDR_LEN] = {0, }; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type >= WIFI_DIRECT_SERVICE_TYPE_ALL && + type <= WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) { + WDC_LOGD("Param service_type [%d]", type); + } else { + WDC_LOGE("Invalid Param [type]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_CANCEL_SERVICE_DISCOVERY; + req.client_id = g_client_info.client_id; + req.data.int1 = type; + if (mac_address) + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ +} + +int wifi_direct_register_service(wifi_direct_service_type_e type, char *info1, char *info2, unsigned int *service_id) +{ +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + char *buf = NULL; + int status = WIFI_DIRECT_ERROR_NONE; + int len = 0; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!info1) { + WDC_LOGE("data is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + if (type < WIFI_DIRECT_SERVICE_TYPE_ALL || + type > WIFI_DIRECT_SERVICE_TYPE_VENDOR) { + WDC_LOGE("Invalid Param [type]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + WDC_LOGD("Service type [%d]", type); + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + len = strlen(info1) + strlen(info2) + 2; + WDC_LOGD("info [%s|%s], len [%d]", info1, info2, len); + buf= g_try_malloc0(sizeof(wifi_direct_client_request_s) + len); + if (NULL == buf) { + WDC_LOGE("Failed to allocate memory for buf"); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + + req.cmd = WIFI_DIRECT_CMD_REGISTER_SERVICE; + req.client_id = g_client_info.client_id; + req.data.int1 = type; + req.cmd_data_len = len; + + memcpy(buf, &req, sizeof(wifi_direct_client_request_s)); + g_snprintf(buf + sizeof(wifi_direct_client_request_s), len, "%s|%s", info1, info2); + + pthread_mutex_lock(&g_client_info.mutex); + status = __wfd_client_write_socket(g_client_info.sync_sockfd, buf, + sizeof(wifi_direct_client_request_s) + len); + g_free(buf); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket, Errno = %s", strerror(errno)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("Success writing data to the socket!"); + + status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + pthread_mutex_unlock(&g_client_info.mutex); + if (status <= 0) { + WDC_LOGE("Error!!! reading socket, status = %d errno = %s", status, strerror(errno)); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.cmd != req.cmd) { + WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! Result received = %d", rsp.result); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + + *service_id = rsp.param1; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ +} + +int wifi_direct_deregister_service(unsigned int service_id) +{ +#ifdef TIZEN_FEATURE_SERVICE_DISCOVERY + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_SERVICE_DISCOVERY_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = 0; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_DEREGISTER_SERVICE; + req.client_id = g_client_info.client_id; + req.data.int1 = service_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_SERVICE_DISCOVERY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_SERVICE_DISCOVERY */ +} + +int wifi_direct_init_miracast(bool enable) +{ +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_INIT_MIRACAST; + req.client_id = g_client_info.client_id; + req.data.int1 = enable; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_get_peer_info(char* mac_address, wifi_direct_discovered_peer_info_s** peer_info) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("mac_addr is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PEER_INFO; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, req.data.mac_addr); + + pthread_mutex_lock(&g_client_info.mutex); + res = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Failed to write into socket [%s]", __wfd_print_error(res)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD("Succeeded to send request [%d: %s]", req.cmd, __wfd_client_print_cmd(req.cmd)); + + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + if (res <= 0) { + WDC_LOGE("Failed to read socket [%d]", res); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.cmd != req.cmd) { + WDC_LOGE("Invalid resp [%d]", rsp.cmd); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Result received [%s]", __wfd_print_error(rsp.result)); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + + wfd_discovery_entry_s *buff = NULL; + + buff = (wfd_discovery_entry_s*) g_try_malloc0(sizeof (wfd_discovery_entry_s)); + if (!buff) { + WDC_LOGE("Failed to alloc memory"); + pthread_mutex_unlock(&g_client_info.mutex); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + + res = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) buff, + sizeof(wfd_discovery_entry_s)); + pthread_mutex_unlock(&g_client_info.mutex); + if (res <= 0) { + free(buff); + WDC_LOGE("Failed to read socket"); + __wfd_reset_control(); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + __wfd_client_print_entry_list(buff, 1); + WDC_LOGD("wifi_direct_get_peer() SUCCESS"); + + wifi_direct_discovered_peer_info_s *peer = NULL; + + peer = (wifi_direct_discovered_peer_info_s *) g_try_malloc0(sizeof(wifi_direct_discovered_peer_info_s)); + if (!peer) { + WDC_LOGE("Failed to alloc memory"); + pthread_mutex_unlock(&g_client_info.mutex); + g_free(buff); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + peer->device_name = g_strdup(buff->device_name); + peer->mac_address = (char*) g_try_malloc0(MACSTR_LEN); + g_snprintf(peer->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff->mac_address)); + peer->interface_address = (char*) g_try_malloc0(MACSTR_LEN); + g_snprintf(peer->interface_address, MACSTR_LEN, MACSTR, MAC2STR(buff->intf_address)); + peer->channel = buff->channel; + peer->is_connected = buff->is_connected; + peer->is_group_owner = buff->is_group_owner; + peer->is_persistent_group_owner = buff->is_persistent_go; + peer->primary_device_type = buff->category; + peer->secondary_device_type = buff->subcategory; + peer->supported_wps_types= buff->wps_cfg_methods; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + peer->is_miracast_device = buff->is_wfd_device; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ + + g_free(buff); + *peer_info = peer; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_passphrase(const char *passphrase) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int status = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!passphrase) { + WDC_LOGE("NULL Param [passphrase]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + WDC_LOGD("passphrase = [%s]", passphrase); + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_PASSPHRASE; + req.client_id = g_client_info.client_id; + req.cmd_data_len = 64; + + pthread_mutex_lock(&g_client_info.mutex); + status = __wfd_client_write_socket(g_client_info.sync_sockfd, &req, + sizeof(wifi_direct_client_request_s)); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + WDC_LOGD( "writing msg hdr is success!\n"); + + status = __wfd_client_write_socket(g_client_info.sync_sockfd, (void*) passphrase, + req.cmd_data_len); + if (status != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! writing to socket[%s]", __wfd_print_error(status)); + __wfd_reset_control(); + pthread_mutex_unlock(&g_client_info.mutex); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } + + status = __wfd_client_read_socket(g_client_info.sync_sockfd, (char*) &rsp, + sizeof(wifi_direct_client_response_s)); + pthread_mutex_unlock(&g_client_info.mutex); + + if (status <= 0) { + WDC_LOGE("Error!!! reading socket, status = %d", status); + __wfd_reset_control(); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_COMMUNICATION_FAILED; + } else { + if (rsp.cmd == WIFI_DIRECT_CMD_SET_PASSPHRASE) { + if (rsp.result != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! Result received = %d", rsp.result); + WDC_LOGE("Error!!! [%s]", __wfd_print_error(rsp.result)); + __WDC_LOG_FUNC_END__; + return rsp.result; + } + } else { + WDC_LOGE("Error!!! Invalid resp cmd = %d", rsp.cmd); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_get_passphrase(char** passphrase) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + char la_passphrase[WIFI_DIRECT_WPA_LEN+1] = {0,}; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if(!passphrase){ + WDC_LOGE("NULL Param [passphrase]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PASSPHRASE; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! Invalid resp = %d", res); + __WDC_LOG_FUNC_END__; + return res; + } + + WDC_LOGD("wifi_direct_get_wpa_passphrase() SUCCESS"); + g_strlcpy(la_passphrase, rsp.param2, WIFI_DIRECT_WPA_LEN + 1); + *passphrase = g_strdup(la_passphrase); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_set_autoconnection_peer(char *mac_address) +{ + __WDC_LOG_FUNC_START__; + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address) { + WDC_LOGE("mac_addr is NULL"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_AUTOCONNECTION_PEER; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, MACADDR_LEN); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_set_autoconnection_peer() SUCCESS"); + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} + +int wifi_direct_init_display(void) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_INIT_DISPLAY; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_deinit_display(void) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + wifi_direct_client_info_s *client_info = __wfd_get_control(); + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((client_info->is_registered == false) || + (client_info->client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_DEINIT_DISPLAY; + req.client_id = g_client_info.client_id; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! Invalid resp = %d", res); + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_set_display(wifi_direct_display_type_e type, int port, int hdcp) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + wifi_direct_client_info_s *client_info = __wfd_get_control(); + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((client_info->is_registered == false) || + (client_info->client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (type < WIFI_DIRECT_DISPLAY_TYPE_SOURCE || type > WIFI_DIRECT_DISPLAY_TYPE_DUAL || port < 0 || hdcp < 0) { + WDC_LOGE("Invalid paramaeters passed type[%d], port[%d], hdcp[%d]!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_DISPLAY; + req.client_id = g_client_info.client_id; + req.data.int1 = type; + req.data.int2 = port; + req.data.int3 = hdcp; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! Invalid resp = %d", res); + __WDC_LOG_FUNC_END__; + return res; + } + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_set_display_availability(bool availability) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered."); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (availability < 0) { + WDC_LOGE("Invalid parameter"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_SET_DISPLAY_AVAILABILITY; + req.client_id = g_client_info.client_id; + req.data.int1 = availability; + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + WDC_LOGE("Error!!! Invalid resp = %d", res); + __WDC_LOG_FUNC_END__; + return res; + } + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_get_peer_display_type(char *mac_address, wifi_direct_display_type_e *type) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address || !type) { + WDC_LOGE("NULL Param!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_TYPE; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, 6); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_peer_display_type() SUCCESS"); + *type = rsp.param1; + + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_get_peer_display_availability(char *mac_address, bool *availability) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address || !availability) { + WDC_LOGE("NULL Param!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_AVAILABILITY; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, 6); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_peer_display_availability() SUCCESS"); + *availability = rsp.param1; + + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_get_peer_display_hdcp(char *mac_address, int *hdcp) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address || !hdcp) { + WDC_LOGE("NULL Param!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_HDCP; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, 6); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_peer_display_hdcp() SUCCESS"); + *hdcp = rsp.param1; + + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_get_peer_display_port(char *mac_address, int *port) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address || !port) { + WDC_LOGE("NULL Param!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_PORT; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, 6); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_peer_display_port() SUCCESS"); + *port = rsp.param1; + + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} + +int wifi_direct_get_peer_display_throughput(char *mac_address, int *throughput) +{ + __WDC_LOG_FUNC_START__; +#ifdef TIZEN_FEATURE_WIFI_DISPLAY + + CHECK_FEATURE_SUPPORTED(WIFIDIRECT_DISPLAY_FEATURE); + + unsigned char la_mac_addr[6]; + wifi_direct_client_request_s req; + wifi_direct_client_response_s rsp; + int res = WIFI_DIRECT_ERROR_NONE; + + if ((g_client_info.is_registered == false) || + (g_client_info.client_id == WFD_INVALID_ID)) { + WDC_LOGE("Client is NOT registered"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_INITIALIZED; + } + + if (!mac_address || !throughput) { + WDC_LOGE("NULL Param!"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + memset(&req, 0, sizeof(wifi_direct_client_request_s)); + memset(&rsp, 0, sizeof(wifi_direct_client_response_s)); + + req.cmd = WIFI_DIRECT_CMD_GET_PEER_DISPLAY_THROUGHPUT; + req.client_id = g_client_info.client_id; + macaddr_atoe(mac_address, la_mac_addr); + memcpy(req.data.mac_addr, la_mac_addr, 6); + + res = __wfd_client_send_request(g_client_info.sync_sockfd, &req, &rsp); + if (res != WIFI_DIRECT_ERROR_NONE) { + __WDC_LOG_FUNC_END__; + return res; + } + WDC_LOGD("wifi_direct_get_peer_display_throughput() SUCCESS"); + *throughput = rsp.param1; + + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +#else /* TIZEN_FEATURE_WIFI_DISPLAY */ + return WIFI_DIRECT_ERROR_NOT_SUPPORTED; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ +} diff --git a/test-wifi-direct.manifest b/test-wifi-direct.manifest new file mode 100755 index 0000000..ea84976 --- /dev/null +++ b/test-wifi-direct.manifest @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100755 index 0000000..a4c2019 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,48 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(TEST_APP_NAME "test-wifi-direct") + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +IF(NOT DEFINED BINDIR) + SET(BINDIR "${PREFIX}/bin") +ENDIF(NOT DEFINED BINDIR) + +INCLUDE(FindPkgConfig) +pkg_check_modules(TEST_APP_REQ_PKGS REQUIRED glib-2.0) + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +IF(TIZEN_FEATURE_SERVICE_DISCOVERY) + ADD_DEFINITIONS(-DTIZEN_FEATURE_SERVICE_DISCOVERY) + SET(FEATURES "${FEATURES} -DTIZEN_FEATURE_SERVICE_DISCOVERY") +ENDIF(TIZEN_FEATURE_SERVICE_DISCOVERY) +IF(TIZEN_FEATURE_WIFI_DISPLAY) + ADD_DEFINITIONS(-DTIZEN_FEATURE_WIFI_DISPLAY) + SET(FEATURES "${FEATURES} -DTIZEN_FEATURE_WIFI_DISPLAY") +ENDIF(TIZEN_FEATURE_WIFI_DISPLAY) +IF(TIZEN_TV) + ADD_DEFINITIONS(" -DTIZEN_TV") + MESSAGE("add -DTIZEN_TV") +ENDIF(TIZEN_TV) + +FOREACH (flag ${TEST_APP_REQ_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${CFLAGS}") + +ADD_EXECUTABLE(${TEST_APP_NAME} + ${CMAKE_CURRENT_SOURCE_DIR}/test-wifi-direct.c +) + +TARGET_LINK_LIBRARIES(${TEST_APP_NAME} + ${TEST_APP_REQ_PKGS_LDFLAGS} "wifi-direct") + +#Install +INSTALL(TARGETS ${TEST_APP_NAME} DESTINATION ${BINDIR}) + diff --git a/test/test-wifi-direct.c b/test/test-wifi-direct.c new file mode 100644 index 0000000..c428c65 --- /dev/null +++ b/test/test-wifi-direct.c @@ -0,0 +1,2754 @@ +#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_PEER_NUM 10 + +static const char *test_wfd_convert_error_to_string(wifi_direct_error_e err_type) +{ + switch (err_type) { + case WIFI_DIRECT_ERROR_NONE: + return "NONE"; + case WIFI_DIRECT_ERROR_NOT_PERMITTED: + return "NOT_PERMITTED"; + case WIFI_DIRECT_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case WIFI_DIRECT_ERROR_RESOURCE_BUSY: + return "RESOURCE_BUSY"; + case WIFI_DIRECT_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT: + return "CONNECTION_TIME_OUT"; + case WIFI_DIRECT_ERROR_NOT_INITIALIZED: + return "NOT_INITIALIZED"; + case WIFI_DIRECT_ERROR_COMMUNICATION_FAILED: + return "COMMUNICATION_FAILED"; + case WIFI_DIRECT_ERROR_WIFI_USED: + return "WIFI_USED"; + case WIFI_DIRECT_ERROR_MOBILE_AP_USED: + return "MOBILE_AP_USED"; + case WIFI_DIRECT_ERROR_CONNECTION_FAILED: + return "CONNECTION_FAILED"; + case WIFI_DIRECT_ERROR_AUTH_FAILED: + return "AUTH_FAILED"; + case WIFI_DIRECT_ERROR_OPERATION_FAILED: + return "OPERATION_FAILED"; + case WIFI_DIRECT_ERROR_TOO_MANY_CLIENT: + return "TOO_MANY_CLIENT"; + case WIFI_DIRECT_ERROR_ALREADY_INITIALIZED: + return "ALREADY_INITIALIZED"; + case WIFI_DIRECT_ERROR_CONNECTION_CANCELED: + return "CONNECTION_CANCELED"; + default: + return "UNKNOWN"; + } + return "UNKNOWN"; +} + +enum +{ + CMD_QUIT, + CMD_FULL_MENU, + CMD_INITIALIZE, + CMD_ACTIVATE_WIFI_DIRECT, + CMD_DEACTIVATE_WIFI_DIRECT, + CMD_START_DISCOVER, + CMD_START_DISCOVER_WITH_LISTEN_ONLY, + CMD_START_DISCOVER_SPECIFIC_CHANNEL, + CMD_CANCEL_DISCOVER, + CMD_GET_DISVOCERY_RESULT, + //CMD_SEND_PROVISION_DISCOVER_REQ, + CMD_SEND_CONNECTION_REQ, + CMD_GET_LINK_STATUS, + CMD_CONNECT_PEER, + CMD_DISCONNECT_ALL, + CMD_DISCONNECT, + + CMD_ENABLE_PUSH_BUTTON, + CMD_CREATE_GROUP, + CMD_CANCEL_GROUP, + CMD_IS_GROUP_OWNER, + CMD_REJECT, + CMD_INVITE, + CMD_SET_DEVICE_NAME, + CMD_GET_DEVICE_NAME, + CMD_SET_SSID, + CMD_GET_SSID, + CMD_SET_WPA, + CMD_SET_CHANNEL, + CMD_SET_WPS_CONFIG, + CMD_SET_MAX_CLIENT, + CMD_GET_MAX_CLIENT, + CMD_SET_HIDE_SSID, + CMD_ACTIVATE_PERSISTENT_GROUP, + CMD_DEACTIVATE_PERSISTENT_GROUP, + CMD_IS_PERSISTENT_GROUP_ACTIVATED, + CMD_GET_PERSISTENT_GROUP_LIST, + CMD_REMOVE_PERSISTENT_GROUP, + //CMD_SET_GROUP_OWNER, + CMD_SET_AUTO_CONNECTION, + CMD_IS_AUTO_CONNECTION, + //CMD_SET_LISTEN_ONLY, + CMD_SET_WPS_PIN, + CMD_GET_WPS_PIN, + CMD_GET_SUPPORTED_WPS_MODE, + CMD_SET_CURRENT_WPS_MODE, + CMD_GET_CURRENT_WPS_MODE, + CMD_GET_CONNECTED_PEERS_INFO, + CMD_GET_GO_INTENT, + CMD_SET_GO_INTENT, + CMD_GET_DEVICE_MAC, + CMD_IS_AUTONOMOUS_GROUP, + CMD_SET_ACTIVATION_CB, + CMD_SET_DISCOVER_CB, + CMD_SET_SERVICE_CB, + CMD_SET_CONNECTION_CB, + CMD_SET_PEER_FOUND_CB, + CMD_SET_DEVICE_NAME_CB, + CMD_UNSET_ACTIVATION_CB, + CMD_UNSET_DISCOVER_CB, + CMD_UNSET_SERVICE_CB, + CMD_UNSET_CONNECTION_CB, + CMD_UNSET_PEER_FOUND_CB, + CMD_UNSET_DEVICE_NAME_CB, + CMD_GET_NETWORK_IF_NAME, + CMD_GET_SUBNET_MASK, + CMD_GET_GATEWAY_ADDR, + CMD_IS_DISCOVERABLE, + CMD_IS_LISTEN_ONLY, + CMD_GET_PRIMARY_DEVICE_TYPE, + CMD_GET_SECONDARY_DEVICE_TYPE, + CMD_GET_OPERATING_CHANNEL, + CMD_GET_IP_ADDR, + CMD_REGISTER_SERVICE, + CMD_DEREGISTER_SERVICE, + CMD_START_SERVICE_DISCOVERY, + CMD_CANCEL_SERVICE_DISCOVERY, + + CMD_INCREASE_OEM_LOGLEVEL, + CMD_DECREASE_OEM_LOGLEVEL, + CMD_DEINITIALIZE, + CMD_INIT_MIRACAST, + CMD_GET_PEER_INFO, + CMD_SET_PASSPHRASE, + CMD_GET_PASSPHRASE, + CMD_SET_AUTOCONNECTION_PEER, + + CMD_INIT_DISPLAY, + CMD_DEINIT_DISPLAY, + CMD_SET_DISPLAY, + CMD_SET_DISPLAY_AVAILABILITY, + CMD_GET_PEER_DISPLAY_TYPE, + CMD_GET_PEER_DISPLAY_AVAILABILITY, + CMD_GET_PEER_DISPLAY_HDCP, + CMD_GET_PEER_DISPLAY_PORT, + CMD_GET_PEER_DISPLAY_THROUGHPUT, + + CMD_INVALID = 255, +}; + +typedef struct +{ + int cmd; + char* menu_str; +} menu_str_t; + +menu_str_t g_menu_str[] = +{ + { CMD_QUIT, "CMD_QUIT" }, + { CMD_FULL_MENU, "CMD_FULL_MENU" }, + { CMD_INITIALIZE, "CMD_INITIALIZE" }, + { CMD_ACTIVATE_WIFI_DIRECT, "CMD_ACTIVATE_WIFI_DIRECT" }, + { CMD_DEACTIVATE_WIFI_DIRECT, "CMD_DEACTIVATE_WIFI_DIRECT" }, + { CMD_START_DISCOVER, "CMD_START_DISCOVER" }, + { CMD_START_DISCOVER_WITH_LISTEN_ONLY, "CMD_START_DISCOVER_WITH_LISTEN_ONLY" }, + { CMD_START_DISCOVER_SPECIFIC_CHANNEL, "CMD_START_DISCOVER_SPECIFIC_CHANNEL" }, + { CMD_CANCEL_DISCOVER, "CMD_CANCEL_DISCOVER" }, + { CMD_GET_DISVOCERY_RESULT, "CMD_GET_DISVOCERY_RESULT" }, + //{ CMD_SEND_PROVISION_DISCOVER_REQ, "CMD_SEND_PROVISION_DISCOVER_REQ" }, + { CMD_SEND_CONNECTION_REQ, "CMD_SEND_CONNECTION_REQ" }, + + { CMD_GET_LINK_STATUS, "CMD_GET_LINK_STATUS" }, + { CMD_CONNECT_PEER, "CMD_CONNECT_PEER" }, + { CMD_DISCONNECT_ALL, "CMD_DISCONNECT_ALL" }, + { CMD_DISCONNECT, "CMD_DISCONNECT" }, + + { CMD_ENABLE_PUSH_BUTTON, "CMD_ENABLE_PUSH_BUTTON" }, + + { CMD_CREATE_GROUP, "CMD_CREATE_GROUP" }, + { CMD_CANCEL_GROUP, "CMD_CANCEL_GROUP" }, + { CMD_IS_GROUP_OWNER, "CMD_IS_GROUP_OWNER" }, + { CMD_REJECT, "CMD_REJECT" }, + { CMD_INVITE, "CMD_INVITE" }, + { CMD_SET_DEVICE_NAME, "CMD_SET_DEVICE_NAME" }, + { CMD_GET_DEVICE_NAME, "CMD_GET_DEVICE_NAME" }, + { CMD_SET_SSID, "CMD_SET_SSID" }, + { CMD_GET_SSID, "CMD_GET_SSID" }, + { CMD_SET_WPA, "CMD_SET_WPA" }, + { CMD_SET_CHANNEL, "CMD_SET_CHANNEL" }, + { CMD_SET_WPS_CONFIG, "CMD_SET_WPS_CONFIG" }, + { CMD_SET_MAX_CLIENT, "CMD_SET_MAX_CLIENT" }, + { CMD_GET_MAX_CLIENT, "CMD_GET_MAX_CLIENT" }, + { CMD_SET_HIDE_SSID, "CMD_SET_HIDE_SSID" }, + { CMD_ACTIVATE_PERSISTENT_GROUP, "CMD_ACTIVATE_PERSISTENT_GROUP" }, + { CMD_DEACTIVATE_PERSISTENT_GROUP, "CMD_DEACTIVATE_PERSISTENT_GROUP" }, + { CMD_IS_PERSISTENT_GROUP_ACTIVATED, "CMD_IS_PERSISTENT_GROUP_ACTIVATED" }, + { CMD_GET_PERSISTENT_GROUP_LIST, "CMD_GET_PERSISTENT_GROUP_LIST" }, + { CMD_REMOVE_PERSISTENT_GROUP, "CMD_REMOVE_PERSISTENT_GROUP" }, + //{ CMD_SET_GROUP_OWNER, "CMD_SET_GROUP_OWNER" }, + { CMD_SET_AUTO_CONNECTION, "CMD_SET_AUTO_CONNECTION" }, + { CMD_IS_AUTO_CONNECTION, "CMD_IS_AUTO_CONNECTION" }, + //{ CMD_SET_LISTEN_ONLY, "CMD_SET_LISTEN_ONLY" }, + { CMD_SET_WPS_PIN, "CMD_SET_WPS_PIN" }, + { CMD_GET_WPS_PIN, "CMD_GET_WPS_PIN" }, + { CMD_GET_SUPPORTED_WPS_MODE, "CMD_GET_SUPPORTED_WPS_MODE" }, + { CMD_SET_CURRENT_WPS_MODE, "CMD_SET_CURRENT_WPS_MODE" }, + { CMD_GET_CURRENT_WPS_MODE, "CMD_GET_CURRENT_WPS_MODE" }, + { CMD_GET_CONNECTED_PEERS_INFO, "CMD_GET_CONNECTED_PEERS_INFO" }, + { CMD_GET_GO_INTENT, "CMD_GET_GO_INTENT" }, + { CMD_SET_GO_INTENT, "CMD_SET_GO_INTENT" }, + { CMD_GET_DEVICE_MAC, "CMD_GET_DEVICE_MAC" }, + { CMD_IS_AUTONOMOUS_GROUP, "CMD_IS_AUTONOMOUS_GROUP" }, + { CMD_SET_ACTIVATION_CB, "CMD_SET_ACTIVATION_CB" }, + { CMD_SET_DISCOVER_CB, "CMD_SET_DISCOVER_CB" }, + { CMD_SET_CONNECTION_CB, "CMD_SET_CONNECTION_CB" }, + { CMD_SET_PEER_FOUND_CB, "CMD_SET_PEER_FOUND_CB" }, + { CMD_SET_DEVICE_NAME_CB, "CMD_SET_DEVICE_NAME_CB"}, + { CMD_UNSET_ACTIVATION_CB, "CMD_UNSET_ACTIVATION_CB" }, + { CMD_UNSET_DISCOVER_CB, "CMD_UNSET_DISCOVER_CB" }, + { CMD_UNSET_CONNECTION_CB, "CMD_UNSET_CONNECTION_CB" }, + { CMD_UNSET_PEER_FOUND_CB, "CMD_UNSET_PEER_FOUND_CB" }, + { CMD_GET_NETWORK_IF_NAME, "CMD_GET_NETWORK_IF_NAME" }, + { CMD_GET_SUBNET_MASK, "CMD_GET_SUBNET_MASK" }, + { CMD_GET_GATEWAY_ADDR, "CMD_GET_GATEWAY_ADDR" }, + { CMD_IS_DISCOVERABLE, "CMD_IS_DISCOVERABLE" }, + { CMD_IS_LISTEN_ONLY, "CMD_IS_LISTEN_ONLY" }, + { CMD_GET_PRIMARY_DEVICE_TYPE, "CMD_GET_PRIMARY_DEVICE_TYPE" }, + { CMD_GET_SECONDARY_DEVICE_TYPE, "CMD_GET_SECONDARY_DEVICE_TYPE" }, + { CMD_GET_OPERATING_CHANNEL, "CMD_GET_OPERATING_CHANNEL" }, + { CMD_GET_IP_ADDR, "CMD_GET_IP_ADDR" }, + { CMD_REGISTER_SERVICE, "CMD_REGISTER_SERVICE" }, + { CMD_DEREGISTER_SERVICE, "CMD_DEREGISTER_SERVICE" }, + { CMD_START_SERVICE_DISCOVERY,"CMD_START_SERVICE_DISCOVERY" }, + { CMD_CANCEL_SERVICE_DISCOVERY,"CMD_CANCEL_SERVICE_DISCOVERY" }, + + { CMD_INCREASE_OEM_LOGLEVEL, "CMD_INCREASE_OEM_LOGLEVEL" }, + { CMD_DECREASE_OEM_LOGLEVEL, "CMD_DECREASE_OEM_LOGLEVEL" }, + + { CMD_DEINITIALIZE, "CMD_DEINITIALIZE" }, + { CMD_INIT_MIRACAST, "CMD_INIT_MIRACAST" }, + { CMD_GET_PEER_INFO, "CMD_GET_PEER_INFO" }, + {CMD_SET_PASSPHRASE, "CMD_SET_PASSPHRASE" }, + {CMD_GET_PASSPHRASE, "CMD_GET_PASSPHRASE" }, + {CMD_SET_AUTOCONNECTION_PEER, "CMD_SET_AUTOCONNECTION_PEER" }, + + {CMD_INIT_DISPLAY, "CMD_INIT_DISPLAY" }, + {CMD_DEINIT_DISPLAY, "CMD_DEINIT_DISPLAY" }, + {CMD_SET_DISPLAY, "CMD_SET_DISPLAY" }, + {CMD_SET_DISPLAY_AVAILABILITY, "CMD_SET_DISPLAY_AVAILABILITY" }, + {CMD_GET_PEER_DISPLAY_TYPE, "CMD_GET_PEER_DISPLAY_TYPE" }, + {CMD_GET_PEER_DISPLAY_AVAILABILITY, "CMD_GET_PEER_DISPLAY_AVAILABILITY" }, + {CMD_GET_PEER_DISPLAY_HDCP, "CMD_GET_PEER_DISPLAY_HDCP" }, + {CMD_GET_PEER_DISPLAY_PORT, "CMD_GET_PEER_DISPLAY_PORT" }, + {CMD_GET_PEER_DISPLAY_THROUGHPUT, "CMD_GET_PEER_DISPLAY_THROUGHPUT" }, + + { -1, NULL }, }; + +struct appdata +{ + GMainLoop* main_loop; + + wifi_direct_discovered_peer_info_s peer_list[MAX_PEER_NUM]; + int peer_count; + int selected_peer_index; + + wifi_direct_connected_peer_info_s connected_peer_list[MAX_PEER_NUM]; + int connected_peer_count; +}; + +struct appdata* g_test_appdata; + +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%4 == 0) + printf("\n"); + printf(" %02d: %-32s ", g_menu_str[i].cmd, + cmd_transform(g_menu_str[i].menu_str)); + + } + 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; +} + +char* print_link_state(wifi_direct_state_e state) +{ + if (state == WIFI_DIRECT_STATE_DEACTIVATED) + return "DEACTIVATED"; + if (state == WIFI_DIRECT_STATE_ACTIVATING) + return "ACTIVATING"; + if (state == WIFI_DIRECT_STATE_ACTIVATED) + return "ACTIVATED"; + if (state == WIFI_DIRECT_STATE_DISCOVERING) + return "DISCOVERING"; + if (state == WIFI_DIRECT_STATE_CONNECTING) + return "CONNECTING"; + if (state == WIFI_DIRECT_STATE_DISCONNECTING) + return "DISCONNECTING"; + if (state == WIFI_DIRECT_STATE_CONNECTED) + return "CONNECTED"; + if (state == WIFI_DIRECT_STATE_GROUP_OWNER) + return "GROUP OWNER"; + + return "Unknown state"; +} + +int select_peer(struct appdata* ad) +{ + wifi_direct_discovered_peer_info_s* list; + int target = -1; + int i; + + if (ad==NULL) + return 0; + + list = ad->peer_list; + + for(i=0; ipeer_count; i++) + { + printf ("index [%d] MAC [%s] Owner=[%s] SSID[%s]\n", + i, + list[i].mac_address, + list[i].is_group_owner ? "YES" : "NO", + list[i].device_name); + } + + printf("input peer index:\n"); + scanf("%d", &target); + + if (target < 0 || target > ad->peer_count) + { + printf("Wrong contact index [%d]\n", target); + return -1; + } + else + { + ad->selected_peer_index = target; + } + + return 1; +} + + +void print_peers_connected(struct appdata* ad) +{ + wifi_direct_connected_peer_info_s* list; + int target = -1; + int i, j; + + if (ad==NULL) + return; + + list = ad->connected_peer_list; + + for(i=0; iconnected_peer_count; i++) + { + if (list[i].service_count == 0) { + printf ("index [%d] MAC [%s] SSID[%s] \n", i, list[i].mac_address, list[i].device_name); + } else { + char services[256] = {0,}; + unsigned int len = 0; + printf ("Service Count = [%d][%p]\n" ,list[i].service_count,list[i].service_list); + for (j=0; jpeer_list; + + for(i=0; ipeer_count; i++) + { + if (list[i].service_count == 0) { + printf ("index [%d] MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d] \n", + i, + list[i].mac_address, + list[i].is_group_owner ? "YES" : "NO", + list[i].is_connected, + list[i].device_name, + list[i].primary_device_type, + list[i].secondary_device_type + ); + } else { + char services[256] = {0,}; + unsigned int len = 0; + printf ("Service Count = [%d][%p]\n" ,list[i].service_count,list[i].service_list); + for (j=0; j%s\n", s); +} + +void _cb_activation(int error_code, wifi_direct_device_state_e device_state, void *user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + int ret; + + switch (device_state) + { + + case WIFI_DIRECT_DEVICE_STATE_ACTIVATED: + event_printf("event -WIFI_DIRECT_DEVICE_STATE_ACTIVATED\n"); + break; + + case WIFI_DIRECT_DEVICE_STATE_DEACTIVATED: + event_printf("event - WIFI_DIRECT_DEVICE_STATE_DEACTIVATED\n"); + break; + + default: + break; + } +} + + +bool _cb_discovered_peers_impl(wifi_direct_discovered_peer_info_s* peer, void* user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + + if(NULL != peer) + { + if ( ad->peer_count >= MAX_PEER_NUM ) + return false; // break out of the loop + + memcpy(&ad->peer_list[ad->peer_count], peer, sizeof(wifi_direct_discovered_peer_info_s)); + ad->peer_count++; + + } + + return true; // continue with the next iteration of the loop +} + +bool _cb_connected_peers_impl(wifi_direct_connected_peer_info_s* peer, void* user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + + if(NULL != peer) + { + if ( ad->connected_peer_count >= MAX_PEER_NUM ) + return false; // break out of the loop + + memcpy(&ad->connected_peer_list[ad->connected_peer_count], peer, sizeof(wifi_direct_connected_peer_info_s)); + ad->connected_peer_count++; + + } + + return true; // continue with the next iteration of the loop +} + +bool _cb_persistent_groups_impl(const char* mac_address, const char* ssid, void* user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + + if(NULL != mac_address) + printf("mac_address=[%s]\n", mac_address); + + if(NULL != ssid) + printf("ssid=[%s]\n", ssid); + + return true; // continue with the next iteration of the loop +} + +void _cb_discover(int error_code, wifi_direct_discovery_state_e discovery_state, void *user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + int ret; + + switch (discovery_state) + { + + case WIFI_DIRECT_DISCOVERY_STARTED: + event_printf("event - WIFI_DIRECT_DISCOVERY_STARTED\n"); + break; + + case WIFI_DIRECT_ONLY_LISTEN_STARTED: + event_printf("event - WIFI_DIRECT_ONLY_LISTEN_STARTED\n"); + break; + + case WIFI_DIRECT_DISCOVERY_FINISHED: + event_printf("event - WIFI_DIRECT_DISCOVERY_FINISHED\n"); + break; + + case WIFI_DIRECT_DISCOVERY_FOUND: + { + event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n"); + + memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM); + ad->peer_count = 0; + ad ->selected_peer_index = 0; + + ret = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad); + printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", ret); + } + break; + + default: + break; + } + // _activate_push_cb((void*)NULL, (Evas_Object*)NULL, (void*)NULL); + +} + +void _cb_peer_found(int error_code, wifi_direct_discovery_state_e discovery_state, const char * mac_address,void *user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + int ret; + + switch (discovery_state) + { + case WIFI_DIRECT_DISCOVERY_FOUND: + { + event_printf("event - WIFI_DIRECT_DISCOVERY_FOUND\n"); + + if(mac_address[0] != '/0') { + printf("Peer Address is %s", mac_address); + wifi_direct_discovered_peer_info_s* peer_info = NULL; + + wifi_direct_get_peer_info(mac_address, &peer_info); + if(peer_info !=NULL) { + printf ("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]", + peer_info->mac_address, + peer_info->is_group_owner ? "YES" : "NO", + peer_info->is_connected, + peer_info->device_name, + peer_info->primary_device_type, + peer_info->secondary_device_type + ); + if(peer_info->mac_address) + free(peer_info->mac_address); + if(peer_info->interface_address) + free(peer_info->interface_address); + if(peer_info) + free(peer_info); + } + } + } + break; + + default: + break; + } +} + +void _cb_service(int error_code, + wifi_direct_service_discovery_state_e discovery_state, + wifi_direct_service_type_e service_type, + void *response_data, const char * mac_address, void *user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + int ret; + + switch (discovery_state) + { + + case WIFI_DIRECT_SERVICE_DISCOVERY_STARTED: + event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_STARTED\n"); + break; + + case WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED: + event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED\n"); + break; + + case WIFI_DIRECT_SERVICE_DISCOVERY_FOUND: + { + event_printf("event - WIFI_DIRECT_SERVICE_DISCOVERY_FOUND\n"); + if (mac_address != NULL) + printf("Peer Wi-Fi Direct mac address %s\n", mac_address); + if (response_data != NULL) + printf("Peer service response %s\n", response_data); + if (service_type == WIFI_DIRECT_SERVICE_TYPE_ALL) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BONJOUR) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_UPNP) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_UPNP\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_BT_ADDR) + printf("Service type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n"); + else if (service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO) + printf("service_type == WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO"); + else + printf("Requested Service !!! NOT FOUND !!!\n"); + } + break; + + default: + break; + } + __FUNC_EXIT__; +} + +void _cb_connection(int error_code, wifi_direct_connection_state_e connection_state, const char* mac_address, void *user_data) +{ + __FUNC_ENTER__; + char status[100] = + { 0, }; + char *ip_addr = NULL; + bool owner; + + switch (connection_state) + { + + case WIFI_DIRECT_CONNECTION_IN_PROGRESS: + { + event_printf("event - WIFI_DIRECT_CONNECTION_IN_PROGRESS\n"); + + if ( error_code == WIFI_DIRECT_ERROR_NONE ) + { + unsigned char _peer_mac[18]={0,}; + + if(NULL != mac_address) + strncpy(_peer_mac, mac_address, strlen(mac_address)); + + + printf ("Connection start with [%s] \n", _peer_mac); + + event_printf("Error None\n"); + + } + else + { + } + + } + break; + + case WIFI_DIRECT_CONNECTION_RSP: + { + event_printf("event - WIFI_DIRECT_CONNECTION_RSP\n"); + + if ( error_code == WIFI_DIRECT_ERROR_NONE ) + { + char incomming_peer_mac[18]={0,}; + + if(NULL != mac_address) + strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); + + + printf ("Connection response with [%s] \n", incomming_peer_mac); + + event_printf("Error None\n"); + + wifi_direct_is_group_owner(&owner); + if (owner) + { + wifi_direct_get_ip_address(&ip_addr); + if(NULL!=ip_addr) + { + sprintf(status, "GO - IP : %s", ip_addr); + free(ip_addr); + } + + } + else + { + wifi_direct_get_ip_address(&ip_addr); + if(NULL!=ip_addr) + { + sprintf(status, "STA - IP : %s", ip_addr); + free(ip_addr); + } + } + } + else + { + if ( error_code == WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT ) + event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT\n"); + else if ( error_code == WIFI_DIRECT_ERROR_AUTH_FAILED ) + event_printf("Error Code - WIFI_DIRECT_ERROR_AUTH_FAILED\n"); + else if ( error_code == WIFI_DIRECT_ERROR_CONNECTION_FAILED ) + event_printf("Error Code - WIFI_DIRECT_ERROR_CONNECTION_FAILED\n"); + } + + } + break; + + case WIFI_DIRECT_CONNECTION_WPS_REQ: + { + event_printf("event - WIFI_DIRECT_CONNECTION_WPS_REQ\n"); + + wifi_direct_wps_type_e wps_mode; + + int result; + + result = wifi_direct_get_local_wps_type(&wps_mode); + printf("wifi_direct_get__local_wps_type() result=[%d]\n", result); + + //BCMP2P_DISCOVER_ENTRY notification_data; + //memcpy(¬ification_data, pNotificationData, sizeof(notification_data)); + if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) + { + printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n"); + + } + else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY) + { + printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n"); + + int num; + char pin[9]= { 0, }; + int result; + + struct appdata *ad = (struct appdata *) user_data; + + if (NULL == ad) + printf("ERROR : ad is NULL!!!\n"); + + memset(pin, 0x00, sizeof(pin)); + printf("Input 8 digit PIN number :\n"); + scanf("%s", pin); + + if( strlen(pin) > 0 ) + result = wifi_direct_set_wps_pin(pin); + else + printf("Invalid PIN number\n"); + + if ( result == WIFI_DIRECT_ERROR_NONE ) + { + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_accept_connection(list[i].mac_address); + printf("wifi_direct_accept_connection() result=[%d]\n", result); + } + else + printf("wifi_direct_set_wps_pin Error [%d]\n", result); + + } + else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD ) + { + printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n"); + char *pin = NULL; + + result = wifi_direct_get_wps_pin(&pin); + printf("wifi_direct_get_wps_pin() result=[%d]\n", result); + if ( NULL != pin ) + { + printf("WPS_PIN [%s]\n", pin); + free(pin); + } + else + printf("WPS_PIN is NULL !! \n"); + } + else + { + printf("wps_config is unkown!\n"); + } + + } + break; + + case WIFI_DIRECT_CONNECTION_REQ: + { + event_printf("event - WIFI_DIRECT_CONNECTION_REQ\n"); + char incomming_peer_mac[18]; + wifi_direct_wps_type_e wps_mode; + bool auto_connection_mode; + int result; + + memset(incomming_peer_mac, 0, sizeof(incomming_peer_mac)); + + if(NULL != mac_address) + strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); + + printf ("Connection Request from [%s] \n", incomming_peer_mac); + + result = wifi_direct_get_local_wps_type(&wps_mode); + printf("wifi_direct_get_local_wps_type() result=[%d]\n", result); + + result = wifi_direct_is_autoconnection_mode(&auto_connection_mode); + printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result); + + if(auto_connection_mode == TRUE) + { + + result = wifi_direct_accept_connection(incomming_peer_mac); + printf("wifi_direct_accept_connection() result=[%d]\n", result); + } + else + { + + if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PBC) + { + char pushbutton; + printf("wps_config is WIFI_DIRECT_WPS_TYPE_PBC\n"); + printf("************\n"); + printf("Connect? (Y/N)\n"); + printf("*************\n"); + + scanf("%c", &pushbutton); + + if( (pushbutton == 'Y') || (pushbutton == 'y') ) + { + result = wifi_direct_accept_connection(incomming_peer_mac); + printf("wifi_direct_accept_connection() result=[%d]\n", result); + } + } + else if ( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD ) + { + printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n"); + + char pin[9]= { 0, }; + + memset(pin, 0x00, sizeof(pin)); + printf("*********************\n"); + printf("Input 8 digit PIN number :\n"); + printf("*********************\n"); + scanf("%s", pin); + + if( strlen(pin) > 0 ) + result = wifi_direct_set_wps_pin(pin); + else + printf("Invalid PIN number\n"); + + + if ( result == WIFI_DIRECT_ERROR_NONE ) + { + result = wifi_direct_accept_connection(incomming_peer_mac); + printf("wifi_direct_accept_connection() result=[%d]\n", result); + } + else + printf("wifi_direct_set_wps_pin Error [%d]\n", result); + + } + else + { + printf("wps_config is unkown!\n"); + } + } + + + + } + break; + + case WIFI_DIRECT_DISCONNECTION_IND: + { + event_printf("event - WIFI_DIRECT_DISCONNECTION_IND\n"); + + if ( error_code == WIFI_DIRECT_ERROR_NONE ) + { + char incomming_peer_mac[18]={0,}; + + if(NULL != mac_address) + strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); + + printf ("Disconnection IND from [%s] \n", incomming_peer_mac); + + event_printf("Error None\n"); + } + + } + break; + + case WIFI_DIRECT_DISCONNECTION_RSP: + { + event_printf("event - WIFI_DIRECT_DISCONNECTION_RSP\n"); + + if ( error_code == WIFI_DIRECT_ERROR_NONE ) + { + char incomming_peer_mac[18]={0,}; + + if(NULL != mac_address) + strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); + + printf ("Disconnection RSP with [%s] \n", incomming_peer_mac); + + event_printf("Error None\n"); + } + + } + break; + + case WIFI_DIRECT_DISASSOCIATION_IND: + { + + event_printf("event - WIFI_DIRECT_DISASSOCIATION_IND\n"); + + if ( error_code == WIFI_DIRECT_ERROR_NONE ) + { + char incomming_peer_mac[18]={0,}; + + if(NULL != mac_address) + strncpy(incomming_peer_mac, mac_address, strlen(mac_address)); + + printf ("Disassociation IND from [%s] \n", incomming_peer_mac); + + event_printf("Error None\n"); + } + } + break; + + case WIFI_DIRECT_GROUP_CREATED: + { + event_printf("event - WIFI_DIRECT_GROUP_CREATED\n"); + } + break; + + case WIFI_DIRECT_GROUP_DESTROYED: + { + event_printf("event - WIFI_DIRECT_GROUP_DESTROYED\n"); + } + break; + + default: + break; + + } + + __FUNC_EXIT__; +} + + +void _cb_ip_assigned(const char* mac_address, const char* ip_address, const char* interface_address, void *user_data) +{ + __FUNC_ENTER__; + + if(NULL != mac_address) + printf ("mac_address [%s] \n", mac_address); + else + printf ("mac_address is NULL !!\n"); + + if(NULL != ip_address) + printf ("ip_address [%s] \n", ip_address); + else + printf ("ip_address is NULL !!\n"); + + if(NULL != interface_address) + printf ("interface_address [%s] \n", interface_address); + else + printf ("interface_address is NULL !!\n"); + + __FUNC_EXIT__; + +} + +bool _cb_foreach_supported_wps_impl(wifi_direct_wps_type_e type, void* user_data) +{ + __FUNC_ENTER__; + + struct appdata* ad = (struct appdata*) user_data; + + switch (type) + { + case WIFI_DIRECT_WPS_TYPE_PBC: + printf("type=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY: + printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD: + printf("type=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); + break; + default: + printf("ERROR : type=[%d]\n", type); + break; + } + + return true; // continue with the next iteration of the loop +} + + +int _get_current_state(void) +{ + __FUNC_ENTER__; + wifi_direct_state_e status; + wifi_direct_get_state(&status); + __FUNC_EXIT__; + + return status; +} + +int init_wfd_client(struct appdata *ad) +{ + int ret; + + ret = wifi_direct_initialize(); + printf("wifi_direct_initialize() result=[%d]\n", ret); + + ret = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad); + printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", ret); + + ret = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad); + printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", ret); + + ret = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad); + printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", ret); + + ret = wifi_direct_set_client_ip_address_assigned_cb(_cb_ip_assigned, (void*)ad); + printf("wifi_direct_set_client_ip_address_assigned_cb() result=[%d]\n", ret); + + ret = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad); + printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", ret); + + ret = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad); + printf("wifi_direct_set_peer_found_cb() result=[%d]\n", ret); + + return ret; +} + +void process_input(const char *input, gpointer user_data) +{ + struct appdata *ad = (struct appdata *) user_data; + int result = -1; + + 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); + + switch (cmd) + { + case CMD_INITIALIZE: + { + result = init_wfd_client(ad); + printf("init_wfd_client() result=[%d]\n", result); + } + break; + + case CMD_SET_ACTIVATION_CB: + { + result = wifi_direct_set_device_state_changed_cb(_cb_activation, (void*)ad); + printf("wifi_direct_set_device_state_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_UNSET_ACTIVATION_CB: + { + result = wifi_direct_unset_device_state_changed_cb(); + printf("wifi_direct_unset_device_state_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_SET_DISCOVER_CB: + { + result = wifi_direct_set_discovery_state_changed_cb(_cb_discover, (void*)ad); + printf("wifi_direct_set_discovery_state_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_UNSET_DISCOVER_CB: + { + result = wifi_direct_unset_discovery_state_changed_cb(); + printf("wifi_direct_unset_discovery_state_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_SET_CONNECTION_CB: + { + result = wifi_direct_set_connection_state_changed_cb(_cb_connection, (void*)ad); + printf("wifi_direct_set_connection_state_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_UNSET_CONNECTION_CB: + { + result = wifi_direct_unset_connection_state_changed_cb(); + printf("wifi_direct_unset_connection_state_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_SET_SERVICE_CB: + { + result = wifi_direct_set_service_state_changed_cb(_cb_service, (void*)ad); + printf("wifi_direct_set_service_state_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_UNSET_SERVICE_CB: + { + result = wifi_direct_unset_service_state_changed_cb(); + printf("wifi_direct_unset_service_changed_cb() result=[%d]\n", result); + } + break; + + case CMD_SET_PEER_FOUND_CB: + { + result = wifi_direct_set_peer_found_cb(_cb_peer_found, (void*)ad); + printf("wifi_direct_set_peer_found_cb() result=[%d]\n", result); + } + break; + + case CMD_UNSET_PEER_FOUND_CB: + { + result = wifi_direct_unset_peer_found_cb(); + printf("wifi_direct_unset_peer_found_cb() result=[%d]\n", result); + } + break; + + case CMD_DEINITIALIZE: + result = wifi_direct_deinitialize(); + printf("wifi_direct_deinitialize() result=[%d]\n", result); + break; + case CMD_ACTIVATE_WIFI_DIRECT: + if (ad != NULL) + { + result = wifi_direct_activate(); + printf("wifi_direct_activate() result=[%d]\n", result); + + if ( result == WIFI_DIRECT_ERROR_WIFI_USED ) + printf(" ERROR : WIFI_DIRECT_ERROR_WIFI_USED \n"); + else if ( result == WIFI_DIRECT_ERROR_MOBILE_AP_USED ) + printf(" ERROR : WIFI_DIRECT_ERROR_MOBILE_AP_USED \n"); + + } + break; + + case CMD_DEACTIVATE_WIFI_DIRECT: + if (ad != NULL) + { + result = wifi_direct_deactivate(); + printf("wifi_direct_deactivate() result=[%d]\n", result); + } + break; + + case CMD_START_DISCOVER_WITH_LISTEN_ONLY: + if (ad != NULL) + { + result = wifi_direct_start_discovery(TRUE, 15); + printf("wifi_direct_start_discovery() listen_only=[true] result=[%d]\n", result); + } + break; + + case CMD_START_DISCOVER: + if (ad != NULL) + { + //result = wifi_direct_start_discovery(FALSE, 15); + result = wifi_direct_start_discovery(FALSE, 0); + printf("wifi_direct_start_discovery() listen_only=[false] result=[%d]\n", result); + } + break; + + case CMD_START_DISCOVER_SPECIFIC_CHANNEL: + if (ad != NULL) + { + int input; + printf("Select Discovery Channel :\n"); + printf("1. WIFI_DIRECT_DISCOVERY_FULL_SCAN\n"); + printf("2. WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL\n"); + printf("3. WIFI_DIRECT_DISCOVERY_CHANNEL1\n"); + printf("4. WIFI_DIRECT_DISCOVERY_CHANNEL6\n"); + printf("5. WIFI_DIRECT_DISCOVERY_CHANNEL11\n"); + scanf("%d", &input); + + switch(input) + { + case 1 : + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_FULL_SCAN); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_FULL_SCAN, result); + } + break; + case 2 : + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL, result); + } + break; + case 3 : + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL1); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL1, result); + } + break; + case 4 : + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL6); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL6, result); + } + break; + case 5 : + { + result = wifi_direct_start_discovery_specific_channel(FALSE, 2, WIFI_DIRECT_DISCOVERY_CHANNEL11); + printf("wifi_direct_start_discovery_specific_channel() channel=[%d] result=[%d]\n", WIFI_DIRECT_DISCOVERY_CHANNEL11, result); + } + break; + default : + printf("ERROR : Invalid Channel !!!\n"); + break; + } + + } + break; + + case CMD_CANCEL_DISCOVER: + if (ad != NULL) + { + result = wifi_direct_cancel_discovery(); + printf("wifi_direct_cancel_discovery() result=[%d]\n", result); + } + break; + case CMD_GET_DISVOCERY_RESULT: + if (ad != NULL) + { + memset(ad->peer_list, 0x00, sizeof(wifi_direct_discovered_peer_info_s)*MAX_PEER_NUM); + ad->peer_count = 0; + ad ->selected_peer_index = 0; + + result = wifi_direct_foreach_discovered_peers(_cb_discovered_peers_impl, (void*)ad); + printf("wifi_direct_foreach_discovered_peers() ret=[%d]\n", result); + + print_peers(ad); + } + break; + + case CMD_SEND_CONNECTION_REQ: + if (ad != NULL) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_accept_connection(list[i].mac_address); + + printf ("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n", + i, + list[i].mac_address, + list[i].is_group_owner ? "YES" : "NO", + list[i].device_name); + + printf("wifi_direct_accept_connection() result=[%d]\n", result); + } + } + break; + + case CMD_DISCONNECT_ALL: + if (ad != NULL) + { + result = wifi_direct_disconnect_all(); + printf("wifi_direct_disconnect_all() result=[%d]\n", result); + } + break; + + case CMD_DISCONNECT: + if (ad != NULL) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_disconnect(list[i].mac_address); + + printf ("Disconnecting... peer-index[%d] MAC [%s] SSID[%s]\n", + i, + list[i].mac_address, + list[i].device_name); + + printf("wifi_direct_disconnect() result=[%d]\n", result); + } + } + break; + + + case CMD_GET_LINK_STATUS: + if (ad != NULL) + { + wifi_direct_state_e status = 0; + result = wifi_direct_get_state(&status); + printf("wifi_direct_get_state() state=[%s(%d)], result=[%d]\n", print_link_state(status), status, result); + } + break; + + case CMD_CONNECT_PEER: + if (ad != NULL) + { + if (select_peer(ad)) + { + wifi_direct_wps_type_e wps_mode; + + result = wifi_direct_get_local_wps_type(&wps_mode); + printf("wifi_direct_get_local_wps_type() result=[%d]\n", result); + + if( wps_mode == WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD ) + { + printf("wifi_direct_generate_wps_pin() result=[%d]\n", result); + } + + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_connect(list[i].mac_address); + + printf ("Connecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n", + i, + list[i].mac_address, + list[i].is_group_owner ? "YES" : "NO", + list[i].device_name); + + printf("wifi_direct_connect() result=[%d]\n", result); + + } + } + break; + + case CMD_ENABLE_PUSH_BUTTON: + if (ad != NULL) + { + result = wifi_direct_activate_pushbutton(); + printf("wifi_direct_activate_pushbutton() result=[%d]\n", result); + } + break; + case CMD_CREATE_GROUP: + if (ad != NULL) + { + result = wifi_direct_create_group(); + printf("wifi_direct_create_group() result=[%d]\n", result); + } + break; + + case CMD_CANCEL_GROUP: + if (ad != NULL) + { + result = wifi_direct_destroy_group(); + printf("wifi_direct_destroy_group() result=[%d]\n", result); + } + break; + + case CMD_IS_GROUP_OWNER: + if (ad != NULL) + { + bool is_group_owner; + result = wifi_direct_is_group_owner(&is_group_owner); + printf("wifi_direct_is_group_owner() is GO[%d] result=[%d]\n", is_group_owner, result); + } + break; + case CMD_REJECT: + if (ad != NULL) + { + //result = wifi_direct_client_reject(); + printf("Under construction...\n"); + } + break; + + case CMD_INVITE: + if (ad != NULL) + { + //result = wifi_direct_client_invite(); + printf("Under construction...\n"); + } + break; + + case CMD_SET_DEVICE_NAME: + { + if (ad != NULL) + { + char device_name[32 + 1]; + + memset(device_name, 0, sizeof(device_name)); + printf("Input device name :\n"); + scanf("%s",device_name); + + if (strlen(device_name) <= 0) + printf("invalid device name !!\n"); + else + printf("device_name: [%s]\n", device_name); + + + if ((strlen(device_name) > 0)) + { + result = wifi_direct_set_device_name(device_name); + printf("wifi_direct_set_device_name() ret=[%d]\n", result); + } + } + } + break; + + case CMD_GET_DEVICE_NAME: + { + if (ad != NULL) + { + char* device_name = NULL; + + result = wifi_direct_get_device_name(&device_name); + printf("wifi_direct_get_device_name() result=[%d]\n", result); + + if (NULL != device_name) + { + printf("ssid: [%s]\n", device_name); + free(device_name); + } + + } + } + break; + + case CMD_GET_SSID: + { + if (ad != NULL) + { + char* ssid = NULL; + + result = wifi_direct_get_ssid(&ssid); + printf("wifi_direct_get_ssid() result=[%d]\n", result); + + if (NULL != ssid) + { + printf("ssid: [%s]\n", ssid); + free(ssid); + } + + } + } + break; + + case CMD_SET_CHANNEL: + if (ad != NULL) + { + +#if 0 + wifi_direct_config_data_s *config; + result = wifi_direct_get_config_data(&config); + if(result != WIFI_DIRECT_ERROR_NONE) + { + printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result); + } + else + { + printf("Current operating channel: [%d]\n", config->channel); + printf("Input operation channel:\n"); + scanf("%d", &config->channel); + + printf("New operation channel: [%d]\n", config->channel); + + result = wifi_direct_set_config_data(config); + printf("wifi_direct_set_config_data() result=[%d]\n", result); + } +#endif + + } + break; + case CMD_SET_WPS_CONFIG: + if (ad != NULL) + { +#if 0 + wifi_direct_config_data_s *config; + result = wifi_direct_get_config_data(&config); + if(result != WIFI_DIRECT_ERROR_NONE) + { + printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result); + } + else + { + printf("Current WPS config method: [%d, %s]\n", config->wps_config, + (config->wps_config==WIFI_DIRECT_WPS_TYPE_PBC)?"Pushbutton": + (config->wps_config==WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)?"Display":"Keypad"); + printf("Input operation channel[%d:Pushbutton %d:display %d:keypad] \n", + WIFI_DIRECT_WPS_TYPE_PBC, WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY, WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD); + + scanf("%d", &config->wps_config); + + printf("New WPS config method: [%d, %s]\n", config->channel, + (config->wps_config==WIFI_DIRECT_WPS_TYPE_PBC)?"Pushbutton": + (config->wps_config==WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY)?"Display":"Keypad"); + + result = wifi_direct_set_config_data(config); + printf("wifi_direct_set_config_data() result=[%d]\n", result); + } +#endif + } + break; + case CMD_SET_MAX_CLIENT: + if (ad != NULL) + { + int max_client; + result = wifi_direct_get_max_clients(&max_client); + + printf("Current max client=[%d]\n", max_client); + printf("Input new max client:\n"); + scanf("%d", &max_client); + + result = wifi_direct_set_max_clients(max_client); + printf("wifi_direct_set_max_clients() result=[%d] max_client[%d]\n", result, max_client); + } + break; + + case CMD_GET_MAX_CLIENT: + if (ad != NULL) + { + int max_client; + + result = wifi_direct_get_max_clients(&max_client); + printf("wifi_direct_get_max_clients() result=[%d] max_client[%d]\n", result, max_client); + } + break; + + case CMD_SET_HIDE_SSID: + if (ad != NULL) + { +#if 0 + wifi_direct_config_data_s *config; + result = wifi_direct_get_config_data(&config); + if(result != WIFI_DIRECT_ERROR_NONE) + { + printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result); + } + else + { + printf("Current hide SSID: [%d]\n", config->hide_SSID); + printf("Want to hide SSID (0: no hide, 1: hide):\n"); + scanf("%d", config->hide_SSID); + printf("New hide SSID: [%d]\n", config->hide_SSID); + result = wifi_direct_set_config_data(config); + printf("wifi_direct_set_config_data() result=[%d]\n", result); + } +#endif + + } + break; + + case CMD_ACTIVATE_PERSISTENT_GROUP: + if (ad != NULL) + { + result = wifi_direct_set_persistent_group_enabled(true); + + if(result != WIFI_DIRECT_ERROR_NONE) + printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); + else + printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); + } + break; + + case CMD_DEACTIVATE_PERSISTENT_GROUP: + if (ad != NULL) + { + result = wifi_direct_set_persistent_group_enabled(false); + + if(result != WIFI_DIRECT_ERROR_NONE) + printf("Failed to wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); + else + printf("wifi_direct_set_persistent_group_enabled() result=[%d]\n", result); + } + break; + + case CMD_IS_PERSISTENT_GROUP_ACTIVATED: + if (ad != NULL) + { + bool enabled; + + result = wifi_direct_is_persistent_group_enabled(&enabled); + printf("wifi_direct_is_persistent_group_enabled() result=[%d]\n", result); + if ( enabled == TRUE ) + printf("Persistent Group mode!! \n"); + else + printf("NOT Persistent group mode!! \n"); + } + break; + + + case CMD_GET_PERSISTENT_GROUP_LIST: + if (ad != NULL) + { + result = wifi_direct_foreach_persistent_groups(_cb_persistent_groups_impl, (void*)ad); + printf("wifi_direct_foreach_persistent_groups() ret=[%d]\n", result); + } + break; + + case CMD_REMOVE_PERSISTENT_GROUP: + if (ad != NULL) + { + char mac[18]; + char ssid[32 + 1]; + + memset(mac, 0, sizeof(mac)); + memset(ssid, 0, sizeof(ssid)); + + printf("Input GO MAC :\n"); + scanf("%s",mac); + + if (strlen(mac) <= 0) + printf("invalid GO MAC !!\n"); + else + printf("GO MAC: [%s]\n", mac); + + + printf("Input ssid :\n"); + scanf("%s",ssid); + + if (strlen(ssid) <= 0) + printf("invalid ssid !!\n"); + else + printf("ssid: [%s]\n", ssid); + + + if ((strlen(mac) > 0) && (strlen(ssid) > 0)) + { + result = wifi_direct_remove_persistent_group(mac, ssid); + printf("wifi_direct_remove_persistent_group() ret=[%d]\n", result); + } + + } + break; + +#if 0 + case CMD_SET_GROUP_OWNER: + if (ad != NULL) + { + wifi_direct_config_data_s *config; + result = wifi_direct_get_config_data(&config); + if(result != WIFI_DIRECT_ERROR_NONE) + { + printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result); + } + else + { + printf("Current want-group-owner: [%d]\n", config->want_group_owner); + printf("Input want-group-owner:\n"); + scanf("%d", config->want_group_owner); + + printf("New want-group-owner: [%d]\n", config->want_group_owner); + + result = wifi_direct_set_config_data(config); + printf("wifi_direct_set_config_data() result=[%d]\n", result); + } + } + break; +#endif + + case CMD_SET_AUTO_CONNECTION: + if (ad != NULL) + { + int autoconnection_mode; + + printf("Input Auto connection: \n"); + printf("[1] true [2] false\n"); + + scanf("%d", &autoconnection_mode); + + if (autoconnection_mode == 1) + result = wifi_direct_set_autoconnection_mode(true); + else if (autoconnection_mode == 2) + result = wifi_direct_set_autoconnection_mode(false); + else + printf("Invalid input parameter!!!\n"); + + printf("wifi_direct_set_autoconnection_mode() result=[%d] \n", result); + + } + break; + + case CMD_IS_AUTO_CONNECTION: + if (ad != NULL) + { + bool auto_connection = false; + + result = wifi_direct_is_autoconnection_mode(&auto_connection); + printf("wifi_direct_is_autoconnection_mode() result=[%d]\n", result); + if ( auto_connection == TRUE ) + printf("Auto connection mode !! \n"); + else + printf("NOT Auto connection mode !! \n"); + + } + break; + + +#if 0 + case CMD_SET_LISTEN_ONLY: + if (ad != NULL) + { + wifi_direct_config_data_s *config; + result = wifi_direct_get_config_data(&config); + if(result != WIFI_DIRECT_ERROR_NONE) + { + printf("Failed to get wifi_direct_get_config_data() result=[%d]\n", result); + } + else + { + printf("Current want-listen-only: [%d]\n", config->want_listen_only); + printf("Input want-listen-only:\n"); + scanf("%d", config->want_listen_only); + + printf("New want-listen-only: [%d]\n", config->want_listen_only); + + result = wifi_direct_set_config_data(config); + printf("wifi_direct_set_config_data() result=[%d]\n", result); + } + } + break; +#endif + + case CMD_SET_WPS_PIN: + if (ad != NULL) + { + + char pin[9] = {0,}; + + printf("Input PIN number :\n"); + scanf("%s", pin); + printf("New PIN: [%s]\n", pin); + + if ((strlen(pin) > 0) && (strlen(pin) < 9)) + wifi_direct_set_wps_pin(pin); + else + printf("Invalid PIN number\n"); + } + break; + + case CMD_GET_WPS_PIN: + if (ad != NULL) + { + char *pin = NULL; + + result = wifi_direct_get_wps_pin(&pin); + printf("wifi_direct_get_wps_pin() result=[%d]\n", result); + if ( NULL != pin ) + { + printf("WPS_PIN [%s]\n", pin); + free(pin); + } + else + printf("WPS_PIN is NULL !! \n"); + } + break; + + case CMD_GET_SUPPORTED_WPS_MODE: + if (ad != NULL) + { + int supported_wps_mode = 0; + + result = wifi_direct_foreach_supported_wps_types(_cb_foreach_supported_wps_impl, NULL); + printf("wifi_direct_foreach_supported_wps_types() result=[%d]\n", result); + + result = wifi_direct_get_supported_wps_mode (&supported_wps_mode); + printf("wifi_direct_foreach_supported_wps_types() supported=[%d] result=[%d]\n", supported_wps_mode, result); + } + break; + + case CMD_SET_CURRENT_WPS_MODE: + if (ad != NULL) + { + + wifi_direct_wps_type_e wps_mode; + int input; + + result = wifi_direct_get_req_wps_type(&wps_mode); + switch(wps_mode) + { + case WIFI_DIRECT_WPS_TYPE_PBC : + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY : + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD : + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); + break; + default : + printf("ERROR : wps_mode=[%d]\n", wps_mode); + break; + } + + printf("Input new wps mode:\n"); + printf("1. WIFI_DIRECT_WPS_TYPE_PBC\n"); + printf("2. WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n"); + printf("3. WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD\n"); + scanf("%d", &input); + + switch(input) + { + case 1 : + wps_mode = WIFI_DIRECT_WPS_TYPE_PBC; + break; + case 2 : + wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY; + break; + case 3 : + wps_mode = WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD; + break; + default : + printf("ERROR : Invalid input wps_mode!!!\n"); + break; + } + + result = wifi_direct_set_req_wps_type(wps_mode); + printf("wifi_direct_set_wps_type() result=[%d]\n", result); + } + break; + + case CMD_GET_CURRENT_WPS_MODE: + if (ad != NULL) + { + wifi_direct_wps_type_e wps_mode; + result = wifi_direct_get_req_wps_type(&wps_mode); + printf("wifi_direct_get_wps_type() wps_mode=[%d], result=[%d]\n", wps_mode, result); + switch(wps_mode) + { + case WIFI_DIRECT_WPS_TYPE_PBC : + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PBC]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY : + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY]\n"); + break; + case WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD : + printf("Current wps_mode=[WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD]\n"); + break; + default : + printf("ERROR : wps_mode=[%d]\n", wps_mode); + break; + } + + } + break; + + case CMD_GET_CONNECTED_PEERS_INFO: + if (ad != NULL) + { + memset(ad->connected_peer_list, 0x00, sizeof(wifi_direct_connected_peer_info_s)*MAX_PEER_NUM); + ad->connected_peer_count = 0; + + result = wifi_direct_foreach_connected_peers(_cb_connected_peers_impl, (void*)ad); + printf("wifi_direct_foreach_connected_peers() ret=[%d]\n", result); + print_peers_connected(ad); + } + break; + + case CMD_GET_GO_INTENT: + if (ad != NULL) + { + int go_intent; + + result = wifi_direct_get_group_owner_intent(&go_intent); + printf("wifi_direct_get_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent); + } + break; + + case CMD_SET_GO_INTENT: + if (ad != NULL) + { + int go_intent; + result = wifi_direct_get_group_owner_intent(&go_intent); + + printf("Current GO intent=[%d]\n", go_intent); + printf("Input new GO intent [0~15]:\n"); + scanf("%d", &go_intent); + + result = wifi_direct_set_group_owner_intent(go_intent); + printf("wifi_direct_set_group_owner_intent() result=[%d] go_intent[%d]\n", result, go_intent); + } + break; + + case CMD_GET_DEVICE_MAC: + if (ad != NULL) + { + char *device_mac = NULL; + + result = wifi_direct_get_mac_address(&device_mac); + printf("wifi_direct_get_mac_addr() result=[%d]\n", result); + if ( NULL != device_mac ) + printf ("MAC [%s] \n", device_mac); + else + printf("device_mac is NULL !! \n"); + } + break; + + case CMD_IS_AUTONOMOUS_GROUP: + if (ad != NULL) + { + bool autonomous_group; + + result = wifi_direct_is_autonomous_group(&autonomous_group); + printf("wifi_direct_is_autonomous_group() result=[%d]\n", result); + if ( autonomous_group == TRUE ) + printf("Autonomous Group !! \n"); + else + printf("NOT Autonomous group !! \n"); + + } + break; + + case CMD_GET_NETWORK_IF_NAME: + if (ad != NULL) + { + char* name = NULL; + + result = wifi_direct_get_network_interface_name(&name); + printf("wifi_direct_get_network_interface_name() result=[%d]\n", result); + + if (NULL != name) + { + printf("name: [%s]\n", name); + free(name); + } + + } + break; + + case CMD_GET_SUBNET_MASK: + if (ad != NULL) + { + char* subnet_mask = NULL; + + result = wifi_direct_get_subnet_mask(&subnet_mask); + printf("wifi_direct_get_subnet_mask() result=[%d]\n", result); + + if (NULL != subnet_mask) + { + printf("subnet_mask: [%s]\n", subnet_mask); + free(subnet_mask); + } + + } + break; + + + case CMD_GET_GATEWAY_ADDR: + if (ad != NULL) + { + char* gateway_address = NULL; + + result = wifi_direct_get_gateway_address(&gateway_address); + printf("wifi_direct_get_gateway_address() result=[%d]\n", result); + + if (NULL != gateway_address) + { + printf("gateway_address: [%s]\n", gateway_address); + free(gateway_address); + } + + } + break; + + case CMD_IS_DISCOVERABLE: + if (ad != NULL) + { + bool discoverable = false; + + result = wifi_direct_is_discoverable(&discoverable); + printf("wifi_direct_is_discoverable() result=[%d]\n", result); + if ( discoverable == TRUE ) + printf("Discoverable state !! \n"); + else + printf("NOT Discoverable state !! \n"); + + } + break; + + case CMD_IS_LISTEN_ONLY: + if (ad != NULL) + { + bool listen_only = false; + + result = wifi_direct_is_listening_only(&listen_only); + printf("wifi_direct_is_listening_only() result=[%d]\n", result); + if ( listen_only == TRUE ) + printf("Listen only state !! \n"); + else + printf("NOT Listen only state !! \n"); + + } + break; + + case CMD_GET_PRIMARY_DEVICE_TYPE: + if (ad != NULL) + { + wifi_direct_primary_device_type_e type; + + result = wifi_direct_get_primary_device_type(&type); + + printf("wifi_direct_get_primary_device_type() result=[%d]\n", result); + printf("Primary Device TYPE [%d]\n", type); + + } + break; + + case CMD_GET_SECONDARY_DEVICE_TYPE: + if (ad != NULL) + { + wifi_direct_secondary_device_type_e type; + + result = wifi_direct_get_secondary_device_type(&type); + + printf("wifi_direct_get_secondary_device_type() result=[%d]\n", result); + printf("Secondary Device TYPE [%d]\n", type); + } + break; + + case CMD_GET_OPERATING_CHANNEL: + if (ad != NULL) + { + int operating_channel; + + result = wifi_direct_get_operating_channel(&operating_channel); + + printf("wifi_direct_get_own_group_channel() result=[%d]\n", result); + printf("Operating Channel [%d]\n", operating_channel); + + } + break; + + case CMD_GET_IP_ADDR: + { + if (ad != NULL) + { + char* ip_addr = NULL; + + result = wifi_direct_get_ip_address(&ip_addr); + printf("wifi_direct_get_ip_address() result=[%d]\n", result); + if(NULL != ip_addr) + { + printf("IP [%s]\n", ip_addr); + free(ip_addr); + } + else + { + printf("IP is NULL\n"); + } + } + } + break; + + case CMD_INCREASE_OEM_LOGLEVEL: + wifi_direct_set_p2poem_loglevel(1); + break; + + case CMD_DECREASE_OEM_LOGLEVEL: + wifi_direct_set_p2poem_loglevel(0); + break; + + case CMD_REGISTER_SERVICE: + if (ad != NULL) + { + wifi_direct_service_type_e service_type; + int input; + char info1[50] = {0,}; + char info2[50] = {0,}; + char str[50] = {0, }; + + printf("Input service type:\n"); + printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n"); + printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n"); + printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n"); + printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n"); + scanf("%d", &input); + printf("input = %d\n",input); + + switch(input) + { + case 1 : + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; + printf("Enter info 1\n"); + scanf("%s", info1); + printf("Enter info 2\n"); + scanf("%s", info2); + break; + case 3 : + service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; + printf("Enter info 1\n"); + scanf("%s", info1); + printf("Enter info 2\n"); + scanf("%s", info2); + break; + case 4 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 5 : + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + printf("Enter contact info\n"); + scanf("%s", str); + break; + default : + printf("ERROR : Invalid input service_type!!!\n"); + break; + } + + result = wifi_direct_register_service(service_type, info1, info2, &input); + printf("wifi_direct_register_service() service id=[%d] result=[%d]\n", + input, result); + } + break; + + case CMD_DEREGISTER_SERVICE: + if (ad != NULL) + { + int input; + + printf("Enter service id:\n"); + scanf("%d", &input); + + + result = wifi_direct_deregister_service(input); + printf("wifi_direct_deregister_service() result=[%d]\n", + result); + } + break; + case CMD_START_SERVICE_DISCOVERY: + if (ad != NULL) + { + int input; + wifi_direct_service_type_e service_type; + + printf("Input service type:\n"); + printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + printf("2. WIFI_DIRECT_SERVICE_TYPE_BONJOUR\n"); + printf("3. WIFI_DIRECT_SERVICE_TYPE_UPNP\n"); + printf("4. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n"); + printf("5. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n"); + scanf("%d", &input); + printf("input = %d\n",input); + + switch(input) + { + case 1 : + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; + break; + case 3 : + service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; + break; + case 4 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 5 : + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + break; + default : + printf("ERROR : Invalid input service_type!!!\n"); + break; + } + + if (select_peer(ad)) + { + + result = wifi_direct_start_service_discovery( + NULL, service_type); + + printf ("Service Discovery... broadcast service type[%d]\n", + service_type); + } else { + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_start_service_discovery( + list[i].mac_address, service_type); + + printf ("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n", + i,list[i].mac_address, service_type); + } + + printf("wifi_direct_start_service_discovery() result=[%d]\n", result); + + } + break; + + case CMD_CANCEL_SERVICE_DISCOVERY: + if (ad != NULL) + { + int input; + wifi_direct_service_type_e service_type; + + printf("Input service ID:\n"); + + scanf("%d", &input); + printf("input = %d\n",input); + + switch(input) + { + case 1 : + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BONJOUR; + break; + case 3 : + service_type = WIFI_DIRECT_SERVICE_TYPE_UPNP; + break; + case 4 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 5 : + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + break; + default : + printf("ERROR : Invalid input service_type!!!\n"); + break; + } + + if (select_peer(ad)) + { + + + result = wifi_direct_cancel_service_discovery( + NULL, service_type); + + printf ("Service Discovery... broadcast service type[%d]\n", + service_type); + } else { + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_cancel_service_discovery( + list[i].mac_address, service_type); + + printf ("Service Discovery... peer-index[%d] MAC [%s] service type[%d]\n", + i,list[i].mac_address, service_type); + } + printf("wifi_direct_cancel_service_discovery() result=[%d]\n", result); + } + break; + + case CMD_INIT_MIRACAST: + if (ad != NULL) + { + int miracast_enable; + + printf("Input miracast enable: \n"); + printf("[1] true [2] false\n"); + + scanf("%d", &miracast_enable); + + if (miracast_enable == 1) + result = wifi_direct_init_miracast(true); + else if (miracast_enable == 2) + result = wifi_direct_init_miracast(false); + else + printf("Invalid input parameter!!!\n"); + + printf("wifi_direct_init_miracast() result=[%d] \n", result); + + } + break; + + case CMD_GET_PEER_INFO: + if (ad != NULL) + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + wifi_direct_discovered_peer_info_s* peer_info = NULL; + + result = wifi_direct_get_peer_info(list[i].mac_address, &peer_info); + if(peer_info !=NULL) { + printf ("MAC [%s] Owner=[%s] connected=[%d] SSID[%s] ctg=[%d/%d]", + peer_info->mac_address, + peer_info->is_group_owner ? "YES" : "NO", + peer_info->is_connected, + peer_info->device_name, + peer_info->primary_device_type, + peer_info->secondary_device_type + ); + if(peer_info->mac_address) + free(peer_info->mac_address); + if(peer_info->interface_address) + free(peer_info->interface_address); + if(peer_info) + free(peer_info); + } + + printf("wifi_direct_get_peer() result=[%d]\n", result); + } + break; + case CMD_SET_PASSPHRASE: + { + if (ad != NULL) + { + char passphrase[64 + 1]; + + memset(passphrase, 0, sizeof(passphrase)); + printf("Input passphrase :\n"); + scanf("%s",passphrase); + + if (strlen(passphrase) <= 0) + printf("invalid passphrase !!\n"); + else + printf("passphrase: [%s]\n", passphrase); + + + if ((strlen(passphrase) > 0)) + { + result = wifi_direct_set_passphrase(passphrase); + printf("wifi_direct_set_passphrase() ret=[%d]\n", result); + } + } + } + break; + case CMD_GET_PASSPHRASE: + { + if (ad != NULL) + { + char* passphrase = NULL; + + result = wifi_direct_get_passphrase(&passphrase); + printf("wifi_direct_get_passphrase() result=[%d]\n", result); + + if (NULL != passphrase) + { + printf("passphrase: [%s]\n", passphrase); + free(passphrase); + } + + } + } + break; + case CMD_SET_AUTOCONNECTION_PEER: + if (ad != NULL) + { + char * mac_address = NULL; + printf("\nEnter Mac_address: "); + if(scanf(" %ms", &mac_address) < 1) + break; + + if (strlen(mac_address) > 23) + { + printf("\nWrong Mac_address"); + } + else { + + int rv = wifi_direct_set_autoconnection_peer(mac_address); + + if (rv == WIFI_DIRECT_ERROR_NONE) + { + free(mac_address); + printf(MAKE_GREEN"SUCCESS %s"RESET_COLOR"\n",__func__); + break; + } + printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv)); + } + + free(mac_address); + } + break; + case CMD_INIT_DISPLAY: + { + if (ad != NULL) + { + result = wifi_direct_init_display(); + printf("wifi_direct_init_display() result=[%d]\n", result); + } + } + break; + case CMD_DEINIT_DISPLAY: + { + if (ad != NULL) + { + result = wifi_direct_deinit_display(); + printf("wifi_direct_deinit_display() result=[%d]\n", result); + } + } + break; + case CMD_SET_DISPLAY: + { + if (ad != NULL) + { + int rv = WIFI_DIRECT_ERROR_NONE; + int use_default = 0; + + printf("Press [0] For Setting Default Values\n"); + if(scanf(" %d",&use_default) < 1) { + break; + } + + if(use_default == 0) { + rv = wifi_direct_set_display(WIFI_DIRECT_DISPLAY_TYPE_SOURCE, 7236, 1); + } else { + int display_type = 0; + int port_number = 0; + int hdcp = 0; + + printf("DISPLAY_TYPE----->\n"); + printf("(0) for WIFI_DISPLAY_TYPE_SOURCE,\n"); + printf("(1) for WIFI_DISPLAY_TYPE_PRIMARY_SINK,\n"); + printf("(2) for WIFI_DISPLAY_TYPE_SECONDARY_SINK,\n"); + printf("(3) WIFI_DISPLAY_TYPE_DUAL_ROLE\n"); + printf("Please Enter DISPLAY_TYPE -----> "); + if(scanf(" %d",&display_type) < 1) { + break; + } + + printf("Please Enter PORT NUMBER -----> "); + if(scanf(" %d",&port_number) < 1) { + break; + } + printf("Please Enter HDCP -----> "); + if(scanf(" %d",&hdcp) < 1) { + break; + } + + rv = wifi_direct_set_display(display_type, port_number, hdcp); + } + + if(rv == WIFI_DIRECT_ERROR_NONE) { + printf(MAKE_GREEN"Success %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv)); + break; + } + + printf(MAKE_RED"FAILED %s : %s"RESET_COLOR"\n",__func__,test_wfd_convert_error_to_string(rv)); + break; + } + } + break; + case CMD_SET_DISPLAY_AVAILABILITY: + { + if (ad != NULL) + { + int availability = 0; + + printf("Enter Wi-Fi Display availability : "); + if(scanf(" %d", &availability) < 0) { + break; + } + + int rv = wifi_direct_set_display_availability(availability); + if (WIFI_DIRECT_ERROR_NONE == rv) + { + printf(MAKE_GREEN"Set Wi-Fi Display availability Successfull"RESET_COLOR"\n"); + break; + } + printf(MAKE_RED"Set Wi-Fi Display availability : %s ",test_wfd_convert_error_to_string(rv)); + printf(RESET_COLOR"\n"); + break; + } + } + break; + case CMD_GET_PEER_DISPLAY_TYPE: + if (ad != NULL) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + int type; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_get_peer_display_type(list[i].mac_address, &type); + + printf("wifi_direct_get_peer_display_type() result=[%d]\n", type); + } + } + break; + case CMD_GET_PEER_DISPLAY_AVAILABILITY: + if (ad != NULL) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + int availability; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_get_peer_display_availability(list[i].mac_address, &availability); + + printf("wifi_direct_get_peer_display_availability() result=[%d]\n", availability); + } + } + break; + case CMD_GET_PEER_DISPLAY_HDCP: + if (ad != NULL) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + int hdcp; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_get_peer_display_hdcp(list[i].mac_address, &hdcp); + + printf("wifi_direct_get_peer_display_hdcp() result=[%d]\n", hdcp); + } + } + break; + case CMD_GET_PEER_DISPLAY_PORT: + if (ad != NULL) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + int port; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_get_peer_display_port(list[i].mac_address, &port); + + printf("wifi_direct_get_peer_display_port() result=[%d]\n", port); + } + } + break; + case CMD_GET_PEER_DISPLAY_THROUGHPUT: + if (ad != NULL) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + int tput; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + + result = wifi_direct_get_peer_display_throughput(list[i].mac_address, &tput); + + printf("wifi_direct_get_peer_display_throughput() result=[%d]\n", tput); + } + } + break; + + case CMD_FULL_MENU: + usage_full(); + break; + + case CMD_QUIT: + printf("Bye\n"); + g_main_loop_quit(ad->main_loop); + break; + + default: + usage_full(); + break; + } +} + +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=%s\n", strerror(errno)); + } + else + { + printf("\n\n"); + //printf("Read [%d]bytes data: [%s]\n", n, buf); + //printf("Processing it ---------------------\n", n, buf); + } + + process_input(buf, user_data); + + return TRUE; +} + +int main(int argc, char **argv) +{ + GMainLoop *main_loop; + int pid = -1; + int result; + + 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)); + + ad->main_loop = main_loop; +#if 0 + ad->peer_list = NULL; +#endif + ad->peer_count = 0; + + set_appdata(ad); + + 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