From: HyungKyu Song Date: Thu, 14 Feb 2013 12:43:47 +0000 (+0900) Subject: Tizen 2.0 Release X-Git-Tag: 2.0_release X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8bc5d84e024ec452e674cbfb048f04f39a3b29ce;p=framework%2Fapi%2Fwifi.git Tizen 2.0 Release --- diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..5c2063d --- /dev/null +++ b/AUTHORS @@ -0,0 +1,2 @@ +Jeik Jaehyun Kim +ByungWoo Lee diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..bfff87f --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,96 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +SET(fw_name "capi-network-wifi") + +PROJECT(${fw_name}) + +SET(CMAKE_INSTALL_PREFIX /usr) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) + +SET(INC_DIR include) +INCLUDE_DIRECTORIES(${INC_DIR}) + +SET(dependents "dlog vconf capi-base-common glib-2.0 network") +SET(pc_dependents "capi-base-common") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_name} REQUIRED ${dependents}) +FOREACH(flag ${${fw_name}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") + +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") +ADD_DEFINITIONS("-DTIZEN_DEBUG") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") + +aux_source_directory(src SOURCES) +ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) + +TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS}) + +SET_TARGET_PROPERTIES(${fw_name} + PROPERTIES + VERSION ${FULLVER} + SOVERSION ${MAJORVER} + CLEAN_DIRECT_OUTPUT 1 +) + +INSTALL(TARGETS ${fw_name} DESTINATION lib) +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 -l${fw_name}) + +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) + +ADD_SUBDIRECTORY(test) + +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) + 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/NOTICE b/NOTICE new file mode 100644 index 0000000..0e0f016 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.APLv2 file for Apache License terms and conditions. diff --git a/capi-network-wifi.manifest b/capi-network-wifi.manifest new file mode 100644 index 0000000..97e8c31 --- /dev/null +++ b/capi-network-wifi.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/capi-network-wifi.pc.in b/capi-network-wifi.pc.in new file mode 100644 index 0000000..127da21 --- /dev/null +++ b/capi-network-wifi.pc.in @@ -0,0 +1,14 @@ +# 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/capi-network-wifi-dev.install b/debian/capi-network-wifi-dev.install new file mode 100644 index 0000000..761a28b --- /dev/null +++ b/debian/capi-network-wifi-dev.install @@ -0,0 +1,4 @@ +/usr/include/* +/usr/include/*/* +/usr/lib/pkgconfig/*.pc + diff --git a/debian/capi-network-wifi.install b/debian/capi-network-wifi.install new file mode 100644 index 0000000..4a755a4 --- /dev/null +++ b/debian/capi-network-wifi.install @@ -0,0 +1 @@ +/usr/lib/lib*.so* diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..e2f591e --- /dev/null +++ b/debian/changelog @@ -0,0 +1,159 @@ +capi-network-wifi (0.1.2-14) unstable; urgency=low + + * Fix memory corruption + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-14 + + -- JaeHyun Kim Mon, 28 Jan 2013 21:04:51 +0900 + +capi-network-wifi (0.1.2-13) unstable; urgency=low + + * Set default address if there is no manual proxy to be restored + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-13 + + -- JaeHyun Kim Wed, 23 Jan 2013 12:17:18 +0900 + +capi-network-wifi (0.1.2-12) unstable; urgency=low + + * Revise wifi_ap_is_passphrase_required() to fit connman 1.3 + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-12 + + -- JaeHyun Kim Wed, 16 Jan 2013 17:15:16 +0900 + +capi-network-wifi (0.1.2-11) unstable; urgency=low + + * Use libnet-client API instead of vconf value to get Wi-Fi state in wifi_is_activated() API + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-11 + + -- JaeHyun Kim Tue, 15 Jan 2013 00:07:57 +0900 + +capi-network-wifi (0.1.2-10) unstable; urgency=low + + * Add WIFI_ERROR_SECURITY_RESTRICTED + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-10 + + -- JaeHyun Kim Fri, 04 Jan 2013 14:19:09 +0900 + +capi-network-wifi (0.1.2-9) unstable; urgency=low + + * In case of setting IP address, Gateway, Subnet and proxy, it is allowed that a value is set to NULL + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-9 + + -- JaeHyun Kim Fri, 04 Jan 2013 13:43:46 +0900 + +capi-network-wifi (0.1.2-8) unstable; urgency=low + + * Fix a bug, the api for dns setting is not work properly + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-8 + + -- JaeHyun Kim Thu, 13 Dec 2012 19:48:24 +0900 + +capi-network-wifi (0.1.2-7) unstable; urgency=low + + * Fix a bug, the list handle not reset to NULL after clearing the AP list. + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-7 + + -- Praveen C Sat, 01 Dec 2012 18:56:38 +0530 + +capi-network-wifi (0.1.2-6) unstable; urgency=low + + * Fix a bug, the setters of proxy/ip method are not work properly + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-6 + + -- JaeHyun Kim Fri, 23 Nov 2012 17:33:40 +0900 + +capi-network-wifi (0.1.2-5) unstable; urgency=low + + * Revise minor things + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-5 + + -- Danny Jeongseok Seo Tue, 13 Nov 2012 14:14:26 +0900 + +capi-network-wifi (0.1.2-4) unstable; urgency=low + + * Revise test code + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-4 + + -- JaeHyun Kim Tue, 06 Nov 2012 20:31:31 +0900 + +capi-network-wifi (0.1.2-3) unstable; urgency=low + + * Add wifi_ap_get_eap_passphrase() + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-3 + + -- JaeHyun Kim Mon, 15 Oct 2012 17:07:31 +0900 + +capi-network-wifi (0.1.2-2) unstable; urgency=low + + * Install license + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-2 + + -- Danny Jeongseok Seo Thu, 11 Oct 2012 19:06:52 +0900 + +capi-network-wifi (0.1.2-1) unstable; urgency=low + + * Extend some APIs to fit requirements from osp + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.2-1 + + -- JaeHyun Kim Thu, 27 Sep 2012 17:25:19 +0900 + +capi-network-wifi (0.1.1-4) unstable; urgency=low + + * Update manifest + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.1-4 + + -- Danny Jeongseok Seo Fri, 21 Sep 2012 15:54:22 +0900 + +capi-network-wifi (0.1.1-3) unstable; urgency=low + + * Remove unused codes from the UTC file + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.1-3 + + -- JaeHyun Kim Tue, 04 Sep 2012 16:21:28 +0900 + +capi-network-wifi (0.1.1-2) unstable; urgency=low + + * Add UTC files + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.1-2 + + -- JaeHyun Kim Wed, 04 Jul 2012 11:41:10 +0900 + +capi-network-wifi (0.1.1-1) unstable; urgency=low + + * Add AP initialization functions for user creation + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.1-1 + + -- JaeHyun Kim Mon, 02 Jul 2012 11:01:10 +0900 + +capi-network-wifi (0.1.1-0) unstable; urgency=low + + * Package implementation + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.1-0 + + -- JaeHyun Kim Mon, 21 May 2012 19:31:01 +0900 + +capi-network-wifi (0.1.0-1) unstable; urgency=low + + * Initial Upload + * Git: framework/api/wifi + * Tag: capi-network-wifi_0.1.0-1 + + -- JaeHyun Kim Mon, 09 Apr 2012 20:54:57 +0900 diff --git a/debian/compat b/debian/compat new file mode 100644 index 0000000..7f8f011 --- /dev/null +++ b/debian/compat @@ -0,0 +1 @@ +7 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..7fb1ee7 --- /dev/null +++ b/debian/control @@ -0,0 +1,21 @@ +Source: capi-network-wifi +Section: libs +Priority: extra +Maintainer: JaeHyun Kim +Build-Depends: debhelper (>= 5), dlog-dev, capi-base-common-dev, libvconf-dev, libglib2.0-dev, libdbus-glib-1-dev, libnetwork-dev + +Package: capi-network-wifi +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: Network Wi-Fi library in TIZEN C API + +Package: capi-network-wifi-dev +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-wifi (= ${Source-Version}), capi-base-common-dev +Description: Network Wi-Fi library in TIZEN C API (DEV) + +Package: capi-network-wifi-dbg +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends}, capi-network-wifi (= ${Source-Version}) +Description: Network Wi-Fi library in TIZEN C API (DBG) + diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..3ae0922 --- /dev/null +++ b/debian/rules @@ -0,0 +1,67 @@ +#!/usr/bin/make -f + +CFLAGS = -Wall -g +FULLVER ?= $(shell dpkg-parsechangelog | grep Version: | cut -d ' ' -f 2 | cut -d '-' -f 1) +MAJORVER ?= $(shell echo $(FULLVER) | cut -d '.' -f 1) + +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 .. -DFULLVER=${FULLVER} -DMAJORVER=${MAJORVER} + 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_strip --dbg-package=capi-network-wifi-dbg + dh_fixperms + dh_makeshlibs + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install configure + diff --git a/include/net_wifi_private.h b/include/net_wifi_private.h new file mode 100644 index 0000000..471b55c --- /dev/null +++ b/include/net_wifi_private.h @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + + +#ifndef __NET_CONNECTION_PRIVATE_H__ /* To prevent inclusion of a header file twice */ +#define __NET_CONNECTION_PRIVATE_H__ + +#include +#include +#include +#include "wifi.h" + +#undef LOG_TAG +#define LOG_TAG "CAPI_NETWORK_WIFI" + +#define WIFI_INFO 1 +#define WIFI_ERROR 2 +#define WIFI_WARN 3 + +#define WIFI_LOG(log_level, format, args...) \ + do { \ + switch (log_level) { \ + case WIFI_ERROR: \ + LOGE(format, ## args); \ + break; \ + case WIFI_WARN: \ + LOGW(format, ## args); \ + break; \ + default: \ + LOGI(format, ## args); \ + } \ + } while(0) + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + + +bool _wifi_libnet_init(void); +bool _wifi_libnet_deinit(void); +int _wifi_activate(wifi_activated_cb callback, void* user_data); +int _wifi_deactivate(wifi_deactivated_cb callback, void* user_data); + +bool _wifi_libnet_check_ap_validity(wifi_ap_h ap_h); +void _wifi_libnet_add_to_ap_list(wifi_ap_h ap_h); +void _wifi_libnet_remove_from_ap_list(wifi_ap_h ap_h); +bool _wifi_libnet_check_profile_name_validity(const char *profile_name); + +bool _wifi_libnet_get_wifi_device_state(wifi_device_state_e *device_state); +bool _wifi_libnet_get_wifi_state(wifi_connection_state_e* connection_state); +int _wifi_libnet_get_intf_name(char** name); +int _wifi_libnet_scan_request(wifi_scan_finished_cb callback, void* user_data); +int _wifi_libnet_get_connected_profile(wifi_ap_h *ap); +bool _wifi_libnet_foreach_found_aps(wifi_found_ap_cb callback, void *user_data); + +int _wifi_libnet_open_profile(wifi_ap_h ap_h, wifi_connected_cb callback, void* user_data); +int _wifi_libnet_close_profile(wifi_ap_h ap_h, wifi_disconnected_cb callback, void* user_data); +int _wifi_libnet_connect_with_wps(wifi_ap_h ap, wifi_connected_cb callback, void* user_data); +int _wifi_libnet_forget_ap(wifi_ap_h ap); + +int _wifi_set_power_on_off_cb(wifi_device_state_changed_cb callback, void *user_data); +int _wifi_unset_power_on_off_cb(void); +int _wifi_set_background_scan_cb(wifi_scan_finished_cb callback, void *user_data); +int _wifi_unset_background_scan_cb(void); +int _wifi_set_connection_state_cb(wifi_connection_state_changed_cb callback, void *user_data); +int _wifi_unset_connection_state_cb(); + +int _wifi_update_ap_info(net_profile_info_t *ap_info); +wifi_connection_state_e _wifi_convert_to_ap_state(net_state_type_t state); +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif diff --git a/include/wifi.h b/include/wifi.h new file mode 100644 index 0000000..1d8fc4e --- /dev/null +++ b/include/wifi.h @@ -0,0 +1,1224 @@ +/* +* Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TIZEN_NETWORK_WIFI_H__ +#define __TIZEN_NETWORK_WIFI_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @addtogroup CAPI_NETWORK_WIFI_MANAGER_MODULE +* @{ +*/ + +/** +* @brief The Wi-Fi error type +*/ +typedef enum +{ + WIFI_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + WIFI_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + WIFI_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */ + WIFI_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */ + WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED = TIZEN_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED, /**< Address family not supported */ + WIFI_ERROR_OPERATION_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0301, /**< Operation failed */ + WIFI_ERROR_NO_CONNECTION = TIZEN_ERROR_NETWORK_CLASS|0x0302, /**< There is no connected AP */ + WIFI_ERROR_NOW_IN_PROGRESS = TIZEN_ERROR_NOW_IN_PROGRESS, /** Now in progress */ + WIFI_ERROR_ALREADY_EXISTS = TIZEN_ERROR_NETWORK_CLASS|0x0303, /**< Already exists */ + WIFI_ERROR_OPERATION_ABORTED = TIZEN_ERROR_NETWORK_CLASS|0x0304, /**< Operation is aborted */ + WIFI_ERROR_DHCP_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0306, /**< DHCP failed */ + WIFI_ERROR_INVALID_KEY = TIZEN_ERROR_NETWORK_CLASS|0x0307, /**< Invalid key */ + WIFI_ERROR_NO_REPLY = TIZEN_ERROR_NETWORK_CLASS|0x0308, /**< No reply */ + WIFI_ERROR_SECURITY_RESTRICTED = TIZEN_ERROR_NETWORK_CLASS|0x0309, /**< Restricted by security system policy */ +} wifi_error_e; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_MONITOR_MODULE +* @{ +*/ + +/** +* @brief The state of Wi-Fi device +*/ +typedef enum +{ + WIFI_DEVICE_STATE_DEACTIVATED = 0, /**< Wi-Fi is Deactivated */ + WIFI_DEVICE_STATE_ACTIVATED = 1, /**< Wi-Fi is activated */ +} wifi_device_state_e; + +/** +* @brief The state of Wi-Fi connection +*/ +typedef enum +{ + WIFI_CONNECTION_STATE_DISCONNECTED = 0, /**< Disconnected state */ + WIFI_CONNECTION_STATE_ASSOCIATION = 1, /**< Association state */ + WIFI_CONNECTION_STATE_CONFIGURATION = 2, /**< Configuration state */ + WIFI_CONNECTION_STATE_CONNECTED = 3, /**< Connected state */ +} wifi_connection_state_e; + +/** +* @brief The RSSI level +*/ +typedef enum +{ + WIFI_RSSI_LEVEL_0 = 0, /**< level 0 */ + WIFI_RSSI_LEVEL_1 = 1, /**< level 1 */ + WIFI_RSSI_LEVEL_2 = 2, /**< level 2 */ + WIFI_RSSI_LEVEL_3 = 3, /**< level 3 */ + WIFI_RSSI_LEVEL_4 = 4, /**< level 4 */ +} wifi_rssi_level_e; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_NETWORK_MODULE +* @{ +*/ + +/** +* @brief Net IP configuration Type +*/ +typedef enum +{ + WIFI_IP_CONFIG_TYPE_NONE = 0, /**< Not defined */ + WIFI_IP_CONFIG_TYPE_STATIC = 1, /**< Manual IP configuration */ + WIFI_IP_CONFIG_TYPE_DYNAMIC = 2, /**< Config IP using DHCP client*/ + WIFI_IP_CONFIG_TYPE_AUTO = 3, /**< Config IP from Auto IP pool (169.254/16). Later with DHCP client, if available */ + WIFI_IP_CONFIG_TYPE_FIXED = 4, /**< Indicates an IP address that can not be modified */ +} wifi_ip_config_type_e; + +/** +* @brief Address type +*/ +typedef enum +{ + WIFI_ADDRESS_FAMILY_IPV4 = 0, /**< IPV4 Address family */ + WIFI_ADDRESS_FAMILY_IPV6 = 1, /**< IPV6 Address family */ +} wifi_address_family_e; + +/** +* @brief This enumeration defines the proxy method type. +*/ +typedef enum +{ + WIFI_PROXY_TYPE_DIRECT = 0, /**< Direct connection */ + WIFI_PROXY_TYPE_AUTO = 1, /**< Auto configuration(Use PAC file). If URL property is not set, DHCP/WPAD auto-discover will be tried */ + WIFI_PROXY_TYPE_MANUAL = 2 /**< Manual configuration */ +} wifi_proxy_type_e; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_SECURITY_MODULE +* @{ +*/ + +/** +* @brief Below security modes are used in infrastructure and ad-hoc mode +* For now all EAP security mechanisms are provided only in infrastructure mode +*/ +typedef enum +{ + WIFI_SECURITY_TYPE_NONE = 0, /**< Security disabled */ + WIFI_SECURITY_TYPE_WEP = 1, /**< WEP */ + WIFI_SECURITY_TYPE_WPA_PSK = 2, /**< WPA-PSK */ + WIFI_SECURITY_TYPE_WPA2_PSK = 3, /**< WPA2-PSK */ + WIFI_SECURITY_TYPE_EAP = 4, /**< EAP */ +} wifi_security_type_e; + +/** +* @brief Below encryption modes are used in infrastructure and ad-hoc mode +*/ +typedef enum +{ + WIFI_ENCRYPTION_TYPE_NONE = 0, /**< Encryption disabled */ + WIFI_ENCRYPTION_TYPE_WEP = 1, /**< WEP */ + WIFI_ENCRYPTION_TYPE_TKIP = 2, /**< TKIP */ + WIFI_ENCRYPTION_TYPE_AES = 3, /**< AES */ + WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED = 4, /**< TKIP and AES are both supported */ +} wifi_encryption_type_e; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_SECURITY_EAP_MODULE +* @{ +*/ + +/** +* @brief EAP type +*/ +typedef enum +{ + WIFI_EAP_TYPE_PEAP = 0, /**< EAP PEAP type */ + WIFI_EAP_TYPE_TLS = 1, /**< EAP TLS type */ + WIFI_EAP_TYPE_TTLS = 2, /**< EAP TTLS type */ + WIFI_EAP_TYPE_SIM = 3, /**< EAP SIM type */ + WIFI_EAP_TYPE_AKA = 4, /**< EAP AKA type */ +} wifi_eap_type_e; + +/** +* @brief EAP phase2 authentication type +*/ +typedef enum +{ + WIFI_EAP_AUTH_TYPE_NONE = 0, /**< EAP phase2 authentication none */ + WIFI_EAP_AUTH_TYPE_PAP = 1, /**< EAP phase2 authentication PAP */ + WIFI_EAP_AUTH_TYPE_MSCHAP = 2, /**< EAP phase2 authentication MSCHAP */ + WIFI_EAP_AUTH_TYPE_MSCHAPV2 = 3, /**< EAP phase2 authentication MSCHAPv2 */ + WIFI_EAP_AUTH_TYPE_GTC = 4, /**< EAP phase2 authentication GTC */ + WIFI_EAP_AUTH_TYPE_MD5 = 5, /**< EAP phase2 authentication MD5 */ +} wifi_eap_auth_type_e; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_MODULE +* @{ +*/ + +/** +* @brief The handle for Wi-Fi access point. +*/ +typedef void* wifi_ap_h; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_MANAGER_MODULE +* @{ +*/ + +/** +* @brief Called when you get the found access point repeatedly. +* @remarks @a ap is valid only in this function. In order to use the ap outside this function, you must copy the ap with wifi_ap_clone(). +* @param[in] ap The access point +* @param[in] user_data The user data passed from the request function +* @return @c true to continue with the next iteration of the loop, \n @c false to break out of the loop +* @pre wifi_foreach_found_aps() will invoke this callback. +* @see wifi_foreach_found_aps() +*/ +typedef bool(*wifi_found_ap_cb)(wifi_ap_h ap, void* user_data); + +/** +* @brief Called when the scan is finished. +* @param[in] error_code The error code +* @param[in] user_data The user data passed from the callback registration function +* @see wifi_scan() +* @see wifi_set_background_scan_cb() +* @see wifi_unset_background_scan_cb() +*/ +typedef void(*wifi_scan_finished_cb)(wifi_error_e error_code, void* user_data); + +/** +* @brief Called after wifi_activate() is completed. +* @param[in] result The result +* @param[in] user_data The user data passed from wifi_activate() +* @pre wifi_activate() will invoke this callback function. +* @see wifi_activate() +*/ +typedef void(*wifi_activated_cb)(wifi_error_e result, void* user_data); + +/** +* @brief Called after wifi_deactivate() is completed. +* @param[in] result The result +* @param[in] user_data The user data passed from wifi_deactivate() +* @pre wifi_deactivate() will invoke this callback function. +* @see wifi_deactivate() +*/ +typedef void(*wifi_deactivated_cb)(wifi_error_e result, void* user_data); + +/** +* @brief Called after either wifi_connect() or wifi_connect_by_wps_pbc() are completed. +* @param[in] result The result +* @param[in] user_data The user data passed from either wifi_connect() or wifi_connect_by_wps_pbc() +* @pre Either wifi_connect() or wifi_connect_by_wps_pbc() will invoke this callback function. +* @see wifi_connect() +* @see wifi_connect_by_wps_pbc() +*/ +typedef void(*wifi_connected_cb)(wifi_error_e result, void* user_data); + +/** +* @brief Called after wifi_disconnect() is completed. +* @param[in] result The result +* @param[in] user_data The user data passed from wifi_disconnect() +* @pre wifi_disconnect() will invoke this callback function. +* @see wifi_disconnect() +*/ +typedef void(*wifi_disconnected_cb)(wifi_error_e result, void* user_data); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_MONITOR_MODULE +* @{ +*/ + +/** +* @brief Called when the device state is changed. +* @param[in] state The device state +* @param[in] user_data The user data passed from the callback registration function +* @see wifi_set_device_state_changed_cb() +* @see wifi_unset_device_state_changed_cb() +*/ +typedef void(*wifi_device_state_changed_cb)(wifi_device_state_e state, void* user_data); + +/** +* @brief Called when the connection state is changed. +* @param[in] state The connection state +* @param[in] ap The access point +* @param[in] user_data The user data passed from the callback registration function +* @see wifi_set_connection_state_changed_cb() +* @see wifi_unset_connection_state_changed_cb() +*/ +typedef void(*wifi_connection_state_changed_cb)(wifi_connection_state_e state, wifi_ap_h ap, void* user_data); + +/** +* @brief Called when the RSSI of connected Wi-Fi changed. +* @param[in] rssi_level The level of RSSI +* @param[in] user_data The user data passed from the callback registration function +* @see wifi_set_rssi_level_changed_cb() +* @see wifi_unset_rssi_level_changed_cb() +*/ +typedef void(*wifi_rssi_level_changed_cb)(wifi_rssi_level_e rssi_level, void* user_data); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_MODULE +* @{ +*/ + +/** +* @brief Initializes Wi-Fi +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_initialize(void); + +/** +* @brief Deinitializes Wi-Fi +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_deinitialize(void); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_MANAGER_MODULE +* @{ +*/ + +/** +* @brief Activates Wi-Fi, asynchronously. +* @param[in] callback The callback function to be called. This can be NULL if you don't want to get the notification. +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_SECURITY_RESTRICTED Restricted by security system policy +* @post wifi_activated_cb() will be invoked +* @see wifi_activated_cb() +* @see wifi_deactivate() +*/ +int wifi_activate(wifi_activated_cb callback, void* user_data); + +/** +* @brief Deactivates Wi-Fi, asynchronously. +* @param[in] callback The callback function to be called. This can be NULL if you don't want to get the notification. +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @post wifi_deactivated_cb() will be invoked +* @see wifi_deactivated_cb() +* @see wifi_activate() +*/ +int wifi_deactivate(wifi_deactivated_cb callback, void* user_data); + +/** +* @brief Check whether Wi-Fi is activated. +* @param[out] activated Indicates whether wifi is activated or not +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_is_activated(bool* activated); + +/** +* @brief Gets the local MAC address. +* @remarks @a mac_address must be released with free() by you. +* @param[out] mac_address The mac address +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_get_mac_address(char** mac_address); + +/** +* @brief Gets the name of network interface. +* @remarks @a name must be released with free() by you. +* @param[out] name The name of network interface +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_get_network_interface_name(char** name); + +/** +* @brief Starts scan, asynchronously. +* @param[in] callback The callback function to be called +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @post This function invokes wifi_scan_finished_cb(). +*/ +int wifi_scan(wifi_scan_finished_cb callback, void* user_data); + +/** +* @brief Gets the handle of connected access point. +* @remarks @a handle must be released with wifi_ap_destroy(). +* @param[out] ap The handle of access point +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_NO_CONNECTION There is no connected AP +*/ +int wifi_get_connected_ap(wifi_ap_h* ap); + +/** +* @brief Gets the result of scan. +* @param[in] callback The callback to be called +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @post This function invokes wifi_found_ap_cb(). +*/ +int wifi_foreach_found_aps(wifi_found_ap_cb callback, void* user_data); + +/** +* @brief Connects the access point, asynchronously. +* @param[in] ap The handle of access point +* @param[in] callback The callback function to be called. This can be NULL if you don't want to get the notification. +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @post This function invokes wifi_connected_cb(). +* @see wifi_connected_cb() +* @see wifi_connect_by_wps_pbc() +* @see wifi_disconnect() +*/ +int wifi_connect(wifi_ap_h ap, wifi_connected_cb callback, void* user_data); + +/** +* @brief Disconnects the access point, asynchronously. +* @param[in] ap The handle of access point +* @param[in] callback The callback function to be called. This can be NULL if you don't want to get the notification. +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @post This function invokes wifi_disconnected_cb(). +* @see wifi_disconnected_cb() +* @see wifi_connect_by_wps_pbc() +* @see wifi_connect() +*/ +int wifi_disconnect(wifi_ap_h ap, wifi_disconnected_cb callback, void* user_data); + +/** +* @brief Connects the access point with WPS PBC, asynchronously. +* @param[in] ap The handle of access point +* @param[in] callback The callback function to be called. This can be NULL if you don't want to get the notification. +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @post This function invokes wifi_connected_cb(). +* @see wifi_connected_cb() +* @see wifi_connect() +* @see wifi_disconnect() +* @see wifi_ap_is_wps_supported() +*/ +int wifi_connect_by_wps_pbc(wifi_ap_h ap, wifi_connected_cb callback, void* user_data); + +/** +* @brief Deletes the information of stored access point. +* @details If an AP is connected, then connection information will be stored. +* This information is used when a connection to that AP is established automatically. +* @param[in] ap The handle of access point +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_forget_ap(wifi_ap_h ap); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_MONITOR_MODULE +* @{ +*/ + +/** +* @brief Gets connection state +* @param[out] connection_state The connection state +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_get_connection_state(wifi_connection_state_e* connection_state); + +/** +* @brief Registers the callback called when the device state is changed. +* @param[in] callback The callback function to be called +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int wifi_set_device_state_changed_cb(wifi_device_state_changed_cb callback, void* user_data); + +/** +* @brief Unregisters the callback called when the device state is changed. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_unset_device_state_changed_cb(void); + +/** +* @brief Registers the callback called when the background scan is finished periodically. +* @param[in] callback The callback function to be called +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int wifi_set_background_scan_cb(wifi_scan_finished_cb callback, void* user_data); + +/** +* @brief Unregisters the callback called when the scan is finished periodically. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_unset_background_scan_cb(void); + +/** +* @brief Registers the callback called when the connection state is changed. +* @param[in] callback The callback function to be called +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int wifi_set_connection_state_changed_cb(wifi_connection_state_changed_cb callback, void* user_data); + +/** +* @brief Unregisters the callback called when the connection state is changed. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_unset_connection_state_changed_cb(void); + +/** +* @brief Registers callback called when the RSSI of connected Wi-Fi changed. +* @param[in] callback The callback function to be called +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int wifi_set_rssi_level_changed_cb(wifi_rssi_level_changed_cb callback, void* user_data); + +/** +* @brief Unregisters callback called when the RSSI of connected Wi-Fi changed. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_unset_rssi_level_changed_cb(void); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_MODULE +* @{ +*/ + +/** +* @brief Creates the handle of access point. +* @remarks @a ap must be released with wifi_ap_destroy(). +* @param[in] essid The ESSID(Extended Service Set Identifier) +* @param[out] ap The handle of access point +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @see wifi_ap_destroy() +*/ +int wifi_ap_create(const char* essid, wifi_ap_h* ap); + +/** +* @brief Destroys the handle of access point. +* @param[in] ap The handle of access point +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @see wifi_ap_create() +*/ +int wifi_ap_destroy(wifi_ap_h ap); + +/** +* @brief Clons the handle of access point. +* @remarks @a cloned_ap must be released with wifi_ap_destroy(). +* @param[out] cloned_ap The handle of cloned access point +* @param[in] origin The handle of origin access point +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @see wifi_ap_destroy() +*/ +int wifi_ap_clone(wifi_ap_h* cloned_ap, wifi_ap_h origin); + +/** +* @brief Refresh the information of access point. +* @remarks You should call this function in order to get the current information because the information of access point can be changed. +* @param[in] ap The handle of access point +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +*/ +int wifi_ap_refresh(wifi_ap_h ap); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_NETWORK_MODULE +* @{ +*/ + +/** +* @brief Gets ESSID(Extended Service Set Identifier). +* @remarks @a essid must be released with free() by you. +* @param[in] ap The handle of access point +* @param[out] essid The ESSID +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +*/ +int wifi_ap_get_essid(wifi_ap_h ap, char** essid); + +/** +* @brief Gets BSSID(Basic Service Set Identifier). +* @remarks @a bssid must be released with free() by you. +* @param[in] ap The handle of access point +* @param[out] bssid The BSSID +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +*/ +int wifi_ap_get_bssid(wifi_ap_h ap, char** bssid); + +/** +* @brief Gets the RSSI. +* @param[in] ap The handle of access point +* @param[out] rssi The RSSI +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_rssi(wifi_ap_h ap, int* rssi); + +/** +* @brief Gets the Frequency band (MHz). +* @param[in] ap The handle of access point +* @param[out] frequency The frequency +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_frequency(wifi_ap_h ap, int* frequency); + +/** +* @brief Gets the max speed (Mbps). +* @param[in] ap The handle of access point +* @param[out] max_speed The max speed +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_max_speed(wifi_ap_h ap, int* max_speed); + +/** +* @brief Indicates whether the access point is favorite or not. +* @param[in] ap The handle of access point +* @param[out] favourite Indicates whether access point is favorite or not. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_is_favorite(wifi_ap_h ap, bool* favorite); + +/** +* @brief Gets the connection state. +* @param[in] ap The handle of access point +* @param[out] state The connection state +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_connection_state(wifi_ap_h ap, wifi_connection_state_e* state); + +/** +* @brief Gets the config type of IP. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[out] type The type of IP config +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_get_ip_config_type(wifi_ap_h ap, wifi_address_family_e address_family, wifi_ip_config_type_e* type); + +/** +* @brief Sets the config type of IP. +* @details If you set IP config type to #WIFI_IP_CONFIG_TYPE_STATIC, +* then IP address, Gateway and Subnet mask will be set to the initial value "0.0.0.0". +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[in] type The type of IP config +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_set_ip_config_type(wifi_ap_h ap, wifi_address_family_e address_family, wifi_ip_config_type_e type); + +/** +* @brief Gets the IP address. +* @remarks @a ip_address must be released with free() by you. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[out] ip_address The IP address +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_get_ip_address(wifi_ap_h ap, wifi_address_family_e address_family, char** ip_address); + +/** +* @brief Sets the IP address. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[in] ip_address The IP address. If you set this value to NULL, then the existing value will be deleted. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_set_ip_address(wifi_ap_h ap, wifi_address_family_e address_family, const char* ip_address); + +/** +* @brief Gets the subnet mask. +* @remarks @a subnet_mask must be released with free() by you. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[out] subnet_mask The subnet mask +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_get_subnet_mask(wifi_ap_h ap, wifi_address_family_e address_family, char** subnet_mask); + +/** +* @brief Sets the subnet mask. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[in] subnet_mask The subnet mask. If you set this value to NULL, then the existing value will be deleted. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_set_subnet_mask(wifi_ap_h ap, wifi_address_family_e address_family, const char* subnet_mask); + +/** +* @brief Gets the gateway address. +* @remarks @a gateway_address must be released with free() by you. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[out] gateway_address The gateway address +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_get_gateway_address(wifi_ap_h ap, wifi_address_family_e address_family, char** gateway_address); + +/** +* @brief Sets the gateway address. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[in] gateway_address The gateway address. If you set this value to NULL, then the existing value will be deleted. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_set_gateway_address(wifi_ap_h ap, wifi_address_family_e address_family, const char* gateway_address); + +/** +* @brief Gets the proxy address. +* @remarks @a proxy_address must be released with free() by you. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[out] proxy_address The proxy address +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_get_proxy_address(wifi_ap_h ap, wifi_address_family_e address_family, char** proxy_address); + +/** +* @brief Sets the proxy address. +* @param[in] ap The handle of access point +* @param[in] address_family The address family +* @param[in] proxy_address The proxy address. If you set this value to NULL, then the existing value will be deleted. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_set_proxy_address(wifi_ap_h ap, wifi_address_family_e address_family, const char* proxy_address); + +/** +* @brief Gets the Proxy type. +* @param[in] ap The handle of access point +* @param[out] type The type of proxy +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_proxy_type(wifi_ap_h ap, wifi_proxy_type_e* type); + +/** +* @brief Sets the Proxy address. +* @details If you set Proxy type to #WIFI_PROXY_TYPE_AUTO or #WIFI_PROXY_TYPE_MANUAL, then Proxy will be restored. +* @param[in] ap The handle of access point +* @param[in] type The type of proxy +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_set_proxy_type(wifi_ap_h ap, wifi_proxy_type_e proxy_type); + +/** +* @brief Gets the DNS address. +* @remarks The allowance of DNS address is 2. @a dns_address must be released with free() by you. +* @param[in] ap The handle of access point +* @param[in] order The order of DNS address. It starts from 1, which means first DNS address. +* @param[in] address_family The address family +* @param[out] dns_address The DNS address +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_get_dns_address(wifi_ap_h ap, int order, wifi_address_family_e address_family, char** dns_address); + +/** +* @brief Sets the DNS address. +* @remarks The allowance of DNS address is 2. +* @param[in] ap The handle of access point +* @param[in] order The order of DNS address. It starts from 1, which means first DNS address. +* @param[in] address_family The address family +* @param[in] dns_address The DNS address. If you set this value to NULL, then the existing value will be deleted. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @retval #WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Address family not supported +*/ +int wifi_ap_set_dns_address(wifi_ap_h ap, int order, wifi_address_family_e address_family, const char* dns_address); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_SECURITY_MODULE +* @{ +*/ + +/** +* @brief Gets the security mode of Wi-Fi. +* @param[in] ap The handle of access point +* @param[out] type The type of Wi-Fi security +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_security_type(wifi_ap_h ap, wifi_security_type_e* type); + +/** +* @brief Sets the security mode of Wi-Fi. +* @param[in] ap The handle of access point +* @param[in] type The type of Wi-Fi security +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_set_security_type(wifi_ap_h ap, wifi_security_type_e type); + +/** +* @brief Gets the encryption type of Wi-Fi. +* @param[in] ap The handle of access point +* @param[out] type The type of Wi-Fi encryption +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_encryption_type(wifi_ap_h ap, wifi_encryption_type_e* type); + +/** +* @brief Sets the encryption type of Wi-Fi. +* @param[in] ap The handle of access point +* @param[in] type The type of Wi-Fi encryption +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_set_encryption_type(wifi_ap_h ap, wifi_encryption_type_e type); + +/** +* @brief Indicates whether the passphrase is required or not. +* @remarks This function is not valid if security type is #WIFI_SECURITY_TYPE_EAP. +* @param[in] ap The handle of access point +* @param[out] required Indicates whether passphrase is required or not +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_is_passphrase_required(wifi_ap_h ap, bool* required); + +/** +* @brief Sets the passphrase. +* @param[in] ap The handle of access point +* @param[in] passphrase The passphrase of access point +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_set_passphrase(wifi_ap_h ap, const char* passphrase); + +/** +* @brief Indicates whether the WPS(Wi-Fi Protected Setup) is supported or not. +* @param[in] ap The handle of access point +* @param[out] supported Indicates whether WPS is supported or not +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +* @see wifi_connect_by_wps_pbc() +*/ +int wifi_ap_is_wps_supported(wifi_ap_h ap, bool* supported); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_WIFI_AP_SECURITY_EAP_MODULE +* @{ +*/ + +/** +* @brief Sets the passphrase of EAP. +* @details You can set one of @a user_name and @a password as NULL. +* In this case, the value of a parameter which is set as NULL will be the previous value. +* But it is not allowed that both @a user_name and @a password are set as NULL. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_PEAP or #WIFI_EAP_TYPE_TTLS. +* @param[in] ap The handle of access point +* @param[in] user_name The user name. This value can be NULL. +* @param[in] password The password. This value can be NULL. +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_set_eap_passphrase(wifi_ap_h ap, const char* user_name, const char* password); + +/** +* @brief Gets the passphrase of EAP. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_PEAP or #WIFI_EAP_TYPE_TTLS. +* @a user_name must be released with free() by you. +* @param[in] ap The handle of access point +* @param[out] user_name The user name +* @param[out] password Indicates whether password is set or not (@c true = set, @c false = not set) +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_get_eap_passphrase(wifi_ap_h ap, char** user_name, bool* is_password_set); + +/** +* @brief Gets the CA Certificate of EAP. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_TLS. +* @a file must be released with free() by you. +* @param[in] ap The handle of access point +* @param[out] file The file path of CA Certificate +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_get_eap_ca_cert_file(wifi_ap_h ap, char** file); + +/** +* @brief Sets the CA Certificate of EAP. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_TLS. +* @param[in] ap The handle of access point +* @param[in] file The file path of CA Certificate +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_set_eap_ca_cert_file(wifi_ap_h ap, const char* file); + +/** +* @brief Gets the Client Certificate of EAP. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_TLS. +* @a file must be released with free() by you. +* @param[in] ap The handle of access point +* @param[out] file The file path of Client Certificate +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_get_eap_client_cert_file(wifi_ap_h ap, char** file); + +/** +* @brief Sets the CA Certificate of EAP. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_TLS. +* @param[in] ap The handle of access point +* @param[in] file The file path of Client Certificate +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_set_eap_client_cert_file(wifi_ap_h ap, const char* file); + +/** +* @brief Gets the private key file of EAP. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_TLS. +* @a file must be released with free() by you. +* @param[in] ap The handle of access point +* @param[out] file The file path of private key +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_OUT_OF_MEMORY Out of memory +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_get_eap_private_key_file(wifi_ap_h ap, char** file); + +/** +* @brief Sets the private key information of EAP. +* @remarks This function is valid only if the EAP type is #WIFI_EAP_TYPE_TLS. +* @param[in] ap The handle of access point +* @param[in] file The file path of private key +* @param[in] password The password +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_set_eap_private_key_info(wifi_ap_h ap, const char* file, const char* password); + +/** +* @brief Gets the EAP type of Wi-Fi. +* @param[in] ap The handle of access point +* @param[out] type The type of EAP +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_eap_type(wifi_ap_h ap, wifi_eap_type_e* type); + +/** +* @brief Sets the EAP type of Wi-Fi. +* @param[in] ap The handle of access point +* @param[in] type The type of EAP +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_set_eap_type(wifi_ap_h ap, wifi_eap_type_e type); + +/** +* @brief Gets the type of EAP phase2 authentication of Wi-Fi. +* @param[in] ap The handle of access point +* @param[out] type The type of EAP phase2 authentication +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +* @retval #WIFI_ERROR_OPERATION_FAILED Operation failed +*/ +int wifi_ap_get_eap_auth_type(wifi_ap_h ap, wifi_eap_auth_type_e* type); + +/** +* @brief Sets the type of EAP phase2 authentication of Wi-Fi. +* @param[in] ap The handle of access point +* @param[in] type The type of EAP phase2 authentication +* @return 0 on success, otherwise negative error value. +* @retval #WIFI_ERROR_NONE Successful +* @retval #WIFI_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #WIFI_ERROR_INVALID_OPERATION Invalid operation +*/ +int wifi_ap_set_eap_auth_type(wifi_ap_h ap, wifi_eap_auth_type_e type); + +/** +* @} +*/ + + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_NETWORK_WIFI_H__ */ diff --git a/packaging/capi-network-wifi.spec b/packaging/capi-network-wifi.spec new file mode 100644 index 0000000..6b3b94e --- /dev/null +++ b/packaging/capi-network-wifi.spec @@ -0,0 +1,59 @@ +Name: capi-network-wifi +Summary: Network Wi-Fi library in TIZEN C API +Version: 0.1.2_14 +Release: 1 +Group: System/Network +License: Apache License Version 2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(network) +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig + +%description +Network Wi-Fi library in Tizen C API + +%package devel +Summary: Network Wi-Fi library in Tizen C API (Development) +Group: System/Network +Requires: %{name} = %{version}-%{release} + +%description devel +Network Wi-Fi library in Tizen C API (Development) + +%prep +%setup -q + + +%build +MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` +cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} + +make %{?_smp_mflags} + + +%install +%make_install + +#License +mkdir -p %{buildroot}%{_datadir}/license +cp LICENSE.APLv2 %{buildroot}%{_datadir}/license/capi-network-wifi + +%post -p /sbin/ldconfig + +%postun -p /sbin/ldconfig + + +%files +%manifest capi-network-wifi.manifest +%attr(644,-,-) %{_libdir}/libcapi-network-wifi.so.* +%{_datadir}/license/capi-network-wifi + +%files devel +%{_includedir}/network/*.h +%{_libdir}/pkgconfig/*.pc +%{_libdir}/libcapi-network-wifi.so diff --git a/src/libnetwork.c b/src/libnetwork.c new file mode 100755 index 0000000..e72b58f --- /dev/null +++ b/src/libnetwork.c @@ -0,0 +1,834 @@ +/* + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "net_wifi_private.h" + +static GSList *ap_handle_list = NULL; + +struct _wifi_cb_s { + wifi_device_state_changed_cb device_state_cb; + void *device_state_user_data; + wifi_scan_finished_cb bg_scan_cb; + void *bg_scan_user_data; + wifi_scan_finished_cb scan_request_cb; + void *scan_request_user_data; + wifi_connection_state_changed_cb connection_state_cb; + void *connection_state_user_data; + wifi_activated_cb activated_cb; + void *activated_user_data; + wifi_deactivated_cb deactivated_cb; + void *deactivated_user_data; + wifi_connected_cb connected_cb; + void *connected_user_data; + wifi_disconnected_cb disconnected_cb; + void *disconnected_user_data; +}; + +struct _profile_list_s { + int count; + net_profile_info_t *profiles; +}; + +static struct _wifi_cb_s wifi_callbacks = {0,}; +static struct _profile_list_s profile_iterator = {0, NULL}; + + +static wifi_error_e __libnet_convert_to_ap_error_type(net_err_t err_type) +{ + switch (err_type) { + case NET_ERR_NONE: + return WIFI_ERROR_NONE; + case NET_ERR_APP_ALREADY_REGISTERED: + return WIFI_ERROR_INVALID_OPERATION; + case NET_ERR_APP_NOT_REGISTERED: + return WIFI_ERROR_INVALID_OPERATION; + case NET_ERR_NO_ACTIVE_CONNECTIONS: + return WIFI_ERROR_NO_CONNECTION; + case NET_ERR_ACTIVE_CONNECTION_EXISTS: + return WIFI_ERROR_ALREADY_EXISTS; + case NET_ERR_CONNECTION_DHCP_FAILED: + return WIFI_ERROR_DHCP_FAILED; + case NET_ERR_CONNECTION_INVALID_KEY: + return WIFI_ERROR_INVALID_KEY; + case NET_ERR_IN_PROGRESS: + return WIFI_ERROR_NOW_IN_PROGRESS; + case NET_ERR_OPERATION_ABORTED: + return WIFI_ERROR_OPERATION_ABORTED; + case NET_ERR_TIME_OUT: + return WIFI_ERROR_NO_REPLY; + default: + return WIFI_ERROR_OPERATION_FAILED; + } +} + +static const char *__libnet_convert_ap_error_type_to_string(wifi_error_e err_type) +{ + switch (err_type) { + case WIFI_ERROR_NONE: + return "NONE"; + case WIFI_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case WIFI_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case WIFI_ERROR_INVALID_OPERATION: + return "INVALID_OPERATION"; + case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: + return "ADDRESS_FAMILY_NOT_SUPPORTED"; + case WIFI_ERROR_OPERATION_FAILED: + return "OPERATION_FAILED"; + case WIFI_ERROR_NO_CONNECTION: + return "NO_CONNECTION"; + case WIFI_ERROR_NOW_IN_PROGRESS: + return "NOW_IN_PROGRESS"; + case WIFI_ERROR_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case WIFI_ERROR_OPERATION_ABORTED: + return "OPERATION_ABORTED"; + case WIFI_ERROR_DHCP_FAILED: + return "DHCP_FAILED"; + case WIFI_ERROR_INVALID_KEY: + return "INVALID_KEY"; + case WIFI_ERROR_NO_REPLY: + return "NO_REPLY"; + case WIFI_ERROR_SECURITY_RESTRICTED: + return "SECURITY_RESTRICTED"; + } + + return "UNKNOWN"; +} + +static const char *__libnet_convert_ap_state_to_string(wifi_connection_state_e state) +{ + switch (state) { + case WIFI_CONNECTION_STATE_DISCONNECTED: + return "DISCONNECTED"; + case WIFI_CONNECTION_STATE_ASSOCIATION: + return "ASSOCIATION"; + case WIFI_CONNECTION_STATE_CONFIGURATION: + return "CONFIGURATION"; + case WIFI_CONNECTION_STATE_CONNECTED: + return "CONNECTED"; + default: + return "UNKNOWN"; + } +} + +static void __libnet_clear_profile_list(struct _profile_list_s *profile_list) +{ + if (profile_list->count > 0) + g_free(profile_list->profiles); + + profile_list->count = 0; + profile_list->profiles = NULL; +} + +static void __libnet_update_profile_iterator(void) +{ + struct _profile_list_s wifi_profiles = {0, NULL}; + + __libnet_clear_profile_list(&profile_iterator); + + net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count); + WIFI_LOG(WIFI_INFO, "Wifi profile count : %d\n", wifi_profiles.count); + + if (wifi_profiles.count == 0) + return; + + profile_iterator.count = wifi_profiles.count; + profile_iterator.profiles = wifi_profiles.profiles; +} + +static void __libnet_convert_profile_info_to_wifi_info(net_wifi_connection_info_t *wifi_info, + net_profile_info_t *ap_info) +{ + g_strlcpy(wifi_info->essid, ap_info->ProfileInfo.Wlan.essid, NET_WLAN_ESSID_LEN+1); + wifi_info->wlan_mode = ap_info->ProfileInfo.Wlan.wlan_mode; + memcpy(&wifi_info->security_info, &ap_info->ProfileInfo.Wlan.security_info, sizeof(wlan_security_info_t)); +} + +static int __libnet_connect_with_wifi_info(net_profile_info_t *ap_info) +{ + net_wifi_connection_info_t wifi_info; + memset(&wifi_info, 0, sizeof(net_wifi_connection_info_t)); + + __libnet_convert_profile_info_to_wifi_info(&wifi_info, ap_info); + + if (net_open_connection_with_wifi_info(&wifi_info) != NET_ERR_NONE) + return WIFI_ERROR_OPERATION_FAILED; + + return WIFI_ERROR_NONE; +} + +static void __libnet_state_changed_cb(char *profile_name, net_profile_info_t *profile_info, + wifi_connection_state_e state) +{ + if (profile_name == NULL) + return; + + if (profile_info == NULL) { + WIFI_LOG(WIFI_ERROR, "Error!! Profile info not found! : %s\n", profile_name); + return; + } + + ap_handle_list = g_slist_append(ap_handle_list, (wifi_ap_h)profile_info); + + if (wifi_callbacks.connection_state_cb) + wifi_callbacks.connection_state_cb(state, (wifi_ap_h)profile_info, + wifi_callbacks.connection_state_user_data); + + ap_handle_list = g_slist_remove(ap_handle_list, (wifi_ap_h)profile_info); +} + +static void __libnet_set_activated_cb(wifi_activated_cb user_cb, void *user_data) +{ + if (user_cb) { + wifi_callbacks.activated_cb = user_cb; + wifi_callbacks.activated_user_data = user_data; + } +} + +static void __libnet_activated_cb(wifi_error_e result) +{ + if (wifi_callbacks.activated_cb) + wifi_callbacks.activated_cb(result, wifi_callbacks.activated_user_data); + + wifi_callbacks.activated_cb = NULL; + wifi_callbacks.activated_user_data = NULL; +} + +static void __libnet_set_deactivated_cb(wifi_disconnected_cb user_cb, void *user_data) +{ + if (user_cb) { + wifi_callbacks.deactivated_cb = user_cb; + wifi_callbacks.deactivated_user_data = user_data; + } +} + +static void __libnet_deactivated_cb(wifi_error_e result) +{ + if (wifi_callbacks.deactivated_cb) + wifi_callbacks.deactivated_cb(result, wifi_callbacks.deactivated_user_data); + + wifi_callbacks.deactivated_cb = NULL; + wifi_callbacks.deactivated_user_data = NULL; +} + +static void __libnet_power_on_off_cb(net_event_info_t *event_cb, bool is_requested) +{ + if (wifi_callbacks.device_state_cb == NULL && + wifi_callbacks.activated_cb == NULL && + wifi_callbacks.deactivated_cb == NULL) + return; + + wifi_error_e error_code = WIFI_ERROR_NONE; + wifi_device_state_e state; + net_wifi_state_t *wifi_state = (net_wifi_state_t*)event_cb->Data; + + if (event_cb->Error == NET_ERR_NONE && + event_cb->Datalength == sizeof(net_wifi_state_t)) { + + if (*wifi_state == WIFI_ON) { + WIFI_LOG(WIFI_INFO, "Wi-Fi State : Power ON\n"); + state = WIFI_DEVICE_STATE_ACTIVATED; + } else if (*wifi_state == WIFI_OFF) { + WIFI_LOG(WIFI_INFO, "Wi-Fi State : Power OFF\n"); + state = WIFI_DEVICE_STATE_DEACTIVATED; + __libnet_clear_profile_list(&profile_iterator); + } else { + WIFI_LOG(WIFI_INFO, "Wi-Fi State : Unknown\n"); + error_code = WIFI_ERROR_OPERATION_FAILED; + state = WIFI_DEVICE_STATE_DEACTIVATED; + } + } else { + WIFI_LOG(WIFI_ERROR, "Wi-Fi Power on/off request failed! Error [%d]\n", event_cb->Error); + error_code = WIFI_ERROR_OPERATION_FAILED; + state = WIFI_DEVICE_STATE_DEACTIVATED; + } + + __libnet_activated_cb(error_code); + __libnet_deactivated_cb(error_code); + + if (wifi_callbacks.device_state_cb) + wifi_callbacks.device_state_cb(state, wifi_callbacks.device_state_user_data); +} + +static void __libnet_scan_cb(net_event_info_t *event_cb, bool is_requested) +{ + wifi_error_e error_code = WIFI_ERROR_NONE; + + if (event_cb->Error != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Scan failed!, Error [%d]\n", event_cb->Error); + error_code = WIFI_ERROR_OPERATION_FAILED; + } + + if (wifi_callbacks.scan_request_cb) { + wifi_callbacks.scan_request_cb(error_code, wifi_callbacks.scan_request_user_data); + wifi_callbacks.scan_request_cb = NULL; + wifi_callbacks.scan_request_user_data = NULL; + return; + } + + if (wifi_callbacks.bg_scan_cb != NULL) + wifi_callbacks.bg_scan_cb(error_code, wifi_callbacks.bg_scan_user_data); +} + +static void __libnet_set_connected_cb(wifi_connected_cb user_cb, void *user_data) +{ + if (user_cb) { + wifi_callbacks.connected_cb = user_cb; + wifi_callbacks.connected_user_data = user_data; + } +} + +static void __libnet_connected_cb(wifi_error_e result) +{ + if (wifi_callbacks.connected_cb) + wifi_callbacks.connected_cb(result, wifi_callbacks.connected_user_data); + + wifi_callbacks.connected_cb = NULL; + wifi_callbacks.connected_user_data = NULL; +} + +static void __libnet_set_disconnected_cb(wifi_disconnected_cb user_cb, void *user_data) +{ + if (user_cb) { + wifi_callbacks.disconnected_cb = user_cb; + wifi_callbacks.disconnected_user_data = user_data; + } +} + +static void __libnet_disconnected_cb(wifi_error_e result) +{ + if (wifi_callbacks.disconnected_cb) + wifi_callbacks.disconnected_cb(result, wifi_callbacks.disconnected_user_data); + + wifi_callbacks.disconnected_cb = NULL; + wifi_callbacks.disconnected_user_data = NULL; +} + +static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data) +{ + bool is_requested = false; + net_profile_info_t *prof_info_p = NULL; + net_profile_info_t prof_info; + wifi_error_e result = WIFI_ERROR_NONE; + + switch (event_cb->Event) { + case NET_EVENT_OPEN_RSP: + case NET_EVENT_WIFI_WPS_RSP: + is_requested = true; + /* fall through */ + case NET_EVENT_OPEN_IND: + if (strstr(event_cb->ProfileName, "/wifi_") == NULL) return; + + result = __libnet_convert_to_ap_error_type(event_cb->Error); + WIFI_LOG(WIFI_INFO, "Got Open RSP/IND : %s\n", + __libnet_convert_ap_error_type_to_string(result)); + + if (is_requested) + __libnet_connected_cb(result); + + switch (event_cb->Error) { + case NET_ERR_NONE: + WIFI_LOG(WIFI_INFO, "Connection open succeeded\n"); + + if (event_cb->Datalength == sizeof(net_profile_info_t)) + prof_info_p = (net_profile_info_t*)event_cb->Data; + + __libnet_state_changed_cb(event_cb->ProfileName, prof_info_p, + WIFI_CONNECTION_STATE_CONNECTED); + return; + default : + WIFI_LOG(WIFI_ERROR, "Connection open failed!\n"); + break; + } + + if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE) + __libnet_state_changed_cb(event_cb->ProfileName, &prof_info, + WIFI_CONNECTION_STATE_DISCONNECTED); + else + __libnet_state_changed_cb(event_cb->ProfileName, NULL, + WIFI_CONNECTION_STATE_DISCONNECTED); + + break; + case NET_EVENT_CLOSE_RSP: + is_requested = true; + /* fall through */ + case NET_EVENT_CLOSE_IND: + if (strstr(event_cb->ProfileName, "/wifi_") == NULL) return; + + result = __libnet_convert_to_ap_error_type(event_cb->Error); + WIFI_LOG(WIFI_INFO, "Got Close RSP/IND : %s\n", + __libnet_convert_ap_error_type_to_string(result)); + + if (is_requested) + __libnet_disconnected_cb(result); + + switch (event_cb->Error) { + case NET_ERR_NONE: + /* Successful PDP Deactivation */ + WIFI_LOG(WIFI_INFO, "Connection close succeeded!\n"); + if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE) + __libnet_state_changed_cb(event_cb->ProfileName, &prof_info, + WIFI_CONNECTION_STATE_DISCONNECTED); + else + __libnet_state_changed_cb(event_cb->ProfileName, NULL, + WIFI_CONNECTION_STATE_DISCONNECTED); + return; + default: + WIFI_LOG(WIFI_ERROR, "Connection close failed!\n"); + break; + } + + break; + case NET_EVENT_NET_STATE_IND: + if (strstr(event_cb->ProfileName, "/wifi_") == NULL) return; + + WIFI_LOG(WIFI_INFO, "Got State changed IND\n"); + + if (event_cb->Datalength != sizeof(net_state_type_t)) + return; + + net_state_type_t *profile_state = (net_state_type_t*)event_cb->Data; + wifi_connection_state_e ap_state = _wifi_convert_to_ap_state(*profile_state); + + WIFI_LOG(WIFI_INFO, + "Profile State : %s, profile name : %s\n", + __libnet_convert_ap_state_to_string(ap_state), + event_cb->ProfileName); + + if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE) + __libnet_state_changed_cb(event_cb->ProfileName, &prof_info, ap_state); + else + __libnet_state_changed_cb(event_cb->ProfileName, NULL, ap_state); + + + break; + case NET_EVENT_WIFI_SCAN_RSP: + case NET_EVENT_WIFI_SCAN_IND: + WIFI_LOG(WIFI_ERROR, "Got wifi scan IND\n"); + __libnet_scan_cb(event_cb, is_requested); + break; + case NET_EVENT_WIFI_POWER_RSP: + is_requested = true; + /* fall through */ + case NET_EVENT_WIFI_POWER_IND: + WIFI_LOG(WIFI_ERROR, "Got wifi power IND\n"); + __libnet_power_on_off_cb(event_cb, is_requested); + break; + default : + WIFI_LOG(WIFI_ERROR, "Error! Unknown Event\n\n"); + } +} + +bool _wifi_libnet_init(void) +{ + int rv; + + rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_WIFI, NULL); + if (rv != NET_ERR_NONE) + return false; + + return true; +} + +bool _wifi_libnet_deinit(void) +{ + if (net_deregister_client_ext(NET_DEVICE_WIFI) != NET_ERR_NONE) + return false; + + __libnet_clear_profile_list(&profile_iterator); + g_slist_free_full(ap_handle_list, g_free); + ap_handle_list = NULL; + memset(&wifi_callbacks, 0, sizeof(struct _wifi_cb_s)); + + return true; +} + +int _wifi_activate(wifi_activated_cb callback, void* user_data) +{ + int rv; + + rv = net_wifi_power_on(); + if (rv == NET_ERR_NONE) { + __libnet_set_activated_cb(callback, user_data); + return WIFI_ERROR_NONE; + } else if (rv == NET_ERR_INVALID_OPERATION) + return WIFI_ERROR_INVALID_OPERATION; + + return WIFI_ERROR_OPERATION_FAILED; +} + +int _wifi_deactivate(wifi_deactivated_cb callback, void* user_data) +{ + int rv; + + rv = net_wifi_power_off(); + if (rv == NET_ERR_NONE) { + __libnet_set_deactivated_cb(callback, user_data); + return WIFI_ERROR_NONE; + } else if (rv == NET_ERR_INVALID_OPERATION) + return WIFI_ERROR_INVALID_OPERATION; + + return WIFI_ERROR_OPERATION_FAILED; +} + +bool _wifi_libnet_check_ap_validity(wifi_ap_h ap_h) +{ + GSList *list; + int i = 0; + + for (list = ap_handle_list; list; list = list->next) + if (ap_h == list->data) return true; + + for (;i < profile_iterator.count;i++) + if (ap_h == &profile_iterator.profiles[i]) return true; + + return false; +} + +void _wifi_libnet_add_to_ap_list(wifi_ap_h ap_h) +{ + ap_handle_list = g_slist_append(ap_handle_list, ap_h); +} + +void _wifi_libnet_remove_from_ap_list(wifi_ap_h ap_h) +{ + ap_handle_list = g_slist_remove(ap_handle_list, ap_h); + g_free(ap_h); +} + +bool _wifi_libnet_check_profile_name_validity(const char *profile_name) +{ + const char *profile_header = "/net/connman/service/wifi_"; + int i = 0; + int string_len = 0; + + if (profile_name == NULL || strlen(profile_name) <= strlen(profile_header)) { + WIFI_LOG(WIFI_ERROR, "Error!!! Profile name is invalid\n"); + return false; + } + + string_len = strlen(profile_name); + + if (strncmp(profile_header, profile_name, strlen(profile_header)) == 0) { + for (;i < string_len;i++) { + if (isgraph(profile_name[i]) == 0) { + WIFI_LOG(WIFI_ERROR, "Error!!! Profile name is invalid\n"); + return false; + } + } + } else { + WIFI_LOG(WIFI_ERROR, "Error!!! Profile name is invalid\n"); + return false; + } + + return true; +} + +bool _wifi_libnet_get_wifi_device_state(wifi_device_state_e *device_state) +{ + net_wifi_state_t wlan_state; + net_profile_name_t profile_name; + + if (net_get_wifi_state(&wlan_state, &profile_name) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Error!! net_get_wifi_state() failed.\n"); + return false; + } + + switch (wlan_state) { + case WIFI_OFF: + *device_state = WIFI_DEVICE_STATE_DEACTIVATED; + break; + case WIFI_ON: + case WIFI_CONNECTING: + case WIFI_CONNECTED: + case WIFI_DISCONNECTING: + *device_state = WIFI_DEVICE_STATE_ACTIVATED; + break; + default : + WIFI_LOG(WIFI_ERROR, "Error!! Unknown state\n"); + return false; + } + + return true; +} + +bool _wifi_libnet_get_wifi_state(wifi_connection_state_e* connection_state) +{ + net_wifi_state_t wlan_state = 0; + net_profile_name_t profile_name; + + if (net_get_wifi_state(&wlan_state, &profile_name) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Error!! net_get_wifi_state() failed.\n"); + return false; + } + + switch (wlan_state) { + case WIFI_OFF: + case WIFI_ON: + *connection_state = WIFI_CONNECTION_STATE_DISCONNECTED; + break; + case WIFI_CONNECTING: + *connection_state = WIFI_CONNECTION_STATE_ASSOCIATION; + break; + case WIFI_CONNECTED: + *connection_state = WIFI_CONNECTION_STATE_CONNECTED; + break; + case WIFI_DISCONNECTING: + *connection_state = WIFI_CONNECTION_STATE_CONNECTED; + break; + default : + WIFI_LOG(WIFI_ERROR, "Error!! Unknown state\n"); + return false; + } + + return true; +} + +int _wifi_libnet_get_intf_name(char** name) +{ + if (profile_iterator.count == 0) + __libnet_update_profile_iterator(); + + if (profile_iterator.count == 0) { + WIFI_LOG(WIFI_ERROR, "Error!! There is no AP\n"); + return WIFI_ERROR_OPERATION_FAILED; + } + + *name = g_strdup(profile_iterator.profiles->ProfileInfo.Wlan.net_info.DevName); + if (*name == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int _wifi_libnet_scan_request(wifi_scan_finished_cb callback, void* user_data) +{ + int rv; + rv = net_scan_wifi(); + + if (rv == NET_ERR_NONE) { + wifi_callbacks.scan_request_cb = callback; + wifi_callbacks.scan_request_user_data = user_data; + return WIFI_ERROR_NONE; + } else if (rv == NET_ERR_INVALID_OPERATION) + return WIFI_ERROR_INVALID_OPERATION; + + return WIFI_ERROR_OPERATION_FAILED; +} + +int _wifi_libnet_get_connected_profile(wifi_ap_h *ap) +{ + int i = 0; + wifi_ap_h ap_h = NULL; + + __libnet_update_profile_iterator(); + + for (;i < profile_iterator.count;i++) { + if (profile_iterator.profiles[i].ProfileState == NET_STATE_TYPE_ONLINE || + profile_iterator.profiles[i].ProfileState == NET_STATE_TYPE_READY) { + ap_h = (wifi_ap_h)(&profile_iterator.profiles[i]); + break; + } + } + + if (ap_h == NULL) { + WIFI_LOG(WIFI_ERROR, "Error!! There is no connected AP.\n"); + return WIFI_ERROR_NO_CONNECTION; + } + + *ap = g_try_malloc0(sizeof(net_profile_info_t)); + if (*ap == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + memcpy(*ap, ap_h, sizeof(net_profile_info_t)); + + _wifi_libnet_add_to_ap_list(*ap); + + return WIFI_ERROR_NONE; +} + +bool _wifi_libnet_foreach_found_aps(wifi_found_ap_cb callback, void *user_data) +{ + int i = 0; + bool rv = true; + + __libnet_update_profile_iterator(); + + if (profile_iterator.count == 0) { + WIFI_LOG(WIFI_INFO, "There is no APs.\n"); + return true; + } + + for (;i < profile_iterator.count;i++) { + rv = callback((wifi_ap_h)(&profile_iterator.profiles[i]), user_data); + if (rv == false) break; + } + + return true; +} + +int _wifi_libnet_open_profile(wifi_ap_h ap_h, wifi_connected_cb callback, void* user_data) +{ + net_profile_info_t *ap_info = ap_h; + net_profile_name_t profile_name; + int rv; + + g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1); + + if (ap_info->ProfileInfo.Wlan.security_info.sec_mode == WLAN_SEC_MODE_IEEE8021X) + rv = __libnet_connect_with_wifi_info(ap_info); + else if (_wifi_libnet_check_profile_name_validity(ap_info->ProfileName) == false) + rv = __libnet_connect_with_wifi_info(ap_info); + else + rv = net_open_connection_with_profile(profile_name.ProfileName); + + if (rv != NET_ERR_NONE) + return WIFI_ERROR_OPERATION_FAILED; + + __libnet_set_connected_cb(callback, user_data); + + return WIFI_ERROR_NONE; +} + +int _wifi_libnet_close_profile(wifi_ap_h ap_h, wifi_disconnected_cb callback, void* user_data) +{ + net_profile_info_t *ap_info = ap_h; + net_profile_name_t profile_name; + + g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1); + + if (net_close_connection(profile_name.ProfileName) != NET_ERR_NONE) + return WIFI_ERROR_OPERATION_FAILED; + + __libnet_set_disconnected_cb(callback, user_data); + + return WIFI_ERROR_NONE; +} + +int _wifi_libnet_connect_with_wps(wifi_ap_h ap_h, wifi_connected_cb callback, void* user_data) +{ + net_profile_info_t *ap_info = ap_h; + net_wifi_wps_info_t wps_info; + net_profile_name_t profile_name; + + memset(&wps_info, 0 , sizeof(net_wifi_wps_info_t)); + g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1); + + wps_info.type = WIFI_WPS_PBC; + + if (net_wifi_enroll_wps(profile_name.ProfileName, &wps_info) != NET_ERR_NONE) + return WIFI_ERROR_OPERATION_FAILED; + + __libnet_set_connected_cb(callback, user_data); + + return WIFI_ERROR_NONE; +} + +int _wifi_libnet_forget_ap(wifi_ap_h ap) +{ + int rv = 0; + net_profile_name_t profile_name; + net_profile_info_t *ap_info = ap; + + g_strlcpy(profile_name.ProfileName, ap_info->ProfileName, NET_PROFILE_NAME_LEN_MAX+1); + + rv = net_delete_profile(profile_name.ProfileName); + if (rv != NET_ERR_NONE) + return WIFI_ERROR_OPERATION_FAILED; + + return WIFI_ERROR_NONE; +} + +int _wifi_set_power_on_off_cb(wifi_device_state_changed_cb callback, void *user_data) +{ + if (wifi_callbacks.device_state_cb) + return WIFI_ERROR_INVALID_OPERATION; + + wifi_callbacks.device_state_cb = callback; + wifi_callbacks.device_state_user_data = user_data; + + return WIFI_ERROR_NONE; +} + +int _wifi_unset_power_on_off_cb(void) +{ + if (wifi_callbacks.device_state_cb == NULL) + return WIFI_ERROR_INVALID_OPERATION; + + wifi_callbacks.device_state_cb = NULL; + wifi_callbacks.device_state_user_data = NULL; + + return WIFI_ERROR_NONE; +} + +int _wifi_set_background_scan_cb(wifi_scan_finished_cb callback, void *user_data) +{ + if (wifi_callbacks.bg_scan_cb) + return WIFI_ERROR_INVALID_OPERATION; + + wifi_callbacks.bg_scan_cb = callback; + wifi_callbacks.bg_scan_user_data = user_data; + + return WIFI_ERROR_NONE; +} + +int _wifi_unset_background_scan_cb(void) +{ + if (wifi_callbacks.bg_scan_cb == NULL) + return WIFI_ERROR_INVALID_OPERATION; + + wifi_callbacks.bg_scan_cb = NULL; + wifi_callbacks.bg_scan_user_data = NULL; + + return WIFI_ERROR_NONE; +} + +int _wifi_set_connection_state_cb(wifi_connection_state_changed_cb callback, void *user_data) +{ + if (wifi_callbacks.connection_state_cb) + return WIFI_ERROR_INVALID_OPERATION; + + wifi_callbacks.connection_state_cb = callback; + wifi_callbacks.connection_state_user_data = user_data; + + return WIFI_ERROR_NONE; +} + +int _wifi_unset_connection_state_cb() +{ + if (wifi_callbacks.connection_state_cb == NULL) + return WIFI_ERROR_INVALID_OPERATION; + + wifi_callbacks.connection_state_cb = NULL; + wifi_callbacks.connection_state_user_data = NULL; + + return WIFI_ERROR_NONE; +} + +int _wifi_update_ap_info(net_profile_info_t *ap_info) +{ + if (net_modify_profile(ap_info->ProfileName, ap_info) != NET_ERR_NONE) + return WIFI_ERROR_OPERATION_FAILED; + + return WIFI_ERROR_NONE; +} + diff --git a/src/net_wifi.c b/src/net_wifi.c new file mode 100755 index 0000000..bc31219 --- /dev/null +++ b/src/net_wifi.c @@ -0,0 +1,364 @@ +/* + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include "net_wifi_private.h" + +static bool is_init = false; +static wifi_rssi_level_changed_cb rssi_level_changed_cb = NULL; +static void *rssi_level_changed_user_data = NULL; + + +static void __rssi_level_changed_cb(keynode_t *node, void *user_data) +{ + int rssi_level = vconf_keynode_get_int(node); + rssi_level_changed_cb(rssi_level, rssi_level_changed_user_data); +} + +int wifi_initialize(void) +{ + if (is_init) { + WIFI_LOG(WIFI_ERROR, "Already initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + if (_wifi_libnet_init() == false) { + WIFI_LOG(WIFI_ERROR, "Init failed!\n"); + return WIFI_ERROR_OPERATION_FAILED; + } + + is_init = true; + + return WIFI_ERROR_NONE; +} + +int wifi_deinitialize(void) +{ + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + if (_wifi_libnet_deinit() == false) { + WIFI_LOG(WIFI_ERROR, "Deinit failed!\n"); + return WIFI_ERROR_OPERATION_FAILED; + } + + is_init = false; + wifi_unset_rssi_level_changed_cb(); + + return WIFI_ERROR_NONE; +} + +int wifi_activate(wifi_activated_cb callback, void* user_data) +{ + int rv; + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + rv = _wifi_activate(callback, user_data); + if (rv != WIFI_ERROR_NONE) + WIFI_LOG(WIFI_ERROR, "Error!! Wi-Fi Activation failed.\n"); + + return rv; +} + +int wifi_deactivate(wifi_deactivated_cb callback, void* user_data) +{ + int rv; + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + rv = _wifi_deactivate(callback, user_data); + if (rv != WIFI_ERROR_NONE) + WIFI_LOG(WIFI_ERROR, "Error!! Wi-Fi Deactivation failed.\n"); + + return rv; +} + +int wifi_is_activated(bool* activated) +{ + wifi_device_state_e device_state; + + if (activated == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (_wifi_libnet_get_wifi_device_state(&device_state) == false) { + return WIFI_ERROR_OPERATION_FAILED; + } else { + WIFI_LOG(WIFI_INFO, "WiFi = %d\n", device_state); + if (WIFI_DEVICE_STATE_DEACTIVATED == device_state) + *activated = false; + else + *activated = true; + } + + return WIFI_ERROR_NONE; +} + +int wifi_get_connection_state(wifi_connection_state_e* connection_state) +{ + if (connection_state == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (_wifi_libnet_get_wifi_state(connection_state) == false) + return WIFI_ERROR_OPERATION_FAILED; + + return WIFI_ERROR_NONE; +} + +int wifi_get_mac_address(char** mac_address) +{ + if (mac_address == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + *mac_address = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS); + + if (*mac_address == NULL) { + WIFI_LOG(WIFI_ERROR, "vconf_get_str Failed\n"); + return WIFI_ERROR_OPERATION_FAILED; + } + + WIFI_LOG(WIFI_INFO, "MAC Address %s\n", *mac_address); + + return WIFI_ERROR_NONE; +} + +int wifi_get_network_interface_name(char** name) +{ + if (name == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + return _wifi_libnet_get_intf_name(name); +} + +int wifi_scan(wifi_scan_finished_cb callback, void* user_data) +{ + int rv; + + if (callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + rv = _wifi_libnet_scan_request(callback, user_data); + if (rv != WIFI_ERROR_NONE) + WIFI_LOG(WIFI_ERROR, "Error!! Wi-Fi scan failed.\n"); + + return rv; +} + +int wifi_get_connected_ap(wifi_ap_h* ap) +{ + int rv; + + if (ap == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + rv = _wifi_libnet_get_connected_profile(ap); + WIFI_LOG(WIFI_INFO, "Connected AP : %p, rv : %d\n", *ap, rv); + + return rv; +} + +int wifi_foreach_found_aps(wifi_found_ap_cb callback, void* user_data) +{ + if (callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (_wifi_libnet_foreach_found_aps(callback, user_data) == false) + return WIFI_ERROR_OPERATION_FAILED; + + return WIFI_ERROR_NONE; +} + +int wifi_connect(wifi_ap_h ap, wifi_connected_cb callback, void* user_data) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + return _wifi_libnet_open_profile(ap, callback, user_data); +} + +int wifi_disconnect(wifi_ap_h ap, wifi_disconnected_cb callback, void* user_data) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + return _wifi_libnet_close_profile(ap, callback, user_data); +} + +int wifi_connect_by_wps_pbc(wifi_ap_h ap, wifi_connected_cb callback, void* user_data) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + return _wifi_libnet_connect_with_wps(ap, callback, user_data); +} + +int wifi_forget_ap(wifi_ap_h ap) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + return _wifi_libnet_forget_ap(ap); +} + +int wifi_set_device_state_changed_cb(wifi_device_state_changed_cb callback, void* user_data) +{ + if (callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + return _wifi_set_power_on_off_cb(callback, user_data); +} + +int wifi_unset_device_state_changed_cb(void) +{ + return _wifi_unset_power_on_off_cb(); +} + +int wifi_set_background_scan_cb(wifi_scan_finished_cb callback, void* user_data) +{ + if (callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + return _wifi_set_background_scan_cb(callback, user_data); +} + +int wifi_unset_background_scan_cb(void) +{ + return _wifi_unset_background_scan_cb(); +} + +int wifi_set_connection_state_changed_cb(wifi_connection_state_changed_cb callback, void* user_data) +{ + if (callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (is_init == false) { + WIFI_LOG(WIFI_ERROR, "Not initialized\n"); + return WIFI_ERROR_INVALID_OPERATION; + } + + return _wifi_set_connection_state_cb(callback, user_data); +} + +int wifi_unset_connection_state_changed_cb(void) +{ + return _wifi_unset_connection_state_cb(); +} + +int wifi_set_rssi_level_changed_cb(wifi_rssi_level_changed_cb callback, void* user_data) +{ + if (callback == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (rssi_level_changed_cb == NULL) + vconf_notify_key_changed(VCONFKEY_WIFI_STRENGTH, __rssi_level_changed_cb, NULL); + else + return WIFI_ERROR_INVALID_OPERATION; + + rssi_level_changed_cb = callback; + rssi_level_changed_user_data = user_data; + + return WIFI_ERROR_NONE; +} + +int wifi_unset_rssi_level_changed_cb(void) +{ + if (rssi_level_changed_cb != NULL) + vconf_ignore_key_changed(VCONFKEY_WIFI_STRENGTH, __rssi_level_changed_cb); + else + return WIFI_ERROR_INVALID_OPERATION; + + rssi_level_changed_cb = NULL; + rssi_level_changed_user_data = NULL; + + return WIFI_ERROR_NONE; +} + diff --git a/src/net_wifi_ap.c b/src/net_wifi_ap.c new file mode 100755 index 0000000..6d01f9d --- /dev/null +++ b/src/net_wifi_ap.c @@ -0,0 +1,1168 @@ +/* + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include "net_wifi_private.h" + + +static char* __ap_convert_ip_to_string(net_addr_t *ip_addr) +{ + unsigned char *ipaddr = (unsigned char *)&ip_addr->Data.Ipv4.s_addr; + + char *ipstr = g_try_malloc0(16); + if (ipstr == NULL) + return NULL; + + snprintf(ipstr, 16, "%d.%d.%d.%d", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); + + return ipstr; +} + +static void __wifi_init_ap(net_profile_info_t *profile_info, const char *essid) +{ + profile_info->profile_type = NET_DEVICE_WIFI; + profile_info->ProfileState = NET_STATE_TYPE_IDLE; + profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF; + profile_info->ProfileInfo.Wlan.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT; + profile_info->ProfileInfo.Wlan.wlan_mode = NETPM_WLAN_CONNMODE_AUTO; + profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_NONE; + profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_NONE; + g_strlcpy(profile_info->ProfileInfo.Wlan.essid, essid, NET_WLAN_ESSID_LEN+1); +} + +wifi_connection_state_e _wifi_convert_to_ap_state(net_state_type_t state) +{ + wifi_connection_state_e ap_state; + + switch (state) { + case NET_STATE_TYPE_ONLINE: + case NET_STATE_TYPE_READY: + ap_state = WIFI_CONNECTION_STATE_CONNECTED; + break; + case NET_STATE_TYPE_IDLE: + case NET_STATE_TYPE_FAILURE: + case NET_STATE_TYPE_DISCONNECT: + ap_state = WIFI_CONNECTION_STATE_DISCONNECTED; + break; + case NET_STATE_TYPE_ASSOCIATION: + ap_state = WIFI_CONNECTION_STATE_ASSOCIATION; + break; + case NET_STATE_TYPE_CONFIGURATION: + ap_state = WIFI_CONNECTION_STATE_CONFIGURATION; + break; + default: + ap_state = -1; + } + + return ap_state; +} + +/* Wi-Fi AP module ********************************************************************************/ + +int wifi_ap_create(const char* essid, wifi_ap_h* ap) +{ + if (essid == NULL || ap == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *ap_info = g_try_malloc0(sizeof(net_profile_info_t)); + if (ap_info == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + __wifi_init_ap(ap_info, essid); + + _wifi_libnet_add_to_ap_list((wifi_ap_h)ap_info); + *ap = (wifi_ap_h)ap_info; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_destroy(wifi_ap_h ap) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + _wifi_libnet_remove_from_ap_list(ap); + + return WIFI_ERROR_NONE; +} + +int wifi_ap_clone(wifi_ap_h* cloned_ap, wifi_ap_h origin) +{ + if (_wifi_libnet_check_ap_validity(origin) == false || cloned_ap == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *ap_info = g_try_malloc0(sizeof(net_profile_info_t)); + if (ap_info == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + memcpy(ap_info, origin, sizeof(net_profile_info_t)); + + _wifi_libnet_add_to_ap_list((wifi_ap_h)ap_info); + *cloned_ap = (wifi_ap_h)ap_info; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_refresh(wifi_ap_h ap) +{ + net_profile_info_t ap_info_local; + net_profile_info_t *ap_info = ap; + + if (net_get_profile_info(ap_info->ProfileName, &ap_info_local) != NET_ERR_NONE) { + WIFI_LOG(WIFI_ERROR, "Error!!! net_get_profile_info() failed\n"); + return WIFI_ERROR_OPERATION_FAILED; + } + + memcpy(ap, &ap_info_local, sizeof(net_profile_info_t)); + + return WIFI_ERROR_NONE; +} + +/* Wi-Fi network information module ***************************************************************/ + +int wifi_ap_get_essid(wifi_ap_h ap, char** essid) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || essid == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + *essid = g_strdup(profile_info->ProfileInfo.Wlan.essid); + if (*essid == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_bssid(wifi_ap_h ap, char** bssid) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || bssid == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + *bssid = g_strdup(profile_info->ProfileInfo.Wlan.bssid); + if (*bssid == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_rssi(wifi_ap_h ap, int* rssi) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || rssi == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + *rssi = (int)profile_info->ProfileInfo.Wlan.Strength; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_frequency(wifi_ap_h ap, int* frequency) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || frequency == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + *frequency = (int)profile_info->ProfileInfo.Wlan.frequency; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_max_speed(wifi_ap_h ap, int* max_speed) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || max_speed == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + *max_speed = (int)profile_info->ProfileInfo.Wlan.max_rate; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_is_favorite(wifi_ap_h ap, bool* favorite) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || favorite == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + if (profile_info->Favourite) + *favorite = true; + else + *favorite = false; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_connection_state(wifi_ap_h ap, wifi_connection_state_e* state) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || state == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + *state = _wifi_convert_to_ap_state(profile_info->ProfileState); + + if (*state < 0) + return WIFI_ERROR_OPERATION_FAILED; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_ip_config_type(wifi_ap_h ap, wifi_address_family_e address_family, wifi_ip_config_type_e* type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6) || + type == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + switch (profile_info->ProfileInfo.Wlan.net_info.IpConfigType) { + case NET_IP_CONFIG_TYPE_STATIC: + *type = WIFI_IP_CONFIG_TYPE_STATIC; + break; + case NET_IP_CONFIG_TYPE_DYNAMIC: + *type = WIFI_IP_CONFIG_TYPE_DYNAMIC; + break; + case NET_IP_CONFIG_TYPE_AUTO_IP: + *type = WIFI_IP_CONFIG_TYPE_AUTO; + break; + case NET_IP_CONFIG_TYPE_FIXED: + *type = WIFI_IP_CONFIG_TYPE_FIXED; + break; + case NET_IP_CONFIG_TYPE_OFF: + *type = WIFI_IP_CONFIG_TYPE_NONE; + break; + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_ip_config_type(wifi_ap_h ap, wifi_address_family_e address_family, wifi_ip_config_type_e type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6)) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + switch (type) { + case WIFI_IP_CONFIG_TYPE_STATIC: + profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_STATIC; + profile_info->ProfileInfo.Wlan.net_info.IpAddr.Data.Ipv4.s_addr = 0; + profile_info->ProfileInfo.Wlan.net_info.SubnetMask.Data.Ipv4.s_addr = 0; + profile_info->ProfileInfo.Wlan.net_info.GatewayAddr.Data.Ipv4.s_addr = 0; + break; + case WIFI_IP_CONFIG_TYPE_DYNAMIC: + profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC; + break; + case WIFI_IP_CONFIG_TYPE_AUTO: + profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_AUTO_IP; + break; + case WIFI_IP_CONFIG_TYPE_FIXED: + profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_FIXED; + break; + case WIFI_IP_CONFIG_TYPE_NONE: + profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF; + break; + default: + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + return _wifi_update_ap_info(profile_info); +} + +int wifi_ap_get_ip_address(wifi_ap_h ap, wifi_address_family_e address_family, char** ip_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6) || + ip_address == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + *ip_address = __ap_convert_ip_to_string(&profile_info->ProfileInfo.Wlan.net_info.IpAddr); + if (*ip_address == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_ip_address(wifi_ap_h ap, wifi_address_family_e address_family, const char* ip_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6)) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + if (ip_address == NULL) + profile_info->ProfileInfo.Wlan.net_info.IpAddr.Data.Ipv4.s_addr = 0; + else if (inet_aton(ip_address, &(profile_info->ProfileInfo.Wlan.net_info.IpAddr.Data.Ipv4)) == 0) + return WIFI_ERROR_INVALID_PARAMETER; + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + return _wifi_update_ap_info(profile_info); +} + +int wifi_ap_get_subnet_mask(wifi_ap_h ap, wifi_address_family_e address_family, char** subnet_mask) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6) || + subnet_mask == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + *subnet_mask = __ap_convert_ip_to_string(&profile_info->ProfileInfo.Wlan.net_info.SubnetMask); + if (*subnet_mask == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_subnet_mask(wifi_ap_h ap, wifi_address_family_e address_family, const char* subnet_mask) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6)) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + if (subnet_mask == NULL) + profile_info->ProfileInfo.Wlan.net_info.SubnetMask.Data.Ipv4.s_addr = 0; + else if (inet_aton(subnet_mask, &(profile_info->ProfileInfo.Wlan.net_info.SubnetMask.Data.Ipv4)) == 0) + return WIFI_ERROR_INVALID_PARAMETER; + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + return _wifi_update_ap_info(profile_info); +} + +int wifi_ap_get_gateway_address(wifi_ap_h ap, wifi_address_family_e address_family, char** gateway_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6) || + gateway_address == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + *gateway_address = __ap_convert_ip_to_string(&profile_info->ProfileInfo.Wlan.net_info.GatewayAddr); + if (*gateway_address == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_gateway_address(wifi_ap_h ap, wifi_address_family_e address_family, const char* gateway_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6)) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + if (gateway_address == NULL) + profile_info->ProfileInfo.Wlan.net_info.GatewayAddr.Data.Ipv4.s_addr = 0; + else if (inet_aton(gateway_address, &(profile_info->ProfileInfo.Wlan.net_info.GatewayAddr.Data.Ipv4)) == 0) + return WIFI_ERROR_INVALID_PARAMETER; + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + return _wifi_update_ap_info(profile_info); +} + +int wifi_ap_get_proxy_address(wifi_ap_h ap, wifi_address_family_e address_family, char** proxy_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6) || + proxy_address == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + *proxy_address = g_strdup(profile_info->ProfileInfo.Wlan.net_info.ProxyAddr); + if (*proxy_address == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_proxy_address(wifi_ap_h ap, wifi_address_family_e address_family, const char* proxy_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6)) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + if (proxy_address == NULL) + profile_info->ProfileInfo.Wlan.net_info.ProxyAddr[0] = '\0'; + else + g_strlcpy(profile_info->ProfileInfo.Wlan.net_info.ProxyAddr, + proxy_address, NET_PROXY_LEN_MAX+1); + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + return _wifi_update_ap_info(profile_info); +} + +int wifi_ap_get_proxy_type(wifi_ap_h ap, wifi_proxy_type_e* type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || type == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + switch (profile_info->ProfileInfo.Wlan.net_info.ProxyMethod) { + case NET_PROXY_TYPE_DIRECT: + *type = WIFI_PROXY_TYPE_DIRECT; + break; + case NET_PROXY_TYPE_AUTO: + *type = WIFI_PROXY_TYPE_AUTO; + break; + case NET_PROXY_TYPE_MANUAL: + *type = WIFI_PROXY_TYPE_MANUAL; + break; + case NET_PROXY_TYPE_UNKNOWN: + *type = WIFI_PROXY_TYPE_DIRECT; + break; + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_proxy_type(wifi_ap_h ap, wifi_proxy_type_e proxy_type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + int rv; + + switch (proxy_type) { + case WIFI_PROXY_TYPE_DIRECT: + profile_info->ProfileInfo.Wlan.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT; + break; + case WIFI_PROXY_TYPE_AUTO: + profile_info->ProfileInfo.Wlan.net_info.ProxyAddr[0] = '\0'; + profile_info->ProfileInfo.Wlan.net_info.ProxyMethod = NET_PROXY_TYPE_AUTO; + break; + case WIFI_PROXY_TYPE_MANUAL: + profile_info->ProfileInfo.Wlan.net_info.ProxyAddr[0] = '\0'; + profile_info->ProfileInfo.Wlan.net_info.ProxyMethod = NET_PROXY_TYPE_MANUAL; + break; + default: + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + rv =_wifi_update_ap_info(profile_info); + if (rv != NET_ERR_NONE && proxy_type == WIFI_PROXY_TYPE_MANUAL) { + g_strlcpy(profile_info->ProfileInfo.Wlan.net_info.ProxyAddr, "0.0.0.0:8080", 15); + rv = _wifi_update_ap_info(profile_info); + } + + return rv; +} + +int wifi_ap_get_dns_address(wifi_ap_h ap, int order, wifi_address_family_e address_family, char** dns_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6) || + dns_address == NULL || + order <= 0 || + order > NET_DNS_ADDR_MAX) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + *dns_address = __ap_convert_ip_to_string(&profile_info->ProfileInfo.Wlan.net_info.DnsAddr[order-1]); + if (*dns_address == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_dns_address(wifi_ap_h ap, int order, wifi_address_family_e address_family, const char* dns_address) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || + (address_family != WIFI_ADDRESS_FAMILY_IPV4 && + address_family != WIFI_ADDRESS_FAMILY_IPV6) || + order <= 0 || + order > NET_DNS_ADDR_MAX) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + if (address_family == WIFI_ADDRESS_FAMILY_IPV6) { + WIFI_LOG(WIFI_ERROR, "Not supported yet\n"); + return WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + } + + net_profile_info_t *profile_info = ap; + + if (dns_address == NULL) + profile_info->ProfileInfo.Wlan.net_info.DnsAddr[order-1].Data.Ipv4.s_addr = 0; + else if (inet_aton(dns_address, &(profile_info->ProfileInfo.Wlan.net_info.DnsAddr[order-1].Data.Ipv4)) == 0) + return WIFI_ERROR_INVALID_PARAMETER; + + if (profile_info->ProfileInfo.Wlan.net_info.DnsCount < order) + profile_info->ProfileInfo.Wlan.net_info.DnsCount = order; + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + return _wifi_update_ap_info(profile_info); +} + + + +/* Wi-Fi security information module **************************************************************/ + +int wifi_ap_get_security_type(wifi_ap_h ap, wifi_security_type_e* type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || type == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + switch (profile_info->ProfileInfo.Wlan.security_info.sec_mode) { + case WLAN_SEC_MODE_NONE: + *type = WIFI_SECURITY_TYPE_NONE; + break; + case WLAN_SEC_MODE_WEP: + *type = WIFI_SECURITY_TYPE_WEP; + break; + case WLAN_SEC_MODE_IEEE8021X: + *type = WIFI_SECURITY_TYPE_EAP; + break; + case WLAN_SEC_MODE_WPA_PSK: + *type = WIFI_SECURITY_TYPE_WPA_PSK; + break; + case WLAN_SEC_MODE_WPA2_PSK: + *type = WIFI_SECURITY_TYPE_WPA2_PSK; + break; + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_security_type(wifi_ap_h ap, wifi_security_type_e type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + switch (type) { + case WIFI_SECURITY_TYPE_NONE: + profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_NONE; + break; + case WIFI_SECURITY_TYPE_WEP: + profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_WEP; + break; + case WIFI_SECURITY_TYPE_EAP: + profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_IEEE8021X; + break; + case WIFI_SECURITY_TYPE_WPA_PSK: + profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_WPA_PSK; + break; + case WIFI_SECURITY_TYPE_WPA2_PSK: + profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_WPA2_PSK; + break; + default: + return WIFI_ERROR_INVALID_PARAMETER; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_encryption_type(wifi_ap_h ap, wifi_encryption_type_e* type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || type == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + switch (profile_info->ProfileInfo.Wlan.security_info.enc_mode) { + case WLAN_ENC_MODE_NONE: + *type = WIFI_ENCRYPTION_TYPE_NONE; + break; + case WLAN_ENC_MODE_WEP: + *type = WIFI_ENCRYPTION_TYPE_WEP; + break; + case WLAN_ENC_MODE_TKIP: + *type = WIFI_ENCRYPTION_TYPE_TKIP; + break; + case WLAN_ENC_MODE_AES: + *type = WIFI_ENCRYPTION_TYPE_AES; + break; + case WLAN_ENC_MODE_TKIP_AES_MIXED: + *type = WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED; + break; + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_encryption_type(wifi_ap_h ap, wifi_encryption_type_e type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + switch (type) { + case WIFI_ENCRYPTION_TYPE_NONE: + profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_NONE; + break; + case WIFI_ENCRYPTION_TYPE_WEP: + profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_WEP; + break; + case WIFI_ENCRYPTION_TYPE_TKIP: + profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_TKIP; + break; + case WIFI_ENCRYPTION_TYPE_AES: + profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_AES; + break; + case WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED: + profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_TKIP_AES_MIXED; + break; + default: + return WIFI_ERROR_INVALID_PARAMETER; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_is_passphrase_required(wifi_ap_h ap, bool* required) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || required == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + if (profile_info->Favourite) { + *required = false; + return WIFI_ERROR_NONE; + } + + switch (profile_info->ProfileInfo.Wlan.security_info.sec_mode) { + case WLAN_SEC_MODE_NONE: + *required = false; + break; + case WLAN_SEC_MODE_WEP: + case WLAN_SEC_MODE_IEEE8021X: + case WLAN_SEC_MODE_WPA_PSK: + case WLAN_SEC_MODE_WPA2_PSK: + *required = true; + break; + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_passphrase(wifi_ap_h ap, const char* passphrase) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || passphrase == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + switch (profile_info->ProfileInfo.Wlan.security_info.sec_mode) { + case WLAN_SEC_MODE_WEP: + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.wep.wepKey, + passphrase, NETPM_WLAN_MAX_WEP_KEY_LEN+1); + break; + case WLAN_SEC_MODE_WPA_PSK: + case WLAN_SEC_MODE_WPA2_PSK: + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.psk.pskKey, + passphrase, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN+1); + break; + case WLAN_SEC_MODE_NONE: + case WLAN_SEC_MODE_IEEE8021X: + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + if (_wifi_libnet_check_profile_name_validity(profile_info->ProfileName) == false) + return WIFI_ERROR_NONE; + + return _wifi_update_ap_info(profile_info); +} + +int wifi_ap_is_wps_supported(wifi_ap_h ap, bool* supported) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || supported == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + + if (profile_info->ProfileInfo.Wlan.security_info.wps_support) + *supported = true; + else + *supported = false; + + return WIFI_ERROR_NONE; +} + + + +/* Wi-Fi EAP module *******************************************************************************/ + +int wifi_ap_set_eap_passphrase(wifi_ap_h ap, const char* user_name, const char* password) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || (user_name == NULL && password == NULL)) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + if (user_name) + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.username, + user_name, NETPM_WLAN_USERNAME_LEN+1); + + if (password) + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.password, + password, NETPM_WLAN_PASSWORD_LEN+1); + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_eap_passphrase(wifi_ap_h ap, char** user_name, bool* is_password_set) +{ + if (_wifi_libnet_check_ap_validity(ap) == false ||user_name == NULL || is_password_set == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + *user_name = g_strdup(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.username); + if (*user_name == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + if (strlen(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.password) > 0) + *is_password_set = true; + else + *is_password_set = false; + + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_eap_ca_cert_file(wifi_ap_h ap, char** file) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || file == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + *file = g_strdup(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.ca_cert_filename); + if (*file == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_eap_ca_cert_file(wifi_ap_h ap, const char* file) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || file == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.ca_cert_filename, + file, NETPM_WLAN_CA_CERT_FILENAME_LEN+1); + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_eap_client_cert_file(wifi_ap_h ap, char** file) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || file == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + *file = g_strdup(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.client_cert_filename); + if (*file == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_eap_client_cert_file(wifi_ap_h ap, const char* file) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || file == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.client_cert_filename, + file, NETPM_WLAN_CLIENT_CERT_FILENAME_LEN+1); + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_eap_private_key_file(wifi_ap_h ap, char** file) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || file == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + *file = g_strdup(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.private_key_filename); + if (*file == NULL) + return WIFI_ERROR_OUT_OF_MEMORY; + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_eap_private_key_info(wifi_ap_h ap, const char* file, const char* password) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || file == NULL || password == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.private_key_filename, + file, NETPM_WLAN_PRIVATE_KEY_FILENAME_LEN+1); + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.eap.private_key_passwd, + password, NETPM_WLAN_PRIVATE_KEY_PASSWD_LEN+1); + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_eap_type(wifi_ap_h ap, wifi_eap_type_e* type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || type == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + switch (profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_type) { + case WLAN_SEC_EAP_TYPE_PEAP: + *type = WIFI_EAP_TYPE_PEAP; + break; + case WLAN_SEC_EAP_TYPE_TLS: + *type = WIFI_EAP_TYPE_TLS; + break; + case WLAN_SEC_EAP_TYPE_TTLS: + *type = WIFI_EAP_TYPE_TTLS; + break; + case WLAN_SEC_EAP_TYPE_SIM: + *type = WIFI_EAP_TYPE_SIM; + break; + case WLAN_SEC_EAP_TYPE_AKA: + *type = WIFI_EAP_TYPE_AKA; + break; + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_eap_type(wifi_ap_h ap, wifi_eap_type_e type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + switch (type) { + case WIFI_EAP_TYPE_PEAP: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_type = WLAN_SEC_EAP_TYPE_PEAP; + break; + case WIFI_EAP_TYPE_TLS: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_type = WLAN_SEC_EAP_TYPE_TLS; + break; + case WIFI_EAP_TYPE_TTLS: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_type = WLAN_SEC_EAP_TYPE_TTLS; + break; + case WIFI_EAP_TYPE_SIM: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_type = WLAN_SEC_EAP_TYPE_SIM; + break; + case WIFI_EAP_TYPE_AKA: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_type = WLAN_SEC_EAP_TYPE_AKA; + break; + default: + return WIFI_ERROR_INVALID_PARAMETER; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_get_eap_auth_type(wifi_ap_h ap, wifi_eap_auth_type_e* type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false || type == NULL) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + switch (profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_auth) { + case WLAN_SEC_EAP_AUTH_NONE: + *type = WIFI_EAP_AUTH_TYPE_NONE; + break; + case WLAN_SEC_EAP_AUTH_PAP: + *type = WIFI_EAP_AUTH_TYPE_PAP; + break; + case WLAN_SEC_EAP_AUTH_MSCHAP: + *type = WIFI_EAP_AUTH_TYPE_MSCHAP; + break; + case WLAN_SEC_EAP_AUTH_MSCHAPV2: + *type = WIFI_EAP_AUTH_TYPE_MSCHAPV2; + break; + case WLAN_SEC_EAP_AUTH_GTC: + *type = WIFI_EAP_AUTH_TYPE_GTC; + break; + case WLAN_SEC_EAP_AUTH_MD5: + *type = WIFI_EAP_AUTH_TYPE_MD5; + break; + default: + return WIFI_ERROR_OPERATION_FAILED; + } + + return WIFI_ERROR_NONE; +} + +int wifi_ap_set_eap_auth_type(wifi_ap_h ap, wifi_eap_auth_type_e type) +{ + if (_wifi_libnet_check_ap_validity(ap) == false) { + WIFI_LOG(WIFI_ERROR, "Wrong Parameter Passed\n"); + return WIFI_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = ap; + if (profile_info->ProfileInfo.Wlan.security_info.sec_mode != WLAN_SEC_MODE_IEEE8021X) + return WIFI_ERROR_INVALID_OPERATION; + + switch (type) { + case WIFI_EAP_AUTH_TYPE_NONE: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_auth = WLAN_SEC_EAP_AUTH_NONE; + break; + case WIFI_EAP_AUTH_TYPE_PAP: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_auth = WLAN_SEC_EAP_AUTH_PAP; + break; + case WIFI_EAP_AUTH_TYPE_MSCHAP: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_auth = WLAN_SEC_EAP_AUTH_MSCHAP; + break; + case WIFI_EAP_AUTH_TYPE_MSCHAPV2: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_auth = WLAN_SEC_EAP_AUTH_MSCHAPV2; + break; + case WIFI_EAP_AUTH_TYPE_GTC: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_auth = WLAN_SEC_EAP_AUTH_GTC; + break; + case WIFI_EAP_AUTH_TYPE_MD5: + profile_info->ProfileInfo.Wlan.security_info.authentication.eap.eap_auth = WLAN_SEC_EAP_AUTH_MD5; + break; + default: + return WIFI_ERROR_INVALID_PARAMETER; + } + + return WIFI_ERROR_NONE; +} + + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..7715cac --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,17 @@ +SET(fw_test "${fw_name}-test") + +INCLUDE(FindPkgConfig) +pkg_check_modules(${fw_test} REQUIRED glib-2.0) +FOREACH(flag ${${fw_test}_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") + +aux_source_directory(. sources) +FOREACH(src ${sources}) + GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) + MESSAGE("${src_name}") + ADD_EXECUTABLE(${src_name} ${src}) + TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) +ENDFOREACH() diff --git a/test/wifi_test.c b/test/wifi_test.c new file mode 100644 index 0000000..0c24089 --- /dev/null +++ b/test/wifi_test.c @@ -0,0 +1,1279 @@ +/* + * Copyright (c) 2012-2013 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "assert.h" +#include "glib.h" +#include +#include + + +gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data); + +static const char *__test_convert_error_to_string(wifi_error_e err_type) +{ + switch (err_type) { + case WIFI_ERROR_NONE: + return "NONE"; + case WIFI_ERROR_INVALID_PARAMETER: + return "INVALID_PARAMETER"; + case WIFI_ERROR_OUT_OF_MEMORY: + return "OUT_OF_MEMORY"; + case WIFI_ERROR_INVALID_OPERATION: + return "INVALID_OPERATION"; + case WIFI_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED: + return "ADDRESS_FAMILY_NOT_SUPPORTED"; + case WIFI_ERROR_OPERATION_FAILED: + return "OPERATION_FAILED"; + case WIFI_ERROR_NO_CONNECTION: + return "NO_CONNECTION"; + case WIFI_ERROR_NOW_IN_PROGRESS: + return "NOW_IN_PROGRESS"; + case WIFI_ERROR_ALREADY_EXISTS: + return "ALREADY_EXISTS"; + case WIFI_ERROR_OPERATION_ABORTED: + return "OPERATION_ABORTED"; + case WIFI_ERROR_DHCP_FAILED: + return "DHCP_FAILED"; + case WIFI_ERROR_INVALID_KEY: + return "INVALID_KEY"; + case WIFI_ERROR_NO_REPLY: + return "NO_REPLY"; + case WIFI_ERROR_SECURITY_RESTRICTED: + return "SECURITY_RESTRICTED"; + } + + return "UNKNOWN"; +} + +static void __test_device_state_callback(wifi_device_state_e state, void* user_data) +{ + printf("Device state changed callback"); + + if (state == WIFI_DEVICE_STATE_ACTIVATED) + printf(", state : Activated\n"); + else + printf(", state : Deactivated\n"); +} + +static void __test_bg_scan_completed_callback(wifi_error_e error_code, void* user_data) +{ + printf("Background Scan Completed, error code : %s\n", + __test_convert_error_to_string(error_code)); +} + +static void __test_scan_request_callback(wifi_error_e error_code, void* user_data) +{ + printf("Scan Completed from scan request, error code : %s\n", + __test_convert_error_to_string(error_code)); +} + +static void __test_connection_state_callback(wifi_connection_state_e state, wifi_ap_h ap, void* user_data) +{ + int rv = 0; + char *ap_name = NULL; + + printf("Connection state changed callback"); + + switch (state) { + case WIFI_CONNECTION_STATE_CONNECTED: + printf(", state : Connected"); + break; + case WIFI_CONNECTION_STATE_ASSOCIATION: + printf(", state : Association"); + break; + case WIFI_CONNECTION_STATE_CONFIGURATION: + printf(", state : Configuration"); + break; + case WIFI_CONNECTION_STATE_DISCONNECTED: + printf(", state : Disconnected"); + break; + default: + printf(", state : Unknown"); + } + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) + printf(", Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + else { + printf(", AP name : %s\n", ap_name); + g_free(ap_name); + } +} + +static void __test_activated_callback(wifi_error_e result, void* user_data) +{ + if (result == WIFI_ERROR_NONE) + printf("Wi-Fi Activation Succeeded\n"); + else + printf("Wi-Fi Activation Failed! error : %s", __test_convert_error_to_string(result)); +} + +static void __test_deactivated_callback(wifi_error_e result, void* user_data) +{ + if (result == WIFI_ERROR_NONE) + printf("Wi-Fi Deactivation Succeeded\n"); + else + printf("Wi-Fi Deactivation Failed! error : %s", __test_convert_error_to_string(result)); +} + +static void __test_connected_callback(wifi_error_e result, void* user_data) +{ + if (result == WIFI_ERROR_NONE) + printf("Wi-Fi Connection Succeeded\n"); + else + printf("Wi-Fi Connection Failed! error : %s", __test_convert_error_to_string(result)); +} + +static void __test_disconnected_callback(wifi_error_e result, void* user_data) +{ + if (result == WIFI_ERROR_NONE) + printf("Wi-Fi Disconnection Succeeded\n"); + else + printf("Wi-Fi Disconnection Failed! error : %s", __test_convert_error_to_string(result)); +} + +static void __test_rssi_level_callback(wifi_rssi_level_e rssi_level, void* user_data) +{ + printf("RSSI level changed callback, level = %d\n", rssi_level); +} + +static const char* __test_print_state(wifi_connection_state_e state) +{ + switch (state) { + case WIFI_CONNECTION_STATE_DISCONNECTED: + return "Disconnected"; + case WIFI_CONNECTION_STATE_ASSOCIATION: + return "Association"; + case WIFI_CONNECTION_STATE_CONNECTED: + return "Connected"; + case WIFI_CONNECTION_STATE_CONFIGURATION: + return "Configuration"; + } + + return "Unknown"; +} + +static bool __test_found_ap_callback(wifi_ap_h ap, void *user_data) +{ + int rv = 0; + char *ap_name = NULL; + wifi_connection_state_e state; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + rv = wifi_ap_get_connection_state(ap, &state); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get State [%s]\n", __test_convert_error_to_string(rv)); + g_free(ap_name); + return false; + } + + printf("AP name : %s, state : %s\n", ap_name, __test_print_state(state)); + g_free(ap_name); + + return true; +} + +static bool __test_found_connect_ap_callback(wifi_ap_h ap, void *user_data) +{ + int rv = 0; + char *ap_name = NULL; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (strstr(ap_name, ap_name_part) != NULL) { + bool required = false; + wifi_ap_is_passphrase_required(ap, &required); + + if (required) { + char passphrase[100]; + printf("Input passphrase for %s : ", ap_name); + rv = scanf("%99s", passphrase); + + rv = wifi_ap_set_passphrase(ap, passphrase); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to set passphrase : %s\n", __test_convert_error_to_string(rv)); + g_free(ap_name); + return false; + } + } + + rv = wifi_connect(ap, __test_connected_callback, NULL); + if (rv != WIFI_ERROR_NONE) + printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv)); + else + printf("Success to connection request [%s]\n", ap_name); + + g_free(ap_name); + return false; + } + + g_free(ap_name); + return true; +} + +static bool __test_found_connect_wps_callback(wifi_ap_h ap, void *user_data) +{ + int rv = 0; + char *ap_name = NULL; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (strstr(ap_name, ap_name_part) != NULL) { + rv = wifi_connect(ap, __test_connected_callback, NULL); + if (rv != WIFI_ERROR_NONE) + printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv)); + else + printf("Success to connection request [%s]\n", ap_name); + + g_free(ap_name); + return false; + } + + g_free(ap_name); + return true; +} + +static bool __test_found_disconnect_ap_callback(wifi_ap_h ap, void *user_data) +{ + int rv = 0; + char *ap_name = NULL; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (strstr(ap_name, ap_name_part) != NULL) { + rv = wifi_disconnect(ap, __test_disconnected_callback, NULL); + if (rv != WIFI_ERROR_NONE) + printf("Fail to disconnection reqeust %s : [%s]\n", ap_name, __test_convert_error_to_string(rv)); + else + printf("Success to disconnection request %s\n", ap_name); + + g_free(ap_name); + return false; + } + + g_free(ap_name); + return true; +} + +static bool __test_found_forget_ap_callback(wifi_ap_h ap, void *user_data) +{ + int rv = 0; + char *ap_name = NULL; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (strstr(ap_name, ap_name_part) != NULL) { + rv = wifi_forget_ap(ap); + if (rv != WIFI_ERROR_NONE) + printf("Fail to forget [%s] : %s\n", ap_name, __test_convert_error_to_string(rv)); + else + printf("Success to forget [%s]\n", ap_name); + + g_free(ap_name); + return false; + } + + g_free(ap_name); + return true; +} + +static bool __test_found_eap_ap_callback(wifi_ap_h ap, void *user_data) +{ + int rv = 0; + char *ap_name = NULL; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (strstr(ap_name, ap_name_part) != NULL) { + wifi_security_type_e type;; + wifi_ap_get_security_type(ap, &type); + + if (type != WIFI_SECURITY_TYPE_EAP) { + g_free(ap_name); + return false; + } + + char input_str1[100]; + printf("Input user name for %s : ", ap_name); + rv = scanf("%99s", input_str1); + + char input_str2[100]; + printf("Input password for %s : ", ap_name); + rv = scanf("%99s", input_str2); + + rv = wifi_ap_set_eap_passphrase(ap, input_str1, input_str2); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to set eap passphrase : %s\n", __test_convert_error_to_string(rv)); + g_free(ap_name); + return false; + } + + char *inputed_name = NULL; + bool is_pass_set; + rv = wifi_ap_get_eap_passphrase(ap, &inputed_name, &is_pass_set); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get eap passphrase : %s\n", __test_convert_error_to_string(rv)); + g_free(ap_name); + return false; + } + + printf("name : %s, is password set : %s\n", inputed_name, is_pass_set ? "TRUE" : "FALSE"); + + rv = wifi_connect(ap, __test_connected_callback, NULL); + if (rv != WIFI_ERROR_NONE) + printf("Fail to connection request [%s] : %s\n", ap_name, __test_convert_error_to_string(rv)); + else + printf("Success to connection request [%s]\n", ap_name); + + g_free(ap_name); + g_free(inputed_name); + return false; + } + + g_free(ap_name); + return true; +} + +static bool __test_found_change_ip_method_callback(wifi_ap_h ap, void *user_data) +{ + int rv; + char *ap_name; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + if (strstr(ap_name, ap_name_part) != NULL) { + wifi_ip_config_type_e type; + int method; + + printf("Input new method type (1:dhcp, 2:manual, 3:auto) :\n"); + rv = scanf("%9d", &method); + if (rv <= 0) { + g_free(ap_name); + return false; + } + + switch (method) { + case 1: + type = WIFI_IP_CONFIG_TYPE_DYNAMIC; + break; + case 2: + type = WIFI_IP_CONFIG_TYPE_STATIC; + break; + case 3: + type = WIFI_IP_CONFIG_TYPE_AUTO; + break; + default: + printf("Invalid input!\n"); + g_free(ap_name); + return false; + } + + rv = wifi_ap_set_ip_config_type(ap, WIFI_ADDRESS_FAMILY_IPV4, type); + if (rv != WIFI_ERROR_NONE) + printf("Fail to set ip method type[%s]\n", __test_convert_error_to_string(rv)); + + if (type == WIFI_IP_CONFIG_TYPE_STATIC) { + char ip_addr[16]; + + printf("Input new ip address (x:skip, 0:clear) :\n"); + rv = scanf("%15s", ip_addr); + if (rv > 0) { + switch (ip_addr[0]) { + case 'x': + rv = WIFI_ERROR_NONE; + break; + case '0': + rv = wifi_ap_set_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, NULL); + break; + default: + rv = wifi_ap_set_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip_addr); + } + + if (rv != WIFI_ERROR_NONE) + printf("Fail to set ip address[%s]\n", + __test_convert_error_to_string(rv)); + } + + printf("Input new subnet mask (x:skip, 0:clear) :\n"); + rv = scanf("%15s", ip_addr); + if (rv > 0) { + switch (ip_addr[0]) { + case 'x': + rv = WIFI_ERROR_NONE; + break; + case '0': + rv = wifi_ap_set_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, NULL); + break; + default: + rv = wifi_ap_set_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, ip_addr); + } + + if (rv != WIFI_ERROR_NONE) + printf("Fail to set subnet mask[%s]\n", + __test_convert_error_to_string(rv)); + } + + printf("Input new gateway address (x:skip, 0:clear) :\n"); + rv = scanf("%15s", ip_addr); + if (rv > 0) { + switch (ip_addr[0]) { + case 'x': + rv = WIFI_ERROR_NONE; + break; + case '0': + rv = wifi_ap_set_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, NULL); + break; + default: + rv = wifi_ap_set_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, ip_addr); + } + + if (rv != WIFI_ERROR_NONE) + printf("Fail to set gateway address[%s]\n", + __test_convert_error_to_string(rv)); + } + } + + g_free(ap_name); + return false; + } + + g_free(ap_name); + return true; +} + +static bool __test_found_change_proxy_method_callback(wifi_ap_h ap, void *user_data) +{ + int rv; + char *ap_name; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + printf("ap_name %s, user input name %s\n", ap_name, ap_name_part); + if (strstr(ap_name, ap_name_part) != NULL) { + wifi_proxy_type_e type; + char proxy_addr[65]; + int method; + + printf("Input new method type (1:direct, 2:manual, 3:auto) :\n"); + rv = scanf("%9d", &method); + if (rv <= 0) { + g_free(ap_name); + return false; + } + + switch (method) { + case 1: + type = WIFI_PROXY_TYPE_DIRECT; + break; + case 2: + type = WIFI_PROXY_TYPE_MANUAL; + break; + case 3: + type = WIFI_PROXY_TYPE_AUTO; + break; + default: + printf("Invalid input!\n"); + g_free(ap_name); + return false; + } + + rv = wifi_ap_set_proxy_type(ap, type); + if (rv != WIFI_ERROR_NONE) + printf("Fail to set proxy method type[%s]\n", __test_convert_error_to_string(rv)); + + printf("Input new proxy address (x:skip, 0:clear) :\n"); + rv = scanf("%64s", proxy_addr); + + if (rv > 0) { + switch (proxy_addr[0]) { + case 'x': + rv = WIFI_ERROR_NONE; + break; + case '0': + rv = wifi_ap_set_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, NULL); + break; + default: + rv = wifi_ap_set_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, proxy_addr); + } + + if (rv != WIFI_ERROR_NONE) + printf("Fail to set proxy address[%s]\n", __test_convert_error_to_string(rv)); + } + + g_free(ap_name); + return false; + } + + g_free(ap_name); + return true; +} + +static bool __test_found_print_ap_info_callback(wifi_ap_h ap, void *user_data) +{ + int rv; + char *ap_name; + char *str_value; + int int_value; + wifi_connection_state_e conn_state; + wifi_ip_config_type_e ip_type; + wifi_proxy_type_e proxy_type; + wifi_security_type_e sec_type; + wifi_encryption_type_e enc_type; + wifi_eap_type_e eap_type; + wifi_eap_auth_type_e eap_auth_type; + bool bool_value; + char *ap_name_part = (char*)user_data; + + rv = wifi_ap_get_essid(ap, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP name [%s]\n", __test_convert_error_to_string(rv)); + return false; + } + + printf("ap_name %s, user input name %s\n", ap_name, ap_name_part); + if (strstr(ap_name, ap_name_part) != NULL) { + + /* Basic info */ + printf("ESSID : %s\n", ap_name); + + if (wifi_ap_get_bssid(ap, &str_value) == WIFI_ERROR_NONE) { + printf("BSSID : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get BSSID\n"); + + if (wifi_ap_get_rssi(ap, &int_value) == WIFI_ERROR_NONE) + printf("RSSI : %d\n", int_value); + else + printf("Fail to get RSSI\n"); + + if (wifi_ap_get_frequency(ap, &int_value) == WIFI_ERROR_NONE) + printf("Frequency : %d\n", int_value); + else + printf("Fail to get Frequency\n"); + + if (wifi_ap_get_max_speed(ap, &int_value) == WIFI_ERROR_NONE) + printf("Max speed : %d\n", int_value); + else + printf("Fail to get Max speed\n"); + + if (wifi_ap_is_favorite(ap, &bool_value) == WIFI_ERROR_NONE) + printf("Favorite : %s\n", bool_value ? "TRUE" : "FALSE"); + else + printf("Fail to get Favorite\n"); + + /* Network info */ + if (wifi_ap_get_connection_state(ap, &conn_state) == WIFI_ERROR_NONE) + printf("Connection State : %d\n", conn_state); + else + printf("Fail to get Connection State\n"); + + if (wifi_ap_get_ip_config_type(ap, WIFI_ADDRESS_FAMILY_IPV4, &ip_type) == WIFI_ERROR_NONE) + printf("IP config type : %d\n", ip_type); + else + printf("Fail to get IP config type\n"); + + if (wifi_ap_get_ip_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + printf("IP : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get IP\n"); + + if (wifi_ap_get_subnet_mask(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + printf("Subnet mask : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get Subnet mask\n"); + + if (wifi_ap_get_gateway_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + printf("Gateway : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get Gateway\n"); + + if (wifi_ap_get_proxy_type(ap, &proxy_type) == WIFI_ERROR_NONE) + printf("Proxy type : %d\n", proxy_type); + else + printf("Fail to get Proxy type\n"); + + if (wifi_ap_get_proxy_address(ap, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + printf("Proxy : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get Proxy\n"); + + if (wifi_ap_get_dns_address(ap, 1, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + printf("DNS1 : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get DNS1\n"); + + if (wifi_ap_get_dns_address(ap, 2, WIFI_ADDRESS_FAMILY_IPV4, &str_value) == WIFI_ERROR_NONE) { + printf("DNS2 : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get DNS2\n"); + + /* Security info */ + if (wifi_ap_get_security_type(ap, &sec_type) == WIFI_ERROR_NONE) + printf("Security type : %d\n", sec_type); + else + printf("Fail to get Security type\n"); + + if (wifi_ap_get_encryption_type(ap, &enc_type) == WIFI_ERROR_NONE) + printf("Encryption type : %d\n", enc_type); + else + printf("Fail to get Encryption type\n"); + + if (wifi_ap_is_passphrase_required(ap, &bool_value) == WIFI_ERROR_NONE) + printf("Passphrase required : %s\n", bool_value ? "TRUE" : "FALSE"); + else + printf("Fail to get Passphrase required\n"); + + if (wifi_ap_is_wps_supported(ap, &bool_value) == WIFI_ERROR_NONE) + printf("WPS supported : %s\n", bool_value ? "TRUE" : "FALSE"); + else + printf("Fail to get WPS supported\n"); + + if (sec_type != WIFI_SECURITY_TYPE_EAP) { + g_free(ap_name); + return false; + } + + /* EAP info */ + if (wifi_ap_get_eap_type(ap, &eap_type) == WIFI_ERROR_NONE) + printf("EAP type : %d\n", eap_type); + else + printf("Fail to get EAP type\n"); + + if (wifi_ap_get_eap_auth_type(ap, &eap_auth_type) == WIFI_ERROR_NONE) + printf("EAP auth type : %d\n", eap_auth_type); + else + printf("Fail to get EAP auth type\n"); + + if (wifi_ap_get_eap_passphrase(ap, &str_value, &bool_value) == WIFI_ERROR_NONE) { + printf("EAP user name : %s\n", str_value); + printf("EAP is password setted : %s\n", bool_value ? "TRUE" : "FALSE"); + g_free(str_value); + } else + printf("Fail to get EAP passphrase(user name/password)\n"); + + if (wifi_ap_get_eap_ca_cert_file(ap, &str_value) == WIFI_ERROR_NONE) { + printf("EAP ca cert file : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get EAP ca cert file\n"); + + if (wifi_ap_get_eap_client_cert_file(ap, &str_value) == WIFI_ERROR_NONE) { + printf("EAP client cert file : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get EAP client cert file\n"); + + if (wifi_ap_get_eap_private_key_file(ap, &str_value) == WIFI_ERROR_NONE) { + printf("EAP private key file : %s\n", str_value); + g_free(str_value); + } else + printf("Fail to get EAP private key file\n"); + + g_free(ap_name); + return false; + } + + g_free(ap_name); + return true; +} + +int test_wifi_init(void) +{ + int rv = wifi_initialize(); + + if (rv == WIFI_ERROR_NONE) { + wifi_set_device_state_changed_cb(__test_device_state_callback, NULL); + wifi_set_background_scan_cb(__test_bg_scan_completed_callback, NULL); + wifi_set_connection_state_changed_cb(__test_connection_state_callback, NULL); + wifi_set_rssi_level_changed_cb(__test_rssi_level_callback, NULL); + } else { + printf("Wifi init failed [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Wifi init succeeded\n"); + return 1; +} + +int test_wifi_deinit(void) +{ + int rv = 0; + + rv = wifi_deinitialize(); + + if (rv != WIFI_ERROR_NONE){ + printf("Wifi deinit failed [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Wifi deinit succeeded\n"); + return 1; +} + +int test_wifi_activate(void) +{ + int rv = 0; + + rv = wifi_activate(__test_activated_callback, NULL); + + if (rv != WIFI_ERROR_NONE) { + printf("Fail to activate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Success to activate Wi-Fi device\n"); + + return 1; +} + +int test_wifi_deactivate(void) +{ + int rv = 0; + + rv = wifi_deactivate(__test_deactivated_callback, NULL); + + if (rv != WIFI_ERROR_NONE) { + printf("Fail to deactivate Wi-Fi device [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Success to deactivate Wi-Fi device\n"); + + return 1; +} + +int test_is_activated(void) +{ + int rv = 0; + bool state = false; + + rv = wifi_is_activated(&state); + + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get Wi-Fi device state [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Success to get Wi-Fi device state : %s\n", (state) ? "TRUE" : "FALSE"); + + return 1; +} + +int test_get_connection_state(void) +{ + int rv = 0; + wifi_connection_state_e connection_state; + + rv = wifi_get_connection_state(&connection_state); + + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get connection state [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Success to get connection state : "); + switch (connection_state) { + case WIFI_CONNECTION_STATE_ASSOCIATION: + printf("Association\n"); + break; + case WIFI_CONNECTION_STATE_CONNECTED: + printf("Connected\n"); + break; + case WIFI_CONNECTION_STATE_CONFIGURATION: + printf("Configuration\n"); + break; + case WIFI_CONNECTION_STATE_DISCONNECTED: + printf("Disconnected\n"); + break; + default: + printf("Unknown\n"); + } + + return 1; +} + +int test_get_mac_address(void) +{ + int rv = 0; + char *mac_addr = NULL; + + rv = wifi_get_mac_address(&mac_addr); + + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get MAC address [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("MAC address : %s\n", mac_addr); + g_free(mac_addr); + + return 1; +} + +int test_get_interface_name(void) +{ + int rv = 0; + char *if_name = NULL; + + rv = wifi_get_network_interface_name(&if_name); + + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get Interface name [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Interface name : %s\n", if_name); + g_free(if_name); + + return 1; +} + +int test_scan_request(void) +{ + int rv = 0; + + rv = wifi_scan(__test_scan_request_callback, NULL); + + if (rv != WIFI_ERROR_NONE) { + printf("Scan request failed [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Scan request succeeded\n"); + + return 1; +} + +int test_get_connected_ap(void) +{ + int rv = 0; + char *ap_name = NULL; + wifi_ap_h ap_h; + + rv = wifi_get_connected_ap(&ap_h); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get connected AP [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + rv = wifi_ap_get_essid(ap_h, &ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get essid [%s]\n", __test_convert_error_to_string(rv)); + wifi_ap_destroy(ap_h); + return -1; + } + + printf("Connected AP : %s\n", ap_name); + g_free(ap_name); + wifi_ap_destroy(ap_h); + + return 1; +} + +int test_foreach_found_aps(void) +{ + int rv = 0; + + rv = wifi_foreach_found_aps(__test_found_ap_callback, NULL); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP list [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Get AP list finished\n"); + + return 1; +} + +int test_connect_ap(void) +{ + int rv = 0; + char ap_name[33]; + bool state = false; + + wifi_is_activated(&state); + if (state == false) + return -1; + + printf("Input a part of AP name to connect : "); + rv = scanf("%32s", ap_name); + + rv = wifi_foreach_found_aps(__test_found_connect_ap_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Connection step finished\n"); + return 1; +} + +int test_disconnect_ap(void) +{ + int rv = 0; + char ap_name[33]; + bool state = false; + + wifi_is_activated(&state); + if (state == false) + return -1; + + printf("Input a part of AP name to disconnect : "); + rv = scanf("%32s", ap_name); + + rv = wifi_foreach_found_aps(__test_found_disconnect_ap_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to disconnect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Disconnection step finished\n"); + return 1; +} + +int test_connect_wps(void) +{ + int rv = 0; + char ap_name[33]; + bool state = false; + + wifi_is_activated(&state); + if (state == false) + return -1; + + printf("Input a part of AP name to connect by wps : "); + rv = scanf("%32s", ap_name); + + rv = wifi_foreach_found_aps(__test_found_connect_wps_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Connection step finished\n"); + return 1; +} + +int test_forget_ap(void) +{ + int rv = 0; + char ap_name[33]; + bool state = false; + + wifi_is_activated(&state); + if (state == false) + return -1; + + printf("Input a part of AP name to forget : "); + rv = scanf("%32s", ap_name); + + rv = wifi_foreach_found_aps(__test_found_forget_ap_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to forget (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Forget AP finished\n"); + return 1; +} + +int test_connect_eap_ap(void) +{ + int rv = 0; + char ap_name[33]; + bool state = false; + + wifi_is_activated(&state); + if (state == false) + return -1; + + printf("Input a part of AP name to connect : "); + rv = scanf("%32s", ap_name); + + rv = wifi_foreach_found_aps(__test_found_eap_ap_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to connect (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Connection step finished\n"); + return 1; +} + +int test_set_ip_method(void) +{ + int rv; + char ap_name[33]; + bool state; + + rv = wifi_is_activated(&state); + if (rv != WIFI_ERROR_NONE || state == false) + return -1; + + printf("Input a part of AP name to change IP method : "); + rv = scanf("%32s", ap_name); + if (rv <= 0) + return -1; + + rv = wifi_foreach_found_aps(__test_found_change_ip_method_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to change (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("IP method changing finished\n"); + return 1; +} + +int test_set_proxy_method(void) +{ + int rv; + char ap_name[33]; + bool state; + + rv = wifi_is_activated(&state); + if (rv != WIFI_ERROR_NONE || state == false) + return -1; + + printf("Input a part of AP name to change Proxy method : "); + rv = scanf("%32s", ap_name); + if (rv <= 0) + return -1; + + rv = wifi_foreach_found_aps(__test_found_change_proxy_method_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to change (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("Proxy method changing finished\n"); + return 1; +} + +int test_get_ap_info(void) +{ + int rv; + char ap_name[33]; + bool state; + + rv = wifi_is_activated(&state); + if (rv != WIFI_ERROR_NONE || state == false) + return -1; + + printf("Input a part of AP name to get detailed info : "); + rv = scanf("%32s", ap_name); + if (rv <= 0) + return -1; + + rv = wifi_foreach_found_aps(__test_found_print_ap_info_callback, ap_name); + if (rv != WIFI_ERROR_NONE) { + printf("Fail to get AP info (can't get AP list) [%s]\n", __test_convert_error_to_string(rv)); + return -1; + } + + printf("AP info printing finished\n"); + return 1; +} + +int main(int argc, char **argv) +{ + GMainLoop *mainloop; + mainloop = g_main_loop_new (NULL, FALSE); + + GIOChannel *channel = g_io_channel_unix_new(0); + g_io_add_watch(channel, (G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL), test_thread, NULL); + + printf("Test Thread created...\n"); + + g_main_loop_run (mainloop); + + return 0; +} + +gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) +{ + int rv; + char a[10]; + + printf("Event received from stdin\n"); + + rv = read(0, a, 10); + + if (rv <= 0 || a[0] == '0') { + rv = wifi_deinitialize(); + + if (rv != WIFI_ERROR_NONE) + printf("Fail to deinitialize.\n"); + + exit(1); + } + + if (a[0] == '\n' || a[0] == '\r') { + printf("\n\n Network Connection API Test App\n\n"); + printf("Options..\n"); + printf("1 - Wi-Fi init and set callbacks\n"); + printf("2 - Wi-Fi deinit(unset callbacks automatically)\n"); + printf("3 - Activate Wi-Fi device\n"); + printf("4 - Deactivate Wi-Fi device\n"); + printf("5 - Is Wi-Fi activated?\n"); + printf("6 - Get connection state\n"); + printf("7 - Get MAC address\n"); + printf("8 - Get Wi-Fi interface name\n"); + printf("9 - Scan request\n"); + printf("a - Get Connected AP\n"); + printf("b - Get AP list\n"); + printf("c - Connect\n"); + printf("d - Disconnect\n"); + printf("e - Connect by wps pbc\n"); + printf("f - Forget an AP\n"); + printf("g - Set & connect EAP\n"); + printf("h - Set IP method type\n"); + printf("i - Set Proxy method type\n"); + printf("j - Get Ap info\n"); + printf("0 - Exit \n"); + + printf("ENTER - Show options menu.......\n"); + } + + switch (a[0]) { + case '1': + rv = test_wifi_init(); + break; + case '2': + rv = test_wifi_deinit(); + break; + case '3': + rv = test_wifi_activate(); + break; + case '4': + rv = test_wifi_deactivate(); + break; + case '5': + rv = test_is_activated(); + break; + case '6': + rv = test_get_connection_state(); + break; + case '7': + rv = test_get_mac_address(); + break; + case '8': + rv = test_get_interface_name(); + break; + case '9': + rv = test_scan_request(); + break; + case 'a': + rv = test_get_connected_ap(); + break; + case 'b': + rv = test_foreach_found_aps(); + break; + case 'c': + rv = test_connect_ap(); + break; + case 'd': + rv = test_disconnect_ap(); + break; + case 'e': + rv = test_connect_wps(); + break; + case 'f': + rv = test_forget_ap(); + break; + case 'g': + rv = test_connect_eap_ap(); + break; + case 'h': + rv = test_set_ip_method(); + break; + case 'i': + rv = test_set_proxy_method(); + break; + case 'j': + rv = test_get_ap_info(); + break; + default: + break; + } + + if (rv == 1) + printf("Operation succeeded!\n"); + else + printf("Operation filed!\n"); + + return TRUE; +} +