From 9d458a3211284cf973d51018b4680745d6a1591f Mon Sep 17 00:00:00 2001 From: "jk7744.park" Date: Tue, 8 Sep 2015 22:12:57 +0900 Subject: [PATCH] tizen 2.3.1 release --- AUTHORS | 3 + CMakeLists.txt | 71 +- 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 | 63 - debian/compat | 1 - debian/control | 21 - debian/rules | 64 - doc/wifi_direct_doc.h | 51 + include/wifi-direct.h | 1422 +++++++-- packaging/capi-network-wifi-direct.spec | 62 +- src/CMakeLists.txt | 117 + src/capi-network-wifi-direct.pc.in | 12 + src/include/wifi-direct-client-proxy.h | 101 + src/include/wifi-direct-ipc.h | 298 ++ src/wifi-direct-client-proxy.c | 4280 ++++++++++++++++++++++++++ test/test.c | 2464 +++++++++++++++ 22 files changed, 8738 insertions(+), 519 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 100755 doc/wifi_direct_doc.h mode change 100644 => 100755 include/wifi-direct.h 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 100644 src/include/wifi-direct-client-proxy.h create mode 100644 src/include/wifi-direct-ipc.h create mode 100755 src/wifi-direct-client-proxy.c create mode 100644 test/test.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 7e39e81..078daf5 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,70 +1,13 @@ 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/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) 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 097a2d1..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=/usr/lib -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 4bc40db..0000000 --- a/debian/changelog +++ /dev/null @@ -1,63 +0,0 @@ -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/doc/wifi_direct_doc.h b/doc/wifi_direct_doc.h new file mode 100755 index 0000000..1daa4b4 --- /dev/null +++ b/doc/wifi_direct_doc.h @@ -0,0 +1,51 @@ +/* + * 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. + */ + + +#ifndef __TIZEN_NETWORK_WIFI_DIRECT_DOC_H__ +#define __TIZEN_NETWORK_WIFI_DIRECT_DOC_H__ + + +/** + * @defgroup CAPI_NETWORK_WIFI_DIRECT_MODULE Wi-Fi Direct + * @brief Wi-Fi Direct provides API to manage Wi-Fi Direct. + * @ingroup CAPI_NETWORK_FRAMEWORK + * + * @section CAPI_NETWORK_WIFI_DIRECT_MODULE_HEADER Required Header + * \#include + * + * @section CAPI_NETWORK_WIFI_DIRECT_MODULE_OVERVIEW Overview + * This set of functions is used to manage the settings of Wi-Fi Direct. + * In addition, This set provides functions to connect and disconnect remote devices using Wi-Fi Direct. + * @section CAPI_NETWORK_WIFI_DIRECT_MANAGER_MODULE_FEATURE Related Features + * This API is related with the following features:\n + * - http://tizen.org/feature/network.wifi\n + * - http://tizen.org/feature/network.wifi.direct\n + * - http://tizen.org/feature/network.wifi.direct.display\n + * - http://tizen.org/feature/network.wifi.direct.serivce_discovery\n + * + * It is recommended to design feature related codes in your application for reliability.\n + * + * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n + * + * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n + * + * More details on featuring your application can be found from Feature List. + * + */ + + +#endif /* __TIZEN_NETWORK_WIFI_DIRECT_DOC_H__ */ diff --git a/include/wifi-direct.h b/include/wifi-direct.h old mode 100644 new mode 100755 index 21ba9a4..7e512fa --- 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__ @@ -23,208 +27,318 @@ extern "C" { #endif +#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" + +#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) + /** - * @addtogroup CAPI_NET_WIFI_DIRECT_MODULE + * @addtogroup CAPI_NETWORK_WIFI_DIRECT_MODULE * @{ */ /** - * @brief Enumeration for Wi-Fi Direct error code + * @brief Enumeration for Wi-Fi Direct error code. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - WIFI_DIRECT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - WIFI_DIRECT_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation not permitted */ - WIFI_DIRECT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter */ - WIFI_DIRECT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy */ - WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT = TIZEN_ERROR_CONNECTION_TIME_OUT, /**< Connection timed out */ - WIFI_DIRECT_ERROR_NOT_INITIALIZED = TIZEN_ERROR_NETWORK_CLASS|0x0201, /**< Not initialized */ - WIFI_DIRECT_ERROR_COMMUNICATION_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0202, /**< I/O error */ - WIFI_DIRECT_ERROR_WIFI_USED = TIZEN_ERROR_NETWORK_CLASS|0x0203, /**< WiFi is being used */ - WIFI_DIRECT_ERROR_MOBILE_AP_USED = TIZEN_ERROR_NETWORK_CLASS|0x0204, /**< Mobile AP is being used */ - WIFI_DIRECT_ERROR_CONNECTION_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0205, /**< Connection failed */ - WIFI_DIRECT_ERROR_AUTH_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0206, /**< Authentication failed */ - WIFI_DIRECT_ERROR_OPERATION_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0207, /**< Operation failed */ - WIFI_DIRECT_ERROR_TOO_MANY_CLIENT = TIZEN_ERROR_NETWORK_CLASS|0x0208, /**< Too many client */ + WIFI_DIRECT_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + WIFI_DIRECT_ERROR_NOT_PERMITTED = TIZEN_ERROR_NOT_PERMITTED, /**< Operation not permitted(1) */ + WIFI_DIRECT_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory(12) */ + WIFI_DIRECT_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied(13) */ + WIFI_DIRECT_ERROR_RESOURCE_BUSY = TIZEN_ERROR_RESOURCE_BUSY, /**< Device or resource busy(16) */ + WIFI_DIRECT_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid function parameter(22) */ + WIFI_DIRECT_ERROR_CONNECTION_TIME_OUT = TIZEN_ERROR_CONNECTION_TIME_OUT, /**< Connection timed out(110) */ + WIFI_DIRECT_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */ + WIFI_DIRECT_ERROR_NOT_INITIALIZED = TIZEN_ERROR_WIFI_DIRECT|0x01, /**< Not initialized */ + WIFI_DIRECT_ERROR_COMMUNICATION_FAILED = TIZEN_ERROR_WIFI_DIRECT|0x02, /**< I/O error */ + WIFI_DIRECT_ERROR_WIFI_USED = TIZEN_ERROR_WIFI_DIRECT|0x03, /**< WiFi is being used */ + WIFI_DIRECT_ERROR_MOBILE_AP_USED = TIZEN_ERROR_WIFI_DIRECT|0x04, /**< Mobile AP is being used */ + WIFI_DIRECT_ERROR_CONNECTION_FAILED = TIZEN_ERROR_WIFI_DIRECT|0x05, /**< Connection failed */ + WIFI_DIRECT_ERROR_AUTH_FAILED = TIZEN_ERROR_WIFI_DIRECT|0x06, /**< Authentication failed */ + WIFI_DIRECT_ERROR_OPERATION_FAILED = TIZEN_ERROR_WIFI_DIRECT|0x07, /**< Operation failed */ + WIFI_DIRECT_ERROR_TOO_MANY_CLIENT = TIZEN_ERROR_WIFI_DIRECT|0x08, /**< Too many client */ + WIFI_DIRECT_ERROR_ALREADY_INITIALIZED = TIZEN_ERROR_WIFI_DIRECT|0x09, /**< Already initialized client */ + WIFI_DIRECT_ERROR_CONNECTION_CANCELED = TIZEN_ERROR_WIFI_DIRECT|0x10, /**< Connection canceled by local device */ } wifi_direct_error_e; /** - * @brief Enumeration for Wi-Fi Direct link status + * @brief Enumeration for Wi-Fi Direct link status. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_STATE_DEACTIVATED = 0, /**< Deactivated */ - WIFI_DIRECT_STATE_DEACTIVATING, /**< Deactivating */ - WIFI_DIRECT_STATE_ACTIVATING, /**< Activating */ - WIFI_DIRECT_STATE_ACTIVATED, /**< Activated */ - WIFI_DIRECT_STATE_DISCOVERING, /**< Discovering */ - WIFI_DIRECT_STATE_CONNECTING, /**< Connecting */ - WIFI_DIRECT_STATE_DISCONNECTING, /**< Disconnecting */ - WIFI_DIRECT_STATE_CONNECTED, /**< Connected */ + WIFI_DIRECT_STATE_DEACTIVATED = 0, /**< Deactivated */ + WIFI_DIRECT_STATE_DEACTIVATING, /**< Deactivating */ + WIFI_DIRECT_STATE_ACTIVATING, /**< Activating */ + WIFI_DIRECT_STATE_ACTIVATED, /**< Activated */ + WIFI_DIRECT_STATE_DISCOVERING, /**< Discovering */ + WIFI_DIRECT_STATE_CONNECTING, /**< Connecting */ + WIFI_DIRECT_STATE_DISCONNECTING, /**< Disconnecting */ + WIFI_DIRECT_STATE_CONNECTED, /**< Connected */ + WIFI_DIRECT_STATE_GROUP_OWNER /**< Group owner */ } wifi_direct_state_e; /** - * @brief Enumeration for Wi-Fi Direct device state + * @brief Enumeration for Wi-Fi Direct device state. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_DEVICE_STATE_ACTIVATED, /**< Activated */ - WIFI_DIRECT_DEVICE_STATE_DEACTIVATED, /**< Deactivated */ + WIFI_DIRECT_DEVICE_STATE_ACTIVATED, /**< Activated */ + WIFI_DIRECT_DEVICE_STATE_DEACTIVATED, /**< Deactivated */ } wifi_direct_device_state_e; /** - * @brief Enumeration for Wi-Fi Direct discovery state + * @brief Enumeration for Wi-Fi Direct discovery state. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_ONLY_LISTEN_STARTED, /**< Only listen started */ - WIFI_DIRECT_DISCOVERY_STARTED, /**< Discovery started */ - WIFI_DIRECT_DISCOVERY_FOUND, /**< A remote peer is found */ - WIFI_DIRECT_DISCOVERY_FINISHED, /**< Discovery finished */ + WIFI_DIRECT_ONLY_LISTEN_STARTED, /**< Only listen started */ + WIFI_DIRECT_DISCOVERY_STARTED, /**< Discovery started */ + WIFI_DIRECT_DISCOVERY_FOUND, /**< A remote peer is found */ + WIFI_DIRECT_DISCOVERY_FINISHED, /**< Discovery finished */ } wifi_direct_discovery_state_e; /** - * @brief Enumeration for Wi-Fi Direct connection state + * @brief Enumeration for Wi-Fi Direct connection state. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_CONNECTION_REQ, /**< Connection is requested */ - WIFI_DIRECT_CONNECTION_WPS_REQ, /**< WPS is requested */ - WIFI_DIRECT_CONNECTION_IN_PROGRESS, /**< Connection in progress */ - WIFI_DIRECT_CONNECTION_RSP, /**< Connected */ - WIFI_DIRECT_DISASSOCIATION_IND, /**< Disconnected by remote Group Client */ - WIFI_DIRECT_DISCONNECTION_RSP, /**< Disconnected by local device */ - WIFI_DIRECT_DISCONNECTION_IND, /**< Disconnected by remote Group Owner */ - WIFI_DIRECT_GROUP_CREATED, /**< Group is created */ - WIFI_DIRECT_GROUP_DESTROYED, /**< Group is destroyed */ + WIFI_DIRECT_CONNECTION_REQ, /**< Connection is requested */ + WIFI_DIRECT_CONNECTION_WPS_REQ, /**< WPS is requested */ + WIFI_DIRECT_CONNECTION_IN_PROGRESS, /**< Connection in progress */ + WIFI_DIRECT_CONNECTION_RSP, /**< Connected */ + WIFI_DIRECT_DISASSOCIATION_IND, /**< Disconnected by remote Group Client */ + WIFI_DIRECT_DISCONNECTION_RSP, /**< Disconnected by local device */ + WIFI_DIRECT_DISCONNECTION_IND, /**< Disconnected by remote Group Owner */ + WIFI_DIRECT_GROUP_CREATED, /**< Group is created */ + WIFI_DIRECT_GROUP_DESTROYED, /**< Group is destroyed */ } wifi_direct_connection_state_e; /** - * @brief Enumeration for Wi-Fi Direct secondary device type + * @brief Enumeration for Wi-Fi Direct secondary device type. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_PC = 1, /**< PC */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_SERVER = 2, /**< Server */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_MEDIA_CENTER = 3, /**< Media Center */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_UMPC = 4, /**< UMPC */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_NOTEBOOK = 5, /**< Notebook */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_DESKTOP = 6, /**< Desktop */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_MID = 7, /**< MID */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_NETBOOK = 8, /**< Netbook */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_KEYBOARD = 1, /**< Keyboard */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_MOUSE = 2, /**< Mouse */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_JOYSTICK = 3, /**< Joystick */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_TRACKBALL = 4, /**< Trackball */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_CONTROLLER = 5, /**< Controller */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_REMOTE = 6, /**< Remote */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_TOUCHSCREEN = 7, /**< Touchscreen */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_BIOMETRIC_READER = 8, /**< Biometric reader */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_BARCODE_READER = 9, /**< Barcode reader */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_PRINTER = 1, /**< Printer */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_SCANNER = 2, /**< Scanner */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_FAX = 3, /**< Fax */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_COPIER = 4, /**< Copier */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_ALL_IN_ONE = 5, /**< All-in-one */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_DIGITAL_STILL = 1, /**< Digital still camera */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_VIDEO = 2, /**< Video camera */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_WEBCAM = 3, /**< Webcam */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_SECURITY = 4, /**< Security camera */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_STORAGE_NAS = 1, /**< NAS */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_AP = 1, /**< AP */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_ROUTER = 2, /**< Router */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_SWITCH = 3, /**< Switch */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_GATEWAY = 4, /**< Gateway */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV = 1, /**< TV */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_PIC_FRAME = 2, /**< Picture frame */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_PROJECTOR = 3, /**< Projector */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_MONITOR = 4, /**< Monitor */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_DAR = 1, /**< DAR */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_PVR = 2, /**< PVR */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_MCX = 3, /**< MCX */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_STB = 4, /**< Set-top box */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_MS_MA_ME = 5, /**< Media Server / Media Adapter / Media Extender */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_PVP = 6, /**< Portable video player */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_XBOX = 1, /**< Xbox */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_XBOX_360 = 2, /**< Xbox 360 */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_PS = 3, /**< Playstation */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_CONSOLE = 4, /**< Console */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_PORTABLE = 5, /**< Portable */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_WINDOWS_MOBILE = 1, /**< Windows Mobile */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_PHONE_SINGLE = 2, /**< Phone - single mode */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_PHONE_DUAL = 3, /**< Phone - dual mode */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_SINGLE = 4, /**< Smart Phone - single mode */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL = 5, /**< Smart Phone - dual mode */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_TUNER = 1, /**< Tuner */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_SPEAKER = 2, /**< Speaker */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_PMP = 3, /**< Portable Music Player */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_HEADSET = 4, /**< Headset */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_HEADPHONE = 5, /**< Headphone */ - WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_MIC = 6, /**< Microphone */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_PC = 1, /**< PC */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_SERVER = 2, /**< Server */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_MEDIA_CENTER = 3, /**< Media Center */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_UMPC = 4, /**< UMPC */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_NOTEBOOK = 5, /**< Notebook */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_DESKTOP = 6, /**< Desktop */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_MID = 7, /**< MID */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_COMPUTER_NETBOOK = 8, /**< Netbook */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_KEYBOARD = 1, /**< Keyboard */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_MOUSE = 2, /**< Mouse */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_JOYSTICK = 3, /**< Joystick */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_TRACKBALL = 4, /**< Trackball */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_CONTROLLER = 5, /**< Controller */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_REMOTE = 6, /**< Remote */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_TOUCHSCREEN = 7, /**< Touchscreen */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_BIOMETRIC_READER = 8, /**< Biometric reader */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_INPUT_BARCODE_READER = 9, /**< Barcode reader */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_PRINTER = 1, /**< Printer */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_SCANNER = 2, /**< Scanner */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_FAX = 3, /**< Fax */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_COPIER = 4, /**< Copier */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_PRINTER_ALL_IN_ONE = 5, /**< All-in-one */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_DIGITAL_STILL = 1, /**< Digital still camera */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_VIDEO = 2, /**< Video camera */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_WEBCAM = 3, /**< Webcam */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_CAMERA_SECURITY = 4, /**< Security camera */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_STORAGE_NAS = 1, /**< NAS */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_AP = 1, /**< AP */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_ROUTER = 2, /**< Router */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_SWITCH = 3, /**< Switch */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_NETWORK_INFRA_GATEWAY = 4, /**< Gateway */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_TV = 1, /**< TV */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_PIC_FRAME = 2, /**< Picture frame */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_PROJECTOR = 3, /**< Projector */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_DISPLAY_MONITOR = 4, /**< Monitor */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_DAR = 1, /**< DAR */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_PVR = 2, /**< PVR */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_MCX = 3, /**< MCX */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_STB = 4, /**< Set-top box */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_MS_MA_ME = 5, /**< Media Server / Media Adapter / Media Extender */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_MULTIMEDIA_PVP = 6, /**< Portable video player */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_XBOX = 1, /**< Xbox */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_XBOX_360 = 2, /**< Xbox 360 */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_PS = 3, /**< Playstation */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_CONSOLE = 4, /**< Console */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_GAME_PORTABLE = 5, /**< Portable */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_WINDOWS_MOBILE = 1, /**< Windows Mobile */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_PHONE_SINGLE = 2, /**< Phone - single mode */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_PHONE_DUAL = 3, /**< Phone - dual mode */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_SINGLE = 4, /**< Smart Phone - single mode */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_TELEPHONE_SMARTPHONE_DUAL = 5, /**< Smart Phone - dual mode */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_TUNER = 1, /**< Tuner */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_SPEAKER = 2, /**< Speaker */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_PMP = 3, /**< Portable Music Player */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_HEADSET = 4, /**< Headset */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_HEADPHONE = 5, /**< Headphone */ + WIFI_DIRECT_SECONDARY_DEVICE_TYPE_AUDIO_MIC = 6, /**< Microphone */ } wifi_direct_secondary_device_type_e; /** - * @brief Enumeration for Wi-Fi Direct primary device type + * @brief Enumeration for Wi-Fi Direct primary device type. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_COMPUTER = 1, /**< Computer */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_INPUT_DEVICE = 2, /**< Input device */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_PRINTER = 3, /**< Printer */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_CAMERA = 4, /**< Camera */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_STORAGE = 5, /**< Storage */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_NETWORK_INFRA = 6, /**< Network Infrastructure */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_DISPLAY = 7, /**< Display */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_MULTIMEDIA_DEVICE = 8, /**< Multimedia device */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_GAME_DEVICE = 9, /**< Game device */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE = 10, /**< Telephone */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_AUDIO = 11, /**< Audio */ - WIFI_DIRECT_PRIMARY_DEVICE_TYPE_OTHER = 255 /**< Others */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_COMPUTER = 1, /**< Computer */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_INPUT_DEVICE = 2, /**< Input device */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_PRINTER = 3, /**< Printer */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_CAMERA = 4, /**< Camera */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_STORAGE = 5, /**< Storage */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_NETWORK_INFRA = 6, /**< Network Infrastructure */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_DISPLAY = 7, /**< Display */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_MULTIMEDIA_DEVICE = 8, /**< Multimedia device */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_GAME_DEVICE = 9, /**< Game device */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_TELEPHONE = 10, /**< Telephone */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_AUDIO = 11, /**< Audio */ + WIFI_DIRECT_PRIMARY_DEVICE_TYPE_OTHER = 255 /**< Others */ } wifi_direct_primary_device_type_e; /** - * @brief Enumeration for Wi-Fi WPS type + * @brief Enumeration for Wi-Fi WPS type. + * @since_tizen 2.3 */ typedef enum { - WIFI_DIRECT_WPS_TYPE_NONE = 0x00, /**< No WPS type */ - WIFI_DIRECT_WPS_TYPE_PBC = 0x01, /**< Push Button Configuration */ - WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY = 0x02, /**< Display PIN code */ - WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD = 0x04, /**< Provide the keypad to input the PIN */ + WIFI_DIRECT_WPS_TYPE_NONE = 0x00, /**< No WPS type */ + WIFI_DIRECT_WPS_TYPE_PBC = 0x01, /**< Push Button Configuration */ + WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY = 0x02, /**< Display PIN code */ + WIFI_DIRECT_WPS_TYPE_PIN_KEYPAD = 0x04, /**< Provide the keypad to input the PIN */ } wifi_direct_wps_type_e; /** - * @brief Wi-Fi Direct buffer structure to store result of peer discovery +* @brief Enumeration for Wi-Fi Display device type +* @since_tizen 2.3 +*/ +typedef enum { + WIFI_DISPLAY_TYPE_NONE, /**< Configure as WFD Source*/ + WIFI_DISPLAY_TYPE_SINK, /**< Configure as WFD Primary Sink */ + WIFI_DISPLAY_TYPE_SRC, /**< Configure as WFD Secondary Sink */ + WIFI_DISPLAY_TYPE_DUAL, /**< Configure as WFD Dual Role */ + WIFI_DISPLAY_TYPE_MAX, /**< Not configured*/ +} wifi_display_type_e; + +/** + * @brief Enumeration for Service Discovery type. + * @since_tizen 2.3 +*/ +typedef enum { + WIFI_DIRECT_SERVICE_TYPE_ALL, /**< Service discovery Type all*/ + WIFI_DIRECT_SERVICE_TYPE_BONJOUR, /**< Service discovery Type bonjour*/ + WIFI_DIRECT_SERVICE_TYPE_UPNP, /**< Service discovery Type UPNP*/ + WIFI_DIRECT_SERVICE_TYPE_WS_DISCOVERY, /**< Service discovery Type ws discovery*/ + WIFI_DIRECT_SERVICE_TYPE_WIFI_DISPLAY, /**< Service discovery Type wifi-display*/ + WIFI_DIRECT_SERVICE_TYPE_BT_ADDR, /**< Service discovery Type bt address*/ + WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO, /**< Service discovery Type contact info*/ + WIFI_DIRECT_SERVICE_TYPE_VENDOR = 0xff, /**< Service discovery Type vendor-specific*/ +} wifi_direct_service_type_e; + +/** + * @brief Enumeration for Wi-Fi Direct service Discovery state. + * @since_tizen 2.3 +*/ +typedef enum { + WIFI_DIRECT_SERVICE_DISCOVERY_STARTED, /**< Service discovery started*/ + WIFI_DIRECT_SERVICE_DISCOVERY_FOUND, /**< Service discovery found*/ + WIFI_DIRECT_SERVICE_DISCOVERY_FINISHED, /**< Service discovery finished*/ +} wifi_direct_service_discovery_state_e; + +/** + * @brief Enumeration for Wi-Fi Direct Discovery Channel. + * @since_tizen 2.3 +*/ +typedef enum { + WIFI_DIRECT_DISCOVERY_FULL_SCAN = 0, /**< Scan full channel*/ + WIFI_DIRECT_DISCOVERY_SOCIAL_CHANNEL = 1611, /**< Scan social channel*/ + WIFI_DIRECT_DISCOVERY_CHANNEL1 = 1, /**< Scan channel 1*/ + WIFI_DIRECT_DISCOVERY_CHANNEL6 = 6, /**< Scan channel 6*/ + WIFI_DIRECT_DISCOVERY_CHANNEL11 = 11, /**< Scan channel 11*/ +} wifi_direct_discovery_channel_e; + +/** + * @brief Wi-Fi Direct buffer structure to store result of peer discovery. + * @since_tizen 2.3 */ typedef struct { - char* ssid; /**< Device friendly name. */ - char *mac_address; /**< Device's P2P Device Address */ - char* interface_address; /**< Device's P2P Interface Address. Valid only if device is a P2P GO. */ - int channel; /**< Channel the device is listening on. */ - bool is_connected; /**< Is peer connected*/ - bool is_group_owner; /**< Is an active P2P Group Owner */ - bool is_persistent_group_owner; /**< Is a stored Persistent GO */ - 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 */ - int supported_wps_types; /**< The list of supported WPS type.\n The OR operation on #wifi_direct_wps_type_e can be used like #WIFI_DIRECT_WPS_TYPE_PBC | #WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY */ - bool is_p2p_invitation_procedure_supported; /**< Is capable of processing P2P Invitation Procedure signaling */ + char *device_name; /**< Device's friendly name */ + char *mac_address; /**< Device's P2P Device Address */ + char *interface_address; /**< Device's P2P Interface Address, Valid only if device is a P2P GO */ + int channel; /**< Channel the device is listening on */ + bool is_connected; /**< Is peer connected*/ + bool is_group_owner; /**< Is an active P2P Group Owner */ + bool is_persistent_group_owner; /**< Is a stored Persistent GO */ + 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 */ + int supported_wps_types; /**< The list of supported WPS type. The OR operation on #wifi_direct_wps_type_e can be used like #WIFI_DIRECT_WPS_TYPE_PBC | #WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY */ + bool is_p2p_invitation_procedure_supported; /**< Is capable of processing P2P Invitation Procedure signaling */ + unsigned int service_count; /**< The number of Registered services */ + char **service_list; /**< The list of registered services */ + bool is_miracast_device; /**< Is a wifi display device */ + + void *vsie_info; /**, 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_SECLOG(format, args...) SECURE_LOG(LOG_INFO, 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_SECLOG(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 MACSTR_LEN 18 +#define MACADDR_LEN 6 +#define IPSTR_LEN 16 +#define WFD_SOCK_FILE_PATH "/tmp/wfd_client_socket" +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 100644 index 0000000..7511a39 --- /dev/null +++ b/src/include/wifi-direct-ipc.h @@ -0,0 +1,298 @@ +/* + * 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_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 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_CONFIG, + WIFI_DIRECT_CMD_SET_CONFIG, + + WIFI_DIRECT_CMD_ACTIVATE_PUSHBUTTON, + WIFI_DIRECT_CMD_SET_WPS_PIN, // 30 + 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, + WIFI_DIRECT_CMD_GET_DEVICE_MAC, // 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, + +#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, +#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; + 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..0ae40d1 --- /dev/null +++ b/src/wifi-direct-client-proxy.c @@ -0,0 +1,4280 @@ +/* + * 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-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_DEVICE_MAC: + return "WIFI_DIRECT_CMD_GET_DEVICE_MAC"; + 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"; + +#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"; +#endif /* TIZEN_FEATURE_WIFI_DISPLAY */ + + case WIFI_DIRECT_CMD_GET_PEER_INFO: + return "WIFI_DIRECT_CMD_GET_PEER_INFO"; + 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); + errno = 0; + 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) { + errno = 0; + 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, }; + int service_type; + 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; + service_type = client_noti.type; + 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_SECLOG("MAC address : "MACSTR, MAC2STR(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_SECLOG("Device MAC : " MACSTR "\n", MAC2STR(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 ["IPSTR"]\n", IP2STR(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_SECLOG("GO MAC : " MACSTR, MAC2STR(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; + + errno = 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; + snprintf(saddr.sun_path, sizeof(saddr.sun_path), WFD_SOCK_FILE_PATH); + + WDC_LOGD("Connecting to server socket to register async socket [%d]", sockfd); + errno = 0; + 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; + } + + 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; + } + + errno = 0; + 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; + 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) { + errno = 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 = 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**) calloc(cnt, sizeof(char *)); + if (!result) { + WDC_LOGE("Failed to allocate memory for result"); + free(pos2); + return NULL; + } + pos1 = pos2; + pos2 = strtok (pos2,",\n"); + while (pos2 != NULL) { + char *s = strchr(pos2, ' '); + if (s) { + *s = '\0'; + result[i++] = strdup(pos2); + pos2 = strtok (NULL, ",\n"); + } + } + } + + free(pos1); + 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*) calloc(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*) calloc(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)); + 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 *) calloc(1, sizeof(wifi_direct_discovered_peer_info_s)); + peer_list->device_name = strdup(buff[i].device_name); + peer_list->mac_address = (char*) calloc(1, MACSTR_LEN); + snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address)); + peer_list->interface_address = (char*) calloc(1, MACSTR_LEN); + 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; + } + + if (buff) + 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*) calloc(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*) calloc(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 *) calloc(1, sizeof(wifi_direct_connected_peer_info_s)); + peer_list->device_name = strdup(buff[i].device_name); + peer_list->ip_address= (char*) calloc(1, IPSTR_LEN); + snprintf(peer_list->ip_address, IPSTR_LEN, IPSTR, IP2STR(buff[i].ip_address)); + peer_list->mac_address = (char*) calloc(1, MACSTR_LEN); + snprintf(peer_list->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].mac_address)); + peer_list->interface_address = (char*) calloc(1, MACSTR_LEN); + 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; + } + if (buff) { + free(buff); + buff = NULL; + } + } + + if (buff) { + free(buff); + buff = NULL; + } + + __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"); + strncpy(la_pin, rsp.param2, WIFI_DIRECT_WPS_PIN_LEN); + la_pin[WIFI_DIRECT_WPS_PIN_LEN] = '\0'; + *pin = 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); + strncpy(la_ssid, rsp.param2, WIFI_DIRECT_MAX_SSID_LEN); + la_ssid[WIFI_DIRECT_MAX_SSID_LEN] = '\0'; + *ssid = 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); + strncpy(la_device_name, rsp.param2, WIFI_DIRECT_MAX_DEVICE_NAME_LEN); + la_device_name[WIFI_DIRECT_MAX_DEVICE_NAME_LEN] = '\0'; + *device_name = 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 = strdup(get_str); + 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_state_e state = 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 (!ip_address) { + WDC_LOGE("NULL Param [ip_address]!\n"); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_INVALID_PARAMETER; + } + + result = wifi_direct_get_state(&state); + WDC_LOGD( "wifi_direct_get_state() state=[%d], result=[%d]", state, result); + if( state < 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_LOCAL_IP); + if (!get_str) + { + WDC_LOGD("vconf (%s) value is NULL!!!", VCONFKEY_LOCAL_IP); + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NOT_PERMITTED; + } + WDC_LOGD("VCONFKEY_LOCAL_IP(%s) : %s", VCONFKEY_LOCAL_IP, get_str); + *ip_address = strdup(get_str); + free(get_str); + + __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 = strdup(get_str); + 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 = strdup(get_str); + 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_DEVICE_MAC; + 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 = (char*) calloc(1, MACSTR_LEN); + snprintf(*mac_address, MACSTR_LEN, MACSTR, MAC2STR(rsp.param2)); + WDC_LOGD("wifi_direct_get_mac_address() %s SUCCESS", *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 *) calloc(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)); + 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 = strdup(buff[i].ssid); + if (!ssid) { + WDC_LOGD("Failed to copy ssid"); + break; + } + go_mac_address = (char*) calloc(1, MACSTR_LEN); + if (!go_mac_address) { + WDC_LOGD("Failed to allocate memory for GO MAC address"); + free(ssid); + free(buff); + return WIFI_DIRECT_ERROR_OUT_OF_MEMORY; + } + snprintf(go_mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff[i].go_mac_address)); + + res = cb(go_mac_address, ssid, user_data); + free(ssid); + ssid = NULL; + free(go_mac_address); + go_mac_address = NULL; + if (!res) + break; + } + + if (buff) + 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!"); + + strncpy(persistent_group_info.ssid, ssid, WIFI_DIRECT_MAX_SSID_LEN); + persistent_group_info.ssid[WIFI_DIRECT_MAX_SSID_LEN] ='\0'; + 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= malloc(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)); + 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); + 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*) calloc(1, 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 *) calloc(1, sizeof(wifi_direct_discovered_peer_info_s)); + if (!peer) { + WDC_LOGE("Failed to alloc memory"); + pthread_mutex_unlock(&g_client_info.mutex); + free(buff); + return WIFI_DIRECT_ERROR_OPERATION_FAILED; + } + peer->device_name = strdup(buff->device_name); + peer->mac_address = (char*) calloc(1, MACSTR_LEN); + snprintf(peer->mac_address, MACSTR_LEN, MACSTR, MAC2STR(buff->mac_address)); + peer->interface_address = (char*) calloc(1, MACSTR_LEN); + 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 */ + + if (buff) + free(buff); + *peer_info = peer; + + __WDC_LOG_FUNC_END__; + return WIFI_DIRECT_ERROR_NONE; +} diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..719f7e8 --- /dev/null +++ b/test/test.c @@ -0,0 +1,2464 @@ +#include +#include +#include +#include +#include + +#include +#include + +#include + +#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 + +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_REJECT, + CMD_INVITE, + 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_UNSET_ACTIVATION_CB, + CMD_UNSET_DISCOVER_CB, + CMD_UNSET_SERVICE_CB, + CMD_UNSET_CONNECTION_CB, + CMD_UNSET_PEER_FOUND_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_LOCAL_SERVICE, + CMD_DEREGISTER_LOCAL_SERVICE, + CMD_START_SERVICE_DISCOVERY, + CMD_CANCEL_SERVICE_DISCOVERY, + + CMD_INCREASE_OEM_LOGLEVEL, + CMD_DECREASE_OEM_LOGLEVEL, + CMD_DEINITIALIZE, + CMD_WFDS_DEREGISTER, + CMD_INIT_MIRACAST, + CMD_GET_PEER_INFO, + + 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_REJECT, "CMD_REJECT" }, + { CMD_INVITE, "CMD_INVITE" }, + { 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_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_LOCAL_SERVICE, "CMD_REGISTER_LOCAL_SERVICE" }, + { CMD_DEREGISTER_LOCAL_SERVICE, "CMD_DEREGISTER_LOCAL_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_WFDS_DEREGISTER, "CMD_WFDS_DEREGISTER" }, + { CMD_INIT_MIRACAST, "CMD_INIT_MIRACAST" }, + { CMD_GET_PEER_INFO, "CMD_GET_PEER_INFO" }, + + { -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++) + { + printf("%d: %s\n", g_menu_str[i].cmd, + cmd_transform(g_menu_str[i].menu_str)); + } +} + +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].ssid); + } + + 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].ssid); + } 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].ssid, + 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->ssid, + 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_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_DISPLAY) + { + printf("wps_config is WIFI_DIRECT_WPS_TYPE_PIN_DISPLAY\n"); + + result = wifi_direct_generate_wps_pin(); + printf("wifi_direct_generate_wps_pin() 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].ssid); + + printf("wifi_direct_accept_connection() result=[%d]\n", result); + } + } + break; + + case CMD_DISCONNECT_ALL: + 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_all(); + + printf ("Disconnecting... peer-index[%d] MAC [%s] Owner=[%s] SSID[%s]\n", + i, + list[i].mac_address, + list[i].is_group_owner ? "YES" : "NO", + list[i].ssid); + + 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].ssid); + + 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 ) + { + result = wifi_direct_generate_wps_pin(); + 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].ssid); + + 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_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_SSID: + if (ad != NULL) + { + char ssid[11] = {0,}; + printf("Input new SSID:\n"); + scanf("%s",ssid); + printf("New ssid: [%s]\n", ssid); + + if (strlen(ssid) > 0) + { + result = wifi_direct_set_ssid(ssid); + printf("wifi_direct_set_ssid() result=[%d]\n", result); + + if(result == WIFI_DIRECT_ERROR_NONE) + { + result = wifi_direct_cancel_discovery(); + printf("wifi_direct_cancel_discovery() result=[%d]\n", result); + } + + if(result == WIFI_DIRECT_ERROR_NONE) + { + result = wifi_direct_start_discovery(FALSE, 1000); + printf("wifi_direct_start_discovery() result=[%d]\n", result); + } + } + else + { + printf("Invalid SSID !!\n"); + } + + } + 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_WPA: + if (ad != NULL) + { + char new_wpa[64+1] = {0,}; + printf("Input new WPA:\n"); + scanf("%s",new_wpa); + printf("New wpa: [%s]\n", new_wpa); + + if (strlen(new_wpa) > 0) + { + result = wifi_direct_set_wpa_passphrase(new_wpa); + printf("wifi_direct_set_wpa_passphrase() result=[%d]\n", result); + } + else + { + printf("Invalid WPA !!\n"); + } + } + 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) + { + result = wifi_direct_foreach_supported_wps_types(_cb_foreach_supported_wps_impl, NULL); + printf("wifi_direct_foreach_supported_wps_types() result=[%d]\n", result); + } + break; + + case CMD_SET_CURRENT_WPS_MODE: + if (ad != NULL) + { + + wifi_direct_wps_type_e wps_mode; + int input; + + result = wifi_direct_get_local_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_local_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_own_group_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_WFDS_DEREGISTER: + { + if (ad != NULL) + { + unsigned int service_type; + printf("Input service type:\n"); + printf("1. WIFI_DIRECT_WFDS_SERVICE_TYPE_SEEK\n"); + printf("2. WIFI_DIRECT_WFDS_SERVICE_TYPE_ADVERTISE\n"); + scanf("%d", &service_type); + if (service_type == 1) { + result = wifi_direct_deregister_wfds_service( + WIFI_DIRECT_WFDS_SERVICE_TYPE_SEEK, "org.wi-fi.wfds.print"); + printf("wifi_direct_deregister_wfds_service() result=[%d]\n", result); + result = wifi_direct_deregister_wfds_service( + WIFI_DIRECT_WFDS_SERVICE_TYPE_SEEK, "org.wi-fi.wfds.play"); + printf("wifi_direct_deregister_wfds_service() result=[%d]\n", result); + } else if (service_type == 2) { + result = wifi_direct_deregister_wfds_service( + WIFI_DIRECT_WFDS_SERVICE_TYPE_ADVERTISE, "org.wi-fi.wfds.print"); + printf("wifi_direct_deregister_wfds_service() result=[%d]\n", result); + result = wifi_direct_deregister_wfds_service( + WIFI_DIRECT_WFDS_SERVICE_TYPE_ADVERTISE, "org.wi-fi.wfds.play"); + printf("wifi_direct_deregister_wfds_service() result=[%d]\n", result); + } else { + printf("Wrong input\n"); + } + } + } + break; + case CMD_REGISTER_LOCAL_SERVICE: + if (ad != NULL) + { + wifi_direct_service_type_e service_type; + int input; + char str[50] = {0, }; + + printf("Input service type:\n"); + printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + printf("2. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n"); + printf("3. 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_BT_ADDR; + break; + case 3 : + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + printf("Enter contact info"); + scanf("%s", str); + break; + default : + printf("ERROR : Invalid input service_type!!!\n"); + break; + } + + result = wifi_direct_register_local_service(service_type, str); + printf("wifi_direct_register_local_service() result=[%d]\n", + result); + } + break; + + case CMD_DEREGISTER_LOCAL_SERVICE: + if (ad != NULL) + { + wifi_direct_service_type_e service_type; + int input; + + printf("Input service type:\n"); + printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + printf("2. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR\n"); + scanf("%d", &input); + + switch(input) + { + case 1 : + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 3 : + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + break; + default : + printf("ERROR : Invalid input service_type!!!\n"); + break; + } + + result = wifi_direct_deregister_local_service(service_type); + printf("wifi_direct_deregister_local_service() result=[%d]\n", + result); + } + break; + + case CMD_START_SERVICE_DISCOVERY: + 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_service_type_e service_type; + int input; + + printf("Input service type:\n"); + printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + printf("2. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR unicast\n"); + printf("3. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR broadcast\n"); + printf("4. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO \n"); + scanf("%d", &input); + + switch(input) + { + case 1 : + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2 : + case 3 : + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 4 : + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + break; + default : + printf("ERROR : Invalid input service_type!!!\n"); + break; + } + + if (3 == input) { + result = wifi_direct_start_service_discovery( + NULL, service_type); + + printf ("Service Discovery... broadcast service type[%d]\n", + service_type); + } else { + 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) + { + if (select_peer(ad)) + { + int i = ad->selected_peer_index; + wifi_direct_discovered_peer_info_s* list = ad->peer_list; + wifi_direct_service_type_e service_type; + int input; + + printf("Input service type:\n"); + printf("1. WIFI_DIRECT_SERVICE_TYPE_ALL\n"); + printf("2. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR unicast\n"); + printf("3. WIFI_DIRECT_SERVICE_TYPE_BT_ADDR broadcast\n"); + printf("4. WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO\n"); + scanf("%d", &input); + + switch(input) + { + case 1 : + service_type = WIFI_DIRECT_SERVICE_TYPE_ALL; + break; + case 2 : + case 3: + service_type = WIFI_DIRECT_SERVICE_TYPE_BT_ADDR; + break; + case 4 : + service_type = WIFI_DIRECT_SERVICE_TYPE_CONTACT_INFO; + break; + default : + printf("ERROR : Invalid input service_type!!!\n"); + break; + } + + if (3 == input) { + result = wifi_direct_cancel_service_discovery( + NULL, service_type); + + printf ("Service Discovery... broadcast service type[%d]\n", + service_type); + } else { + 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->ssid, + 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_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