From 5c3be6619673e4d19a36059a282815d0809908d9 Mon Sep 17 00:00:00 2001 From: Sehong Na Date: Sat, 31 May 2014 12:54:14 +0900 Subject: [PATCH 1/1] Initialize Tizen 2.3 --- .gitignore | 25 + mobile/AUTHORS | 5 + mobile/CMakeLists.txt | 95 + mobile/LICENSE.APLv2 | 202 ++ mobile/NOTICE | 3 + mobile/include/emulator.h | 36 + mobile/include/log.h | 43 + mobile/include/netconfig.h | 33 + mobile/include/netdbus.h | 84 + mobile/include/neterror.h | 69 + mobile/include/netsupplicant.h | 52 + mobile/include/network-clock.h | 34 + mobile/include/network-state.h | 59 + mobile/include/network-statistics.h | 74 + mobile/include/signal-handler.h | 34 + mobile/include/util.h | 59 + mobile/include/wifi-agent.h | 41 + mobile/include/wifi-background-scan.h | 44 + mobile/include/wifi-eap-config.h | 52 + mobile/include/wifi-eap.h | 39 + mobile/include/wifi-indicator.h | 36 + mobile/include/wifi-power.h | 41 + mobile/include/wifi-ssid-scan.h | 51 + mobile/include/wifi-state.h | 75 + mobile/include/wifi.h | 62 + .../interfaces/netconfig-iface-network-state.xml | 17 + .../netconfig-iface-network-statistics.xml | 33 + mobile/interfaces/netconfig-iface-wifi.xml | 61 + mobile/net-config.manifest | 16 + mobile/net-config.rule | 8 + .../resources/etc/dbus-1/system.d/net-config.conf | 22 + mobile/resources/opt/etc/resolv.conf | 2 + .../usr/lib/systemd/system/net-config.service | 10 + .../share/dbus-1/services/net.netconfig.service | 4 + mobile/src/dbus/netdbus.c | 526 ++++++ mobile/src/dbus/netsupplicant.c | 273 +++ mobile/src/main.c | 140 ++ mobile/src/neterror.c | 89 + mobile/src/network-clock.c | 114 ++ mobile/src/network-state.c | 666 +++++++ mobile/src/network-statistics.c | 452 +++++ mobile/src/signal-handler.c | 372 ++++ mobile/src/utils/emulator.c | 119 ++ mobile/src/utils/util.c | 429 +++++ mobile/src/wifi-agent.c | 203 ++ mobile/src/wifi-background-scan.c | 286 +++ mobile/src/wifi-eap-config.c | 216 +++ mobile/src/wifi-eap.c | 471 +++++ mobile/src/wifi-indicator.c | 287 +++ mobile/src/wifi-power.c | 441 +++++ mobile/src/wifi-ssid-scan.c | 496 +++++ mobile/src/wifi-state.c | 455 +++++ mobile/src/wifi.c | 173 ++ packaging/net-config.spec | 253 +++ wearable/AUTHORS | 5 + wearable/CMakeLists.txt | 106 ++ wearable/LICENSE | 203 ++ wearable/LICENSE-FLORA | 75 + wearable/debian/changelog | 1970 ++++++++++++++++++++ wearable/debian/compat | 1 + wearable/debian/control | 17 + wearable/debian/net-config.install.in | 7 + wearable/debian/net-config.postinst | 35 + wearable/debian/rules | 136 ++ wearable/include/cellular-state.h | 54 + wearable/include/emulator.h | 36 + wearable/include/log.h | 52 + wearable/include/netdbus.h | 82 + wearable/include/neterror.h | 50 + wearable/include/netsupplicant.h | 65 + wearable/include/network-accessibility.h | 44 + wearable/include/network-clock.h | 34 + wearable/include/network-state.h | 72 + wearable/include/network-statistics.h | 99 + wearable/include/signal-handler.h | 34 + wearable/include/util.h | 70 + wearable/include/wifi-agent.h | 53 + wearable/include/wifi-background-scan.h | 43 + wearable/include/wifi-ccode.h | 33 + wearable/include/wifi-eap-config.h | 40 + wearable/include/wifi-eap.h | 44 + wearable/include/wifi-firmware.h | 47 + wearable/include/wifi-indicator.h | 37 + wearable/include/wifi-passpoint.h | 38 + wearable/include/wifi-power.h | 46 + wearable/include/wifi-ssid-scan.h | 43 + wearable/include/wifi-state.h | 85 + wearable/include/wifi-wps.h | 41 + wearable/include/wifi.h | 61 + .../interfaces/netconfig-iface-network-state.xml | 17 + .../netconfig-iface-network-statistics.xml | 33 + wearable/interfaces/netconfig-iface-wifi.xml | 87 + wearable/net-config.manifest | 48 + .../resources/etc/dbus-1/system.d/net-config.conf | 22 + wearable/resources/etc/resolv.conf | 6 + wearable/resources/etc/wifi/ccode.conf | 237 +++ .../opt/etc/dump.d/module.d/network_log_dump.sh | 20 + .../usr/lib/systemd/system/net-config.service | 13 + wearable/resources/usr/sbin/net-config.service | 23 + .../share/dbus-1/services/net.netconfig.service | 4 + wearable/resources/usr/share/wifi_offloading.sql | 18 + wearable/src/cellular-state.c | 80 + wearable/src/dbus/netdbus.c | 502 +++++ wearable/src/dbus/netsupplicant.c | 355 ++++ wearable/src/main.c | 84 + wearable/src/neterror.c | 157 ++ wearable/src/network-clock.c | 117 ++ wearable/src/network-state.c | 1080 +++++++++++ wearable/src/network-statistics.c | 452 +++++ wearable/src/signal-handler.c | 519 ++++++ wearable/src/utils/emulator.c | 120 ++ wearable/src/utils/log.c | 126 ++ wearable/src/utils/network-accessibility.c | 555 ++++++ wearable/src/utils/util.c | 511 +++++ wearable/src/wifi-agent.c | 603 ++++++ wearable/src/wifi-background-scan.c | 247 +++ wearable/src/wifi-ccode.c | 162 ++ wearable/src/wifi-eap-config.c | 363 ++++ wearable/src/wifi-eap.c | 554 ++++++ wearable/src/wifi-firmware.c | 298 +++ wearable/src/wifi-indicator.c | 353 ++++ wearable/src/wifi-passpoint.c | 110 ++ wearable/src/wifi-power.c | 662 +++++++ wearable/src/wifi-ssid-scan.c | 506 +++++ wearable/src/wifi-state.c | 704 +++++++ wearable/src/wifi-wps.c | 610 ++++++ wearable/src/wifi.c | 139 ++ 127 files changed, 22337 insertions(+) create mode 100644 .gitignore create mode 100644 mobile/AUTHORS create mode 100644 mobile/CMakeLists.txt create mode 100644 mobile/LICENSE.APLv2 create mode 100644 mobile/NOTICE create mode 100644 mobile/include/emulator.h create mode 100644 mobile/include/log.h create mode 100644 mobile/include/netconfig.h create mode 100644 mobile/include/netdbus.h create mode 100644 mobile/include/neterror.h create mode 100644 mobile/include/netsupplicant.h create mode 100644 mobile/include/network-clock.h create mode 100644 mobile/include/network-state.h create mode 100644 mobile/include/network-statistics.h create mode 100644 mobile/include/signal-handler.h create mode 100644 mobile/include/util.h create mode 100644 mobile/include/wifi-agent.h create mode 100644 mobile/include/wifi-background-scan.h create mode 100644 mobile/include/wifi-eap-config.h create mode 100644 mobile/include/wifi-eap.h create mode 100644 mobile/include/wifi-indicator.h create mode 100644 mobile/include/wifi-power.h create mode 100644 mobile/include/wifi-ssid-scan.h create mode 100644 mobile/include/wifi-state.h create mode 100644 mobile/include/wifi.h create mode 100644 mobile/interfaces/netconfig-iface-network-state.xml create mode 100644 mobile/interfaces/netconfig-iface-network-statistics.xml create mode 100644 mobile/interfaces/netconfig-iface-wifi.xml create mode 100644 mobile/net-config.manifest create mode 100644 mobile/net-config.rule create mode 100644 mobile/resources/etc/dbus-1/system.d/net-config.conf create mode 100644 mobile/resources/opt/etc/resolv.conf create mode 100644 mobile/resources/usr/lib/systemd/system/net-config.service create mode 100644 mobile/resources/usr/share/dbus-1/services/net.netconfig.service create mode 100644 mobile/src/dbus/netdbus.c create mode 100644 mobile/src/dbus/netsupplicant.c create mode 100644 mobile/src/main.c create mode 100644 mobile/src/neterror.c create mode 100644 mobile/src/network-clock.c create mode 100644 mobile/src/network-state.c create mode 100644 mobile/src/network-statistics.c create mode 100644 mobile/src/signal-handler.c create mode 100644 mobile/src/utils/emulator.c create mode 100644 mobile/src/utils/util.c create mode 100644 mobile/src/wifi-agent.c create mode 100644 mobile/src/wifi-background-scan.c create mode 100644 mobile/src/wifi-eap-config.c create mode 100644 mobile/src/wifi-eap.c create mode 100644 mobile/src/wifi-indicator.c create mode 100644 mobile/src/wifi-power.c create mode 100644 mobile/src/wifi-ssid-scan.c create mode 100644 mobile/src/wifi-state.c create mode 100644 mobile/src/wifi.c create mode 100644 packaging/net-config.spec create mode 100644 wearable/AUTHORS create mode 100644 wearable/CMakeLists.txt create mode 100644 wearable/LICENSE create mode 100755 wearable/LICENSE-FLORA create mode 100644 wearable/debian/changelog create mode 100644 wearable/debian/compat create mode 100644 wearable/debian/control create mode 100644 wearable/debian/net-config.install.in create mode 100644 wearable/debian/net-config.postinst create mode 100755 wearable/debian/rules create mode 100644 wearable/include/cellular-state.h create mode 100644 wearable/include/emulator.h create mode 100644 wearable/include/log.h create mode 100644 wearable/include/netdbus.h create mode 100644 wearable/include/neterror.h create mode 100644 wearable/include/netsupplicant.h create mode 100644 wearable/include/network-accessibility.h create mode 100644 wearable/include/network-clock.h create mode 100644 wearable/include/network-state.h create mode 100644 wearable/include/network-statistics.h create mode 100644 wearable/include/signal-handler.h create mode 100644 wearable/include/util.h create mode 100644 wearable/include/wifi-agent.h create mode 100644 wearable/include/wifi-background-scan.h create mode 100644 wearable/include/wifi-ccode.h create mode 100644 wearable/include/wifi-eap-config.h create mode 100644 wearable/include/wifi-eap.h create mode 100644 wearable/include/wifi-firmware.h create mode 100644 wearable/include/wifi-indicator.h create mode 100644 wearable/include/wifi-passpoint.h create mode 100644 wearable/include/wifi-power.h create mode 100644 wearable/include/wifi-ssid-scan.h create mode 100644 wearable/include/wifi-state.h create mode 100644 wearable/include/wifi-wps.h create mode 100644 wearable/include/wifi.h create mode 100644 wearable/interfaces/netconfig-iface-network-state.xml create mode 100644 wearable/interfaces/netconfig-iface-network-statistics.xml create mode 100644 wearable/interfaces/netconfig-iface-wifi.xml create mode 100644 wearable/net-config.manifest create mode 100644 wearable/resources/etc/dbus-1/system.d/net-config.conf create mode 100644 wearable/resources/etc/resolv.conf create mode 100644 wearable/resources/etc/wifi/ccode.conf create mode 100755 wearable/resources/opt/etc/dump.d/module.d/network_log_dump.sh create mode 100644 wearable/resources/usr/lib/systemd/system/net-config.service create mode 100755 wearable/resources/usr/sbin/net-config.service create mode 100644 wearable/resources/usr/share/dbus-1/services/net.netconfig.service create mode 100644 wearable/resources/usr/share/wifi_offloading.sql create mode 100644 wearable/src/cellular-state.c create mode 100644 wearable/src/dbus/netdbus.c create mode 100644 wearable/src/dbus/netsupplicant.c create mode 100644 wearable/src/main.c create mode 100644 wearable/src/neterror.c create mode 100644 wearable/src/network-clock.c create mode 100644 wearable/src/network-state.c create mode 100644 wearable/src/network-statistics.c create mode 100644 wearable/src/signal-handler.c create mode 100644 wearable/src/utils/emulator.c create mode 100644 wearable/src/utils/log.c create mode 100644 wearable/src/utils/network-accessibility.c create mode 100644 wearable/src/utils/util.c create mode 100644 wearable/src/wifi-agent.c create mode 100644 wearable/src/wifi-background-scan.c create mode 100644 wearable/src/wifi-ccode.c create mode 100644 wearable/src/wifi-eap-config.c create mode 100644 wearable/src/wifi-eap.c create mode 100644 wearable/src/wifi-firmware.c create mode 100644 wearable/src/wifi-indicator.c create mode 100644 wearable/src/wifi-passpoint.c create mode 100644 wearable/src/wifi-power.c create mode 100644 wearable/src/wifi-ssid-scan.c create mode 100644 wearable/src/wifi-state.c create mode 100644 wearable/src/wifi-wps.c create mode 100644 wearable/src/wifi.c diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..83f06ae --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ +*.[oa] +*~ +build-stamp +cmake_build_tmp +configure-stamp +debian/files +debian/net-config-dbg.debhelper.log +debian/net-config-dbg.substvars +debian/net-config-dbg +debian/net-config.debhelper.log +debian/net-config.install +debian/net-config.substvars +debian/net-config +debian/net.netconfig.service +debian/tmp +netconfig-iface*-glue.h +.project +.cproject +.settings diff --git a/mobile/AUTHORS b/mobile/AUTHORS new file mode 100644 index 0000000..df0456d --- /dev/null +++ b/mobile/AUTHORS @@ -0,0 +1,5 @@ +Danny Jeongseok Seo +Jeik Jaehyun Kim +Sunkey Lee +Sanghoon Cho +DongHoo Park \ No newline at end of file diff --git a/mobile/CMakeLists.txt b/mobile/CMakeLists.txt new file mode 100644 index 0000000..0d8384e --- /dev/null +++ b/mobile/CMakeLists.txt @@ -0,0 +1,95 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(net-config C) +SET(PACKAGE ${PROJECT_NAME}) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(BINDIR "${PREFIX}/sbin") +SET(DATADIR "${PREFIX}/share") +SET(LIBDIR "${PREFIX}/lib") + +SET(SRCS + src/main.c + src/neterror.c + src/wifi.c + src/wifi-power.c + src/wifi-state.c + src/wifi-eap.c + src/network-clock.c + src/network-state.c + src/network-statistics.c + src/wifi-indicator.c + src/signal-handler.c + src/wifi-ssid-scan.c + src/wifi-background-scan.c + src/wifi-agent.c + src/wifi-eap-config.c + src/dbus/netdbus.c + src/dbus/netsupplicant.c + src/utils/util.c + src/utils/emulator.c + ) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(pkgs REQUIRED + glib-2.0 + dbus-glib-1 + dlog + vconf + wifi-direct + tapi + syspopup-caller + libsystemd-daemon) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden -Wall") +SET(CMAKE_C_FLAGS "-I${CMAKE_SOURCE_DIR}/include ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" +OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DEMBEDDED_TARGET") + MESSAGE("add -DEMBEDDED_TARGET") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"") +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) + +ADD_CUSTOM_TARGET(netconfig-iface-network-state-glue.h + COMMAND dbus-binding-tool --mode=glib-server --prefix=netconfig_iface_network_state + --output=${CMAKE_SOURCE_DIR}/include/netconfig-iface-network-state-glue.h + ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-state.xml + DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-state.xml +) +ADD_CUSTOM_TARGET(netconfig-iface-network-statistics-glue.h + COMMAND dbus-binding-tool --mode=glib-server --prefix=netconfig_iface_network_statistics + --output=${CMAKE_SOURCE_DIR}/include/netconfig-iface-network-statistics-glue.h + ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-statistics.xml + DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-statistics.xml +) +ADD_CUSTOM_TARGET(netconfig-iface-wifi-glue.h + COMMAND dbus-binding-tool --mode=glib-server --prefix=netconfig_iface_wifi + --output=${CMAKE_SOURCE_DIR}/include/netconfig-iface-wifi-glue.h + ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-wifi.xml + DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-wifi.xml +) + +ADD_DEPENDENCIES(${PROJECT_NAME} netconfig-iface-network-state-glue.h) +ADD_DEPENDENCIES(${PROJECT_NAME} netconfig-iface-network-statistics-glue.h) +ADD_DEPENDENCIES(${PROJECT_NAME} netconfig-iface-wifi-glue.h) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR}) diff --git a/mobile/LICENSE.APLv2 b/mobile/LICENSE.APLv2 new file mode 100644 index 0000000..d645695 --- /dev/null +++ b/mobile/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/mobile/NOTICE b/mobile/NOTICE new file mode 100644 index 0000000..0e0f016 --- /dev/null +++ b/mobile/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/mobile/include/emulator.h b/mobile/include/emulator.h new file mode 100644 index 0000000..87914b8 --- /dev/null +++ b/mobile/include/emulator.h @@ -0,0 +1,36 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_EMULATOR_H__ +#define __NETCONFIG_EMULATOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +gboolean netconfig_emulator_is_emulated(void); +void netconfig_emulator_test_and_start(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_EMULATOR_H__ */ diff --git a/mobile/include/log.h b/mobile/include/log.h new file mode 100644 index 0000000..028f2c6 --- /dev/null +++ b/mobile/include/log.h @@ -0,0 +1,43 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_LOG_H__ +#define __NETCONFIG_LOG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#undef LOG_TAG +#define LOG_TAG "NET_CONFIG" + +#define DBG(format, arg...) LOGD(format, ## arg) +#define INFO(format, arg...) LOGI(format, ## arg) +#define WARN(format, arg...) LOGW(format, ## arg) +#define ERR(format, arg...) LOGE(format, ## arg) + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_LOG_H__ */ diff --git a/mobile/include/netconfig.h b/mobile/include/netconfig.h new file mode 100644 index 0000000..0336419 --- /dev/null +++ b/mobile/include/netconfig.h @@ -0,0 +1,33 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_H__ +#define __NETCONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#define NETCONFIG_SERVICE "net.netconfig" + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_H__ */ diff --git a/mobile/include/netdbus.h b/mobile/include/netdbus.h new file mode 100644 index 0000000..8f58900 --- /dev/null +++ b/mobile/include/netdbus.h @@ -0,0 +1,84 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_NETDBUS_H__ +#define __NETCONFIG_NETDBUS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define CONNMAN_SERVICE "net.connman" +#define CONNMAN_PATH "/net/connman" + +#define CONNMAN_CLOCK_INTERFACE CONNMAN_SERVICE ".Clock" +#define CONNMAN_ERROR_INTERFACE CONNMAN_SERVICE ".Error" +#define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" +#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" +#define CONNMAN_TECHNOLOGY_INTERFACE CONNMAN_SERVICE ".Technology" +#define CONNMAN_MANAGER_PATH "/" + +#define CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/cellular_" +#define CONNMAN_WIFI_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/wifi_" +#define CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/ethernet_" +#define CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/bluetooth_" +#define CONNMAN_CELLULAR_TECHNOLOGY_PREFIX CONNMAN_PATH "/technology/cellular" +#define CONNMAN_WIFI_TECHNOLOGY_PREFIX CONNMAN_PATH "/technology/wifi" + +#define NETCONFIG_WIFI_INTERFACE "net.netconfig.wifi" +#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi" + +#define DBUS_PATH_MAX_BUFLEN 512 +#define DBUS_STATE_MAX_BUFLEN 64 + +typedef enum { + NETCONFIG_DBUS_RESULT_GET_BGSCAN_MODE, + NETCONFIG_DBUS_RESULT_DEFAULT_TECHNOLOGY, +} netconfig_dbus_result_type; + +gboolean netconfig_is_cellular_profile(const char *profile); +gboolean netconfig_is_wifi_profile(const char *profile); +gboolean netconfig_is_ethernet_profile(const char *profile); +gboolean netconfig_is_bluetooth_profile(const char *profile); + +char *netconfig_wifi_get_connected_service_name(DBusMessage *message); + +gboolean netconfig_invoke_dbus_method_nonblock( + const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[], + DBusPendingCallNotifyFunction notify_func); +DBusMessage *netconfig_invoke_dbus_method(const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[]); + +gboolean netconfig_dbus_get_basic_params_string(DBusMessage *message, + char **key, int type, void *value); +gboolean netconfig_dbus_get_basic_params_array(DBusMessage *message, + char **key, void **value); + +DBusGConnection *netconfig_setup_dbus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETDBUS_H__ */ diff --git a/mobile/include/neterror.h b/mobile/include/neterror.h new file mode 100644 index 0000000..98b0f4b --- /dev/null +++ b/mobile/include/neterror.h @@ -0,0 +1,69 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_ERROR_H__ +#define __NETCONFIG_ERROR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "glib.h" + +G_BEGIN_DECLS + +typedef enum { + NETCONFIG_NO_ERROR = 0x00, + NETCONFIG_ERROR_INTERNAL = 0x01, + NETCONFIG_ERROR_NO_SERVICE = 0x02, + NETCONFIG_ERROR_TRASPORT = 0x03, + NETCONFIG_ERROR_NO_PROFILE = 0x04, + NETCONFIG_ERROR_WRONG_PROFILE = 0x05, + NETCONFIG_ERROR_WIFI_LOAD_INPROGRESS = 0x06, + NETCONFIG_ERROR_WIFI_DRIVER_FAILURE = 0x07, + NETCONFIG_ERROR_SECURITY_RESTRICTED = 0x08, + NETCONFIG_ERROR_FAILED_GET_IMSI = 0x09, + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH = 0x0A, + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM = 0x0B, + NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA = 0x0C, + NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY = 0x0D, + NETCONFIG_ERROR_MAX = 0x0E, +} NETCONFIG_ERROR; + +GQuark netconfig_error_quark(void); + +#define NETCONFIG_ERROR_QUARK (netconfig_error_quark()) + +G_END_DECLS + +#ifdef __cplusplus +} +#endif + +void netconfig_error_wifi_load_inprogress(GError **error); +void netconfig_error_wifi_driver_failed(GError **error); +void netconfig_error_security_restricted(GError **error); +void netconfig_error_wifi_direct_failed(GError **error); +void netconfig_error_fail_get_imsi(GError **error); +void netconfig_error_fail_req_sim_auth(GError **error); +void netconfig_error_fail_req_sim_auth_wrong_param(GError **error); +void netconfig_error_fail_get_sim_auth_wrong_data(GError **error); +void netconfig_error_fail_get_sim_auth_delay(GError **error); + +#endif /* __NETCONFIG_ERROR_H__ */ diff --git a/mobile/include/netsupplicant.h b/mobile/include/netsupplicant.h new file mode 100644 index 0000000..ea5ae37 --- /dev/null +++ b/mobile/include/netsupplicant.h @@ -0,0 +1,52 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_NETSUPPLICANT_H__ +#define __NETCONFIG_NETSUPPLICANT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define SUPPLICANT_SERVICE "fi.w1.wpa_supplicant1" +#define SUPPLICANT_INTERFACE "fi.w1.wpa_supplicant1" +#define SUPPLICANT_PATH "/fi/w1/wpa_supplicant1" +#define SUPPLICANT_GLOBAL_INTERFACE "org.freedesktop.DBus.Properties" + +struct dbus_input_arguments { + int type; + void *data; +}; + +gboolean netconfig_wifi_get_ifname(char **ifname); +gboolean netconfig_wifi_get_supplicant_interface(char **path); +DBusMessage *netconfig_supplicant_invoke_dbus_method(const char *dest, + DBusConnection *connection, + const char *path, const char *interface_name, + const char *method, GList *args); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETSUPPLICANT_H__ */ diff --git a/mobile/include/network-clock.h b/mobile/include/network-clock.h new file mode 100644 index 0000000..4b1b810 --- /dev/null +++ b/mobile/include/network-clock.h @@ -0,0 +1,34 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_NETWORK_CLOCK_H__ +#define __NETCONFIG_NETWORK_CLOCK_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void netconfig_clock_init(void); +void netconfig_clock_deinit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETWORK_CLOCK_H__ */ diff --git a/mobile/include/network-state.h b/mobile/include/network-state.h new file mode 100644 index 0000000..0f180c8 --- /dev/null +++ b/mobile/include/network-state.h @@ -0,0 +1,59 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_NETWORK_STATE_H__ +#define __NETCONFIG_NETWORK_STATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +G_BEGIN_DECLS + +typedef struct NetconfigNetworkState NetconfigNetworkState; +typedef struct NetconfigNetworkStateClass NetconfigNetworkStateClass; + +#define NETCONFIG_TYPE_NETWORK_STATE ( netconfig_network_state_get_type() ) +#define NETCONFIG_NETWORK_STATE(obj) ( G_TYPE_CHECK_INSTANCE_CAST( (obj),NETCONFIG_TYPE_NETWORK_STATE, NetconfigNetworkState ) ) +#define NETCONFIG_IS_NETWORK_STATE(obj) (G_TYPE_CHECK_INSTANCE_TYPE( (obj), NETCONFIG_TYPE_NETWORK_STATE) ) + +#define NETCONFIG_NETWORK_STATE_CLASS(klass) ( G_TYPE_CHECK_CLASS_CAST( (klass), NETCONFIG_TYPE_NETWORK_STATE, NetconfigNetworkStateClass) ) +#define NETCONFIG_IS_NETWORK_STATE_CLASS(klass) ( G_TYPE_CHECK_CLASS_TYPE( (klass), NETCONFIG_TYPE_NETWORK_STATE) ) +#define NETCONFIG_NETWORK_STATE_GET_CLASS(obj) ( G_TYPE_INSTANCE_GET_CLASS( (obj), NETCONFIG_TYPE_NETWORK_STATE, NetconfigNetworkStateClass ) ) + +GType netconfig_network_state_get_type(void); + +gpointer netconfig_network_state_create_and_init(DBusGConnection *conn); + +const char *netconfig_get_default_profile(void); +const char *netconfig_get_default_ipaddress(void); +const char *netconfig_get_default_proxy(void); +const char *netconfig_wifi_get_connected_essid(const char *default_profile); +void netconfig_set_default_profile(const char *profile); + +G_END_DECLS + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETWORK_STATE_H__ */ diff --git a/mobile/include/network-statistics.h b/mobile/include/network-statistics.h new file mode 100644 index 0000000..5149844 --- /dev/null +++ b/mobile/include/network-statistics.h @@ -0,0 +1,74 @@ +/* + * Network Configuration Module + * + * 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 NETWORK_STATISTICS_H_ +#define NETWORK_STATISTICS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include + +G_BEGIN_DECLS + +typedef struct NetconfigNetworkStatistics NetconfigNetworkStatistics; +typedef struct NetconfigNetworkStatisticsClass NetconfigNetworkStatisticsClass; + +#define NETCONFIG_TYPE_NETWORK_STATISTICS ( netconfig_network_statistics_get_type() ) +#define NETCONFIG_NETWORK_STATISTICS(obj) ( G_TYPE_CHECK_INSTANCE_CAST( (obj),NETCONFIG_TYPE_NETWORK_STATISTICS, NetconfigNetworkStatistics ) ) +#define NETCONFIG_IS_NETWORK_STATISTICS(obj) (G_TYPE_CHECK_INSTANCE_TYPE( (obj), NETCONFIG_TYPE_NETWORK_STATISTICS) ) + +#define NETCONFIG_NETWORK_STATISTICS_CLASS(klass) ( G_TYPE_CHECK_CLASS_CAST( (klass), NETCONFIG_TYPE_NETWORK_STATISTICS, NetconfigNetworkStatisticsClass) ) +#define NETCONFIG_IS_NETWORK_STATISTICS_CLASS(klass) ( G_TYPE_CHECK_CLASS_TYPE( (klass), NETCONFIG_TYPE_NETWORK_STATISTICS) ) +#define NETCONFIG_NETWORK_STATISTICS_GET_CLASS(obj) ( G_TYPE_INSTANCE_GET_CLASS( (obj), NETCONFIG_TYPE_NETWORK_STATISTICS, NetconfigNetworkStatisticsClass ) ) + +GType netconfig_network_statistics_get_type(void); + +gpointer netconfig_network_statistics_create_and_init(DBusGConnection *conn); + + +gboolean netconfig_iface_network_statistics_get_wifi_total_tx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *total_bytes, GError **error); +gboolean netconfig_iface_network_statistics_get_wifi_total_rx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *total_bytes, GError **error); +gboolean netconfig_iface_network_statistics_get_wifi_last_tx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *last_bytes, GError **error); +gboolean netconfig_iface_network_statistics_get_wifi_last_rx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *last_bytes, GError **error); + +gboolean netconfig_iface_network_statistics_reset_cellular_total_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_cellular_total_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_cellular_last_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_cellular_last_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); + +gboolean netconfig_iface_network_statistics_reset_wifi_total_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_wifi_total_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_wifi_last_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_wifi_last_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error); + +gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx); +void netconfig_wifi_statistics_update_powered_off(void); + +G_END_DECLS + +#ifdef __cplusplus +} +#endif + +#endif /* NETWORK_STATISTICS_H_ */ diff --git a/mobile/include/signal-handler.h b/mobile/include/signal-handler.h new file mode 100644 index 0000000..d802ef8 --- /dev/null +++ b/mobile/include/signal-handler.h @@ -0,0 +1,34 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_SIGNAL_HANDLER_H__ +#define __NETCONFIG_SIGNAL_HANDLER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void netconfig_register_signal(void); +void netconfig_deregister_signal(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_SIGNAL_HANDLER_H__ */ diff --git a/mobile/include/util.h b/mobile/include/util.h new file mode 100644 index 0000000..8a37f8a --- /dev/null +++ b/mobile/include/util.h @@ -0,0 +1,59 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_UTIL_H__ +#define __NETCONFIG_UTIL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "wifi.h" + +GKeyFile *netconfig_keyfile_load(const char *pathname); +void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname); + +void netconfig_start_timer_seconds(guint secs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id); +void netconfig_start_timer(guint msecs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id); +void netconfig_stop_timer(guint *timer_id); + +void netconfig_wifi_device_picker_service_start(void); +void netconfig_wifi_device_picker_service_stop(void); + +gboolean netconfig_is_wifi_direct_on(void); +gboolean netconfig_is_wifi_tethering_on(void); + +gboolean netconfig_execute_file(const char *file_path, + char *const args[], char *const env[]); + +gboolean netconfig_iface_wifi_launch_direct(NetconfigWifi *wifi, GError **error); +void netconfig_set_wifi_mac_address(void); + +void netconfig_add_wifi_found_notification(void); +void netconfig_del_wifi_found_notification(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_UTIL_H__ */ diff --git a/mobile/include/wifi-agent.h b/mobile/include/wifi-agent.h new file mode 100644 index 0000000..274a493 --- /dev/null +++ b/mobile/include/wifi-agent.h @@ -0,0 +1,41 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_AGENT_H__ +#define __NETCONFIG_WIFI_AGENT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_agent_register(void); +gboolean netconfig_agent_unregister(void); +gboolean netconfig_iface_wifi_set_field(NetconfigWifi *wifi, + GHashTable *fields, GError **error); +gboolean netconfig_iface_wifi_request_input(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_AGENT_H__ */ diff --git a/mobile/include/wifi-background-scan.h b/mobile/include/wifi-background-scan.h new file mode 100644 index 0000000..999400b --- /dev/null +++ b/mobile/include/wifi-background-scan.h @@ -0,0 +1,44 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFIBACKGROUND_SCAN_H__ +#define __NETCONFIG_WIFIBACKGROUND_SCAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +void netconfig_wifi_bgscan_start(void); +void netconfig_wifi_bgscan_stop(void); +gboolean netconfig_wifi_get_bgscan_state(void); + +gboolean netconfig_wifi_get_scanning(void); +void netconfig_wifi_set_scanning(gboolean scanning); + +gboolean netconfig_iface_wifi_set_bgscan(NetconfigWifi *wifi, guint scan_mode, GError **error); +void netconfig_wifi_init_bgscan(); +void netconfig_wifi_deinit_bgscan(); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFIBACKGROUND_SCAN_H__ */ diff --git a/mobile/include/wifi-eap-config.h b/mobile/include/wifi-eap-config.h new file mode 100644 index 0000000..95ae43e --- /dev/null +++ b/mobile/include/wifi-eap-config.h @@ -0,0 +1,52 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_EAP_CONFIG_H__ +#define __NETCONFIG_WIFI_EAP_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +#define CONNMAN_STORAGEDIR "/var/lib/connman" + +#define CONNMAN_CONFIG_FIELD_TYPE "Type" +#define CONNMAN_CONFIG_FIELD_NAME "Name" +#define CONNMAN_CONFIG_FIELD_SSID "SSID" +#define CONNMAN_CONFIG_FIELD_EAP_METHOD "EAP" +#define CONNMAN_CONFIG_FIELD_IDENTITY "Identity" +#define CONNMAN_CONFIG_FIELD_PASSPHRASE "Passphrase" +#define CONNMAN_CONFIG_FIELD_PHASE2 "Phase2" +#define CONNMAN_CONFIG_FIELD_CA_CERT_FILE "CACertFile" +#define CONNMAN_CONFIG_FIELD_CLIENT_CERT_FILE "ClientCertFile" +#define CONNMAN_CONFIG_FIELD_PVT_KEY_FILE "PrivateKeyFile" +#define CONNMAN_CONFIG_FIELD_PVT_KEY_PASSPHRASE "PrivateKeyPassphrase" + +gboolean netconfig_iface_wifi_create_config(NetconfigWifi *wifi, + GHashTable *fields, GError **error); +gboolean netconfig_iface_wifi_delete_config(NetconfigWifi *wifi, + gchar *profile, GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_EAP_CONFIG_H__ */ diff --git a/mobile/include/wifi-eap.h b/mobile/include/wifi-eap.h new file mode 100644 index 0000000..0338629 --- /dev/null +++ b/mobile/include/wifi-eap.h @@ -0,0 +1,39 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_EAP_H__ +#define __NETCONFIG_WIFI_EAP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_iface_wifi_get_sim_imsi(NetconfigWifi *wifi, DBusGMethodInvocation *context); +gboolean netconfig_iface_wifi_req_sim_auth(NetconfigWifi *wifi, GArray *rand_data, gboolean *result, GError **error); +gboolean netconfig_iface_wifi_req_aka_auth(NetconfigWifi *wifi, GArray *rand_data, GArray *autn_data, gboolean *result, GError **error); +gboolean netconfig_iface_wifi_get_sim_auth(NetconfigWifi *wifi, DBusGMethodInvocation *context); +gboolean netconfig_iface_wifi_get_aka_auth(NetconfigWifi *wifi, DBusGMethodInvocation *context); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_EAP_H__ */ diff --git a/mobile/include/wifi-indicator.h b/mobile/include/wifi-indicator.h new file mode 100644 index 0000000..ffdd0d3 --- /dev/null +++ b/mobile/include/wifi-indicator.h @@ -0,0 +1,36 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_INDICATOR_H__ +#define __NETCONFIG_WIFI_INDICATOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +int netconfig_wifi_get_rssi(void); + +void netconfig_wifi_indicator_start(void); +void netconfig_wifi_indicator_stop(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_INDICATOR_H__ */ diff --git a/mobile/include/wifi-power.h b/mobile/include/wifi-power.h new file mode 100644 index 0000000..fd338ef --- /dev/null +++ b/mobile/include/wifi-power.h @@ -0,0 +1,41 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_POWER_H__ +#define __NETCONFIG_WIFI_POWER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void netconfig_set_power_in_progress(gboolean in_progress); +void netconfig_check_fm_waiting(void); +void netconfig_wifi_power_configuration(void); + +gboolean netconfig_iface_wifi_load_driver(NetconfigWifi *wifi, GError **error); +gboolean netconfig_iface_wifi_remove_driver(NetconfigWifi *wifi, GError **error); +gboolean netconfig_is_wifi_allowed(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_POWER_H__ */ diff --git a/mobile/include/wifi-ssid-scan.h b/mobile/include/wifi-ssid-scan.h new file mode 100644 index 0000000..d3927a5 --- /dev/null +++ b/mobile/include/wifi-ssid-scan.h @@ -0,0 +1,51 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_SSID_SCAN_H__ +#define __NETCONFIG_WIFI_SSID_SCAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +enum netconfig_wifi_security { + WIFI_SECURITY_UNKNOWN = 0x00, + WIFI_SECURITY_NONE = 0x01, + WIFI_SECURITY_WEP = 0x02, + WIFI_SECURITY_PSK = 0x03, + WIFI_SECURITY_IEEE8021X = 0x04, +}; + +gboolean netconfig_wifi_get_ssid_scan_state(void); + +void netconfig_wifi_notify_ssid_scan_done(void); +void netconfig_wifi_bss_added(DBusMessage *message); + +gboolean netconfig_wifi_ssid_scan(const char *ssid); + +gboolean netconfig_iface_wifi_request_specific_scan(NetconfigWifi *wifi, + gchar *ssid, GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_SSID_SCAN_H__ */ diff --git a/mobile/include/wifi-state.h b/mobile/include/wifi-state.h new file mode 100644 index 0000000..6c84149 --- /dev/null +++ b/mobile/include/wifi-state.h @@ -0,0 +1,75 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_STATE_H__ +#define __NETCONFIG_WIFI_STATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +enum netconfig_wifi_service_state { + NETCONFIG_WIFI_UNKNOWN = 0x00, + NETCONFIG_WIFI_IDLE = 0x01, + NETCONFIG_WIFI_CONNECTING = 0x02, + NETCONFIG_WIFI_CONNECTED = 0x03, +}; + +enum netconfig_wifi_tech_state { + NETCONFIG_WIFI_TECH_UNKNOWN = 0x00, + NETCONFIG_WIFI_TECH_OFF = 0x01, + NETCONFIG_WIFI_TECH_POWERED = 0x02, + NETCONFIG_WIFI_TECH_CONNECTED = 0x03, + NETCONFIG_WIFI_TECH_TETHERING_ON = 0x04, +}; + +struct netconfig_wifi_state_notifier { + void (*netconfig_wifi_state_changed) + (enum netconfig_wifi_service_state, void *user_data); + void *user_data; +}; + +void netconfig_wifi_state_set_service_state( + enum netconfig_wifi_service_state state); +enum netconfig_wifi_service_state + netconfig_wifi_state_get_service_state(void); + +enum netconfig_wifi_tech_state + netconfig_wifi_get_technology_state(void); + +void netconfig_wifi_update_power_state(gboolean powered); + +char *netconfig_wifi_get_favorite_service(void); + +void netconfig_wifi_check_network_notification(DBusMessage *message); + +void netconfig_wifi_state_notifier_cleanup(void); +void netconfig_wifi_state_notifier_register( + struct netconfig_wifi_state_notifier *notifier); +void netconfig_wifi_state_notifier_unregister( + struct netconfig_wifi_state_notifier *notifier); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_STATE_H__ */ diff --git a/mobile/include/wifi.h b/mobile/include/wifi.h new file mode 100644 index 0000000..1e05eb5 --- /dev/null +++ b/mobile/include/wifi.h @@ -0,0 +1,62 @@ +/* + * Network Configuration Module + * + * 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 __NETCONFIG_WIFI_H__ +#define __NETCONFIG_WIFI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +G_BEGIN_DECLS + +typedef struct NetconfigWifi NetconfigWifi; +typedef struct NetconfigWifiClass NetconfigWifiClass; + +#define NETCONFIG_TYPE_WIFI (netconfig_wifi_get_type()) +#define NETCONFIG_WIFI(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), NETCONFIG_TYPE_WIFI, NetconfigWifi)) +#define NETCONFIG_IS_WIFI(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), NETCONFIG_TYPE_WIFI)) +#define NETCONFIG_WIFI_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), NETCONFIG_TYPE_WIFI, NetconfigWifiClass)) +#define NETCONFIG_IS_WIFI_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), NETCONFIG_TYPE_WIFI)) +#define NETCONFIG_WIFI_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), NETCONFIG_TYPE_WIFI, NetconfigWifiClass)) + +#define VCONF_WIFI_LAST_POWER_STATE "file/private/wifi/last_power_state" + +enum netconfig_wifi_power_state { + WIFI_POWER_OFF = 0x00, + WIFI_POWER_ON = 0x01, +}; + +GType netconfig_wifi_get_type(void); + +gpointer netconfig_wifi_create_and_init(DBusGConnection *conn); +gboolean netconfig_wifi_remove_driver(void); +void netconfig_wifi_notify_power_completed(gboolean power_on); + +G_END_DECLS + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_H__ */ diff --git a/mobile/interfaces/netconfig-iface-network-state.xml b/mobile/interfaces/netconfig-iface-network-state.xml new file mode 100644 index 0000000..d2dae90 --- /dev/null +++ b/mobile/interfaces/netconfig-iface-network-state.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/mobile/interfaces/netconfig-iface-network-statistics.xml b/mobile/interfaces/netconfig-iface-network-statistics.xml new file mode 100644 index 0000000..d436a61 --- /dev/null +++ b/mobile/interfaces/netconfig-iface-network-statistics.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/interfaces/netconfig-iface-wifi.xml b/mobile/interfaces/netconfig-iface-wifi.xml new file mode 100644 index 0000000..d6f862e --- /dev/null +++ b/mobile/interfaces/netconfig-iface-wifi.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/net-config.manifest b/mobile/net-config.manifest new file mode 100644 index 0000000..848ec5e --- /dev/null +++ b/mobile/net-config.manifest @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/mobile/net-config.rule b/mobile/net-config.rule new file mode 100644 index 0000000..f450630 --- /dev/null +++ b/mobile/net-config.rule @@ -0,0 +1,8 @@ +root net-config rw--- +_default_ net-config rw--- +net-config system::vconf_network rw--- +net-config system::vconf_setting rw--- +net-config system::use_internet rwx-- +net-config dbus rwx-- +system::use_internet net-config rwx-- +dbus net-config rwx-- diff --git a/mobile/resources/etc/dbus-1/system.d/net-config.conf b/mobile/resources/etc/dbus-1/system.d/net-config.conf new file mode 100644 index 0000000..cb73052 --- /dev/null +++ b/mobile/resources/etc/dbus-1/system.d/net-config.conf @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/resources/opt/etc/resolv.conf b/mobile/resources/opt/etc/resolv.conf new file mode 100644 index 0000000..a67674d --- /dev/null +++ b/mobile/resources/opt/etc/resolv.conf @@ -0,0 +1,2 @@ +search localdomain +nameserver 127.0.0.1 \ No newline at end of file diff --git a/mobile/resources/usr/lib/systemd/system/net-config.service b/mobile/resources/usr/lib/systemd/system/net-config.service new file mode 100644 index 0000000..63d2c1b --- /dev/null +++ b/mobile/resources/usr/lib/systemd/system/net-config.service @@ -0,0 +1,10 @@ +[Unit] +Description=net config service +After=syslog.target + +[Service] +Type=notify +ExecStart=/usr/sbin/net-config --nofork + +[Install] +WantedBy=multi-user.target diff --git a/mobile/resources/usr/share/dbus-1/services/net.netconfig.service b/mobile/resources/usr/share/dbus-1/services/net.netconfig.service new file mode 100644 index 0000000..6d497a1 --- /dev/null +++ b/mobile/resources/usr/share/dbus-1/services/net.netconfig.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=net.netconfig +Exec=/usr/sbin/net-config +User=root diff --git a/mobile/src/dbus/netdbus.c b/mobile/src/dbus/netdbus.c new file mode 100644 index 0000000..928dfde --- /dev/null +++ b/mobile/src/dbus/netdbus.c @@ -0,0 +1,526 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "netdbus.h" +#include "netconfig.h" + +#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000) + +#define DBUS_PARAM_TYPE_STRING "string" +#define DBUS_PARAM_TYPE_INT16 "int16" +#define DBUS_PARAM_TYPE_UINT16 "uint16" +#define DBUS_PARAM_TYPE_INT32 "int32" +#define DBUS_PARAM_TYPE_UINT32 "uint32" +#define DBUS_PARAM_TYPE_INT64 "int64" +#define DBUS_PARAM_TYPE_UINT64 "uint64" +#define DBUS_PARAM_TYPE_DOUBLE "double" +#define DBUS_PARAM_TYPE_BYTE "byte" +#define DBUS_PARAM_TYPE_BOOLEAN "boolean" +#define DBUS_PARAM_TYPE_OBJECT_PATH "objpath" +#define DBUS_PARAM_TYPE_VARIANT "variant" +#define DBUS_PARAM_TYPE_ARRAY "array" + + +static gboolean __netconfig_dbus_append_param_variant( + DBusMessageIter *iter, char *type, char *param) +{ + DBusMessageIter value, array; + char *args = NULL, *ch = NULL; + dbus_bool_t b_value = FALSE; + + if (strcmp(type, DBUS_PARAM_TYPE_STRING) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_STRING_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, ¶m); + + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(type, DBUS_PARAM_TYPE_BOOLEAN) == 0) { + if (strcmp(param, "true") == 0) { + b_value = TRUE; + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_BOOLEAN_AS_STRING, &value); + dbus_message_iter_append_basic(&value, + DBUS_TYPE_BOOLEAN, &b_value); + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(param, "false") == 0) { + b_value = FALSE; + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_BOOLEAN_AS_STRING, &value); + dbus_message_iter_append_basic(&value, + DBUS_TYPE_BOOLEAN, &b_value); + dbus_message_iter_close_container(iter, &value); + } else { + ERR("Error!!! Expected \"true\" or" + "\"false\" instead of \"%s\"", ch); + return FALSE; + } + } else if (strcmp(type, DBUS_PARAM_TYPE_OBJECT_PATH) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_OBJECT_PATH_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_OBJECT_PATH, ¶m); + + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(type, DBUS_PARAM_TYPE_ARRAY) == 0) { + args = param; + ch = strchr(args, ':'); + if (ch == NULL) { + ERR("Error!!! Invalid data format[\"%s\"]", args); + return FALSE; + } + *ch = 0; ch++; + + if (strcmp(args, DBUS_PARAM_TYPE_STRING) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, + &value); + + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, &array); + + dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &ch); + + dbus_message_iter_close_container(&value, &array); + + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(args, DBUS_PARAM_TYPE_OBJECT_PATH) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING, + &value); + + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + DBUS_TYPE_OBJECT_PATH_AS_STRING, &array); + + dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH, &ch); + + dbus_message_iter_close_container(&value, &array); + + dbus_message_iter_close_container(iter, &value); + } else { + ERR("Error!!! Not supported data format[\"%s\"]", args); + return FALSE; + } + } else { + ERR("Error!!! Not supported data format[\"%s\"]", args); + return FALSE; + } + + return TRUE; +} + +static gboolean __netconfig_dbus_append_param( + DBusMessage *message, char *param_array[]) +{ + int count = 0; + dbus_uint32_t uint32 = 0; + DBusMessageIter iter; + char *args = NULL, *ch = NULL; + + if (param_array == NULL) + return TRUE; + + dbus_message_iter_init_append(message, &iter); + + while (param_array[count] != NULL) { + args = param_array[count]; + DBG("parameter %d - [%s]", count, param_array[count]); + + ch = strchr(args, ':'); + if (ch == NULL) { + ERR("Error!!! Invalid parameter[\"%s\"]\n", args); + return FALSE; + } + *ch = 0; ch++; + + if (strcmp(args, DBUS_PARAM_TYPE_STRING) == 0) { + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ch); + } else if (strcmp(args, DBUS_PARAM_TYPE_UINT32) == 0) { + uint32 = strtoul(ch, NULL, 0); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &uint32); + } else if (strcmp(args, DBUS_PARAM_TYPE_VARIANT) == 0) { + args = ch; + ch = strchr(args, ':'); + if (ch == NULL) { + ERR("Error!!! Invalid data format[\"%s\"]\n", args); + return FALSE; + } + *ch = 0; ch++; + + if (__netconfig_dbus_append_param_variant(&iter, args, ch) != TRUE) + return FALSE; + + } else if (strcmp(args, DBUS_PARAM_TYPE_OBJECT_PATH) == 0) { + dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &ch); + } else { + ERR("Error!!! Not supported data format[\"%s\"]", args); + return FALSE; + } + + count++; + } + + return TRUE; +} + +gboolean netconfig_dbus_get_basic_params_string(DBusMessage *message, + char **key, int type, void *value) +{ + DBusMessageIter iter, iter_variant; + + dbus_message_iter_init(message, &iter); + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&iter)); + return FALSE; + } + + dbus_message_iter_get_basic(&iter, key); + + if (value == NULL) + return TRUE; + + dbus_message_iter_next(&iter); + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&iter)); + return TRUE; + } + + dbus_message_iter_recurse(&iter, &iter_variant); + if (dbus_message_iter_get_arg_type(&iter_variant) != type) + return FALSE; + + dbus_message_iter_get_basic(&iter_variant, value); + + return TRUE; +} + +gboolean netconfig_dbus_get_basic_params_array(DBusMessage *message, + char **key, void **value) +{ + DBusMessageIter args, dict, entry, variant; + int type = 0; + + if (key == NULL) + return FALSE; + + /* read parameters */ + if (dbus_message_iter_init(message, &args) == FALSE) { + DBG("Message does not have parameters"); + return FALSE; + } + + if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&args)); + return FALSE; + } + + dbus_message_iter_recurse(&args, &dict); + + if (dbus_message_iter_get_arg_type(&dict) != DBUS_TYPE_DICT_ENTRY) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&dict)); + return FALSE; + } + + dbus_message_iter_recurse(&dict, &entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&entry)); + return FALSE; + } + + dbus_message_iter_get_basic(&entry, key); + + if (value == NULL) + return TRUE; + + dbus_message_iter_next(&entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&entry)); + return TRUE; + } + + dbus_message_iter_recurse(&entry, &variant); + + type = dbus_message_iter_get_arg_type(&variant); + if (type == DBUS_TYPE_STRING) + dbus_message_iter_get_basic(&variant, value); + else if (type == DBUS_TYPE_BYTE || type == DBUS_TYPE_BOOLEAN || + type == DBUS_TYPE_INT16 || type == DBUS_TYPE_UINT16 || + type == DBUS_TYPE_INT32 || type == DBUS_TYPE_UINT32 || + type == DBUS_TYPE_DOUBLE) + dbus_message_iter_get_basic(&variant, *value); + else + DBG("Argument type %d", type); + + return TRUE; +} + +gboolean netconfig_is_cellular_profile(const char *profile) +{ + if (profile == NULL) + return FALSE; + + return g_str_has_prefix(profile, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX); +} + +gboolean netconfig_is_wifi_profile(const char *profile) +{ + if (profile == NULL) + return FALSE; + + return g_str_has_prefix(profile, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX); +} + +gboolean netconfig_is_ethernet_profile(const char *profile) +{ + if (profile == NULL) + return FALSE; + + return g_str_has_prefix(profile, CONNMAN_ETHERNET_SERVICE_PROFILE_PREFIX); +} + +gboolean netconfig_is_bluetooth_profile(const char *profile) +{ + if (profile == NULL) + return FALSE; + + return g_str_has_prefix(profile, CONNMAN_BLUETOOTH_SERVICE_PROFILE_PREFIX); +} + +gboolean netconfig_invoke_dbus_method_nonblock( + const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[], + DBusPendingCallNotifyFunction notify_func) +{ + dbus_bool_t result; + DBusPendingCall *call; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + + DBG("[DBUS Async] %s %s %s", interface_name, method, path); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + + return FALSE; + } + + message = dbus_message_new_method_call(dest, path, interface_name, method); + if (message == NULL) { + ERR("Failed DBus method call"); + + dbus_connection_unref(connection); + + return FALSE; + } + + if (__netconfig_dbus_append_param(message, param_array) == FALSE) { + ERR("Failed to append DBus params"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return FALSE; + } + + result = dbus_connection_send_with_reply(connection, message, &call, + NETCONFIG_DBUS_REPLY_TIMEOUT); + + if (result != TRUE || call == NULL) { + ERR("dbus_connection_send_with_reply() failed."); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return FALSE; + } + + if (notify_func == NULL) + dbus_pending_call_cancel(call); + else + dbus_pending_call_set_notify(call, notify_func, NULL, NULL); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return TRUE; +} + +DBusMessage *netconfig_invoke_dbus_method(const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[]) +{ + DBusError error; + DBusConnection *conn = NULL; + DBusMessage *reply = NULL; + DBusMessage *message = NULL; + + DBG("[DBUS Sync] %s %s %s", interface_name, method, path); + + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) { + ERR("Failed to get system bus"); + + return NULL; + } + + message = dbus_message_new_method_call(dest, path, interface_name, method); + if (message == NULL) { + ERR("Error!!! Failed to GetProperties"); + + dbus_connection_unref(conn); + + return NULL; + } + + if (__netconfig_dbus_append_param(message, param_array) == FALSE) { + ERR("Error!!! __netconfig_dbus_append_param() failed"); + + dbus_message_unref(message); + dbus_connection_unref(conn); + + return NULL; + } + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(conn, message, + NETCONFIG_DBUS_REPLY_TIMEOUT, &error); + + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + ERR("Error!!! dbus_connection_send_with_reply_and_block() failed. " + "DBus error [%s: %s]", error.name, error.message); + + dbus_error_free(&error); + } else + ERR("Error!!! Failed to get properties"); + + dbus_message_unref(message); + dbus_connection_unref(conn); + + return NULL; + } + + dbus_message_unref(message); + dbus_connection_unref(conn); + + return reply; +} + +char *netconfig_wifi_get_connected_service_name(DBusMessage *message) +{ + int is_connected = 0; + char *essid_name = NULL; + DBusMessageIter iter, array; + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, string; + const char *key = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + if (g_str_equal(key, "State") == TRUE && is_connected == 0) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &string); + + if (dbus_message_iter_get_arg_type(&string) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&string, &key); + + if (g_str_equal(key, "ready") == TRUE || + g_str_equal(key, "online") == TRUE) + is_connected = 1; + } + } else if (g_str_equal(key, "Name") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &string); + + if (dbus_message_iter_get_arg_type(&string) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&string, &key); + + essid_name = (char *)g_strdup(key); + } + } + + dbus_message_iter_next(&array); + } + + if (is_connected == 1 && essid_name != NULL) + return essid_name; + + if (essid_name != NULL) + g_free(essid_name); + + return NULL; +} + +DBusGConnection *netconfig_setup_dbus(void) +{ + DBusGConnection* connection = NULL; + GError *error = NULL; + DBusGProxy *proxy; + guint rv = 0; + + connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + ERR("Fail to get DBus(%s)", error->message); + g_error_free(error); + + return connection; + } + + INFO("Successfully get system DBus connection(%p)", connection); + + proxy = dbus_g_proxy_new_for_name(connection, "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus"); + + if (!dbus_g_proxy_call(proxy, "RequestName", &error, + G_TYPE_STRING, NETCONFIG_SERVICE, G_TYPE_UINT, 0, + G_TYPE_INVALID, G_TYPE_UINT, &rv, + G_TYPE_INVALID)) { + ERR("Failed to acquire service(%s) error(%s)", + NETCONFIG_SERVICE, error->message); + g_error_free(error); + + dbus_g_connection_unref(connection); + + return NULL; + } + + if (rv != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + ERR("Service name is already in use"); + + dbus_g_connection_unref(connection); + + return NULL; + } + + return connection; +} diff --git a/mobile/src/dbus/netsupplicant.c b/mobile/src/dbus/netsupplicant.c new file mode 100644 index 0000000..d3926d5 --- /dev/null +++ b/mobile/src/dbus/netsupplicant.c @@ -0,0 +1,273 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "netdbus.h" +#include "netsupplicant.h" + +#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000) + +static void setup_dbus_args(gpointer data, gpointer user_data) +{ + struct dbus_input_arguments *args; + DBusMessageIter *iter; + + if (data != NULL && user_data != NULL) { + args = (struct dbus_input_arguments *)data; + iter = (DBusMessageIter *) user_data; + + dbus_message_iter_append_basic(iter, args->type, + &(args->data)); + } +} + +static GList *setup_input_args(GList *list, + struct dbus_input_arguments *items) +{ + struct dbus_input_arguments *iter = items; + + if (iter == NULL) + return NULL; + + while (iter->data) { + list = g_list_append(list, iter); + iter++; + } + + return list; +} + +gboolean netconfig_wifi_get_ifname(char **ifname) +{ + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusMessageIter iter; + int MessageType = 0; + char *ptr = (char *)*ifname; + const char *temp = NULL; + + char object_path[DBUS_PATH_MAX_BUFLEN] = { 0, }; + char *path_ptr = &object_path[0]; + + GList *input_args = NULL; + struct dbus_input_arguments args[] = { + {DBUS_TYPE_STRING, SUPPLICANT_INTERFACE ".Interface"}, + {DBUS_TYPE_STRING, "Ifname"}, + {0, NULL} + }; + + if (ptr == NULL) + return FALSE; + + if (netconfig_wifi_get_supplicant_interface(&path_ptr) != TRUE) { + DBG("Fail to get wpa_supplicant DBus path"); + return FALSE; + } + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Error!!! Fail to get system DBus"); + return FALSE; + } + + input_args = setup_input_args(input_args, args); + + message = netconfig_supplicant_invoke_dbus_method( + SUPPLICANT_SERVICE, connection, + path_ptr, + SUPPLICANT_GLOBAL_INTERFACE, "Get", + input_args); + + g_list_free(input_args); + + if (message == NULL) { + ERR("Error!!! Failed to get service properties"); + goto error; + } + + MessageType = dbus_message_get_type(message); + + if (MessageType == DBUS_MESSAGE_TYPE_ERROR) { + const char *err_ptr = dbus_message_get_error_name(message); + ERR("Error!!! Error message received %s", err_ptr); + goto error; + } + + dbus_message_iter_init(message, &iter); + + if ((MessageType = dbus_message_iter_get_arg_type(&iter)) + == DBUS_TYPE_VARIANT) { + DBusMessageIter string_type; + dbus_message_iter_recurse(&iter, &string_type); + + if ((MessageType = dbus_message_iter_get_arg_type(&string_type)) + == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&string_type, &temp); + } else + goto error; + } else + goto error; + + g_strlcpy(ptr, temp, 16); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return TRUE; + +error: + if (message != NULL) + dbus_message_unref(message); + + if (connection != NULL) + dbus_connection_unref(connection); + + return FALSE; +} + +gboolean netconfig_wifi_get_supplicant_interface(char **path) +{ + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusMessageIter iter; + int MessageType = 0; + char *ptr = (char *)*path; + const char *temp = NULL; + + GList *input_args = NULL; + struct dbus_input_arguments args[] = { + {DBUS_TYPE_STRING, SUPPLICANT_INTERFACE}, + {DBUS_TYPE_STRING, "Interfaces"}, + {0, NULL} + }; + + if (ptr == NULL) + return FALSE; + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Error!!! Fail to get system DBus"); + return FALSE; + } + + input_args = setup_input_args(input_args, args); + + message = netconfig_supplicant_invoke_dbus_method( + SUPPLICANT_SERVICE, connection, + SUPPLICANT_PATH, + SUPPLICANT_GLOBAL_INTERFACE, "Get", + input_args); + + g_list_free(input_args); + + if (message == NULL) { + ERR("Error!!! Failed to get service properties"); + goto error; + } + + MessageType = dbus_message_get_type(message); + + if (MessageType == DBUS_MESSAGE_TYPE_ERROR) { + const char *err_msg = dbus_message_get_error_name(message); + ERR("Error!!! Error message received %s", err_msg); + goto error; + } + + dbus_message_iter_init(message, &iter); + if ((MessageType = dbus_message_iter_get_arg_type(&iter)) + == DBUS_TYPE_VARIANT) { + DBusMessageIter array; + dbus_message_iter_recurse(&iter, &array); + + if ((MessageType = dbus_message_iter_get_arg_type(&array)) + == DBUS_TYPE_ARRAY) { + DBusMessageIter object_path; + dbus_message_iter_recurse(&array, &object_path); + + if ((MessageType = dbus_message_iter_get_arg_type(&object_path)) + == DBUS_TYPE_OBJECT_PATH) + dbus_message_iter_get_basic(&object_path, &temp); + else + goto error; + } else + goto error; + } else + goto error; + + g_strlcpy(ptr, temp, DBUS_PATH_MAX_BUFLEN); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return TRUE; + +error: + if (message != NULL) + dbus_message_unref(message); + + if (connection != NULL) + dbus_connection_unref(connection); + + return FALSE; +} + +DBusMessage *netconfig_supplicant_invoke_dbus_method(const char *dest, + DBusConnection *connection, + const char *path, const char *interface_name, + const char *method, GList *args) +{ + DBusError error; + DBusMessageIter iter; + DBusMessage *reply = NULL; + DBusMessage *message = NULL; + + message = dbus_message_new_method_call(dest, path, interface_name, method); + if (message == NULL) { + ERR("Error!!! DBus method call fail"); + return NULL; + } + + dbus_message_iter_init_append(message, &iter); + + if (args != NULL) + g_list_foreach(args, setup_dbus_args, (gpointer) &iter); + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + NETCONFIG_DBUS_REPLY_TIMEOUT, &error); + + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + ERR("Error!!! dbus_connection_send_with_reply_and_block() failed. DBus error [%s: %s]", + error.name, error.message); + + dbus_error_free(&error); + } else + ERR("Error!!! Failed to get properties"); + + dbus_message_unref(message); + + return NULL; + } + + dbus_message_unref(message); + + return reply; +} diff --git a/mobile/src/main.c b/mobile/src/main.c new file mode 100644 index 0000000..ccdc669 --- /dev/null +++ b/mobile/src/main.c @@ -0,0 +1,140 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "wifi.h" +#include "util.h" +#include "emulator.h" +#include "netdbus.h" +#include "network-clock.h" +#include "network-state.h" +#include "network-statistics.h" +#include "signal-handler.h" +#include "wifi-agent.h" + +static GMainLoop *main_loop = NULL; + +static int no_fork = FALSE; + +void netconfig_signal_handler_SIGTERM(int signum) +{ + g_main_loop_quit(main_loop); +} + +int netconfig_register_signal_handler_SIGTERM(void) +{ + struct sigaction sigset; + + sigemptyset(&sigset.sa_mask); + sigaddset( &sigset.sa_mask, SIGTERM ); + sigset.sa_flags = 0; + sigset.sa_handler = netconfig_signal_handler_SIGTERM; + + if (sigaction( SIGTERM, &sigset, NULL) < 0) { + ERR("Sigaction for SIGTERM failed [%s]", strerror( errno )); + return -1; + } + + INFO( "Handler for SIGTERM ok" ); + return 0; +} + +int netconfig_test_input_parameters(int argc, char* argv[]) +{ + struct option tab[] = { + { "nofork", no_argument, 0, 0 }, + { NULL, 0, NULL, 0 } + }; + int idx = 0; + + while (getopt_long(argc, argv, "", tab, &idx) >= 0) { + + if (idx == 0) + no_fork = TRUE; + idx = 0; + } + return 0; +} + +int main(int argc, char* argv[]) +{ + DBusGConnection *connection; + + DBG("Network Configuration Module"); + + /* + * Call parameters veryfication + */ + netconfig_test_input_parameters(argc, argv); + + if (!no_fork) { + if (daemon(0, 0) != 0) + DBG("Cannot start daemon"); + } + + netconfig_set_wifi_mac_address(); + + g_type_init(); + + main_loop = g_main_loop_new(NULL, FALSE); + + connection = netconfig_setup_dbus(); + if (connection == NULL) + return -1; + + if (netconfig_network_state_create_and_init(connection) == NULL) + return -1; + + netconfig_register_signal(); + + /* Registering the agent for exchanging security credentials */ + netconfig_agent_register(); + + if (netconfig_wifi_create_and_init(connection) == NULL) + return -1; + + if (netconfig_network_statistics_create_and_init(connection) == NULL) + return -1; + + /* Register SIGCHLD signal handler function */ + if (netconfig_register_signal_handler_SIGTERM() != 0) + return -1; + + /* If its environment uses Emulator, network configuration is set by emulator default */ + netconfig_emulator_test_and_start(); + + // Notyfication to systemd + sd_notify(0, "READY=1"); + + g_main_loop_run(main_loop); + + netconfig_deregister_signal(); + netconfig_wifi_state_notifier_cleanup(); + + /* Unregistering the agent */ + netconfig_agent_unregister(); + + return 0; +} diff --git a/mobile/src/neterror.c b/mobile/src/neterror.c new file mode 100644 index 0000000..0c55268 --- /dev/null +++ b/mobile/src/neterror.c @@ -0,0 +1,89 @@ +/* + * Network Configuration Module + * + * 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 "neterror.h" +#include "netconfig.h" + +#define NETCONFIG_ERROR_INTERFACE NETCONFIG_SERVICE ".Error" + +GQuark netconfig_error_quark(void) +{ + static GQuark quark = 0; + + if (!quark) + quark = g_quark_from_static_string("netconfig_error"); + + return quark; +} + +void netconfig_error_wifi_load_inprogress(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_LOAD_INPROGRESS, + NETCONFIG_ERROR_INTERFACE ".WifiLoadInprogress"); +} + +void netconfig_error_wifi_driver_failed(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_DRIVER_FAILURE, + NETCONFIG_ERROR_INTERFACE ".WifiDriverFailed"); +} + +void netconfig_error_security_restricted(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_SECURITY_RESTRICTED, + NETCONFIG_ERROR_INTERFACE ".SecurityRestricted"); +} + +void netconfig_error_wifi_direct_failed(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_WIFI_DRIVER_FAILURE, + NETCONFIG_ERROR_INTERFACE ".WifiDirectFailed"); +} + +void netconfig_error_fail_get_imsi(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_IMSI, + NETCONFIG_ERROR_INTERFACE".FailGetSimImsi"); +} + +void netconfig_error_fail_req_sim_auth(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH, + NETCONFIG_ERROR_INTERFACE".FailReqSimAuth"); +} + +void netconfig_error_fail_req_sim_auth_wrong_param(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM, + NETCONFIG_ERROR_INTERFACE".FailReqSimAuthWrongParam"); +} + +void netconfig_error_fail_get_sim_auth_wrong_data(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA, + NETCONFIG_ERROR_INTERFACE".FailGetSimAuthWrongData"); +} + +void netconfig_error_fail_get_sim_auth_delay(GError **error) +{ + g_set_error(error, netconfig_error_quark(), NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY, + NETCONFIG_ERROR_INTERFACE".FailGetSimAuthDelay"); +} diff --git a/mobile/src/network-clock.c b/mobile/src/network-clock.c new file mode 100644 index 0000000..a09e3b1 --- /dev/null +++ b/mobile/src/network-clock.c @@ -0,0 +1,114 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-state.h" + +#define NTP_SERVER "pool.ntp.org" +#define CONNMAN_GLOBAL_SETTING "/var/lib/connman/settings" + +static void __netconfig_clock_clear_timeserver(void) +{ + GKeyFile *keyfile = NULL; + + keyfile = netconfig_keyfile_load(CONNMAN_GLOBAL_SETTING); + + if (keyfile == NULL) + return; + + g_key_file_remove_key(keyfile, "global", "Timeservers", NULL); + + netconfig_keyfile_save(keyfile, CONNMAN_GLOBAL_SETTING); +} + +static gboolean __netconfig_clock_clear_timeserver_timer(gpointer data) +{ + INFO("Clear NTP server"); + + __netconfig_clock_clear_timeserver(); + + return FALSE; +} + +static void __netconfig_clock_set_timeserver(const char *server) +{ + DBusMessage* reply = NULL; + char param1[] = "string:Timeservers"; + char *param2 = NULL; + char *param_array[] = {NULL, NULL, NULL}; + + param2 = g_strdup_printf("variant:array:string:%s", server); + + param_array[0] = param1; + param_array[1] = param2; + + reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_CLOCK_INTERFACE, + "SetProperty", param_array); + if (reply == NULL) { + ERR("Failed to configure NTP server"); + return; + } + + dbus_message_unref(reply); +} + +static void __netconfig_clock( + enum netconfig_wifi_service_state state, void *user_data) +{ + gboolean automatic_time_update = 0; + guint timeserver_clear_timer = 0; + + if (state != NETCONFIG_WIFI_CONNECTED) + return; + + vconf_get_bool( + VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, + &automatic_time_update); + + if (automatic_time_update == FALSE) { + INFO("Automatic time update is not set (%d)", automatic_time_update); + return; + } + + __netconfig_clock_set_timeserver((const char *)NTP_SERVER); + + netconfig_start_timer_seconds(5, __netconfig_clock_clear_timeserver_timer, + NULL, ×erver_clear_timer); +} + +static struct netconfig_wifi_state_notifier netconfig_clock_notifier = { + .netconfig_wifi_state_changed = __netconfig_clock, + .user_data = NULL, +}; + +void netconfig_clock_init(void) +{ + netconfig_wifi_state_notifier_register(&netconfig_clock_notifier); +} + +void netconfig_clock_deinit(void) +{ + netconfig_wifi_state_notifier_unregister(&netconfig_clock_notifier); +} diff --git a/mobile/src/network-state.c b/mobile/src/network-state.c new file mode 100644 index 0000000..ff5c701 --- /dev/null +++ b/mobile/src/network-state.c @@ -0,0 +1,666 @@ +/* + * Network Configuration Module + * + * 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 "wifi.h" +#include "log.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "emulator.h" +#include "wifi-state.h" +#include "network-state.h" + +#define NETCONFIG_NETWORK_STATE_PATH "/net/netconfig/network" +#define ROUTE_EXEC_PATH "/sbin/route" + +#define PROP_DEFAULT FALSE +#define PROP_DEFAULT_STR NULL + + +gboolean netconfig_iface_network_state_add_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error); + +gboolean netconfig_iface_network_state_remove_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error); + +#include "netconfig-iface-network-state-glue.h" + +enum { + PROP_O, + PROP_NETWORK_STATE_CONN, + PROP_NETWORK_STATE_PATH, +}; + +struct NetconfigNetworkStateClass { + GObjectClass parent; +}; + +struct NetconfigNetworkState { + GObject parent; + + DBusGConnection *conn; + gchar *path; +}; + +G_DEFINE_TYPE(NetconfigNetworkState, netconfig_network_state, G_TYPE_OBJECT); + + +static void __netconfig_network_state_gobject_get_property(GObject *object, + guint prop_id, GValue *value, GParamSpec *pspec) +{ + return; +} + +static void __netconfig_network_state_gobject_set_property(GObject *object, + guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NetconfigNetworkState *network_state = NETCONFIG_NETWORK_STATE(object); + + switch (prop_id) { + case PROP_NETWORK_STATE_CONN: + { + network_state->conn = g_value_get_boxed(value); + INFO("network_state(%p) set conn(%p)", network_state, network_state->conn); + break; + } + + case PROP_NETWORK_STATE_PATH: + { + if (network_state->path) + g_free(network_state->path); + + network_state->path = g_value_dup_string(value); + INFO("network_state(%p) path(%s)", network_state, network_state->path); + + break; + } + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void netconfig_network_state_init(NetconfigNetworkState *network_state) +{ + DBG("network_state initialize"); + + network_state->conn = NULL; + network_state->path = g_strdup(PROP_DEFAULT_STR); +} + +static void netconfig_network_state_class_init(NetconfigNetworkStateClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + DBG("class initialize"); + + object_class->get_property = __netconfig_network_state_gobject_get_property; + object_class->set_property = __netconfig_network_state_gobject_set_property; + + /* DBus register */ + dbus_g_object_type_install_info(NETCONFIG_TYPE_NETWORK_STATE, + &dbus_glib_netconfig_iface_network_state_object_info); + + /* property */ + g_object_class_install_property(object_class, PROP_NETWORK_STATE_CONN, + g_param_spec_boxed("conn", "CONNECTION", "DBus connection", + DBUS_TYPE_G_CONNECTION, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property(object_class, PROP_NETWORK_STATE_PATH, + g_param_spec_string("path", "Path", "Object path", + PROP_DEFAULT_STR, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + +struct netconfig_default_connection { + char *profile; + char *ifname; + char *ipaddress; + char *proxy; + char *essid; +}; + +static struct netconfig_default_connection + netconfig_default_connection_info; + +static void __netconfig_pop_3g_alert_syspoppup(void) +{ + int rv = 0; + bundle *b = NULL; + int wifi_ug_state = 0; + + vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); + if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) + return; + + b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", "Cellular connection popup"); + bundle_add(b, "_SYSPOPUP_TYPE_", "notification"); + bundle_add(b, "_SYSPOPUP_CONTENT_", "connected"); + + DBG("Launch 3G alert network popup"); + rv = aul_launch_app("org.tizen.net-popup", b); + + bundle_free(b); +} + +static gboolean __netconfig_is_connected(const char *profile) +{ + gboolean is_connected = FALSE; + DBusMessage *message = NULL; + DBusMessageIter iter, array; + + if (profile == NULL) + return FALSE; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, profile, + CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL); + if (message == NULL) { + ERR("Failed to get service properties"); + return is_connected; + } + + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { + const char *ptr = dbus_message_get_error_name(message); + ERR("Error!!! Error message received [%s]", ptr); + goto done; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, string; + const char *key = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + if (g_str_equal(key, "State") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &string); + + if (dbus_message_iter_get_arg_type(&string) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&string, &key); + + if (g_str_equal(key, "ready") == TRUE || + g_str_equal(key, "online") == TRUE) { + is_connected = TRUE; + + break; + } + } + } + + dbus_message_iter_next(&array); + } + +done: + if (message != NULL) + dbus_message_unref(message); + + return is_connected; +} + +static char *__netconfig_get_default_profile(void) +{ + DBusMessage *message = NULL; + GSList *service_profiles = NULL; + GSList *list = NULL; + DBusMessageIter iter, dict; + char *default_profile = NULL; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetServices", NULL); + if (message == NULL) { + ERR("Failed to get profiles"); + return NULL; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry; + const char *object_path = NULL; + + dbus_message_iter_recurse(&dict, &entry); + dbus_message_iter_get_basic(&entry, &object_path); + + if (object_path) + service_profiles = g_slist_append( + service_profiles, + g_strdup(object_path)); + + dbus_message_iter_next(&dict); + } + + for (list = service_profiles; list != NULL; list = list->next) { + char *profile_path = list->data; + + if (__netconfig_is_connected((const char *)profile_path) == TRUE) { + default_profile = g_strdup(profile_path); + break; + } + } + + g_slist_free(service_profiles); + + dbus_message_unref(message); + + return default_profile; +} + +static void __netconfig_get_default_connection_info(const char *profile) +{ + DBusMessage *message = NULL; + DBusMessageIter iter, array; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, profile, + CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL); + if (message == NULL) { + ERR("Failed to get service properties"); + return; + } + + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { + const char *ptr = dbus_message_get_error_name(message); + ERR("Error!!! Error message received [%s]", ptr); + goto done; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, variant, string, iter1, iter2, iter3; + const char *key = NULL, *value = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + if (g_str_equal(key, "Name") == TRUE && + netconfig_is_wifi_profile(profile) == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &string); + + if (dbus_message_iter_get_arg_type(&string) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&string, &value); + + netconfig_default_connection_info.essid = g_strdup(value); + } + } else if (g_str_equal(key, "Ethernet") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Interface") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + dbus_message_iter_get_basic(&iter3, &value); + + netconfig_default_connection_info.ifname = g_strdup(value); + } + + dbus_message_iter_next(&iter1); + } + } else if (g_str_equal(key, "IPv4") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Address") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + dbus_message_iter_get_basic(&iter3, &value); + + netconfig_default_connection_info.ipaddress = g_strdup(value); + } + + dbus_message_iter_next(&iter1); + } + } else if (g_str_equal(key, "IPv6") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Address") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + dbus_message_iter_get_basic(&iter3, &value); + + netconfig_default_connection_info.ipaddress = g_strdup(value); + } + + dbus_message_iter_next(&iter1); + } + } else if (g_str_equal(key, "Proxy") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter iter4; + + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Servers") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + if (dbus_message_iter_get_arg_type(&iter3) + != DBUS_TYPE_ARRAY) + break; + + dbus_message_iter_recurse(&iter3, &iter4); + if (dbus_message_iter_get_arg_type(&iter4) + != DBUS_TYPE_STRING) + break; + + dbus_message_iter_get_basic(&iter4, &value); + if (value != NULL && (strlen(value) > 0)) + netconfig_default_connection_info.proxy = g_strdup(value); + + } else if (g_str_equal(key, "Method") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + if (dbus_message_iter_get_arg_type(&iter3) + != DBUS_TYPE_STRING) + break; + + dbus_message_iter_get_basic(&iter3, &value); + if (g_strcmp0(value, "direct") == 0) { + g_free(netconfig_default_connection_info.proxy); + netconfig_default_connection_info.proxy = NULL; + + break; + } + } + + dbus_message_iter_next(&iter1); + } + } + + dbus_message_iter_next(&array); + } + +done: + if (message != NULL) + dbus_message_unref(message); +} + +static void __netconfig_update_default_connection_info(void) +{ + int old_network_status = 0; + const char *profile = netconfig_get_default_profile(); + const char *ip_addr = netconfig_get_default_ipaddress(); + const char *proxy_addr = netconfig_get_default_proxy(); + + if (netconfig_emulator_is_emulated() == TRUE) + return; + + if (profile == NULL) + DBG("Reset network state configuration"); + else + DBG("%s: ip(%s) proxy(%s)", profile, ip_addr, proxy_addr); + + vconf_get_int(VCONFKEY_NETWORK_STATUS, &old_network_status); + + if (profile == NULL && old_network_status != VCONFKEY_NETWORK_OFF) { + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_OFF); + + vconf_set_str(VCONFKEY_NETWORK_IP, ""); + vconf_set_str(VCONFKEY_NETWORK_PROXY, ""); + + vconf_set_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 0); + + DBG("Successfully clear IP and PROXY up"); + } else if (profile != NULL) { + char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP); + char *old_proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY); + + if (netconfig_is_wifi_profile(profile) == TRUE) { + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_WIFI); + } else if (netconfig_is_cellular_profile(profile) == TRUE) { + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_CELLULAR); + + if (old_network_status != VCONFKEY_NETWORK_CELLULAR) + __netconfig_pop_3g_alert_syspoppup(); + } else if (netconfig_is_ethernet_profile(profile) == TRUE) { + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_ETHERNET); + } else if (netconfig_is_bluetooth_profile(profile) == TRUE) { + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_BLUETOOTH); + } else { + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_OFF); + } + + if (g_strcmp0(old_ip, ip_addr) != 0) { + if (ip_addr == NULL) + vconf_set_str(VCONFKEY_NETWORK_IP, ""); + else + vconf_set_str(VCONFKEY_NETWORK_IP, ip_addr); + } + + if (g_strcmp0(old_proxy, proxy_addr) != 0) { + if (proxy_addr == NULL) + vconf_set_str(VCONFKEY_NETWORK_PROXY, ""); + else + vconf_set_str(VCONFKEY_NETWORK_PROXY, proxy_addr); + } + + vconf_set_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 1); + + DBG("Successfully update default network configuration"); + } +} + +const char *netconfig_get_default_profile(void) +{ + return netconfig_default_connection_info.profile; +} + +const char *netconfig_get_default_ipaddress(void) +{ + return netconfig_default_connection_info.ipaddress; +} + +const char *netconfig_get_default_proxy(void) +{ + return netconfig_default_connection_info.proxy; +} + +const char *netconfig_wifi_get_connected_essid(const char *default_profile) +{ + if (default_profile == NULL) + return NULL; + + if (netconfig_is_wifi_profile(default_profile) != TRUE) + return NULL; + + if (g_str_equal(default_profile, netconfig_default_connection_info.profile) + != TRUE) + return NULL; + + return netconfig_default_connection_info.essid; +} + +void netconfig_set_default_profile(const char *profile) +{ + char *default_profile = NULL; + + /* It's automatically updated by signal-handler + * DO NOT update manually + * + * It is going to update default connection information + */ + if (netconfig_default_connection_info.profile != NULL) { + g_free(netconfig_default_connection_info.profile); + netconfig_default_connection_info.profile = NULL; + + g_free(netconfig_default_connection_info.ifname); + netconfig_default_connection_info.ifname = NULL; + + g_free(netconfig_default_connection_info.ipaddress); + netconfig_default_connection_info.ipaddress = NULL; + + g_free(netconfig_default_connection_info.proxy); + netconfig_default_connection_info.proxy = NULL; + + if (netconfig_wifi_state_get_service_state() + != NETCONFIG_WIFI_CONNECTED) { + g_free(netconfig_default_connection_info.essid); + netconfig_default_connection_info.essid = NULL; + } + } + + if (profile == NULL) { + default_profile = __netconfig_get_default_profile(); + if (default_profile == NULL) { + __netconfig_update_default_connection_info(); + return; + } + } + + if (profile != NULL) + netconfig_default_connection_info.profile = g_strdup(profile); + else + netconfig_default_connection_info.profile = default_profile; + + __netconfig_get_default_connection_info( + netconfig_default_connection_info.profile); + + __netconfig_update_default_connection_info(); +} + +gboolean netconfig_iface_network_state_add_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error) +{ + gboolean ret = FALSE; + gboolean rv = FALSE; + const char *path = ROUTE_EXEC_PATH; + char *const args[] = {"route", "add", + "-net", ip_addr, + "netmask", netmask, + "dev", interface, + 0}; + char *const envs[] = { NULL }; + + DBG("ip_addr(%s), netmask(%s), interface(%s)", ip_addr, netmask, interface); + + if (ip_addr == NULL || netmask == NULL || interface == NULL) { + DBG("Invalid parameter!"); + goto done; + } + + rv = netconfig_execute_file(path, args, envs); + if (rv != TRUE) { + DBG("Failed to add a new route"); + goto done; + } + + DBG("Successfully added a new route"); + ret = TRUE; + +done: + *result = ret; + return ret; +} + +gboolean netconfig_iface_network_state_remove_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error) +{ + gboolean ret = FALSE; + gboolean rv = FALSE; + const char *path = ROUTE_EXEC_PATH; + char *const args[] = {"route", "del", + "-net", ip_addr, + "netmask", netmask, + "dev", interface, + 0}; + char *const envs[] = { NULL }; + + DBG("ip_addr(%s), netmask(%s), interface(%s)", ip_addr, netmask, interface); + + if (ip_addr == NULL || netmask == NULL || interface == NULL) { + DBG("Invalid parameter!"); + goto done; + } + + rv = netconfig_execute_file(path, args, envs); + if (rv != TRUE) { + DBG("Failed to remove a new route"); + goto done; + } + + DBG("Successfully remove a new route"); + ret = TRUE; + +done: + *result = ret; + return ret; +} + +gpointer netconfig_network_state_create_and_init(DBusGConnection *conn) +{ + GObject *object; + + g_return_val_if_fail(conn != NULL, NULL); + + object = g_object_new(NETCONFIG_TYPE_NETWORK_STATE, "conn", conn, "path", + NETCONFIG_NETWORK_STATE_PATH, NULL); + + INFO("create network_state(%p)", object); + + dbus_g_connection_register_g_object(conn, NETCONFIG_NETWORK_STATE_PATH, object); + + INFO("network_state(%p) register DBus path(%s)", object, NETCONFIG_NETWORK_STATE_PATH); + + return object; +} diff --git a/mobile/src/network-statistics.c b/mobile/src/network-statistics.c new file mode 100644 index 0000000..e176d7a --- /dev/null +++ b/mobile/src/network-statistics.c @@ -0,0 +1,452 @@ +/* + * Network Configuration Module + * + * 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 "wifi.h" +#include "log.h" +#include "util.h" +#include "netsupplicant.h" +#include "wifi-indicator.h" +#include "network-statistics.h" + +#include "netconfig-iface-network-statistics-glue.h" + +#define NETCONFIG_NETWORK_STATISTICS_PATH "/net/netconfig/network_statistics" + +#define NETCONFIG_PROCDEVFILE "/proc/net/dev" + +#define PROP_DEFAULT FALSE +#define PROP_DEFAULT_STR NULL + +enum { + PROP_O, + PROP_NETWORK_STATISTICS_CONN, + PROP_NETWORK_STATISTICS_PATH, +}; + +struct NetconfigNetworkStatisticsClass { + GObjectClass parent; +}; + +struct NetconfigNetworkStatistics { + GObject parent; + + DBusGConnection *conn; + gchar *path; +}; + +G_DEFINE_TYPE(NetconfigNetworkStatistics, netconfig_network_statistics, G_TYPE_OBJECT); + +static void __netconfig_network_statistics_gobject_get_property(GObject *object, + guint prop_id, GValue *value, GParamSpec *pspec) +{ + return; +} + +static void __netconfig_network_statistics_gobject_set_property(GObject *object, + guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NetconfigNetworkStatistics *network_statistics = NETCONFIG_NETWORK_STATISTICS(object); + + switch (prop_id) { + case PROP_NETWORK_STATISTICS_CONN: + { + network_statistics->conn = g_value_get_boxed(value); + INFO("network_statistics(%p) set conn(%p)", network_statistics, network_statistics->conn); + break; + } + + case PROP_NETWORK_STATISTICS_PATH: + { + if (network_statistics->path) + g_free(network_statistics->path); + + network_statistics->path = g_value_dup_string(value); + INFO("network_statistics(%p) path(%s)", network_statistics, network_statistics->path); + + break; + } + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void netconfig_network_statistics_init(NetconfigNetworkStatistics *network_statistics) +{ + DBG("network_statistics initialize"); + + network_statistics->conn = NULL; + network_statistics->path = g_strdup(PROP_DEFAULT_STR); +} + +static void netconfig_network_statistics_class_init(NetconfigNetworkStatisticsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + DBG("class initialize"); + + object_class->get_property = __netconfig_network_statistics_gobject_get_property; + object_class->set_property = __netconfig_network_statistics_gobject_set_property; + + /* DBus register */ + dbus_g_object_type_install_info(NETCONFIG_TYPE_NETWORK_STATISTICS, + &dbus_glib_netconfig_iface_network_statistics_object_info); + + /* property */ + g_object_class_install_property(object_class, PROP_NETWORK_STATISTICS_CONN, + g_param_spec_boxed("conn", "CONNECTION", "DBus connection", + DBUS_TYPE_G_CONNECTION, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property(object_class, PROP_NETWORK_STATISTICS_PATH, + g_param_spec_string("path", "Path", "Object path", + PROP_DEFAULT_STR, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + + +gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx) +{ + gboolean ret = FALSE; + FILE *fp; + gchar buf[1024]; + gchar ifname[16] = { 0, }; + gchar *p_ifname = NULL, *p_entry = NULL; + gchar *ifname_ptr = &ifname[0]; + + *tx = 0; + *rx = 0; + + if (netconfig_wifi_get_ifname(&ifname_ptr) != TRUE) { + DBG("Fail to get Wi-Fi ifname from wpa_supplicant: %s", ifname_ptr); + return FALSE; + } + + fp = fopen(NETCONFIG_PROCDEVFILE, "r"); + if (fp == NULL) { + ERR("Failed to open file %s", NETCONFIG_PROCDEVFILE); + return FALSE; + } + + /* skip the first and second line */ + if (fgets(buf, sizeof(buf), fp) == NULL || + fgets(buf, sizeof(buf), fp) == NULL) + goto endline; + + while (fgets(buf, sizeof(buf), fp)) { + guint64 llval; + gulong lval; + + p_ifname = buf; + while (*p_ifname == ' ') p_ifname++; + p_entry = strchr(p_ifname, ':'); + *p_entry++ = '\0'; + + if (g_str_equal(p_ifname, ifname) != TRUE) + continue; + + /* read interface statistics */ + sscanf(p_entry, + "%llu %llu %lu %lu %lu %lu %lu %lu " + "%llu %llu %lu %lu %lu %lu %lu %lu", + rx, /* rx bytes */ + &llval, /* rx packet */ + &lval, /* rx errors */ + &lval, /* rx dropped */ + &lval, /* rx fifo errors */ + &lval, /* rx frame errors */ + &lval, /* rx compressed */ + &lval, /* rx multicast */ + + tx, /* tx bytes */ + &llval, /* tx packet */ + &lval, /* tx errors */ + &lval, /* tx dropped */ + &lval, /* tx fifo errors */ + &lval, /* collisions */ + &lval, /* tx carrier errors */ + &lval /* tx compressed */ + ); + + ret = TRUE; + break; + } + +endline: + fclose(fp); + return ret; +} + +gboolean netconfig_iface_network_statistics_get_wifi_total_tx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *total_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 tx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val); + tx_bytes = (guint64)val; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *total_bytes = (guint64)tx + (guint64)tx_bytes; + else + *total_bytes = (guint64)tx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_get_wifi_total_rx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *total_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 rx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val); + rx_bytes = (guint64)val; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *total_bytes = (guint64)rx + (guint64)rx_bytes; + else + *total_bytes = (guint64)rx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_get_wifi_last_tx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *last_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 tx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val); + tx_bytes = (guint64)val; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + *last_bytes = (guint64)tx_bytes; + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *last_bytes = (((guint64)tx - (guint64)tx_bytes) > (guint64)0) ? + ((guint64)tx - (guint64)tx_bytes) : (guint64)0; + else + *last_bytes = (guint64)tx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_get_wifi_last_rx_bytes(NetconfigNetworkStatistics *network_statistics, guint64 *last_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 rx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val); + rx_bytes = (guint64)val; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + *last_bytes = (guint64)rx_bytes; + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *last_bytes = (((guint64)rx - (guint64)rx_bytes) > (guint64)0) ? + ((guint64)rx - (guint64)rx_bytes) : (guint64)0; + else + *last_bytes = (guint64)rx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_total_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + vconf_set_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_total_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + vconf_set_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_last_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + vconf_set_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_last_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + vconf_set_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_total_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, -(int)tx); + else + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, 0); + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_total_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, -(int)rx); + else + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, 0); + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_last_tx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)tx); + else + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_last_rx_bytes(NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0); + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)rx); + else + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0); + + return TRUE; +} + +void netconfig_wifi_statistics_update_powered_off(void) +{ + guint64 cur_tx = 0, cur_rx = 0; + guint64 prev_tx = 0, prev_rx = 0; + guint64 total_tx = 0, total_rx = 0; + int val = 0; + + if (netconfig_wifi_get_bytes_statistics(&cur_tx, &cur_rx) != TRUE) + return; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val); + prev_tx = (guint64)val; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val); + prev_rx = (guint64)val; + + total_tx = prev_tx + cur_tx; + total_rx = prev_rx + cur_rx; + + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx); + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx); +} + +static void netconfig_wifi_statistics_update_state( + enum netconfig_wifi_service_state state, void *user_data) +{ + guint64 tx = 0, rx = 0; + guint64 last_tx = 0, last_rx = 0; + int val = 0; + static enum netconfig_wifi_service_state prev_state = NETCONFIG_WIFI_UNKNOWN; + + if (prev_state == NETCONFIG_WIFI_UNKNOWN) { + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0); + + prev_state = NETCONFIG_WIFI_IDLE; + return; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) != TRUE) + return; + + if (state == NETCONFIG_WIFI_CONNECTED) { + last_tx = tx; + last_rx = rx; + } else { + if (prev_state != NETCONFIG_WIFI_CONNECTED) + return; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val); + last_tx = (guint64)val; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val); + last_rx = (guint64)val; + + last_tx = (((guint64)tx - (guint64)last_tx) > (guint64)0) ? + ((guint64)tx - (guint64)last_tx) : (guint64)0; + last_rx = (((guint64)rx - (guint64)last_rx) > (guint64)0) ? + ((guint64)rx - (guint64)last_rx) : (guint64)0; + } + + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx); + vconf_set_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx); + + prev_state = state; +} + +static struct netconfig_wifi_state_notifier state_notifier = { + .netconfig_wifi_state_changed = netconfig_wifi_statistics_update_state, + .user_data = NULL, +}; + +gpointer netconfig_network_statistics_create_and_init(DBusGConnection *conn) +{ + GObject *object; + + g_return_val_if_fail(conn != NULL, NULL); + + object = g_object_new(NETCONFIG_TYPE_NETWORK_STATISTICS, "conn", conn, "path", + NETCONFIG_NETWORK_STATISTICS_PATH, NULL); + + INFO("create network_statistics(%p)", object); + + dbus_g_connection_register_g_object(conn, NETCONFIG_NETWORK_STATISTICS_PATH, object); + + INFO("network_statistics(%p) register DBus path(%s)", object, NETCONFIG_NETWORK_STATISTICS_PATH); + + netconfig_wifi_statistics_update_state(NETCONFIG_WIFI_IDLE, NULL); + netconfig_wifi_state_notifier_register(&state_notifier); + + return object; +} diff --git a/mobile/src/signal-handler.c b/mobile/src/signal-handler.c new file mode 100644 index 0000000..e066541 --- /dev/null +++ b/mobile/src/signal-handler.c @@ -0,0 +1,372 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "netsupplicant.h" +#include "wifi-state.h" +#include "wifi-indicator.h" +#include "wifi-ssid-scan.h" +#include "wifi-background-scan.h" +#include "network-state.h" +#include "neterror.h" +#include "wifi.h" + +#define SIGNAL_SCAN_DONE "ScanDone" +#define SIGNAL_BSS_ADDED "BSSAdded" +#define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged" + +#define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged" +#define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged" + +#define CONNMAN_MANAGER_SIGNAL_FILTER "type='signal',interface='net.connman.Manager'" +#define CONNMAN_TECHNOLOGY_SIGNAL_FILTER "type='signal',interface='net.connman.Technology'" +#define CONNMAN_SERVICE_SIGNAL_FILTER "type='signal',interface='net.connman.Service'" +#define SUPPLICANT_INTERFACE_SIGNAL_FILTER "type='signal',interface='fi.w1.wpa_supplicant1.Interface'" + + +static DBusConnection *signal_connection = NULL; + +static char *__netconfig_get_property(DBusMessage *msg, int *prop_value) +{ + DBusMessageIter args, variant; + char *property = NULL; + dbus_bool_t data; + + /** read these parameters */ + if (!dbus_message_iter_init(msg, &args)) { + ERR("Message does not have parameters"); + } else if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) { + ERR("Argument is not string"); + } else { + dbus_message_iter_get_basic(&args, &property); + dbus_message_iter_next(&args); + dbus_message_iter_recurse(&args, &variant); + /* Right now, checking for only 'Powered' property which has + * Boolean type values + */ + if (dbus_message_iter_get_arg_type(&variant) == DBUS_TYPE_BOOLEAN) { + dbus_message_iter_get_basic(&variant, &data); + if (data) + *prop_value = TRUE; + else + *prop_value = FALSE; + } else { + *prop_value = FALSE; + } + } + + return property; +} + +static void __netconfig_technology_signal_handler(DBusMessage *msg) +{ + char *key = NULL; + const char *tech = NULL; + dbus_bool_t value = FALSE; + + if (netconfig_dbus_get_basic_params_string(msg, + &key, DBUS_TYPE_BOOLEAN, &value) != TRUE) + return; + + tech = dbus_message_get_path(msg); + if (key == NULL || tech == NULL) + return; + + if (g_str_has_prefix(tech, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) { + INFO("Wi-Fi Technology %s, property %d", key, value); + + if (g_strcmp0(key, "Powered") == 0) { + /* Power state */ + if (value == TRUE) + netconfig_wifi_update_power_state(TRUE); + else + netconfig_wifi_update_power_state(FALSE); + + netconfig_set_power_in_progress(FALSE); + netconfig_check_fm_waiting(); + } else if (g_strcmp0(key, "Connected") == 0) { + /* Connection state */ + } else if (g_strcmp0(key, "Tethering") == 0) { + /* Tethering state */ + } + } else if (g_str_has_prefix(tech, + CONNMAN_CELLULAR_TECHNOLOGY_PREFIX) == TRUE) { + /* Cellular technology state */ + } +} + +static void __netconfig_wifi_service_state_signal_handler(DBusMessage *msg) +{ + char *sigvalue = NULL; + char *property = NULL; + char *service_profile = NULL; + DBusMessageIter args, variant; + + service_profile = (char *)dbus_message_get_path(msg); + if (service_profile == NULL) + return; + + dbus_message_iter_init(msg, &args); + dbus_message_iter_get_basic(&args, &sigvalue); + if (sigvalue == NULL) + return; + + if (g_str_equal(sigvalue, "State") == TRUE) { + dbus_message_iter_next(&args); + dbus_message_iter_recurse(&args, &variant); + dbus_message_iter_get_basic(&variant, &property); + + DBG("[%s] %s", property, service_profile); + if (netconfig_is_wifi_profile(service_profile) == TRUE) { + int wifi_state = 0; + + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + if (wifi_state == VCONFKEY_WIFI_OFF) + return; + + if (g_str_equal(property, "ready") == TRUE || + g_str_equal(property, "online") == TRUE) { + if (wifi_state >= VCONFKEY_WIFI_CONNECTED) + return; + + netconfig_set_default_profile(service_profile); + + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED); + + } else if (g_str_equal(property, "failure") == TRUE || + g_str_equal(property, "disconnect") == TRUE || + g_str_equal(property, "idle") == TRUE) { + if (netconfig_get_default_profile() == NULL || + netconfig_is_wifi_profile(netconfig_get_default_profile()) + != TRUE) { + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); + return; + } + + if (g_str_equal(service_profile, netconfig_get_default_profile()) != TRUE) + return; + + netconfig_set_default_profile(NULL); + + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_IDLE); + + } else if (g_str_equal(property, "association") == TRUE || + g_str_equal(property, "configuration") == TRUE) { + if (netconfig_get_default_profile() == NULL || + netconfig_is_wifi_profile(netconfig_get_default_profile()) + != TRUE) { + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTING); + return; + } + + if (g_str_equal(service_profile, netconfig_get_default_profile()) != TRUE) + return; + + netconfig_set_default_profile(NULL); + + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTING); + } + } else { + if (g_str_equal(property, "ready") == TRUE || + g_str_equal(property, "online") == TRUE) { + if (netconfig_get_default_profile() == NULL) + netconfig_set_default_profile(service_profile); + + } else if (g_str_equal(property, "failure") == TRUE || + g_str_equal(property, "disconnect") == TRUE || + g_str_equal(property, "idle") == TRUE) { + if (netconfig_get_default_profile() == NULL) + return; + + if (g_str_equal(service_profile, netconfig_get_default_profile()) != TRUE) + return; + + netconfig_set_default_profile(NULL); + + } else if (g_str_equal(property, "association") == TRUE || + g_str_equal(property, "configuration") == TRUE) { + if (netconfig_get_default_profile() == NULL) + return; + + if (g_str_equal(service_profile, netconfig_get_default_profile()) != TRUE) + return; + + netconfig_set_default_profile(NULL); + } + } + } +} + +static DBusHandlerResult __netconfig_signal_filter_handler( + DBusConnection *conn, DBusMessage *msg, void *user_data) +{ + char *sigvalue = NULL; + + if (msg == NULL) { + DBG("Invalid Message. Ignore"); + return DBUS_HANDLER_RESULT_HANDLED; + } + + if (dbus_message_is_signal(msg, CONNMAN_MANAGER_INTERFACE, + CONNMAN_SIGNAL_PROPERTY_CHANGED)) { + /* We have handled this message, don't pass it on */ + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, CONNMAN_TECHNOLOGY_INTERFACE, + CONNMAN_SIGNAL_PROPERTY_CHANGED)) { + __netconfig_technology_signal_handler(msg); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, CONNMAN_SERVICE_INTERFACE, + CONNMAN_SIGNAL_PROPERTY_CHANGED)) { + __netconfig_wifi_service_state_signal_handler(msg); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, CONNMAN_MANAGER_INTERFACE, + CONNMAN_SIGNAL_SERVICES_CHANGED)) { + DBG("Received CONNMAN_SIGNAL_SERVICES_CHANGED message"); + netconfig_wifi_check_network_notification(msg); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE ".Interface", + SIGNAL_PROPERTIES_CHANGED)) { + dbus_bool_t scanning = FALSE; + void *property = &scanning; + + if (netconfig_dbus_get_basic_params_array(msg, + &sigvalue, &property) != TRUE) + return DBUS_HANDLER_RESULT_HANDLED; + + if (sigvalue == NULL) + return DBUS_HANDLER_RESULT_HANDLED; + + if (scanning == TRUE) + netconfig_wifi_set_scanning(TRUE); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE ".Interface", + SIGNAL_BSS_ADDED)) { + if (netconfig_wifi_get_ssid_scan_state() == TRUE) + netconfig_wifi_bss_added(msg); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE ".Interface", + SIGNAL_SCAN_DONE)) { + netconfig_wifi_set_scanning(FALSE); + + if (netconfig_wifi_get_bgscan_state() != TRUE) { + if (netconfig_wifi_get_ssid_scan_state() == TRUE) + netconfig_wifi_notify_ssid_scan_done(); + else + netconfig_wifi_ssid_scan(NULL); + } + + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +void netconfig_register_signal(void) +{ + DBusConnection *conn = NULL; + DBusError err; + + DBG("Register DBus signal filters"); + + dbus_error_init(&err); + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) { + ERR("Error! Failed to connect to the D-BUS daemon: [%s]", + err.message); + dbus_error_free(&err); + return; + } + + signal_connection = conn; + + dbus_connection_setup_with_g_main(conn, NULL); + + /* listening to messages from all objects as no path is specified */ + /* see signals from the given interface */ + dbus_bus_add_match(conn, CONNMAN_MANAGER_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Error! Match Error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, CONNMAN_TECHNOLOGY_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Error! Match Error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, CONNMAN_SERVICE_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Error! Match Error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, SUPPLICANT_INTERFACE_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Error! Match Error (%s)", err.message); + dbus_error_free(&err); + return; + } + + if (dbus_connection_add_filter(conn, + __netconfig_signal_filter_handler, NULL, NULL) == FALSE) { + ERR("Error! dbus_connection_add_filter() failed"); + return; + } + + INFO("Successfully register signal filters"); +} + +void netconfig_deregister_signal(void) +{ + if (signal_connection == NULL) { + ERR("Error! Already de-registered. Nothing to be done"); + return; + } + + dbus_connection_remove_filter(signal_connection, + __netconfig_signal_filter_handler, NULL); + INFO("Successfully remove DBus signal filters"); + + dbus_connection_unref(signal_connection); + signal_connection = NULL; + + netconfig_wifi_deinit_bgscan(); +} diff --git a/mobile/src/utils/emulator.c b/mobile/src/utils/emulator.c new file mode 100644 index 0000000..5a04d7c --- /dev/null +++ b/mobile/src/utils/emulator.c @@ -0,0 +1,119 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "emulator.h" + +static gboolean netconfig_is_emulated = FALSE; + +static gboolean __netconfig_emulator_test_emulation_env(void) +{ + struct utsname buf; + const char *EMUL_UTSNAME_MACHINE_SUFFIX = "emulated"; + + DBG("Test emulation environment"); + + if (uname(&buf) != 0) + return FALSE; + + if (g_str_has_suffix(buf.machine, EMUL_UTSNAME_MACHINE_SUFFIX) == TRUE) + return TRUE; + + return FALSE; +} + +static void __netconfig_emulator_set_ip(void) +{ + const int BUF_LEN_MAX = 255; + const char EMUL_IFNAME[] = "eth0"; + char ip[BUF_LEN_MAX]; + int sockfd = 0; + struct ifreq ifr; + + if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { + ERR("Failed to open socket"); + return; + } + + memset(&ifr, 0, sizeof(struct ifreq)); + g_strlcpy((char*)&ifr.ifr_name, EMUL_IFNAME, sizeof(EMUL_IFNAME)); + + if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) { + ERR("Error getting IP address"); + + close(sockfd); + return; + } + + g_strlcpy(ip, (char*)inet_ntoa(((struct sockaddr_in*)&ifr.ifr_addr)->sin_addr), BUF_LEN_MAX); + + vconf_set_str(VCONFKEY_NETWORK_IP, ip); + + close(sockfd); +} + +static void __netconfig_emulator_set_proxy(void) +{ + const char HTTP_PROXY[] = "http_proxy"; + char *proxy = NULL; + + proxy = getenv(HTTP_PROXY); + DBG("Get system proxy: %s", proxy); + + if(proxy != NULL) + vconf_set_str(VCONFKEY_NETWORK_PROXY, proxy); +} + +static void __netconfig_emulator_set_network_state(void) +{ + vconf_set_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 1); + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_ETHERNET); + vconf_set_int(VCONFKEY_DNET_STATE, VCONFKEY_DNET_OFF); +} + +static void __netconfig_emulator_config_emul_env(void) +{ + __netconfig_emulator_set_ip(); + __netconfig_emulator_set_proxy(); + __netconfig_emulator_set_network_state(); +} + +gboolean netconfig_emulator_is_emulated(void) +{ + return netconfig_is_emulated; +} + +void netconfig_emulator_test_and_start(void) +{ + netconfig_is_emulated = __netconfig_emulator_test_emulation_env(); + + DBG("Emulation environment tested: %s", netconfig_is_emulated ? "It's emulated" : "Not emulated"); + + if (netconfig_is_emulated == TRUE) + __netconfig_emulator_config_emul_env(); +} diff --git a/mobile/src/utils/util.c b/mobile/src/utils/util.c new file mode 100644 index 0000000..07680a3 --- /dev/null +++ b/mobile/src/utils/util.c @@ -0,0 +1,429 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "neterror.h" +#include "wifi-state.h" + +#define WIFI_MAC_INFO_FILE "/opt/etc/.mac.info" +#define WIFI_MAC_INFO_LENGTH 17 + +GKeyFile *netconfig_keyfile_load(const char *pathname) +{ + GKeyFile *keyfile = NULL; + GError *error = NULL; + + keyfile = g_key_file_new(); + if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) { + DBG("Unable to open %s, error %s", pathname, error->message); + g_error_free(error); + + g_key_file_free(keyfile); + keyfile = NULL; + } + + return keyfile; +} + +void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname) +{ + gsize size = 0; + GError *error = NULL; + gchar *keydata = NULL; + gchar *needle = NULL, *directory = NULL; + + directory = g_strdup(pathname); + needle = g_strrstr(directory, "/"); + + if (needle != NULL) + *needle = '\0'; + + if (directory == NULL || (*directory) == '\0') { + g_free(directory); + return; + } + + if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) { + if (g_mkdir_with_parents(directory, + S_IRUSR | S_IWUSR | S_IXUSR) != 0) { + g_free(directory); + return; + } + } + g_free(directory); + + keydata = g_key_file_to_data(keyfile, &size, &error); + if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) { + DBG("Unable to save %s, error %s", pathname, error->message); + g_error_free(error); + } + + if (chmod(pathname, S_IRUSR | S_IWUSR) != 0) + DBG("Unable to change permission of %s", pathname); + + g_free(keydata); + + g_key_file_free(keyfile); +} + +void netconfig_start_timer_seconds(guint secs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id) +{ + guint t_id = 0; + + if (callback == NULL) { + ERR("callback function is NULL"); + return; + } + + if ((timer_id != NULL && *timer_id != 0)) { + ERR("timer already is registered"); + return; + } + + t_id = g_timeout_add_seconds(secs, callback, user_data); + + if (t_id == 0) { + ERR("Can't add timer"); + return; + } + + if (timer_id != NULL) + *timer_id = t_id; +} + +void netconfig_start_timer(guint msecs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id) +{ + guint t_id = 0; + + INFO("Register timer with callback pointer (%p)", callback); + + if (callback == NULL) { + ERR("callback function is NULL"); + return; + } + + if ((timer_id != NULL && *timer_id != 0)) { + ERR("timer already is registered"); + return; + } + + t_id = g_timeout_add(msecs, callback, user_data); + + if (t_id == 0) { + ERR("Can't add timer"); + return; + } + + if (timer_id != NULL) + *timer_id = t_id; +} + +void netconfig_stop_timer(guint *timer_id) +{ + if (timer_id == NULL) { + ERR("timer is NULL"); + return; + } + + if (*timer_id != 0) { + g_source_remove(*timer_id); + *timer_id = 0; + } +} + +static gboolean __netconfig_test_device_picker() +{ + char *favorite_wifi_service = NULL; + + favorite_wifi_service = netconfig_wifi_get_favorite_service(); + if (favorite_wifi_service != NULL) { + g_free(favorite_wifi_service); + return FALSE; + } + + return TRUE; +} + +static void __netconfig_pop_device_picker(void) +{ + int rv = 0; + bundle *b = NULL; + int wifi_ug_state = 0; + + vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); + if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) + return; + + b = bundle_create(); + + DBG("Launch Wi-Fi device picker"); + rv = syspopup_launch("wifi-qs", b); + + bundle_free(b); +} + +static gboolean __netconfig_wifi_try_device_picker(gpointer data) +{ + if (__netconfig_test_device_picker() == TRUE) + __netconfig_pop_device_picker(); + + return FALSE; +} + +static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, + guint timer_id) +{ + static guint netconfig_wifi_device_picker_service_timer = 0; + + if (is_set_method != TRUE) + return netconfig_wifi_device_picker_service_timer; + + if (netconfig_wifi_device_picker_service_timer != timer_id) + netconfig_wifi_device_picker_service_timer = timer_id; + + return netconfig_wifi_device_picker_service_timer; +} + +static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id) +{ + __netconfig_wifi_device_picker_timer_id(TRUE, timer_id); +} + +static guint __netconfig_wifi_device_picker_get_timer_id(void) +{ + return __netconfig_wifi_device_picker_timer_id(FALSE, -1); +} + +void netconfig_wifi_device_picker_service_start(void) +{ + int wifi_ug_state; + const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700; + guint timer_id = 0; + + vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); + if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) + return; + + DBG("Register device picker timer with %d milliseconds", + NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL); + + netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, + __netconfig_wifi_try_device_picker, NULL, &timer_id); + + __netconfig_wifi_device_picker_set_timer_id(timer_id); +} + +void netconfig_wifi_device_picker_service_stop(void) +{ + guint timer_id = 0; + + timer_id = __netconfig_wifi_device_picker_get_timer_id(); + if (timer_id == 0) + return; + + DBG("Clear device picker timer with timer_id %d", timer_id); + + netconfig_stop_timer(&timer_id); + + __netconfig_wifi_device_picker_set_timer_id(timer_id); +} + +gboolean netconfig_is_wifi_direct_on(void) +{ + int wifi_direct_state = 0; + + vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state); + + DBG("Wi-Fi direct mode %d", wifi_direct_state); + return (wifi_direct_state != 0) ? TRUE : FALSE; +} + +gboolean netconfig_is_wifi_tethering_on(void) +{ + int wifi_tethering_state = 0; + + vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state); + + DBG("Wi-Ti tethering mode %d", wifi_tethering_state); + if (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) + return TRUE; + + return FALSE; +} + +/* args[] and env[] should be terminated with NULL pointer */ +gboolean netconfig_execute_file(const char *file_path, + char *const args[], char *const env[]) +{ + pid_t pid = 0; + int rv = 0; + errno = 0; + + if (!(pid = fork())) { + register unsigned int index = 0; + INFO("pid(%d), ppid (%d)", getpid(), getppid()); + INFO("Inside child, exec (%s) command", file_path); + + index = 0; + while (args[index] != NULL) { + INFO(" %s", args[index]); + index++; + } + + errno = 0; + if (execve(file_path, args, env) == -1) { + DBG("Fail to execute command...(%s)", + strerror(errno)); + return FALSE; + } + } else if (pid > 0) { + if (waitpid(pid, &rv, 0) == -1) { + DBG("wait pid (%u) rv (%d)", pid, rv); + + if (WIFEXITED(rv)) { + DBG("exited, rv=%d", WEXITSTATUS(rv)); + } else if (WIFSIGNALED(rv)) { + DBG("killed by signal %d", WTERMSIG(rv)); + } else if (WIFSTOPPED(rv)) { + DBG("stopped by signal %d", WSTOPSIG(rv)); + } else if (WIFCONTINUED(rv)) { + DBG("continued"); + } + } + return TRUE; + } + + DBG("failed to fork()...(%s)", strerror(errno)); + return FALSE; +} + +gboolean netconfig_iface_wifi_launch_direct(NetconfigWifi *wifi, GError **error) +{ + gboolean ret = TRUE; + + DBG("Launch Wi-Fi direct daemon"); + + const char *path = "/usr/bin/wifi-direct-server.sh"; + char *const args[] = { "wifi-direct-server.sh", "start", NULL}; + char *const env[] = { NULL }; + + ret = netconfig_execute_file(path, args, env); + + if (ret != TRUE) { + INFO("Failed to launch Wi-Fi direct daemon"); + + netconfig_error_wifi_direct_failed(error); + } + + return ret; +} + +void netconfig_add_wifi_found_notification(void) +{ + int ret; + bundle *b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TYPE_", "add_found_ap_noti"); + + ret = aul_launch_app("org.tizen.net-popup", b); + + bundle_free(b); + + if (ret >= 0) + DBG("Successfully added notification"); + else + ERR("Unable to launch noti-popup. Err = %d", ret); +} + +void netconfig_del_wifi_found_notification(void) +{ + int ret; + bundle *b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TYPE_", "del_found_ap_noti"); + + ret = aul_launch_app("org.tizen.net-popup", b); + + bundle_free(b); + + if (ret >= 0) + DBG("Successfully deleted notification"); + else + ERR("Unable to launch noti-popup. Err = %d", ret); +} + + +void netconfig_set_wifi_mac_address(void) +{ + FILE *fp; + char buf[WIFI_MAC_INFO_LENGTH + 1]; + char *mac_info; + + mac_info = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS); + if (mac_info == NULL) { + ERR("Failed to open vconf key %s", VCONFKEY_WIFI_BSSID_ADDRESS); + return; + } + + INFO("%s : %s", VCONFKEY_WIFI_BSSID_ADDRESS, mac_info); + + fp = fopen(WIFI_MAC_INFO_FILE, "r"); + if (fp == NULL) { + ERR("Failed to open file %s", WIFI_MAC_INFO_FILE); + g_free(mac_info); + return; + } + + if (fgets(buf, sizeof(buf), fp) == NULL) { + ERR("Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); + goto done; + } + + INFO("%s : %s", WIFI_MAC_INFO_FILE, buf); + + if (strlen(buf) < WIFI_MAC_INFO_LENGTH) { + ERR("Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); + goto done; + } + + buf[WIFI_MAC_INFO_LENGTH] = '\0'; + + if (g_str_equal(mac_info, buf) == TRUE) + goto done; + + if (vconf_set_str(VCONFKEY_WIFI_BSSID_ADDRESS, buf) != 0) + ERR("Failed to set MAC info to %s", VCONFKEY_WIFI_BSSID_ADDRESS); + +done: + g_free(mac_info); + fclose(fp); +} diff --git a/mobile/src/wifi-agent.c b/mobile/src/wifi-agent.c new file mode 100644 index 0000000..ba7d331 --- /dev/null +++ b/mobile/src/wifi-agent.c @@ -0,0 +1,203 @@ +/* + * Network Configuration Module + * + * 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 "wifi-agent.h" +#include "log.h" +#include "wifi.h" +#include "netdbus.h" + +#define NETCONFIG_AGENT_FIELD_PASSPHRASE "Passphrase" +#define NETCONFIG_AGENT_FIELD_WPS "WPS" +#define NETCONFIG_AGENT_FIELD_WPS_PBC "WPS_PBC" +#define NETCONFIG_AGENT_FIELD_WPS_PIN "WPS_PIN" + +struct netconfig_wifi_agent { + char *passphrase; + char *wps_pin; + gboolean wps_pbc; +}; + +static struct netconfig_wifi_agent agent; + +static void __netconfig_agent_clear_fields(void) +{ + DBG("__netconfig_agent_clear_fields"); + + g_free(agent.passphrase); + g_free(agent.wps_pin); + + agent.passphrase = NULL; + agent.wps_pin = NULL; + agent.wps_pbc = FALSE; +} + +gboolean netconfig_agent_register(void) +{ + DBG("netconfig_agent_register"); + + DBusMessage *reply = NULL; + char param1[64] = ""; + char *param_array[] = {NULL, NULL}; + + snprintf(param1, 64, "objpath:%s", NETCONFIG_WIFI_PATH); + param_array[0] = param1; + + reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "RegisterAgent", param_array); + + if (reply == NULL) { + ERR("Error! Request failed"); + return FALSE; + } + + dbus_message_unref(reply); + + return TRUE; +} + +gboolean netconfig_agent_unregister(void) +{ + DBG("netconfig_agent_unregister"); + + DBusMessage *reply = NULL; + char param1[64] = ""; + char *param_array[] = {NULL, NULL}; + + snprintf(param1, 64, "objpath:%s", NETCONFIG_WIFI_PATH); + param_array[0] = param1; + + reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "UnregisterAgent", param_array); + + if (reply == NULL) { + ERR("Error! Request failed"); + return FALSE; + } + + dbus_message_unref(reply); + + /* Clearing the agent fields */ + __netconfig_agent_clear_fields(); + + return TRUE; +} + +gboolean netconfig_iface_wifi_set_field(NetconfigWifi *wifi, + GHashTable *fields, GError **error) +{ + GHashTableIter iter; + gpointer field, value; + + DBG("Set agent fields"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + __netconfig_agent_clear_fields(); + + g_hash_table_iter_init(&iter, fields); + + while (g_hash_table_iter_next(&iter, &field, &value)) { + DBG("Field - [%s]", field); + if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0) { + g_free(agent.passphrase); + agent.passphrase = g_strdup(value); + + DBG("Field [%s] - []", field); + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PBC) == 0) { + agent.wps_pbc = FALSE; + if (g_strcmp0(value, "enable") == 0) + agent.wps_pbc = TRUE; + + DBG("Field [%s] - [%d]", field, agent.wps_pbc); + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PIN) == 0) { + g_free(agent.wps_pin); + agent.wps_pbc = FALSE; + agent.wps_pin = g_strdup(value); + + DBG("Field [%s] - []", field); + } + } + + return TRUE; +} + +gboolean netconfig_iface_wifi_request_input(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context) +{ + GHashTableIter iter; + gpointer field, value; + GHashTable *out_table = NULL; + GValue *ret_value = NULL; + + g_return_val_if_fail(wifi != NULL, FALSE); + + if (NULL == service) + return FALSE; + + DBG("Agent fields requested for service: %s", service); + + out_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + if (NULL == out_table) + return FALSE; + + g_hash_table_iter_init(&iter, fields); + + while (g_hash_table_iter_next(&iter, &field, &value)) { + if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0 && + agent.passphrase != NULL) { + ret_value = g_slice_new0(GValue); + + g_value_init(ret_value, G_TYPE_STRING); + g_value_set_string(ret_value, agent.passphrase); + g_hash_table_insert(out_table, g_strdup(field), ret_value); + + DBG("Setting [%s] - []", field); + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS) == 0 && + (agent.wps_pbc == TRUE || agent.wps_pin != NULL)) { + ret_value = g_slice_new0(GValue); + + g_value_init(ret_value, G_TYPE_STRING); + + if (agent.wps_pbc == TRUE) { + /* Sending empty string for WPS push button method */ + g_value_set_string(ret_value, ""); + + DBG("Setting empty string for [%s]", field); + } else if (agent.wps_pin != NULL) { + g_value_set_string(ret_value, agent.wps_pin); + + DBG("Setting string [%s] - []", field); + } + + g_hash_table_insert(out_table, g_strdup(field), ret_value); + } + } + + dbus_g_method_return(context, out_table); + + __netconfig_agent_clear_fields(); + + return TRUE; +} diff --git a/mobile/src/wifi-background-scan.c b/mobile/src/wifi-background-scan.c new file mode 100644 index 0000000..46e98e2 --- /dev/null +++ b/mobile/src/wifi-background-scan.c @@ -0,0 +1,286 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "wifi.h" +#include "netdbus.h" +#include "wifi-state.h" +#include "wifi-background-scan.h" + +#define SCAN_PERIODIC_DELAY 10 +#define SCAN_EXPONENTIAL_MIN 4 +#define SCAN_EXPONENTIAL_MAX 128 + +enum { + WIFI_BGSCAN_MODE_EXPONENTIAL = 0x00, + WIFI_BGSCAN_MODE_PERIODIC, + WIFI_BGSCAN_MODE_MAX, +}; + +struct bgscan_timer_data { + guint time; + guint mode; + guint timer_id; +}; + +static gboolean netconfig_wifi_scanning = FALSE; + +static struct bgscan_timer_data *__netconfig_wifi_bgscan_get_bgscan_data(void) +{ + static struct bgscan_timer_data timer_data = {SCAN_EXPONENTIAL_MIN, WIFI_BGSCAN_MODE_EXPONENTIAL, 0}; + + return &timer_data; +} + +static guint __netconfig_wifi_bgscan_mode(gboolean is_set_mode, guint mode) +{ + static guint bgscan_mode = WIFI_BGSCAN_MODE_EXPONENTIAL; + + if (is_set_mode != TRUE) + return bgscan_mode; + + if (mode < WIFI_BGSCAN_MODE_MAX) + bgscan_mode = mode; + + DBG("Wi-Fi background scan mode set %d", bgscan_mode); + + return bgscan_mode; +} + +static void __netconfig_wifi_bgscan_set_mode(guint mode) +{ + __netconfig_wifi_bgscan_mode(TRUE, mode); +} + +static guint __netconfig_wifi_bgscan_get_mode(void) +{ + return __netconfig_wifi_bgscan_mode(FALSE, -1); +} + +static gboolean __netconfig_wifi_bgscan_request_connman_scan(void) +{ + DBusMessage *reply = NULL; + + if (netconfig_wifi_state_get_service_state() == NETCONFIG_WIFI_CONNECTED) + if (__netconfig_wifi_bgscan_get_mode() == WIFI_BGSCAN_MODE_EXPONENTIAL) + return FALSE; + + if (netconfig_wifi_state_get_service_state() == NETCONFIG_WIFI_CONNECTING) + return FALSE; + + netconfig_wifi_set_scanning(TRUE); + + reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, CONNMAN_WIFI_TECHNOLOGY_PREFIX, + CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL); + + if (reply == NULL) { + ERR("Error! Request failed"); + return FALSE; + } + + dbus_message_unref(reply); + + return TRUE; +} + +static gboolean __netconfig_wifi_bgscan_request_scan(gpointer data); + +static void __netconfig_wifi_bgscan_start_timer(struct bgscan_timer_data *data) +{ + if (data == NULL) + return; + + netconfig_stop_timer(&(data->timer_id)); + + data->mode = __netconfig_wifi_bgscan_get_mode(); + + switch (data->mode) { + case WIFI_BGSCAN_MODE_EXPONENTIAL: + if (data->time == 0) + data->time = SCAN_EXPONENTIAL_MIN; + else if ((data->time >= SCAN_EXPONENTIAL_MAX) || + (data->time > SCAN_EXPONENTIAL_MAX / 2)) + data->time = SCAN_EXPONENTIAL_MAX; + else + data->time = data->time * 2; + + break; + case WIFI_BGSCAN_MODE_PERIODIC: + data->time = SCAN_PERIODIC_DELAY; + + break; + default: + DBG("Error! Wi-Fi background scan mode [%d]", data->mode); + return; + } + + DBG("Register background scan timer with %d seconds", data->time); + + netconfig_start_timer_seconds(data->time, + __netconfig_wifi_bgscan_request_scan, data, &(data->timer_id)); +} + +static void __netconfig_wifi_bgscan_stop_timer(struct bgscan_timer_data *data) +{ + if (data == NULL) + return; + + netconfig_stop_timer(&(data->timer_id)); +} + +static gboolean __netconfig_wifi_bgscan_request_scan(gpointer data) +{ + struct bgscan_timer_data *timer = (struct bgscan_timer_data *)data; + int pm_state = VCONFKEY_PM_STATE_NORMAL; + + if (timer == NULL) + return FALSE; + + /* In case of LCD off, we don't need Wi-Fi scan */ + vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) + return TRUE; + + __netconfig_wifi_bgscan_stop_timer(timer); + + DBG("Request Wi-Fi scan to ConnMan"); + __netconfig_wifi_bgscan_request_connman_scan(); + + __netconfig_wifi_bgscan_start_timer(timer); + + return FALSE; +} + +static void __netconfig_wifi_bgscan_mode_cb(keynode_t* node, void* user_data) +{ + int value; + int wifi_state; + + if (vconf_get_int(VCONFKEY_WIFI_BGSCAN_MODE, &value) < 0) { + ERR("VCONFKEY_WIFI_BGSCAN_MODE get failed"); + return; + } + + DBG("Background scanning mode is changed : %d", value); + + __netconfig_wifi_bgscan_set_mode((guint)value); + + if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state) < 0) { + ERR("VCONFKEY_WIFI_STATE get failed"); + return; + } + + if (wifi_state == VCONFKEY_WIFI_OFF) + return; + + struct bgscan_timer_data *timer_data = __netconfig_wifi_bgscan_get_bgscan_data(); + + if (timer_data->timer_id != 0) + netconfig_wifi_bgscan_stop(); + + netconfig_wifi_bgscan_start(); +} + +void netconfig_wifi_bgscan_start(void) +{ + struct bgscan_timer_data *timer_data = + __netconfig_wifi_bgscan_get_bgscan_data(); + + if (timer_data == NULL) + return; + + DBG("Wi-Fi background scan start"); + + __netconfig_wifi_bgscan_start_timer(timer_data); +} + +void netconfig_wifi_bgscan_stop(void) +{ + struct bgscan_timer_data *timer_data = + __netconfig_wifi_bgscan_get_bgscan_data(); + + if (timer_data == NULL) + return; + + DBG("Wi-Fi background scan stop"); + + timer_data->time = SCAN_EXPONENTIAL_MIN; + + __netconfig_wifi_bgscan_stop_timer(timer_data); +} + +gboolean netconfig_wifi_get_bgscan_state(void) +{ + struct bgscan_timer_data *timer_data = + __netconfig_wifi_bgscan_get_bgscan_data(); + + return ((timer_data->timer_id > (guint)0) ? TRUE : FALSE); +} + +gboolean netconfig_wifi_get_scanning(void) +{ + return netconfig_wifi_scanning; +} + +void netconfig_wifi_set_scanning(gboolean scanning) +{ + if (netconfig_wifi_scanning != scanning) + netconfig_wifi_scanning = scanning; +} + +gboolean netconfig_iface_wifi_set_bgscan(NetconfigWifi *wifi, guint scan_mode, GError **error) +{ + struct bgscan_timer_data *timer_data = __netconfig_wifi_bgscan_get_bgscan_data(); + + __netconfig_wifi_bgscan_set_mode(scan_mode); + + if (timer_data->timer_id != 0) + netconfig_wifi_bgscan_stop(); + + netconfig_wifi_bgscan_start(); + + return TRUE; +} + +void netconfig_wifi_init_bgscan() +{ + guint scan_mode = __netconfig_wifi_bgscan_get_mode(); + + if (scan_mode == WIFI_BGSCAN_MODE_PERIODIC) + vconf_set_int(VCONFKEY_WIFI_BGSCAN_MODE, VCONFKEY_WIFI_BGSCAN_MODE_PERIODIC); + else + vconf_set_int(VCONFKEY_WIFI_BGSCAN_MODE, VCONFKEY_WIFI_BGSCAN_MODE_EXPONENTIAL); + + if (vconf_notify_key_changed(VCONFKEY_WIFI_BGSCAN_MODE, + __netconfig_wifi_bgscan_mode_cb, NULL)) + DBG("Failed to set notify callback"); +} + +void netconfig_wifi_deinit_bgscan() +{ + if (vconf_ignore_key_changed(VCONFKEY_WIFI_BGSCAN_MODE, + __netconfig_wifi_bgscan_mode_cb)) + DBG("Failed to unset notify callback"); +} + diff --git a/mobile/src/wifi-eap-config.c b/mobile/src/wifi-eap-config.c new file mode 100644 index 0000000..1a47507 --- /dev/null +++ b/mobile/src/wifi-eap-config.c @@ -0,0 +1,216 @@ +/* + * Network Configuration Module + * + * 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 "wifi-eap-config.h" +#include "log.h" +#include "wifi.h" + +static char *__get_ssid(const char *name) +{ + char *buf = NULL; + char buf_tmp[32] = {0,}; + int i = 0; + int len = 0; + + if (NULL == name) + return NULL; + + len = strlen(name); + + buf = g_try_malloc0(len * 2 + 1); + if (buf == NULL) + return NULL; + + for (i = 0; i < len; i++) { + snprintf(buf_tmp, 3, "%02x", name[i]); + strcat(buf, buf_tmp); + } + + DBG("SSID - [%s]\n", buf); + + return buf; +} + +static gboolean __config_save(GKeyFile *keyfile, char *file_name) +{ + gchar *data = NULL; + gsize length = 0; + FILE *file = NULL; + int ret = TRUE; + + data = g_key_file_to_data(keyfile, &length, NULL); + DBG("Data lenght-[%d]", length); + + file = fopen(file_name, "w"); + if (NULL == file) { + DBG("fopen() fails!"); + ret = FALSE; + } else { + fputs(data, file); + fclose(file); + DBG("Wrote data successfully to [%s] file!", file_name); + } + + g_free(data); + + return ret; +} + +static gboolean __config_delete(const char *ssid) +{ + gchar *config_file = NULL; + gboolean ret = FALSE; + + config_file = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, + ssid); + if(config_file == NULL) + return FALSE; + + if (g_file_test(config_file, G_FILE_TEST_EXISTS) == FALSE) { + ret = TRUE; + } else if (g_file_test(config_file, G_FILE_TEST_IS_REGULAR) == TRUE) { + unlink(config_file); + ret = TRUE; + } + + g_free(config_file); + + return ret; +} + +gboolean netconfig_iface_wifi_create_config(NetconfigWifi *wifi, + GHashTable *fields, GError **error) +{ + DBG("netconfig_iface_wifi_create_config"); + g_return_val_if_fail(wifi != NULL, FALSE); + + gboolean ret = TRUE; + GKeyFile *keyfile = NULL; + GHashTableIter iter; + gpointer field, value; + gchar *file_name = NULL; + gchar *ssid_hex = NULL; + gchar *grp_name = NULL; + + g_hash_table_iter_init(&iter, fields); + while (g_hash_table_iter_next(&iter, &field, &value)) { + if (NULL != value) { + if (!strcmp(field, CONNMAN_CONFIG_FIELD_NAME)) { + ssid_hex = __get_ssid(value); + break; + } else if (!strcmp(field, CONNMAN_CONFIG_FIELD_SSID)) { + ssid_hex = g_strdup_printf("%s", + (gchar *)value); + break; + } + } + } + + if (NULL == ssid_hex) { + DBG("Fail! Could not fetch the ssid"); + return FALSE; + } + + /* Create unique service group name */ + grp_name = g_strdup_printf("service_%s", ssid_hex); + if(NULL == grp_name) { + DBG("Fail! Could not create the service group name"); + g_free(ssid_hex); + return FALSE; + } + + keyfile = g_key_file_new(); + if (NULL == keyfile) { + DBG("g_key_file_new() fails!"); + g_free(grp_name); + g_free(ssid_hex); + return FALSE; + } + + g_hash_table_iter_init(&iter, fields); + while (g_hash_table_iter_next(&iter, &field, &value)) { + DBG("Field - [%s] Value - [%s]", field, value); + + if (NULL != value) + g_key_file_set_string(keyfile, grp_name, field, value); + } + + file_name = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, + ssid_hex); + if(NULL == file_name) { + DBG("g_strdup_printf() fails. Could not save config!"); + g_key_file_free(keyfile); + g_free(grp_name); + g_free(ssid_hex); + return FALSE; + } + + ret = __config_save(keyfile, file_name); + if (FALSE == ret) + DBG("Could not save config!"); + else + DBG("Saved config in [%s] successfully", file_name); + + g_key_file_free(keyfile); + g_free(file_name); + g_free(grp_name); + g_free(ssid_hex); + + return ret; +} + +gboolean netconfig_iface_wifi_delete_config(NetconfigWifi *wifi, + gchar *profile, GError **error) +{ + DBG("netconfig_iface_wifi_delete_config"); + g_return_val_if_fail(wifi != NULL, FALSE); + + gboolean ret = TRUE; + char *str1 = NULL; + char *str2 = NULL; + char *str3 = NULL; + char ssid[512] = ""; + int ssid_len = 0; + + str1 = strstr(profile, "wifi_"); + if (NULL != str1) { + str2 = strchr(str1 + 5, '_'); + if (NULL != str2) { + str3 = strchr(str2 + 1, '_'); + ssid_len = str3 - str2 - 1; + strncpy(ssid, str2 + 1, ssid_len); + DBG("ssid_len - [%d] SSID - [%s]", ssid_len, ssid); + + ret = __config_delete(ssid); + if (TRUE == ret) + DBG("Deleted the config file successfully"); + else + DBG("Deletion of config file failed"); + } else { + DBG("Fetching of SSID fails"); + } + } else { + DBG("Fetching of SSID fails"); + } + + return ret; +} diff --git a/mobile/src/wifi-eap.c b/mobile/src/wifi-eap.c new file mode 100644 index 0000000..9e3a4de --- /dev/null +++ b/mobile/src/wifi-eap.c @@ -0,0 +1,471 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" + +#define SIM_RAND_DATA_LEN 16 +#define SIM_AUTH_MAX_RESP_DATA_LEN 128 +#define SIM_AUTH_SRES_LEN 4 +#define SIM_AUTH_KC_LEN 8 + +#define AKA_RAND_DATA_LEN 16 +#define AKA_AUTN_DATA_LEN 16 +#define AKA_AUTH_RES_MAX_LEN 16 +#define AKA_AUTH_RES_MIN_LEN 4 +#define AKA_AUTH_CK_LEN 16 +#define AKA_AUTH_IK_LEN 16 + +struct wifii_authentication_data { + int auth_result; + int resp_length; + int authentication_key_length; + int cipher_length; + int integrity_length; + char *resp_data; + char *authentication_key; + char *cipher_data; + char *integrity_data; +}; + +TapiHandle *tapi_handle = NULL; +static struct wifii_authentication_data *wifi_authdata; + +static void *__netconfig_wifi_free_wifi_authdata(struct wifii_authentication_data *data) +{ + if (data) { + if (data->resp_data) + g_free(data->resp_data); + if (data->authentication_key) + g_free(data->authentication_key); + if (data->cipher_data) + g_free(data->cipher_data); + if (data->integrity_data) + g_free(data->integrity_data); + + g_free(data); + data = NULL; + } + + return NULL; +} + +static void __netconfig_tapi_init() +{ + tapi_handle = tel_init(NULL); +} + +static void __netconfig_tapi_deinit() +{ + tel_deinit(tapi_handle); + tapi_handle = NULL; + + wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); +} + +static gboolean __netconfig_wifi_get_sim_imsi(DBusGMethodInvocation *context) +{ + DBG(" "); + + int ret; + GError *error = NULL; + TelSimImsiInfo_t imsi_info; + char *imsi; + + if (tapi_handle == NULL) + __netconfig_tapi_init(); + + ret = tel_get_sim_imsi(tapi_handle, &imsi_info); + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_get_sim_imsi() : [%d]", ret); + netconfig_error_fail_get_imsi(&error); + dbus_g_method_return_error(context, error); + return FALSE; + } + + imsi = g_strdup_printf("%s%s%s", imsi_info.szMcc, imsi_info.szMnc, imsi_info.szMsin); + + dbus_g_method_return(context, imsi); + g_free(imsi); + + return TRUE; +} + +void __netconfig_response_sim_authentication(TapiHandle *handle, int result, void *data, void *user_data) +{ + DBG(" "); + + if (wifi_authdata != NULL) + wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); + + wifi_authdata = g_try_new0(struct wifii_authentication_data, 1); + + TelSimAuthenticationResponse_t *auth_resp = (TelSimAuthenticationResponse_t *) data; + if (auth_resp == NULL) { + ERR("the auth response is NULL"); + wifi_authdata->auth_result = -1; + return; + } else { + wifi_authdata->auth_result = auth_resp->auth_result; + } + + if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + wifi_authdata->resp_length = auth_resp->resp_length; + wifi_authdata->authentication_key_length = auth_resp->authentication_key_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + + if (wifi_authdata->authentication_key != NULL) + g_free(wifi_authdata->authentication_key); + wifi_authdata->authentication_key = g_strdup(auth_resp->authentication_key); + } else { + ERR("the result error for sim auth : [%d]", auth_resp->auth_result); + wifi_authdata->resp_length = 0; + wifi_authdata->authentication_key_length = 0; + } +} + +void __netconfig_response_aka_authentication(TapiHandle *handle, int result, void *data, void *user_data) +{ + DBG(" "); + + if (wifi_authdata != NULL) + wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); + + wifi_authdata = g_try_new0(struct wifii_authentication_data, 1); + + TelSimAuthenticationResponse_t *auth_resp = (TelSimAuthenticationResponse_t *) data; + if (auth_resp == NULL) { + ERR("the auth response is NULL"); + wifi_authdata->auth_result = -1; + return; + } else { + wifi_authdata->auth_result = auth_resp->auth_result; + } + + if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + wifi_authdata->resp_length = auth_resp->resp_length; + wifi_authdata->cipher_length = auth_resp->cipher_length; + wifi_authdata->integrity_length = auth_resp->integrity_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + + if (wifi_authdata->cipher_data != NULL) + g_free(wifi_authdata->cipher_data); + wifi_authdata->cipher_data = g_strdup(auth_resp->cipher_data); + + if (wifi_authdata->integrity_data != NULL) + g_free(wifi_authdata->integrity_data); + wifi_authdata->integrity_data = g_strdup(auth_resp->integrity_data); + } else { + ERR("the result error for aka auth : [%d]", auth_resp->auth_result); + if (auth_resp->auth_result == TAPI_SIM_AUTH_SQN_FAILURE || + auth_resp->auth_result == TAPI_SIM_AUTH_SYNCH_FAILURE) { + wifi_authdata->resp_length = auth_resp->resp_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + } + } +} + +static gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data, GError **error) +{ + DBG(" "); + + int i; + int ret; + TelSimAuthenticationData_t auth_data; + + if (rand_data->len != SIM_RAND_DATA_LEN) { + ERR("wrong rand data len : [%d]", rand_data->len); + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if ((ret = g_array_get_element_size(rand_data)) != 1) { + ERR("wrong rand data size : [%d]", ret); + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + memset(&auth_data, 0, sizeof(auth_data)); + auth_data.auth_type = TAPI_SIM_AUTH_TYPE_GSM; + auth_data.rand_length = SIM_RAND_DATA_LEN; + for (i=0; ilen; i++) + auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); + + if (tapi_handle == NULL) + __netconfig_tapi_init(); + + ret = tel_req_sim_authentication(tapi_handle, &auth_data, __netconfig_response_sim_authentication, NULL); + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_req_sim_authentication() : [%d]", ret); + netconfig_error_fail_req_sim_auth(error); + return FALSE; + } + + return TRUE; +} + +static gboolean __netconfig_wifi_req_aka_auth(GArray *rand_data, GArray *autn_data, GError **error) +{ + DBG(" "); + + int i; + int ret; + TelSimAuthenticationData_t auth_data; + + if (rand_data->len != AKA_RAND_DATA_LEN) { + ERR("wrong rand data len : [%d]", rand_data->len); + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if (autn_data->len != AKA_AUTN_DATA_LEN) { + ERR("wrong autn data len : [%d]", autn_data->len); + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if ((ret = g_array_get_element_size(rand_data)) != 1) { + ERR("wrong rand data size : [%d]", ret); + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if ((ret = g_array_get_element_size(autn_data)) != 1) { + ERR("wrong autn data size : [%d]", ret); + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + memset(&auth_data, 0, sizeof(auth_data)); + auth_data.auth_type = TAPI_SIM_AUTH_TYPE_3G; + auth_data.rand_length = AKA_RAND_DATA_LEN; + auth_data.autn_length = AKA_AUTN_DATA_LEN; + for (i=0; ilen; i++) + auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); + for (i=0; ilen; i++) + auth_data.autn_data[i] = g_array_index(autn_data, guint8, i); + + if (tapi_handle == NULL) + __netconfig_tapi_init(); + + ret = tel_req_sim_authentication(tapi_handle, &auth_data, __netconfig_response_aka_authentication, NULL); + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_req_sim_authentication() : [%d]", ret); + netconfig_error_fail_req_sim_auth(error); + return FALSE; + } + + return TRUE; +} + +static gboolean __netconfig_wifi_get_sim_authdata(DBusGMethodInvocation *context) +{ + DBG(" "); + + GArray *array = NULL; + GError *error = NULL; + + if (wifi_authdata == NULL) { + DBG("the status error : no response yet"); + netconfig_error_fail_get_sim_auth_delay(&error); + dbus_g_method_return_error(context, error); + return FALSE; + } + + if (wifi_authdata->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + if (wifi_authdata->resp_length == SIM_AUTH_SRES_LEN && + wifi_authdata->authentication_key_length == SIM_AUTH_KC_LEN) { + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), SIM_AUTH_SRES_LEN+SIM_AUTH_KC_LEN); + g_array_append_vals(array, wifi_authdata->resp_data, SIM_AUTH_SRES_LEN); + g_array_append_vals(array, wifi_authdata->authentication_key, SIM_AUTH_KC_LEN); + dbus_g_method_return(context, array); + g_array_free (array, TRUE); + } else { + ERR("auth data length is wrong, SRES = [%d], Kc = [%d]", + wifi_authdata->resp_length, wifi_authdata->authentication_key_length); + + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + __netconfig_tapi_deinit(); + return FALSE; + } + } else { + ERR("failed auth result = [%d]", wifi_authdata->auth_result); + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + __netconfig_tapi_deinit(); + return FALSE; + } + + __netconfig_tapi_deinit(); + return TRUE; +} + +static gboolean __netconfig_wifi_get_aka_authdata(DBusGMethodInvocation *context) +{ + DBG(" "); + + GArray *array = NULL; + GError *error = NULL; + guchar res_len; + + if (wifi_authdata == NULL) { + DBG("the status error : no response yet"); + netconfig_error_fail_get_sim_auth_delay(&error); + dbus_g_method_return_error(context, error); + return FALSE; + } + + switch (wifi_authdata->auth_result) { + case TAPI_SIM_AUTH_NO_ERROR: + break; + + case TAPI_SIM_AUTH_SQN_FAILURE: + case TAPI_SIM_AUTH_SYNCH_FAILURE: + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), wifi_authdata->resp_length+1); + res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); + + g_array_append_vals(array, &res_len, 1); + g_array_append_vals(array, wifi_authdata->resp_data, wifi_authdata->resp_length); + + dbus_g_method_return(context, array); + g_array_free (array, TRUE); + + g_free(wifi_authdata->resp_data); + g_free(wifi_authdata); + wifi_authdata = NULL; + + return TRUE; + + default: + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + __netconfig_tapi_deinit(); + return FALSE; + } + + if ((wifi_authdata->resp_length >= AKA_AUTH_RES_MIN_LEN || + wifi_authdata->resp_length <= AKA_AUTH_RES_MAX_LEN) && + wifi_authdata->cipher_length == AKA_AUTH_CK_LEN && + wifi_authdata->integrity_length == AKA_AUTH_IK_LEN) { + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), wifi_authdata->resp_length+AKA_AUTH_CK_LEN+AKA_AUTH_IK_LEN+1); + + res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); + g_array_append_vals(array, &res_len, 1); + g_array_append_vals(array, wifi_authdata->resp_data, wifi_authdata->resp_length); + g_array_append_vals(array, wifi_authdata->cipher_data, AKA_AUTH_CK_LEN); + g_array_append_vals(array, wifi_authdata->integrity_data, AKA_AUTH_IK_LEN); + + dbus_g_method_return(context, array); + g_array_free (array, TRUE); + } else { + ERR("auth data length is wrong, res = [%d], Kc = [%d], Ki = [%d]", + wifi_authdata->resp_length, wifi_authdata->cipher_length, wifi_authdata->integrity_length); + + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + __netconfig_tapi_deinit(); + return FALSE; + } + + __netconfig_tapi_deinit(); + return TRUE; +} + +gboolean netconfig_iface_wifi_get_sim_imsi(NetconfigWifi *wifi, DBusGMethodInvocation *context) +{ + gboolean ret = TRUE; + + DBG("Get sim Imsi"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_get_sim_imsi(context); + + return ret; +} + +gboolean netconfig_iface_wifi_req_sim_auth(NetconfigWifi *wifi, GArray *rand_data, gboolean *result, GError **error) +{ + gboolean ret = TRUE; + + DBG("Req sim Authentication"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_req_sim_auth(rand_data, error); + + *result = ret; + return ret; +} + +gboolean netconfig_iface_wifi_req_aka_auth(NetconfigWifi *wifi, GArray *rand_data, GArray *autn_data, gboolean *result, GError **error) +{ + gboolean ret = TRUE; + + DBG("Req aka Authentication"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_req_aka_auth(rand_data, autn_data, error); + + *result = ret; + return ret; +} + +gboolean netconfig_iface_wifi_get_sim_auth(NetconfigWifi *wifi, DBusGMethodInvocation *context) +{ + gboolean ret = TRUE; + + DBG("Get sim Authdata"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_get_sim_authdata(context); + + return ret; +} + +gboolean netconfig_iface_wifi_get_aka_auth(NetconfigWifi *wifi, DBusGMethodInvocation *context) +{ + gboolean ret = TRUE; + + DBG("Get aka Authdata"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_get_aka_authdata(context); + + return ret; +} diff --git a/mobile/src/wifi-indicator.c b/mobile/src/wifi-indicator.c new file mode 100644 index 0000000..115e08f --- /dev/null +++ b/mobile/src/wifi-indicator.c @@ -0,0 +1,287 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "network-statistics.h" +#include "netsupplicant.h" +#include "wifi-indicator.h" + +#define VCONFKEY_WIFI_SNR_MIN -89 + +#define NETCONFIG_WIFI_INDICATOR_INTERVAL 1 + +static guint64 netconfig_wifi_tx_bytes = 0; +static guint64 netconfig_wifi_rx_bytes = 0; + +static guint netconfig_wifi_indicator_timer = 0; + +#if defined NL80211 +static int __netconfig_wifi_get_signal(const char *object_path) +{ + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusMessageIter iter; + int rssi_dbm = 0; + int MessageType = 0; + + if (object_path == NULL) { + ERR("Error!!! path is NULL"); + goto error; + } + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Error!!! Failed to get system DBus"); + goto error; + } + + message = netconfig_supplicant_invoke_dbus_method( + SUPPLICANT_SERVICE, connection, object_path, + SUPPLICANT_INTERFACE ".Interface", "GetLinkSignal", + NULL); + + if (message == NULL) { + ERR("Error!!! Failed to get service properties"); + goto error; + } + + MessageType = dbus_message_get_type(message); + + if (MessageType == DBUS_MESSAGE_TYPE_ERROR) { + const char *err_msg = dbus_message_get_error_name(message); + ERR("Error!!! Error message received [%s]", err_msg); + goto error; + } + + dbus_message_iter_init(message, &iter); + + if ((MessageType = dbus_message_iter_get_arg_type(&iter)) == DBUS_TYPE_INT32) + dbus_message_iter_get_basic(&iter, &rssi_dbm); + else + goto error; + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return rssi_dbm; + +error: + if (message != NULL) + dbus_message_unref(message); + + if (connection != NULL) + dbus_connection_unref(connection); + + return VCONFKEY_WIFI_SNR_MIN; +} + +static int __netconfig_wifi_get_rssi_from_supplicant(void) +{ + int rssi_dbm =0; + + char object_path[DBUS_PATH_MAX_BUFLEN] = { 0, }; + char *path_ptr = &object_path[0]; + + if (netconfig_wifi_get_supplicant_interface(&path_ptr) != TRUE) { + DBG("Fail to get wpa_supplicant DBus path"); + return VCONFKEY_WIFI_SNR_MIN; + } + + rssi_dbm = __netconfig_wifi_get_signal((const char *)path_ptr); + + return rssi_dbm; +} +#endif /* #if defined NL80211 */ + +#if !defined NL80211 +static int __netconfig_wifi_get_rssi_from_system(void) +{ + int rssi_dbm = 0; + char ifname[16] = { 0, }; + char *ifname_ptr = &ifname[0]; + + int fd = -1; + struct iwreq wifi_req; + struct iw_statistics stats; + unsigned int iw_stats_len = sizeof(struct iw_statistics); + + if (netconfig_wifi_get_ifname(&ifname_ptr) != TRUE) { + DBG("Fail to get Wi-Fi ifname from wpa_supplicant: %s", ifname_ptr); + return VCONFKEY_WIFI_SNR_MIN; + } + + /* Set device name */ + memset(wifi_req.ifr_name, 0, sizeof(wifi_req.ifr_name)); + strncpy(wifi_req.ifr_name, ifname, sizeof(wifi_req.ifr_name) - 1); + wifi_req.ifr_name[sizeof(wifi_req.ifr_name) - 1] = '\0'; + + wifi_req.u.data.pointer = (caddr_t) &stats; + wifi_req.u.data.length = iw_stats_len; + wifi_req.u.data.flags = 1; /* Clear updated flag */ + + if ((fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0) { + DBG("Fail to open socket to get rssi"); + return VCONFKEY_WIFI_SNR_MIN; + } + + memset(&stats, 0, iw_stats_len); + + if (ioctl(fd, SIOCGIWSTATS, &wifi_req) < 0) { + DBG("Fail to execute ioctl for SIOCGIWSTATS"); + close(fd); + + return VCONFKEY_WIFI_SNR_MIN; + } + close(fd); + + rssi_dbm = stats.qual.level - 255; /** signed integer, so 255 */ + + return rssi_dbm; +} +#endif /* #if !defined NL80211 */ + +int netconfig_wifi_get_rssi(void) +{ + int rssi_dbm = 0; + + /* There are two ways to get Wi-Fi RSSI: + * - WEXT interface, get DBus path of wpa_supplicant, + * and get Wi-Fi interface name e.g. wlan0 from wpa_supplicant. + * IOCTL with ifname will return RSSI dB. + * - NL80211 interface, get DBus path of wpa_supplicant, + * and get RSSI from wpa_supplicant directly. + * However, in this case wpa_supplicant needs some modification + * to get RSSI from DBus interface. */ + +#if defined NL80211 + rssi_dbm = __netconfig_wifi_get_rssi_from_supplicant(); +#else + rssi_dbm = __netconfig_wifi_get_rssi_from_system(); +#endif + + return rssi_dbm; +} + +static void __netconfig_wifi_set_rssi_level(int rssi_dbm) +{ + int snr_level = 0; + static int last_snr_level = 0; + + /* Wi-Fi Signal Strength Display + * + * Excellent : -63 ~ + * Good: -74 ~ -64 + * Weak: -82 ~ -75 + * Very weak: ~ -83 + */ + if (rssi_dbm >= -63) + snr_level = 4; + else if (rssi_dbm >= -74) + snr_level = 3; + else if (rssi_dbm >= -82) + snr_level = 2; + else + snr_level = 1; + + if (snr_level != last_snr_level) { + INFO("Wi-Fi RSSI: %d dB, %d level", rssi_dbm, snr_level); + + vconf_set_int(VCONFKEY_WIFI_STRENGTH, snr_level); + + last_snr_level = snr_level; + } +} + +static gboolean __netconfig_wifi_indicator_monitor(gpointer data) +{ + int rssi_dbm = 0; + int pm_state = VCONFKEY_PM_STATE_NORMAL; + guint64 tx = 0, rx = 0; + + /* In case of LCD off, we don't need to update Wi-Fi indicator */ + vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) + return TRUE; + + rssi_dbm = netconfig_wifi_get_rssi(); + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) { + if (netconfig_wifi_tx_bytes < tx) { + if (netconfig_wifi_rx_bytes < rx) + vconf_set_int(VCONFKEY_WIFI_TRANSFER_STATE, VCONFKEY_WIFI_TRANSFER_STATE_TXRX); + else + vconf_set_int(VCONFKEY_WIFI_TRANSFER_STATE, VCONFKEY_WIFI_TRANSFER_STATE_TX); + } else { + if (netconfig_wifi_rx_bytes < rx) + vconf_set_int(VCONFKEY_WIFI_TRANSFER_STATE, VCONFKEY_WIFI_TRANSFER_STATE_RX); + else + vconf_set_int(VCONFKEY_WIFI_TRANSFER_STATE, VCONFKEY_WIFI_TRANSFER_STATE_NONE); + } + + netconfig_wifi_tx_bytes = tx; + netconfig_wifi_rx_bytes = rx; + } + + __netconfig_wifi_set_rssi_level(rssi_dbm); + + return TRUE; +} + +void netconfig_wifi_indicator_start(void) +{ + guint64 tx = 0, rx = 0; + + INFO("Start Wi-Fi indicator"); + + vconf_set_int(VCONFKEY_WIFI_STRENGTH, VCONFKEY_WIFI_STRENGTH_MAX); + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) { + netconfig_wifi_tx_bytes = tx; + netconfig_wifi_rx_bytes = rx; + } else { + netconfig_wifi_tx_bytes = 0; + netconfig_wifi_rx_bytes = 0; + } + + netconfig_start_timer_seconds( + NETCONFIG_WIFI_INDICATOR_INTERVAL, + __netconfig_wifi_indicator_monitor, + NULL, + &netconfig_wifi_indicator_timer); +} + +void netconfig_wifi_indicator_stop(void) +{ + INFO("Stop Wi-Fi indicator"); + + vconf_set_int(VCONFKEY_WIFI_STRENGTH, VCONFKEY_WIFI_STRENGTH_MAX); + + netconfig_stop_timer(&netconfig_wifi_indicator_timer); +} diff --git a/mobile/src/wifi-power.c b/mobile/src/wifi-power.c new file mode 100644 index 0000000..1eb0e07 --- /dev/null +++ b/mobile/src/wifi-power.c @@ -0,0 +1,441 @@ +/* + * Network Configuration Module + * + * 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 "wifi.h" +#include "log.h" +#include "wifi.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "netconfig.h" +#include "emulator.h" +#include "network-statistics.h" +#include "wifi-background-scan.h" +#include "wifi-power.h" +#include "wifi-state.h" +#include "wifi-agent.h" +#include "wifi-eap-config.h" + + +#define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh" + +static gboolean power_in_progress = FALSE; +static gboolean fm_waiting = FALSE; + +static void __netconfig_wifi_technology_reply(DBusPendingCall *call, void *data) +{ + DBusMessage *message; + + message = dbus_pending_call_steal_reply(call); + + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { + ERR("%s", dbus_message_get_error_name(message)); + + if (dbus_message_is_error(message, + CONNMAN_ERROR_INTERFACE ".AlreadyEnabled") == TRUE) { + netconfig_wifi_update_power_state(TRUE); + power_in_progress = FALSE; + } else if (dbus_message_is_error(message, + CONNMAN_ERROR_INTERFACE ".AlreadyDisabled") == TRUE) { + netconfig_wifi_update_power_state(FALSE); + power_in_progress = FALSE; + } + } else { + DBG("Successfully requested"); + } + + dbus_message_unref(message); + dbus_pending_call_unref(call); +} + +static gboolean __netconfig_wifi_enable_technology(void) +{ + gboolean reply = FALSE; + char param0[] = "string:Powered"; + char param1[] = "variant:boolean:true"; + char *param_array[] = { NULL, NULL, NULL }; + + param_array[0] = param0; + param_array[1] = param1; + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, + "SetProperty", param_array, __netconfig_wifi_technology_reply); + + if (reply != TRUE) + ERR("Fail to enable Wi-Fi"); + + return reply; +} + +static gboolean __netconfig_wifi_disable_technology(void) +{ + gboolean reply = FALSE; + char param0[] = "string:Powered"; + char param1[] = "variant:boolean:false"; + char *param_array[] = { NULL, NULL, NULL }; + + param_array[0] = param0; + param_array[1] = param1; + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, + "SetProperty", param_array, __netconfig_wifi_technology_reply); + + if (reply != TRUE) + ERR("Fail to disable Wi-Fi"); + + return reply; +} + +static gboolean __netconfig_wifi_load_driver(void) +{ + gboolean rv = FALSE; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "wlan.sh", "start", NULL }; + char *const envs[] = { NULL }; + + if (netconfig_emulator_is_emulated() == TRUE) + return rv; + + rv = netconfig_execute_file(path, args, envs); + if (rv != TRUE) { + DBG("Failed to load wireless device driver"); + return FALSE; + } + + DBG("Successfully loaded wireless device driver"); + return TRUE; +} + +gboolean netconfig_wifi_remove_driver(void) +{ + gboolean rv = FALSE; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "wlan.sh", "stop", NULL }; + char *const env[] = { NULL }; + + if (netconfig_emulator_is_emulated() == TRUE) + return rv; + + rv = netconfig_execute_file(path, args, env); + if (rv != TRUE) { + DBG("Failed to remove wireless device driver"); + return FALSE; + } + + DBG("Successfully removed wireless device driver"); + return TRUE; +} + +static int __netconfig_wifi_try_to_load_driver(void); +static gboolean __netconfig_wifi_try_to_remove_driver(void); + +void netconfig_wifi_notify_power_completed(gboolean power_on) +{ + DBusMessage *signal; + DBusConnection *connection; + DBusError error; + char *sig_name; + + if (power_on) + sig_name = "PowerOnCompleted"; + else + sig_name = "PowerOffCompleted"; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + ERR("Error!!! Failed to get system DBus, error [%s]", error.message); + dbus_error_free(&error); + return; + } + + signal = dbus_message_new_signal(NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, sig_name); + if (signal == NULL) + return; + + dbus_connection_send(connection, signal, NULL); + + dbus_message_unref(signal); + dbus_connection_unref(connection); + + INFO("(%s)", sig_name); +} + +static void __netconfig_wifi_direct_state_cb(int error_code, + wifi_direct_device_state_e device_state, void *user_data) +{ + wifi_direct_unset_device_state_changed_cb(); + wifi_direct_deinitialize(); + + if (device_state == WIFI_DIRECT_DEVICE_STATE_DEACTIVATED) { + if (__netconfig_wifi_try_to_load_driver() < 0) { + power_in_progress = FALSE; + + /* TODO: error report */ + + return; + } + } +} + +static gboolean __netconfig_wifi_direct_power_off(void) +{ + DBG("Wi-Fi direct is turning off"); + + if (wifi_direct_initialize() < 0) + return FALSE; + + if (wifi_direct_set_device_state_changed_cb( + __netconfig_wifi_direct_state_cb, NULL) < 0) + return FALSE; + + if (wifi_direct_deactivate() < 0) + return FALSE; + + return TRUE; +} + +gboolean netconfig_is_wifi_allowed(void) +{ + return TRUE; +} + +static int __netconfig_wifi_try_to_load_driver(void) +{ + if (netconfig_is_wifi_allowed() != TRUE) + return -EPERM; + + if (netconfig_is_wifi_tethering_on() == TRUE) { + /* TODO: Wi-Fi tethering turns off here */ + /* return TRUE; */ + return -EBUSY; + } + + if (netconfig_is_wifi_direct_on() == TRUE) { + if (__netconfig_wifi_direct_power_off() == TRUE) { + power_in_progress = TRUE; + return -EINPROGRESS; + } else + return -EBUSY; + } + + if (__netconfig_wifi_load_driver() != TRUE) { + netconfig_wifi_remove_driver(); + + return -EIO; + } + + if (__netconfig_wifi_enable_technology() != TRUE) { + netconfig_wifi_remove_driver(); + return -EIO; + } + + power_in_progress = TRUE; + + return 0; +} + +static gboolean __netconfig_wifi_try_to_remove_driver(void) +{ + netconfig_wifi_device_picker_service_stop(); + + netconfig_wifi_statistics_update_powered_off(); + + if (__netconfig_wifi_disable_technology() != TRUE) + return FALSE; + + power_in_progress = TRUE; + + return TRUE; +} + +static void __netconfig_wifi_airplane_mode(keynode_t* node, + void* user_data) +{ + int value = 0; + int wifi_state = 0; + static gboolean powered_off_by_flightmode = FALSE; + + if (power_in_progress) { + fm_waiting = TRUE; + return; + } + + fm_waiting = FALSE; + + vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &value); + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + + DBG("flight mode %s", value > 0 ? "ON" : "OFF"); + DBG("Wi-Fi state %d, Wi-Fi was off by flight mode %s", + wifi_state, powered_off_by_flightmode == TRUE ? "Yes" : "No"); + + if (value > 0) { + /* flight mode enabled */ + if (wifi_state == VCONFKEY_WIFI_OFF) + return; + + DBG("Turning Wi-Fi off"); + + __netconfig_wifi_try_to_remove_driver(); + + powered_off_by_flightmode = TRUE; + } else if (value == 0) { + /* flight mode disabled */ + if (wifi_state > VCONFKEY_WIFI_OFF) + return; + + if (powered_off_by_flightmode != TRUE) + return; + + __netconfig_wifi_try_to_load_driver(); + + powered_off_by_flightmode = FALSE; + } else + DBG("Invalid value (%d)", value); +} + +static void __netconfig_wifi_pm_state_mode(keynode_t* node, + void* user_data) +{ + int value = -1; + int wifi_state = 0; + static int prev_state = VCONFKEY_PM_STATE_NORMAL; + + /*** vconf-keys.h *** + * VCONFKEY_PM_STATE_NORMAL = 1, + * VCONFKEY_PM_STATE_LCDDIM, + * VCONFKEY_PM_STATE_LCDOFF, + * VCONFKEY_PM_STATE_SLEEP + */ + + if(vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state) == 0) { + DBG("wifi state : %d (0 off / 1 on / 2 connected)", wifi_state); + if(wifi_state <= VCONFKEY_WIFI_OFF) + return; + } + + if(vconf_get_int(VCONFKEY_PM_STATE, &value) < 0) { + ERR("VCONFKEY_PM_STATE get failed"); + return; + } + + DBG("Old state: %d, current: %d", prev_state, value); + + if((value == VCONFKEY_PM_STATE_NORMAL) && (prev_state >= VCONFKEY_PM_STATE_LCDOFF)) { + DBG("PM state : Wake UP!"); + + netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_start(); + } + + prev_state = value; +} + +void netconfig_set_power_in_progress(gboolean in_progress) +{ + power_in_progress = in_progress; +} + +void netconfig_check_fm_waiting(void) +{ + if (fm_waiting) + __netconfig_wifi_airplane_mode(NULL, NULL); +} + +void netconfig_wifi_power_configuration(void) +{ + int wifi_last_power_state = 0; + + vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + __netconfig_wifi_airplane_mode, NULL); + + vconf_notify_key_changed(VCONFKEY_PM_STATE, + __netconfig_wifi_pm_state_mode, NULL); + + vconf_get_int(VCONF_WIFI_LAST_POWER_STATE, &wifi_last_power_state); + + if (wifi_last_power_state == WIFI_POWER_ON) { + DBG("Turn Wi-Fi on automatically"); + + __netconfig_wifi_try_to_load_driver(); + } +} + +gboolean netconfig_iface_wifi_load_driver(NetconfigWifi *wifi, GError **error) +{ + DBG("Wi-Fi power on requested"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + int err; + + if (netconfig_is_wifi_allowed() != TRUE) { + netconfig_error_security_restricted(error); + + return FALSE; + } + + if (power_in_progress) { + netconfig_error_wifi_driver_failed(error); + return FALSE; + } + + err = __netconfig_wifi_try_to_load_driver(); + if (err < 0) { + if (err == -EINPROGRESS) + netconfig_error_wifi_load_inprogress(error); + else + netconfig_error_wifi_driver_failed(error); + + return FALSE; + } + + return TRUE; +} + +gboolean netconfig_iface_wifi_remove_driver(NetconfigWifi *wifi, GError **error) +{ + DBG("Wi-Fi power off requested"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + if (power_in_progress) { + netconfig_error_wifi_driver_failed(error); + return FALSE; + } + + if (__netconfig_wifi_try_to_remove_driver() != TRUE) { + netconfig_error_wifi_driver_failed(error); + + return FALSE; + } + + return TRUE; +} diff --git a/mobile/src/wifi-ssid-scan.c b/mobile/src/wifi-ssid-scan.c new file mode 100644 index 0000000..3f49101 --- /dev/null +++ b/mobile/src/wifi-ssid-scan.c @@ -0,0 +1,496 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "neterror.h" +#include "netdbus.h" +#include "netsupplicant.h" +#include "wifi-ssid-scan.h" +#include "wifi-background-scan.h" + +struct bss_info_t { + unsigned char ssid[32]; + enum netconfig_wifi_security security; + dbus_bool_t privacy; + dbus_bool_t wps; +}; + +static gboolean wifi_ssid_scan_state = FALSE; +static GSList *wifi_bss_info_list = NULL; +static guint netconfig_wifi_ssid_scan_timer = 0; + +static gboolean __netconfig_wifi_ssid_scan_timeout(gpointer data) +{ + netconfig_wifi_notify_ssid_scan_done(); + + return FALSE; +} + +static void __netconfig_wifi_ssid_scan_started(void) +{ + INFO("Wi-Fi SSID scan started"); + wifi_ssid_scan_state = TRUE; + + netconfig_start_timer_seconds( + 5, + __netconfig_wifi_ssid_scan_timeout, + NULL, + &netconfig_wifi_ssid_scan_timer); +} + +static void __netconfig_wifi_ssid_scan_finished(void) +{ + INFO("Wi-Fi SSID scan finished"); + wifi_ssid_scan_state = FALSE; + + netconfig_stop_timer(&netconfig_wifi_ssid_scan_timer); +} + +static gboolean __netconfig_wifi_invoke_ssid_scan( + const char *object_path, const char *ssid) +{ + /* TODO: Revise following code */ + +#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000) + + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusMessageIter iter, dict, entry; + DBusMessageIter value, array, array2; + DBusError error; + int MessageType = 0; + const char *key1 = "Type"; + const char *val1 = "active"; + const char *key2 = "SSIDs"; + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Error!!! Failed to get system DBus"); + goto error; + } + + message = dbus_message_new_method_call(SUPPLICANT_SERVICE, + object_path, SUPPLICANT_INTERFACE ".Interface", "Scan"); + if (message == NULL) { + ERR("Error!!! DBus method call fail"); + goto error; + } + + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + + dbus_message_iter_open_container(&dict, + DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key1); + + dbus_message_iter_open_container(&entry, + DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &val1); + + dbus_message_iter_close_container(&entry, &value); + dbus_message_iter_close_container(&dict, &entry); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key2); + + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING + DBUS_TYPE_ARRAY_AS_STRING + DBUS_TYPE_BYTE_AS_STRING, + &value); + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + DBUS_TYPE_ARRAY_AS_STRING + DBUS_TYPE_BYTE_AS_STRING, + &array); + dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &array2); + + dbus_message_iter_append_fixed_array(&array2, DBUS_TYPE_BYTE, &ssid, strlen(ssid)); + + dbus_message_iter_close_container(&array, &array2); + dbus_message_iter_close_container(&value, &array); + dbus_message_iter_close_container(&entry, &value); + dbus_message_iter_close_container(&dict, &entry); + dbus_message_iter_close_container(&iter, &dict); + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + NETCONFIG_DBUS_REPLY_TIMEOUT, &error); + + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + ERR("Error!!! dbus_connection_send_with_reply_and_block() failed. " + "DBus error [%s: %s]", error.name, error.message); + + dbus_error_free(&error); + return FALSE; + } else + ERR("Error!!! Failed to get properties"); + + goto error; + } + + MessageType = dbus_message_get_type(reply); + if (MessageType == DBUS_MESSAGE_TYPE_ERROR) { + const char *err_msg = dbus_message_get_error_name(reply); + ERR("Error!!! Error message received %s", err_msg); + goto error; + } + + dbus_message_unref(message); + dbus_message_unref(reply); + dbus_connection_unref(connection); + + return TRUE; + +error: + if (message != NULL) + dbus_message_unref(message); + + if (reply != NULL) + dbus_message_unref(reply); + + if (connection != NULL) + dbus_connection_unref(connection); + + return FALSE; +} + +static void __netconfig_wifi_notify_ssid_scan_done(void) +{ + DBusMessage *signal; + DBusConnection *connection = NULL; + DBusMessageIter dict, type, array, value; + DBusError error; + char *prop_ssid = "ssid"; + char *prop_security = "security"; + const char *sig_name = "SpecificScanCompleted"; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + /* TODO: If this occurs then UG should be informed abt SCAN fail. CHECK THIS. */ + ERR("Error!!! Failed to get system DBus, error [%s]", error.message); + dbus_error_free(&error); + + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + + return; + } + + signal = dbus_message_new_signal(NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, sig_name); + if (signal == NULL) { + /* TODO: If this occurs then UG should be informed abt SCAN fail. CHECK THIS. */ + dbus_connection_unref(connection); + + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + + return; + } + + dbus_message_iter_init_append(signal, &array); + dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, "{sv}", &dict); + GSList* list = wifi_bss_info_list; + while (list) { + struct bss_info_t *bss_info = (struct bss_info_t *)g_slist_nth_data(list, 0); + + if (bss_info) { + char *ssid = (char *)&(bss_info->ssid[0]); + dbus_int16_t security = bss_info->security; + DBG("Bss found. SSID: %s; Sec mode: %d;", ssid, security); + + /* Lets pack the SSID */ + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_ssid); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &ssid); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + + /* Lets pack the Security */ + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_security); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_INT16_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_INT16, &security); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + } + list = g_slist_next(list); + } + + dbus_message_iter_close_container(&array, &dict); + + dbus_error_init(&error); + dbus_connection_send(connection, signal, NULL); + + dbus_message_unref(signal); + dbus_connection_unref(connection); + + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + + INFO("(%s)", sig_name); +} + +static void __netconfig_wifi_check_security(const char *str_keymgmt, struct bss_info_t *bss_data) +{ + INFO("keymgmt : %s", str_keymgmt); + + if (strcmp(str_keymgmt, "ieee8021x") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wpa-psk") == 0) { + bss_data->security = WIFI_SECURITY_PSK; + } else if (strcmp(str_keymgmt, "wpa-psk-sha256") == 0) { + bss_data->security = WIFI_SECURITY_PSK; + } else if (strcmp(str_keymgmt, "wpa-ft-psk") == 0) { + bss_data->security = WIFI_SECURITY_PSK; + } else if (strcmp(str_keymgmt, "wpa-ft-eap") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wpa-eap") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wpa-eap-sha256") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wps") == 0) { + bss_data->wps = TRUE; + } +} + +static void __netconfig_wifi_parse_keymgmt_message(DBusMessageIter *iter, struct bss_info_t *bss_data) +{ + DBusMessageIter dict, entry, array, value; + const char *key; + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(iter, &dict); + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&dict, &entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) + return; + + dbus_message_iter_get_basic(&entry, &key); + if (g_strcmp0(key, "KeyMgmt") == 0) { + dbus_message_iter_next(&entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) + return; + + dbus_message_iter_recurse(&entry, &array); + if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(&array, &value); + while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { + const char *str = NULL; + + dbus_message_iter_get_basic(&value, &str); + if (str == NULL) + return; + + __netconfig_wifi_check_security(str, bss_data); + dbus_message_iter_next(&value); + } + } + + dbus_message_iter_next(&dict); + } +} + +gboolean netconfig_wifi_get_ssid_scan_state(void) +{ + return wifi_ssid_scan_state; +} + +void netconfig_wifi_notify_ssid_scan_done(void) +{ + if (netconfig_wifi_get_ssid_scan_state() != TRUE) + return; + + __netconfig_wifi_ssid_scan_finished(); + + __netconfig_wifi_notify_ssid_scan_done(); + + netconfig_wifi_bgscan_start(); +} + +void netconfig_wifi_bss_added(DBusMessage *message) +{ + DBusMessageIter iter, dict, entry; + DBusMessageIter value, array; + const char *key; + struct bss_info_t *bss_info; + + if (netconfig_wifi_get_ssid_scan_state() != TRUE) + return; + + INFO("NEW BSS added"); + + if (!dbus_message_iter_init(message, &iter)) { + DBG("Message does not have parameters"); + return; + } + + dbus_message_iter_next(&iter); + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) { + DBG("Invalid message type"); + return; + } + + bss_info = g_try_new0(struct bss_info_t, 1); + if (bss_info == NULL) { + DBG("Out of memory"); + return; + } + + dbus_message_iter_recurse(&iter, &dict); + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&dict, &entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) + goto error; + + dbus_message_iter_get_basic(&entry, &key); + if (key == NULL) + goto error; + + dbus_message_iter_next(&entry); + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) + goto error; + + dbus_message_iter_recurse(&entry, &value); + + if (g_strcmp0(key, "SSID") == 0) { + unsigned char *ssid; + int ssid_len; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len); + + if (ssid_len > 0 && ssid_len < 33) + memcpy(bss_info->ssid, ssid, ssid_len); + else + memset(bss_info->ssid, 0, sizeof(bss_info->ssid)); + } else if (g_strcmp0(key, "Privacy") == 0) { + dbus_bool_t privacy = FALSE; + + dbus_message_iter_get_basic(&value, &privacy); + bss_info->privacy = privacy; + } else if ((g_strcmp0(key, "RSN") == 0) || (g_strcmp0(key, "WPA") == 0)) { + + __netconfig_wifi_parse_keymgmt_message(&value, bss_info); + } else if (g_strcmp0(key, "IEs") == 0) { + unsigned char *ie; + int ie_len; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, &ie, &ie_len); + } + + dbus_message_iter_next(&dict); + } + + if (bss_info->ssid[0] == 0) + goto error; + + if (bss_info->security == WIFI_SECURITY_UNKNOWN) { + if (bss_info->privacy == TRUE) + bss_info->security = WIFI_SECURITY_WEP; + else + bss_info->security = WIFI_SECURITY_NONE; + } + + wifi_bss_info_list = g_slist_append(wifi_bss_info_list, bss_info); + return; + +error: + g_free(bss_info); +} + +gboolean netconfig_wifi_ssid_scan(const char *ssid) +{ + char object_path[DBUS_PATH_MAX_BUFLEN] = { 0, }; + char *path_ptr = &object_path[0]; + static char *scan_ssid = NULL; + + netconfig_wifi_bgscan_stop(); + + if (ssid != NULL) { + g_free(scan_ssid); + scan_ssid = g_strdup(ssid); + } + + if (scan_ssid == NULL) { + netconfig_wifi_bgscan_start(); + return FALSE; + } + + if (netconfig_wifi_get_scanning() == TRUE) { + DBG("Wi-Fi scan is in progress! SSID %s scan will be delayed", + scan_ssid); + return FALSE; + } + + INFO("Start SSID Scan with %s", scan_ssid); + + if (wifi_bss_info_list) { + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + } + + if (netconfig_wifi_get_supplicant_interface(&path_ptr) != TRUE) { + DBG("Fail to get wpa_supplicant DBus path"); + return FALSE; + } + + if (__netconfig_wifi_invoke_ssid_scan( + (const char *)object_path, (const char *)scan_ssid) == TRUE) { + __netconfig_wifi_ssid_scan_started(); + + g_free(scan_ssid); + scan_ssid = NULL; + + return TRUE; + } + + return FALSE; +} + +gboolean netconfig_iface_wifi_request_specific_scan(NetconfigWifi *wifi, + gchar *ssid, GError **error) +{ + g_return_val_if_fail(wifi != NULL, FALSE); + g_return_val_if_fail(ssid != NULL, FALSE); + + netconfig_wifi_ssid_scan((const char *)ssid); + + return TRUE; +} diff --git a/mobile/src/wifi-state.c b/mobile/src/wifi-state.c new file mode 100644 index 0000000..9028b5b --- /dev/null +++ b/mobile/src/wifi-state.c @@ -0,0 +1,455 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "network-state.h" +#include "network-statistics.h" +#include "wifi-state.h" +#include "wifi-indicator.h" +#include "wifi-background-scan.h" + +static int profiles_count = 0; + +static enum netconfig_wifi_service_state + wifi_service_state = NETCONFIG_WIFI_UNKNOWN; + +static GSList *notifier_list = NULL; + + +static void __netconfig_wifi_set_profiles_count(const int count) +{ + profiles_count = count; +} + +static int __netconfig_wifi_get_profiles_count(void) +{ + return profiles_count; +} + +static void __netconfig_wifi_set_essid(void) +{ + const char *essid_name = NULL; + const char *wifi_profile = netconfig_get_default_profile(); + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + return; + + if (wifi_profile == NULL || + netconfig_is_wifi_profile(wifi_profile) != TRUE) { + ERR("Can't get Wi-Fi profile"); + return; + } + + essid_name = netconfig_wifi_get_connected_essid(wifi_profile); + if (essid_name == NULL) { + ERR("Can't get Wi-Fi name"); + return; + } + + vconf_set_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name); +} + +static void __netconfig_wifi_unset_essid(void) +{ + vconf_set_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, ""); +} + +static GSList *__netconfig_wifi_state_get_service_profiles(DBusMessage *message) +{ + GSList *service_profiles = NULL; + DBusMessageIter iter, dict; + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry; + const char *object_path = NULL; + + dbus_message_iter_recurse(&dict, &entry); + dbus_message_iter_get_basic(&entry, &object_path); + + if (object_path == NULL) { + dbus_message_iter_next(&dict); + continue; + } + + if (netconfig_is_wifi_profile(object_path) == TRUE) + service_profiles = g_slist_append(service_profiles, + g_strdup(object_path)); + + dbus_message_iter_next(&dict); + } + + return service_profiles; +} + +static char *__netconfig_wifi_get_connman_favorite_service(void) +{ + char *favorite_service = NULL; + DBusMessage *message = NULL; + GSList *service_profiles = NULL; + GSList *list = NULL; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetServices", NULL); + if (message == NULL) { + ERR("Failed to get service list"); + return NULL; + } + + /* Get service profiles from ConnMan Manager */ + service_profiles = __netconfig_wifi_state_get_service_profiles(message); + dbus_message_unref(message); + + for (list = service_profiles; list != NULL; list = list->next) { + char *profile_path = list->data; + DBusMessageIter iter, array; + + if (favorite_service != NULL) + break; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + profile_path, CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL); + + if (message == NULL) { + ERR("Failed to get service information of %s", profile_path); + continue; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, variant; + const char *key = NULL; + dbus_bool_t value; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + + if (g_str_equal(key, "Favorite") != TRUE) { + dbus_message_iter_next(&array); + continue; + } + + dbus_message_iter_get_basic(&variant, &value); + + if (value) + favorite_service = g_strdup(profile_path); + + break; + } + + dbus_message_unref(message); + } + + g_slist_free(service_profiles); + + return favorite_service; +} + +static void __netconfig_wifi_state_changed( + enum netconfig_wifi_service_state state) +{ + GSList *list; + + for (list = notifier_list; list; list = list->next) { + struct netconfig_wifi_state_notifier *notifier = list->data; + + if (notifier->netconfig_wifi_state_changed != NULL) + notifier->netconfig_wifi_state_changed(state, notifier->user_data); + } +} + +void netconfig_wifi_state_set_service_state( + enum netconfig_wifi_service_state new_state) +{ + enum netconfig_wifi_service_state old_state = wifi_service_state; + + if (old_state == new_state) + return; + + wifi_service_state = new_state; + DBG("Wi-Fi state %d ==> %d", old_state, new_state); + + if (new_state == NETCONFIG_WIFI_CONNECTED) { + netconfig_del_wifi_found_notification(); + + vconf_set_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED); + vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_CONNECTED); + + __netconfig_wifi_set_essid(); + + netconfig_wifi_indicator_start(); + } else if (old_state == NETCONFIG_WIFI_CONNECTED) { + vconf_set_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED); + vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); + + __netconfig_wifi_unset_essid(); + + netconfig_wifi_indicator_stop(); + } + + __netconfig_wifi_state_changed(new_state); +} + +enum netconfig_wifi_service_state +netconfig_wifi_state_get_service_state(void) +{ + return wifi_service_state; +} + +enum netconfig_wifi_tech_state netconfig_wifi_get_technology_state(void) +{ + DBusMessage *message = NULL; + DBusMessageIter iter, array; + enum netconfig_wifi_tech_state ret = NETCONFIG_WIFI_TECH_OFF; + gboolean wifi_tech_powered = FALSE; + gboolean wifi_tech_connected = FALSE; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetTechnologies", NULL); + if (message == NULL) { + ERR("Failed to get Wi-Fi technology state"); + return NETCONFIG_WIFI_TECH_UNKNOWN; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry, dict; + const char *path; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &path); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &dict); + + if (path == NULL || + g_str_equal(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == FALSE) { + dbus_message_iter_next(&array); + continue; + } + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry1, value1; + const char *key, *sdata; + dbus_bool_t data; + + dbus_message_iter_recurse(&dict, &entry1); + dbus_message_iter_get_basic(&entry1, &key); + + dbus_message_iter_next(&entry1); + dbus_message_iter_recurse(&entry1, &value1); + + if (dbus_message_iter_get_arg_type(&value1) == + DBUS_TYPE_BOOLEAN) { + dbus_message_iter_get_basic(&value1, &data); + DBG("key-[%s] - %s", key, data ? "True" : "False"); + + if (strcmp(key, "Powered") == 0 && data) { + wifi_tech_powered = TRUE; + } else if (strcmp(key, "Connected") == 0 && data) { + wifi_tech_connected = TRUE; + } else if (strcmp(key, "Tethering") == 0 && data) { + /* For further use */ + } + } else if (dbus_message_iter_get_arg_type(&value1) == + DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&value1, &sdata); + DBG("%s", sdata); + } + dbus_message_iter_next(&dict); + } + + dbus_message_iter_next(&array); + } + + dbus_message_unref(message); + + if (wifi_tech_powered) + ret = NETCONFIG_WIFI_TECH_POWERED; + + if (wifi_tech_connected) + ret = NETCONFIG_WIFI_TECH_CONNECTED; + + return ret; +} + +void netconfig_wifi_update_power_state(gboolean powered) +{ + int wifi_state = 0; + + /* It's automatically updated by signal-handler + * DO NOT update manually + * It includes Wi-Fi state configuration + */ + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + + if (powered == TRUE) { + if (wifi_state == VCONFKEY_WIFI_OFF && + netconfig_is_wifi_direct_on() != TRUE && + netconfig_is_wifi_tethering_on() != TRUE) { + DBG("Wi-Fi successfully turned on or waken up from power-save mode"); + + vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); + vconf_set_int(VCONF_WIFI_LAST_POWER_STATE, WIFI_POWER_ON); + vconf_set_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED); + + netconfig_wifi_notify_power_completed(TRUE); + + netconfig_wifi_device_picker_service_start(); + + netconfig_wifi_bgscan_start(); + } + } else { + if (wifi_state != VCONFKEY_WIFI_OFF) { + DBG("Wi-Fi successfully turned off or in power-save mode"); + + netconfig_wifi_device_picker_service_stop(); + + netconfig_wifi_remove_driver(); + + vconf_set_int(VCONFKEY_NETWORK_WIFI_STATE, VCONFKEY_NETWORK_WIFI_OFF); + vconf_set_int(VCONF_WIFI_LAST_POWER_STATE, WIFI_POWER_OFF); + vconf_set_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF); + + netconfig_wifi_notify_power_completed(FALSE); + + netconfig_del_wifi_found_notification(); + + netconfig_wifi_bgscan_stop(); + + __netconfig_wifi_set_profiles_count(0); + } + } +} + +char *netconfig_wifi_get_favorite_service(void) +{ + return __netconfig_wifi_get_connman_favorite_service(); +} + +void netconfig_wifi_check_network_notification(DBusMessage *message) +{ + DBusMessageIter iter; + int profiles_count = 0; + int qs_enable, ug_state; + + if (netconfig_wifi_state_get_service_state() == NETCONFIG_WIFI_CONNECTED) { + DBG("Service state is connected"); + return; + } + + if (vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable) == -1) { + DBG("Fail to get %s", VCONFKEY_WIFI_ENABLE_QS); + return; + } + + if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) { + DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE"); + return; + } + + if (vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state) == -1) { + DBG("Fail to get %s", VCONFKEY_WIFI_UG_RUN_STATE); + return; + } + + if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) { + DBG("ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND"); + return; + } + + if (message == NULL) { + ERR("Failed to get service list"); + return; + } + + dbus_message_iter_init(message, &iter); + DBusMessageIter array, value; + dbus_message_iter_recurse(&iter, &array); + if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_STRUCT) { + DBG("Array not found. type %d", dbus_message_iter_get_arg_type(&array)); + return; + } + + dbus_message_iter_recurse(&array, &value); + while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_OBJECT_PATH) { + const char *object_path = NULL; + + dbus_message_iter_get_basic(&value, &object_path); + + DBG("found a profile: %s", object_path); + if (netconfig_is_wifi_profile(object_path) == TRUE) { + profiles_count++; + DBG("Total wifi profile cnt = %d", profiles_count); + } + + dbus_message_iter_next(&array); + if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_STRUCT) { + DBG("Not a structure entry. Arg type = %d", dbus_message_iter_get_arg_type(&array)); + break; + } + dbus_message_iter_recurse(&array, &value); + } + + if (__netconfig_wifi_get_profiles_count() != profiles_count) { + DBG("profiles prev_count (%d) - profiles count (%d)", + __netconfig_wifi_get_profiles_count(), profiles_count); + + netconfig_add_wifi_found_notification(); + __netconfig_wifi_set_profiles_count(profiles_count); + } else + DBG("No change in profile count[%d]", profiles_count); +} + +void netconfig_wifi_state_notifier_cleanup(void) +{ + g_slist_free_full(notifier_list, NULL); +} + +void netconfig_wifi_state_notifier_register( + struct netconfig_wifi_state_notifier *notifier) +{ + DBG("register notifier"); + + notifier_list = g_slist_append(notifier_list, notifier); +} + +void netconfig_wifi_state_notifier_unregister( + struct netconfig_wifi_state_notifier *notifier) +{ + DBG("un-register notifier"); + + notifier_list = g_slist_remove_all(notifier_list, notifier); +} diff --git a/mobile/src/wifi.c b/mobile/src/wifi.c new file mode 100644 index 0000000..e5e4ddb --- /dev/null +++ b/mobile/src/wifi.c @@ -0,0 +1,173 @@ +/* + * Network Configuration Module + * + * 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 "log.h" +#include "wifi.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "netconfig.h" +#include "wifi-power.h" +#include "wifi-state.h" +#include "wifi-ssid-scan.h" +#include "wifi-eap.h" +#include "wifi-eap-config.h" +#include "wifi-background-scan.h" +#include "wifi-agent.h" + +#include "netconfig-iface-wifi-glue.h" + + +#define PROP_DEFAULT FALSE +#define PROP_DEFAULT_STR NULL + +enum { + PROP_O, + PROP_WIFI_CONN, + PROP_WIFI_PATH, +}; + +enum { + SIG_WIFI_DRIVER, + SIG_LAST +}; + +struct NetconfigWifiClass { + GObjectClass parent; + + /* method and signals */ + void (*driver_loaded) (NetconfigWifi *wifi, gchar *mac); +}; + +struct NetconfigWifi { + GObject parent; + + /* member variable */ + DBusGConnection *conn; + gchar *path; +}; + +static guint32 signals[SIG_LAST] = { 0, }; + +G_DEFINE_TYPE(NetconfigWifi, netconfig_wifi, G_TYPE_OBJECT); + + +static void __netconfig_wifi_gobject_get_property(GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + return; +} + +static void __netconfig_wifi_gobject_set_property(GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NetconfigWifi *wifi = NETCONFIG_WIFI(object); + + switch (prop_id) { + case PROP_WIFI_CONN: + { + wifi->conn = g_value_get_boxed(value); + INFO("wifi(%p) set conn(%p)", wifi, wifi->conn); + break; + } + + case PROP_WIFI_PATH: + { + if (wifi->path) + g_free(wifi->path); + + wifi->path = g_value_dup_string(value); + INFO("wifi(%p) path(%s)", wifi, wifi->path); + + break; + } + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void netconfig_wifi_init(NetconfigWifi *wifi) +{ + DBG("wifi initialize"); + + wifi->conn = NULL; + wifi->path = g_strdup(PROP_DEFAULT_STR); +} + +static void netconfig_wifi_class_init(NetconfigWifiClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + DBG("class initialize"); + + object_class->get_property = __netconfig_wifi_gobject_get_property; + object_class->set_property = __netconfig_wifi_gobject_set_property; + + /* DBus register */ + dbus_g_object_type_install_info(NETCONFIG_TYPE_WIFI, + &dbus_glib_netconfig_iface_wifi_object_info); + + /* property */ + g_object_class_install_property(object_class, PROP_WIFI_CONN, + g_param_spec_boxed("conn", "CONNECTION", "DBus connection", + DBUS_TYPE_G_CONNECTION, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property(object_class, PROP_WIFI_PATH, + g_param_spec_string("path", "PATH", "Object Path", + PROP_DEFAULT_STR, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + /* signal */ + signals[SIG_WIFI_DRIVER] = g_signal_new("driver-loaded", + G_OBJECT_CLASS_TYPE(klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(NetconfigWifiClass, + driver_loaded), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); +} + +gpointer netconfig_wifi_create_and_init(DBusGConnection *conn) +{ + GObject *object; + + g_return_val_if_fail(conn != NULL, NULL); + + object = g_object_new(NETCONFIG_TYPE_WIFI, "conn", conn, "path", + NETCONFIG_WIFI_PATH, NULL); + + INFO("create wifi(%p)", object); + + dbus_g_connection_register_g_object(conn, NETCONFIG_WIFI_PATH, object); + + INFO("wifi(%p) register DBus path(%s)", object, NETCONFIG_WIFI_PATH); + + netconfig_wifi_power_configuration(); + netconfig_wifi_init_bgscan(); + + return object; +} diff --git a/packaging/net-config.spec b/packaging/net-config.spec new file mode 100644 index 0000000..41daedc --- /dev/null +++ b/packaging/net-config.spec @@ -0,0 +1,253 @@ +Name: net-config +Summary: TIZEN Network Configuration Module +Version: 0.1.90_27 +Release: 1 +Group: System/Network +License: Apache License Version 2.0 +Source0: %{name}-%{version}.tar.gz + +%if %{_repository} == "wearable" +BuildRequires: cmake +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(appsvc) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(notification) +BuildRequires: pkgconfig(alarm-service) +BuildRequires: pkgconfig(syspopup-caller) +BuildRequires: pkgconfig(capi-appfw-application) +Requires: sed +Requires: systemd +Requires: vconf +Requires(post): systemd +Requires(post): vconf +Requires(preun): systemd +Requires(postun): systemd +%else +BuildRequires: cmake +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(dbus-glib-1) +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(wifi-direct) +BuildRequires: pkgconfig(tapi) +BuildRequires: pkgconfig(syspopup-caller) +Requires(post): /usr/bin/vconftool +BuildRequires: pkgconfig(libsystemd-daemon) +%{?systemd_requires} +%endif + +%description +TIZEN Network Configuration Module + +%prep +%setup -q + +%build +%if %{_repository} == "wearable" +cd wearable +%cmake -DCMAKE_INSTALL_PREFIX=%{_prefix} \ +%if 0%{?sec_product_feature_wlan_concurrent_mode} == 1 + -DWLAN_CONCURRENT_MODE=1 \ +%endif + +make %{?_smp_mflags} +%else +cd mobile +cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} + +make %{?_smp_mflags} +%endif + +%install +%if %{_repository} == "wearable" +cd wearable +%make_install + +#Systemd service file +mkdir -p %{buildroot}%{_libdir}/systemd/system/ +cp resources/usr/lib/systemd/system/net-config.service %{buildroot}%{_libdir}/systemd/system/net-config.service +mkdir -p %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/ +ln -s ../net-config.service %{buildroot}%{_libdir}/systemd/system/multi-user.target.wants/net-config.service + +mkdir -p %{buildroot}%{_datadir}/dbus-1/services/ +cp resources/usr/share/dbus-1/services/net.netconfig.service %{buildroot}%{_datadir}/dbus-1/services/net.netconfig.service + +mkdir -p %{buildroot}%{_sysconfdir}/ +cp resources/etc/resolv.conf %{buildroot}%{_sysconfdir}/resolv.conf + +mkdir -p %{buildroot}%{_sysconfdir}/wifi/ +cp resources/etc/wifi/ccode.conf %{buildroot}%{_sysconfdir}/wifi/ccode.conf + +mkdir -p %{buildroot}%{_sbindir}/ +cp resources/usr/sbin/net-config.service %{buildroot}%{_sbindir}/net-config.service + +mkdir -p %{buildroot}/opt/dbspace +sqlite3 %{buildroot}/opt/dbspace/.wifi_offload.db < resources/usr/share/wifi_offloading.sql + +#DBus DAC (net-config.manifest enables DBus SMACK) +#mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d +#cp resources/etc/dbus-1/system.d/net-config.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/net-config.conf + +#log dump +mkdir -p %{buildroot}/opt/etc/dump.d/module.d +cp resources/opt/etc/dump.d/module.d/network_log_dump.sh %{buildroot}/opt/etc/dump.d/module.d/network_log_dump.sh + +#License +mkdir -p %{buildroot}%{_datadir}/license +cp LICENSE %{buildroot}%{_datadir}/license/net-config +cat LICENSE-FLORA >> %{buildroot}%{_datadir}/license/net-config +%else +cd mobile +%make_install + +mkdir -p %{buildroot}%{_datadir}/dbus-1/services +cp resources/usr/share/dbus-1/services/net.netconfig.service %{buildroot}%{_datadir}/dbus-1/services/net.netconfig.service +mkdir -p %{buildroot}%{_sysconfdir}/dbus-1/system.d +cp resources/etc/dbus-1/system.d/net-config.conf %{buildroot}%{_sysconfdir}/dbus-1/system.d/net-config.conf +mkdir -p %{buildroot}/opt/etc +cp resources/opt/etc/resolv.conf %{buildroot}/opt/etc/resolv.conf + +# Systemd service file +mkdir -p %{buildroot}%{_libdir}/systemd/system/ +cp resources/usr/lib/systemd/system/net-config.service %{buildroot}%{_libdir}/systemd/system/net-config.service +mkdir -p %{buildroot}%{_libdir}/systemd/system/network.target.wants/ +ln -s ../net-config.service %{buildroot}%{_libdir}/systemd/system/network.target.wants/net-config.service + +#License +mkdir -p %{buildroot}%{_datadir}/license +cp LICENSE.APLv2 %{buildroot}%{_datadir}/license/net-config + +#Rule file +mkdir -p %{buildroot}/opt/etc/smack/accesses.d +cp net-config.rule %{buildroot}/opt/etc/smack/accesses.d +%endif + +%post +%if %{_repository} == "wearable" +vconftool set -t int memory/dnet/state 0 -i -s system::vconf_network +vconftool set -t int memory/wifi/state 0 -i -s system::vconf_network +vconftool set -t int memory/wifi/transfer_state 0 -i -s system::vconf_network +vconftool set -t int memory/wifi/strength 0 -i -s system::vconf_network + +vconftool set -t int memory/dnet/cellular 0 -i -s system::vconf_network +vconftool set -t int memory/dnet/wifi 0 -i -s system::vconf_network +vconftool set -t int memory/dnet/network_config 0 -i -s system::vconf_network +vconftool set -t int memory/dnet/status 0 -i -s system::vconf_network +vconftool set -t string memory/dnet/ip "" -i -s system::vconf_network +vconftool set -t string memory/dnet/proxy "" -i -s system::vconf_network + +vconftool set -t string memory/wifi/connected_ap_name "" -i -s system::vconf_network + +vconftool set -t string db/wifi/bssid_address "" -s system::vconf_network + +#Default Call Statistics +vconftool set -t int db/dnet/statistics/cellular/totalsnt 0 -s system::vconf_network +vconftool set -t int db/dnet/statistics/cellular/totalrcv 0 -s system::vconf_network +vconftool set -t int db/dnet/statistics/cellular/lastsnt 0 -s system::vconf_network +vconftool set -t int db/dnet/statistics/cellular/lastrcv 0 -s system::vconf_network +vconftool set -t int db/dnet/statistics/wifi/totalsnt 0 -s system::vconf_network +vconftool set -t int db/dnet/statistics/wifi/totalrcv 0 -s system::vconf_network +vconftool set -t int db/dnet/statistics/wifi/lastsnt 0 -s system::vconf_network +vconftool set -t int db/dnet/statistics/wifi/lastrcv 0 -s system::vconf_network + +#Wi-Fi last power state +vconftool set -t int file/private/wifi/last_power_state 0 -s system::vconf_network + +#Wi-Fi power state due to airplane mode +vconftool set -t int file/private/wifi/wifi_off_by_airplane 0 -s system::vconf_network + +#Wi-Fi power state due to restricted mode +vconftool set -t int file/private/wifi/wifi_off_by_restricted 0 -s system::vconf_network + +#Wi-Fi power state due to emergency mode +vconftool set -t int file/private/wifi/wifi_off_by_emergency 0 -s system::vconf_network + +#Wi-Fi sleep policy +vconftool set -t int file/private/wifi/sleep_policy 0 -g 6519 -s system::vconf_setting + +#systemctl daemon-reload +#systemctl restart net-config.service + +%else +vconftool set -t int memory/dnet/state 0 -i +vconftool set -t int memory/wifi/state 0 -i +vconftool set -t int memory/wifi/transfer_state 0 -i +vconftool set -t int memory/wifi/strength 0 -i +vconftool set -t int memory/wifi/bgscan_mode 0 -i + +vconftool set -t int memory/dnet/wifi 0 -i +vconftool set -t int memory/dnet/network_config 0 -i +vconftool set -t int memory/dnet/status 0 -i +vconftool set -t string memory/dnet/ip "" -i +vconftool set -t string memory/dnet/proxy "" -i + +vconftool set -t string memory/wifi/connected_ap_name "" -i + +vconftool set -t string db/wifi/bssid_address "" + +#Default Call Statistics +vconftool set -t int db/dnet/statistics/cellular/totalsnt "0" +vconftool set -t int db/dnet/statistics/cellular/totalrcv "0" +vconftool set -t int db/dnet/statistics/cellular/lastsnt "0" +vconftool set -t int db/dnet/statistics/cellular/lastrcv "0" +vconftool set -t int db/dnet/statistics/wifi/totalsnt "0" +vconftool set -t int db/dnet/statistics/wifi/totalrcv "0" +vconftool set -t int db/dnet/statistics/wifi/lastsnt "0" +vconftool set -t int db/dnet/statistics/wifi/lastrcv "0" + +vconftool set -t int file/private/wifi/last_power_state "0" + +systemctl daemon-reload +if [ "$1" == "1" ]; then + systemctl restart net-config.service +fi +%endif + +%if %{_repository} == "wearable" +%preun +#systemctl stop net-config.service + +%postun +#systemctl daemon-reload +%else +%preun +if [ "$1" == "0" ]; then + systemctl stop net-config.service +fi + +%postun +systemctl daemon-reload +if [ "$1" == "1" ]; then + systemctl restart net-config.service +fi +%endif + +%files +%if %{_repository} == "wearable" +%manifest wearable/net-config.manifest +%attr(500,root,root) %{_sbindir}/* +%attr(644,root,root) %{_sysconfdir}/resolv.conf +%attr(400,root,root) %{_sysconfdir}/wifi/ccode.conf +%attr(644,root,root) %{_datadir}/dbus-1/services/* +#DBus DAC +#%attr(644,root,root) %{_sysconfdir}/dbus-1/system.d/* +%attr(644,root,root) %{_libdir}/systemd/system/net-config.service +%attr(644,root,root) %{_libdir}/systemd/system/multi-user.target.wants/net-config.service +%{_datadir}/license/net-config +%attr(660,root,root) /opt/dbspace/.wifi_offload.db +%attr(664,root,root) /opt/dbspace/.wifi_offload.db-journal +%attr(544,root,root) /opt/etc/dump.d/module.d/network_log_dump.sh +%else +%manifest mobile/net-config.manifest +/opt/etc/smack/accesses.d/net-config.rule +%{_sbindir}/* +%attr(644,root,root) /opt/etc/resolv.conf +%{_datadir}/dbus-1/services/* +%{_sysconfdir}/dbus-1/system.d/* +%{_libdir}/systemd/system/net-config.service +%{_libdir}/systemd/system/network.target.wants/net-config.service +%{_datadir}/license/net-config +%endif diff --git a/wearable/AUTHORS b/wearable/AUTHORS new file mode 100644 index 0000000..df0456d --- /dev/null +++ b/wearable/AUTHORS @@ -0,0 +1,5 @@ +Danny Jeongseok Seo +Jeik Jaehyun Kim +Sunkey Lee +Sanghoon Cho +DongHoo Park \ No newline at end of file diff --git a/wearable/CMakeLists.txt b/wearable/CMakeLists.txt new file mode 100644 index 0000000..8d0fa3a --- /dev/null +++ b/wearable/CMakeLists.txt @@ -0,0 +1,106 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.6) +PROJECT(net-config C) +SET(PACKAGE ${PROJECT_NAME}) +SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(BINDIR "${PREFIX}/sbin") +SET(DATADIR "${PREFIX}/share") +SET(LIBDIR "${PREFIX}/lib") + +SET(SRCS + src/main.c + src/wifi.c + src/neterror.c + src/wifi-eap.c + src/wifi-agent.c + src/wifi-ccode.c + src/wifi-power.c + src/wifi-state.c + src/wifi-wps.c + src/wifi-passpoint.c + src/cellular-state.c + src/utils/log.c + src/utils/util.c + src/dbus/netdbus.c + src/network-clock.c + src/network-state.c + src/wifi-firmware.c + src/wifi-indicator.c + src/signal-handler.c + src/wifi-ssid-scan.c + src/utils/emulator.c + src/wifi-eap-config.c + src/network-statistics.c + src/dbus/netsupplicant.c + src/wifi-background-scan.c + src/utils/network-accessibility.c + ) + +IF("${CMAKE_BUILD_TYPE}" STREQUAL "") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +MESSAGE("Build type: ${CMAKE_BUILD_TYPE}") + +INCLUDE(FindPkgConfig) +PKG_CHECK_MODULES(pkgs REQUIRED + dlog + tapi + vconf + gio-2.0 + glib-2.0 + dbus-glib-1 + notification + alarm-service + syspopup-caller + capi-appfw-application + ) + +FOREACH(flag ${pkgs_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + +SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -Werror -fvisibility=hidden") +SET(EXTRA_CXXFLAGS "${EXTRA_CXXFLAGS} -Wall -Werror -fvisibility=hidden -fvisibility-inlines-hidden") +SET(CMAKE_C_FLAGS "-I${CMAKE_SOURCE_DIR}/include ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") +SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") +SET(CMAKE_C_FLAGS_RELEASE "-O2") + +FIND_PROGRAM(UNAME NAMES uname) +EXEC_PROGRAM("${UNAME}" ARGS "-m" +OUTPUT_VARIABLE "ARCH") +IF("${ARCH}" STREQUAL "arm") + ADD_DEFINITIONS("-DTARGET_ARM") + MESSAGE("add -DTARGET_ARM") +ENDIF("${ARCH}" STREQUAL "arm") + +ADD_DEFINITIONS("-DPACKAGE=\"${PACKAGE}\"") +ADD_DEFINITIONS("-DPREFIX=\"${PREFIX}\"") + +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed") + +ADD_EXECUTABLE(${PROJECT_NAME} ${SRCS}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${pkgs_LDFLAGS}) + +ADD_CUSTOM_TARGET(netconfig-iface-network-state-glue.h + COMMAND dbus-binding-tool --mode=glib-server --prefix=netconfig_iface_network_state + --output=${CMAKE_SOURCE_DIR}/include/netconfig-iface-network-state-glue.h + ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-state.xml + DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-state.xml +) +ADD_CUSTOM_TARGET(netconfig-iface-network-statistics-glue.h + COMMAND dbus-binding-tool --mode=glib-server --prefix=netconfig_iface_network_statistics + --output=${CMAKE_SOURCE_DIR}/include/netconfig-iface-network-statistics-glue.h + ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-statistics.xml + DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-network-statistics.xml +) +ADD_CUSTOM_TARGET(netconfig-iface-wifi-glue.h + COMMAND dbus-binding-tool --mode=glib-server --prefix=netconfig_iface_wifi + --output=${CMAKE_SOURCE_DIR}/include/netconfig-iface-wifi-glue.h + ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-wifi.xml + DEPENDS ${CMAKE_SOURCE_DIR}/interfaces/netconfig-iface-wifi.xml +) + +ADD_DEPENDENCIES(${PROJECT_NAME} netconfig-iface-network-state-glue.h) +ADD_DEPENDENCIES(${PROJECT_NAME} netconfig-iface-network-statistics-glue.h) +ADD_DEPENDENCIES(${PROJECT_NAME} netconfig-iface-wifi-glue.h) + +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${BINDIR}) diff --git a/wearable/LICENSE b/wearable/LICENSE new file mode 100644 index 0000000..181359e --- /dev/null +++ b/wearable/LICENSE @@ -0,0 +1,203 @@ +Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/wearable/LICENSE-FLORA b/wearable/LICENSE-FLORA new file mode 100755 index 0000000..7ccb5b5 --- /dev/null +++ b/wearable/LICENSE-FLORA @@ -0,0 +1,75 @@ +Flora License + +Version 1.0, May, 2012 + +http://www.tizenopensource.org/license + +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. + +"Tizen Certified Platform" shall mean a software platform that complies with the standards set forth in the Compatibility Definition Document and passes the Compatibility Test Suite as defined from time to time by the Tizen Technical Steering Group and certified by the Tizen Association or its designated agent. + +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 solely as incorporated into a Tizen Certified Platform, 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 solely as incorporated into a Tizen Certified Platform 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 pursuant to the copyright license above, in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and + + 2. You must cause any modified files to carry prominent notices stating that You changed the files; and + + 3. 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 + + 4. 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 Flora License to your work + +To apply the Flora 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 Flora License, Version 1.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.tizenopensource.org/license + + 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/wearable/debian/changelog b/wearable/debian/changelog new file mode 100644 index 0000000..8274eb9 --- /dev/null +++ b/wearable/debian/changelog @@ -0,0 +1,1970 @@ +net-config (0.1.197) unstable; urgency=low + + * release mdm service only in cases of succeed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.197 + + -- Misun Kim Mon, 20 Jan 2014 17:19:28 +0900 + +net-config (0.1.196) unstable; urgency=low + + * wifi-power: add emergency mode scenario + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.196 + + -- Danny Jeongseok Seo Mon, 23 Dec 2013 22:08:41 +0900 + +net-config (0.1.195) unstable; urgency=low + + * wifi-agent: handle connect error + * wifi-background-scan: unnecessary duplicated bgscan_stop_timer + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.195 + + -- Danny Jeongseok Seo Fri, 13 Dec 2013 21:06:37 +0900 + +net-config (0.1.194) unstable; urgency=low + + * avoid continuous recovery to wifi + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.194 + + -- Misun Kim Fri, 13 Dec 2013 18:13:58 +0900 + +net-config (0.1.193) unstable; urgency=low + + * avoid redundant sacn request + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.193 + + -- Misun Kim Fri, 13 Dec 2013 14:09:39 +0900 + +net-config (0.1.192) unstable; urgency=low + + * define DBUS_OBJECT_PATH_MAX + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.192 + + -- Danny Jeongseok Seo Thu, 12 Dec 2013 00:30:23 +0900 + +net-config (0.1.191) unstable; urgency=low + + * Fix invalid memory access + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.191 + + -- Danny Jeongseok Seo Wed, 11 Dec 2013 00:44:57 +0900 + +net-config (0.1.190) unstable; urgency=low + + * Revise checking internet accessibility logic for portal + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.190 + + -- Misun Kim Sun, 08 Dec 2013 19:34:04 +0900 + +net-config (0.1.189) unstable; urgency=low + + * Fix prevent issues + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.189 + + -- Sanghoon Cho Sun, 08 Dec 2013 12:35:27 +0900 + +net-config (0.1.188) unstable; urgency=low + + * Maintain Wi-Fi state due to restricted mode changes in vconf + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.188 + + -- Naveen H Sat, 07 Dec 2013 11:48:22 +0530 + +net-config (0.1.187) precise; urgency=low + + * To avoid 2 Noti for Portal + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.187 + + -- Vikram Shrirang Bidkar Fri, 06 Dec 2013 19:36:53 +0530 + +net-config (0.1.186) unstable; urgency=low + + * Enable wps scan when Wi-Fi is connected + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.186 + + -- Sanghoon Cho Fri, 06 Dec 2013 18:05:40 +0900 + +net-config (0.1.185) precise; urgency=low + + * Remove mdm phase 2 option for wifi policy + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.185 + + -- sunil85.kim Wed, 04 Dec 2013 21:44:01 +0900 + +net-config (0.1.184) unstable; urgency=low + + * Do not check internet accessibility when smart switch is turned off + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.184 + + -- Misun Kim Wed, 04 Dec 2013 20:36:49 +0900 + +net-config (0.1.183) unstable; urgency=low + + * Revise recover logic to connect Wi-Fi switched with good signal + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.183 + + -- Misun Kim Wed, 04 Dec 2013 16:33:47 +0900 + +net-config (0.1.182) unstable; urgency=low + + * pseudonym id: remove sim/aka pseudonymid files when device rebooted + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.182 + + -- Sanghoon Cho Tue, 03 Dec 2013 22:03:35 +0900 + +net-config (0.1.181) unstable; urgency=low + + * Delete wifi notification if no wifi profiles found + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.181 + + -- Naveen H Tue, 03 Dec 2013 16:46:46 +0530 + +net-config (0.1.180) unstable; urgency=low + + * Maintain Wi-Fi state due to airplane mode changes in vconf + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.180 + + -- Naveen H Mon, 02 Dec 2013 16:59:48 +0530 + +net-config (0.1.179) unstable; urgency=low + + * error: revise net-config errors + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.179 + + -- Danny Jeongseok Seo Fri, 29 Nov 2013 23:31:54 +0900 + +net-config (0.1.178) unstable; urgency=low + + * agent: fix hidden network connection + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.178 + + -- Danny Jeongseok Seo Fri, 29 Nov 2013 12:05:24 +0900 + +net-config (0.1.177) unstable; urgency=low + + * network-state: default TCP buffer size + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.177 + + -- Danny Jeongseok Seo Thu, 28 Nov 2013 23:54:42 +0900 + +net-config (0.1.176) unstable; urgency=low + + * ConnMan agent: support hidden network connection + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.176 + + -- Danny Jeongseok Seo Thu, 28 Nov 2013 15:45:39 +0900 + +net-config (0.1.175) unstable; urgency=low + + * absolute execute paths + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.175 + + -- Danny Jeongseok Seo Thu, 28 Nov 2013 11:41:51 +0900 + +net-config (0.1.174) unstable; urgency=low + + * revise script path and return value + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.174 + + -- Sanghoon Cho Wed, 27 Nov 2013 15:57:51 +0900 + +net-config (0.1.173) unstable; urgency=low + + * Fix prevent defect - remove dead code + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.173 + + -- Misun Kim Mon, 25 Nov 2013 19:55:31 +0900 + +net-config (0.1.172) unstable; urgency=low + + * remove vconf callback - power saving mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.172 + + -- Sanghoon Cho Fri, 22 Nov 2013 12:12:21 +0900 + +net-config (0.1.171) unstable; urgency=low + + * apply csc feature for portal ignore list + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.171 + + -- Misun Kim Wed, 20 Nov 2013 16:17:51 +0900 + +net-config (0.1.170) unstable; urgency=low + + * wps-scan: fix crash for invalid utf8 ssid + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.170 + + -- Sanghoon Cho Tue, 19 Nov 2013 20:55:27 +0900 + +net-config (0.1.169) unstable; urgency=low + + * wifi-background-scan: immediate scan for a rather fast auto-connection + * TIZEN has a poor auto-connection 160% than Android does (MEV) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.169 + + -- Danny Jeongseok Seo Mon, 18 Nov 2013 16:17:41 +0900 + +net-config (0.1.168) unstable; urgency=low + + * wifi-state: lock power state during Wi-Fi connection + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.168 + + -- Danny Jeongseok Seo Fri, 15 Nov 2013 18:38:18 +0900 + +net-config (0.1.167) unstable; urgency=low + + * wifi-indicator: 3 leveled wifi activity booster + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.167 + + -- Danny Jeongseok Seo Fri, 15 Nov 2013 15:28:26 +0900 + +net-config (0.1.166) unstable; urgency=low + + * resolve: disable ipv6 loopback + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.166 + + -- Danny Jeongseok Seo Thu, 14 Nov 2013 22:16:34 +0900 + +net-config (0.1.165) unstable; urgency=low + + * Revise WPS scan + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.165 + + -- Danny Jeongseok Seo Thu, 14 Nov 2013 18:02:04 +0900 + +net-config (0.1.164) unstable; urgency=low + + * pseudonym id: remove when device rebooted + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.164 + + -- Danny Jeongseok Seo Thu, 14 Nov 2013 00:39:53 +0900 + +net-config (0.1.163) unstable; urgency=low + + * log: adjust log permission + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.163 + + -- Danny Jeongseok Seo Wed, 13 Nov 2013 23:57:02 +0900 + +net-config (0.1.162) unstable; urgency=low + + * wifi-firmware: hardening Wi-Fi firmware status + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.162 + + -- Danny Jeongseok Seo Mon, 11 Nov 2013 23:22:59 +0900 + +net-config (0.1.161) unstable; urgency=low + + * Fix RSSI filter scheme + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.161 + + -- Danny Jeongseok Seo Mon, 11 Nov 2013 19:28:43 +0900 + +net-config (0.1.160) unstable; urgency=low + + * agent: Revise EAP connection error, and delete config when if failed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.160 + + -- Danny Jeongseok Seo Mon, 11 Nov 2013 18:15:32 +0900 + +net-config (0.1.159) unstable; urgency=low + + * Revise checking internet accessibility + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.159 + + -- Misun Kim Fri, 08 Nov 2013 12:03:58 +0900 + +net-config (0.1.158) unstable; urgency=low + + * Fix not update for power saving mode + * Revise Wi-Fi power, Wi-Fi technology state, Wi-Fi firmware management + * Tag: net-config_0.1.158 + + -- Sanghoon Cho Wed, 06 Nov 2013 19:51:07 +0900 + +net-config (0.1.157) unstable; urgency=low + + * Connect Cellular after confirmed + * Revise Wi-Fi power, Wi-Fi technology state, Wi-Fi firmware management + * Tag: net-config_0.1.157 + + -- Misun Kim Tue, 05 Nov 2013 20:50:25 +0900 + +net-config (0.1.156) unstable; urgency=low + + * New DBus API to enable and disable WLAN driver + * Revise Wi-Fi power, Wi-Fi technology state, Wi-Fi firmware management + * Tag: net-config_0.1.156 + + -- Danny Jeongseok Seo Mon, 04 Nov 2013 19:47:50 +0900 + +net-config (0.1.155) unstable; urgency=low + + * wifi: network restricted mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.155 + + -- Danny Jeongseok Seo Fri, 01 Nov 2013 17:31:44 +0900 + +net-config (0.1.154) unstable; urgency=low + + * Update DBus signal fitler + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.154 + + -- Sanghoon Cho Mon, 28 Oct 2013 18:22:57 +0900 + +net-config (0.1.153) unstable; urgency=low + + * Draw SecurityRestricted popup using net-popup + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.153 + + -- Naveen H Tue, 29 Oct 2013 11:00:25 +0530 + +net-config (0.1.152) unstable; urgency=low + + * agent: ConnMan agent should be registered + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.152 + + -- Danny Jeongseok Seo Sun, 27 Oct 2013 18:27:32 +0900 + +net-config (0.1.151) unstable; urgency=low + + * Get link signal from /proc/net/wireless + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.151 + + -- Danny Jeongseok Seo Sun, 27 Oct 2013 17:14:40 +0900 + +net-config (0.1.150) unstable; urgency=low + + * remove legacy sysvinit, enable systemd activation with dbus + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.150 + + -- Danny Jeongseok Seo Sun, 27 Oct 2013 11:44:26 +0900 + +net-config (0.1.149) unstable; urgency=low + + * Revise checking internet status + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.149 + + -- Misun Kim Thu, 24 Oct 2013 14:19:56 +0900 + +net-config (0.1.148) unstable; urgency=low + + * agent: ConnMan agent should be registered + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.148 + + -- Danny Jeongseok Seo Tue, 22 Oct 2013 17:45:57 +0900 + +net-config (0.1.147) unstable; urgency=low + + * handle http response with 307 status [P131017-02660] + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.147 + + -- Misun Kim Mon, 21 Oct 2013 21:11:10 +0900 + +net-config (0.1.146) unstable; urgency=low + + * add logs for vconf set + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.146 + + -- Misun Kim Fri, 18 Oct 2013 18:19:37 +0900 + +net-config (0.1.145) unstable; urgency=low + + * clean up poor rx count + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.145 + + -- Misun Kim Mon, 14 Oct 2013 16:29:58 +0900 + +net-config (0.1.144) unstable; urgency=low + + * indicator: revise indicator update + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.144 + + -- Danny Jeongseok Seo Sun, 13 Oct 2013 12:28:39 +0900 + +net-config (0.1.143) unstable; urgency=low + + * util: terminated when execute has been failed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.143 + + -- Danny Jeongseok Seo Fri, 11 Oct 2013 22:39:16 +0900 + +net-config (0.1.142) unstable; urgency=low + + * Update enum for power saving mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.142 + + -- Sanghoon Cho Thu, 10 Oct 2013 22:04:22 +0900 + +net-config (0.1.141) unstable; urgency=low + + * Check for Wifi power state before loading/unloading of Wifi driver + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.141 + -- Jaganmohan K Thu, 10 Oct 2013 11:59:54 +0530 + +net-config (0.1.140) unstable; urgency=low + + * Modify pseudonym ID path + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.140 + + -- Sanghoon Cho Tue, 08 Oct 2013 20:56:27 +0900 + +net-config (0.1.139) unstable; urgency=low + + * data activity booster + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.139 + + -- Danny Jeongseok Seo Tue, 08 Oct 2013 20:20:32 +0900 + +net-config (0.1.138) unstable; urgency=low + + * Fix Wi-Fi on/off for airplane mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.138 + + -- Sanghoon Cho Tue, 08 Oct 2013 19:41:35 +0900 + +net-config (0.1.137) unstable; urgency=low + + * Fix Wi-Fi power state (WPS, recovery and deep sleep) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.137 + + -- Danny Jeongseok Seo Fri, 04 Oct 2013 22:45:09 +0900 + +net-config (0.1.136) unstable; urgency=low + + * fixed missing braces + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.136 + + -- Misun Kim Mon, 07 Oct 2013 19:31:52 +0900 + +net-config (0.1.135) unstable; urgency=low + + * captive portal is not worked for docomo Wi-Fi + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.135 + + -- Misun Kim Mon, 07 Oct 2013 13:53:08 +0900 + +net-config (0.1.134) unstable; urgency=low + + * revise getting 'LocalNetwork' property + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.134 + + -- Misun Kim Fri, 04 Oct 2013 19:54:55 +0900 + +net-config (0.1.133) unstable; urgency=low + + * resolve: enable IPv6 + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.133 + + -- Danny Jeongseok Seo Fri, 04 Oct 2013 15:21:58 +0900 + +net-config (0.1.132) unstable; urgency=low + + * resolv: enable attempts 8 + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.132 + + -- Danny Jeongseok Seo Fri, 04 Oct 2013 14:53:08 +0900 + +net-config (0.1.131) unstable; urgency=low + + * Launch keepit-service when Wi-Fi is connected + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.131 + + -- Sanghoon Cho Fri, 27 Sep 2013 14:30:48 +0900 + +net-config (0.1.130) unstable; urgency=low + + * Avoid unnecessary net-popup notifications(Wi-Fi networks available) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.130 + + -- Naveen H Thu, 26 Sep 2013 18:57:55 +0530 + +net-config (0.1.129) unstable; urgency=low + + * Net-config directly makes a connection to ConnMan when Wi-Fi EAP configuration installed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.129 + + -- Danny Jeongseok Seo Mon, 23 Sep 2013 17:54:39 +0900 + +net-config (0.1.128) unstable; urgency=low + + * lower disconnect threshold rssi and fix bug + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.128 + + -- Misun Kim Mon, 23 Sep 2013 21:48:03 +0900 + +net-config (0.1.127) unstable; urgency=low + + * Smart switching: remove vconf callback for flight mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.127 + + -- Sanghoon Cho Mon, 23 Sep 2013 15:38:50 +0900 + +net-config (0.1.126) unstable; urgency=low + + * Revise Wi-Fi technology state transition + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.126 + + -- Danny Jeongseok Seo Sat, 14 Sep 2013 00:07:11 +0900 + +net-config (0.1.125) unstable; urgency=low + + * Net-config directly makes a connection to ConnMan when Wi-Fi agent information is fed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.125 + + -- Danny Jeongseok Seo Fri, 13 Sep 2013 23:01:50 +0900 + +net-config (0.1.124) unstable; urgency=low + + * ConnMan agent error return when request input is invalid + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.124 + + -- Danny Jeongseok Seo Fri, 13 Sep 2013 16:51:23 +0900 + +net-config (0.1.123) unstable; urgency=low + + * Revise initial Wi-Fi power on, check SIM status + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.123 + + -- Sanghoon Cho Fri, 13 Sep 2013 20:26:25 +0900 + +net-config (0.1.122) precise; urgency=low + + * add portal notification instead of launching browser directly + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.122 + + -- Misun Kim Fri, 13 Sep 2013 19:19:20 +0900 + +net-config (0.1.121) unstable; urgency=low + + * Fix several leaks + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.121 + + -- Danny Jeongseok Seo Wed, 11 Sep 2013 16:21:14 +0900 + +net-config (0.1.120) unstable; urgency=low + + * Remove pseudonym ID for Wi-Fi EAP-AKA/SIM while booting + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.120 + + -- Sanghoon Cho Tue, 11 Sep 2013 11:34:59 +0900 + +net-config (0.1.119) unstable; urgency=low + + * Fix several memory leaks + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.119 + + -- Danny Jeongseok Seo Wed, 11 Sep 2013 00:41:28 +0900 + +net-config (0.1.118) unstable; urgency=low + + * Revise portal login, adjust tcp buffer size and remove kies-via-wifi + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.118 + + -- Danny Jeongseok Seo Thu, 05 Sep 2013 21:27:08 +0900 + +net-config (0.1.117) unstable; urgency=low + + * disable DBus DAC + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.117 + + -- Danny Jeongseok Seo Tue, 03 Sep 2013 17:44:50 +0900 + +net-config (0.1.116) unstable; urgency=low + + * apply new UX concept for smart switching and fix bug + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.116 + + -- Misun Kim Mon, 02 Sep 2013 16:10:24 +0900 + +net-config (0.1.115) unstable; urgency=low + + * DBus SMACK applied + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.115 + + -- Danny Jeongseok Seo Fri, 30 Aug 2013 22:30:36 +0900 + +net-config (0.1.114) unstable; urgency=low + + * Enable to set/get Wi-Fi passpoint option + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.114 + + -- Sanghoon Cho Tue, 29 Aug 2013 21:13:41 +0900 + +net-config (0.1.113) unstable; urgency=low + + * Wi-Fi profile provisioned from CSC default + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.113 + + -- Danny Jeongseok Seo Tue, 27 Aug 2013 23:19:40 +0900 + +net-config (0.1.112) unstable; urgency=low + + * Wi-Fi: revise Wi-Fi powemode to save consumption + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.112 + + -- Danny Jeongseok Seo Tue, 27 Aug 2013 17:31:40 +0900 + +net-config (0.1.111) unstable; urgency=low + + * Revise Wi-Fi suspendmode during associating and DHCP + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.111 + + -- Danny Jeongseok Seo Fri, 23 Aug 2013 15:47:35 +0900 + +net-config (0.1.110) unstable; urgency=low + + * Portal login: Handling Captive Portal AP disconnection + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.110 + -- Jaganmohan K Thu, 22 Aug 2013 12:32:21 +0530 + +net-config (0.1.109) unstable; urgency=low + + * Captive portal login implementation + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.109 + + -- Jaganmohan K Mon, 05 Aug 2013 22:32:49 +0530 + +net-config (0.1.108) unstable; urgency=low + + * Implement Wi-Fi power saving mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.108 + + -- Sanghoon Cho Fri, 09 Aug 2013 18:35:44 +0900 + +net-config (0.1.107) unstable; urgency=low + + * Implement to enable Wi-Fi scan on Wi-Fi off state + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.107 + + -- Sanghoon Cho Tue, 06 Aug 2013 10:41:02 +0900 + +net-config (0.1.106) unstable; urgency=low + + * Handle 'Proxy' property change signal + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.106 + + -- Naveen H Fri, 26 Jul 2013 19:06:37 +0530 + +net-config (0.1.105) unstable; urgency=low + + * Revise country code setting, remove revision number + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.105 + + -- Ravi RK Fri, 19 Jul 2013 13:37:25 +0530 + +net-config (0.1.104) unstable; urgency=low + + * Support SIOCKILLADDR during disconnection + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.104 + + -- Naveen H Tue, 16 Jul 2013 09:58:23 +0530 + +net-config (0.1.103) unstable; urgency=low + + * Support early suspend driver command + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.103 + + -- Ravi RK Fri, 28 Jun 2013 16:06:11 +0530 + +net-config (0.1.102) unstable; urgency=low + + * Update Wi-Fi indicator when it has been changed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.102 + + -- Danny Jeongseok Seo Sat, 06 Jul 2013 16:28:07 +0900 + +net-config (0.1.101) unstable; urgency=low + + * Revise ssid scan response + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.101 + + -- Danny Jeongseok Seo Sat, 29 Jun 2013 12:08:05 +0900 + +net-config (0.1.100) unstable; urgency=low + + * Static variable rather than heap variable (prevent warning) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.100 + + -- Danny Jeongseok Seo Wed, 19 Jun 2013 14:42:11 +0900 + +net-config (0.1.99) unstable; urgency=low + + * Return correct value of specific scan request + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.99 + + -- Naveen H Tue, 18 Jun 2013 11:31:22 +0530 + +net-config (0.1.98) unstable; urgency=low + + * Temporary disable IPv6 + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.98 + + -- Danny Jeongseok Seo Thu, 13 Jun 2013 21:25:20 +0900 + +net-config (0.1.97) unstable; urgency=low + + * Add interface of device picker test during power on + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.97 + + -- Danny Jeongseok Seo Sat, 08 Jun 2013 18:18:35 +0900 + +net-config (0.1.96) unstable; urgency=low + + * Remove init script + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.96 + + -- Danny Jeongseok Seo Tue, 04 Jun 2013 15:47:21 +0900 + +net-config (0.1.95) unstable; urgency=low + + * Support Wi-Fi connected notification + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.95 + + -- Sanghoon Cho Mon, 03 Jun 2013 18:27:04 +0900 + +net-config (0.1.94) unstable; urgency=low + + * Enable systemd tizen-runtime + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.94 + + -- Danny Jeongseok Seo Sat, 25 May 2013 14:16:00 +0900 + +net-config (0.1.93) unstable; urgency=low + + * Revise the initiation of 3G alert popup + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.93 + + -- Danny Jeongseok Seo Wed, 22 May 2013 21:08:10 +0900 + +net-config (0.1.92-56) unstable; urgency=low + + * Update strings for smart switch notification + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_56 + + -- Sanghoon Cho Tue, 21 May 2013 13:55:43 +0900 + +net-config (0.1.92-55) unstable; urgency=low + + * Udpate for smack_rule(labeling vconf) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_55 + + -- sunil85.kim Fri, 10 May 2013 22:40:58 +0900 + +net-config (0.1.92-54) unstable; urgency=low + + * Handle Wi-Fi firmware crash + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_54 + + -- Danny Jeongseok Seo Thu, 09 May 2013 22:41:38 +0900 + +net-config (0.1.92-53) unstable; urgency=low + + * logd enabled + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_53 + + -- Danny Jeongseok Seo Thu, 09 May 2013 09:47:00 +0900 + +net-config (0.1.92-52) unstable; urgency=low + + * Add exception handling for MDM + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_52 + + -- JaeHyun Kim Tue, 07 May 2013 19:18:58 +0900 + +net-config (0.1.92-51) unstable; urgency=low + + * Modify Smart Switching + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_51 + + -- JunHwan An Tue, 30 Apr 2013 18:51:46 +0900 + +net-config (0.1.92-50) unstable; urgency=low + + * Enable network module log + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_50 + + -- Danny Jeongseok Seo Thu, 02 May 2013 16:25:41 +0900 + +net-config (0.1.92-49) unstable; urgency=low + + * logd enabled to get Wi-Fi power state + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_49 + + -- Danny Jeongseok Seo Fri, 26 Apr 2013 13:20:52 +0900 + +net-config (0.1.92-48) unstable; urgency=low + + * Fix Prevent Issues + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_48 + + -- Madhusmita Sahu Tue, 23 Apr 2013 18:55:36 +0530 + +net-config (0.1.92-47) unstable; urgency=low + + * Upgrade Smart Switching (Apply Smart switching On/Off) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_47 + + -- JunHwan An Mon, 15 Apr 2013 15:51:10 +0900 + +net-config (0.1.92-46) unstable; urgency=low + + * Fix Prevent issues + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_46 + + -- Naveen H Mon, 15 Apr 2013 14:56:45 +0900 + +net-config (0.1.92-45) unstable; urgency=low + + * Update spec file for added vconf + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_45 + + -- Sanghoon Cho Fri, 12 Apr 2013 19:18:09 +0900 + +net-config (0.1.92-44) unstable; urgency=low + + * Revise Wi-Fi state for tx/rx transfer + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_44 + + -- Sanghoon Cho Fri, 12 Apr 2013 16:48:22 +0900 + +net-config (0.1.92-43) unstable; urgency=low + + * Add Wi-Fi state for tx/rx transfer + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_43 + + -- Sanghoon Cho Thu, 11 Apr 2013 18:04:48 +0900 + +net-config (0.1.92-42) unstable; urgency=low + + * Eliminate user privacy logs + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_42 + + -- Danny Jeongseok Seo Fri, 05 Apr 2013 22:34:58 +0900 + +net-config (0.1.92-41) unstable; urgency=low + + * Power saving strategy feature + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_41 + + -- Naveen H Thu, 28 Mar 2013 10:35:25 +0900 + +net-config (0.1.92-40) unstable; urgency=low + + * Disable power save mode while connecting + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_40 + + -- Sanghoon Cho Thu, 28 Mar 2013 14:15:36 +0900 + +net-config (0.1.92-39) unstable; urgency=low + + * Print the result of child process after running script + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_39 + + -- Naveen H Sat, 23 Mar 2013 23:26:49 +0900 + +net-config (0.1.92-38) unstable; urgency=low + + * Start/Stop background scan when Wi-Fi is disconnected/connected + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_38 + + -- Sanghoon Cho Fri, 15 Mar 2013 17:45:01 +0900 + +net-config (0.1.92-37) unstable; urgency=low + + * Add new dbus method to revise bg scan mechanism during hidden network search + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_37 + + -- Naveen H Thu, 14 Mar 2013 10:55:26 +0530 + +net-config (0.1.92-36) unstable; urgency=low + + * Move resolv.conf file to read-only part(/etc) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_36 + + -- Sanghoon Cho Tue, 12 Mar 2013 21:52:11 +0900 + +net-config (0.1.92-35) unstable; urgency=low + + * Fix net-config crash and memory leaks + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_35 + + -- Ravi RK Tue, 12 Mar 2013 08:50:47 +0530 + +net-config (0.1.92-34) unstable; urgency=low + + * Revise booting sequence + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_34 + + -- Sanghoon Cho Mon, 11 Mar 2013 12:05:40 +0900 + +net-config (0.1.92-33) unstable; urgency=low + + * Wi-Fi concurrent mode support + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_33 + + -- Danny Jeongseok Seo Sun, 10 Mar 2013 16:36:22 +0900 + +net-config (0.1.92-32) unstable; urgency=low + + * Optimize fetching of profile list + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_32 + + -- Naveen H Mon, 04 Mar 2013 10:07:36 +0530 + +net-config (0.1.92-31) unstable; urgency=low + + * Fix thread conlict of smart-switching + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_31 + + -- Sanghoon Cho Thu, 28 Feb 2013 11:02:31 +0900 + +net-config (0.1.92-30) unstable; urgency=low + + * Update default connection when net-config lost DBus signals + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_30 + + -- Praveen C Tue, 26 Feb 2013 17:30:05 +0900 + +net-config (0.1.92-29) unstable; urgency=low + + * Check for EAP service before trying to delete config file + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_29 + + -- Naveen H Mon, 25 Feb 2013 09:19:13 +0530 + +net-config (0.1.92-28) unstable; urgency=low + + * Recover agent registration when ConnMan destroyed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_28 + + -- Danny Jeongseok Seo Mon, 25 Feb 2013 17:48:51 +0900 + +net-config (0.1.92-27) unstable; urgency=low + + * Fix PLM#P130221-4417 + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_27 + + -- Ravi RK Fri, 22 Feb 2013 19:16:51 +0530 + +net-config (0.1.92-26) unstable; urgency=low + + * Check for Wi-Fi state w.r.t Flight mode changes + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_26 + + -- Naveen H Wed, 20 Feb 2013 17:55:31 +0530 + +net-config (0.1.92-25) unstable; urgency=low + + * Fix prevent bugs + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_25 + + -- Danny Jeongseok Seo Thu, 21 Feb 2013 14:31:39 +0900 + +net-config (0.1.92-24) unstable; urgency=low + + * Start "Kies via Wi-Fi", when Wi-Fi is connected + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_24 + + -- Danny Jeongseok Seo Wed, 20 Feb 2013 14:51:09 +0900 + +net-config (0.1.92-23) unstable; urgency=low + + * Change to netlink from ioctl when get Wi-Fi signal strength + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_23 + + -- Sanghoon Cho Wed, 20 Feb 2013 21:58:29 +0900 + +net-config (0.1.92-22) unstable; urgency=low + + * Network configuration module launched by DBus auto-activation + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_22 + + -- Danny Jeongseok Seo Tue, 19 Feb 2013 12:24:22 +0900 + +net-config (0.1.92-21) unstable; urgency=low + + * Wi-Fi concurrent mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_21 + + -- Danny Jeongseok Seo Thu, 14 Feb 2013 12:03:43 +0900 + +net-config (0.1.92-20) unstable; urgency=low + + * Implement Wi-Fi smart offloading + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_20 + + -- Sanghoon Cho Tue, 29 Jan 2013 11:21:07 +0900 + +net-config (0.1.92-19) unstable; urgency=low + + * Clear the WiFi found notification after changing the the WiFi state to OFF. (Fix PLM # P130206-6006) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_19 + + -- Praveen C Mon, 11 Feb 2013 15:22:50 +0530 + +net-config (0.1.92-18) unstable; urgency=low + + * Update regulatory domain soon after driver loading + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_18 + + -- Ravi RK Tue, 05 Feb 2013 15:08:21 +0530 + +net-config (0.1.92-17) unstable; urgency=low + + * SMACK rules updated + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_17 + + -- Danny Jeongseok Seo Fri, 01 Feb 2013 16:45:36 +0900 + +net-config (0.1.92-16) unstable; urgency=low + + * Change net-popup package name. + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_16 + + -- Praveen C Tue, 29 Jan 2013 16:54:30 +0530 + +net-config (0.1.92-15) unstable; urgency=low + + * Debug dlog/file optionable + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_15 + + -- Danny Jeongseok Seo Tue, 29 Jan 2013 17:02:53 +0900 + +net-config (0.1.92-14) unstable; urgency=low + + * Fix WPS PBC + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_14 + + -- Danny Jeongseok Seo Mon, 28 Jan 2013 19:57:42 +0900 + +net-config (0.1.92-13) unstable; urgency=low + + * Clear agent fields before update + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_13 + + -- Danny Jeongseok Seo Mon, 28 Jan 2013 12:21:07 +0900 + +net-config (0.1.92-12) unstable; urgency=low + + * Implement 'ReportError' method in net-config agent + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_12 + + -- Naveen H Fri, 25 Jan 2013 17:49:05 +0530 + +net-config (0.1.92-11) unstable; urgency=low + + * Fix Wi-Fi PBC & connection + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_11 + + -- Danny Jeongseok Seo Fri, 25 Jan 2013 13:22:31 +0900 + +net-config (0.1.92-10) unstable; urgency=low + + * Add support for WPS type connection in agent + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_10 + + -- Praveen C Thu, 24 Jan 2013 14:29:19 +0530 + +net-config (0.1.92-9) unstable; urgency=low + + * Check already powered during Wi-Fi enable/disable + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_9 + + -- Naveen H Thu, 24 Jan 2013 10:16:19 +0530 + +net-config (0.1.92-8) unstable; urgency=low + + * Revise Wi-Fi technology state + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_8 + + -- Danny Jeongseok Seo Wed, 23 Jan 2013 12:07:53 +0900 + +net-config (0.1.92-7) unstable; urgency=low + + * Fix Smart Switching + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_7 + + -- Danny Jeongseok Seo Wed, 16 Jan 2013 23:58:23 +0900 + +net-config (0.1.92-6) unstable; urgency=low + + * Fix crash issues seen due to invalid memory freeing + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_6 + + -- Naveen H Tue, 08 Jan 2013 15:25:09 +0530 + +net-config (0.1.92-5) unstable; urgency=low + + * Fix resource leak, check returns, etc. + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_5 + + -- Danny Jeongseok Seo Wed, 02 Jan 2013 15:18:20 +0900 + +net-config (0.1.92-4) unstable; urgency=low + + * Launch net-popup from AUL. Moved the add/del notification into noti-popup. + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_4 + + -- Praveen C Fri, 04 Jan 2013 11:50:11 +0530 + +net-config (0.1.92-3) unstable; urgency=low + + * Change the way EAP config file is saved + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_3 + + -- Naveen H Thu, 27 Dec 2012 10:46:34 +0530 + +net-config (0.1.92-2) unstable; urgency=low + + * Fix crash due to non-NULL terminated string array. + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_2 + + -- Praveen C Thu, 20 Dec 2012 10:41:58 +0530 + +net-config (0.1.92-1) unstable; urgency=low + + * Upgrade ConnMan 1.3 + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.92_1 + + -- Danny Jeongseok Seo Tue, 18 Dec 2012 20:46:01 +0900 + +net-config (0.1.91-3) unstable; urgency=low + + * Changed the notification type from box type to list type. + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.91-3 + + -- Praveen C Tue, 18 Dec 2012 18:47:00 +0530 + +net-config (0.1.91-2) unstable; urgency=low + + * Add TCP buffer adjustment for LTE bearer + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.91-2 + + -- Danny Jeongseok Seo Mon, 10 Dec 2012 19:36:40 +0900 + +net-config (0.1.91-1) unstable; urgency=low + + * Support Wi-Fi country code + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.91-1 + + -- Danny Jeongseok Seo Mon, 10 Dec 2012 16:43:08 +0900 + +net-config (0.1.90-14) unstable; urgency=low + + * Disable NTP service + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-14 + + -- Danny Jeongseok Seo Fri, 30 Nov 2012 17:10:47 +0900 + +net-config (0.1.90-13) unstable; urgency=low + + * Fix turn on Wi-Fi fails when Wi-Fi Direct is on + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-13 + + -- Sanghoon Cho Wed, 21 Nov 2012 16:59:56 +0900 + +net-config (0.1.90-12) unstable; urgency=low + + * Fix proxy clean up + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-12 + + -- Danny Jeongseok Seo Wed, 21 Nov 2012 15:01:48 +0900 + +net-config (0.1.90-11) unstable; urgency=low + + * Modify deleting notification by new policy + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-11 + + -- Sanghoon Cho Mon, 19 Nov 2012 16:21:12 +0900 + +net-config (0.1.90-10) unstable; urgency=low + + * Change vconf key for flight mode + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-10 + + -- Sanghoon Cho Fri, 16 Nov 2012 13:56:37 +0900 + +net-config (0.1.90-9) unstable; urgency=low + + * Implement deleting noti before adding one by new notification policy + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-9 + + -- Sanghoon Cho Thu, 15 Nov 2012 20:19:26 +0900 + +net-config (0.1.90-8) unstable; urgency=low + + * Check return value + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-8 + + -- Danny Jeongseok Seo Sat, 10 Nov 2012 15:09:34 +0900 + +net-config (0.1.90-7) unstable; urgency=low + + * Smart switching: do not recover Wi-Fi when MAC link failed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-7 + + -- Danny Jeongseok Seo Wed, 07 Nov 2012 00:01:03 +0900 + +net-config (0.1.90-6) unstable; urgency=low + + * Expand Wi-Fi state to laucn several services according to the Wi-Fi state transition + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-6 + + -- Danny Jeongseok Seo Tue, 06 Nov 2012 16:19:40 +0900 + +net-config (0.1.90-5) unstable; urgency=low + + * Fix post required dependency + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-5 + + -- Danny Jeongseok Seo Tue, 06 Nov 2012 13:28:47 +0900 + +net-config (0.1.90-4) unstable; urgency=low + + * Add mdm features(block network, minimum security) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-4 + + -- JaeHyun Kim Mon, 05 Nov 2012 20:59:18 +0900 + +net-config (0.1.90-3) unstable; urgency=low + + * Fix memory leaks and several warns + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-3 + + -- Danny Jeongseok Seo Fri, 02 Nov 2012 16:34:08 +0900 + +net-config (0.1.90-2) unstable; urgency=low + + * Revise Smart switching (Samsung proprietary) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-2 + + -- Danny Jeongseok Seo Thu, 01 Nov 2012 11:07:14 +0900 + +net-config (0.1.90-1) unstable; urgency=low + + * Revise network state machine + * Adjust TCP buffer size according to the bearer type + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.90-1 + + -- Danny Jeongseok Seo Wed, 17 Oct 2012 13:47:46 +0900 + +net-config (0.1.89-24) unstable; urgency=low + + * Fix fail to delete Wi-Fi found notification when Wi-Fi is connected + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-24 + + -- Sanghoon Cho Wed, 24 Oct 2012 16:58:47 +0900 + +net-config (0.1.89-23) unstable; urgency=low + + * Fix status conflict with supplicant + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-23 + + -- Sanghoon Cho Wed, 24 Oct 2012 15:21:38 +0900 + +net-config (0.1.89-22) unstable; urgency=low + + * Fix not destroy "please wait" popup when request SSID scan + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-22 + + -- Sanghoon Cho Fri, 19 Oct 2012 15:56:19 +0900 + +net-config (0.1.89-21) unstable; urgency=low + + * Consolidation of wpa_supplicant + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-21 + + -- Sanghoon Cho Fri, 12 Oct 2012 14:11:46 +0900 + +net-config (0.1.89-20) unstable; urgency=low + + * Add add/remove route + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-20 + + -- JaeHyun Kim Fri, 12 Oct 2012 20:54:45 +0900 + +net-config (0.1.89-19) unstable; urgency=low + + * Install license + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-19 + + -- Danny Jeongseok Seo Fri, 12 Oct 2012 10:19:28 +0900 + +net-config (0.1.89-18) unstable; urgency=low + + * Support NTP timeserver + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-18 + + -- Danny Jeongseok Seo Thu, 04 Oct 2012 16:59:35 +0900 + +net-config (0.1.89-17) unstable; urgency=low + + * Modify manifest rule + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-17 + + -- Sanghoon Cho Mon, 24 Sep 2012 17:59:01 +0900 + +net-config (0.1.89-16) unstable; urgency=low + + * Fix manifest error + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-16 + + -- Danny Jeongseok Seo Fri, 21 Sep 2012 17:06:42 +0900 + +net-config (0.1.89-15) unstable; urgency=low + + * Apply SMACK manifest + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-15 + + -- Sanghoon Cho Thu, 20 Sep 2012 13:38:32 +0900 + +net-config (0.1.89-14) unstable; urgency=low + + * Reorganize wifi gobject declaration + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-14 + + -- Sanghoon Cho Mon, 10 Sep 2012 13:33:43 +0900 + +net-config (0.1.89-13) unstable; urgency=low + + * Implement wifi eap-sim/aka + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-13 + + -- Sanghoon Cho Thu, 30 Aug 2012 16:07:53 +0900 + +net-config (0.1.89-12) unstable; urgency=low + + * Find hidden network need to get true when the scan is in progress + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-12 + + -- Danny Jeongseok Seo Fri, 31 Aug 2012 15:41:34 +0900 + +net-config (0.1.89-11) unstable; urgency=low + + * Fix SSID scan failure because of background scan + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-11 + + -- Danny Jeongseok Seo Thu, 30 Aug 2012 20:34:49 +0900 + +net-config (0.1.89-10) unstable; urgency=low + + * Revise Wi-Fi background scan + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-10 + + -- Danny Jeongseok Seo Thu, 30 Aug 2012 20:11:43 +0900 + +net-config (0.1.89-9) unstable; urgency=low + + * Revise netdbus and signal fitler handler + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-9 + + -- Danny Jeongseok Seo Thu, 30 Aug 2012 19:54:50 +0900 + +net-config (0.1.89-8) unstable; urgency=low + + * Correct MAC failure, collisions and carrier + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-8 + + -- Danny Jeongseok Seo Fri, 24 Aug 2012 19:47:11 +0900 + +net-config (0.1.89-7) unstable; urgency=low + + * Correct MAC failure, collisions and carrier + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-7 + + -- Danny Jeongseok Seo Fri, 24 Aug 2012 17:26:35 +0900 + +net-config (0.1.89-6) unstable; urgency=low + + * Wi-Fi usability monitoring interval + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-6 + + -- Danny Jeongseok Seo Fri, 24 Aug 2012 13:17:04 +0900 + +net-config (0.1.89-5) unstable; urgency=low + + * Wi-Fi BG scan and specific scan exclusively + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-5 + + -- Danny Jeongseok Seo Fri, 24 Aug 2012 10:45:38 +0900 + +net-config (0.1.89-4) unstable; urgency=low + + * Revise mac failure + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-4 + + -- Danny Jeongseok Seo Thu, 23 Aug 2012 10:08:54 +0900 + +net-config (0.1.89-3) unstable; urgency=low + + * Noise filter for RSSI + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-3 + + -- Danny Jeongseok Seo Wed, 22 Aug 2012 13:05:28 +0900 + +net-config (0.1.89-2) unstable; urgency=low + + * Reduce power consumption in case of LCD off + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-2 + + -- Danny Jeongseok Seo Wed, 22 Aug 2012 12:32:28 +0900 + +net-config (0.1.89-1) unstable; urgency=low + + * First draft of Wi-Fi smart switching + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.89-1 + + -- Danny Jeongseok Seo Tue, 21 Aug 2012 11:00:30 +0900 + +net-config (0.1.88-6) unstable; urgency=low + + * Add keyfile load/save + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.88-6 + + -- Danny Jeongseok Seo Fri, 17 Aug 2012 17:16:28 +0900 + +net-config (0.1.88-5) unstable; urgency=low + + * wifi-state notifier + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.88-5 + + -- Danny Jeongseok Seo Fri, 17 Aug 2012 00:24:16 +0900 + +net-config (0.1.88-4) unstable; urgency=low + + * Re-factor wifi-state, statistics + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.88-4 + + -- Danny Jeongseok Seo Thu, 16 Aug 2012 16:52:47 +0900 + +net-config (0.1.88-3) unstable; urgency=low + + * Fix build break + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.88-3 + + -- Danny Jeongseok Seo Tue, 14 Aug 2012 13:30:07 +0900 + +net-config (0.1.88-2) unstable; urgency=low + + * Implement SSID scan for Finding Hidden Network + * First draft from Sanghoon Cho, Praveen C + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.88-2 + + -- Danny Jeongseok Seo Sat, 11 Aug 2012 16:30:06 +0900 + +net-config (0.1.88-1) unstable; urgency=low + + * Revise functions for dbus method call to avoid GPL license issue + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.88-1 + + -- JaeHyun Kim Fri, 10 Aug 2012 19:22:42 +0900 + +net-config (0.1.87-3) unstable; urgency=low + + * Revise test_device_picker to refer service favorite + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.87-3 + + -- Danny Jeongseok Seo Mon, 06 Aug 2012 19:43:16 +0900 + +net-config (0.1.87-2) unstable; urgency=low + + * Revise mdm codes to make public source release + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.87-2 + + -- Danny Jeongseok Seo Fri, 03 Aug 2012 18:07:18 +0900 + +net-config (0.1.87-1) unstable; urgency=low + + * Wi-Fi ANT BAR update (updated) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.87-1 + + -- Danny Jeongseok Seo Wed, 18 Jul 2012 14:44:47 +0900 + +net-config (0.1.86-7) unstable; urgency=low + + * Add power on/off completed signal + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.86-7 + + -- JaeHyun Kim Tue, 17 Jul 2012 16:40:10 +0900 + +net-config (0.1.86-6) unstable; urgency=low + + * Implement to delete Wi-Fi found notification when Wi-Fi is turned off + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.86-6 + + -- Sanghoon Cho Mon, 16 Jul 2012 16:40:40 +0900 + +net-config (0.1.86-5) unstable; urgency=low + + * Fix not showing 3G alert popup + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.86-5 + + -- Sanghoon Cho Fri, 13 Jul 2012 21:03:36 +0900 + +net-config (0.1.86-4) unstable; urgency=low + + * No update RSSI when LCD off + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.86-4 + + -- Danny Jeongseok Seo Wed, 11 Jul 2012 23:19:51 +0900 + +net-config (0.1.86-3) unstable; urgency=low + + * Fix Wi-Fi state update during Wi-Fi power off + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.86-3 + + -- Danny Jeongseok Seo Sat, 07 Jul 2012 20:53:21 +0900 + +net-config (0.1.86-2) unstable; urgency=low + + * No device picker during connecting + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.86-2 + + -- Danny Jeongseok Seo Sat, 07 Jul 2012 16:45:40 +0900 + +net-config (0.1.86-1) unstable; urgency=low + + * Implement to set/get network statistics + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.86-1 + + -- Sanghoon Cho Fri, 06 Jul 2012 19:47:02 +0900 + +net-config (0.1.85-6) unstable; urgency=low + + * Fix wifi indicator update bug + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.85-6 + + -- Sanghoon Cho Fri, 06 Jul 2012 16:36:04 +0900 + +net-config (0.1.85-5) unstable; urgency=low + + * Implement Wi-Fi found notification + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.85-5 + + -- Sanghoon Cho Tue, 03 Jul 2012 14:07:28 +0900 + +net-config (0.1.85-4) unstable; urgency=low + + * Re-factor Wi-Fi indicator + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.85-4 + + -- Danny Jeongseok Seo Tue, 05 Jun 2012 16:28:12 +0900 + +net-config (0.1.85-3) unstable; urgency=low + + * Remove logging of libnet-client and net-config + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.85-3 + + -- JaeHyun Kim Tue, 12 Jun 2012 19:57:12 +0900 + +net-config (0.1.85-2) unstable; urgency=low + + * Clean up the useless + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.85-2 + + -- Danny Jeongseok Seo Tue, 05 Jun 2012 10:41:42 +0900 + +net-config (0.1.85-1) unstable; urgency=low + + * Fix Wi-Fi BG Scan bug for default value + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.85-1 + + -- Sanghoon Cho Fri, 01 Jun 2012 15:12:49 +0900 + +net-config (0.1.84-1) unstable; urgency=low + + * Fix Wi-Fi power state update + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.84-1 + + -- Danny Jeongseok Seo Wed, 30 May 2012 13:34:17 +0900 + +net-config (0.1.83) unstable; urgency=low + + * Revise emulator support + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.83 + + -- Danny Jeongseok Seo Thu, 17 May 2012 17:55:47 +0900 + +net-config (0.1.82) unstable; urgency=low + + * Check NULL: Wi-Fi technology state + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.82 + + -- Danny Jeongseok Seo Thu, 17 May 2012 16:20:17 +0900 + +net-config (0.1.81) unstable; urgency=low + + * Revise private vconf key name + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.81 + + -- Danny Jeongseok Seo Tue, 15 May 2012 13:54:28 +0900 + +net-config (0.1.80) unstable; urgency=low + + * Revise unnecessary funtions + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.80 + + -- Danny Jeongseok Seo Wed, 09 May 2012 15:13:52 +0900 + +net-config (0.1.79) unstable; urgency=low + + * Revise net-config signal filter handler + * Revise Wi-Fi state management + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.79 + + -- Danny Jeongseok Seo Wed, 09 May 2012 11:41:09 +0900 + +net-config (0.1.78) unstable; urgency=low + + * Revise ConnMan profile prefix to fit ConnMan 0.78 + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.78 + + -- Danny Jeongseok Seo Tue, 08 May 2012 15:55:04 +0900 + +net-config (0.1.77) unstable; urgency=low + + * Revise net-config to fit Android supplicant + * Revise net-config log + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.77 + + -- Danny Jeongseok Seo Tue, 24 Apr 2012 23:08:11 +0900 + +net-config (0.1.76) unstable; urgency=low + + * Add a vconf key for local MAC address of Wi-Fi device + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.76 + + -- JaeHyun Kim Tue, 17 Apr 2012 10:28:08 +0900 + +net-config (0.1.75) unstable; urgency=low + + * Modify background scan policy + * disallow to request bg scan in case the state is connected and rssi is below level 2 + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.75 + + -- Sanghoon Cho Fri, 13 Apr 2012 16:37:55 +0900 + +net-config (0.1.74) unstable; urgency=low + + * Fix Wi-Fi power bug when Wi-Fi direct is on + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.74 + + -- Sanghoon Cho Thu, 12 Apr 2012 22:06:27 +0900 + +net-config (0.1.73) unstable; urgency=low + + * Fix Wi-Fi tethering state bugs + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.73 + + -- Danny Jeongseok Seo Mon, 02 Apr 2012 17:27:06 +0900 + +net-config (0.1.72) unstable; urgency=low + + * Fix emulator proxy setting + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.72 + + -- Danny Jeongseok Seo Thu, 29 Mar 2012 10:45:15 +0900 + +net-config (0.1.71) unstable; urgency=low + + * Enable DBus auto-activation + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.71 + + -- Danny Jeongseok Seo Tue, 27 Mar 2012 14:01:40 +0900 + +net-config (0.1.70) unstable; urgency=low + + * Implement Wi-Fi device picker service + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.70 + + -- Danny Jeongseok Seo Fri, 23 Mar 2012 19:28:01 +0900 + +net-config (0.1.69) unstable; urgency=low + + * Change alert popup name to net-popup + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.69 + + -- Sunkey Lee Fri, 16 Mar 2012 10:21:53 +0900 + +net-config (0.1.68) unstable; urgency=low + + * Revise Network State update DBus interface name (object path) + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.68 + + -- Danny Jeongseok Seo Thu, 15 Mar 2012 13:33:17 +0900 + +net-config (0.1.67) unstable; urgency=low + + * Write update default connection information + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.67 + + -- Danny Jeongseok Seo Wed, 14 Mar 2012 21:31:57 +0900 + +net-config (0.1.66) unstable; urgency=low + + * Write initial Network Configuration Module based on exist sonet + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.66 + + -- Danny Jeongseok Seo Wed, 14 Mar 2012 19:00:26 +0900 + +net-config (0.1.65) unstable; urgency=low + + * Fix network status update + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.65 + + -- Danny Jeongseok Seo Thu, 08 Mar 2012 22:17:24 +0900 + +net-config (0.1.64) unstable; urgency=low + + * Fix vconf memory backend to be installed + * Git: magnolia/framework/connectivity/net-config + * Tag: net-config_0.1.64 + + -- Danny Jeongseok Seo Tue, 06 Mar 2012 21:11:08 +0900 + +sonet (0.1.0) unstable; urgency=low + + * Initial Release + + -- DongHoo Park Tue, 23 Aug 2011 11:22:04 +0900 diff --git a/wearable/debian/compat b/wearable/debian/compat new file mode 100644 index 0000000..7ed6ff8 --- /dev/null +++ b/wearable/debian/compat @@ -0,0 +1 @@ +5 diff --git a/wearable/debian/control b/wearable/debian/control new file mode 100644 index 0000000..885af41 --- /dev/null +++ b/wearable/debian/control @@ -0,0 +1,17 @@ +Source: net-config +Section: net +Priority: extra +Maintainer: Danny Jeongseok Seo +Uploaders: Danny Jeongseok Seo , Jeik Jaehyun Kim , Misun Kim , Sanghoon Cho +Build-Depends: debhelper (>= 5), libdbus-1-dev (>= 1.1.1), libglib2.0-dev, libdbus-glib-1-dev, dlog-dev, syspopup-caller-dev +Standards-Version: 3.7.2 + +Package: net-config +Architecture: any +Depends: ${shlibs:Depends}, ${misc:Depends} +Description: TIZEN Network Configuration Module + +Package: net-config-dbg +Architecture: any +Depends: net-config (= ${Source-Version}), ${shlibs:Depends}, ${misc:Depends} +Description: debug symbols for TIZEN Network Configuration Module diff --git a/wearable/debian/net-config.install.in b/wearable/debian/net-config.install.in new file mode 100644 index 0000000..4ceff5e --- /dev/null +++ b/wearable/debian/net-config.install.in @@ -0,0 +1,7 @@ +@PREFIX@/sbin/* +@PREFIX@/share/dbus-1/services/* +@PREFIX@/etc/dbus-1/system.d/* +/etc/resolv.conf +/etc/rc.d/init.d/net-config +/etc/rc.d/rc3.d/S45net-config +/etc/rc.d/rc5.d/S45net-config diff --git a/wearable/debian/net-config.postinst b/wearable/debian/net-config.postinst new file mode 100644 index 0000000..d4bb99d --- /dev/null +++ b/wearable/debian/net-config.postinst @@ -0,0 +1,35 @@ +#!/bin/sh + +vconftool set -t int memory/dnet/state 0 -i +vconftool set -t int memory/wifi/state 0 -i +vconftool set -t int memory/wifi/strength 0 -i + +vconftool set -t int memory/dnet/cellular 0 -i +vconftool set -t int memory/dnet/wifi 0 -i +vconftool set -t int memory/dnet/network_config 0 -i +vconftool set -t int memory/dnet/status 0 -i +vconftool set -t string memory/dnet/ip "" -i +vconftool set -t string memory/dnet/proxy "" -i + +vconftool set -t string memory/wifi/connected_ap_name "" -i + +vconftool set -t string db/wifi/bssid_address "" + +#Default Call Statistics +vconftool set -t int db/dnet/statistics/cellular/totalsnt "0" +vconftool set -t int db/dnet/statistics/cellular/totalrcv "0" +vconftool set -t int db/dnet/statistics/cellular/lastsnt "0" +vconftool set -t int db/dnet/statistics/cellular/lastrcv "0" +vconftool set -t int db/dnet/statistics/wifi/totalsnt "0" +vconftool set -t int db/dnet/statistics/wifi/totalrcv "0" +vconftool set -t int db/dnet/statistics/wifi/lastsnt "0" +vconftool set -t int db/dnet/statistics/wifi/lastrcv "0" + +vconftool set -t int file/private/wifi/last_power_state "0" +vconftool set -t int file/private/wifi/wifi_off_by_airplane "0" +vconftool set -t int file/private/wifi/wifi_off_by_restricted "0" + +#Change File Permission +#Resource +chmod 644 /etc/resolv.conf + diff --git a/wearable/debian/rules b/wearable/debian/rules new file mode 100755 index 0000000..e6e98a7 --- /dev/null +++ b/wearable/debian/rules @@ -0,0 +1,136 @@ +#!/usr/bin/make -f +# -*- makefile -*- +# Sample debian/rules that uses debhelper. +# This file was originally written by Joey Hess and Craig Small. +# As a special exception, when this file is copied by dh-make into a +# dh-make output file, you may use that output file without restriction. +# This special exception was added by Craig Small in version 0.37 of dh-make. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +CFLAGS += -g -rdynamic +CFLAGS += -Wall -Werror +LDFLAGS ?= +PREFIX ?= /usr +DATADIR ?= /usr/share + +ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) + CFLAGS += -O0 +else + CFLAGS += -O2 +endif + +LDFLAGS += -Wl,--rpath=$(PREFIX)/lib -Wl,--as-needed + +CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp + +configure: configure-stamp +configure-stamp: + dh_testdir + # Add here commands to configure the package. + mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && \ + CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" cmake .. -DCMAKE_INSTALL_PREFIX="$(PREFIX)" + + touch configure-stamp + +build: build-stamp + +build-stamp: configure-stamp + dh_testdir + + # Add here commands to compile the package. + cd $(CMAKE_BUILD_DIR) && $(MAKE) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + cat $$f > $${f%.in}; \ + sed -i -e "s#@PREFIX@#$(PREFIX)#g" $${f%.in}; \ + sed -i -e "s#@DATADIR@#$(DATADIR)#g" $${f%.in}; \ + done + + touch $@ + +clean: + dh_testdir + dh_testroot + rm -f build-stamp configure-stamp + rm -f $(CURDIR)/src/*.service + rm -f $(CURDIR)/include/*-glue.h + + # Add here commands to clean up after the build process. + rm -rf $(CMAKE_BUILD_DIR) + + for f in `find $(CURDIR)/debian/ -name "*.in"`; do \ + rm -f $${f%.in}; \ + done + + rm -f ../net-config_*.deb + rm -f ../net-config-*.deb + rm -f ../net-config_*.changes + rm -f ../net-config_*.dsc + rm -f ../net-config_*.tar.gz + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + + # Add here commands to install the package into debian/wavplayer. + cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install + + mkdir -p $(CURDIR)/debian/tmp$(PREFIX)/share/dbus-1/services + cp -f $(CURDIR)/resources$(PREFIX)/share/dbus-1/services/net.netconfig.service \ + $(CURDIR)/debian/tmp$(PREFIX)/share/dbus-1/services/net.netconfig.service + mkdir -p $(CURDIR)/debian/tmp$(PREFIX)/etc/dbus-1/system.d + cp -f $(CURDIR)/resources$(PREFIX)/etc/dbus-1/system.d/net-config.conf \ + $(CURDIR)/debian/tmp$(PREFIX)/etc/dbus-1/system.d/net-config.conf + mkdir -p $(CURDIR)/debian/tmp/opt/etc + cp -f $(CURDIR)/resources/etc/resolv.conf $(CURDIR)/debian/tmp/etc/resolv.conf + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/init.d + cp -f $(CURDIR)/resources/etc/rc.d/init.d/net-config $(CURDIR)/debian/tmp/etc/rc.d/init.d/net-config + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc3.d + ln -s ../init.d/net-config $(CURDIR)/debian/tmp/etc/rc.d/rc3.d/S45net-config + mkdir -p $(CURDIR)/debian/tmp/etc/rc.d/rc5.d + ln -s ../init.d/net-config $(CURDIR)/debian/tmp/etc/rc.d/rc5.d/S45net-config + + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot +# dh_installchangelogs +# dh_installdocs +# dh_installexamples + dh_install --sourcedir=debian/tmp +# dh_installmenu +# dh_installdebconf +# dh_installlogrotate +# dh_installemacsen +# dh_installpam +# dh_installmime +# dh_python +# dh_installinit +# dh_installcron +# dh_installinfo +# dh_installman + dh_link + dh_strip --dbg-package=net-config-dbg + dh_compress + dh_fixperms +# dh_perl + 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/wearable/include/cellular-state.h b/wearable/include/cellular-state.h new file mode 100644 index 0000000..c95f583 --- /dev/null +++ b/wearable/include/cellular-state.h @@ -0,0 +1,54 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_CELLULAR_STATE_H__ +#define __NETCONFIG_CELLULAR_STATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +enum netconfig_cellular_service_state { + NETCONFIG_CELLULAR_UNKNOWN = 0x00, + NETCONFIG_CELLULAR_IDLE = 0x01, + NETCONFIG_CELLULAR_ONLINE = 0x02, +}; + +struct netconfig_cellular_state_notifier { + void (*netconfig_cellular_state_changed) + (enum netconfig_cellular_service_state, void *user_data); + void *user_data; +}; + +void netconfig_cellular_state_set_service_state( + enum netconfig_cellular_service_state new_state); +enum netconfig_cellular_service_state + netconfig_cellular_state_get_service_state(void); + +void netconfig_cellular_state_notifier_cleanup(void); +void netconfig_cellular_state_notifier_register( + struct netconfig_cellular_state_notifier *notifier); +void netconfig_cellular_state_notifier_unregister( + struct netconfig_cellular_state_notifier *notifier); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_CELLULAR_STATE_H__ */ diff --git a/wearable/include/emulator.h b/wearable/include/emulator.h new file mode 100644 index 0000000..3bff8b2 --- /dev/null +++ b/wearable/include/emulator.h @@ -0,0 +1,36 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_EMULATOR_H__ +#define __NETCONFIG_EMULATOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +gboolean netconfig_emulator_is_emulated(void); +void netconfig_emulator_test_and_start(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_EMULATOR_H__ */ diff --git a/wearable/include/log.h b/wearable/include/log.h new file mode 100644 index 0000000..4496814 --- /dev/null +++ b/wearable/include/log.h @@ -0,0 +1,52 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_LOG_H__ +#define __NETCONFIG_LOG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#define NETCONFIG_DEBUG_FILE (1) + +void __netconfig_debug(const char *format, ...); + +#define __LOG(level, format, arg...) \ + do { \ + if (NETCONFIG_DEBUG_FILE) { \ + __netconfig_debug("%s "format"\n", __FUNCTION__, ## arg); \ + } else { \ + SLOG(level, PACKAGE, "%s "format"\n", __FUNCTION__, ## arg); \ + } \ + } while(0) + +#define DBG(format, arg...) __LOG(LOG_DEBUG, format, ## arg) +#define INFO(format, arg...) __LOG(LOG_INFO, format, ## arg) +#define WARN(format, arg...) __LOG(LOG_WARN, format, ## arg) +#define ERR(format, arg...) __LOG(LOG_ERROR, format, ## arg) + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_LOG_H__ */ diff --git a/wearable/include/netdbus.h b/wearable/include/netdbus.h new file mode 100644 index 0000000..2b4111b --- /dev/null +++ b/wearable/include/netdbus.h @@ -0,0 +1,82 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_NETDBUS_H__ +#define __NETCONFIG_NETDBUS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define NETCONFIG_SERVICE "net.netconfig" + +#define CONNMAN_SERVICE "net.connman" +#define CONNMAN_PATH "/net/connman" + +#define CONNMAN_CLOCK_INTERFACE CONNMAN_SERVICE ".Clock" +#define CONNMAN_ERROR_INTERFACE CONNMAN_SERVICE ".Error" +#define CONNMAN_MANAGER_INTERFACE CONNMAN_SERVICE ".Manager" +#define CONNMAN_SERVICE_INTERFACE CONNMAN_SERVICE ".Service" +#define CONNMAN_TECHNOLOGY_INTERFACE CONNMAN_SERVICE ".Technology" +#define CONNMAN_MANAGER_PATH "/" + +#define CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/cellular_" +#define CONNMAN_WIFI_SERVICE_PROFILE_PREFIX CONNMAN_PATH "/service/wifi_" + +#define CONNMAN_CELLULAR_TECHNOLOGY_PREFIX CONNMAN_PATH "/technology/cellular" +#define CONNMAN_WIFI_TECHNOLOGY_PREFIX CONNMAN_PATH "/technology/wifi" + +#define NETCONFIG_WIFI_INTERFACE "net.netconfig.wifi" +#define NETCONFIG_WIFI_PATH "/net/netconfig/wifi" + +#define DBUS_PATH_MAX_BUFLEN 512 +#define DBUS_STATE_MAX_BUFLEN 64 + +typedef enum { + NETCONFIG_DBUS_RESULT_GET_BGSCAN_MODE, + NETCONFIG_DBUS_RESULT_DEFAULT_TECHNOLOGY, +} netconfig_dbus_result_type; + +gboolean netconfig_is_cellular_internet_profile(const char *profile); +gboolean netconfig_is_cellular_profile(const char *profile); +gboolean netconfig_is_wifi_profile(const char *profile); + +gboolean netconfig_invoke_dbus_method_nonblock( + const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[], + DBusPendingCallNotifyFunction notify_func); +DBusMessage *netconfig_invoke_dbus_method(const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[]); + +gboolean netconfig_dbus_get_basic_params_string(DBusMessage *message, + char **key, int type, void *value); +gboolean netconfig_dbus_get_basic_params_array(DBusMessage *message, + const char *key, void **value); + +DBusGConnection *netconfig_setup_dbus(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETDBUS_H__ */ diff --git a/wearable/include/neterror.h b/wearable/include/neterror.h new file mode 100644 index 0000000..8ef3706 --- /dev/null +++ b/wearable/include/neterror.h @@ -0,0 +1,50 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_ERROR_H__ +#define __NETCONFIG_ERROR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "glib.h" + +#define NETCONFIG_ERROR_QUARK (netconfig_error_quark()) +#define NETCONFIG_CONNMAN_AGENT_ERROR_QUARK (netconfig_connman_agent_error_quark()) + +void netconfig_error_inprogress(GError **error); +void netconfig_error_already_exists(GError **error); +void netconfig_error_invalid_parameter(GError **error); +void netconfig_error_permission_denied(GError **error); +void netconfig_error_wifi_driver_failed(GError **error); +void netconfig_error_wifi_direct_failed(GError **error); +void netconfig_error_fail_get_imsi(GError **error); +void netconfig_error_fail_req_sim_auth(GError **error); +void netconfig_error_fail_req_sim_auth_wrong_param(GError **error); +void netconfig_error_fail_get_sim_auth_wrong_data(GError **error); +void netconfig_error_fail_get_sim_auth_delay(GError **error); + +void netconfig_error_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_ERROR_H__ */ diff --git a/wearable/include/netsupplicant.h b/wearable/include/netsupplicant.h new file mode 100644 index 0000000..1cf35f8 --- /dev/null +++ b/wearable/include/netsupplicant.h @@ -0,0 +1,65 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_NETSUPPLICANT_H__ +#define __NETCONFIG_NETSUPPLICANT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define WIFI_IFNAME "wlan0" + +#define SUPPLICANT_SERVICE "fi.w1.wpa_supplicant1" +#define SUPPLICANT_INTERFACE "fi.w1.wpa_supplicant1" +#define SUPPLICANT_IFACE_INTERFACE SUPPLICANT_INTERFACE ".Interface" +#define SUPPLICANT_IFACE_BSS SUPPLICANT_INTERFACE ".BSS" +#define SUPPLICANT_PATH "/fi/w1/wpa_supplicant1" + +struct dbus_input_arguments { + int type; + void *data; +}; + +/* Returns Supplicant interface + * Do not free the returned interface */ +const char *netconfig_wifi_get_supplicant_interface(void); + +GList *setup_input_args(GList *list, struct dbus_input_arguments *items); +DBusMessage *netconfig_supplicant_invoke_dbus_method(const char *dest, + const char *path, const char *interface_name, + const char *method, GList *args); +dbus_bool_t netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, + const char *path, const char *interface_name, + const char *method, GList *args, + DBusPendingCallNotifyFunction notify_func); +DBusMessage *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface, + const char *key); +dbus_bool_t netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface, + const char *key, const char *type, GList *args, + DBusPendingCallNotifyFunction notify_func); +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETSUPPLICANT_H__ */ diff --git a/wearable/include/network-accessibility.h b/wearable/include/network-accessibility.h new file mode 100644 index 0000000..4232e0a --- /dev/null +++ b/wearable/include/network-accessibility.h @@ -0,0 +1,44 @@ +/* +* internet-accessibility check +* +* Copyright 2012 Samsung Electronics Co., Ltd +* +* Licensed under the Flora License, Version 1.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.tizenopensource.org/license +* +* 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 __NETCONFIG_NETWORK_ACCESSIBILITY_H__ +#define __NETCONFIG_NETWORK_ACCESSIBILITY_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void netconfig_check_internet_accessibility(void); +void netconfig_stop_internet_check(void); + +/* Alert: Please do not use netconfig_get_internet_status() API to get the + * status of Internet availability on general Wifi access points, as this module + * primarily checks for Internet availability on portal enabled Wifi access + * points, so we only check for below criteria in server's response to conclude + * whether Internet is accessible. + * 1) If the HTTP status != 302 + * 2) If the HTTP status != (200 with redirection), +*/ +gboolean netconfig_get_internet_status(); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETWORK_ACCESSIBILITY_H__ */ diff --git a/wearable/include/network-clock.h b/wearable/include/network-clock.h new file mode 100644 index 0000000..e1ef985 --- /dev/null +++ b/wearable/include/network-clock.h @@ -0,0 +1,34 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_NETWORK_CLOCK_H__ +#define __NETCONFIG_NETWORK_CLOCK_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void netconfig_clock_init(void); +void netconfig_clock_deinit(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETWORK_CLOCK_H__ */ diff --git a/wearable/include/network-state.h b/wearable/include/network-state.h new file mode 100644 index 0000000..22d3f35 --- /dev/null +++ b/wearable/include/network-state.h @@ -0,0 +1,72 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_NETWORK_STATE_H__ +#define __NETCONFIG_NETWORK_STATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +G_BEGIN_DECLS + +typedef struct NetconfigNetworkState NetconfigNetworkState; +typedef struct NetconfigNetworkStateClass NetconfigNetworkStateClass; + +#define NETCONFIG_TYPE_NETWORK_STATE ( netconfig_network_state_get_type() ) +#define NETCONFIG_NETWORK_STATE(obj) \ + ( G_TYPE_CHECK_INSTANCE_CAST((obj), NETCONFIG_TYPE_NETWORK_STATE, \ + NetconfigNetworkState) ) +#define NETCONFIG_IS_NETWORK_STATE(obj) \ + ( G_TYPE_CHECK_INSTANCE_TYPE((obj), NETCONFIG_TYPE_NETWORK_STATE) ) + +#define NETCONFIG_NETWORK_STATE_CLASS(klass) \ + ( G_TYPE_CHECK_CLASS_CAST((klass), NETCONFIG_TYPE_NETWORK_STATE, \ + NetconfigNetworkStateClass) ) +#define NETCONFIG_IS_NETWORK_STATE_CLASS(klass) \ + ( G_TYPE_CHECK_CLASS_TYPE((klass), NETCONFIG_TYPE_NETWORK_STATE) ) +#define NETCONFIG_NETWORK_STATE_GET_CLASS(obj) \ + ( G_TYPE_INSTANCE_GET_CLASS((obj), NETCONFIG_TYPE_NETWORK_STATE, \ + NetconfigNetworkStateClass) ) + +GType netconfig_network_state_get_type(void); + +gpointer netconfig_network_state_create_and_init(DBusGConnection *connection); + +G_END_DECLS + +const char *netconfig_get_default_profile(void); +const char *netconfig_get_default_ifname(void); +const char *netconfig_get_default_ipaddress(void); +const char *netconfig_get_default_proxy(void); +const char *netconfig_wifi_get_connected_essid(const char *default_profile); + +void netconfig_update_default(void); +void netconfig_update_default_profile(const char *profile); + +char *netconfig_network_get_ifname(const char *profile); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_NETWORK_STATE_H__ */ diff --git a/wearable/include/network-statistics.h b/wearable/include/network-statistics.h new file mode 100644 index 0000000..671a24b --- /dev/null +++ b/wearable/include/network-statistics.h @@ -0,0 +1,99 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETWORK_STATISTICS_H__ +#define __NETWORK_STATISTICS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +#include "wifi-state.h" + +G_BEGIN_DECLS + +typedef struct NetconfigNetworkStatistics NetconfigNetworkStatistics; +typedef struct NetconfigNetworkStatisticsClass NetconfigNetworkStatisticsClass; + +#define NETCONFIG_TYPE_NETWORK_STATISTICS \ + ( netconfig_network_statistics_get_type() ) +#define NETCONFIG_NETWORK_STATISTICS(obj) \ + ( G_TYPE_CHECK_INSTANCE_CAST((obj), NETCONFIG_TYPE_NETWORK_STATISTICS, \ + NetconfigNetworkStatistics) ) +#define NETCONFIG_IS_NETWORK_STATISTICS(obj) \ + ( G_TYPE_CHECK_INSTANCE_TYPE((obj), NETCONFIG_TYPE_NETWORK_STATISTICS) ) + +#define NETCONFIG_NETWORK_STATISTICS_CLASS(klass) \ + ( G_TYPE_CHECK_CLASS_CAST((klass), NETCONFIG_TYPE_NETWORK_STATISTICS, \ + NetconfigNetworkStatisticsClass) ) +#define NETCONFIG_IS_NETWORK_STATISTICS_CLASS(klass) \ + ( G_TYPE_CHECK_CLASS_TYPE((klass), NETCONFIG_TYPE_NETWORK_STATISTICS) ) +#define NETCONFIG_NETWORK_STATISTICS_GET_CLASS(obj) \ + ( G_TYPE_INSTANCE_GET_CLASS((obj), NETCONFIG_TYPE_NETWORK_STATISTICS, \ + NetconfigNetworkStatisticsClass) ) + +GType netconfig_network_statistics_get_type(void); + +gpointer netconfig_network_statistics_create_and_init( + DBusGConnection *connection); + +G_END_DECLS + +gboolean netconfig_iface_network_statistics_get_wifi_total_tx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *total_bytes, GError **error); +gboolean netconfig_iface_network_statistics_get_wifi_total_rx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *total_bytes, GError **error); +gboolean netconfig_iface_network_statistics_get_wifi_last_tx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *last_bytes, GError **error); +gboolean netconfig_iface_network_statistics_get_wifi_last_rx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *last_bytes, GError **error); + +gboolean netconfig_iface_network_statistics_reset_cellular_total_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_cellular_total_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_cellular_last_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_cellular_last_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); + +gboolean netconfig_iface_network_statistics_reset_wifi_total_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_wifi_total_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_wifi_last_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); +gboolean netconfig_iface_network_statistics_reset_wifi_last_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error); + +gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx); +void netconfig_wifi_statistics_update_powered_off(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETWORK_STATISTICS_H__ */ diff --git a/wearable/include/signal-handler.h b/wearable/include/signal-handler.h new file mode 100644 index 0000000..0864452 --- /dev/null +++ b/wearable/include/signal-handler.h @@ -0,0 +1,34 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_SIGNAL_HANDLER_H__ +#define __NETCONFIG_SIGNAL_HANDLER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void netconfig_register_signal(void); +void netconfig_deregister_signal(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_SIGNAL_HANDLER_H__ */ diff --git a/wearable/include/util.h b/wearable/include/util.h new file mode 100644 index 0000000..f690fe9 --- /dev/null +++ b/wearable/include/util.h @@ -0,0 +1,70 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_UTIL_H__ +#define __NETCONFIG_UTIL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include "wifi.h" + +#define NETCONFIG_ADD_FOUND_AP_NOTI "add_found_ap_noti" +#define NETCONFIG_DEL_FOUND_AP_NOTI "del_found_ap_noti" +#define NETCONFIG_ADD_PORTAL_NOTI "add_portal_noti" +#define NETCONFIG_DEL_PORTAL_NOTI "del_portal_noti" + +GKeyFile *netconfig_keyfile_load(const char *pathname); +void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname); + +void netconfig_start_timer_seconds(guint secs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id); +void netconfig_start_timer(guint msecs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id); +void netconfig_stop_timer(guint *timer_id); + +void netconfig_wifi_enable_device_picker_test(void); +void netconfig_wifi_device_picker_service_start(void); +void netconfig_wifi_device_picker_service_stop(void); + +gboolean netconfig_is_wifi_direct_on(void); +gboolean netconfig_is_wifi_tethering_on(void); + +gboolean netconfig_interface_up(const char *ifname); +gboolean netconfig_interface_down(const char *ifname); + +int netconfig_execute_file(const char *file_path, + char *const args[], char *const env[]); + +gboolean netconfig_iface_wifi_launch_direct(NetconfigWifi *wifi, GError **error); + +gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * data); +int netconfig_send_message_to_net_popup(const char *title, + const char *content, const char *type, const char *ssid); +void netconfig_set_vconf_int(const char * key, int value); +void netconfig_set_vconf_str(const char * key, const char * value); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_UTIL_H__ */ diff --git a/wearable/include/wifi-agent.h b/wearable/include/wifi-agent.h new file mode 100644 index 0000000..f0504d7 --- /dev/null +++ b/wearable/include/wifi-agent.h @@ -0,0 +1,53 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_AGENT_H__ +#define __NETCONFIG_WIFI_AGENT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_agent_register(void); +gboolean netconfig_agent_unregister(void); + +gboolean netconfig_wifi_set_agent_field_for_eap_network( + const char *name, const char *identity, const char *passphrase); + +gboolean netconfig_iface_wifi_set_field(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context); +gboolean netconfig_iface_wifi_request_input(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context); +gboolean netconfig_iface_wifi_report_error(NetconfigWifi *wifi, + gchar *service, gchar *error, + DBusGMethodInvocation *context); + +gboolean netconfig_iface_wifi_request_browser(NetconfigWifi *wifi, + gchar *service, gchar *url, + DBusGMethodInvocation *context); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_AGENT_H__ */ diff --git a/wearable/include/wifi-background-scan.h b/wearable/include/wifi-background-scan.h new file mode 100644 index 0000000..2247c45 --- /dev/null +++ b/wearable/include/wifi-background-scan.h @@ -0,0 +1,43 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFIBACKGROUND_SCAN_H__ +#define __NETCONFIG_WIFIBACKGROUND_SCAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +void netconfig_wifi_bgscan_start(void); +void netconfig_wifi_bgscan_stop(void); +gboolean netconfig_wifi_get_bgscan_state(void); + +gboolean netconfig_wifi_get_scanning(void); +void netconfig_wifi_set_scanning(gboolean scanning); + +gboolean netconfig_iface_wifi_set_bgscan( + NetconfigWifi *wifi, guint scan_mode, GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFIBACKGROUND_SCAN_H__ */ diff --git a/wearable/include/wifi-ccode.h b/wearable/include/wifi-ccode.h new file mode 100644 index 0000000..7dba8b1 --- /dev/null +++ b/wearable/include/wifi-ccode.h @@ -0,0 +1,33 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_CCODE_H__ +#define __NETCONFIG_WIFI_CCODE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void netconfig_wifi_ccode_init(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_CCODE_H__ */ diff --git a/wearable/include/wifi-eap-config.h b/wearable/include/wifi-eap-config.h new file mode 100644 index 0000000..7b23c02 --- /dev/null +++ b/wearable/include/wifi-eap-config.h @@ -0,0 +1,40 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_EAP_CONFIG_H__ +#define __NETCONFIG_WIFI_EAP_CONFIG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_iface_wifi_create_config(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context); +gboolean netconfig_iface_wifi_delete_config(NetconfigWifi *wifi, + gchar *profile, + DBusGMethodInvocation *context); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_EAP_CONFIG_H__ */ diff --git a/wearable/include/wifi-eap.h b/wearable/include/wifi-eap.h new file mode 100644 index 0000000..79ff229 --- /dev/null +++ b/wearable/include/wifi-eap.h @@ -0,0 +1,44 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_EAP_H__ +#define __NETCONFIG_WIFI_EAP_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_iface_wifi_get_sim_imsi(NetconfigWifi *wifi, + DBusGMethodInvocation *context); +gboolean netconfig_iface_wifi_req_sim_auth(NetconfigWifi *wifi, + GArray *rand_data, gboolean *result, GError **error); +gboolean netconfig_iface_wifi_req_aka_auth(NetconfigWifi *wifi, + GArray *rand_data, GArray *autn_data, gboolean *result, GError **error); +gboolean netconfig_iface_wifi_get_sim_auth(NetconfigWifi *wifi, + DBusGMethodInvocation *context); +gboolean netconfig_iface_wifi_get_aka_auth(NetconfigWifi *wifi, + DBusGMethodInvocation *context); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_EAP_H__ */ diff --git a/wearable/include/wifi-firmware.h b/wearable/include/wifi-firmware.h new file mode 100644 index 0000000..71ff5e5 --- /dev/null +++ b/wearable/include/wifi-firmware.h @@ -0,0 +1,47 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_FIRMWARE_H__ +#define __NETCONFIG_WIFI_FIRMWARE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +enum netconfig_wifi_firmware { + NETCONFIG_WIFI_OFF = 0x00, + NETCONFIG_WIFI_STA = 0x01, + NETCONFIG_WIFI_P2P = 0x02, + NETCONFIG_WIFI_SOFTAP = 0x03, +}; + +int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable); + +gboolean netconfig_iface_wifi_start( + NetconfigWifi *wifi, gchar *device, GError **error); +gboolean netconfig_iface_wifi_stop( + NetconfigWifi *wifi, gchar *device, GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_FIRMWARE_H__ */ diff --git a/wearable/include/wifi-indicator.h b/wearable/include/wifi-indicator.h new file mode 100644 index 0000000..8bbbd06 --- /dev/null +++ b/wearable/include/wifi-indicator.h @@ -0,0 +1,37 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_INDICATOR_H__ +#define __NETCONFIG_WIFI_INDICATOR_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +int netconfig_wifi_get_rssi(void); +int netconfig_wifi_rssi_level(const int rssi_dbm); + +void netconfig_wifi_indicator_start(void); +void netconfig_wifi_indicator_stop(void); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_INDICATOR_H__ */ diff --git a/wearable/include/wifi-passpoint.h b/wearable/include/wifi-passpoint.h new file mode 100644 index 0000000..4940a87 --- /dev/null +++ b/wearable/include/wifi-passpoint.h @@ -0,0 +1,38 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_PASSPOINT_H__ +#define __NETCONFIG_WIFI_PASSPOINT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_iface_wifi_get_passpoint(NetconfigWifi *wifi, + int *result, GError **error); +gboolean netconfig_iface_wifi_set_passpoint(NetconfigWifi *wifi, + int enable, GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_PASSPOINT_H__ */ diff --git a/wearable/include/wifi-power.h b/wearable/include/wifi-power.h new file mode 100644 index 0000000..04f4dfa --- /dev/null +++ b/wearable/include/wifi-power.h @@ -0,0 +1,46 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_POWER_H__ +#define __NETCONFIG_WIFI_POWER_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void netconfig_wifi_power_initialize(void); + +int netconfig_wifi_on(void); +int netconfig_wifi_off(void); +int netconfig_wifi_driver_and_supplicant(gboolean enable); + +void netconfig_wifi_recover_firmware(void); + +gboolean netconfig_iface_wifi_load_driver( + NetconfigWifi *wifi, gboolean device_picker_test, GError **error); +gboolean netconfig_iface_wifi_remove_driver( + NetconfigWifi *wifi, GError **error); +gboolean netconfig_is_wifi_allowed(void); +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_POWER_H__ */ diff --git a/wearable/include/wifi-ssid-scan.h b/wearable/include/wifi-ssid-scan.h new file mode 100644 index 0000000..12b4b1f --- /dev/null +++ b/wearable/include/wifi-ssid-scan.h @@ -0,0 +1,43 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_SSID_SCAN_H__ +#define __NETCONFIG_WIFI_SSID_SCAN_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_wifi_get_ssid_scan_state(void); + +void netconfig_wifi_notify_ssid_scan_done(void); +void netconfig_wifi_bss_added(DBusMessage *message); + +gboolean netconfig_wifi_ssid_scan(const char *ssid); + +gboolean netconfig_iface_wifi_request_specific_scan(NetconfigWifi *wifi, + gchar *ssid, GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_SSID_SCAN_H__ */ diff --git a/wearable/include/wifi-state.h b/wearable/include/wifi-state.h new file mode 100644 index 0000000..bb27d05 --- /dev/null +++ b/wearable/include/wifi-state.h @@ -0,0 +1,85 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_STATE_H__ +#define __NETCONFIG_WIFI_STATE_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +enum netconfig_wifi_service_state { + NETCONFIG_WIFI_UNKNOWN = 0x00, + NETCONFIG_WIFI_IDLE = 0x01, + NETCONFIG_WIFI_CONNECTING = 0x02, + NETCONFIG_WIFI_CONNECTED = 0x03, + NETCONFIG_WIFI_FAILURE = 0x04, +}; + +enum netconfig_wifi_tech_state { + NETCONFIG_WIFI_TECH_UNKNOWN = 0x00, + NETCONFIG_WIFI_TECH_OFF = 0x01, + NETCONFIG_WIFI_TECH_WPS_ONLY = 0x02, + NETCONFIG_WIFI_TECH_POWERED = 0x03, + NETCONFIG_WIFI_TECH_CONNECTED = 0x04, + NETCONFIG_WIFI_TECH_TETHERED = 0x05, +}; + +struct netconfig_wifi_state_notifier { + void (*netconfig_wifi_state_changed) + (enum netconfig_wifi_service_state, void *user_data); + void *user_data; +}; + +#define VCONF_WIFI_LAST_POWER_STATE "file/private/wifi/last_power_state" + +void netconfig_wifi_set_bss_found(const gboolean found); +gboolean netconfig_wifi_is_bss_found(void); +void netconfig_wifi_state_set_service_state( + enum netconfig_wifi_service_state new_state); +enum netconfig_wifi_service_state + netconfig_wifi_state_get_service_state(void); + +void netconfig_wifi_state_set_technology_state( + enum netconfig_wifi_tech_state new_state); +enum netconfig_wifi_tech_state + netconfig_wifi_state_get_technology_state(void); + +void netconfig_wifi_notify_power_failed(void); +void netconfig_wifi_notify_power_completed(gboolean power_on); +void netconfig_wifi_update_power_state(gboolean powered); + +char *netconfig_wifi_get_favorite_service(void); + +void netconfig_wifi_check_network_notification(void); + +void netconfig_wifi_state_notifier_cleanup(void); +void netconfig_wifi_state_notifier_register( + struct netconfig_wifi_state_notifier *notifier); +void netconfig_wifi_state_notifier_unregister( + struct netconfig_wifi_state_notifier *notifier); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_STATE_H__ */ diff --git a/wearable/include/wifi-wps.h b/wearable/include/wifi-wps.h new file mode 100644 index 0000000..f08f544 --- /dev/null +++ b/wearable/include/wifi-wps.h @@ -0,0 +1,41 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_WPS_H__ +#define __NETCONFIG_WIFI_WPS_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "wifi.h" + +gboolean netconfig_wifi_is_wps_enabled(void); + +void netconfig_wifi_wps_signal_scandone(void); +void netconfig_wifi_wps_signal_scanaborted(void); + +gboolean netconfig_iface_wifi_request_wps_scan( + NetconfigWifi *wifi, GError **error); + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_WPS_H__ */ diff --git a/wearable/include/wifi.h b/wearable/include/wifi.h new file mode 100644 index 0000000..0a11d04 --- /dev/null +++ b/wearable/include/wifi.h @@ -0,0 +1,61 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 __NETCONFIG_WIFI_H__ +#define __NETCONFIG_WIFI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +G_BEGIN_DECLS + +typedef struct NetconfigWifi NetconfigWifi; +typedef struct NetconfigWifiClass NetconfigWifiClass; + +#define NETCONFIG_TYPE_WIFI ( netconfig_wifi_get_type() ) +#define NETCONFIG_WIFI(obj) \ + ( G_TYPE_CHECK_INSTANCE_CAST((obj), NETCONFIG_TYPE_WIFI, NetconfigWifi) ) +#define NETCONFIG_IS_WIFI(obj) \ + ( G_TYPE_CHECK_INSTANCE_TYPE((obj), NETCONFIG_TYPE_WIFI) ) + +#define NETCONFIG_WIFI_CLASS(klass) \ + ( G_TYPE_CHECK_CLASS_CAST((klass), NETCONFIG_TYPE_WIFI, \ + NetconfigWifiClass) ) +#define NETCONFIG_IS_WIFI_CLASS(klass) \ + ( G_TYPE_CHECK_CLASS_TYPE((klass), NETCONFIG_TYPE_WIFI) ) +#define NETCONFIG_WIFI_GET_CLASS(obj) \ + ( G_TYPE_INSTANCE_GET_CLASS((obj), NETCONFIG_TYPE_WIFI, \ + NetconfigWifiClass) ) + +GType netconfig_wifi_get_type(void); + +gpointer netconfig_wifi_create_and_init(DBusGConnection *connection); + +G_END_DECLS + +#ifdef __cplusplus +} +#endif + +#endif /* __NETCONFIG_WIFI_H__ */ diff --git a/wearable/interfaces/netconfig-iface-network-state.xml b/wearable/interfaces/netconfig-iface-network-state.xml new file mode 100644 index 0000000..061560f --- /dev/null +++ b/wearable/interfaces/netconfig-iface-network-state.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/wearable/interfaces/netconfig-iface-network-statistics.xml b/wearable/interfaces/netconfig-iface-network-statistics.xml new file mode 100644 index 0000000..8935ae9 --- /dev/null +++ b/wearable/interfaces/netconfig-iface-network-statistics.xml @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wearable/interfaces/netconfig-iface-wifi.xml b/wearable/interfaces/netconfig-iface-wifi.xml new file mode 100644 index 0000000..079ac51 --- /dev/null +++ b/wearable/interfaces/netconfig-iface-wifi.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wearable/net-config.manifest b/wearable/net-config.manifest new file mode 100644 index 0000000..6746fed --- /dev/null +++ b/wearable/net-config.manifest @@ -0,0 +1,48 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/wearable/resources/etc/dbus-1/system.d/net-config.conf b/wearable/resources/etc/dbus-1/system.d/net-config.conf new file mode 100644 index 0000000..cb73052 --- /dev/null +++ b/wearable/resources/etc/dbus-1/system.d/net-config.conf @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/wearable/resources/etc/resolv.conf b/wearable/resources/etc/resolv.conf new file mode 100644 index 0000000..6c6c5d4 --- /dev/null +++ b/wearable/resources/etc/resolv.conf @@ -0,0 +1,6 @@ +# Generated by Connection Manager +nameserver 127.0.0.1 +#nameserver ::1 + +options timeout:5 +options attempts:8 diff --git a/wearable/resources/etc/wifi/ccode.conf b/wearable/resources/etc/wifi/ccode.conf new file mode 100644 index 0000000..02c0bdb --- /dev/null +++ b/wearable/resources/etc/wifi/ccode.conf @@ -0,0 +1,237 @@ +#This group is for mcc to country code mapping. +[mcc_iso_map] + +202=gr +204=nl +206=be +208=fr +212=mc +213=ad +214=es +216=hu +218=ba +219=hr +220=rs +222=it +225=va +226=ro +228=ch +230=cz +231=sk +232=at +234=gb +235=gb +238=dk +240=se +242=no +244=fi +246=lt +247=lv +248=ee +250=ru +255=ua +257=by +259=md +260=pl +262=de +266=gi +268=pt +270=lu +272=ie +274=is +276=al +278=mt +280=cy +282=ge +283=am +284=bg +286=tr +288=fo +289=ge +290=gl +292=sm +293=si +294=mk +295=li +297=me +302=ca +308=pm +310=us +311=us +312=us +313=us +314=us +315=us +316=us +330=pr +332=vi +334=mx +338=jm +340=gp +342=bb +344=ag +346=ky +348=vg +350=bm +352=gd +354=ms +356=kn +358=lc +360=vc +362=ai +363=aw +364=bs +365=ai +366=dm +368=cu +370=do +372=ht +374=tt +376=tc +400=az +401=kz +402=bt +404=in +405=in +410=pk +412=af +413=lk +414=mm +415=lb +416=jo +417=sy +418=iq +419=kw +420=sa +421=ye +422=om +423=ps +424=ae +425=il +426=bh +427=qa +428=mn +429=np +430=ae +431=ae +432=ir +434=uz +436=tj +437=kg +438=tm +440=jp +441=jp +450=kr +452=vn +454=hk +455=mo +456=kh +457=la +460=cn +461=cn +466=tw +467=kp +470=bd +472=mv +502=my +505=au +510=id +514=tl +515=ph +520=th +525=sg +528=bn +530=nz +534=mp +535=gu +536=nr +537=pg +539=to +540=sb +541=vu +542=fj +543=wf +544=as +545=ki +546=nc +547=pf +548=ck +549=ws +550=fm +551=mh +552=pw +602=eg +603=dz +604=ma +605=tn +606=ly +607=gm +608=sn +609=mr +610=ml +611=gn +612=ci +613=bf +614=ne +615=tg +616=bj +617=mu +618=lr +619=sl +620=gh +621=ng +622=td +623=cf +624=cm +625=cv +626=st +627=gq +628=ga +629=cg +630=cg +631=ao +632=gw +633=sc +634=sd +635=rw +636=et +637=so +638=dj +639=ke +640=tz +641=ug +642=bi +643=mz +645=zm +646=mg +647=re +648=zw +649=na +650=mw +651=ls +652=bw +653=sz +654=km +655=za +657=er +702=bz +704=gt +706=sv +708=hn +710=ni +712=cr +714=pa +716=pe +722=ar +724=br +730=cl +732=co +734=ve +736=bo +738=gy +740=ec +742=gf +744=py +746=sr +748=uy +750=fk diff --git a/wearable/resources/opt/etc/dump.d/module.d/network_log_dump.sh b/wearable/resources/opt/etc/dump.d/module.d/network_log_dump.sh new file mode 100755 index 0000000..61d980d --- /dev/null +++ b/wearable/resources/opt/etc/dump.d/module.d/network_log_dump.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +#-------------------------------------- +# network +#-------------------------------------- + +export DISPLAY=:0.0 +NETWORK_DEBUG=$1/network + +/bin/mkdir -p ${NETWORK_DEBUG} + +/sbin/ifconfig > ${NETWORK_DEBUG}/ifconfig +/bin/netstat -na > ${NETWORK_DEBUG}/netstat +/sbin/route -n > ${NETWORK_DEBUG}/route +/bin/cat /etc/resolv.conf > ${NETWORK_DEBUG}/resolv.conf +/usr/bin/vconftool get memory/dnet >> ${NETWORK_DEBUG}/status +/usr/bin/vconftool get memory/wifi >> ${NETWORK_DEBUG}/status +/usr/bin/vconftool get file/private/wifi >> ${NETWORK_DEBUG}/status +/usr/bin/vconftool get db/wifi >> ${NETWORK_DEBUG}/status +/sbin/ifconfig -a > ${NETWORK_DEBUG}/ifconfig diff --git a/wearable/resources/usr/lib/systemd/system/net-config.service b/wearable/resources/usr/lib/systemd/system/net-config.service new file mode 100644 index 0000000..47e2324 --- /dev/null +++ b/wearable/resources/usr/lib/systemd/system/net-config.service @@ -0,0 +1,13 @@ +[Unit] +Description=Network Configuration service +After=tizen-system.target + +[Service] +Type=dbus +BusName=net.netconfig +RemainAfterExit=yes +ExecStartPre=/usr/sbin/net-config.service +ExecStart=/usr/sbin/net-config + +[Install] +WantedBy=multi-user.target diff --git a/wearable/resources/usr/sbin/net-config.service b/wearable/resources/usr/sbin/net-config.service new file mode 100755 index 0000000..9e899dc --- /dev/null +++ b/wearable/resources/usr/sbin/net-config.service @@ -0,0 +1,23 @@ +#!/bin/sh + +bssid="$(/usr/bin/vconftool -t string get db/wifi/bssid_address | /bin/sed -n "/\([0-9A-F][0-9A-F]:\)\{5\}[0-9A-F][0-9A-F]/p")" +if [ "$bssid" = "" ]; then + if [ -f /opt/etc/.mac.info ]; then + /bin/cat /opt/etc/.mac.info | /bin/sed -n "/^\([0-9A-F][0-9A-F]:\)\{5\}[0-9A-F][0-9A-F]$/p" | /usr/bin/xargs /usr/bin/vconftool set -t string db/wifi/bssid_address -f + fi +fi + +if [ ! -d /var/lib/net-config ]; then + /bin/mkdir -p /var/lib/net-config +fi + +if [ ! -f /var/lib/net-config/.provisioned ]; then + /bin/touch /var/lib/net-config/.provisioned +fi + +if [ ! -d /var/lib/wifi ]; then + /bin/mkdir -p /var/lib/wifi +fi + +/bin/rm /var/lib/wifi/.pseudonym.info +/bin/rm /var/lib/wifi/.pseudonym_sim.info diff --git a/wearable/resources/usr/share/dbus-1/services/net.netconfig.service b/wearable/resources/usr/share/dbus-1/services/net.netconfig.service new file mode 100644 index 0000000..6d497a1 --- /dev/null +++ b/wearable/resources/usr/share/dbus-1/services/net.netconfig.service @@ -0,0 +1,4 @@ +[D-BUS Service] +Name=net.netconfig +Exec=/usr/sbin/net-config +User=root diff --git a/wearable/resources/usr/share/wifi_offloading.sql b/wearable/resources/usr/share/wifi_offloading.sql new file mode 100644 index 0000000..3c3edb5 --- /dev/null +++ b/wearable/resources/usr/share/wifi_offloading.sql @@ -0,0 +1,18 @@ +PRAGMA journal_mode = PERSIST; + +DROP TABLE IF EXISTS "connected_wifi"; +CREATE TABLE connected_wifi( + wifi_id INTEGER PRIMARY KEY, + ssid TEXT +); + +DROP TABLE IF EXISTS "related_cell"; +CREATE TABLE related_cell( + cell_id INTEGER, + registered INTEGER, + max_rscp INTEGER, + min_rscp INTEGER, + wifi_id INTEGER +); + +CREATE INDEX related_cell_ix_1 ON related_cell (wifi_id); diff --git a/wearable/src/cellular-state.c b/wearable/src/cellular-state.c new file mode 100644 index 0000000..43c1de5 --- /dev/null +++ b/wearable/src/cellular-state.c @@ -0,0 +1,80 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "cellular-state.h" + +static enum netconfig_cellular_service_state + cellular_service_state = NETCONFIG_CELLULAR_UNKNOWN; + +static GSList *notifier_list = NULL; + +static void __netconfig_cellular_state_changed( + enum netconfig_cellular_service_state state) +{ + GSList *list; + + for (list = notifier_list; list; list = list->next) { + struct netconfig_cellular_state_notifier *notifier = list->data; + + if (notifier->netconfig_cellular_state_changed != NULL) + notifier->netconfig_cellular_state_changed(state, notifier->user_data); + } +} + +void netconfig_cellular_state_set_service_state( + enum netconfig_cellular_service_state new_state) +{ + enum netconfig_cellular_service_state old_state = cellular_service_state; + + if (old_state == new_state) + return; + + cellular_service_state = new_state; + DBG("Cellular state %d ==> %d", old_state, new_state); + __netconfig_cellular_state_changed(new_state); +} + +enum netconfig_cellular_service_state +netconfig_cellular_state_get_service_state(void) +{ + return cellular_service_state; +} + +void netconfig_cellular_state_notifier_cleanup(void) +{ + g_slist_free_full(notifier_list, NULL); +} + +void netconfig_cellular_state_notifier_register( + struct netconfig_cellular_state_notifier *notifier) +{ + DBG("register notifier"); + + notifier_list = g_slist_append(notifier_list, notifier); +} + +void netconfig_cellular_state_notifier_unregister( + struct netconfig_cellular_state_notifier *notifier) +{ + DBG("un-register notifier"); + + notifier_list = g_slist_remove_all(notifier_list, notifier); +} diff --git a/wearable/src/dbus/netdbus.c b/wearable/src/dbus/netdbus.c new file mode 100644 index 0000000..fcf1fa3 --- /dev/null +++ b/wearable/src/dbus/netdbus.c @@ -0,0 +1,502 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "netdbus.h" + +#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000) + +#define DBUS_PARAM_TYPE_STRING "string" +#define DBUS_PARAM_TYPE_INT16 "int16" +#define DBUS_PARAM_TYPE_UINT16 "uint16" +#define DBUS_PARAM_TYPE_INT32 "int32" +#define DBUS_PARAM_TYPE_UINT32 "uint32" +#define DBUS_PARAM_TYPE_INT64 "int64" +#define DBUS_PARAM_TYPE_UINT64 "uint64" +#define DBUS_PARAM_TYPE_DOUBLE "double" +#define DBUS_PARAM_TYPE_BYTE "byte" +#define DBUS_PARAM_TYPE_BOOLEAN "boolean" +#define DBUS_PARAM_TYPE_OBJECT_PATH "objpath" +#define DBUS_PARAM_TYPE_VARIANT "variant" +#define DBUS_PARAM_TYPE_ARRAY "array" + + +static gboolean __netconfig_dbus_append_param_variant( + DBusMessageIter *iter, char *type, char *param) +{ + DBusMessageIter value, array; + char *args = NULL, *ch = NULL; + dbus_bool_t b_value = FALSE; + + if (strcmp(type, DBUS_PARAM_TYPE_STRING) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_STRING_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, ¶m); + + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(type, DBUS_PARAM_TYPE_BOOLEAN) == 0) { + if (strcmp(param, "true") == 0) { + b_value = TRUE; + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_BOOLEAN_AS_STRING, &value); + dbus_message_iter_append_basic(&value, + DBUS_TYPE_BOOLEAN, &b_value); + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(param, "false") == 0) { + b_value = FALSE; + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_BOOLEAN_AS_STRING, &value); + dbus_message_iter_append_basic(&value, + DBUS_TYPE_BOOLEAN, &b_value); + dbus_message_iter_close_container(iter, &value); + } else { + ERR("Error!!! Expected \"true\" or" + "\"false\" instead of \"%s\"", ch); + return FALSE; + } + } else if (strcmp(type, DBUS_PARAM_TYPE_OBJECT_PATH) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_OBJECT_PATH_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_OBJECT_PATH, ¶m); + + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(type, DBUS_PARAM_TYPE_ARRAY) == 0) { + args = param; + ch = strchr(args, ':'); + if (ch == NULL) { + ERR("Invalid data format[\"%s\"]", args); + return FALSE; + } + *ch = 0; ch++; + + if (strcmp(args, DBUS_PARAM_TYPE_STRING) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_STRING_AS_STRING, + &value); + + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + DBUS_TYPE_STRING_AS_STRING, &array); + + dbus_message_iter_append_basic(&array, DBUS_TYPE_STRING, &ch); + + dbus_message_iter_close_container(&value, &array); + + dbus_message_iter_close_container(iter, &value); + } else if (strcmp(args, DBUS_PARAM_TYPE_OBJECT_PATH) == 0) { + dbus_message_iter_open_container(iter, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING DBUS_TYPE_OBJECT_PATH_AS_STRING, + &value); + + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + DBUS_TYPE_OBJECT_PATH_AS_STRING, &array); + + dbus_message_iter_append_basic(&array, DBUS_TYPE_OBJECT_PATH, &ch); + + dbus_message_iter_close_container(&value, &array); + + dbus_message_iter_close_container(iter, &value); + } else { + ERR("Not supported data format[\"%s\"]", args); + return FALSE; + } + } else { + ERR("Not supported data format[\"%s\"]", args); + return FALSE; + } + + return TRUE; +} + +static gboolean __netconfig_dbus_append_param( + DBusMessage *message, char *param_array[]) +{ + int count = 0; + dbus_int16_t int16 = 0; + dbus_uint16_t uint16 = 0; + dbus_int32_t int32 = 0; + dbus_uint32_t uint32 = 0; + dbus_int64_t int64 = 0; + dbus_uint64_t uint64 = 0; + DBusMessageIter iter; + char *args = NULL, *ch = NULL; + + if (param_array == NULL) + return TRUE; + + dbus_message_iter_init_append(message, &iter); + + while (param_array[count] != NULL) { + args = param_array[count]; + + DBG("parameter [%s]", param_array[count]); + + ch = strchr(args, ':'); + if (ch == NULL) { + ERR("Invalid parameter[\"%s\"]", args); + return FALSE; + } + *ch = '\0'; ch++; + + if (strcmp(args, DBUS_PARAM_TYPE_STRING) == 0) { + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &ch); + } else if (strcmp(args, DBUS_PARAM_TYPE_INT16) == 0) { + int16 = (dbus_int16_t)strtol(ch, NULL, 0); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT16, &int16); + } else if (strcmp(args, DBUS_PARAM_TYPE_UINT16) == 0) { + uint16 = (dbus_uint16_t)strtoul(ch, NULL, 0); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT16, &uint16); + } else if (strcmp(args, DBUS_PARAM_TYPE_INT32) == 0) { + int32 = strtol(ch, NULL, 0); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT32, &int32); + } else if (strcmp(args, DBUS_PARAM_TYPE_UINT32) == 0) { + uint32 = strtoul(ch, NULL, 0); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT32, &uint32); + } else if (strcmp(args, DBUS_PARAM_TYPE_INT64) == 0) { + int64 = strtoq(ch, NULL, 0); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_INT64, &int64); + } else if (strcmp(args, DBUS_PARAM_TYPE_UINT64) == 0) { + uint64 = strtouq(ch, NULL, 0); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_UINT64, &uint64); + } else if (strcmp(args, DBUS_PARAM_TYPE_VARIANT) == 0) { + args = ch; + ch = strchr(args, ':'); + if (ch == NULL) { + ERR("Invalid data format[\"%s\"]", args); + return FALSE; + } + *ch = 0; ch++; + + if (__netconfig_dbus_append_param_variant(&iter, args, ch) != TRUE) + return FALSE; + } else if (strcmp(args, DBUS_PARAM_TYPE_OBJECT_PATH) == 0) { + dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &ch); + } else { + ERR("Not supported data format[\"%s\"]", args); + return FALSE; + } + + count++; + } + + return TRUE; +} + +gboolean netconfig_dbus_get_basic_params_string(DBusMessage *message, + char **key, int type, void *value) +{ + DBusMessageIter iter, iter_variant; + + dbus_message_iter_init(message, &iter); + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_STRING) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&iter)); + return FALSE; + } + + dbus_message_iter_get_basic(&iter, key); + + if (value == NULL) + return TRUE; + + dbus_message_iter_next(&iter); + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_VARIANT) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&iter)); + return TRUE; + } + + dbus_message_iter_recurse(&iter, &iter_variant); + if (dbus_message_iter_get_arg_type(&iter_variant) != type) + return FALSE; + + dbus_message_iter_get_basic(&iter_variant, value); + + return TRUE; +} + +gboolean netconfig_dbus_get_basic_params_array(DBusMessage *message, + const char *key, void **value) +{ + int type = 0; + gboolean find = FALSE; + const char *arg = NULL; + DBusMessageIter args, dict, entry, variant; + + if (key == NULL || value == NULL) + return FALSE; + + /* read parameters */ + if (dbus_message_iter_init(message, &args) == FALSE) { + DBG("Message does not have parameters"); + return FALSE; + } + + if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_ARRAY) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&args)); + return FALSE; + } + + dbus_message_iter_recurse(&args, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&dict, &entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&entry)); + return FALSE; + } + + dbus_message_iter_get_basic(&entry, &arg); + + if (g_strcmp0(key, arg) != 0) { + dbus_message_iter_next(&dict); + continue; + } + + dbus_message_iter_next(&entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) { + DBG("Argument type %d", dbus_message_iter_get_arg_type(&entry)); + return FALSE; + } + + dbus_message_iter_recurse(&entry, &variant); + + type = dbus_message_iter_get_arg_type(&variant); + if (type == DBUS_TYPE_STRING) { + find = TRUE; + dbus_message_iter_get_basic(&variant, value); + } else if (type == DBUS_TYPE_BYTE || type == DBUS_TYPE_BOOLEAN || + type == DBUS_TYPE_INT16 || type == DBUS_TYPE_UINT16 || + type == DBUS_TYPE_INT32 || type == DBUS_TYPE_UINT32 || + type == DBUS_TYPE_DOUBLE) { + find = TRUE; + dbus_message_iter_get_basic(&variant, *value); + } else + DBG("Argument type %d", type); + + if (find == TRUE) + break; + + dbus_message_iter_next(&dict); + } + + return find; +} + +gboolean netconfig_is_cellular_internet_profile(const char *profile) +{ + const char internet_suffix[] = "_1"; + char *suffix = NULL; + + if (profile == NULL) + return FALSE; + + if (g_str_has_prefix(profile, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) + == TRUE) { + suffix = strrchr(profile, '_'); + if (g_strcmp0(suffix, internet_suffix) == 0) + return TRUE; + } + + return FALSE; +} + +gboolean netconfig_is_cellular_profile(const char *profile) +{ + if (profile == NULL) + return FALSE; + + return g_str_has_prefix(profile, CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX); +} + +gboolean netconfig_is_wifi_profile(const char *profile) +{ + if (profile == NULL) + return FALSE; + + return g_str_has_prefix(profile, CONNMAN_WIFI_SERVICE_PROFILE_PREFIX); +} + +gboolean netconfig_invoke_dbus_method_nonblock( + const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[], + DBusPendingCallNotifyFunction notify_func) +{ + dbus_bool_t result; + DBusPendingCall *call; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + + DBG("[DBUS Async] %s %s %s", interface_name, method, path); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + + return FALSE; + } + + message = dbus_message_new_method_call(dest, path, interface_name, method); + if (message == NULL) { + ERR("Failed DBus method call"); + + dbus_connection_unref(connection); + + return FALSE; + } + + if (__netconfig_dbus_append_param(message, param_array) == FALSE) { + ERR("Failed to append DBus params"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return FALSE; + } + + result = dbus_connection_send_with_reply(connection, message, &call, + NETCONFIG_DBUS_REPLY_TIMEOUT); + + if (result != TRUE || call == NULL) { + ERR("dbus_connection_send_with_reply() failed."); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return FALSE; + } + + if (notify_func == NULL) + dbus_pending_call_cancel(call); + else + dbus_pending_call_set_notify(call, notify_func, NULL, NULL); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return TRUE; +} + +DBusMessage *netconfig_invoke_dbus_method(const char *dest, const char *path, + const char *interface_name, const char *method, char *param_array[]) +{ + DBusError error; + DBusMessage *reply = NULL; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + + DBG("[DBUS Sync] %s %s %s", interface_name, method, path); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + + return NULL; + } + + message = dbus_message_new_method_call(dest, path, interface_name, method); + if (message == NULL) { + ERR("Failed DBus method call"); + + dbus_connection_unref(connection); + + return NULL; + } + + if (__netconfig_dbus_append_param(message, param_array) == FALSE) { + ERR("Failed to append DBus params"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return NULL; + } + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + NETCONFIG_DBUS_REPLY_TIMEOUT, &error); + + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + ERR("dbus_connection_send_with_reply_and_block() failed. " + "DBus error [%s: %s]", error.name, error.message); + + dbus_error_free(&error); + } else + ERR("Failed to get properties"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return NULL; + } + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return reply; +} + +DBusGConnection *netconfig_setup_dbus(void) +{ + guint rv = 0; + DBusGProxy *proxy; + GError *error = NULL; + DBusGConnection* connection = NULL; + + connection = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + ERR("Fail to get DBus(%s)", error->message); + g_error_free(error); + return connection; + } + + proxy = dbus_g_proxy_new_for_name(connection, "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus"); + + if (!dbus_g_proxy_call(proxy, "RequestName", &error, + G_TYPE_STRING, NETCONFIG_SERVICE, G_TYPE_UINT, 0, + G_TYPE_INVALID, G_TYPE_UINT, &rv, + G_TYPE_INVALID)) { + ERR("Failed to acquire service(%s) error(%s)", + NETCONFIG_SERVICE, error->message); + g_error_free(error); + + dbus_g_connection_unref(connection); + + return NULL; + } + + if (rv != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + ERR("Service name is already in use"); + + dbus_g_connection_unref(connection); + + return NULL; + } + + return connection; +} diff --git a/wearable/src/dbus/netsupplicant.c b/wearable/src/dbus/netsupplicant.c new file mode 100644 index 0000000..281ad64 --- /dev/null +++ b/wearable/src/dbus/netsupplicant.c @@ -0,0 +1,355 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "netdbus.h" +#include "netsupplicant.h" + +#define DBUS_OBJECT_PATH_MAX 150 +#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000) + +static void setup_dbus_args(gpointer data, gpointer user_data) +{ + DBusMessageIter *iter; + struct dbus_input_arguments *args; + + if (data == NULL || user_data == NULL) + return; + + iter = (DBusMessageIter *) user_data; + args = (struct dbus_input_arguments *)data; + if (args->data == NULL) + return; + + switch (args->type) { + case DBUS_TYPE_STRING: + case DBUS_TYPE_OBJECT_PATH: + DBG("parameter [%s]", args->data); + dbus_message_iter_append_basic(iter, args->type, &(args->data)); + break; + case DBUS_TYPE_BOOLEAN: + case DBUS_TYPE_UINT32: + case DBUS_TYPE_INT32: + DBG("parameter [%d]", args->data); + dbus_message_iter_append_basic(iter, args->type, args->data); + break; + case DBUS_TYPE_INVALID: + default: + return; + } +} + +GList *setup_input_args(GList *list, struct dbus_input_arguments *items) +{ + struct dbus_input_arguments *iter = items; + + if (iter == NULL) + return NULL; + + while (iter->data) { + list = g_list_append(list, iter); + iter++; + } + + return list; +} + +const char *netconfig_wifi_get_supplicant_interface(void) +{ + GList *input_args = NULL; + DBusMessage *message = NULL; + struct dbus_input_arguments args[] = { + {DBUS_TYPE_STRING, WIFI_IFNAME}, + {DBUS_TYPE_INVALID, NULL} + }; + const char *path; + static char obj_path[DBUS_OBJECT_PATH_MAX] = { '\0', }; + + if (obj_path[0] != '\0') + return (const char *)obj_path; + + input_args = setup_input_args(input_args, args); + + message = netconfig_supplicant_invoke_dbus_method( + SUPPLICANT_SERVICE, SUPPLICANT_PATH, + SUPPLICANT_INTERFACE, "GetInterface", input_args); + + g_list_free(input_args); + + if (message == NULL) + return NULL; + + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { + const char *err_msg = dbus_message_get_error_name(message); + ERR("Error!!! Error message received %s", err_msg); + goto error; + } + + dbus_message_get_args(message, NULL, DBUS_TYPE_OBJECT_PATH, &path, + DBUS_TYPE_INVALID); + + g_strlcpy(obj_path, path, DBUS_OBJECT_PATH_MAX); + + dbus_message_unref(message); + + return (const char *)obj_path; + +error: + if (message != NULL) + dbus_message_unref(message); + + return NULL; +} + +DBusMessage *netconfig_supplicant_invoke_dbus_method(const char *dest, + const char *path, const char *interface_name, + const char *method, GList *args) +{ + DBusError error; + DBusMessageIter iter; + DBusMessage *reply = NULL; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + +// DBG("[DBUS Sync] %s %s %s", interface_name, method, path); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + return NULL; + } + + message = dbus_message_new_method_call(dest, path, interface_name, method); + if (message == NULL) { + ERR("Failed DBus method call"); + dbus_connection_unref(connection); + return NULL; + } + + dbus_message_iter_init_append(message, &iter); + + if (args != NULL) + g_list_foreach(args, setup_dbus_args, (gpointer)&iter); + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + NETCONFIG_DBUS_REPLY_TIMEOUT, &error); + + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + ERR("dbus_connection_send_with_reply_and_block() failed. " + "DBus error [%s: %s]", error.name, error.message); + + dbus_error_free(&error); + } else + ERR("Failed to get properties"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return NULL; + } + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return reply; +} + +dbus_bool_t netconfig_supplicant_invoke_dbus_method_nonblock(const char *dest, + const char *path, const char *interface_name, + const char *method, GList *args, + DBusPendingCallNotifyFunction notify_func) +{ + dbus_bool_t result = FALSE; + DBusMessageIter iter; + DBusPendingCall *call; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + + DBG("[DBUS Async] %s %s %s", interface_name, method, path); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + return result; + } + + message = dbus_message_new_method_call(dest, path, interface_name, method); + if (message == NULL) { + ERR("Failed DBus method call"); + dbus_connection_unref(connection); + return result; + } + + dbus_message_iter_init_append(message, &iter); + + if (args != NULL) + g_list_foreach(args, setup_dbus_args, (gpointer)&iter); + + result = dbus_connection_send_with_reply(connection, message, &call, + NETCONFIG_DBUS_REPLY_TIMEOUT); + if (result == FALSE || call == NULL) { + ERR("dbus_connection_send_with_reply() failed"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return result; + } + + if (notify_func == NULL) + dbus_pending_call_cancel(call); + else + dbus_pending_call_set_notify(call, notify_func, NULL, NULL); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return result; +} + +DBusMessage *netconfig_supplicant_invoke_dbus_interface_property_get(const char *interface, + const char *key) +{ + DBusError error; + DBusMessage *reply = NULL; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + const char *path; + + ERR("[DBUS] property_get : %s", key); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + return NULL; + } + + path = netconfig_wifi_get_supplicant_interface(); + if (path == NULL) { + DBG("Failed to get wpa_supplicant DBus path"); + dbus_connection_unref(connection); + return NULL; + } + + message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path, + DBUS_INTERFACE_PROPERTIES, "Get"); + if (message == NULL) { + ERR("Failed DBus method call"); + dbus_connection_unref(connection); + return NULL; + } + + dbus_message_append_args(message, DBUS_TYPE_STRING, &interface, + DBUS_TYPE_STRING, &key, NULL); + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + NETCONFIG_DBUS_REPLY_TIMEOUT, &error); + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + ERR("dbus_connection_send_with_reply_and_block() failed. " + "DBus error [%s: %s]", error.name, error.message); + + dbus_error_free(&error); + } else + ERR("Failed to get properties"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return NULL; + } + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return reply; +} + +dbus_bool_t netconfig_supplicant_invoke_dbus_interface_property_set(const char *interface, + const char *key, const char *type, GList *args, + DBusPendingCallNotifyFunction notify_func) +{ + dbus_bool_t result = FALSE; + DBusPendingCall *call; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + DBusMessageIter iter, value; + const char *path; + + DBG("[DBUS] property_set : %s", key); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + return result; + } + + path = netconfig_wifi_get_supplicant_interface(); + if (path == NULL) { + ERR("Failed to get wpa_supplicant DBus path"); + dbus_connection_unref(connection); + return result; + } + + message = dbus_message_new_method_call(SUPPLICANT_SERVICE, path, + DBUS_INTERFACE_PROPERTIES, "Set"); + if (message == NULL) { + ERR("Failed DBus method call"); + dbus_connection_unref(connection); + return result; + } + + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &interface); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_STRING, &key); + + dbus_message_iter_open_container(&iter, DBUS_TYPE_VARIANT, + type, &value); + + if (args != NULL) + g_list_foreach(args, setup_dbus_args, (gpointer)&value); + + dbus_message_iter_close_container(&iter, &value); + + result = dbus_connection_send_with_reply(connection, message, &call, + NETCONFIG_DBUS_REPLY_TIMEOUT); + if (result == FALSE || call == NULL) { + ERR("dbus_connection_send_with_reply() failed"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return result; + } + + if (notify_func == NULL) + dbus_pending_call_cancel(call); + else + dbus_pending_call_set_notify(call, notify_func, NULL, NULL); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return result; +} diff --git a/wearable/src/main.c b/wearable/src/main.c new file mode 100644 index 0000000..0f5be75 --- /dev/null +++ b/wearable/src/main.c @@ -0,0 +1,84 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "wifi.h" +#include "netdbus.h" +#include "emulator.h" +#include "neterror.h" +#include "wifi-agent.h" +#include "wifi-power.h" +#include "network-clock.h" +#include "network-state.h" +#include "signal-handler.h" +#include "network-statistics.h" + +static GMainLoop *main_loop = NULL; + +int main(int argc, char *argv[]) +{ + DBusGConnection *connection; + + umask(0077); + + DBG("Network Configuration service"); + + if (daemon(0, 0) != 0) + DBG("Cannot start daemon"); + + g_type_init(); + + main_loop = g_main_loop_new(NULL, FALSE); + + connection = netconfig_setup_dbus(); + if (connection == NULL) + return -1; + + netconfig_register_signal(); + + netconfig_agent_register(); + + if (netconfig_wifi_create_and_init(connection) == NULL) + return -1; + + if (netconfig_network_state_create_and_init(connection) == NULL) + return -1; + + if (netconfig_network_statistics_create_and_init(connection) == NULL) + return -1; + + netconfig_error_init(); + + /* If its environment uses Emulator, network configuration is set by emulator default */ + netconfig_emulator_test_and_start(); + + g_main_loop_run(main_loop); + + netconfig_deregister_signal(); + + netconfig_wifi_state_notifier_cleanup(); + + /* Unregistering the agent */ + netconfig_agent_unregister(); + + return 0; +} diff --git a/wearable/src/neterror.c b/wearable/src/neterror.c new file mode 100644 index 0000000..e31b5c1 --- /dev/null +++ b/wearable/src/neterror.c @@ -0,0 +1,157 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "netdbus.h" +#include "neterror.h" + +typedef enum { + NETCONFIG_NO_ERROR = 0x00, + NETCONFIG_ERROR_INTERNAL = 0x01, + NETCONFIG_ERROR_NO_SERVICE = 0x02, + NETCONFIG_ERROR_TRASPORT = 0x03, + NETCONFIG_ERROR_NO_PROFILE = 0x04, + NETCONFIG_ERROR_WRONG_PROFILE = 0x05, + NETCONFIG_ERROR_INPROGRESS = 0x06, + NETCONFIG_ERROR_ALREADYEXISTS = 0x07, + NETCONFIG_ERROR_INVALID_PARAMETER = 0x08, + NETCONFIG_ERROR_PERMISSION_DENIED = 0x09, + NETCONFIG_ERROR_WIFI_DRIVER_FAILURE = 0x0A, + NETCONFIG_ERROR_FAILED_GET_IMSI = 0x0B, + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH = 0x0C, + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM = 0x0D, + NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA = 0x0E, + NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY = 0x0F, + NETCONFIG_ERROR_MAX = 0x10, +} NETCONFIG_ERROR; + +#define NETCONFIG_ERROR_INTERFACE NETCONFIG_SERVICE ".Error" +#define CONNMAN_AGENT_ERROR_INTERFACE "net.connman.Agent.Error" + +GQuark netconfig_error_quark(void) +{ + static GQuark quark = 0; + + if (!quark) + quark = g_quark_from_static_string("netconfig_error"); + + return quark; +} + +GQuark netconfig_connman_agent_error_quark(void) +{ + static GQuark quark = 0; + + if (!quark) + quark = g_quark_from_static_string("netconfig_connman_agent_error"); + + return quark; +} + +void netconfig_error_inprogress(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_INPROGRESS, + NETCONFIG_ERROR_INTERFACE ".InProgress"); +} + +void netconfig_error_already_exists(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_ALREADYEXISTS, + NETCONFIG_ERROR_INTERFACE ".AlreadyExists"); +} + +void netconfig_error_invalid_parameter(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_INVALID_PARAMETER, + NETCONFIG_ERROR_INTERFACE ".InvalidParameter"); +} + +void netconfig_error_permission_denied(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_PERMISSION_DENIED, + NETCONFIG_ERROR_INTERFACE ".PermissionDenied"); +} + +void netconfig_error_wifi_driver_failed(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_WIFI_DRIVER_FAILURE, + NETCONFIG_ERROR_INTERFACE ".WifiDriverFailed"); +} + +void netconfig_error_wifi_direct_failed(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_WIFI_DRIVER_FAILURE, + NETCONFIG_ERROR_INTERFACE ".WifiDirectFailed"); +} + +void netconfig_error_fail_get_imsi(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_FAILED_GET_IMSI, + NETCONFIG_ERROR_INTERFACE".FailGetSimImsi"); +} + +void netconfig_error_fail_req_sim_auth(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH, + NETCONFIG_ERROR_INTERFACE".FailReqSimAuth"); +} + +void netconfig_error_fail_req_sim_auth_wrong_param(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_FAILED_REQ_SIM_AUTH_WRONG_PARAM, + NETCONFIG_ERROR_INTERFACE".FailReqSimAuthWrongParam"); +} + +void netconfig_error_fail_get_sim_auth_wrong_data(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_WRONG_DATA, + NETCONFIG_ERROR_INTERFACE".FailGetSimAuthWrongData"); +} + +void netconfig_error_fail_get_sim_auth_delay(GError **error) +{ + g_set_error(error, netconfig_error_quark(), + NETCONFIG_ERROR_FAILED_GET_SIM_AUTH_DELAY, + NETCONFIG_ERROR_INTERFACE".FailGetSimAuthDelay"); +} + +void netconfig_error_init(void) +{ + /* TODO: register GError domain to make error_name */ + /* + dbus_g_error_domain_register(NETCONFIG_ERROR_QUARK, + NETCONFIG_ERROR_INTERFACE, + code_num_netconfig); + + dbus_g_error_domain_register(NETCONFIG_CONNMAN_AGENT_ERROR_QUARK, + CONNMAN_AGENT_ERROR_INTERFACE, + code_num_connman); + */ +} diff --git a/wearable/src/network-clock.c b/wearable/src/network-clock.c new file mode 100644 index 0000000..68ac748 --- /dev/null +++ b/wearable/src/network-clock.c @@ -0,0 +1,117 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-state.h" + +#define NTP_SERVER "pool.ntp.org" +#define CONNMAN_GLOBAL_SETTING "/var/lib/connman/settings" + +static void __netconfig_clock_clear_timeserver(void) +{ + GKeyFile *keyfile = NULL; + + keyfile = netconfig_keyfile_load(CONNMAN_GLOBAL_SETTING); + + if (keyfile == NULL) + return; + + g_key_file_remove_key(keyfile, "global", "Timeservers", NULL); + + netconfig_keyfile_save(keyfile, CONNMAN_GLOBAL_SETTING); +} + +static gboolean __netconfig_clock_clear_timeserver_timer(gpointer data) +{ + INFO("Clear NTP server"); + + __netconfig_clock_clear_timeserver(); + + return FALSE; +} + +static void __netconfig_clock_set_timeserver(const char *server) +{ + DBusMessage* reply = NULL; + char param0[] = "string:Timeservers"; + char *param1 = NULL; + char *param_array[] = { NULL, NULL, NULL }; + + param1 = g_strdup_printf("variant:array:string:%s", server); + + param_array[0] = param0; + param_array[1] = param1; + + reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_CLOCK_INTERFACE, + "SetProperty", param_array); + if (reply == NULL) { + ERR("Failed to configure NTP server"); + + g_free(param1); + return; + } + + g_free(param1); + dbus_message_unref(reply); +} + +static void __netconfig_clock( + enum netconfig_wifi_service_state state, void *user_data) +{ + gboolean automatic_time_update = 0; + guint timeserver_clear_timer = 0; + + if (state != NETCONFIG_WIFI_CONNECTED) + return; + + vconf_get_bool( + VCONFKEY_SETAPPL_STATE_AUTOMATIC_TIME_UPDATE_BOOL, + &automatic_time_update); + + if (automatic_time_update == FALSE) { + INFO("Automatic time update is not set (%d)", automatic_time_update); + return; + } + + __netconfig_clock_set_timeserver((const char *)NTP_SERVER); + + netconfig_start_timer_seconds(5, __netconfig_clock_clear_timeserver_timer, + NULL, ×erver_clear_timer); +} + +static struct netconfig_wifi_state_notifier netconfig_clock_notifier = { + .netconfig_wifi_state_changed = __netconfig_clock, + .user_data = NULL, +}; + +void netconfig_clock_init(void) +{ + netconfig_wifi_state_notifier_register(&netconfig_clock_notifier); +} + +void netconfig_clock_deinit(void) +{ + netconfig_wifi_state_notifier_unregister(&netconfig_clock_notifier); +} diff --git a/wearable/src/network-state.c b/wearable/src/network-state.c new file mode 100644 index 0000000..a93acc5 --- /dev/null +++ b/wearable/src/network-state.c @@ -0,0 +1,1080 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "emulator.h" +#include "wifi-state.h" +#include "wifi-power.h" +#include "network-state.h" +#include "netsupplicant.h" + +/* Define TCP buffer sizes for various networks */ +/* ReadMin, ReadInitial, ReadMax */ /* WriteMin, WriteInitial, WriteMax */ +#define NET_TCP_BUFFERSIZE_DEFAULT_READ "4096 87380 704512" +#define NET_TCP_BUFFERSIZE_DEFAULT_WRITE "4096 16384 110208" +#define NET_TCP_BUFFERSIZE_WIFI_READ "524288 1048576 2560000" +#define NET_TCP_BUFFERSIZE_WIFI_WRITE "524288 1048576 2560000" +#define NET_TCP_BUFFERSIZE_LTE_READ "524288 1048576 2560000" +#define NET_TCP_BUFFERSIZE_LTE_WRITE "524288 1048576 2560000" +#define NET_TCP_BUFFERSIZE_UMTS_READ "4094 87380 704512" +#define NET_TCP_BUFFERSIZE_UMTS_WRITE "4096 16384 110208" +#define NET_TCP_BUFFERSIZE_HSPA_READ "4092 87380 704512" +#define NET_TCP_BUFFERSIZE_HSPA_WRITE "4096 16384 262144" +#define NET_TCP_BUFFERSIZE_HSDPA_READ "4092 87380 704512" +#define NET_TCP_BUFFERSIZE_HSDPA_WRITE "4096 16384 110208" +#define NET_TCP_BUFFERSIZE_HSUPA_READ "4092 87380 704512" +#define NET_TCP_BUFFERSIZE_HSUPA_WRITE "4096 16384 262144" +#define NET_TCP_BUFFERSIZE_HSPAP_READ "4092 87380 704512" +#define NET_TCP_BUFFERSIZE_HSPAP_WRITE "4096 16384 262144" +#define NET_TCP_BUFFERSIZE_EDGE_READ "4093 26280 35040" +#define NET_TCP_BUFFERSIZE_EDGE_WRITE "4096 16384 35040" +#define NET_TCP_BUFFERSIZE_GPRS_READ "4096 30000 30000" +#define NET_TCP_BUFFERSIZE_GPRS_WRITE "4096 8760 11680" + +#define NET_TCP_BUFFERSIZE_WIFI_RMEM_MAX "1048576" +#define NET_TCP_BUFFERSIZE_WIFI_WMEM_MAX "2097152" +#define NET_TCP_BUFFERSIZE_LTE_RMEM_MAX "5242880" + +#define NET_TCP_BUFFERSIZE_WIFID_WMEM_MAX "2097152" + +#define NET_PROC_SYS_NET_IPV4_TCP_RMEM "/proc/sys/net/ipv4/tcp_rmem" +#define NET_PROC_SYS_NET_IPv4_TCP_WMEM "/proc/sys/net/ipv4/tcp_wmem" +#define NET_PROC_SYS_NET_CORE_RMEM_MAX "/proc/sys/net/core/rmem_max" +#define NET_PROC_SYS_NET_CORE_WMEM_MAX "/proc/sys/net/core/wmem_max" + +#define ROUTE_EXEC_PATH "/sbin/route" + + +#define NETCONFIG_NETWORK_STATE_PATH "/net/netconfig/network" + +#define PROP_DEFAULT FALSE +#define PROP_DEFAULT_STR NULL + +gboolean netconfig_iface_network_state_add_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error); + +gboolean netconfig_iface_network_state_remove_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error); + +#include "netconfig-iface-network-state-glue.h" + +enum { + PROP_O, + PROP_NETWORK_STATE_CONN, + PROP_NETWORK_STATE_PATH, +}; + +struct NetconfigNetworkStateClass { + GObjectClass parent; +}; + +struct NetconfigNetworkState { + GObject parent; + + DBusGConnection *connection; + gchar *path; +}; + +G_DEFINE_TYPE(NetconfigNetworkState, netconfig_network_state, G_TYPE_OBJECT); + +static void __netconfig_network_state_gobject_get_property(GObject *object, + guint prop_id, GValue *value, GParamSpec *pspec) +{ + return; +} + +static void __netconfig_network_state_gobject_set_property(GObject *object, + guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NetconfigNetworkState *network_state = NETCONFIG_NETWORK_STATE(object); + + switch (prop_id) { + case PROP_NETWORK_STATE_CONN: + { + network_state->connection = g_value_get_boxed(value); + break; + } + + case PROP_NETWORK_STATE_PATH: + { + if (network_state->path) + g_free(network_state->path); + + network_state->path = g_value_dup_string(value); + break; + } + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void netconfig_network_state_init(NetconfigNetworkState *network_state) +{ + network_state->connection = NULL; + network_state->path = g_strdup(PROP_DEFAULT_STR); +} + +static void netconfig_network_state_class_init(NetconfigNetworkStateClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->get_property = __netconfig_network_state_gobject_get_property; + object_class->set_property = __netconfig_network_state_gobject_set_property; + + /* DBus register */ + dbus_g_object_type_install_info(NETCONFIG_TYPE_NETWORK_STATE, + &dbus_glib_netconfig_iface_network_state_object_info); + + /* property */ + g_object_class_install_property(object_class, PROP_NETWORK_STATE_CONN, + g_param_spec_boxed("connection", "CONNECTION", "DBus connection", + DBUS_TYPE_G_CONNECTION, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property(object_class, PROP_NETWORK_STATE_PATH, + g_param_spec_string("path", "Path", "Object path", + PROP_DEFAULT_STR, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + + +struct netconfig_default_connection { + char *profile; + char *ifname; + char *ipaddress; + char *proxy; + char *essid; +}; + +static struct netconfig_default_connection + netconfig_default_connection_info = { NULL, }; + +static void __netconfig_pop_3g_alert_poppup(void) +{ + bundle *b = NULL; + + b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", "Cellular connection popup"); + bundle_add(b, "_SYSPOPUP_TYPE_", "notification"); + bundle_add(b, "_SYSPOPUP_CONTENT_", "connected"); + + DBG("Launch 3G alert network popup"); + aul_launch_app("net.netpopup", b); + + bundle_free(b); +} + +static gboolean __netconfig_is_connected(DBusMessageIter *array) +{ + gboolean is_connected = FALSE; + + while (dbus_message_iter_get_arg_type(array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, variant; + const char *key = NULL; + const char *value = NULL; + + dbus_message_iter_recurse(array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + if (g_str_equal(key, "State") != TRUE) { + dbus_message_iter_next(array); + continue; + } + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + + if (dbus_message_iter_get_arg_type(&variant) == + DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&variant, &value); + + if (g_str_equal(value, "ready") == TRUE || + g_str_equal(value, "online") == TRUE) + is_connected = TRUE; + } + + break; + } + + return is_connected; +} + +static char *__netconfig_get_default_profile(void) +{ + DBusMessage *message = NULL; + DBusMessageIter iter, dict; + char *default_profile = NULL; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetServices", NULL); + if (message == NULL) { + ERR("Failed to get profiles"); + return NULL; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry; + DBusMessageIter array; + const char *object_path = NULL; + + dbus_message_iter_recurse(&dict, &entry); + dbus_message_iter_get_basic(&entry, &object_path); + + if (object_path == NULL) { + dbus_message_iter_next(&dict); + continue; + } + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &array); + + if (__netconfig_is_connected(&array) == TRUE) { + default_profile = g_strdup(object_path); + break; + } + + dbus_message_iter_next(&dict); + } + + dbus_message_unref(message); + + return default_profile; +} + +static void __netconfig_get_default_connection_info(const char *profile) +{ + DBusMessage *message = NULL; + DBusMessageIter iter, array; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, profile, + CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL); + if (message == NULL) { + ERR("Failed to get service properties"); + return; + } + + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { + const char *ptr = dbus_message_get_error_name(message); + ERR("Error!!! Error message received [%s]", ptr); + goto done; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, variant, string, iter1, iter2, iter3; + const char *key = NULL, *value = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + if (g_str_equal(key, "Name") == TRUE && + netconfig_is_wifi_profile(profile) == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &string); + + if (dbus_message_iter_get_arg_type(&string) == DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&string, &value); + + netconfig_default_connection_info.essid = g_strdup(value); + } + } else if (g_str_equal(key, "Ethernet") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Interface") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + dbus_message_iter_get_basic(&iter3, &value); + + netconfig_default_connection_info.ifname = g_strdup(value); + } + + dbus_message_iter_next(&iter1); + } + } else if (g_str_equal(key, "IPv4") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Address") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + dbus_message_iter_get_basic(&iter3, &value); + + netconfig_default_connection_info.ipaddress = g_strdup(value); + } + + dbus_message_iter_next(&iter1); + } + } else if (g_str_equal(key, "IPv6") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Address") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + dbus_message_iter_get_basic(&iter3, &value); + + /* TODO: support IPv6 + netconfig_default_connection_info.ipaddress = g_strdup(value); + */ + } + + dbus_message_iter_next(&iter1); + } + } else if (g_str_equal(key, "Proxy") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter iter4; + + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Servers") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + if (dbus_message_iter_get_arg_type(&iter3) + != DBUS_TYPE_ARRAY) + break; + + dbus_message_iter_recurse(&iter3, &iter4); + if (dbus_message_iter_get_arg_type(&iter4) + != DBUS_TYPE_STRING) + break; + + dbus_message_iter_get_basic(&iter4, &value); + if (value != NULL && (strlen(value) > 0)) + netconfig_default_connection_info.proxy = g_strdup(value); + + } else if (g_str_equal(key, "Method") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + if (dbus_message_iter_get_arg_type(&iter3) + != DBUS_TYPE_STRING) + break; + + dbus_message_iter_get_basic(&iter3, &value); + if (g_strcmp0(value, "direct") == 0) { + g_free(netconfig_default_connection_info.proxy); + netconfig_default_connection_info.proxy = NULL; + + break; + } + } + + dbus_message_iter_next(&iter1); + } + } + + dbus_message_iter_next(&array); + } + +done: + if (message != NULL) + dbus_message_unref(message); +} + +static void __netconfig_adjust_tcp_buffer_size(void) +{ + int fdr = 0, fdw = 0; + int fdrmax = 0, fdwmax = 0; + const char *rbuf_size = NULL; + const char *wbuf_size = NULL; + const char *rmax_size = NULL; + const char *wmax_size = NULL; + const char *profile = netconfig_get_default_profile(); + + if (profile == NULL) { + DBG("There is no default connection"); + + rbuf_size = NET_TCP_BUFFERSIZE_DEFAULT_READ; + wbuf_size = NET_TCP_BUFFERSIZE_DEFAULT_WRITE; + } else if (netconfig_is_wifi_profile(profile) == TRUE) { + DBG("Default connection: Wi-Fi"); + + rbuf_size = NET_TCP_BUFFERSIZE_WIFI_READ; + wbuf_size = NET_TCP_BUFFERSIZE_WIFI_WRITE; + rmax_size = NET_TCP_BUFFERSIZE_WIFI_RMEM_MAX; + wmax_size = NET_TCP_BUFFERSIZE_WIFI_WMEM_MAX; + } else if (netconfig_is_cellular_profile(profile) == TRUE) { + int telephony_svctype = 0, telephony_pstype = 0; + + vconf_get_int(VCONFKEY_TELEPHONY_SVCTYPE, &telephony_svctype); + vconf_get_int(VCONFKEY_TELEPHONY_PSTYPE, &telephony_pstype); + + DBG("Default cellular %d, %d", telephony_svctype, telephony_pstype); + + switch (telephony_pstype) { + case VCONFKEY_TELEPHONY_PSTYPE_HSPA: + rbuf_size = NET_TCP_BUFFERSIZE_HSPA_READ; + wbuf_size = NET_TCP_BUFFERSIZE_HSPA_WRITE; + break; + case VCONFKEY_TELEPHONY_PSTYPE_HSUPA: + rbuf_size = NET_TCP_BUFFERSIZE_HSUPA_READ; + wbuf_size = NET_TCP_BUFFERSIZE_HSDPA_WRITE; + break; + case VCONFKEY_TELEPHONY_PSTYPE_HSDPA: + rbuf_size = NET_TCP_BUFFERSIZE_HSDPA_READ; + wbuf_size = NET_TCP_BUFFERSIZE_HSDPA_WRITE; + break; + default: + switch (telephony_svctype) { + case VCONFKEY_TELEPHONY_SVCTYPE_LTE: + rbuf_size = NET_TCP_BUFFERSIZE_LTE_READ; + wbuf_size = NET_TCP_BUFFERSIZE_LTE_WRITE; + rmax_size = NET_TCP_BUFFERSIZE_LTE_RMEM_MAX; + break; + case VCONFKEY_TELEPHONY_SVCTYPE_3G: + rbuf_size = NET_TCP_BUFFERSIZE_UMTS_READ; + wbuf_size = NET_TCP_BUFFERSIZE_UMTS_WRITE; + break; + case VCONFKEY_TELEPHONY_SVCTYPE_2_5G_EDGE: + rbuf_size = NET_TCP_BUFFERSIZE_EDGE_READ; + wbuf_size = NET_TCP_BUFFERSIZE_EDGE_WRITE; + break; + case VCONFKEY_TELEPHONY_SVCTYPE_2_5G: + rbuf_size = NET_TCP_BUFFERSIZE_GPRS_READ; + wbuf_size = NET_TCP_BUFFERSIZE_GPRS_WRITE; + break; + default: + /* TODO: Check LTE support */ + rbuf_size = NET_TCP_BUFFERSIZE_DEFAULT_READ; + wbuf_size = NET_TCP_BUFFERSIZE_DEFAULT_WRITE; + break; + } + break; + } + } else { + DBG("Default TCP buffer configured"); + + rbuf_size = NET_TCP_BUFFERSIZE_DEFAULT_READ; + wbuf_size = NET_TCP_BUFFERSIZE_DEFAULT_WRITE; + } + + if (rbuf_size != NULL) { + fdr = open(NET_PROC_SYS_NET_IPV4_TCP_RMEM, O_RDWR | O_CLOEXEC); + + if (fdr < 0 || write(fdr, rbuf_size, strlen(rbuf_size)) < 0) + ERR("Failed to set TCP read buffer size"); + + if (fdr >= 0) + close(fdr); + } + + if (wbuf_size != NULL) { + fdw = open(NET_PROC_SYS_NET_IPv4_TCP_WMEM, O_RDWR | O_CLOEXEC); + + if (fdw < 0 || write(fdw, wbuf_size, strlen(wbuf_size)) < 0) + ERR("Failed to set TCP write buffer size"); + + if (fdw >= 0) + close(fdw); + } + + /* As default */ + if (rmax_size == NULL) + rmax_size = NET_TCP_BUFFERSIZE_WIFI_RMEM_MAX; + if (wmax_size == NULL) + wmax_size = NET_TCP_BUFFERSIZE_WIFI_WMEM_MAX; + + if (rmax_size != NULL) { + fdrmax = open(NET_PROC_SYS_NET_CORE_RMEM_MAX, O_RDWR | O_CLOEXEC); + + if (fdrmax < 0 || write(fdrmax, rmax_size, strlen(rmax_size)) < 0) + ERR("Failed to set TCP rmem_max size"); + + if (fdrmax >= 0) + close(fdrmax); + } + + if (wmax_size != NULL) { + fdwmax = open(NET_PROC_SYS_NET_CORE_WMEM_MAX, O_RDWR | O_CLOEXEC); + + if (fdwmax < 0 || write(fdwmax, wmax_size, strlen(wmax_size)) < 0) + ERR("Failed to set TCP wmem_max size"); + + if (fdwmax >= 0) + close(fdwmax); + } +} + +static void __netconfig_update_default_connection_info(void) +{ + int old_network_status = 0; + const char *profile = netconfig_get_default_profile(); + const char *ip_addr = netconfig_get_default_ipaddress(); + const char *proxy_addr = netconfig_get_default_proxy(); + + if (netconfig_emulator_is_emulated() == TRUE) + return; + + if (profile == NULL) + DBG("Reset network state configuration"); + else + DBG("%s: ip(%s) proxy(%s)", profile, ip_addr, proxy_addr); + + vconf_get_int(VCONFKEY_NETWORK_STATUS, &old_network_status); + + if (profile == NULL && old_network_status != VCONFKEY_NETWORK_OFF) { + netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_OFF); + + netconfig_set_vconf_str(VCONFKEY_NETWORK_IP, ""); + netconfig_set_vconf_str(VCONFKEY_NETWORK_PROXY, ""); + + netconfig_set_vconf_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 0); + + DBG("Successfully clear IP and PROXY up"); + } else if (profile != NULL) { + char *old_ip = vconf_get_str(VCONFKEY_NETWORK_IP); + char *old_proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY); + + if (netconfig_is_wifi_profile(profile) == TRUE) + netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_WIFI); + else if (netconfig_is_cellular_profile(profile) == TRUE) + netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_CELLULAR); + else + netconfig_set_vconf_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_OFF); + + if (g_strcmp0(old_ip, ip_addr) != 0) { + if (ip_addr == NULL) + netconfig_set_vconf_str(VCONFKEY_NETWORK_IP, ""); + else + netconfig_set_vconf_str(VCONFKEY_NETWORK_IP, ip_addr); + } + g_free(old_ip); + + if (g_strcmp0(old_proxy, proxy_addr) != 0) { + if (proxy_addr == NULL) + netconfig_set_vconf_str(VCONFKEY_NETWORK_PROXY, ""); + else + netconfig_set_vconf_str(VCONFKEY_NETWORK_PROXY, proxy_addr); + } + g_free(old_proxy); + + netconfig_set_vconf_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 1); + + DBG("Successfully update default network configuration"); + } + + __netconfig_adjust_tcp_buffer_size(); +} + +static gboolean __netconfig_is_tech_state_connected(void) +{ + gboolean ret = FALSE; + DBusMessage *message; + DBusMessageIter iter, array; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetTechnologies", NULL); + + if (message == NULL) { + DBG("Fail to get technology state"); + return FALSE; + } + + if (!dbus_message_iter_init(message, &iter)) { + DBG("Message does not have parameters"); + goto done; + } + + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry, dict; + char *path = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &path); + + if (path == NULL) { + dbus_message_iter_next(&array); + continue; + } + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry1, value1; + const char *key; + dbus_bool_t data; + + dbus_message_iter_recurse(&dict, &entry1); + dbus_message_iter_get_basic(&entry1, &key); + + if (0 == g_strcmp0(key, "Connected")) { + dbus_message_iter_next(&entry1); + dbus_message_iter_recurse(&entry1, &value1); + + if (dbus_message_iter_get_arg_type(&value1) == + DBUS_TYPE_BOOLEAN) { + dbus_message_iter_get_basic(&value1, &data); + DBG("%s [%s: %s]", path, key, data ? "True" : "False"); + + if (TRUE == data) { + ret = TRUE; + goto done; + } + } + } + dbus_message_iter_next(&dict); + } + + dbus_message_iter_next(&array); + } + +done: + if (message != NULL) + dbus_message_unref(message); + + return ret; +} + +static void __netconfig_update_if_service_connected(void) +{ + DBusMessage *message; + DBusMessageIter iter, array; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetServices", NULL); + + if (message == NULL) { + DBG("Fail to get services"); + return; + } + + if (!dbus_message_iter_init(message, &iter)) { + DBG("Message does not have parameters"); + goto done; + } + + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry, dict; + char *path = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &path); + + if (path == NULL) { + dbus_message_iter_next(&array); + continue; + } + + if (g_str_has_prefix(path, + CONNMAN_WIFI_SERVICE_PROFILE_PREFIX) == TRUE) { + if (g_strrstr(path + strlen(CONNMAN_WIFI_SERVICE_PROFILE_PREFIX), + "hidden") != NULL) { + /* skip hidden profiles */ + dbus_message_iter_next(&array); + continue; + } + /* Process this */ + } else if (g_str_has_prefix(path, + CONNMAN_CELLULAR_SERVICE_PROFILE_PREFIX) == TRUE) { + /* Process this */ + } else { + dbus_message_iter_next(&array); + continue; + } + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry1, value1; + const char *key, *sdata; + + dbus_message_iter_recurse(&dict, &entry1); + dbus_message_iter_get_basic(&entry1, &key); + + if (0 == g_strcmp0(key, "State")) { + dbus_message_iter_next(&entry1); + dbus_message_iter_recurse(&entry1, &value1); + + if (dbus_message_iter_get_arg_type(&value1) == + DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&value1, &sdata); + DBG("%s [%s: %s]", path, key, sdata); + + if (0 == g_strcmp0(sdata, "online") || + 0 == g_strcmp0(sdata, "ready")) { + + /* Found a connected WiFi / 3G service. + * Lets update the default profile info. + */ + netconfig_update_default_profile(path); + goto done; + } + } + } + dbus_message_iter_next(&dict); + } + + dbus_message_iter_next(&array); + } + +done: + if (message != NULL) + dbus_message_unref(message); +} + +const char *netconfig_get_default_profile(void) +{ + return netconfig_default_connection_info.profile; +} + +const char *netconfig_get_default_ifname(void) +{ + return netconfig_default_connection_info.ifname; +} + +const char *netconfig_get_default_ipaddress(void) +{ + return netconfig_default_connection_info.ipaddress; +} + +const char *netconfig_get_default_proxy(void) +{ + return netconfig_default_connection_info.proxy; +} + +const char *netconfig_wifi_get_connected_essid(const char *default_profile) +{ + if (default_profile == NULL) + return NULL; + + if (netconfig_is_wifi_profile(default_profile) != TRUE) + return NULL; + + if (g_str_equal(default_profile, netconfig_default_connection_info.profile) + != TRUE) + return NULL; + + return netconfig_default_connection_info.essid; +} + +static int __netconfig_reset_ipv4_socket(void) +{ + int ret; + int fd; + struct ifreq ifr; + struct sockaddr_in sai; + const char *ipaddr = netconfig_get_default_ipaddress(); + DBG("ipaddr-[%s]", ipaddr); + + if (!ipaddr) + return -1; + + fd = socket(AF_INET, SOCK_DGRAM, 0); + if (fd < 0) + return -1; + + memset(&sai, 0, sizeof(struct sockaddr_in)); + sai.sin_family = AF_INET; + sai.sin_port = 0; + if (!inet_aton(ipaddr, &sai.sin_addr)) { + DBG("fail to inet_aton()"); + close(fd); + return -1; + } + + memset(&ifr, 0, sizeof(struct ifreq)); + memcpy(&ifr.ifr_addr, &sai, sizeof(sai)); + g_strlcpy((char *)ifr.ifr_name, WIFI_IFNAME, IFNAMSIZ); + +#ifndef SIOCKILLADDR +#define SIOCKILLADDR 0x8939 +#endif + + ret = ioctl(fd, SIOCKILLADDR, &ifr); + if (ret < 0) { + DBG("fail to ioctl[SIOCKILLADDR]"); + close(fd); + return -1; + } + + close(fd); + return 0; +} + +void netconfig_update_default_profile(const char *profile) +{ + char *default_profile = NULL; + static char *old_profile = NULL; + + /* It's automatically updated by signal-handler + * DO NOT update manually + * + * It is going to update default connection information + */ + if (netconfig_default_connection_info.profile != NULL) { + if (netconfig_is_wifi_profile( + netconfig_default_connection_info.profile) == TRUE) + __netconfig_reset_ipv4_socket(); + + g_free(old_profile); + old_profile = strdup(netconfig_default_connection_info.profile); + + g_free(netconfig_default_connection_info.profile); + netconfig_default_connection_info.profile = NULL; + + g_free(netconfig_default_connection_info.ifname); + netconfig_default_connection_info.ifname = NULL; + + g_free(netconfig_default_connection_info.ipaddress); + netconfig_default_connection_info.ipaddress = NULL; + + g_free(netconfig_default_connection_info.proxy); + netconfig_default_connection_info.proxy = NULL; + + if (netconfig_wifi_state_get_service_state() + != NETCONFIG_WIFI_CONNECTED) { + g_free(netconfig_default_connection_info.essid); + netconfig_default_connection_info.essid = NULL; + } + } + + if (profile == NULL) { + default_profile = __netconfig_get_default_profile(); + if (default_profile == NULL) { + __netconfig_update_default_connection_info(); + return; + } + netconfig_default_connection_info.profile = default_profile; + } else + netconfig_default_connection_info.profile = g_strdup(profile); + + __netconfig_get_default_connection_info( + netconfig_default_connection_info.profile); + + __netconfig_update_default_connection_info(); + + if ((old_profile == NULL || netconfig_is_wifi_profile(old_profile) == TRUE) + && netconfig_is_cellular_profile( + netconfig_default_connection_info.profile) == TRUE) + __netconfig_pop_3g_alert_poppup(); +} + +void netconfig_update_default(void) +{ + if (__netconfig_is_tech_state_connected() == TRUE) + __netconfig_update_if_service_connected(); + else + __netconfig_adjust_tcp_buffer_size(); +} + +char *netconfig_network_get_ifname(const char *profile) +{ + DBusMessage *message = NULL; + DBusMessageIter iter, array; + char *ifname = NULL; + + if (profile == NULL) + return NULL; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, profile, + CONNMAN_SERVICE_INTERFACE, "GetProperties", NULL); + if (message == NULL) { + ERR("Failed to get service properties"); + return NULL; + } + + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { + const char *ptr = dbus_message_get_error_name(message); + ERR("Error!!! Error message received [%s]", ptr); + goto done; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, variant, iter1, iter2, iter3; + const char *key = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &key); + + if (g_str_equal(key, "Ethernet") == TRUE) { + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + dbus_message_iter_recurse(&variant, &iter1); + + while (dbus_message_iter_get_arg_type(&iter1) + == DBUS_TYPE_DICT_ENTRY) { + const char *value; + + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &key); + + if (g_str_equal(key, "Interface") == TRUE) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + dbus_message_iter_get_basic(&iter3, &value); + + ifname = g_strdup(value); + } + dbus_message_iter_next(&iter1); + } + } + dbus_message_iter_next(&array); + } + +done: + if (message != NULL) + dbus_message_unref(message); + + return ifname; +} + +gboolean netconfig_iface_network_state_add_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error) +{ + int rv = 0; + const char *path = ROUTE_EXEC_PATH; + char *const args[] = { "/sbin/route", "add", "-net", ip_addr, + "netmask", netmask, "dev", interface, NULL }; + char *const envs[] = { NULL }; + + DBG("ip_addr(%s), netmask(%s), interface(%s)", ip_addr, netmask, interface); + + if (ip_addr == NULL || netmask == NULL || interface == NULL) { + ERR("Invalid parameter"); + + netconfig_error_invalid_parameter(error); + *result = FALSE; + return FALSE; + } + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) { + ERR("Failed to add a new route"); + + netconfig_error_permission_denied(error); + *result = FALSE; + return FALSE; + } + + DBG("Successfully added a new route"); + *result = TRUE; + return TRUE; +} + +gboolean netconfig_iface_network_state_remove_route( + NetconfigNetworkState *master, + gchar *ip_addr, gchar *netmask, + gchar *interface, gboolean *result, GError **error) +{ + int rv = 0; + const char *path = ROUTE_EXEC_PATH; + char *const args[] = { "/sbin/route", "del", "-net", ip_addr, + "netmask", netmask, "dev", interface, NULL }; + char *const envs[] = { NULL }; + + DBG("ip_addr(%s), netmask(%s), interface(%s)", ip_addr, netmask, interface); + + if (ip_addr == NULL || netmask == NULL || interface == NULL) { + ERR("Invalid parameter"); + + netconfig_error_invalid_parameter(error); + *result = FALSE; + return FALSE; + } + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) { + ERR("Failed to remove a new route"); + + netconfig_error_permission_denied(error); + *result = FALSE; + return FALSE; + } + + DBG("Successfully remove a new route"); + *result = TRUE; + return TRUE; +} + +gpointer netconfig_network_state_create_and_init(DBusGConnection *connection) +{ + GObject *object; + + g_return_val_if_fail(connection != NULL, NULL); + + object = g_object_new(NETCONFIG_TYPE_NETWORK_STATE, "connection", + connection, "path", NETCONFIG_NETWORK_STATE_PATH, NULL); + + dbus_g_connection_register_g_object(connection, + NETCONFIG_NETWORK_STATE_PATH, object); + + return object; +} diff --git a/wearable/src/network-statistics.c b/wearable/src/network-statistics.c new file mode 100644 index 0000000..d19e4e0 --- /dev/null +++ b/wearable/src/network-statistics.c @@ -0,0 +1,452 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netsupplicant.h" +#include "network-statistics.h" + +#include "netconfig-iface-network-statistics-glue.h" + +#define NETCONFIG_NETWORK_STATISTICS_PATH "/net/netconfig/network_statistics" + +#define NETCONFIG_PROCDEV "/proc/net/dev" + +#define PROP_DEFAULT FALSE +#define PROP_DEFAULT_STR NULL + +enum { + PROP_O, + PROP_NETWORK_STATISTICS_CONN, + PROP_NETWORK_STATISTICS_PATH, +}; + +struct NetconfigNetworkStatisticsClass { + GObjectClass parent; +}; + +struct NetconfigNetworkStatistics { + GObject parent; + + DBusGConnection *connection; + gchar *path; +}; + +G_DEFINE_TYPE(NetconfigNetworkStatistics, netconfig_network_statistics, G_TYPE_OBJECT); + +static void __netconfig_network_statistics_gobject_get_property(GObject *object, + guint prop_id, GValue *value, GParamSpec *pspec) +{ + return; +} + +static void __netconfig_network_statistics_gobject_set_property(GObject *object, + guint prop_id, const GValue *value, GParamSpec *pspec) +{ + NetconfigNetworkStatistics *network_statistics = + NETCONFIG_NETWORK_STATISTICS(object); + + switch (prop_id) { + case PROP_NETWORK_STATISTICS_CONN: + { + network_statistics->connection = g_value_get_boxed(value); + break; + } + + case PROP_NETWORK_STATISTICS_PATH: + { + if (network_statistics->path) + g_free(network_statistics->path); + + network_statistics->path = g_value_dup_string(value); + break; + } + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void netconfig_network_statistics_init( + NetconfigNetworkStatistics *network_statistics) +{ + network_statistics->connection = NULL; + network_statistics->path = g_strdup(PROP_DEFAULT_STR); +} + +static void netconfig_network_statistics_class_init( + NetconfigNetworkStatisticsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->get_property = + __netconfig_network_statistics_gobject_get_property; + object_class->set_property = + __netconfig_network_statistics_gobject_set_property; + + /* DBus register */ + dbus_g_object_type_install_info(NETCONFIG_TYPE_NETWORK_STATISTICS, + &dbus_glib_netconfig_iface_network_statistics_object_info); + + /* property */ + g_object_class_install_property(object_class, PROP_NETWORK_STATISTICS_CONN, + g_param_spec_boxed("connection", "CONNECTION", "DBus connection", + DBUS_TYPE_G_CONNECTION, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property(object_class, PROP_NETWORK_STATISTICS_PATH, + g_param_spec_string("path", "Path", "Object path", + PROP_DEFAULT_STR, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + + +gboolean netconfig_wifi_get_bytes_statistics(guint64 *tx, guint64 *rx) +{ + gboolean ret = FALSE; + FILE *fp; + gchar buf[1024]; + gchar *p_ifname = NULL, *p_entry = NULL; + + *tx = 0; + *rx = 0; + + fp = fopen(NETCONFIG_PROCDEV, "r"); + if (fp == NULL) { + ERR("Failed to open %s", NETCONFIG_PROCDEV); + return FALSE; + } + + /* skip the first and second line */ + if (fgets(buf, sizeof(buf), fp) == NULL || + fgets(buf, sizeof(buf), fp) == NULL) + goto endline; + + while (fgets(buf, sizeof(buf), fp)) { + guint64 llval; + gulong lval; + + p_ifname = buf; + while (*p_ifname == ' ') p_ifname++; + p_entry = strchr(p_ifname, ':'); + *p_entry++ = '\0'; + + if (g_str_equal(p_ifname, WIFI_IFNAME) != TRUE) + continue; + + /* read interface statistics */ + sscanf(p_entry, + "%llu %llu %lu %lu %lu %lu %lu %lu " + "%llu %llu %lu %lu %lu %lu %lu %lu", + rx, /* rx bytes */ + &llval, /* rx packet */ + &lval, /* rx errors */ + &lval, /* rx dropped */ + &lval, /* rx fifo errors */ + &lval, /* rx frame errors */ + &lval, /* rx compressed */ + &lval, /* rx multicast */ + + tx, /* tx bytes */ + &llval, /* tx packet */ + &lval, /* tx errors */ + &lval, /* tx dropped */ + &lval, /* tx fifo errors */ + &lval, /* collisions */ + &lval, /* tx carrier errors */ + &lval /* tx compressed */ + ); + + ret = TRUE; + break; + } + +endline: + fclose(fp); + return ret; +} + +gboolean netconfig_iface_network_statistics_get_wifi_total_tx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *total_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 tx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val); + tx_bytes = (guint64)val; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *total_bytes = tx + tx_bytes; + else + *total_bytes = tx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_get_wifi_total_rx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *total_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 rx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val); + rx_bytes = (guint64)val; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *total_bytes = rx + rx_bytes; + else + *total_bytes = rx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_get_wifi_last_tx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *last_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 tx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val); + tx_bytes = (guint64)val; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + *last_bytes = tx_bytes; + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *last_bytes = tx < tx_bytes ? 0 : tx - tx_bytes; + else + *last_bytes = tx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_get_wifi_last_rx_bytes( + NetconfigNetworkStatistics *network_statistics, + guint64 *last_bytes, GError **error) +{ + guint64 tx = 0, rx = 0; + guint64 rx_bytes = 0; + int val = 0; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val); + rx_bytes = (guint64)val; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + *last_bytes = rx_bytes; + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + *last_bytes = rx < rx_bytes ? 0 : rx - rx_bytes; + else + *last_bytes = rx_bytes; + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_total_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + netconfig_set_vconf_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_total_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + netconfig_set_vconf_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_last_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + netconfig_set_vconf_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_cellular_last_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + netconfig_set_vconf_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, 0); + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_total_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, -(int)tx); + else + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, 0); + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_total_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, -(int)rx); + else + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, 0); + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_last_tx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)tx); + else + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); + + return TRUE; +} + +gboolean netconfig_iface_network_statistics_reset_wifi_last_rx_bytes( + NetconfigNetworkStatistics *network_statistics, GError **error) +{ + guint64 tx = 0, rx = 0; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) { + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0); + return TRUE; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)rx); + else + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0); + + return TRUE; +} + +void netconfig_wifi_statistics_update_powered_off(void) +{ + guint64 cur_tx = 0, cur_rx = 0; + guint64 prev_tx = 0, prev_rx = 0; + guint64 total_tx = 0, total_rx = 0; + int val = 0; + + if (netconfig_wifi_get_bytes_statistics(&cur_tx, &cur_rx) != TRUE) + return; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, &val); + prev_tx = (guint64)val; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, &val); + prev_rx = (guint64)val; + + total_tx = prev_tx + cur_tx; + total_rx = prev_rx + cur_rx; + + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, (int)total_tx); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, (int)total_rx); +} + +static void netconfig_wifi_statistics_update_state( + enum netconfig_wifi_service_state state, void *user_data) +{ + guint64 tx = 0, rx = 0; + guint64 last_tx = 0, last_rx = 0; + int val = 0; + static enum netconfig_wifi_service_state prev_state = NETCONFIG_WIFI_UNKNOWN; + + if (prev_state == NETCONFIG_WIFI_UNKNOWN) { + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, 0); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, 0); + + prev_state = NETCONFIG_WIFI_IDLE; + return; + } + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) != TRUE) + return; + + if (state == NETCONFIG_WIFI_CONNECTED) { + last_tx = tx; + last_rx = rx; + } else { + if (prev_state != NETCONFIG_WIFI_CONNECTED) + return; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, &val); + last_tx = (guint64)val; + + vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, &val); + last_rx = (guint64)val; + + last_tx = tx < last_tx ? 0 : tx - last_tx; + last_rx = rx < last_rx ? 0 : rx - last_rx; + } + + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, (int)last_tx); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, (int)last_rx); + + prev_state = state; +} + +static struct netconfig_wifi_state_notifier state_notifier = { + .netconfig_wifi_state_changed = netconfig_wifi_statistics_update_state, + .user_data = NULL, +}; + +gpointer netconfig_network_statistics_create_and_init( + DBusGConnection *connection) +{ + GObject *object; + + g_return_val_if_fail(connection != NULL, NULL); + + object = g_object_new(NETCONFIG_TYPE_NETWORK_STATISTICS, "connection", + connection, "path", NETCONFIG_NETWORK_STATISTICS_PATH, NULL); + + dbus_g_connection_register_g_object(connection, + NETCONFIG_NETWORK_STATISTICS_PATH, object); + + netconfig_wifi_statistics_update_state(NETCONFIG_WIFI_IDLE, NULL); + netconfig_wifi_state_notifier_register(&state_notifier); + + return object; +} diff --git a/wearable/src/signal-handler.c b/wearable/src/signal-handler.c new file mode 100644 index 0000000..0bef637 --- /dev/null +++ b/wearable/src/signal-handler.c @@ -0,0 +1,519 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "wifi-wps.h" +#include "wifi-agent.h" +#include "wifi-power.h" +#include "wifi-state.h" +#include "netsupplicant.h" +#include "network-state.h" +#include "cellular-state.h" +#include "signal-handler.h" +#include "wifi-ssid-scan.h" +#include "wifi-background-scan.h" + +#define SIGNAL_INTERFACE_REMOVED "InterfaceRemoved" +#define SIGNAL_SCAN_DONE "ScanDone" +#define SIGNAL_BSS_ADDED "BSSAdded" +#define SIGNAL_PROPERTIES_CHANGED "PropertiesChanged" +#define SIGNAL_PROPERTIES_DRIVER_HANGED "DriverHanged" + +#define CONNMAN_SIGNAL_SERVICES_CHANGED "ServicesChanged" +#define CONNMAN_SIGNAL_PROPERTY_CHANGED "PropertyChanged" + +#define CONNMAN_TECHNOLOGY_SIGNAL_FILTER \ + "type='signal',interface='"CONNMAN_TECHNOLOGY_INTERFACE"'" + +#define CONNMAN_SERVICE_STATE_SIGNAL_FILTER \ + "type='signal',interface='"CONNMAN_SERVICE_INTERFACE \ + "',member='PropertyChanged',arg0='State'" + +#define CONNMAN_SERVICE_PROXY_SIGNAL_FILTER \ + "type='signal',interface='"CONNMAN_SERVICE_INTERFACE \ + "',member='PropertyChanged',arg0='Proxy'" + +#define SUPPLICANT_INTERFACE_REMOVED_SIGNAL_FILTER \ + "type='signal',interface='"SUPPLICANT_INTERFACE \ + "',member='"SIGNAL_INTERFACE_REMOVED"'" + +#define SUPPLICANT_INTERFACE_PROPERTIESCHANGED_SIGNAL_FILTER \ + "type='signal',interface='"SUPPLICANT_IFACE_INTERFACE \ + "',member='"SIGNAL_PROPERTIES_CHANGED"'" + +#define SUPPLICANT_INTERFACE_BSSADDED_SIGNAL_FILTER \ + "type='signal',interface='"SUPPLICANT_IFACE_INTERFACE \ + "',member='"SIGNAL_BSS_ADDED"'" + +#define SUPPLICANT_INTERFACE_SCANDONE_SIGNAL_FILTER \ + "type='signal',interface='"SUPPLICANT_IFACE_INTERFACE \ + "',member='"SIGNAL_SCAN_DONE"'" + +#define SUPPLICANT_INTERFACE_DRIVERHANGED_SIGNAL_FILTER \ + "type='signal',interface='"SUPPLICANT_IFACE_INTERFACE \ + "',member='"SIGNAL_PROPERTIES_DRIVER_HANGED"'" + +#define CONNMAN_SERVICE_NAMECHANGED_SIGNAL_FILTER \ + "type='signal',sender='"DBUS_SERVICE_DBUS \ + "',interface='"DBUS_INTERFACE_DBUS \ + "',member='NameOwnerChanged',path='/org/freedesktop/DBus'" \ + ",arg0='"CONNMAN_SERVICE"'" + + +static DBusConnection *signal_connection = NULL; + +static void __netconfig_technology_signal_handler(DBusMessage *msg) +{ + char *key = NULL; + const char *tech = NULL; + dbus_bool_t value = FALSE; + + if (netconfig_dbus_get_basic_params_string(msg, + &key, DBUS_TYPE_BOOLEAN, &value) != TRUE) + return; + + tech = dbus_message_get_path(msg); + if (key == NULL || tech == NULL) + return; + + if (g_str_has_prefix(tech, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == TRUE) { + if (g_strcmp0(key, "Powered") == 0) { + /* Power state */ + if (value == TRUE) { + netconfig_wifi_update_power_state(TRUE); + } else { + netconfig_wifi_update_power_state(FALSE); + } + } else if (g_strcmp0(key, "Connected") == 0) { + /* Connection state */ + netconfig_wifi_state_set_technology_state( + NETCONFIG_WIFI_TECH_CONNECTED); + } else if (g_strcmp0(key, "Tethering") == 0) { + /* Tethering state */ + netconfig_wifi_state_set_technology_state( + NETCONFIG_WIFI_TECH_TETHERED); + } + } else if (g_str_has_prefix(tech, + CONNMAN_CELLULAR_TECHNOLOGY_PREFIX) == TRUE) { + /* Cellular technology state */ + } +} + +static void __netconfig_service_signal_handler(DBusMessage *msg) +{ + char *sigvalue = NULL; + char *property = NULL; + char *service_profile = NULL; + DBusMessageIter args, variant, iter1, iter2, iter3, iter4; + const char *value = NULL; + + service_profile = (char *)dbus_message_get_path(msg); + if (service_profile == NULL) + return; + + dbus_message_iter_init(msg, &args); + dbus_message_iter_get_basic(&args, &sigvalue); + if (sigvalue == NULL) + return; + + if (g_str_equal(sigvalue, "State") == TRUE) { + dbus_message_iter_next(&args); + dbus_message_iter_recurse(&args, &variant); + dbus_message_iter_get_basic(&variant, &property); + + DBG("[%s] %s", property, service_profile); + if (netconfig_is_wifi_profile(service_profile) == TRUE) { + int wifi_state = 0; + + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + if (wifi_state == VCONFKEY_WIFI_OFF) + return; + + if (g_str_equal(property, "ready") == TRUE || + g_str_equal(property, "online") == TRUE) { + if (wifi_state >= VCONFKEY_WIFI_CONNECTED) + return; + + netconfig_update_default_profile(service_profile); + + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTED); + + } else if (g_str_equal(property, "failure") == TRUE || + g_str_equal(property, "disconnect") == TRUE || + g_str_equal(property, "idle") == TRUE) { + if (netconfig_get_default_profile() == NULL || + netconfig_is_wifi_profile(netconfig_get_default_profile()) + != TRUE) { + if (g_str_equal(property, "failure") == TRUE) + netconfig_wifi_state_set_service_state( + NETCONFIG_WIFI_FAILURE); + else + netconfig_wifi_state_set_service_state( + NETCONFIG_WIFI_IDLE); + return; + } + + if (g_str_equal(service_profile, netconfig_get_default_profile()) + != TRUE) + return; + + netconfig_update_default_profile(NULL); + + if (g_str_equal(property, "failure") == TRUE) + netconfig_wifi_state_set_service_state( + NETCONFIG_WIFI_FAILURE); + else + netconfig_wifi_state_set_service_state( + NETCONFIG_WIFI_IDLE); + + } else if (g_str_equal(property, "association") == TRUE || + g_str_equal(property, "configuration") == TRUE) { + if (netconfig_get_default_profile() == NULL || + netconfig_is_wifi_profile(netconfig_get_default_profile()) + != TRUE) { + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTING); + return; + } + + if (g_str_equal(service_profile, netconfig_get_default_profile()) != TRUE) + return; + + netconfig_update_default_profile(NULL); + + netconfig_wifi_state_set_service_state(NETCONFIG_WIFI_CONNECTING); + + } + } else { + if (g_str_equal(property, "ready") == TRUE || + g_str_equal(property, "online") == TRUE) { + if (netconfig_get_default_profile() == NULL) + netconfig_update_default_profile(service_profile); + + if (netconfig_is_cellular_profile(service_profile) == TRUE) + netconfig_cellular_state_set_service_state(NETCONFIG_CELLULAR_ONLINE); + } else if (g_str_equal(property, "failure") == TRUE || + g_str_equal(property, "disconnect") == TRUE || + g_str_equal(property, "idle") == TRUE) { + if (netconfig_get_default_profile() == NULL) + return; + + if (netconfig_is_cellular_profile(service_profile) == TRUE) + netconfig_cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE); + + if (g_str_equal(service_profile, netconfig_get_default_profile()) != TRUE) + return; + + netconfig_update_default_profile(NULL); + } else if (g_str_equal(property, "association") == TRUE || + g_str_equal(property, "configuration") == TRUE) { + if (netconfig_get_default_profile() == NULL) + return; + + if (netconfig_is_cellular_profile(service_profile) == TRUE) + netconfig_cellular_state_set_service_state(NETCONFIG_CELLULAR_IDLE); + + if (g_str_equal(service_profile, netconfig_get_default_profile()) != TRUE) + return; + + netconfig_update_default_profile(NULL); + } + } + } else if (g_str_equal(sigvalue, "Proxy") == TRUE) { + dbus_message_iter_next(&args); + dbus_message_iter_recurse(&args, &variant); + + if (netconfig_is_wifi_profile(service_profile) != TRUE || + g_strcmp0(service_profile, netconfig_get_default_profile()) != 0) + return; + + if (dbus_message_iter_get_arg_type(&variant) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(&variant, &iter1); + while (dbus_message_iter_get_arg_type(&iter1) == + DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&iter1, &iter2); + dbus_message_iter_get_basic(&iter2, &property); + + if (g_strcmp0(property, "Servers") == 0) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + + if (dbus_message_iter_get_arg_type(&iter3) != + DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(&iter3, &iter4); + if (dbus_message_iter_get_arg_type(&iter4) != + DBUS_TYPE_STRING) + return; + + dbus_message_iter_get_basic(&iter4, &value); + DBG("Proxy - [%s]", value); + + vconf_set_str(VCONFKEY_NETWORK_PROXY, value); + break; + } else if (g_strcmp0(property, "Method") == 0) { + dbus_message_iter_next(&iter2); + dbus_message_iter_recurse(&iter2, &iter3); + + if (dbus_message_iter_get_arg_type(&iter3) != + DBUS_TYPE_STRING) + return; + + dbus_message_iter_get_basic(&iter3, &value); + DBG("Method - [%s]", value); + + if (g_strcmp0(value, "direct") == 0) + vconf_set_str(VCONFKEY_NETWORK_PROXY, ""); + + break; + } + dbus_message_iter_next(&iter1); + } + } +} + +static void __netconfig_dbus_name_changed_signal_handler(DBusMessage *msg) +{ + char *name, *old, *new; + + dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &name, + DBUS_TYPE_STRING, &old, DBUS_TYPE_STRING, &new); + + if (g_strcmp0(name, CONNMAN_SERVICE) == 0 && *new == '\0') { + DBG("ConnMan destroyed: name %s, old %s, new %s", name, old, new); + + netconfig_agent_register(); + } +} + +static DBusHandlerResult __netconfig_signal_filter_handler( + DBusConnection *conn, DBusMessage *msg, void *user_data) +{ + if (msg == NULL) { + DBG("Invalid Message. Ignore"); + return DBUS_HANDLER_RESULT_HANDLED; + } + + if (dbus_message_is_signal(msg, CONNMAN_TECHNOLOGY_INTERFACE, + CONNMAN_SIGNAL_PROPERTY_CHANGED)) { + __netconfig_technology_signal_handler(msg); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, CONNMAN_SERVICE_INTERFACE, + CONNMAN_SIGNAL_PROPERTY_CHANGED)) { + __netconfig_service_signal_handler(msg); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE, + SIGNAL_INTERFACE_REMOVED)) { + if (netconfig_wifi_is_wps_enabled() == TRUE) + netconfig_wifi_wps_signal_scanaborted(); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE ".Interface", + SIGNAL_PROPERTIES_CHANGED)) { + dbus_bool_t scanning = FALSE; + void *property = &scanning; + + if (netconfig_dbus_get_basic_params_array(msg, + "Scanning", &property) == TRUE) { + if (scanning == TRUE) + netconfig_wifi_set_scanning(TRUE); + } + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE ".Interface", + SIGNAL_BSS_ADDED)) { + if (netconfig_wifi_get_ssid_scan_state() == TRUE) + netconfig_wifi_bss_added(msg); + else + netconfig_wifi_set_bss_found(TRUE); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE ".Interface", + SIGNAL_SCAN_DONE)) { + netconfig_wifi_set_scanning(FALSE); + + if (netconfig_wifi_is_wps_enabled() == TRUE) { + netconfig_wifi_wps_signal_scandone(); + if (netconfig_wifi_state_get_technology_state() < + NETCONFIG_WIFI_TECH_POWERED) + return DBUS_HANDLER_RESULT_HANDLED; + } + + if (netconfig_wifi_get_bgscan_state() != TRUE) { + if (netconfig_wifi_get_ssid_scan_state() == TRUE) + netconfig_wifi_notify_ssid_scan_done(); + else + netconfig_wifi_ssid_scan(NULL); + } else { + netconfig_wifi_check_network_notification(); + } + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, SUPPLICANT_INTERFACE ".Interface", + SIGNAL_PROPERTIES_DRIVER_HANGED)) { + ERR("Critical. Wi-Fi firmware crashed"); + + netconfig_wifi_recover_firmware(); + + return DBUS_HANDLER_RESULT_HANDLED; + } else if (dbus_message_is_signal(msg, DBUS_INTERFACE_DBUS, + "NameOwnerChanged")) { + __netconfig_dbus_name_changed_signal_handler(msg); + + return DBUS_HANDLER_RESULT_HANDLED; + } + + return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; +} + +void netconfig_register_signal(void) +{ + DBusError err; + DBusConnection *conn = NULL; + + dbus_error_init(&err); + conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (conn == NULL) { + ERR("Failed to get system bus [%s]", err.message); + dbus_error_free(&err); + return; + } + + signal_connection = conn; + + dbus_connection_setup_with_g_main(conn, NULL); + + /* listening to messages from all objects as no path is specified */ + /* see signals from the given interface */ + dbus_bus_add_match(conn, CONNMAN_TECHNOLOGY_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, CONNMAN_SERVICE_STATE_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, CONNMAN_SERVICE_PROXY_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, SUPPLICANT_INTERFACE_REMOVED_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, + SUPPLICANT_INTERFACE_PROPERTIESCHANGED_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, SUPPLICANT_INTERFACE_BSSADDED_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, SUPPLICANT_INTERFACE_SCANDONE_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, + SUPPLICANT_INTERFACE_DRIVERHANGED_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + dbus_bus_add_match(conn, CONNMAN_SERVICE_NAMECHANGED_SIGNAL_FILTER, &err); + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) { + ERR("Match error (%s)", err.message); + dbus_error_free(&err); + return; + } + + if (dbus_connection_add_filter(conn, + __netconfig_signal_filter_handler, NULL, NULL) == FALSE) { + ERR("Error! dbus_connection_add_filter() failed"); + return; + } + + INFO("Successfully register DBus signal filters"); + + /* In case ConnMan precedes this signal register, + * net-config should update the default connected profile. + */ + netconfig_update_default(); +} + +void netconfig_deregister_signal(void) +{ + if (signal_connection == NULL) { + ERR("Already de-registered. Nothing to be done"); + return; + } + + dbus_connection_remove_filter(signal_connection, + __netconfig_signal_filter_handler, NULL); + INFO("Successfully remove DBus signal filters"); + + dbus_connection_unref(signal_connection); + signal_connection = NULL; +} diff --git a/wearable/src/utils/emulator.c b/wearable/src/utils/emulator.c new file mode 100644 index 0000000..921a20f --- /dev/null +++ b/wearable/src/utils/emulator.c @@ -0,0 +1,120 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "emulator.h" + +static gboolean netconfig_is_emulated = FALSE; + +static gboolean __netconfig_emulator_test_emulation_env(void) +{ + struct utsname buf; + const char *EMUL_UTSNAME_MACHINE_SUFFIX = "emulated"; + + DBG("Test emulation environment"); + + uname(&buf); + + if (g_str_has_suffix(buf.machine, EMUL_UTSNAME_MACHINE_SUFFIX) == TRUE) + return TRUE; + + return FALSE; +} + +static void __netconfig_emulator_set_ip(void) +{ + const char EMUL_IFNAME[] = "eth0"; + char ip[30] = { 0, }; + int sockfd = 0; + struct ifreq ifr; + + sockfd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (sockfd < 0) { + ERR("Failed to open socket"); + return; + } + + memset(&ifr, 0, sizeof(struct ifreq)); + g_strlcpy((char *)ifr.ifr_name, EMUL_IFNAME, 16); + + if (ioctl(sockfd, SIOCGIFADDR, &ifr) < 0) { + ERR("Failed to get IP address"); + + close(sockfd); + return; + } + + close(sockfd); + + g_strlcpy(ip, + inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr), 30); + + vconf_set_str(VCONFKEY_NETWORK_IP, ip); +} + +static void __netconfig_emulator_set_proxy(void) +{ + const char HTTP_PROXY[] = "http_proxy"; + char *proxy = NULL; + + proxy = getenv(HTTP_PROXY); + DBG("Get system proxy: %s", proxy); + + if(proxy != NULL) + vconf_set_str(VCONFKEY_NETWORK_PROXY, proxy); +} + +static void __netconfig_emulator_set_network_state(void) +{ + vconf_set_int(VCONFKEY_NETWORK_CONFIGURATION_CHANGE_IND, 1); + vconf_set_int(VCONFKEY_NETWORK_STATUS, VCONFKEY_NETWORK_CELLULAR); + vconf_set_int(VCONFKEY_DNET_STATE, VCONFKEY_DNET_NORMAL_CONNECTED); +} + +static void __netconfig_emulator_config_emul_env(void) +{ + __netconfig_emulator_set_ip(); + __netconfig_emulator_set_proxy(); + __netconfig_emulator_set_network_state(); +} + +gboolean netconfig_emulator_is_emulated(void) +{ + return netconfig_is_emulated; +} + +void netconfig_emulator_test_and_start(void) +{ + netconfig_is_emulated = __netconfig_emulator_test_emulation_env(); + + DBG("Emulation environment tested: %s", netconfig_is_emulated ? + "It's emulated" : "Not emulated"); + + if (netconfig_is_emulated == TRUE) + __netconfig_emulator_config_emul_env(); +} diff --git a/wearable/src/utils/log.c b/wearable/src/utils/log.c new file mode 100644 index 0000000..a8d7cb6 --- /dev/null +++ b/wearable/src/utils/log.c @@ -0,0 +1,126 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" + +#define LOG_FILE_PATH "/var/log/netconfig.log" +#define MAX_LOG_SIZE 2 * 1024 * 1024 +#define MAX_LOG_COUNT 2 + +static FILE *log_file = NULL; + +static inline void __netconfig_log_update_file_revision(int rev) +{ + int next_log_rev = 0; + char *log_file = NULL; + char *next_log_file = NULL; + + next_log_rev = rev + 1; + + log_file = g_strdup_printf("%s.%d", LOG_FILE_PATH, rev); + next_log_file = g_strdup_printf("%s.%d", LOG_FILE_PATH, next_log_rev); + + if (next_log_rev >= MAX_LOG_COUNT) + remove(next_log_file); + + if (access(next_log_file, F_OK) == 0) + __netconfig_log_update_file_revision(next_log_rev); + + if (rename(log_file, next_log_file) != 0) + remove(log_file); + + g_free(log_file); + g_free(next_log_file); +} + +static inline void __netconfig_log_make_backup(void) +{ + const int rev = 0; + char *backup = NULL; + + backup = g_strdup_printf("%s.%d", LOG_FILE_PATH, rev); + + if (access(backup, F_OK) == 0) + __netconfig_log_update_file_revision(rev); + + if (rename(LOG_FILE_PATH, backup) != 0) + remove(LOG_FILE_PATH); + + g_free(backup); +} + +static inline void __netconfig_log_get_local_time(char *strtime, const int size) +{ + time_t buf; + struct tm *local_ptm; + + time(&buf); + buf = time(NULL); + local_ptm = localtime(&buf); + + strftime(strtime, size, "%m/%d %H:%M:%S", local_ptm); +} + +void __netconfig_debug(const char *format, ...) +{ + va_list ap; + int log_size = 0; + struct stat buf; + char str[256]; + char strtime[40]; + + if (log_file == NULL) + log_file = (FILE *)fopen(LOG_FILE_PATH, "a+"); + + if (log_file == NULL) + return; + + va_start(ap, format); + + if (fstat(fileno(log_file), &buf) == 0) + log_size = buf.st_size; + + if (log_size >= MAX_LOG_SIZE) { + fclose(log_file); + log_file = NULL; + + __netconfig_log_make_backup(); + + log_file = (FILE *)fopen(LOG_FILE_PATH, "a+"); + + if (log_file == NULL) { + va_end(ap); + return; + } + } + + __netconfig_log_get_local_time(strtime, sizeof(strtime)); + + if (vsnprintf(str, sizeof(str), format, ap) > 0) + fprintf(log_file, "%s %s", strtime, str); + + va_end(ap); +} diff --git a/wearable/src/utils/network-accessibility.c b/wearable/src/utils/network-accessibility.c new file mode 100644 index 0000000..379dd37 --- /dev/null +++ b/wearable/src/utils/network-accessibility.c @@ -0,0 +1,555 @@ +/* + * Internet-accessibility check + * + * Copyright 2012 Samsung Electronics Co., Ltd + * + * Licensed under the Flora License, Version 1.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.tizenopensource.org/license + * + * 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 +#include +#include +#include +#include +#include +#include + +#include "log.h" +#include "util.h" +#include "wifi-agent.h" +#include "netsupplicant.h" +#include "network-state.h" +#include "network-accessibility.h" + +#define BUF_SIZE 2048 +#define NETCONFIG_INTERNET_CHECK_TIMEOUT 3 + +enum netconfig_internet_check_state { + INTERNET_CHECK_STATE_NONE, + INTERNET_CHECK_STATE_DNS_CHECK, + INTERNET_CHECK_STATE_PACKET_CHECK +}; + +struct internet_params { + int fd; + char *addr; + int port; + guint transport_watch; + guint send_watch; + gboolean header_done; + gboolean request_started; + GCancellable *resolv_cancel; +}; + +const static char* url_list[] = { + "www.google.com", + "www.msn.com", + "www.yahoo.com", + "m.google.com", + "www.amazon.com", + "www.youtube.com" + }; + +static guint timer_id = 0; +static const char *proxy_addr = NULL; +static gboolean perform_recheck = TRUE; +struct internet_params *net_params = NULL; +static gboolean is_internet_available = FALSE; +const static int url_list_num = 6; +static int url_index = 0; +static char * redirect_url1 = NULL; +static char * redirect_url2 = NULL; +static enum netconfig_internet_check_state check_state = + INTERNET_CHECK_STATE_NONE; + +static void __netconfig_connect_sockets(void); +static void __internet_check_state( + enum netconfig_internet_check_state state); + +gboolean netconfig_get_internet_status() +{ + return is_internet_available; +} + +static void __netconfig_update_internet_status(unsigned char *reply) +{ + /* If the HTTP response is either 302 or 200 with redirection, + * then no Internet is available */ + char *temp = NULL; + is_internet_available = FALSE; + + if (NULL != reply) { + if ((NULL != g_strrstr((char*)reply, "HTTP/1.1 200")) && + (NULL != g_strrstr((char*)reply, "auth action"))) { + DBG("200 OK but redirection found so:: Internet is un-available"); + } else if (NULL != g_strrstr((char*)reply, "HTTP/1.1 302")) { + DBG("302:: Internet is un-available"); + } else if ((temp = g_strrstr((char*)reply, "Location:")) != NULL) { + char * location = strtok(temp, "\r"); + if (location != NULL) { + DBG("%s", location); + if (redirect_url1 == NULL) + redirect_url1 = g_strdup(location + strlen("Location: ")); + else if (redirect_url2 == NULL) + redirect_url2 = g_strdup(location + strlen("Location: ")); + + if (redirect_url1 != NULL && redirect_url2 != NULL) { + DBG("[%s] [%s]", redirect_url1, redirect_url2); + if (g_strcmp0(redirect_url1, redirect_url2) == 0) { + DBG("Internet is un-available(Redirection to Error page)"); + is_internet_available = FALSE; + } else + is_internet_available = TRUE; + + g_free(redirect_url1); + g_free(redirect_url2); + redirect_url1 = NULL; + redirect_url2 = NULL; + } + } + } else { + is_internet_available = TRUE; + DBG("Internet is available"); + } + } + + if (is_internet_available == TRUE) + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL); +} + +static gboolean __netconfig_data_activity_timeout(gpointer data) +{ + DBG("Timer timed-out"); + enum netconfig_internet_check_state prev_state = + (enum netconfig_internet_check_state)data; + INFO("Prev_state: state=%d (1:dns check / 2:packet check)",prev_state); + + if (net_params == NULL) + return FALSE; + + if (TRUE == perform_recheck && prev_state != INTERNET_CHECK_STATE_NONE) { + perform_recheck = FALSE; + if (prev_state == INTERNET_CHECK_STATE_DNS_CHECK) { + net_params->request_started = FALSE; + netconfig_check_internet_accessibility(); + } else /* (state == NETCONFIG_DATA_ACTIVITY_STATE_PACKET_CHECK) */ + __netconfig_connect_sockets(); + return FALSE; + } else { + perform_recheck = TRUE; + __internet_check_state(INTERNET_CHECK_STATE_NONE); + } + + return FALSE; +} + +static void __netconfig_internet_check_timer_stop(void) +{ + if (timer_id != 0) + netconfig_stop_timer(&timer_id); +} + +static void __netconfig_internet_check_timer_start( + enum netconfig_internet_check_state state) +{ + static guint timeout = 0; + if (timer_id != 0) { + DBG("netconfig_data_activity_timer is already running, so stop it"); + __netconfig_internet_check_timer_stop(); + } + + if (state == INTERNET_CHECK_STATE_NONE) + return; + else if (state == INTERNET_CHECK_STATE_DNS_CHECK) + timeout = NETCONFIG_INTERNET_CHECK_TIMEOUT; + else if (state == INTERNET_CHECK_STATE_PACKET_CHECK) + timeout = NETCONFIG_INTERNET_CHECK_TIMEOUT; + + netconfig_start_timer_seconds(timeout, + __netconfig_data_activity_timeout, + (void *)state, + &timer_id); +} + +static void __internet_check_state( + enum netconfig_internet_check_state state) +{ + if (check_state == state) + return; + + INFO("state change (%d) -> (%d)", check_state, state); + switch (state) { + case INTERNET_CHECK_STATE_DNS_CHECK: + __netconfig_internet_check_timer_start(state); + break; + case INTERNET_CHECK_STATE_PACKET_CHECK: + if (check_state == INTERNET_CHECK_STATE_DNS_CHECK) + __netconfig_internet_check_timer_stop(); + + __netconfig_internet_check_timer_start(state); + break; + case INTERNET_CHECK_STATE_NONE: + switch (check_state) { + case INTERNET_CHECK_STATE_DNS_CHECK: + case INTERNET_CHECK_STATE_PACKET_CHECK: + __netconfig_internet_check_timer_stop(); + netconfig_stop_internet_check(); + break; + default: + break; + } + break; + } + check_state = state; +} + +void netconfig_stop_internet_check(void) +{ + if (net_params == NULL) + return; + + net_params->header_done = FALSE; + net_params->request_started = FALSE; + + if (net_params->resolv_cancel != NULL) { + g_cancellable_cancel(net_params->resolv_cancel); + g_object_unref(net_params->resolv_cancel); + net_params->resolv_cancel = NULL; + } + + if (net_params->transport_watch > 0) { + g_source_remove(net_params->transport_watch); + net_params->transport_watch = 0; + } + + if (net_params->send_watch > 0) { + g_source_remove(net_params->send_watch); + net_params->send_watch = 0; + } + + if (net_params->fd > 0) { + close(net_params->fd); + net_params->fd = -1; + } + + if (net_params->addr != NULL) { + g_free(net_params->addr); + net_params->addr = NULL; + } + + g_free(net_params); + net_params = NULL; +} + +static gboolean __received_data_event(GIOChannel *channel, + GIOCondition condition, gpointer data) +{ + int n, fd; + unsigned char buf[BUF_SIZE] = { 0, }; + + if (net_params == NULL) + return FALSE; + + if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) + goto cleanup; + + fd = g_io_channel_unix_get_fd(channel); + if (fd < 0) + goto cleanup; + + n = read(fd, buf, BUF_SIZE - 1); + DBG("Received %d bytes[%s]", n, buf); + buf[BUF_SIZE - 1] = '\0'; + + if (n < 0) { + ERR("read failed. %s", strerror(errno)); + + goto cleanup; + } else if (n == 0) { + INFO("connection closed"); + + goto cleanup; + } + + /* We got data from server successfully */ + __netconfig_update_internet_status(buf); + __internet_check_state(INTERNET_CHECK_STATE_NONE); + + return TRUE; + +cleanup: + /* Fail to get data from server */ + __internet_check_state(INTERNET_CHECK_STATE_NONE); + + return FALSE; +} + +static gboolean __send_data_event(GIOChannel *channel, + GIOCondition condition, gpointer data) +{ + int n, fd; + const char *request_data = + "GET /index.html HTTP/1.1\r\nHost: connman.net\r\n\r\n"; + + if (net_params == NULL) + return FALSE; + + if (condition & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) + goto cleanup; + + fd = g_io_channel_unix_get_fd(channel); + if (fd < 0) + goto cleanup; + + /* We don't need to send anymore. Just return here.*/ + /* Socket will be closed received part*/ + if (net_params->header_done == TRUE) + return FALSE; + + n = send(fd, request_data, strlen(request_data), 0); + DBG("Sent %d bytes", n); + + if (n < 0) { + ERR("send failed. %s", strerror(errno)); + + goto cleanup; + } else if (n == 0) { + INFO("connection closed"); + + goto cleanup; + } + + net_params->header_done = TRUE; + return TRUE; + +cleanup: + __internet_check_state(INTERNET_CHECK_STATE_NONE); + + return FALSE; +} + +static void __netconfig_connect_sockets(void) +{ + GIOFlags flags; + struct sockaddr_in addr; + GIOChannel *channel = NULL; + int sock; + + if (net_params == NULL || net_params->addr == NULL) + return; + + sock = socket(PF_INET, SOCK_STREAM, 0); + if (sock < 0) + goto cleanup; + + if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, + WIFI_IFNAME, strlen(WIFI_IFNAME) + 1) < 0) { + ERR("Bind to device error"); + close(sock); + goto cleanup; + } + + memset(&addr, 0, sizeof(struct sockaddr_in)); + addr.sin_family = AF_INET; + addr.sin_addr.s_addr = inet_addr(net_params->addr); + addr.sin_port = htons(net_params->port); + + /* Register Watch */ + channel = g_io_channel_unix_new(sock); + + flags = g_io_channel_get_flags(channel); + g_io_channel_set_flags(channel, flags | G_IO_FLAG_NONBLOCK, NULL); + g_io_channel_set_encoding(channel, NULL, NULL); + g_io_channel_set_buffered(channel, FALSE); + + if (connect(sock, (struct sockaddr *)&addr, + sizeof(struct sockaddr_in)) < 0) { + if (errno != EINPROGRESS) { + INFO("connect fail"); + close(sock); + goto cleanup; + } + } + + DBG("Connect successful"); + + net_params->fd = sock; + net_params->transport_watch = g_io_add_watch(channel, + (GIOCondition) (G_IO_IN | G_IO_HUP | G_IO_NVAL | G_IO_ERR), + (GIOFunc) __received_data_event, NULL); + net_params->send_watch = g_io_add_watch(channel, + (GIOCondition) (G_IO_OUT | G_IO_HUP | G_IO_NVAL | G_IO_ERR), + (GIOFunc) __send_data_event, NULL); + + __internet_check_state(INTERNET_CHECK_STATE_PACKET_CHECK); + return; + + cleanup: + __internet_check_state(INTERNET_CHECK_STATE_NONE); +} + +static void __netconfig_obtain_host_ip_addr_cb(GObject *src, + GAsyncResult *res, + gpointer user_data) +{ + GList *list, *cur; + GInetAddress *addr; + gchar *str_addr; + + if (net_params == NULL) + return; + + if (check_state == INTERNET_CHECK_STATE_NONE) + return; + + list = g_resolver_lookup_by_name_finish((GResolver *)src, res, NULL); + if (!list) { + INFO("no data"); + goto cleanup; + } + + for (cur = list; cur; cur = cur->next) { + addr = cur->data; + str_addr = g_inet_address_to_string(addr); + if (!str_addr) + continue; + + if (net_params != NULL) { + g_free(net_params->addr); + net_params->addr = str_addr; + } + + g_object_unref(cur->data); + break; + } + + g_list_free(list); + + if (net_params->addr == NULL) + goto cleanup; + + net_params->port = 80; + __netconfig_connect_sockets(); + + return; + +cleanup: + __internet_check_state(INTERNET_CHECK_STATE_NONE); +} + +gboolean __netconfig_obtain_host_ip_addr(void) +{ + char *host, *addr, *port; + + if (net_params == NULL) + return FALSE; + + if (net_params->request_started == TRUE) + return FALSE; + else + net_params->request_started = TRUE; + + if (net_params->addr != NULL) + return TRUE; + + proxy_addr = netconfig_get_default_proxy(); + DBG("Proxy(%s)", proxy_addr); + + if (++url_index >= url_list_num) + url_index = 0; + + DBG("addr (%s)", url_list[url_index]); + + if (proxy_addr == NULL) { + GResolver *r = NULL; + net_params->resolv_cancel = g_cancellable_new(); + r = g_resolver_get_default(); + g_resolver_lookup_by_name_async(r, + url_list[url_index], + net_params->resolv_cancel, + __netconfig_obtain_host_ip_addr_cb, + NULL); + __internet_check_state(INTERNET_CHECK_STATE_DNS_CHECK); + return FALSE; + } else { + host = g_strdup(proxy_addr); + if (host == NULL) + goto cleanup; + + addr = strtok(host, ":"); + if (addr == NULL) + goto cleanup; + + port = strrchr(proxy_addr, ':'); + if (port == NULL) + goto cleanup; + else { + char *end; + int tmp = strtol(port + 1, &end, 10); + + if (*end == '\0') { + *port = '\0'; + net_params->port = tmp; + } + } + g_free(net_params->addr); + net_params->addr = g_strdup(addr); + + g_free(host); + } + return TRUE; + +cleanup: + g_free(host); + netconfig_stop_internet_check(); + + return FALSE; +} + +void netconfig_check_internet_accessibility(void) +{ + DBG("::Entry"); + + if (net_params == NULL) { + net_params = g_try_malloc0(sizeof(struct internet_params)); + if (net_params == NULL) + return; + net_params->fd = -1; + } + + if ((check_state != INTERNET_CHECK_STATE_NONE) || + (net_params->request_started == TRUE)) { + DBG("Older query in progress"); + return; + } + + is_internet_available = FALSE; + + /* If the host IP is resolved, directly go for connecting to sockets*/ + if (__netconfig_obtain_host_ip_addr() == TRUE) { + __netconfig_connect_sockets(); + } +} diff --git a/wearable/src/utils/util.c b/wearable/src/utils/util.c new file mode 100644 index 0000000..d0b21c0 --- /dev/null +++ b/wearable/src/utils/util.c @@ -0,0 +1,511 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "neterror.h" +#include "wifi-state.h" + +static gboolean netconfig_device_picker_test = FALSE; + +GKeyFile *netconfig_keyfile_load(const char *pathname) +{ + GKeyFile *keyfile = NULL; + GError *error = NULL; + + keyfile = g_key_file_new(); + if (g_key_file_load_from_file(keyfile, pathname, 0, &error) != TRUE) { + DBG("Unable to open %s, error %s", pathname, error->message); + g_error_free(error); + + g_key_file_free(keyfile); + keyfile = NULL; + } + + return keyfile; +} + +void netconfig_keyfile_save(GKeyFile *keyfile, const char *pathname) +{ + gsize size = 0; + GError *error = NULL; + gchar *keydata = NULL; + gchar *needle = NULL, *directory = NULL; + + directory = g_strdup(pathname); + needle = g_strrstr(directory, "/"); + + if (needle != NULL) + *needle = '\0'; + + if (directory == NULL || (*directory) == '\0') { + g_free(directory); + return; + } + + if (g_file_test(directory, G_FILE_TEST_IS_DIR) != TRUE) { + if (g_mkdir_with_parents(directory, + S_IRUSR | S_IWUSR | S_IXUSR) != 0) { + g_free(directory); + return; + } + } + g_free(directory); + + keydata = g_key_file_to_data(keyfile, &size, &error); + if (g_file_set_contents(pathname, keydata, size, &error) != TRUE) { + DBG("Unable to save %s, error %s", pathname, error->message); + g_error_free(error); + } + + chmod(pathname, S_IRUSR | S_IWUSR); + + g_free(keydata); + + g_key_file_free(keyfile); +} + +void netconfig_start_timer_seconds(guint secs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id) +{ + guint t_id = 0; + + if (callback == NULL) { + ERR("callback function is NULL"); + return; + } + + if ((timer_id != NULL && *timer_id != 0)) { + ERR("timer already is registered"); + return; + } + + t_id = g_timeout_add_seconds(secs, callback, user_data); + + if (t_id == 0) { + ERR("Can't add timer"); + return; + } + + if (timer_id != NULL) + *timer_id = t_id; +} + +void netconfig_start_timer(guint msecs, + gboolean(*callback) (gpointer), void *user_data, guint *timer_id) +{ + guint t_id = 0; + + INFO("Register timer with callback pointer (%p)", callback); + + if (callback == NULL) { + ERR("callback function is NULL"); + return; + } + + if ((timer_id != NULL && *timer_id != 0)) { + ERR("timer already is registered"); + return; + } + + t_id = g_timeout_add(msecs, callback, user_data); + + if (t_id == 0) { + ERR("Can't add timer"); + return; + } + + if (timer_id != NULL) + *timer_id = t_id; +} + +void netconfig_stop_timer(guint *timer_id) +{ + if (timer_id == NULL) { + ERR("timer is NULL"); + return; + } + + if (*timer_id != 0) { + g_source_remove(*timer_id); + *timer_id = 0; + } +} + +static gboolean __netconfig_test_device_picker() +{ + char *favorite_wifi_service = NULL; + + favorite_wifi_service = netconfig_wifi_get_favorite_service(); + if (favorite_wifi_service != NULL) { + g_free(favorite_wifi_service); + return FALSE; + } + + return TRUE; +} + +static void __netconfig_pop_device_picker(void) +{ + bundle *b = NULL; + int wifi_ug_state = 0; + + vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); + if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) + return; + + b = bundle_create(); + + DBG("Launch Wi-Fi device picker"); + syspopup_launch("wifi-qs", b); + + bundle_free(b); +} + +static gboolean __netconfig_wifi_try_device_picker(gpointer data) +{ + if (__netconfig_test_device_picker() == TRUE) + __netconfig_pop_device_picker(); + + return FALSE; +} + +static guint __netconfig_wifi_device_picker_timer_id(gboolean is_set_method, + guint timer_id) +{ + static guint netconfig_wifi_device_picker_service_timer = 0; + + if (is_set_method != TRUE) + return netconfig_wifi_device_picker_service_timer; + + if (netconfig_wifi_device_picker_service_timer != timer_id) + netconfig_wifi_device_picker_service_timer = timer_id; + + return netconfig_wifi_device_picker_service_timer; +} + +static void __netconfig_wifi_device_picker_set_timer_id(guint timer_id) +{ + __netconfig_wifi_device_picker_timer_id(TRUE, timer_id); +} + +static guint __netconfig_wifi_device_picker_get_timer_id(void) +{ + return __netconfig_wifi_device_picker_timer_id(FALSE, -1); +} + +void netconfig_wifi_enable_device_picker_test(void) +{ + netconfig_device_picker_test = TRUE; +} + +void netconfig_wifi_device_picker_service_start(void) +{ + int wifi_ug_state; + const int NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL = 700; + guint timer_id = 0; + + if (netconfig_device_picker_test == TRUE) + netconfig_device_picker_test = FALSE; + else + return; + + vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &wifi_ug_state); + if (wifi_ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) + return; + + DBG("Register device picker timer with %d milliseconds", + NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL); + + netconfig_start_timer(NETCONFIG_WIFI_DEVICE_PICKER_INTERVAL, + __netconfig_wifi_try_device_picker, NULL, &timer_id); + + __netconfig_wifi_device_picker_set_timer_id(timer_id); +} + +void netconfig_wifi_device_picker_service_stop(void) +{ + guint timer_id = 0; + + timer_id = __netconfig_wifi_device_picker_get_timer_id(); + if (timer_id == 0) + return; + + DBG("Clear device picker timer with timer_id %d", timer_id); + + netconfig_stop_timer(&timer_id); + + __netconfig_wifi_device_picker_set_timer_id(timer_id); +} + +gboolean netconfig_is_wifi_direct_on(void) +{ + int wifi_direct_state = 0; + + vconf_get_int(VCONFKEY_WIFI_DIRECT_STATE, &wifi_direct_state); + + DBG("Wi-Fi direct mode %d", wifi_direct_state); + return (wifi_direct_state != 0) ? TRUE : FALSE; +} + +gboolean netconfig_is_wifi_tethering_on(void) +{ + int wifi_tethering_state = 0; + + vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &wifi_tethering_state); + + DBG("Wi-Ti tethering mode %d", wifi_tethering_state); + if (wifi_tethering_state & VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI) + return TRUE; + + return FALSE; +} + +gboolean netconfig_interface_up(const char *ifname) +{ + int fd; + struct ifreq ifr; + + fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (fd < 0) + return FALSE; + + memset(&ifr, 0, sizeof(ifr)); + g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; + } + + ifr.ifr_flags |= (IFF_UP | IFF_DYNAMIC); + if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; + } + + close(fd); + + DBG("Successfully activated wireless interface"); + return TRUE; +} + +gboolean netconfig_interface_down(const char *ifname) +{ + int fd; + struct ifreq ifr; + + fd = socket(PF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0); + if (fd < 0) + return FALSE; + + memset(&ifr, 0, sizeof(ifr)); + g_strlcpy((char *)ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + + if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; + } + + ifr.ifr_flags = (ifr.ifr_flags & ~IFF_UP) | IFF_DYNAMIC; + if (ioctl(fd, SIOCSIFFLAGS, &ifr) < 0) { + close(fd); + return FALSE; + } + + close(fd); + + DBG("Successfully de-activated wireless interface"); + return TRUE; +} + +int netconfig_execute_file(const char *file_path, + char *const args[], char *const envs[]) +{ + pid_t pid = 0; + int status = 0; + int rv = 0; + errno = 0; + register unsigned int index = 0; + + while (args[index] != NULL) { + DBG("%s", args[index]); + index++; + } + + if (!(pid = fork())) { + DBG("pid(%d), ppid (%d)", getpid(), getppid()); + DBG("Inside child, exec (%s) command", file_path); + + errno = 0; + if (execve(file_path, args, envs) == -1) { + DBG("Fail to execute command (%s)", strerror(errno)); + exit(1); + } + } else if (pid > 0) { + if (waitpid(pid, &status, 0) == -1) + DBG("wait pid (%u) status (%d)", pid, status); + + if (WIFEXITED(status)) { + rv = WEXITSTATUS(status); + DBG("exited, status=%d", rv); + } else if (WIFSIGNALED(status)) { + DBG("killed by signal %d", WTERMSIG(status)); + } else if (WIFSTOPPED(status)) { + DBG("stopped by signal %d", WSTOPSIG(status)); + } else if (WIFCONTINUED(status)) { + DBG("continued"); + } + + return rv; + } + + DBG("failed to fork (%s)", strerror(errno)); + return -EIO; +} + +gboolean netconfig_iface_wifi_launch_direct(NetconfigWifi *wifi, GError **error) +{ + int ret = 0; + + DBG("Launch Wi-Fi direct daemon"); + + const char *path = "/usr/bin/wifi-direct-server.sh"; + char *const args[] = { "wifi-direct-server.sh", "start", NULL }; + char *const envs[] = { NULL }; + + ret = netconfig_execute_file(path, args, envs); + if (ret < 0) { + ERR("Failed to launch Wi-Fi direct daemon"); + + netconfig_error_wifi_direct_failed(error); + return FALSE; + } + + return TRUE; +} + +gboolean netconfig_send_notification_to_net_popup(const char * noti, const char * ssid) +{ + int ret = 0; + bundle *b; + static gboolean is_found_noti_exists = FALSE; + static gboolean is_portal_noti_exists = FALSE; + + if (noti == NULL) { + ERR("Invalid notification"); + return FALSE; + } + + if (g_strcmp0(noti, NETCONFIG_DEL_FOUND_AP_NOTI) == 0) { + if (is_found_noti_exists == FALSE) + return TRUE; + + is_found_noti_exists = FALSE; + } else if (g_strcmp0(noti, NETCONFIG_ADD_FOUND_AP_NOTI) == 0) { + if (is_found_noti_exists == TRUE) + return TRUE; + + is_found_noti_exists = TRUE; + } else if (g_strcmp0(noti, NETCONFIG_ADD_PORTAL_NOTI) == 0) { + if (is_portal_noti_exists == TRUE) + return TRUE; + + is_portal_noti_exists = TRUE; + } else if (g_strcmp0(noti, NETCONFIG_DEL_PORTAL_NOTI) == 0) { + if (is_portal_noti_exists == FALSE) + return TRUE; + + is_portal_noti_exists = FALSE; + } + + b = bundle_create(); + bundle_add(b, "_SYSPOPUP_TYPE_", noti); + + if (ssid != NULL) { + DBG("ssid (%s)", ssid); + bundle_add(b, "_AP_NAME_", ssid); + } + + ret = aul_launch_app("net.netpopup", b); + + bundle_free(b); + + if (ret < 0) { + ERR("Unable to launch noti-popup. Err = %d", ret); + return FALSE; + } + + DBG("Successfully sent notification (%s)", noti); + return TRUE; +} + +int netconfig_send_message_to_net_popup(const char *title, + const char *content, const char *type, const char *ssid) +{ + int ret = 0; + bundle *b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", title); + bundle_add(b, "_SYSPOPUP_CONTENT_", content); + bundle_add(b, "_SYSPOPUP_TYPE_", type); + bundle_add(b, "_AP_NAME_", ssid); + + ret = aul_launch_app("net.netpopup", b); + + bundle_free(b); + + return ret; +} + +void netconfig_set_vconf_int(const char * key, int value) +{ + int ret = 0; + + DBG("[ %s : %d ]", key, value); + + ret = vconf_set_int(key, value); + if(ret != VCONF_OK) + ERR("Failed to set vconf!!!!!"); +} + +void netconfig_set_vconf_str(const char * key, const char * value) +{ + int ret = 0; + + DBG("[ %s : %s ]", key, value); + + ret = vconf_set_str(key, value); + if(ret != VCONF_OK) + ERR("Failed to set vconf!!!!!"); +} + diff --git a/wearable/src/wifi-agent.c b/wearable/src/wifi-agent.c new file mode 100644 index 0000000..43e3d87 --- /dev/null +++ b/wearable/src/wifi-agent.c @@ -0,0 +1,603 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "wifi.h" +#include "netdbus.h" +#include "wifi-agent.h" +#include "wifi-state.h" +#include "wifi-eap-config.h" +#include "network-state.h" +#include "network-accessibility.h" + +#define NETCONFIG_AGENT_FIELD_NAME "Name" +#define NETCONFIG_AGENT_FIELD_SSID "SSID" +#define NETCONFIG_AGENT_FIELD_IDENTITY "Identity" +#define NETCONFIG_AGENT_FIELD_PASSPHRASE "Passphrase" +#define NETCONFIG_AGENT_FIELD_WPS "WPS" +#define NETCONFIG_AGENT_FIELD_WPS_PBC "WPS_PBC" +#define NETCONFIG_AGENT_FIELD_WPS_PIN "WPS_PIN" + +#define NETCONFIG_AGENT_ERR_CONNECT_FAILED "connect-failed" +#define QUERY_FOR_INTERNET_INTERVAL 20 +#define TIMER_THRESHOLD 120 + +static gboolean __netconfig_wifi_portal_login_timeout(gpointer data); +static void __wifi_state_monitor(enum netconfig_wifi_service_state state, + void *user_data); +static gboolean __check_ignore_portal_list(const char * ssid); + +static gboolean is_monitor_notifier_registered = FALSE; +static struct netconfig_wifi_state_notifier wifi_state_monitor_notifier = { + .netconfig_wifi_state_changed = __wifi_state_monitor, + .user_data = NULL, +}; + +struct poll_timer_data { + guint time_elapsed; + guint timer_id; + void* data; +}; + +struct netconfig_wifi_agent { + GByteArray *ssid; + char *name; + char *identity; + char *passphrase; + char *wps_pin; + gboolean wps_pbc; +}; + +static struct netconfig_wifi_agent agent; +static struct poll_timer_data timer_data = {QUERY_FOR_INTERNET_INTERVAL, 0, NULL}; + +static gboolean __check_ignore_portal_list(const char * ssid) +{ + return FALSE; +} + +static void __wifi_state_monitor(enum netconfig_wifi_service_state state, + void *user_data) +{ + DBG("Wi-Fi state: %x", state); + + if (state == NETCONFIG_WIFI_CONNECTED) + return; + + if (is_monitor_notifier_registered == TRUE) { + netconfig_wifi_state_notifier_unregister(&wifi_state_monitor_notifier); + is_monitor_notifier_registered = FALSE; + } + + /* suspend if Internet check activity in progress */ + if (timer_data.timer_id == 0) + return; + + netconfig_stop_timer(&timer_data.timer_id); + netconfig_stop_internet_check(); + + DBG("Stopped Internet accessibility check"); +} + +static void __netconfig_agent_clear_fields(void) +{ + g_byte_array_free(agent.ssid, TRUE); + g_free(agent.name); + g_free(agent.identity); + g_free(agent.passphrase); + g_free(agent.wps_pin); + + agent.ssid = NULL; + agent.name = NULL; + agent.identity = NULL; + agent.passphrase = NULL; + agent.wps_pin = NULL; + agent.wps_pbc = FALSE; +} + +gboolean netconfig_agent_register(void) +{ + DBusError error; + DBusMessageIter iter; + DBusMessage *reply = NULL; + DBusMessage *message = NULL; + DBusConnection *connection = NULL; + const char *path = NETCONFIG_WIFI_PATH; + + DBG("ConnMan agent register"); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + return FALSE; + } + + message = dbus_message_new_method_call(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, "RegisterAgent"); + if (message == NULL) { + ERR("Failed DBus method call"); + dbus_connection_unref(connection); + return FALSE; + } + + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_append_basic(&iter, DBUS_TYPE_OBJECT_PATH, &path); + + do { + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + 10 * 1000, &error); + + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + if (g_strcmp0(error.name, + "net.connman.Error.AlreadyExists") == 0) { + dbus_error_free(&error); + + break; + } else { + ERR("Fail to register agent [%s: %s]", + error.name, error.message); + dbus_error_free(&error); + } + } else { + ERR("Fail to register agent"); + } + } + + if (reply != NULL) + dbus_message_unref(reply); + + sleep(1); + } while (TRUE); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return TRUE; +} + +gboolean netconfig_agent_unregister(void) +{ + gboolean reply; + char param0[] = "objpath:" NETCONFIG_WIFI_PATH; + char *param_array[] = { NULL, NULL }; + + param_array[0] = param0; + + DBG("ConnMan agent unregister"); + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "UnregisterAgent", param_array, NULL); + + if (reply != TRUE) + ERR("Fail to unregister agent"); + + /* Clearing the agent fields */ + __netconfig_agent_clear_fields(); + + return reply; +} + +gboolean netconfig_wifi_set_agent_field_for_eap_network( + const char *name, const char *identity, const char *passphrase) +{ + int name_len; + + if (name == NULL) + return FALSE; + + __netconfig_agent_clear_fields(); + + name_len = strlen(name); + agent.ssid = g_byte_array_sized_new(name_len); + agent.ssid->len = name_len; + memcpy(agent.ssid->data, name, name_len); + + if (identity) + agent.identity = g_strdup(identity); + + if (passphrase) + agent.passphrase = g_strdup(passphrase); + + DBG("Successfully configured for EAP network"); + + return TRUE; +} + +gboolean netconfig_iface_wifi_set_field(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context) +{ + GError *error; + GHashTableIter iter; + gpointer field, value; + gboolean updated = FALSE; + gboolean reply = FALSE; + + g_return_val_if_fail(wifi != NULL, FALSE); + + DBG("Set agent fields for %s", service); + + if (netconfig_is_wifi_profile(service) != TRUE) { + error = g_error_new(DBUS_GERROR, + DBUS_GERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidService"); + + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + return reply; + } + + __netconfig_agent_clear_fields(); + + g_hash_table_iter_init(&iter, fields); + + while (g_hash_table_iter_next(&iter, &field, &value)) { + if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0) { + g_free(agent.passphrase); + if (G_VALUE_TYPE(value) == G_TYPE_STRING) { + agent.passphrase = g_value_dup_string(value); + updated = TRUE; + + DBG("Field [%s] - []", field); + } else { + agent.passphrase = NULL; + } + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PBC) == 0) { + agent.wps_pbc = FALSE; + if (G_VALUE_TYPE(value) == G_TYPE_STRING && + g_strcmp0(g_value_get_string(value), "enable") == 0) { + agent.wps_pbc = TRUE; + updated = TRUE; + + DBG("Field [%s] - [%d]", field, agent.wps_pbc); + } + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS_PIN) == 0) { + g_free(agent.wps_pin); + agent.wps_pbc = FALSE; + if (G_VALUE_TYPE(value) == G_TYPE_STRING) { + agent.wps_pin = g_value_dup_string(value); + updated = TRUE; + + DBG("Field [%s] - []", field); + } else { + agent.wps_pin = NULL; + } + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_NAME) == 0) { + g_free(agent.name); + if (G_VALUE_TYPE(value) == G_TYPE_STRING) { + agent.name = g_value_dup_string(value); + updated = TRUE; + + DBG("Field [%s] - []", field); + } else { + agent.name = NULL; + } + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_SSID) == 0) { + if (agent.ssid != NULL) { + g_byte_array_free(agent.ssid, TRUE); + agent.ssid = NULL; + } + + if (G_VALUE_HOLDS(value, DBUS_TYPE_G_UCHAR_ARRAY) == TRUE) { + GByteArray *array = (GByteArray *)g_value_get_boxed(value); + if (array != NULL && (array->len > 0)) { + agent.ssid = g_byte_array_sized_new(array->len); + agent.ssid->len = array->len; + memcpy(agent.ssid->data, array->data, array->len); + updated = TRUE; + + DBG("Field [%s] - []", field); + } + } + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_IDENTITY) == 0) { + g_free(agent.identity); + if (G_VALUE_TYPE(value) == G_TYPE_STRING) { + agent.identity = g_value_dup_string(value); + updated = TRUE; + + DBG("Field [%s] - []", field); + } else { + agent.identity = NULL; + } + } + } + + if (updated == TRUE) { + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + service, CONNMAN_SERVICE_INTERFACE, "Connect", NULL, NULL); + if (reply == TRUE) { + dbus_g_method_return(context); + } else { + error = g_error_new(DBUS_GERROR, + DBUS_GERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidArguments"); + + dbus_g_method_return_error(context, error); + g_clear_error(&error); + } + } else { + error = g_error_new(DBUS_GERROR, + DBUS_GERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidArguments"); + + dbus_g_method_return_error(context, error); + g_clear_error(&error); + } + + if (reply != TRUE) { + ERR("Fail to connect Wi-Fi"); + + __netconfig_agent_clear_fields(); + } + + return reply; +} + +static void __g_slice_value_free(gpointer data) +{ + g_slice_free(GValue, data); +} + +gboolean netconfig_iface_wifi_request_input(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context) +{ + GError *error; + GHashTableIter iter; + gpointer field, r_value; + GHashTable *out_table = NULL; + GValue *value = NULL; + gboolean updated = FALSE; + + g_return_val_if_fail(wifi != NULL, FALSE); + + if (NULL == service) + return FALSE; + + DBG("Agent fields requested for service: %s", service); + + out_table = g_hash_table_new_full(g_str_hash, g_str_equal, + g_free, __g_slice_value_free); + if (NULL == out_table) + return FALSE; + + g_hash_table_iter_init(&iter, fields); + + while (g_hash_table_iter_next(&iter, &field, &r_value)) { + if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_PASSPHRASE) == 0 && + agent.passphrase != NULL) { + value = g_slice_new0(GValue); + + g_value_init(value, G_TYPE_STRING); + g_value_set_string(value, agent.passphrase); + g_hash_table_insert(out_table, g_strdup(field), value); + + updated = TRUE; + DBG("Setting [%s] - []", field); + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_WPS) == 0 && + (agent.wps_pbc == TRUE || agent.wps_pin != NULL)) { + value = g_slice_new0(GValue); + + g_value_init(value, G_TYPE_STRING); + + if (agent.wps_pbc == TRUE) { + /* Sending empty string for WPS push button method */ + g_value_set_string(value, ""); + g_hash_table_insert(out_table, g_strdup(field), value); + + updated = TRUE; + DBG("Setting empty string for [%s]", field); + } else if (agent.wps_pin != NULL) { + g_value_set_string(value, agent.wps_pin); + g_hash_table_insert(out_table, g_strdup(field), value); + + updated = TRUE; + DBG("Setting string [%s] - []", field); + } + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_NAME) == 0 && + agent.name != NULL) { + value = g_slice_new0(GValue); + + g_value_init(value, G_TYPE_STRING); + g_value_set_string(value, agent.name); + g_hash_table_insert(out_table, g_strdup(field), value); + + updated = TRUE; + DBG("Settings [%s] - []", field); + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_SSID) == 0 && + agent.ssid != NULL) { + value = g_slice_new0(GValue); + + g_value_init(value, DBUS_TYPE_G_UCHAR_ARRAY); + g_value_set_boxed(value, agent.ssid); + g_hash_table_insert(out_table, g_strdup(field), value); + + updated = TRUE; + DBG("Settings [%s] - []", field); + } else if (g_strcmp0(field, NETCONFIG_AGENT_FIELD_IDENTITY) == 0 && + agent.identity != NULL) { + value = g_slice_new0(GValue); + + g_value_init(value, G_TYPE_STRING); + g_value_set_string(value, agent.identity); + g_hash_table_insert(out_table, g_strdup(field), value); + + updated = TRUE; + DBG("Settings [%s] - []", field); + } + } + + if (updated == TRUE) + dbus_g_method_return(context, out_table); + else { + error = g_error_new(DBUS_GERROR, + DBUS_GERROR_AUTH_FAILED, + "net.connman.Agent.Error.Canceled"); + + dbus_g_method_return_error(context, error); + g_clear_error(&error); + } + + __netconfig_agent_clear_fields(); + g_hash_table_destroy(out_table); + + return updated; +} + +gboolean netconfig_iface_wifi_report_error(NetconfigWifi *wifi, + gchar *service, gchar *error, + DBusGMethodInvocation *context) +{ + gboolean ret = TRUE; + + g_return_val_if_fail(wifi != NULL, FALSE); + + dbus_g_method_return(context); + DBG("Agent error for service[%s] - [%s]", service, error); + + // Do something when it failed to make a connection + + return ret; +} + +static void __netconfig_wifi_portal_login_timer_start(struct poll_timer_data + *data) +{ + DBG("__netconfig_wifi_browser_start_timer...starting timer"); + + if (data == NULL) + return; + + netconfig_stop_timer(&(data->timer_id)); + + /* Timer logic: After successful launch of browser, we would check for + * Internet status for every 20s until a threshold of 120s + */ + + data->time_elapsed = QUERY_FOR_INTERNET_INTERVAL; + netconfig_start_timer_seconds(QUERY_FOR_INTERNET_INTERVAL, + __netconfig_wifi_portal_login_timeout, data, &(data->timer_id)); +} + +static gboolean __netconfig_wifi_portal_login_timeout(gpointer data) +{ + char *service_profile = NULL; + DBusMessage *reply = NULL; + + DBG(""); + + struct poll_timer_data *timer = (struct poll_timer_data *)data; + if (timer == NULL) + return FALSE; + + if (TRUE == netconfig_get_internet_status()) { + if (is_monitor_notifier_registered == TRUE) { + netconfig_wifi_state_notifier_unregister( + &wifi_state_monitor_notifier); + is_monitor_notifier_registered = FALSE; + } + + DBG("Webportal login Successful, update Connman"); + return FALSE; /* to stop the timer */ + } else { + if (timer->time_elapsed >= TIMER_THRESHOLD) { + DBG("Login failed, update Connman"); + + if (is_monitor_notifier_registered == TRUE) { + netconfig_wifi_state_notifier_unregister( + &wifi_state_monitor_notifier); + is_monitor_notifier_registered = FALSE; + } + + /* Disconnect and forget the AP */ + service_profile = (char*) netconfig_get_default_profile(); + if (service_profile && netconfig_is_wifi_profile(service_profile)) { + /* Now forget the AP*/ + reply = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + service_profile, CONNMAN_SERVICE_INTERFACE, "Remove", + NULL); + + if(NULL == reply) + ERR("Failed to forget the AP"); + } + } else { + if (NETCONFIG_WIFI_CONNECTED == + netconfig_wifi_state_get_service_state()) { + /* check for Internet availability by sending and receiving data*/ + netconfig_check_internet_accessibility(); + /* Returning TRUE itself is enough to restart the timer */ + timer->time_elapsed = timer->time_elapsed + QUERY_FOR_INTERNET_INTERVAL; + return TRUE; + } + } + } + + return FALSE; +} + +gboolean netconfig_iface_wifi_request_browser(NetconfigWifi *wifi, + gchar *service, gchar *url, + DBusGMethodInvocation *context) +{ + gboolean ret = FALSE; + gboolean ignore_portal = FALSE; + const char * ssid = NULL; + + g_return_val_if_fail(wifi != NULL, FALSE); + + dbus_g_method_return(context); + DBG("service[%s] - url[%s]", service, url); + + ssid = netconfig_wifi_get_connected_essid(netconfig_get_default_profile()); + if (ssid == NULL) { + ERR("Connected AP name is NULL!!"); + return ret; + } + + ignore_portal = __check_ignore_portal_list(ssid); + + if (ignore_portal == TRUE) + return TRUE; + + timer_data.time_elapsed = 0; + __netconfig_wifi_portal_login_timer_start(&timer_data); + + /* Register for Wifi state change notifier*/ + if (is_monitor_notifier_registered == FALSE) { + netconfig_wifi_state_notifier_register(&wifi_state_monitor_notifier); + is_monitor_notifier_registered = TRUE; + } + + ret = netconfig_send_notification_to_net_popup(NETCONFIG_ADD_PORTAL_NOTI, ssid); + + return ret; +} diff --git a/wearable/src/wifi-background-scan.c b/wearable/src/wifi-background-scan.c new file mode 100644 index 0000000..dd69920 --- /dev/null +++ b/wearable/src/wifi-background-scan.c @@ -0,0 +1,247 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-state.h" +#include "wifi-background-scan.h" + +#define SCAN_PERIODIC_DELAY 10 +#define SCAN_EXPONENTIAL_MIN 4 +#define SCAN_EXPONENTIAL_MAX 128 + +enum { + WIFI_BGSCAN_MODE_EXPONENTIAL = 0x00, + WIFI_BGSCAN_MODE_PERIODIC, + WIFI_BGSCAN_MODE_MAX, +}; + +struct bgscan_timer_data { + guint time; + guint mode; + guint timer_id; +}; + +static gboolean netconfig_wifi_scanning = FALSE; + +static struct bgscan_timer_data *__netconfig_wifi_bgscan_get_bgscan_data(void) +{ + static struct bgscan_timer_data timer_data = + {SCAN_EXPONENTIAL_MIN, WIFI_BGSCAN_MODE_EXPONENTIAL, 0}; + + return &timer_data; +} + +static guint __netconfig_wifi_bgscan_mode(gboolean is_set_mode, guint mode) +{ + static guint bgscan_mode = WIFI_BGSCAN_MODE_EXPONENTIAL; + + if (is_set_mode != TRUE) + return bgscan_mode; + + if (mode < WIFI_BGSCAN_MODE_MAX) + bgscan_mode = mode; + + DBG("Wi-Fi background scan mode set %d", bgscan_mode); + + return bgscan_mode; +} + +static void __netconfig_wifi_bgscan_set_mode(guint mode) +{ + __netconfig_wifi_bgscan_mode(TRUE, mode); +} + +static guint __netconfig_wifi_bgscan_get_mode(void) +{ + return __netconfig_wifi_bgscan_mode(FALSE, -1); +} + +static gboolean __netconfig_wifi_bgscan_request_connman_scan(void) +{ + gboolean reply; + + if (netconfig_wifi_state_get_service_state() == NETCONFIG_WIFI_CONNECTED) + if (__netconfig_wifi_bgscan_get_mode() == WIFI_BGSCAN_MODE_EXPONENTIAL) + return TRUE; + + if (netconfig_wifi_state_get_service_state() == NETCONFIG_WIFI_CONNECTING) + return FALSE; + + netconfig_wifi_set_scanning(TRUE); + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_WIFI_TECHNOLOGY_PREFIX, + CONNMAN_TECHNOLOGY_INTERFACE, "Scan", NULL, NULL); + if (reply != TRUE) + netconfig_wifi_set_scanning(FALSE); + + return reply; +} + +static gboolean __netconfig_wifi_bgscan_next_scan(gpointer data); + +static gboolean __netconfig_wifi_bgscan_immediate_scan(gpointer data) +{ + static int retry = 0; + + if (__netconfig_wifi_bgscan_request_connman_scan() == TRUE) { + retry = 0; + return FALSE; + } else if (retry >= 3) { + retry = 0; + return FALSE; + } + + retry++; + + return TRUE; +} + +static void __netconfig_wifi_bgscan_start_timer(struct bgscan_timer_data *data) +{ + if (data == NULL) + return; + + netconfig_stop_timer(&(data->timer_id)); + + data->mode = __netconfig_wifi_bgscan_get_mode(); + + if (data->time < SCAN_EXPONENTIAL_MIN) + data->time = SCAN_EXPONENTIAL_MIN; + + switch (data->mode) { + case WIFI_BGSCAN_MODE_EXPONENTIAL: + if ((data->time * 2) > SCAN_EXPONENTIAL_MAX) + data->time = SCAN_EXPONENTIAL_MAX; + else + data->time = data->time * 2; + + break; + case WIFI_BGSCAN_MODE_PERIODIC: + if ((data->time * 2) > SCAN_PERIODIC_DELAY) + data->time = SCAN_PERIODIC_DELAY; + else + data->time = data->time * 2; + + break; + default: + DBG("Error! Wi-Fi background scan mode [%d]", data->mode); + return; + } + + g_timeout_add(500, __netconfig_wifi_bgscan_immediate_scan, NULL); + + netconfig_start_timer_seconds(data->time, + __netconfig_wifi_bgscan_next_scan, data, &(data->timer_id)); +} + +static void __netconfig_wifi_bgscan_stop_timer(struct bgscan_timer_data *data) +{ + if (data == NULL) + return; + + netconfig_stop_timer(&(data->timer_id)); +} + +static gboolean __netconfig_wifi_bgscan_next_scan(gpointer data) +{ + struct bgscan_timer_data *timer = (struct bgscan_timer_data *)data; + int pm_state = VCONFKEY_PM_STATE_NORMAL; + + if (timer == NULL) + return FALSE; + + /* In case of LCD off, we don't need Wi-Fi scan */ + vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) + return TRUE; + + __netconfig_wifi_bgscan_start_timer(timer); + + return FALSE; +} + +void netconfig_wifi_bgscan_start(void) +{ + enum netconfig_wifi_tech_state wifi_tech_state; + struct bgscan_timer_data *timer_data = + __netconfig_wifi_bgscan_get_bgscan_data(); + + if (timer_data == NULL) + return; + + wifi_tech_state = netconfig_wifi_state_get_technology_state(); + if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED) + return; + + DBG("Wi-Fi background scan start or re-started"); + + __netconfig_wifi_bgscan_start_timer(timer_data); +} + +void netconfig_wifi_bgscan_stop(void) +{ + struct bgscan_timer_data *timer_data = + __netconfig_wifi_bgscan_get_bgscan_data(); + + if (timer_data == NULL) + return; + + DBG("Wi-Fi background scan stop"); + + timer_data->time = SCAN_EXPONENTIAL_MIN; + + __netconfig_wifi_bgscan_stop_timer(timer_data); +} + +gboolean netconfig_wifi_get_bgscan_state(void) +{ + struct bgscan_timer_data *timer_data = + __netconfig_wifi_bgscan_get_bgscan_data(); + + return ((timer_data->timer_id > (guint)0) ? TRUE : FALSE); +} + +gboolean netconfig_wifi_get_scanning(void) +{ + return netconfig_wifi_scanning; +} + +void netconfig_wifi_set_scanning(gboolean scanning) +{ + if (netconfig_wifi_scanning != scanning) + netconfig_wifi_scanning = scanning; +} + +gboolean netconfig_iface_wifi_set_bgscan( + NetconfigWifi *wifi, guint scan_mode, GError **error) +{ + __netconfig_wifi_bgscan_set_mode(scan_mode); + + netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_start(); + + return TRUE; +} diff --git a/wearable/src/wifi-ccode.c b/wearable/src/wifi-ccode.c new file mode 100644 index 0000000..30e3796 --- /dev/null +++ b/wearable/src/wifi-ccode.c @@ -0,0 +1,162 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netsupplicant.h" + +#define CCODE_CONFIG_FILE "/etc/wifi/ccode.conf" +#define MCC_TO_ISO_MAP_GROUP_NAME "mcc_iso_map" +#define DEFAULT_CCODE "GB" + +/* Structure to send private command to Wi-Fi driver */ +typedef struct netconfig_wifi_priv_cmd { + char *buf; + int used_len; + int total_len; +} netconfig_wifi_priv_cmd; + +static char *__netconfig_get_mcc(void) +{ + int plmn = 0; + char mcc[4] = { 0, }; + const int mcc_length = 3; + + if (vconf_get_int(VCONFKEY_TELEPHONY_PLMN, &plmn) != 0) { + ERR("OPERATION_FAILED"); + return NULL; + } + + g_snprintf(mcc, mcc_length + 1, "%d", plmn); + + return g_strdup(mcc); +} + +static char *__netconfig_wifi_ccode_get_csc(void) +{ + char *iso = NULL; + + iso = vconf_get_str(VCONFKEY_CSC_COUNTRY_ISO); + if (iso == NULL) + ERR("Failed to get CSC country ISO code"); + + return iso; +} + +/* + * Get the iso code and rev number from Broadcom config file with mcc + * Input: valid keyfile of the config file, valid mcc + * Return: the ISO on success + * NULL on failure + */ +static gchar *__netconfig_wifi_ccode_get_iso_from_mcc( + GKeyFile *keyfile, char *mcc) +{ + gchar *iso = NULL; + + if (keyfile == NULL || mcc == NULL) + return NULL; + + iso = g_key_file_get_string(keyfile, MCC_TO_ISO_MAP_GROUP_NAME, mcc, NULL); + if (iso == NULL) + ERR("Failed to get ISO with mcc %s", mcc); + + return iso; +} + +void netconfig_wifi_ccode_init(void) +{ + char *iso = NULL; + char *mcc = NULL; + GKeyFile *keyfile = NULL; + struct ifreq ifr; + char buf[248] = { 0, }; /* Max driver command size is 248 */ + netconfig_wifi_priv_cmd priv_cmd; + int ret = 0; + int ioctl_sock = 0; + size_t buf_len; + + DBG("Init Wi-Fi country code"); + + keyfile = netconfig_keyfile_load(CCODE_CONFIG_FILE); + if (keyfile == NULL) { + DBG("Unable to get ISO code... Default ISO=[%s]", DEFAULT_CCODE); + goto SET_COUNTRY_REV; + } + + mcc = __netconfig_get_mcc(); + iso = __netconfig_wifi_ccode_get_iso_from_mcc(keyfile, mcc); + + if (iso == NULL) { + /* + * Unable to get the ISO code using mcc. + * Lets get it from CSC. + */ + iso = __netconfig_wifi_ccode_get_csc(); + } + + +SET_COUNTRY_REV: + + if (mcc != NULL) + g_free(mcc); + + if (keyfile != NULL) + g_key_file_free(keyfile); + + if (iso == NULL) { + g_snprintf(buf, sizeof(buf), "COUNTRY %s", DEFAULT_CCODE); + } else { + char *iso_upper = g_ascii_strup(iso, -1); + g_snprintf(buf, sizeof(buf), "COUNTRY %s", iso_upper); + g_free(iso_upper); + g_free(iso); + } + + memset(&ifr, 0, sizeof(struct ifreq)); + g_strlcpy((char *)ifr.ifr_name, WIFI_IFNAME, IFNAMSIZ); + + DBG("CCode command: [%s]", buf); + memset(&priv_cmd, 0, sizeof(priv_cmd)); + buf_len = strlen(buf); + priv_cmd.buf = buf; + priv_cmd.used_len = buf_len; + priv_cmd.total_len = buf_len; + ifr.ifr_data = (char *)&priv_cmd; + + ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); + if (ioctl_sock < 0) { + DBG("socket(PF_INET,SOCK_DGRAM) failed"); + return; + } + + ret = ioctl(ioctl_sock, SIOCDEVPRIVATE + 1, &ifr); + if (ret < 0) + ERR("Fail to issue private commands: %d %s", ret, strerror(errno)); + + close(ioctl_sock); +} diff --git a/wearable/src/wifi-eap-config.c b/wearable/src/wifi-eap-config.c new file mode 100644 index 0000000..f7785db --- /dev/null +++ b/wearable/src/wifi-eap-config.c @@ -0,0 +1,363 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-agent.h" +#include "wifi-state.h" +#include "wifi-eap-config.h" + +#define CONNMAN_STORAGEDIR "/var/lib/connman" + +#define CONNMAN_CONFIG_FIELD_TYPE "Type" +#define CONNMAN_CONFIG_FIELD_NAME "Name" +#define CONNMAN_CONFIG_FIELD_SSID "SSID" +#define CONNMAN_CONFIG_FIELD_EAP_METHOD "EAP" +#define CONNMAN_CONFIG_FIELD_IDENTITY "Identity" +#define CONNMAN_CONFIG_FIELD_PASSPHRASE "Passphrase" +#define CONNMAN_CONFIG_FIELD_PHASE2 "Phase2" +#define CONNMAN_CONFIG_FIELD_CA_CERT_FILE "CACertFile" +#define CONNMAN_CONFIG_FIELD_CLIENT_CERT_FILE "ClientCertFile" +#define CONNMAN_CONFIG_FIELD_PVT_KEY_FILE "PrivateKeyFile" +#define CONNMAN_CONFIG_FIELD_PVT_KEY_PASSPHRASE "PrivateKeyPassphrase" + +static char *__get_encoded_ssid(const char *name) +{ + char *str = NULL; + char *pstr = NULL; + int i = 0, len = 0; + + if (name == NULL) + return NULL; + + len = strlen(name); + + str = g_try_malloc0(len * 2 + 1); + if (str == NULL) + return NULL; + + pstr = str; + for (i = 0; i < len; i++) { + g_snprintf(pstr, 3, "%02x", name[i]); + pstr += 2; + } + + return str; +} + +static int __config_save(const char *ssid, GKeyFile *keyfile) +{ + gchar *data = NULL; + gchar *config_file = NULL; + gsize length = 0; + FILE *file = NULL; + int err = 0; + + config_file = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, ssid); + if (config_file == NULL) { + err = -ENOMEM; + goto out; + } + + data = g_key_file_to_data(keyfile, &length, NULL); + + file = fopen(config_file, "w"); + if (file == NULL) { + ERR("Failed to open %s", config_file); + + err = -EIO; + goto out; + } + + if (fputs(data, file) < 0) { + ERR("Failed to write %s", config_file); + + err = -EIO; + goto out; + } + +out: + if (file != NULL) + fclose(file); + + g_free(data); + g_free(config_file); + + return err; +} + +static int __config_delete(const char *ssid) +{ + gchar *config_file = NULL; + int err = 0; + + config_file = g_strdup_printf("%s/%s.config", CONNMAN_STORAGEDIR, ssid); + if(config_file == NULL) + return -ENOMEM; + + if (remove(config_file) < 0) { + err = -EIO; + goto out; + } + +out: + g_free(config_file); + + return err; +} + +static gboolean __netconfig_create_config(GHashTable *fields) +{ + GKeyFile *keyfile = NULL; + GHashTableIter iter; + gchar *encoded_ssid = NULL; + gchar *group_name = NULL; + gpointer field, value; + gboolean updated = FALSE; + + g_hash_table_iter_init(&iter, fields); + while (g_hash_table_iter_next(&iter, &field, &value)) { + if (value != NULL) { + if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_NAME) == 0) { + encoded_ssid = __get_encoded_ssid((const char *)value); + break; + } else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_SSID) == 0) { + encoded_ssid = g_strdup((const char *)value); + break; + } + } + } + + if (encoded_ssid == NULL) { + ERR("Failed to fetch SSID"); + goto out; + } + + /* Create unique service group name */ + group_name = g_strdup_printf("service_%s", encoded_ssid); + if (group_name == NULL) { + ERR("Failed to create service group name"); + goto out; + } + + keyfile = g_key_file_new(); + if (keyfile == NULL) { + ERR("Failed to g_key_file_new"); + goto out; + } + + g_hash_table_iter_init(&iter, fields); + while (g_hash_table_iter_next(&iter, &field, &value)) { + if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_SSID) == 0 || + g_strcmp0(field, CONNMAN_CONFIG_FIELD_EAP_METHOD) == 0 || + g_strcmp0(field, CONNMAN_CONFIG_FIELD_PHASE2) == 0) + DBG("field: %s, value: %s", field, value); + else + DBG("field: %s, value:", field); + + if (value != NULL) + g_key_file_set_string(keyfile, group_name, field, value); + } + + if (__config_save((const char *)encoded_ssid, keyfile) == 0) { + DBG("Successfully created %s", encoded_ssid); + updated = TRUE; + } + +out: + if (keyfile != NULL) + g_key_file_free(keyfile); + + g_free(group_name); + g_free(encoded_ssid); + + return updated; +} + +static gboolean __netconfig_delete_config(const char *profile) +{ + char *wifi_ident = NULL; + char *essid = NULL; + char *mode = NULL; + char *ssid = NULL; + int ssid_len = 0; + + if (NULL == profile) { + ERR("Invalid profile name"); + return FALSE; + } + + wifi_ident = strstr(profile, "wifi_"); + if (wifi_ident == NULL) { + ERR("Invalid profile name"); + return FALSE; + } + + essid = strchr(wifi_ident + 5, '_'); + if (essid == NULL) { + ERR("Invalid profile name"); + return FALSE; + } + + essid++; + mode = strchr(essid, '_'); + + ssid_len = mode - essid; + + ssid = g_try_malloc0(ssid_len + 1); + if (ssid == NULL) { + ERR("Memory allocation failed"); + return FALSE; + } + + g_strlcpy(ssid, essid, ssid_len + 1); /* include NULL-terminated */ + if (__config_delete((const char *)ssid) < 0) { + g_free(ssid); + return FALSE; + } + + DBG("Successfully deleted %s with length %d", ssid, ssid_len); + + g_free(ssid); + return TRUE; +} + +static void __netconfig_eap_state( + enum netconfig_wifi_service_state state, void *user_data); + +static struct netconfig_wifi_state_notifier netconfig_eap_notifier = { + .netconfig_wifi_state_changed = __netconfig_eap_state, + .user_data = NULL, +}; + +static void __netconfig_eap_state( + enum netconfig_wifi_service_state state, void *user_data) +{ + const char *wifi_profile = (const char *)user_data; + + if (wifi_profile == NULL) { + netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier); + return; + } + + if (state != NETCONFIG_WIFI_CONNECTED && state != NETCONFIG_WIFI_FAILURE) + return; + + if (state == NETCONFIG_WIFI_FAILURE) + __netconfig_delete_config(wifi_profile); + + g_free(netconfig_eap_notifier.user_data); + netconfig_eap_notifier.user_data = NULL; + + netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier); +} + +gboolean netconfig_iface_wifi_create_config(NetconfigWifi *wifi, + gchar *service, GHashTable *fields, + DBusGMethodInvocation *context) +{ + GError *error; + gboolean updated = FALSE; + gboolean reply = FALSE; + + g_return_val_if_fail(wifi != NULL, FALSE); + + DBG("Set agent fields for %s", service); + + if (netconfig_is_wifi_profile(service) != TRUE) { + error = g_error_new(DBUS_GERROR, + DBUS_GERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidService"); + + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + return reply; + } + + updated = __netconfig_create_config(fields); + if (updated == TRUE) { + dbus_g_method_return(context); + + if (g_strstr_len(service, strlen(service), "_hidden_") != NULL) { + GHashTableIter iter; + gpointer field, value; + const char *name = NULL; + const char *identity = NULL; + const char *passphrase = NULL; + + g_hash_table_iter_init(&iter, fields); + + while (g_hash_table_iter_next(&iter, &field, &value)) { + if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_NAME) == 0) + name = (const char *)value; + else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_SSID) == 0) + name = (const char *)value; + else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_IDENTITY) == 0) + identity = (const char *)value; + else if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_PASSPHRASE) == 0) + passphrase = (const char *)value; + } + + netconfig_wifi_set_agent_field_for_eap_network( + name, identity, passphrase); + } + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + service, CONNMAN_SERVICE_INTERFACE, "Connect", NULL, NULL); + + if (netconfig_eap_notifier.user_data != NULL) { + g_free(netconfig_eap_notifier.user_data); + netconfig_eap_notifier.user_data = NULL; + + netconfig_wifi_state_notifier_unregister(&netconfig_eap_notifier); + } + + netconfig_eap_notifier.user_data = g_strdup(service); + netconfig_wifi_state_notifier_register(&netconfig_eap_notifier); + } else { + error = g_error_new(DBUS_GERROR, + DBUS_GERROR_AUTH_FAILED, + CONNMAN_ERROR_INTERFACE ".InvalidArguments"); + + dbus_g_method_return_error(context, error); + g_clear_error(&error); + } + + if (reply != TRUE) + ERR("Fail to connect %s", service); + + return reply; +} + +gboolean netconfig_iface_wifi_delete_config(NetconfigWifi *wifi, + gchar *profile, + DBusGMethodInvocation *context) +{ + g_return_val_if_fail(wifi != NULL, FALSE); + + dbus_g_method_return(context); + + return __netconfig_delete_config((const char *)profile); +} diff --git a/wearable/src/wifi-eap.c b/wearable/src/wifi-eap.c new file mode 100644 index 0000000..ac38d0b --- /dev/null +++ b/wearable/src/wifi-eap.c @@ -0,0 +1,554 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "network-state.h" + +#define SIM_RAND_DATA_LEN 16 +#define SIM_AUTH_MAX_RESP_DATA_LEN 128 +#define SIM_AUTH_SRES_LEN 4 +#define SIM_AUTH_KC_LEN 8 + +#define AKA_RAND_DATA_LEN 16 +#define AKA_AUTN_DATA_LEN 16 +#define AKA_AUTH_RES_MAX_LEN 16 +#define AKA_AUTH_RES_MIN_LEN 4 +#define AKA_AUTH_CK_LEN 16 +#define AKA_AUTH_IK_LEN 16 + +struct wifii_authentication_data { + int auth_result; + int resp_length; + int authentication_key_length; + int cipher_length; + int integrity_length; + char *resp_data; + char *authentication_key; + char *cipher_data; + char *integrity_data; +}; + +static TapiHandle *tapi_handle = NULL; +static struct wifii_authentication_data *wifi_authdata; + +static TapiHandle *netconfig_tapi_init(void) +{ + if (tapi_handle == NULL) { + tapi_handle = tel_init(NULL); + + if (tapi_handle == NULL) + ERR("tel_init() Failed"); + } + + return tapi_handle; +} + +static void netconfig_tapi_deinit(void) +{ + if (tapi_handle) + tel_deinit(tapi_handle); + + tapi_handle = NULL; +} + +static void *__netconfig_wifi_free_wifi_authdata( + struct wifii_authentication_data *data) +{ + if (data != NULL) { + if (data->resp_data) + g_free(data->resp_data); + if (data->authentication_key) + g_free(data->authentication_key); + if (data->cipher_data) + g_free(data->cipher_data); + if (data->integrity_data) + g_free(data->integrity_data); + + g_free(data); + data = NULL; + } + + return NULL; +} + +static void __netconfig_wifi_clean_authentication(void) +{ + netconfig_tapi_deinit(); + + wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); +} + +static gboolean __netconfig_wifi_get_sim_imsi(DBusGMethodInvocation *context) +{ + int ret; + GError *error = NULL; + TapiHandle *handle; + TelSimImsiInfo_t imsi_info; + char *imsi; + + handle = (TapiHandle *)netconfig_tapi_init(); + if (handle == NULL) + return FALSE; + + ret = tel_get_sim_imsi(handle, &imsi_info); + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_get_sim_imsi() : [%d]", ret); + + netconfig_error_fail_get_imsi(&error); + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + return FALSE; + } + + imsi = g_strdup_printf("%s%s%s", imsi_info.szMcc, + imsi_info.szMnc, imsi_info.szMsin); + + dbus_g_method_return(context, imsi); + g_free(imsi); + + return TRUE; +} + +void __netconfig_response_sim_authentication(TapiHandle *handle, + int result, void *data, void *user_data) +{ + if (wifi_authdata != NULL) + wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); + + wifi_authdata = g_try_new0(struct wifii_authentication_data, 1); + + TelSimAuthenticationResponse_t *auth_resp = + (TelSimAuthenticationResponse_t *) data; + if (auth_resp == NULL) { + ERR("the auth response is NULL"); + + wifi_authdata->auth_result = -1; + return; + } else + wifi_authdata->auth_result = auth_resp->auth_result; + + if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + wifi_authdata->resp_length = auth_resp->resp_length; + wifi_authdata->authentication_key_length = + auth_resp->authentication_key_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + + if (wifi_authdata->authentication_key != NULL) + g_free(wifi_authdata->authentication_key); + + wifi_authdata->authentication_key = + g_strdup(auth_resp->authentication_key); + } else { + ERR("the result error for sim auth : [%d]", auth_resp->auth_result); + + wifi_authdata->resp_length = 0; + wifi_authdata->authentication_key_length = 0; + } +} + +void __netconfig_response_aka_authentication(TapiHandle *handle, + int result, void *data, void *user_data) +{ + if (wifi_authdata != NULL) + wifi_authdata = __netconfig_wifi_free_wifi_authdata(wifi_authdata); + + wifi_authdata = g_try_new0(struct wifii_authentication_data, 1); + + TelSimAuthenticationResponse_t *auth_resp = + (TelSimAuthenticationResponse_t *) data; + if (auth_resp == NULL) { + ERR("the auth response is NULL"); + + wifi_authdata->auth_result = -1; + return; + } else + wifi_authdata->auth_result = auth_resp->auth_result; + + if (auth_resp->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + wifi_authdata->resp_length = auth_resp->resp_length; + wifi_authdata->cipher_length = auth_resp->cipher_length; + wifi_authdata->integrity_length = auth_resp->integrity_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + + if (wifi_authdata->cipher_data != NULL) + g_free(wifi_authdata->cipher_data); + + wifi_authdata->cipher_data = g_strdup(auth_resp->cipher_data); + + if (wifi_authdata->integrity_data != NULL) + g_free(wifi_authdata->integrity_data); + + wifi_authdata->integrity_data = g_strdup(auth_resp->integrity_data); + } else { + ERR("the result error for aka auth : [%d]", auth_resp->auth_result); + + if (auth_resp->auth_result == TAPI_SIM_AUTH_SQN_FAILURE || + auth_resp->auth_result == TAPI_SIM_AUTH_SYNCH_FAILURE) { + wifi_authdata->resp_length = auth_resp->resp_length; + + if (wifi_authdata->resp_data != NULL) + g_free(wifi_authdata->resp_data); + + wifi_authdata->resp_data = g_strdup(auth_resp->resp_data); + } + } +} + +static gboolean __netconfig_wifi_req_sim_auth(GArray *rand_data, GError **error) +{ + int i; + int ret; + TapiHandle *handle; + TelSimAuthenticationData_t auth_data; + + if (rand_data->len != SIM_RAND_DATA_LEN) { + ERR("wrong rand data len : [%d]", rand_data->len); + + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if ((ret = g_array_get_element_size(rand_data)) != 1) { + ERR("wrong rand data size : [%d]", ret); + + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + memset(&auth_data, 0, sizeof(auth_data)); + + auth_data.auth_type = TAPI_SIM_AUTH_TYPE_GSM; + auth_data.rand_length = SIM_RAND_DATA_LEN; + + for (i=0; ilen; i++) + auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); + + handle = (TapiHandle *)netconfig_tapi_init(); + if (handle == NULL) { + netconfig_error_fail_req_sim_auth(error); + return FALSE; + } + + ret = tel_req_sim_authentication(handle, + &auth_data, __netconfig_response_sim_authentication, NULL); + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_req_sim_authentication() : [%d]", ret); + + netconfig_error_fail_req_sim_auth(error); + return FALSE; + } + + return TRUE; +} + +static gboolean __netconfig_wifi_req_aka_auth( + GArray *rand_data, GArray *autn_data, GError **error) +{ + int i; + int ret; + TapiHandle *handle; + TelSimAuthenticationData_t auth_data; + + if (rand_data->len != AKA_RAND_DATA_LEN) { + ERR("wrong rand data len : [%d]", rand_data->len); + + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if (autn_data->len != AKA_AUTN_DATA_LEN) { + ERR("wrong autn data len : [%d]", autn_data->len); + + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if ((ret = g_array_get_element_size(rand_data)) != 1) { + ERR("wrong rand data size : [%d]", ret); + + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + if ((ret = g_array_get_element_size(autn_data)) != 1) { + ERR("wrong autn data size : [%d]", ret); + + netconfig_error_fail_req_sim_auth_wrong_param(error); + return FALSE; + } + + memset(&auth_data, 0, sizeof(auth_data)); + + auth_data.auth_type = TAPI_SIM_AUTH_TYPE_3G; + auth_data.rand_length = AKA_RAND_DATA_LEN; + auth_data.autn_length = AKA_AUTN_DATA_LEN; + + for (i=0; ilen; i++) + auth_data.rand_data[i] = g_array_index(rand_data, guint8, i); + + for (i=0; ilen; i++) + auth_data.autn_data[i] = g_array_index(autn_data, guint8, i); + + handle = (TapiHandle *)netconfig_tapi_init(); + if (handle == NULL) { + netconfig_error_fail_req_sim_auth(error); + return FALSE; + } + + ret = tel_req_sim_authentication(handle, &auth_data, + __netconfig_response_aka_authentication, NULL); + + if (ret != TAPI_API_SUCCESS) { + ERR("Failed tel_req_sim_authentication() : [%d]", ret); + + netconfig_error_fail_req_sim_auth(error); + + return FALSE; + } + + return TRUE; +} + +static gboolean __netconfig_wifi_get_sim_authdata(DBusGMethodInvocation *context) +{ + GArray *array = NULL; + GError *error = NULL; + + if (wifi_authdata == NULL) { + DBG("the status error : no response yet"); + + netconfig_error_fail_get_sim_auth_delay(&error); + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + return FALSE; + } + + if (wifi_authdata->auth_result == TAPI_SIM_AUTH_NO_ERROR) { + if (wifi_authdata->resp_length == SIM_AUTH_SRES_LEN && + wifi_authdata->authentication_key_length == SIM_AUTH_KC_LEN) { + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), + SIM_AUTH_SRES_LEN+SIM_AUTH_KC_LEN); + g_array_append_vals(array, wifi_authdata->resp_data, + SIM_AUTH_SRES_LEN); + g_array_append_vals(array, wifi_authdata->authentication_key, + SIM_AUTH_KC_LEN); + + dbus_g_method_return(context, array); + g_array_free (array, TRUE); + } else { + ERR("auth data length is wrong, SRES = [%d], Kc = [%d]", + wifi_authdata->resp_length, + wifi_authdata->authentication_key_length); + + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + __netconfig_wifi_clean_authentication(); + + return FALSE; + } + } else { + ERR("failed auth result = [%d]", wifi_authdata->auth_result); + + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + __netconfig_wifi_clean_authentication(); + + return FALSE; + } + + __netconfig_wifi_clean_authentication(); + + return TRUE; +} + +static gboolean __netconfig_wifi_get_aka_authdata(DBusGMethodInvocation *context) +{ + GArray *array = NULL; + GError *error = NULL; + guchar res_len; + + if (wifi_authdata == NULL) { + DBG("the status error : no response yet"); + + netconfig_error_fail_get_sim_auth_delay(&error); + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + return FALSE; + } + + switch (wifi_authdata->auth_result) { + case TAPI_SIM_AUTH_NO_ERROR: + break; + + case TAPI_SIM_AUTH_SQN_FAILURE: + case TAPI_SIM_AUTH_SYNCH_FAILURE: + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), + wifi_authdata->resp_length+1); + res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); + + g_array_append_vals(array, &res_len, 1); + g_array_append_vals(array, wifi_authdata->resp_data, + wifi_authdata->resp_length); + + dbus_g_method_return(context, array); + g_array_free (array, TRUE); + + __netconfig_wifi_clean_authentication(); + + return TRUE; + + default: + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + __netconfig_wifi_clean_authentication(); + + return FALSE; + } + + if ((wifi_authdata->resp_length >= AKA_AUTH_RES_MIN_LEN || + wifi_authdata->resp_length <= AKA_AUTH_RES_MAX_LEN) && + wifi_authdata->cipher_length == AKA_AUTH_CK_LEN && + wifi_authdata->integrity_length == AKA_AUTH_IK_LEN) { + array = g_array_sized_new(FALSE, FALSE, sizeof(guchar), + wifi_authdata->resp_length+AKA_AUTH_CK_LEN+AKA_AUTH_IK_LEN+1); + + res_len = (guchar)((wifi_authdata->resp_length-1) & 0xff); + g_array_append_vals(array, &res_len, 1); + g_array_append_vals(array, wifi_authdata->resp_data, + wifi_authdata->resp_length); + g_array_append_vals(array, wifi_authdata->cipher_data, + AKA_AUTH_CK_LEN); + g_array_append_vals(array, wifi_authdata->integrity_data, + AKA_AUTH_IK_LEN); + + dbus_g_method_return(context, array); + g_array_free (array, TRUE); + } else { + ERR("auth data length is wrong, res = [%d], Kc = [%d], Ki = [%d]", + wifi_authdata->resp_length, wifi_authdata->cipher_length, + wifi_authdata->integrity_length); + + netconfig_error_fail_get_sim_auth_wrong_data(&error); + dbus_g_method_return_error(context, error); + g_clear_error(&error); + + __netconfig_wifi_clean_authentication(); + + return FALSE; + } + + __netconfig_wifi_clean_authentication(); + + return TRUE; +} + +gboolean netconfig_iface_wifi_get_sim_imsi(NetconfigWifi *wifi, + DBusGMethodInvocation *context) +{ + gboolean ret = TRUE; + + DBG("Get IMSI"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_get_sim_imsi(context); + + return ret; +} + +gboolean netconfig_iface_wifi_req_sim_auth(NetconfigWifi *wifi, + GArray *rand_data, gboolean *result, GError **error) +{ + gboolean ret = TRUE; + + DBG("Request SIM Authentication"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_req_sim_auth(rand_data, error); + + *result = ret; + return ret; +} + +gboolean netconfig_iface_wifi_req_aka_auth(NetconfigWifi *wifi, + GArray *rand_data, GArray *autn_data, gboolean *result, GError **error) +{ + gboolean ret = TRUE; + + DBG("Request AKA Authentication"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_req_aka_auth(rand_data, autn_data, error); + + *result = ret; + return ret; +} + +gboolean netconfig_iface_wifi_get_sim_auth(NetconfigWifi *wifi, + DBusGMethodInvocation *context) +{ + gboolean ret = TRUE; + + DBG("Get SIM Authdata"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_get_sim_authdata(context); + + return ret; +} + +gboolean netconfig_iface_wifi_get_aka_auth(NetconfigWifi *wifi, + DBusGMethodInvocation *context) +{ + gboolean ret = TRUE; + + DBG("Get AKA Authdata"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + ret = __netconfig_wifi_get_aka_authdata(context); + + return ret; +} diff --git a/wearable/src/wifi-firmware.c b/wearable/src/wifi-firmware.c new file mode 100644 index 0000000..806cf41 --- /dev/null +++ b/wearable/src/wifi-firmware.c @@ -0,0 +1,298 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "emulator.h" +#include "neterror.h" +#include "wifi-ccode.h" +#include "netsupplicant.h" +#include "wifi-firmware.h" +#include "network-statistics.h" + +#define WLAN_DRIVER_SCRIPT "/usr/bin/wlan.sh" +#define WLAN_P2P_IFACE_NAME "p2p0" + +static int __netconfig_sta_firmware_start(void) +{ + int rv = 0; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "/usr/bin/wlan.sh", "start", NULL }; + char *const envs[] = { NULL }; + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) + return -EIO; + + /* Do CCODE initialization here */ + netconfig_wifi_ccode_init(); + + DBG("Successfully loaded wireless device driver"); + return 0; +} + +static int __netconfig_sta_firmware_stop(void) +{ + int rv = 0; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const envs[] = { NULL }; + + /* Update statistics before driver remove */ + netconfig_wifi_statistics_update_powered_off(); + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) + return -EIO; + + DBG("Successfully removed wireless device driver"); + return 0; +} + +static int __netconfig_p2p_firmware_start(void) +{ + int rv = 0; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "/usr/bin/wlan.sh", "p2p", NULL }; + char *const envs[] = { NULL }; + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) + return -EIO; + + DBG("Successfully loaded p2p device driver"); + return 0; +} + +static int __netconfig_p2p_firmware_stop(void) +{ + int rv = 0; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const envs[] = { NULL }; + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) + return -EIO; + + DBG("Successfully removed p2p device driver"); + return 0; +} + +static int __netconfig_softap_firmware_start(void) +{ + int rv = 0; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "/usr/bin/wlan.sh", "softap", NULL }; + char *const envs[] = { NULL }; + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) + return -EIO; + + DBG("Successfully loaded softap device driver"); + return 0; +} + +static int __netconfig_softap_firmware_stop(void) +{ + int rv = 0; + const char *path = WLAN_DRIVER_SCRIPT; + char *const args[] = { "/usr/bin/wlan.sh", "stop", NULL }; + char *const envs[] = { NULL }; + + rv = netconfig_execute_file(path, args, envs); + if (rv < 0) + return -EIO; + + DBG("Successfully removed softap device driver"); + return 0; +} + +static int __netconfig_wifi_firmware_start(enum netconfig_wifi_firmware type) +{ + if (netconfig_emulator_is_emulated() == TRUE) + return -EIO; + + switch (type) { + case NETCONFIG_WIFI_STA: + return __netconfig_sta_firmware_start(); + case NETCONFIG_WIFI_P2P: + return __netconfig_p2p_firmware_start(); + case NETCONFIG_WIFI_SOFTAP: + return __netconfig_softap_firmware_start(); + default: + break; + } + + return -ENXIO; +} + +static int __netconfig_wifi_firmware_stop(enum netconfig_wifi_firmware type) +{ + if (netconfig_emulator_is_emulated() == TRUE) + return -EIO; + + switch (type) { + case NETCONFIG_WIFI_STA: + return __netconfig_sta_firmware_stop(); + case NETCONFIG_WIFI_P2P: + return __netconfig_p2p_firmware_stop(); + case NETCONFIG_WIFI_SOFTAP: + return __netconfig_softap_firmware_stop(); + default: + break; + } + + return -ENXIO; +} + +int netconfig_wifi_firmware(enum netconfig_wifi_firmware type, gboolean enable) +{ + int err; + static enum netconfig_wifi_firmware current_driver = NETCONFIG_WIFI_OFF; + enum netconfig_wifi_firmware alias = type; + +#if defined WLAN_CONCURRENT_MODE + int flight_mode = 0; + + if (type == NETCONFIG_WIFI_P2P) + alias = NETCONFIG_WIFI_STA; +#endif + + DBG("Wi-Fi current firmware %d (type: %d %s)", current_driver, type, + enable == TRUE ? "enable" : "disable"); + + if (enable == FALSE) { + if (current_driver == NETCONFIG_WIFI_OFF) { + return -EALREADY; + } else if (current_driver == alias) { + +#if defined WLAN_CONCURRENT_MODE + vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &flight_mode); + + if (flight_mode == 0 && type == NETCONFIG_WIFI_STA && + netconfig_is_wifi_direct_on() == TRUE) { + netconfig_interface_down(WIFI_IFNAME); + + return -EALREADY; + } + + if (type == NETCONFIG_WIFI_P2P && + netconfig_wifi_state_get_technology_state() > + NETCONFIG_WIFI_TECH_OFF) { + netconfig_interface_down(WLAN_P2P_IFACE_NAME); + + return -EALREADY; + } +#endif + err = __netconfig_wifi_firmware_stop(type); + if (err < 0 && err != -EALREADY) + return err; + + current_driver = NETCONFIG_WIFI_OFF; + + return err; + } + + return -EIO; + } + + if (current_driver > NETCONFIG_WIFI_OFF) { + if (current_driver == alias) { + +#if defined WLAN_CONCURRENT_MODE + if (type == NETCONFIG_WIFI_STA) + netconfig_interface_up(WIFI_IFNAME); + else if (type == NETCONFIG_WIFI_P2P) + netconfig_interface_up(WLAN_P2P_IFACE_NAME); +#endif + return -EALREADY; + } + + return -EIO; + } + + err = __netconfig_wifi_firmware_start(type); + + current_driver = alias; + + return err; +} + +gboolean netconfig_iface_wifi_start( + NetconfigWifi *wifi, gchar *device, GError **error) +{ + int err; + + g_return_val_if_fail(wifi != NULL, FALSE); + + DBG("Wi-Fi firmware start %s", device != NULL ? device : "null"); + + if (g_strcmp0("p2p", device) == 0) + err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, TRUE); + else if (g_strcmp0("softap", device) == 0) + err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, TRUE); + else + err = -EINVAL; + + if (err < 0) { + if (err == -EALREADY) + netconfig_error_already_exists(error); + else + netconfig_error_wifi_driver_failed(error); + + return FALSE; + } + + return TRUE; +} + +gboolean netconfig_iface_wifi_stop( + NetconfigWifi *wifi, gchar *device, GError **error) +{ + int err; + + g_return_val_if_fail(wifi != NULL, FALSE); + + DBG("Wi-Fi firmware stop %s", device != NULL ? device : "null"); + + if (g_strcmp0("p2p", device) == 0) + err = netconfig_wifi_firmware(NETCONFIG_WIFI_P2P, FALSE); + else if (g_strcmp0("softap", device) == 0) + err = netconfig_wifi_firmware(NETCONFIG_WIFI_SOFTAP, FALSE); + else + err = -EINVAL; + + if (err < 0) { + if (err == -EALREADY) + netconfig_error_already_exists(error); + else + netconfig_error_wifi_driver_failed(error); + + return FALSE; + } + + return TRUE; +} diff --git a/wearable/src/wifi-indicator.c b/wearable/src/wifi-indicator.c new file mode 100644 index 0000000..3719817 --- /dev/null +++ b/wearable/src/wifi-indicator.c @@ -0,0 +1,353 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-state.h" +#include "network-state.h" +#include "network-statistics.h" +#include "netsupplicant.h" +#include "wifi-indicator.h" + +#define VCONFKEY_WIFI_SNR_MIN -89 + +#define NETCONFIG_WIFI_INDICATOR_INTERVAL 1 + +#define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 (19200 * 1024) +#define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 (7680 * 1024) +#define NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 (3840 * 1024) +#define NETCONFIG_PROCWIRELESS "/proc/net/wireless" + +static int netconfig_wifi_rssi = VCONFKEY_WIFI_SNR_MIN; +static guint netconfig_wifi_indicator_timer = 0; + +int netconfig_wifi_get_rssi(void) +{ + return netconfig_wifi_rssi; +} + +static int __netconfig_wifi_update_and_get_rssi(void) +{ + FILE *fp; + char buf[512]; + char *p_ifname = NULL, *p_entry = NULL; + int rssi_dbm = VCONFKEY_WIFI_SNR_MIN; + + fp = fopen(NETCONFIG_PROCWIRELESS, "r"); + if (fp == NULL) { + ERR("Failed to open %s", NETCONFIG_PROCWIRELESS); + return rssi_dbm; + } + + /* skip the first and second line */ + if (fgets(buf, sizeof(buf), fp) == NULL || + fgets(buf, sizeof(buf), fp) == NULL) + goto endline; + + while (fgets(buf, sizeof(buf), fp)) { + unsigned int status; + int link, noise; + /* No need to read */ + /* + unsigned long nwid, crypt, frag, retry, misc, missed; + */ + + p_ifname = buf; + while (*p_ifname == ' ') p_ifname++; + p_entry = strchr(p_ifname, ':'); + *p_entry++ = '\0'; + + if (g_str_equal(p_ifname, WIFI_IFNAME) != TRUE) + continue; + + /* read wireless status */ + p_entry = strtok(p_entry, " ."); // status "%x" + sscanf(p_entry, "%x", &status); + p_entry = strtok(NULL, " ."); // Quality link "%d" + sscanf(p_entry, "%d", &link); + p_entry = strtok(NULL, " ."); // Quality level "%d" + sscanf(p_entry, "%d", &rssi_dbm); + p_entry = strtok(NULL, " ."); // Quality noise "%d" + sscanf(p_entry, "%d", &noise); + + /* No need to read */ + /* + p_entry = strtok(NULL, " ."); // Discarded nwid "%lu" + sscanf(p_entry, "%lu", &nwid); + p_entry = strtok(NULL, " ."); // Discarded crypt "%lu" + sscanf(p_entry, "%lu", &crypt); + p_entry = strtok(NULL, " ."); // Discarded frag "%lu" + sscanf(p_entry, "%lu", &frag); + p_entry = strtok(NULL, " ."); // Discarded retry "%lu" + sscanf(p_entry, "%lu", &retry); + p_entry = strtok(NULL, " ."); // Discarded misc "%lu" + sscanf(p_entry, "%lu", &misc); + p_entry = strtok(NULL, " ."); // Discarded missed "%lu" + sscanf(p_entry, "%lu", &missed); + */ + + break; + } + +endline: + fclose(fp); + netconfig_wifi_rssi = rssi_dbm; + + return rssi_dbm; +} + +int netconfig_wifi_rssi_level(const int rssi_dbm) +{ + int snr_level = 0; + + /* Wi-Fi Signal Strength Display + * + * Excellent : -63 ~ + * Good: -74 ~ -64 + * Weak: -82 ~ -75 + * Very weak: ~ -83 + */ + if (rssi_dbm >= -63) + snr_level = 4; + else if (rssi_dbm >= -74) + snr_level = 3; + else if (rssi_dbm >= -82) + snr_level = 2; + else + snr_level = 1; + + return snr_level; +} + +static void __netconfig_wifi_set_rssi_level(const int snr_level) +{ + static int last_snr_level = 0; + + if (snr_level != last_snr_level) { + netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, snr_level); + last_snr_level = snr_level; + } +} + +static void __netconfig_wifi_data_activity_booster(int level) +{ + gboolean reply = FALSE; + char level1[] = "int32:1"; + char level2[] = "int32:2"; + char level3[] = "int32:3"; + + char lock[] = "int32:2000"; + char unlock[] = "int32:0"; + + char *param_array[] = { NULL, NULL, NULL }; + static int booster_level = 0; + + if (level < 0 || booster_level == level) + return; + + if (level > 0) { + /* enable booster */ + switch(level) { + case 1: + param_array[0] = level1; + break; + case 2: + param_array[0] = level2; + break; + case 3: + param_array[0] = level3; + break; + default: + ERR("Invalid level"); + return; + } + param_array[1] = lock; + + reply = netconfig_invoke_dbus_method_nonblock( + "org.tizen.system.deviced", + "/Org/Tizen/System/DeviceD/PmQos", + "org.tizen.system.deviced.PmQos", + "WifiThroughput", + param_array, + NULL); + if (reply != TRUE) + return; + } + + /* disable previous booster */ + if (booster_level == 0) + return; + + switch(booster_level) { + case 1: + param_array[0] = level1; + break; + case 2: + param_array[0] = level2; + break; + case 3: + param_array[0] = level3; + break; + default: + ERR("Invalid level"); + return; + } + param_array[1] = unlock; + + reply = netconfig_invoke_dbus_method_nonblock( + "org.tizen.system.deviced", + "/Org/Tizen/System/DeviceD/PmQos", + "org.tizen.system.deviced.PmQos", + "WifiThroughput", + param_array, + NULL); + if (reply != TRUE) + return; + + booster_level = level; +} + +static void __netconfig_wifi_update_indicator(void) +{ + static int last_transfer_state = 0; + static guint64 netconfig_wifi_tx_bytes = 0; + static guint64 netconfig_wifi_rx_bytes = 0; + static int booster_tic = 0; + static int old_level = 0; + int booster_level = 0; + guint64 tx, rx, tx_diff, rx_diff; + int transfer_state; + + if (netconfig_wifi_get_bytes_statistics(&tx, &rx) == TRUE) { + tx_diff = tx - netconfig_wifi_tx_bytes; + rx_diff = rx - netconfig_wifi_rx_bytes; + + if (tx_diff > 0) { + if (rx_diff > 0) + transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TXRX; + else + transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_TX; + } else { + if (rx_diff > 0) + transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_RX; + else + transfer_state = VCONFKEY_WIFI_TRANSFER_STATE_NONE; + } + + if (transfer_state != last_transfer_state) { + netconfig_set_vconf_int(VCONFKEY_WIFI_TRANSFER_STATE, + transfer_state); + last_transfer_state = transfer_state; + } + + /* NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER */ + if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1 || + rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL1) + booster_level = 1; + else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2 || + rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL2) + booster_level = 2; + else if (tx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3 || + rx_diff >= NETCONFIG_WIFI_DATA_ACTIVITY_BOOSTER_LEVEL3) + booster_level = 3; + + if (old_level == booster_level) { + if (--booster_tic <= 0) { + __netconfig_wifi_data_activity_booster(0); + + if (booster_level > 0) { + __netconfig_wifi_data_activity_booster(booster_level); + + booster_tic = 2; + } + } + } else { + __netconfig_wifi_data_activity_booster(booster_level); + + if (booster_level > 0) + booster_tic = 2; + else + booster_tic = 0; + } + + if (booster_tic < 0) + booster_tic = 0; + + old_level = booster_level; + + netconfig_wifi_tx_bytes = tx; + netconfig_wifi_rx_bytes = rx; + } +} + +static gboolean __netconfig_wifi_indicator_monitor(gpointer data) +{ + int rssi_dbm = 0; + int snr_level = 0; + int pm_state = VCONFKEY_PM_STATE_NORMAL; + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + return FALSE; + + /* In case of LCD off, we don't need to update Wi-Fi indicator */ + vconf_get_int(VCONFKEY_PM_STATE, &pm_state); + if (pm_state >= VCONFKEY_PM_STATE_LCDOFF) + return TRUE; + + rssi_dbm = __netconfig_wifi_update_and_get_rssi(); + snr_level = netconfig_wifi_rssi_level(rssi_dbm); + __netconfig_wifi_set_rssi_level(snr_level); + + __netconfig_wifi_update_indicator(); + + return TRUE; +} + +void netconfig_wifi_indicator_start(void) +{ + INFO("Start Wi-Fi indicator"); + + netconfig_set_vconf_int(VCONFKEY_WIFI_STRENGTH, VCONFKEY_WIFI_STRENGTH_MAX); + + netconfig_start_timer_seconds( + NETCONFIG_WIFI_INDICATOR_INTERVAL, + __netconfig_wifi_indicator_monitor, + NULL, + &netconfig_wifi_indicator_timer); +} + +void netconfig_wifi_indicator_stop(void) +{ + INFO("Stop Wi-Fi indicator"); + + netconfig_stop_timer(&netconfig_wifi_indicator_timer); + + netconfig_wifi_rssi = VCONFKEY_WIFI_SNR_MIN; +} diff --git a/wearable/src/wifi-passpoint.c b/wearable/src/wifi-passpoint.c new file mode 100644 index 0000000..01a9fcb --- /dev/null +++ b/wearable/src/wifi-passpoint.c @@ -0,0 +1,110 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "neterror.h" +#include "netdbus.h" +#include "netsupplicant.h" +#include "wifi-passpoint.h" + + +static gboolean netconfig_wifi_get_passpoint(gint32 *enabled) +{ + DBusMessage *reply; + DBusMessageIter iter, variant; + dbus_bool_t value; + gboolean result = FALSE; + + reply = netconfig_supplicant_invoke_dbus_interface_property_get(SUPPLICANT_IFACE_INTERFACE, + "Passpoint"); + if (reply == NULL) { + ERR("Error!!! Failed to get passpoint property"); + return result; + } + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + const char *err_msg = dbus_message_get_error_name(reply); + ERR("Error!!! Error message received [%s]", err_msg); + return result; + } + + dbus_message_iter_init(reply, &iter); + + if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) { + dbus_message_iter_recurse(&iter, &variant); + if (dbus_message_iter_get_arg_type(&variant) == DBUS_TYPE_INT32) { + dbus_message_iter_get_basic(&variant, &value); + if (value == TRUE) + *enabled = 1; + else + *enabled = 0; + + result = TRUE; + } + } + + dbus_message_unref(reply); + + return result; +} + +static gboolean netconfig_wifi_set_passpoint(gint32 enable) +{ + gint32 value = enable; + gboolean result = FALSE; + GList *input_args = NULL; + + struct dbus_input_arguments args_enable[2] = { + {DBUS_TYPE_INT32, &value}, + {DBUS_TYPE_INVALID, NULL} + }; + + input_args = setup_input_args(input_args, args_enable); + + result = netconfig_supplicant_invoke_dbus_interface_property_set(SUPPLICANT_IFACE_INTERFACE, + "Passpoint", DBUS_TYPE_INT32_AS_STRING, input_args, NULL); + if (result == FALSE) + ERR("Fail to set passpoint enable [%d]", enable); + + g_list_free(input_args); + + return result; +} + +gboolean netconfig_iface_wifi_get_passpoint(NetconfigWifi *wifi, + gint32 *result, GError **error) +{ + g_return_val_if_fail(wifi != NULL, FALSE); + + if (netconfig_wifi_get_passpoint(result)) + return TRUE; + + return FALSE; +} + +gboolean netconfig_iface_wifi_set_passpoint(NetconfigWifi *wifi, + gint32 enable, GError **error) +{ + g_return_val_if_fail(wifi != NULL, FALSE); + + return netconfig_wifi_set_passpoint(enable); +} diff --git a/wearable/src/wifi-power.c b/wearable/src/wifi-power.c new file mode 100644 index 0000000..246949c --- /dev/null +++ b/wearable/src/wifi-power.c @@ -0,0 +1,662 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "wifi-wps.h" +#include "wifi-power.h" +#include "wifi-state.h" +#include "netsupplicant.h" +#include "network-state.h" +#include "wifi-firmware.h" +#include "wifi-background-scan.h" + +#define WLAN_SUPPLICANT_SCRIPT "/usr/sbin/wpa_supp.sh" +#define VCONF_WIFI_OFF_STATE_BY_AIRPLANE \ + "file/private/wifi/wifi_off_by_airplane" +#define VCONF_WIFI_OFF_STATE_BY_RESTRICTED \ + "file/private/wifi/wifi_off_by_restricted" +#define VCONF_WIFI_OFF_STATE_BY_EMERGENCY \ + "file/private/wifi/wifi_off_by_emergency" + +static gboolean connman_wifi_technology_state = FALSE; + +static gboolean wifi_firmware_recovery_mode = FALSE; + +static TapiHandle *tapi_handle = NULL; + +static TapiHandle *netconfig_tapi_init(void) +{ + if (tapi_handle == NULL) { + tapi_handle = tel_init(NULL); + + if (tapi_handle == NULL) + ERR("tel_init() Failed"); + } + + return tapi_handle; +} + +static void netconfig_tapi_deinit(void) +{ + if (tapi_handle) + tel_deinit(tapi_handle); + + tapi_handle = NULL; +} + +static void __netconfig_wifi_technology_reply(DBusPendingCall *call, void *data) +{ + DBusMessage *message; + + message = dbus_pending_call_steal_reply(call); + + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_ERROR) { + ERR("%s", dbus_message_get_error_name(message)); + + if (dbus_message_is_error(message, + CONNMAN_ERROR_INTERFACE ".AlreadyEnabled") == TRUE) + netconfig_wifi_update_power_state(TRUE); + else if (dbus_message_is_error(message, + CONNMAN_ERROR_INTERFACE ".AlreadyDisabled") == TRUE) + netconfig_wifi_update_power_state(FALSE); + } else { + DBG("Successfully requested"); + } + + dbus_message_unref(message); + dbus_pending_call_unref(call); +} + +static gboolean __netconfig_is_wifi_restricted(void) +{ + int restricted_mode = 0; + + vconf_get_bool(VCONFKEY_SETAPPL_NETWORK_RESTRICT_MODE, &restricted_mode); + if (restricted_mode != 0) { + DBG("network restricted mode[%d]", restricted_mode); + return TRUE; + } + + return FALSE; +} + +static int __netconfig_wifi_connman_technology(gboolean enable) +{ + gboolean reply = FALSE; + char key[] = "string:Powered"; + char value_enable[] = "variant:boolean:true"; + char value_disable[] = "variant:boolean:false"; + char *param_array[] = { NULL, NULL, NULL }; + + if (connman_wifi_technology_state == enable) + return -EALREADY; + + param_array[0] = key; + if (enable == TRUE) + param_array[1] = value_enable; + else + param_array[1] = value_disable; + + reply = netconfig_invoke_dbus_method_nonblock(CONNMAN_SERVICE, + CONNMAN_WIFI_TECHNOLOGY_PREFIX, CONNMAN_TECHNOLOGY_INTERFACE, + "SetProperty", param_array, __netconfig_wifi_technology_reply); + + if (reply != TRUE) { + ERR("Fail to set technology %s", enable == TRUE ? "enable" : "disable"); + return -ESRCH; + } + + connman_wifi_technology_state = enable; + + /* To be keep safe, early disable Wi-Fi tech state */ + if (enable != TRUE) + netconfig_wifi_state_set_technology_state(NETCONFIG_WIFI_TECH_WPS_ONLY); + + return 0; +} + +static int __netconfig_wifi_supplicant(gboolean enable) +{ + int rv = 0; + const char *path = WLAN_SUPPLICANT_SCRIPT; + char *const args_enable[] = { "/usr/sbin/wpa_supp.sh", "start", NULL }; + char *const args_disable[] = { "/usr/sbin/wpa_supp.sh", "stop", NULL }; + char *const envs[] = { NULL }; + static gboolean enabled = FALSE; + + if (enabled == enable) + return -EALREADY; + + if (enable == TRUE) + rv = netconfig_execute_file(path, args_enable, envs); + else + rv = netconfig_execute_file(path, args_disable, envs); + if (rv < 0) + return -EIO; + + DBG("wpa_supplicant %s", enable == TRUE ? "started" : "stopped"); + + enabled = enable; + + return 0; +} + +void netconfig_wifi_recover_firmware(void) +{ + wifi_firmware_recovery_mode = TRUE; + + netconfig_wifi_bgscan_stop(); + + netconfig_wifi_off(); +} + +static gboolean __netconfig_wifi_direct_power_off(void) +{ + return TRUE; +} + +static int __netconfig_wifi_try_to_load_driver_and_supplicant(void) +{ + int err = 0; + enum netconfig_wifi_tech_state wifi_tech_state; + + wifi_tech_state = netconfig_wifi_state_get_technology_state(); + if (wifi_tech_state > NETCONFIG_WIFI_TECH_OFF) + return -EALREADY; + + err = __netconfig_wifi_supplicant(TRUE); + if (err < 0 && err != -EALREADY) + return err; + + err = netconfig_wifi_firmware(NETCONFIG_WIFI_STA, TRUE); + if (err < 0 && err != -EALREADY) { + __netconfig_wifi_supplicant(FALSE); + return err; + } + + netconfig_wifi_state_set_technology_state(NETCONFIG_WIFI_TECH_WPS_ONLY); + + return 0; +} + +static int __netconfig_wifi_try_to_remove_driver_and_supplicant(void) +{ + int err = 0; + + if (wifi_firmware_recovery_mode != TRUE && + netconfig_wifi_is_wps_enabled() == TRUE) { + DBG("Wi-Fi WPS mode"); + return 0; + } + + err = netconfig_wifi_firmware(NETCONFIG_WIFI_STA, FALSE); + if (err < 0 && err != -EALREADY) + return err; + + err = __netconfig_wifi_supplicant(FALSE); + if (err < 0 && err != -EALREADY) + return err; + + netconfig_wifi_state_set_technology_state(NETCONFIG_WIFI_TECH_OFF); + + if (wifi_firmware_recovery_mode == TRUE) { + if (netconfig_wifi_on() < 0) + ERR("Failed to recover Wi-Fi firmware"); + + wifi_firmware_recovery_mode = FALSE; + } + + return 0; +} + +int netconfig_wifi_driver_and_supplicant(gboolean enable) +{ + /* There are 3 thumb rules for Wi-Fi power management + * 1. Do not make exposed API to control wpa_supplicant and driver directly. + * It probably breaks ConnMan technology operation. + * + * 2. Do not remove driver and wpa_supplicant if ConnMan already enabled. + * It breaks ConnMan technology operation. + * + * 3. Final the best rule: make it as simple as possible. + * Simple code enables easy maintenance and reduces logical errors. + */ + if (enable == TRUE) + return __netconfig_wifi_try_to_load_driver_and_supplicant(); + else { + if (connman_wifi_technology_state == TRUE) + return -ENOSYS; + + return __netconfig_wifi_try_to_remove_driver_and_supplicant(); + } +} + +gboolean netconfig_is_wifi_allowed(void) +{ + return TRUE; +} + +int netconfig_wifi_on(void) +{ + int err = 0; + enum netconfig_wifi_tech_state wifi_tech_state; + + wifi_tech_state = netconfig_wifi_state_get_technology_state(); + if (wifi_tech_state >= NETCONFIG_WIFI_TECH_POWERED) + return -EALREADY; + + if (netconfig_is_wifi_allowed() != TRUE) { + ERR("Wi-Fi disabled"); + netconfig_send_message_to_net_popup("Network connection popup", + "wifi restricted", "popup", NULL); + return -EPERM; + } + + if (__netconfig_is_wifi_restricted() == TRUE) + return -EPERM; + + if (netconfig_is_wifi_tethering_on() == TRUE) { + /* TODO: Wi-Fi tethering turns off here */ + /* return TRUE; */ + ERR("Failed to turn tethering off"); + return -EBUSY; + } + +#if !defined WLAN_CONCURRENT_MODE + if (netconfig_is_wifi_direct_on() == TRUE) { + if (__netconfig_wifi_direct_power_off() == TRUE) + return -EINPROGRESS; + else { + ERR("Failed to turn Wi-Fi direct off"); + return -EBUSY; + } + } +#endif + + err = netconfig_wifi_driver_and_supplicant(TRUE); + if (err < 0 && err != -EALREADY) + return err; + + err = __netconfig_wifi_connman_technology(TRUE); + + return err; +} + +int netconfig_wifi_off(void) +{ + int err; + + err = __netconfig_wifi_connman_technology(FALSE); + if (err == -EALREADY) + netconfig_wifi_update_power_state(FALSE); + + return 0; +} + +static void __netconfig_wifi_airplane_mode(keynode_t *node, void *user_data) +{ + int wifi_state = 0, airplane_state = 0; + int wifi_off_by_airplane = 0; + + vconf_get_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, &wifi_off_by_airplane); + + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + + if (node != NULL) + airplane_state = vconf_keynode_get_bool(node); + else + vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &airplane_state); + + DBG("airplane mode %s", airplane_state > 0 ? "ON" : "OFF"); + DBG("Wi-Fi state %d, Wi-Fi was off by flight mode %s", wifi_state, + wifi_off_by_airplane ? "Yes" : "No"); + + if (airplane_state > 0) { + /* airplane mode on */ + if (wifi_state == VCONFKEY_WIFI_OFF) + return; + + netconfig_wifi_off(); + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 1); + } else { + /* airplane mode off */ + if (!wifi_off_by_airplane) + return; + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); + + if (wifi_state > VCONFKEY_WIFI_OFF) + return; + + netconfig_wifi_on(); + } +} + +static void __netconfig_wifi_restrict_mode(keynode_t *node, void *user_data) +{ + int wifi_state = 0, restricted = 0; + int wifi_off_by_restricted = 0; + + vconf_get_int(VCONF_WIFI_OFF_STATE_BY_RESTRICTED, &wifi_off_by_restricted); + + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + + if (node != NULL) + restricted = vconf_keynode_get_bool(node); + else + vconf_get_bool(VCONFKEY_SETAPPL_NETWORK_RESTRICT_MODE, &restricted); + + DBG("network restricted mode %s", restricted > 0 ? "ON" : "OFF"); + DBG("Wi-Fi state %d, Wi-Fi was off by restricted mode %s", wifi_state, + wifi_off_by_restricted ? "Yes" : "No"); + + if (restricted > 0) { + /* network restricted on */ + if (wifi_state == VCONFKEY_WIFI_OFF) + return; + + netconfig_wifi_off(); + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_RESTRICTED, 1); + } else { + /* network restricted off */ + if (!wifi_off_by_restricted) + return; + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_RESTRICTED, 0); + + if (wifi_state > VCONFKEY_WIFI_OFF) + return; + + netconfig_wifi_on(); + } +} + +static void __netconfig_wifi_emergency_mode(keynode_t *node, void *user_data) +{ + int wifi_state = 0, emergency = 0; + int wifi_off_by_emergency = 0; + + vconf_get_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, &wifi_off_by_emergency); + + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + + if (node != NULL) + emergency = vconf_keynode_get_int(node); + else + vconf_get_int(VCONFKEY_SETAPPL_PSMODE, &emergency); + + DBG("emergency mode %s", emergency > SETTING_PSMODE_NORMAL ? "ON" : "OFF"); + DBG("Wi-Fi state %d, Wi-Fi was off by emergency mode %s", wifi_state, + wifi_off_by_emergency ? "Yes" : "No"); + + if (emergency > SETTING_PSMODE_NORMAL) { + /* emergency mode on */ + if (wifi_state == VCONFKEY_WIFI_OFF) + return; + + netconfig_wifi_off(); + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 1); + } else { + /* emergency mode off */ + if (!wifi_off_by_emergency) + return; + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_EMERGENCY, 0); + + if (wifi_state > VCONFKEY_WIFI_OFF) + return; + + netconfig_wifi_on(); + } +} + +static void __netconfig_wifi_pm_state_mode(keynode_t* node, void* user_data) +{ + int new_state = -1; + int wifi_state = 0; + static int prev_state = VCONFKEY_PM_STATE_NORMAL; + + if (vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state) < 0) { + ERR("Fail to get VCONFKEY_WIFI_STATE"); + return; + } + + /* PM state + * VCONFKEY_PM_STATE_NORMAL = 1, + * VCONFKEY_PM_STATE_LCDDIM, + * VCONFKEY_PM_STATE_LCDOFF, + * VCONFKEY_PM_STATE_SLEEP + */ + if (node != NULL) + new_state = vconf_keynode_get_int(node); + else + vconf_get_int(VCONFKEY_PM_STATE, &new_state); + + DBG("wifi state: %d (0 off / 1 on / 2 connected)", wifi_state); + DBG("Old PM state: %d, current: %d", prev_state, new_state); + + if ((new_state == VCONFKEY_PM_STATE_NORMAL) && + (prev_state >= VCONFKEY_PM_STATE_LCDOFF)) { + netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_start(); + } + + prev_state = new_state; +} + +static void _tapi_noti_sim_status_cb(TapiHandle *handle, const char *noti_id, + void *data, void *user_data) +{ + TelSimCardStatus_t *status = data; + + if (*status == TAPI_SIM_STATUS_SIM_INIT_COMPLETED) { + DBG("Turn Wi-Fi on automatically"); + + netconfig_wifi_on(); + + netconfig_tapi_deinit(); + } +} + +static gboolean netconfig_tapi_check_sim_state(void) +{ + int ret, card_changed; + TelSimCardStatus_t status; + + netconfig_tapi_init(); + + ret = tel_get_sim_init_info(tapi_handle, &status, &card_changed); + if (ret != TAPI_API_SUCCESS) { + ERR("tel_get_sim_init_info() Failed"); + tel_deinit(tapi_handle); + tapi_handle = NULL; + return FALSE; + } + + switch (status) { + case TAPI_SIM_STATUS_UNKNOWN: + case TAPI_SIM_STATUS_CARD_ERROR: + case TAPI_SIM_STATUS_CARD_NOT_PRESENT: + case TAPI_SIM_STATUS_CARD_BLOCKED: + case TAPI_SIM_STATUS_SIM_INIT_COMPLETED: + break; + case TAPI_SIM_STATUS_SIM_PIN_REQUIRED: + case TAPI_SIM_STATUS_SIM_INITIALIZING: + case TAPI_SIM_STATUS_SIM_PUK_REQUIRED: + case TAPI_SIM_STATUS_SIM_LOCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_NSCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_SPCK_REQUIRED: + case TAPI_SIM_STATUS_SIM_CCK_REQUIRED: + tel_register_noti_event(tapi_handle, TAPI_NOTI_SIM_STATUS, + _tapi_noti_sim_status_cb, NULL); + return FALSE; + default: + ERR("not defined status(%d)", status); + break; + } + + tel_deinit(tapi_handle); + + return TRUE; +} + +static void __netconfig_tapi_state_changed_cb(keynode_t * node, void *data) +{ + int tapi_state = 0; + + if (node != NULL) + tapi_state = vconf_keynode_get_int(node); + else + vconf_get_int(VCONFKEY_TELEPHONY_TAPI_STATE, &tapi_state); + + if (tapi_state != VCONFKEY_TELEPHONY_TAPI_STATE_NONE) { + if (netconfig_tapi_check_sim_state() == FALSE) { + DBG("Sim is not initialized yet."); + + goto done; + } + } else + return; + + DBG("Turn Wi-Fi on automatically"); + + netconfig_wifi_on(); + +done: + vconf_ignore_key_changed(VCONFKEY_TELEPHONY_TAPI_STATE, + __netconfig_tapi_state_changed_cb); +} + +void netconfig_wifi_power_initialize(void) +{ + int tapi_state = 0; + int airplane_state = 0; + int wifi_last_power_state = 0; + + vconf_get_int(VCONF_WIFI_LAST_POWER_STATE, &wifi_last_power_state); + + if (wifi_last_power_state > VCONFKEY_WIFI_OFF) { + vconf_get_bool(VCONFKEY_TELEPHONY_FLIGHT_MODE, &airplane_state); + + if (airplane_state == 0) { + vconf_get_int(VCONFKEY_TELEPHONY_TAPI_STATE, &tapi_state); + + if (tapi_state == VCONFKEY_TELEPHONY_TAPI_STATE_NONE) { + vconf_notify_key_changed(VCONFKEY_TELEPHONY_TAPI_STATE, + __netconfig_tapi_state_changed_cb, NULL); + + goto done; + } else { + if (netconfig_tapi_check_sim_state() == FALSE) { + DBG("Sim is not initialized yet."); + + goto done; + } + } + } + + DBG("Turn Wi-Fi on automatically"); + + netconfig_wifi_on(); + } + +done: + vconf_notify_key_changed(VCONFKEY_TELEPHONY_FLIGHT_MODE, + __netconfig_wifi_airplane_mode, NULL); + + vconf_notify_key_changed(VCONFKEY_SETAPPL_NETWORK_RESTRICT_MODE, + __netconfig_wifi_restrict_mode, NULL); + + vconf_notify_key_changed(VCONFKEY_SETAPPL_PSMODE, + __netconfig_wifi_emergency_mode, NULL); + + vconf_notify_key_changed(VCONFKEY_PM_STATE, + __netconfig_wifi_pm_state_mode, NULL); +} + +gboolean netconfig_iface_wifi_load_driver(NetconfigWifi *wifi, + gboolean device_picker_test, GError **error) +{ + int err; + + DBG("Wi-Fi power on requested"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + err = netconfig_wifi_on(); + if (err < 0) { + if (err == -EINPROGRESS) + netconfig_error_inprogress(error); + else if (err == -EALREADY) + netconfig_error_already_exists(error); + else if (err == -EPERM) + netconfig_error_permission_denied(error); + else + netconfig_error_wifi_driver_failed(error); + + return FALSE; + } + + if (device_picker_test == TRUE) + netconfig_wifi_enable_device_picker_test(); + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); + + return TRUE; +} + +gboolean netconfig_iface_wifi_remove_driver(NetconfigWifi *wifi, GError **error) +{ + int err; + + DBG("Wi-Fi power off requested"); + + g_return_val_if_fail(wifi != NULL, FALSE); + + err = netconfig_wifi_off(); + if (err < 0) { + if (err == -EINPROGRESS) + netconfig_error_inprogress(error); + else if (err == -EALREADY) + netconfig_error_already_exists(error); + else if (err == -EPERM) + netconfig_error_permission_denied(error); + else + netconfig_error_wifi_driver_failed(error); + + return FALSE; + } + + netconfig_set_vconf_int(VCONF_WIFI_OFF_STATE_BY_AIRPLANE, 0); + + return TRUE; +} diff --git a/wearable/src/wifi-ssid-scan.c b/wearable/src/wifi-ssid-scan.c new file mode 100644 index 0000000..6a58961 --- /dev/null +++ b/wearable/src/wifi-ssid-scan.c @@ -0,0 +1,506 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "neterror.h" +#include "netdbus.h" +#include "netsupplicant.h" +#include "wifi-ssid-scan.h" +#include "wifi-background-scan.h" + +enum netconfig_wifi_security { + WIFI_SECURITY_UNKNOWN = 0x00, + WIFI_SECURITY_NONE = 0x01, + WIFI_SECURITY_WEP = 0x02, + WIFI_SECURITY_PSK = 0x03, + WIFI_SECURITY_IEEE8021X = 0x04, +}; + +struct bss_info_t { + unsigned char ssid[33]; + enum netconfig_wifi_security security; + dbus_bool_t privacy; + dbus_bool_t wps; +}; + +static gboolean wifi_ssid_scan_state = FALSE; +static GSList *wifi_bss_info_list = NULL; +static guint netconfig_wifi_ssid_scan_timer = 0; + +static gboolean __netconfig_wifi_ssid_scan_timeout(gpointer data) +{ + netconfig_wifi_notify_ssid_scan_done(); + + return FALSE; +} + +static void __netconfig_wifi_ssid_scan_started(void) +{ + INFO("Wi-Fi SSID scan started"); + wifi_ssid_scan_state = TRUE; + + netconfig_start_timer_seconds(5, + __netconfig_wifi_ssid_scan_timeout, + NULL, + &netconfig_wifi_ssid_scan_timer); +} + +static void __netconfig_wifi_ssid_scan_finished(void) +{ + INFO("Wi-Fi SSID scan finished"); + wifi_ssid_scan_state = FALSE; + + netconfig_stop_timer(&netconfig_wifi_ssid_scan_timer); +} + +static gboolean __netconfig_wifi_invoke_ssid_scan( + const char *object_path, const char *ssid) +{ + /* TODO: Revise following code */ + +#define NETCONFIG_DBUS_REPLY_TIMEOUT (10 * 1000) + + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusMessage *reply = NULL; + DBusMessageIter iter, dict, entry; + DBusMessageIter value, array, array2; + DBusError error; + const char *key1 = "Type"; + const char *val1 = "active"; + const char *key2 = "SSIDs"; + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system DBus"); + goto error; + } + + message = dbus_message_new_method_call(SUPPLICANT_SERVICE, + object_path, SUPPLICANT_INTERFACE ".Interface", "Scan"); + if (message == NULL) { + ERR("Error!!! DBus method call fail"); + goto error; + } + + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + + dbus_message_iter_open_container(&dict, + DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key1); + + dbus_message_iter_open_container(&entry, + DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &val1); + + dbus_message_iter_close_container(&entry, &value); + dbus_message_iter_close_container(&dict, &entry); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key2); + + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING + DBUS_TYPE_ARRAY_AS_STRING + DBUS_TYPE_BYTE_AS_STRING, + &value); + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, + DBUS_TYPE_ARRAY_AS_STRING + DBUS_TYPE_BYTE_AS_STRING, + &array); + dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &array2); + + dbus_message_iter_append_fixed_array(&array2, DBUS_TYPE_BYTE, &ssid, strlen(ssid)); + + dbus_message_iter_close_container(&array, &array2); + dbus_message_iter_close_container(&value, &array); + dbus_message_iter_close_container(&entry, &value); + dbus_message_iter_close_container(&dict, &entry); + dbus_message_iter_close_container(&iter, &dict); + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block(connection, message, + NETCONFIG_DBUS_REPLY_TIMEOUT, &error); + + if (reply == NULL) { + if (dbus_error_is_set(&error) == TRUE) { + ERR("Error!!! dbus_connection_send_with_reply_and_block() failed. " + "DBus error [%s: %s]", error.name, error.message); + + dbus_error_free(&error); + return FALSE; + } else + ERR("Error!!! Failed to get properties"); + + goto error; + } + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) { + const char *err_msg = dbus_message_get_error_name(reply); + ERR("Error!!! Error message received %s", err_msg); + goto error; + } + + dbus_message_unref(message); + dbus_message_unref(reply); + dbus_connection_unref(connection); + + return TRUE; + +error: + if (message != NULL) + dbus_message_unref(message); + + if (reply != NULL) + dbus_message_unref(reply); + + if (connection != NULL) + dbus_connection_unref(connection); + + return FALSE; +} + +static void __netconfig_wifi_notify_ssid_scan_done(void) +{ + DBusMessage *signal; + DBusConnection *connection = NULL; + DBusMessageIter dict, type, array, value; + DBusError error; + + GSList* list = NULL; + const char *prop_ssid = "ssid"; + const char *prop_security = "security"; + const char *prop_wps = "wps"; + const char *sig_name = "SpecificScanCompleted"; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + ERR("Failed to get system DBus, error [%s]", error.message); + dbus_error_free(&error); + + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + + return; + } + + signal = dbus_message_new_signal(NETCONFIG_WIFI_PATH, NETCONFIG_WIFI_INTERFACE, sig_name); + if (signal == NULL) { + dbus_connection_unref(connection); + + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + + return; + } + + dbus_message_iter_init_append(signal, &array); + dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, "{sv}", &dict); + + for (list = wifi_bss_info_list; list != NULL; list = list->next) { + struct bss_info_t *bss_info = (struct bss_info_t *)list->data; + + if (bss_info) { + char *ssid = (char *)bss_info->ssid; + enum netconfig_wifi_security security = bss_info->security; + dbus_bool_t wps = bss_info->wps; + DBG("BSS found; SSID:%s security:%d WPS:%d", ssid, security, wps); + + /* SSID */ + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_ssid); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &ssid); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + + /* Security */ + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_security); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_INT32, &security); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + + /* WPS */ + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_wps); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_BOOLEAN_AS_STRING, &value); + + dbus_message_iter_append_basic(&value, DBUS_TYPE_BOOLEAN, &wps); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + } + } + + dbus_message_iter_close_container(&array, &dict); + + dbus_connection_send(connection, signal, NULL); + + dbus_message_unref(signal); + dbus_connection_unref(connection); + + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + + INFO("(%s)", sig_name); +} + +static void __netconfig_wifi_check_security(const char *str_keymgmt, struct bss_info_t *bss_data) +{ + INFO("keymgmt : %s", str_keymgmt); + + if (strcmp(str_keymgmt, "ieee8021x") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wpa-psk") == 0) { + bss_data->security = WIFI_SECURITY_PSK; + } else if (strcmp(str_keymgmt, "wpa-psk-sha256") == 0) { + bss_data->security = WIFI_SECURITY_PSK; + } else if (strcmp(str_keymgmt, "wpa-ft-psk") == 0) { + bss_data->security = WIFI_SECURITY_PSK; + } else if (strcmp(str_keymgmt, "wpa-ft-eap") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wpa-eap") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wpa-eap-sha256") == 0) { + bss_data->security = WIFI_SECURITY_IEEE8021X; + } else if (strcmp(str_keymgmt, "wps") == 0) { + bss_data->wps = TRUE; + } +} + +static void __netconfig_wifi_parse_keymgmt_message(DBusMessageIter *iter, struct bss_info_t *bss_data) +{ + DBusMessageIter dict, entry, array, value; + const char *key; + + if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(iter, &dict); + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&dict, &entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) + return; + + dbus_message_iter_get_basic(&entry, &key); + if (g_strcmp0(key, "KeyMgmt") == 0) { + dbus_message_iter_next(&entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) + return; + + dbus_message_iter_recurse(&entry, &array); + if (dbus_message_iter_get_arg_type(&array) != DBUS_TYPE_ARRAY) + return; + + dbus_message_iter_recurse(&array, &value); + while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) { + const char *str = NULL; + + dbus_message_iter_get_basic(&value, &str); + if (str == NULL) + return; + + __netconfig_wifi_check_security(str, bss_data); + dbus_message_iter_next(&value); + } + } + + dbus_message_iter_next(&dict); + } +} + +gboolean netconfig_wifi_get_ssid_scan_state(void) +{ + return wifi_ssid_scan_state; +} + +void netconfig_wifi_notify_ssid_scan_done(void) +{ + if (netconfig_wifi_get_ssid_scan_state() != TRUE) + return; + + __netconfig_wifi_ssid_scan_finished(); + + __netconfig_wifi_notify_ssid_scan_done(); +} + +void netconfig_wifi_bss_added(DBusMessage *message) +{ + DBusMessageIter iter, dict, entry; + DBusMessageIter value, array; + const char *key; + struct bss_info_t *bss_info; + + if (netconfig_wifi_get_ssid_scan_state() != TRUE) + return; + + INFO("NEW BSS added"); + + if (!dbus_message_iter_init(message, &iter)) { + DBG("Message does not have parameters"); + return; + } + + dbus_message_iter_next(&iter); + + if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) { + DBG("Invalid message type"); + return; + } + + bss_info = g_try_new0(struct bss_info_t, 1); + if (bss_info == NULL) + return; + + dbus_message_iter_recurse(&iter, &dict); + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(&dict, &entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) + return; + + dbus_message_iter_get_basic(&entry, &key); + if (key == NULL) + return; + + dbus_message_iter_next(&entry); + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) + return; + + dbus_message_iter_recurse(&entry, &value); + + if (g_strcmp0(key, "SSID") == 0) { + unsigned char *ssid; + int ssid_len; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len); + + if (ssid_len > 0 && ssid_len < 33) + memcpy(bss_info->ssid, ssid, ssid_len); + else + memset(bss_info->ssid, 0, sizeof(bss_info->ssid)); + } else if (g_strcmp0(key, "Privacy") == 0) { + dbus_bool_t privacy = FALSE; + + dbus_message_iter_get_basic(&value, &privacy); + bss_info->privacy = privacy; + } else if ((g_strcmp0(key, "RSN") == 0) || (g_strcmp0(key, "WPA") == 0)) { + + __netconfig_wifi_parse_keymgmt_message(&value, bss_info); + } else if (g_strcmp0(key, "IEs") == 0) { + unsigned char *ie; + int ie_len; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, &ie, &ie_len); + } + + dbus_message_iter_next(&dict); + } + + if (bss_info->ssid[0] == '\0') { + g_free(bss_info); + return; + } + + if (bss_info->security == WIFI_SECURITY_UNKNOWN) { + if (bss_info->privacy == TRUE) + bss_info->security = WIFI_SECURITY_WEP; + else + bss_info->security = WIFI_SECURITY_NONE; + } + + wifi_bss_info_list = g_slist_append(wifi_bss_info_list, bss_info); +} + +gboolean netconfig_wifi_ssid_scan(const char *ssid) +{ + const char *if_path; + static char *scan_ssid = NULL; + + netconfig_wifi_bgscan_stop(); + + if (ssid != NULL) { + g_free(scan_ssid); + scan_ssid = g_strdup(ssid); + } + + if (scan_ssid == NULL) + goto error; + + if_path = netconfig_wifi_get_supplicant_interface(); + if (if_path == NULL) { + DBG("Fail to get wpa_supplicant DBus path"); + goto error; + } + + if (netconfig_wifi_get_scanning() == TRUE) { + DBG("Wi-Fi scan in progress, %s scan will be delayed", scan_ssid); + return TRUE; + } + + if (wifi_bss_info_list) { + g_slist_free_full(wifi_bss_info_list, g_free); + wifi_bss_info_list = NULL; + } + + INFO("Start Wi-Fi scan with %s(%d)", scan_ssid, strlen(scan_ssid)); + if (__netconfig_wifi_invoke_ssid_scan(if_path, + (const char *)scan_ssid) == TRUE) { + __netconfig_wifi_ssid_scan_started(); + + g_free(scan_ssid); + scan_ssid = NULL; + + return TRUE; + } + +error: + if (scan_ssid != NULL) { + g_free(scan_ssid); + scan_ssid = NULL; + } + + netconfig_wifi_bgscan_start(); + + return FALSE; +} + +gboolean netconfig_iface_wifi_request_specific_scan(NetconfigWifi *wifi, + gchar *ssid, GError **error) +{ + g_return_val_if_fail(wifi != NULL, FALSE); + g_return_val_if_fail(ssid != NULL, FALSE); + + return netconfig_wifi_ssid_scan((const char *)ssid); +} diff --git a/wearable/src/wifi-state.c b/wearable/src/wifi-state.c new file mode 100644 index 0000000..399fa59 --- /dev/null +++ b/wearable/src/wifi-state.c @@ -0,0 +1,704 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "wifi-state.h" +#include "wifi-power.h" +#include "netsupplicant.h" +#include "network-state.h" +#include "wifi-indicator.h" +#include "network-statistics.h" +#include "wifi-background-scan.h" + +static gboolean new_bss_found = FALSE; + +static enum netconfig_wifi_service_state + wifi_service_state = NETCONFIG_WIFI_UNKNOWN; +static enum netconfig_wifi_tech_state + wifi_technology_state = NETCONFIG_WIFI_TECH_UNKNOWN; + +static GSList *notifier_list = NULL; + + +static void __netconfig_pop_wifi_connected_poppup(const char *ssid) +{ + bundle *b = NULL; + + if (ssid == NULL) + return; + + b = bundle_create(); + + bundle_add(b, "_SYSPOPUP_TITLE_", "Network connection popup"); + bundle_add(b, "_SYSPOPUP_TYPE_", "notification"); + bundle_add(b, "_SYSPOPUP_CONTENT_", "wifi connected"); + bundle_add(b, "_AP_NAME_", ssid); + + DBG("Launch Wi-Fi connected alert network popup"); + aul_launch_app("net.netpopup", b); + + bundle_free(b); +} + +static void __netconfig_wifi_state_connected_activation(void) +{ + /* Add activation of services when Wi-Fi is connected */ + bundle *b = NULL; + + b = bundle_create(); + aul_launch_app("com.samsung.keepit-service-standby", b); + bundle_free(b); + + /* logd service checks Wi-Fi state */ +} + +static void __netconfig_wifi_state_disconnected_activation(void) +{ + /* Add activation of services when Wi-Fi is disconnected */ + + /* logd service checks Wi-Fi state */ +} + +static void __netconfig_wifi_state_powered_activation(gboolean powered) +{ + if (powered == TRUE) { + /* Add activation when Wi-Fi is powered on */ + + /* logd service checks Wi-Fi power state */ + } else { + /* Add activation when Wi-Fi is powered off */ + + /* logd service checks Wi-Fi power state */ + } +} + +static void __netconfig_wifi_set_essid(void) +{ + const char *essid_name = NULL; + const char *wifi_profile = netconfig_get_default_profile(); + + if (netconfig_wifi_state_get_service_state() != NETCONFIG_WIFI_CONNECTED) + return; + + if (wifi_profile == NULL || + netconfig_is_wifi_profile(wifi_profile) != TRUE) { + ERR("Can't get Wi-Fi profile"); + return; + } + + essid_name = netconfig_wifi_get_connected_essid(wifi_profile); + if (essid_name == NULL) { + ERR("Can't get Wi-Fi name"); + return; + } + + netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, essid_name); + + __netconfig_pop_wifi_connected_poppup(essid_name); +} + +static void __netconfig_wifi_unset_essid(void) +{ + netconfig_set_vconf_str(VCONFKEY_WIFI_CONNECTED_AP_NAME, ""); +} + +static gboolean __netconfig_is_wifi_profile_available(void) +{ + DBusMessage *message = NULL; + DBusMessageIter iter, array; + int ret = FALSE; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetServices", NULL); + if (message == NULL) { + ERR("Failed to get service list"); + return FALSE; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry; + const char *obj = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &obj); + + if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE) { + dbus_message_iter_next(&array); + continue; + } + + ret = TRUE; + goto done; + } + +done: + dbus_message_unref(message); + + return ret; +} + +static char *__netconfig_wifi_get_connman_favorite_service(void) +{ + char *favorite_service = NULL; + DBusMessage *message = NULL; + DBusMessageIter iter, array; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetServices", NULL); + if (message == NULL) { + ERR("Failed to get service list"); + return NULL; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry; + DBusMessageIter dict; + const char *obj = NULL; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &obj); + + if (obj == NULL || netconfig_is_wifi_profile(obj) == FALSE) { + dbus_message_iter_next(&array); + continue; + } + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, variant; + const char *key = NULL; + dbus_bool_t value; + + dbus_message_iter_recurse(&dict, &entry); + dbus_message_iter_get_basic(&entry, &key); + + if (g_str_equal(key, "Favorite") != TRUE) { + dbus_message_iter_next(&dict); + continue; + } + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &variant); + + dbus_message_iter_get_basic(&variant, &value); + + if (value) + favorite_service = g_strdup(obj); + + goto done; + } + + dbus_message_iter_next(&array); + } + +done: + dbus_message_unref(message); + + return favorite_service; +} + +static void __netconfig_wifi_state_changed( + enum netconfig_wifi_service_state state) +{ + GSList *list; + + for (list = notifier_list; list; list = list->next) { + struct netconfig_wifi_state_notifier *notifier = list->data; + + if (notifier->netconfig_wifi_state_changed != NULL) + notifier->netconfig_wifi_state_changed(state, notifier->user_data); + } +} + +void netconfig_wifi_set_bss_found(const gboolean found) +{ + if (found != new_bss_found) + new_bss_found = found; +} + +gboolean netconfig_wifi_is_bss_found(void) +{ + return new_bss_found; +} + +static void __netconfig_wifi_state_set_power_save(gboolean power_save) +{ + dbus_bool_t result; + const char *if_path; + GList *input_args = NULL; + static gboolean old_state = TRUE; + + struct dbus_input_arguments args_disable[2] = { + {DBUS_TYPE_STRING, "POWERMODE 1"}, + {DBUS_TYPE_INVALID, NULL} + }; + struct dbus_input_arguments args_enable[2] = { + {DBUS_TYPE_STRING, "POWERMODE 0"}, + {DBUS_TYPE_INVALID, NULL} + }; + + if (old_state == power_save) + return; + + if_path = netconfig_wifi_get_supplicant_interface(); + if (if_path == NULL) { + ERR("Fail to get wpa_supplicant DBus path"); + return; + } + + if (power_save) + input_args = setup_input_args(input_args, args_enable); + else + input_args = setup_input_args(input_args, args_disable); + + result = netconfig_supplicant_invoke_dbus_method_nonblock( + SUPPLICANT_SERVICE, if_path, + SUPPLICANT_INTERFACE ".Interface", "Driver", input_args, + NULL); + if (result == FALSE) + ERR("Fail to set power save mode POWERMODE %d", power_save); + else + old_state = power_save; + + g_list_free(input_args); +} + +static void __netconfig_wifi_state_set_power_lock(gboolean power_lock) +{ + int ret = 0; + DBusMessage *reply; + char state[] = "string:lcdoff"; + char flag[] = "string:staycurstate"; + char standby[] = "string:NULL"; + char timeout[] = "int32:0"; + char sleepmargin[] = "string:sleepmargin"; + char *param_array[] = { NULL, NULL, NULL, NULL, NULL }; + + const char *lockstate = "lockstate"; + const char *unlockstate = "unlockstate"; + static gboolean old_state = FALSE; + const char *lock_method; + + if (old_state == power_lock) + return; + + if (power_lock == TRUE) { + /* deviced power lock enable */ + param_array[0] = state; + param_array[1] = flag; + param_array[2] = standby; + param_array[3] = timeout; + + lock_method = lockstate; + } else { + /* deviced power lock disable */ + param_array[0] = state; + param_array[1] = sleepmargin; + + lock_method = unlockstate; + } + + reply = netconfig_invoke_dbus_method( + "org.tizen.system.deviced", + "/Org/Tizen/System/DeviceD/Display", + "org.tizen.system.deviced.display", + lock_method, + param_array); + if (reply == NULL) + return; + + dbus_message_get_args(reply, NULL, DBUS_TYPE_INT32, + &ret, DBUS_TYPE_INVALID); + if (ret < 0) + ERR("Failed to set power lock %s with ret %d", + power_lock == TRUE ? "enable" : "disable", ret); + else + old_state = power_lock; + + dbus_message_unref(reply); +} + +void netconfig_wifi_state_set_service_state( + enum netconfig_wifi_service_state new_state) +{ + static gboolean dhcp_stage = FALSE; + enum netconfig_wifi_service_state old_state = wifi_service_state; + + if (old_state == new_state) + return; + + wifi_service_state = new_state; + DBG("Wi-Fi state %d ==> %d", old_state, new_state); + + /* During DHCP, temporarily disable Wi-Fi power saving */ + if ((old_state < NETCONFIG_WIFI_CONNECTING || + old_state == NETCONFIG_WIFI_FAILURE) && + new_state == NETCONFIG_WIFI_CONNECTING) { + __netconfig_wifi_state_set_power_lock(TRUE); + __netconfig_wifi_state_set_power_save(FALSE); + dhcp_stage = TRUE; + } else if (dhcp_stage == TRUE) { + __netconfig_wifi_state_set_power_lock(FALSE); + __netconfig_wifi_state_set_power_save(TRUE); + dhcp_stage = FALSE; + } + + if (new_state == NETCONFIG_WIFI_CONNECTED) { + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL); + + netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_CONNECTED); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, + VCONFKEY_NETWORK_WIFI_CONNECTED); + + __netconfig_wifi_set_essid(); + + netconfig_wifi_indicator_start(); + } else if (old_state == NETCONFIG_WIFI_CONNECTED) { + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL); + + netconfig_set_vconf_int (VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_UNCONNECTED); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, + VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); + + __netconfig_wifi_unset_essid(); + + netconfig_wifi_indicator_stop(); + + netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_start(); + } + + __netconfig_wifi_state_changed(new_state); + + if (new_state == NETCONFIG_WIFI_CONNECTED) + __netconfig_wifi_state_connected_activation(); + else if (old_state == NETCONFIG_WIFI_CONNECTED) + __netconfig_wifi_state_disconnected_activation(); +} + +enum netconfig_wifi_service_state +netconfig_wifi_state_get_service_state(void) +{ + return wifi_service_state; +} + +void netconfig_wifi_state_set_technology_state( + enum netconfig_wifi_tech_state new_state) +{ + enum netconfig_wifi_tech_state old_state = wifi_technology_state; + + if (old_state == new_state) + return; + + wifi_technology_state = new_state; + + DBG("Wi-Fi technology state %d ==> %d", old_state, new_state); +} + +enum netconfig_wifi_tech_state netconfig_wifi_state_get_technology_state(void) +{ + DBusMessage *message = NULL; + DBusMessageIter iter, array; + enum netconfig_wifi_tech_state ret = NETCONFIG_WIFI_TECH_OFF; + gboolean wifi_tech_powered = FALSE; + gboolean wifi_tech_connected = FALSE; + + if (wifi_technology_state > NETCONFIG_WIFI_TECH_UNKNOWN) + return wifi_technology_state; + + message = netconfig_invoke_dbus_method(CONNMAN_SERVICE, + CONNMAN_MANAGER_PATH, CONNMAN_MANAGER_INTERFACE, + "GetTechnologies", NULL); + if (message == NULL) { + ERR("Failed to get Wi-Fi technology state"); + return NETCONFIG_WIFI_TECH_UNKNOWN; + } + + dbus_message_iter_init(message, &iter); + dbus_message_iter_recurse(&iter, &array); + + while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRUCT) { + DBusMessageIter entry, dict; + const char *path; + + dbus_message_iter_recurse(&array, &entry); + dbus_message_iter_get_basic(&entry, &path); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &dict); + + if (path == NULL || + g_str_equal(path, CONNMAN_WIFI_TECHNOLOGY_PREFIX) == FALSE) { + dbus_message_iter_next(&array); + continue; + } + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry1, value1; + const char *key, *sdata; + dbus_bool_t data; + + dbus_message_iter_recurse(&dict, &entry1); + dbus_message_iter_get_basic(&entry1, &key); + + dbus_message_iter_next(&entry1); + dbus_message_iter_recurse(&entry1, &value1); + + if (dbus_message_iter_get_arg_type(&value1) == + DBUS_TYPE_BOOLEAN) { + dbus_message_iter_get_basic(&value1, &data); + DBG("key-[%s] - %s", key, data ? "True" : "False"); + + if (strcmp(key, "Powered") == 0 && data) { + wifi_tech_powered = TRUE; + } else if (strcmp(key, "Connected") == 0 && data) { + wifi_tech_connected = TRUE; + } else if (strcmp(key, "Tethering") == 0 && data) { + /* For further use */ + } + } else if (dbus_message_iter_get_arg_type(&value1) == + DBUS_TYPE_STRING) { + dbus_message_iter_get_basic(&value1, &sdata); + DBG("%s", sdata); + } + + dbus_message_iter_next(&dict); + } + + dbus_message_iter_next(&array); + } + + dbus_message_unref(message); + + if (wifi_tech_powered == TRUE) + ret = NETCONFIG_WIFI_TECH_POWERED; + + if (wifi_tech_connected == TRUE) + ret = NETCONFIG_WIFI_TECH_CONNECTED; + + wifi_technology_state = ret; + + return wifi_technology_state; +} + +void netconfig_wifi_notify_power_failed(void) +{ + DBusMessage *signal; + DBusConnection *connection = NULL; + DBusError error; + char *sig_name = "PowerOperationFailed"; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + ERR("Failed to get system DBus, error [%s]", error.message); + dbus_error_free(&error); + return; + } + + signal = dbus_message_new_signal(NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, sig_name); + if (signal == NULL) + return; + + dbus_connection_send(connection, signal, NULL); + + dbus_message_unref(signal); + dbus_connection_unref(connection); +} + +void netconfig_wifi_notify_power_completed(gboolean power_on) +{ + DBusMessage *signal; + DBusConnection *connection = NULL; + DBusError error; + char *sig_name = NULL; + + if (power_on) + sig_name = "PowerOnCompleted"; + else + sig_name = "PowerOffCompleted"; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + ERR("Failed to get system DBus, error [%s]", error.message); + dbus_error_free(&error); + return; + } + + signal = dbus_message_new_signal(NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, sig_name); + if (signal == NULL) + return; + + dbus_connection_send(connection, signal, NULL); + + DBG("Successfully sent signal [%s]", sig_name); + + dbus_message_unref(signal); + dbus_connection_unref(connection); +} + +void netconfig_wifi_update_power_state(gboolean powered) +{ + enum netconfig_wifi_tech_state wifi_tech_state; + + /* It's automatically updated by signal-handler + * DO NOT update manually + * It includes Wi-Fi state configuration + */ + wifi_tech_state = netconfig_wifi_state_get_technology_state(); + + if (powered == TRUE) { + if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED && + netconfig_is_wifi_tethering_on() != TRUE) { + DBG("Wi-Fi turned on"); + + netconfig_wifi_state_set_technology_state( + NETCONFIG_WIFI_TECH_POWERED); + + netconfig_wifi_notify_power_completed(TRUE); + + netconfig_wifi_device_picker_service_start(); + + netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, + VCONFKEY_WIFI_UNCONNECTED); + netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, + VCONFKEY_WIFI_UNCONNECTED); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, + VCONFKEY_NETWORK_WIFI_NOT_CONNECTED); + + netconfig_wifi_bgscan_stop(); + netconfig_wifi_bgscan_start(); + } + } else if (wifi_tech_state > NETCONFIG_WIFI_TECH_OFF) { + DBG("Wi-Fi turned off"); + + netconfig_wifi_state_set_technology_state( + NETCONFIG_WIFI_TECH_WPS_ONLY); + + netconfig_wifi_device_picker_service_stop(); + + netconfig_wifi_driver_and_supplicant(FALSE); + + netconfig_wifi_notify_power_completed(FALSE); + + netconfig_set_vconf_int(VCONF_WIFI_LAST_POWER_STATE, VCONFKEY_WIFI_OFF); + netconfig_set_vconf_int(VCONFKEY_WIFI_STATE, VCONFKEY_WIFI_OFF); + netconfig_set_vconf_int(VCONFKEY_NETWORK_WIFI_STATE, + VCONFKEY_NETWORK_WIFI_OFF); + + netconfig_wifi_bgscan_stop(); + + netconfig_wifi_set_bss_found(FALSE); + + /* Inform net-popup to remove the wifi found notification */ + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_FOUND_AP_NOTI, NULL); + netconfig_send_notification_to_net_popup(NETCONFIG_DEL_PORTAL_NOTI, NULL); + } + + __netconfig_wifi_state_powered_activation(powered); +} + +char *netconfig_wifi_get_favorite_service(void) +{ + return __netconfig_wifi_get_connman_favorite_service(); +} + +void netconfig_wifi_check_network_notification(void) +{ + int qs_enable = 0, ug_state = 0; + enum netconfig_wifi_tech_state wifi_tech_state; + enum netconfig_wifi_service_state wifi_service_state; + + wifi_service_state = netconfig_wifi_state_get_service_state(); + if (wifi_service_state == NETCONFIG_WIFI_CONNECTED) { + DBG("Service state is connected"); + return; + } + + wifi_tech_state = netconfig_wifi_state_get_technology_state(); + if (wifi_tech_state < NETCONFIG_WIFI_TECH_POWERED) { + DBG("Wi-Fi off or WPS only supported[%d]", wifi_tech_state); + return; + } + + if (FALSE == netconfig_wifi_is_bss_found()) { + if (__netconfig_is_wifi_profile_available() == FALSE) { + netconfig_send_notification_to_net_popup( + NETCONFIG_DEL_FOUND_AP_NOTI, NULL); + } + return; + } + + vconf_get_int(VCONFKEY_WIFI_ENABLE_QS, &qs_enable); + if (qs_enable != VCONFKEY_WIFI_QS_ENABLE) { + DBG("qs_enable != VCONFKEY_WIFI_QS_ENABLE"); + return; + } + + vconf_get_int(VCONFKEY_WIFI_UG_RUN_STATE, &ug_state); + if (ug_state == VCONFKEY_WIFI_UG_RUN_STATE_ON_FOREGROUND) { + return; + } + + netconfig_send_notification_to_net_popup(NETCONFIG_ADD_FOUND_AP_NOTI, NULL); + + netconfig_wifi_set_bss_found(FALSE); +} + +void netconfig_wifi_state_notifier_cleanup(void) +{ + g_slist_free_full(notifier_list, NULL); +} + +void netconfig_wifi_state_notifier_register( + struct netconfig_wifi_state_notifier *notifier) +{ + DBG("register notifier"); + + notifier_list = g_slist_append(notifier_list, notifier); +} + +void netconfig_wifi_state_notifier_unregister( + struct netconfig_wifi_state_notifier *notifier) +{ + DBG("un-register notifier"); + + notifier_list = g_slist_remove_all(notifier_list, notifier); +} diff --git a/wearable/src/wifi-wps.c b/wearable/src/wifi-wps.c new file mode 100644 index 0000000..20437bf --- /dev/null +++ b/wearable/src/wifi-wps.c @@ -0,0 +1,610 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "wifi-wps.h" +#include "wifi-power.h" +#include "wifi-state.h" +#include "netsupplicant.h" +#include "wifi-background-scan.h" + +#define NETCONFIG_SSID_LEN 32 +#define NETCONFIG_BSSID_LEN 6 +#define NETCONFIG_WPS_DBUS_REPLY_TIMEOUT (10 * 1000) + +#define VCONF_WIFI_ALWAYS_ALLOW_SCANNING \ + "file/private/wifi/always_allow_scanning" + +static gboolean netconfig_is_wps_enabled = FALSE; +static gboolean netconfig_is_device_scanning = FALSE; +static gboolean netconfig_is_wps_scan_aborted = FALSE; +static int wps_bss_list_count = 0; + +struct wps_bss_info_t { + unsigned char ssid[NETCONFIG_SSID_LEN + 1]; + unsigned char bssid[NETCONFIG_BSSID_LEN + 1]; + int ssid_len; + int rssi; + int mode; +}; + +static GSList *wps_bss_info_list = NULL; + +static void __netconfig_wps_set_mode(gboolean enable) +{ + if (netconfig_is_wps_enabled == enable) + return; + + netconfig_is_wps_enabled = enable; +} + +gboolean netconfig_wifi_is_wps_enabled(void) +{ + return netconfig_is_wps_enabled; +} + +static void __netconfig_wifi_wps_notify_scan_done(void) +{ + DBusMessage *signal; + DBusConnection *connection = NULL; + DBusMessageIter dict, type, array, value, iter; + DBusError error; + + GSList* list = NULL; + const char *prop_ssid = "ssid"; + const char *prop_bssid = "bssid"; + const char *prop_rssi = "rssi"; + const char *prop_mode = "mode"; + const char *sig_name = "WpsScanCompleted"; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); + if (connection == NULL) { + ERR("Failed to get system DBus, error [%s]", error.message); + dbus_error_free(&error); + return; + } + + signal = dbus_message_new_signal(NETCONFIG_WIFI_PATH, + NETCONFIG_WIFI_INTERFACE, sig_name); + if (signal == NULL) { + dbus_connection_unref(connection); + return; + } + + dbus_message_iter_init_append(signal, &array); + dbus_message_iter_open_container(&array, DBUS_TYPE_ARRAY, "{sv}", &dict); + + for (list = wps_bss_info_list; list != NULL; list = list->next) { + struct wps_bss_info_t *bss_info = (struct wps_bss_info_t *)list->data; + + if (bss_info) { + char bssid_buff[18] = { 0, }; + char *bssid_str = bssid_buff; + unsigned char *ssid = (unsigned char *)bss_info->ssid; + int ssid_len = (int)bss_info->ssid_len; + int rssi = (int)bss_info->rssi; + int mode = (int)bss_info->mode; + g_snprintf(bssid_buff, 18, "%02x:%02x:%02x:%02x:%02x:%02x", + bss_info->bssid[0], bss_info->bssid[1], bss_info->bssid[2], + bss_info->bssid[3], bss_info->bssid[4], bss_info->bssid[5]); + + DBG("BSS found; SSID %s, BSSID %s, RSSI %d MODE %d", ssid, bssid_str, rssi, mode); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_ssid); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, + DBUS_TYPE_ARRAY_AS_STRING + DBUS_TYPE_BYTE_AS_STRING, + &value); + dbus_message_iter_open_container(&value, DBUS_TYPE_ARRAY, DBUS_TYPE_BYTE_AS_STRING, &iter); + dbus_message_iter_append_fixed_array(&iter, DBUS_TYPE_BYTE, &ssid, ssid_len); + dbus_message_iter_close_container(&value, &iter); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_bssid); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &bssid_str); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_rssi); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_INT32, &rssi); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, 0, &type); + dbus_message_iter_append_basic(&type, DBUS_TYPE_STRING, &prop_mode); + dbus_message_iter_open_container(&type, DBUS_TYPE_VARIANT, DBUS_TYPE_INT32_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_INT32, &mode); + dbus_message_iter_close_container(&type, &value); + dbus_message_iter_close_container(&dict, &type); + } + } + + dbus_message_iter_close_container(&array, &dict); + + dbus_connection_send(connection, signal, NULL); + + dbus_message_unref(signal); + dbus_connection_unref(connection); + + g_slist_free_full(wps_bss_info_list, g_free); + wps_bss_info_list = NULL; + wps_bss_list_count = 0; +} + +static void __netconfig_wifi_wps_get_bss_info_result( + DBusPendingCall *call, void *data) +{ + DBusMessage *reply; + DBusMessageIter iter; + DBusMessageIter dict; + struct wps_bss_info_t *bss_info; + + reply = dbus_pending_call_steal_reply(call); + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) + goto done; + + if (dbus_message_iter_init(reply, &iter) == FALSE) + goto done; + + bss_info = g_try_new0(struct wps_bss_info_t, 1); + if (bss_info == NULL) + goto done; + + if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_ARRAY) { + dbus_message_iter_recurse(&iter, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter entry, value; + const char *key; + + dbus_message_iter_recurse(&dict, &entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_STRING) + break; + + dbus_message_iter_get_basic(&entry, &key); + dbus_message_iter_next(&entry); + + if (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_VARIANT) + break; + + dbus_message_iter_recurse(&entry, &value); + + if (key != NULL) { + if (g_strcmp0(key, "BSSID") == 0) { + DBusMessageIter array; + unsigned char *bssid; + int bssid_len; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, &bssid, &bssid_len); + + if (bssid_len == NETCONFIG_BSSID_LEN) + memcpy(bss_info->bssid, bssid, bssid_len); + } else if (g_strcmp0(key, "SSID") == 0) { + DBusMessageIter array; + unsigned char *ssid; + int ssid_len; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, &ssid, &ssid_len); + + if (ssid_len > 0 && ssid_len <= NETCONFIG_SSID_LEN) { + memcpy(bss_info->ssid, ssid, ssid_len); + bss_info->ssid_len = ssid_len; + } else { + memset(bss_info->ssid, 0, sizeof(bss_info->ssid)); + bss_info->ssid_len = 0; + } + } else if (g_strcmp0(key, "Mode") == 0) {; + const char *mode = NULL; + + dbus_message_iter_get_basic(&value, &mode); + + if (mode == NULL) + bss_info->mode = 0; + else { + if (g_str_equal(mode, "infrastructure") == TRUE) + bss_info->mode = 1; + else if (g_str_equal(mode, "ad-hoc") == TRUE) + bss_info->mode = 2; + else + bss_info->mode = 0; + } + } else if (g_strcmp0(key, "Signal") == 0) { + dbus_int16_t signal = 0; + + dbus_message_iter_get_basic(&value, &signal); + + bss_info->rssi = signal; + } + } + + dbus_message_iter_next(&dict); + } + } + + if (bss_info->ssid[0] == '\0') + g_free(bss_info); + else + wps_bss_info_list = g_slist_append(wps_bss_info_list, bss_info); + +done: + dbus_message_unref(reply); + + dbus_pending_call_unref(call); + + wps_bss_list_count--; + if (wps_bss_list_count <= 0) { + __netconfig_wifi_wps_notify_scan_done(); + + if (netconfig_is_wps_scan_aborted == FALSE) + netconfig_wifi_driver_and_supplicant(FALSE); + } +} + +static void __netconfig_wifi_wps_get_bss_info(const char *path, int index) +{ + gboolean reply = FALSE; + char *param0 = NULL; + char *param_array[] = { NULL, NULL }; + + param0 = g_strdup_printf("string:%s", SUPPLICANT_IFACE_BSS); + param_array[0] = param0; + reply = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE, + path, DBUS_INTERFACE_PROPERTIES, + "GetAll", param_array, __netconfig_wifi_wps_get_bss_info_result); + if (reply != TRUE) + ERR("Fail to invoke_dbus_method_nonblock GetAll"); + + if (param0) + g_free(param0); +} + +static void __netconfig_wifi_wps_get_bsss_result( + DBusPendingCall *call, void *data) +{ + DBusMessage *reply; + DBusMessageIter iter; + char *path; + + reply = dbus_pending_call_steal_reply(call); + + if (dbus_message_get_type(reply) == DBUS_MESSAGE_TYPE_ERROR) + goto done; + + if (dbus_message_iter_init(reply, &iter) == FALSE) + goto done; + + if (dbus_message_iter_get_arg_type(&iter) == DBUS_TYPE_VARIANT) { + DBusMessageIter variant, entry; + + dbus_message_iter_recurse(&iter, &variant); + + if (dbus_message_iter_get_arg_type(&variant) == DBUS_TYPE_ARRAY) { + dbus_message_iter_recurse(&variant, &entry); + while (dbus_message_iter_get_arg_type(&entry) != DBUS_TYPE_INVALID) { + dbus_message_iter_get_basic(&entry, &path); + if (path != NULL && g_strcmp0(path, "/") != 0) + __netconfig_wifi_wps_get_bss_info(path, ++wps_bss_list_count); + + dbus_message_iter_next(&entry); + } + } + } + +done: + dbus_message_unref(reply); + + dbus_pending_call_unref(call); +} + +static int _netconfig_wifi_wps_get_bsss(void) +{ + gboolean reply = FALSE; + const char *if_path = NULL; + char *param0 = NULL; + char param1[] = "string:BSSs"; + char *param_array[] = { NULL, NULL, NULL }; + + if_path = netconfig_wifi_get_supplicant_interface(); + if (if_path == NULL) { + DBG("Fail to get wpa_supplicant DBus path"); + return -ESRCH; + } + + param0 = g_strdup_printf("string:%s", SUPPLICANT_IFACE_INTERFACE); + param_array[0] = param0; + param_array[1] = param1; + + reply = netconfig_invoke_dbus_method_nonblock(SUPPLICANT_SERVICE, + if_path, DBUS_INTERFACE_PROPERTIES, + "Get", param_array, __netconfig_wifi_wps_get_bsss_result); + if (reply != TRUE) { + ERR("Fail to invoke_dbus_method_nonblock Get"); + + if (param0) + g_free(param0); + return -ESRCH; + } + + if (param0) + g_free(param0); + return 0; +} + +void netconfig_wifi_wps_signal_scandone(void) +{ + wps_bss_list_count = 0; + _netconfig_wifi_wps_get_bsss(); + + netconfig_is_device_scanning = FALSE; + + __netconfig_wps_set_mode(FALSE); +} + +void netconfig_wifi_wps_signal_scanaborted(void) +{ + wps_bss_list_count = 0; + netconfig_is_wps_scan_aborted = TRUE; + _netconfig_wifi_wps_get_bsss(); + + netconfig_is_device_scanning = FALSE; + + __netconfig_wps_set_mode(FALSE); +} + +static int __netconfig_wifi_wps_request_scan(const char *if_path) +{ + dbus_bool_t result = FALSE; + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusPendingCall *call; + DBusMessageIter iter, dict, entry; + DBusMessageIter value; + const char *key1 = "Type"; + const char *val1 = "passive"; + + if (if_path == NULL) + if_path = netconfig_wifi_get_supplicant_interface(); + + if (if_path == NULL) { + DBG("Fail to get wpa_supplicant DBus path"); + return -ESRCH; + } + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + return -EIO; + } + + message = dbus_message_new_method_call(SUPPLICANT_SERVICE, + if_path, SUPPLICANT_INTERFACE ".Interface", "Scan"); + if (message == NULL) { + ERR("Failed DBus method call"); + dbus_connection_unref(connection); + return -EIO; + } + + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + + dbus_message_iter_open_container(&dict, + DBUS_TYPE_DICT_ENTRY, NULL, &entry); + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key1); + + dbus_message_iter_open_container(&entry, + DBUS_TYPE_VARIANT, DBUS_TYPE_STRING_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &val1); + + dbus_message_iter_close_container(&entry, &value); + dbus_message_iter_close_container(&dict, &entry); + dbus_message_iter_close_container(&iter, &dict); + + result = dbus_connection_send_with_reply(connection, message, &call, + NETCONFIG_WPS_DBUS_REPLY_TIMEOUT); + if (result == FALSE || call == NULL) { + ERR("dbus_connection_send_with_reply() failed"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return -ESRCH; + } + + dbus_pending_call_cancel(call); + dbus_message_unref(message); + dbus_connection_unref(connection); + + /* Clear bss_info_list for the next scan result */ + if (wps_bss_info_list) { + g_slist_free_full(wps_bss_info_list, g_free); + wps_bss_info_list = NULL; + } + + netconfig_is_wps_scan_aborted = FALSE; + + return 0; +} + +static void __netconfig_wifi_interface_create_result( + DBusPendingCall *call, void *data) +{ + DBusMessage *message; + DBusMessageIter iter; + const char *path = NULL; + + message = dbus_pending_call_steal_reply(call); + if (dbus_message_get_type(message) != DBUS_MESSAGE_TYPE_ERROR) { + dbus_message_iter_init(message, &iter); + dbus_message_iter_get_basic(&iter, &path); + + if (path) + __netconfig_wifi_wps_request_scan(path); + } else { + DBG("Failed to create interface"); + } + + dbus_message_unref(message); + dbus_pending_call_unref(call); +} + +static int __netconfig_wifi_wps_create_interface(void) +{ + dbus_bool_t result = FALSE; + DBusConnection *connection = NULL; + DBusMessage *message = NULL; + DBusPendingCall *call; + DBusMessageIter iter, dict, entry, value; + const char *key = "Ifname"; + const char *val = WIFI_IFNAME; + + connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL); + if (connection == NULL) { + ERR("Failed to get system bus"); + return -EIO; + } + + message = dbus_message_new_method_call(SUPPLICANT_SERVICE, + SUPPLICANT_PATH, SUPPLICANT_INTERFACE, "CreateInterface"); + if (message == NULL) { + ERR("Failed DBus method call"); + dbus_connection_unref(connection); + return -EIO; + } + + dbus_message_iter_init_append(message, &iter); + dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY, + DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING + DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING + DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict); + dbus_message_iter_open_container(&dict, DBUS_TYPE_DICT_ENTRY, + NULL, &entry); + + dbus_message_iter_append_basic(&entry, DBUS_TYPE_STRING, &key); + dbus_message_iter_open_container(&entry, DBUS_TYPE_VARIANT, + DBUS_TYPE_STRING_AS_STRING, &value); + dbus_message_iter_append_basic(&value, DBUS_TYPE_STRING, &val); + dbus_message_iter_close_container(&entry, &value); + dbus_message_iter_close_container(&dict, &entry); + dbus_message_iter_close_container(&iter, &dict); + + result = dbus_connection_send_with_reply(connection, message, &call, + NETCONFIG_WPS_DBUS_REPLY_TIMEOUT); + if (result == FALSE || call == NULL) { + ERR("dbus_connection_send_with_reply() failed"); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return -ESRCH; + } + + dbus_pending_call_set_notify(call, + __netconfig_wifi_interface_create_result, NULL, NULL); + + dbus_message_unref(message); + dbus_connection_unref(connection); + + return 0; +} + +static int __netconfig_wifi_wps_scan(void) +{ + int err = 0; + enum netconfig_wifi_tech_state wifi_tech_state; + + if (netconfig_is_device_scanning == TRUE) + return -EINPROGRESS; + + wifi_tech_state = netconfig_wifi_state_get_technology_state(); + if (wifi_tech_state <= NETCONFIG_WIFI_TECH_OFF) + err = netconfig_wifi_driver_and_supplicant(TRUE); + + if (err < 0 && err != -EALREADY) + return err; + + netconfig_is_device_scanning = TRUE; + + if (wifi_tech_state >= NETCONFIG_WIFI_TECH_POWERED) { + if (netconfig_wifi_get_scanning() == TRUE) + return -EINPROGRESS; + + netconfig_wifi_bgscan_start(); + + if (wifi_tech_state == NETCONFIG_WIFI_TECH_CONNECTED) + __netconfig_wifi_wps_request_scan(NULL); + } else { + err = __netconfig_wifi_wps_create_interface(); + } + + return err; +} + +gboolean netconfig_iface_wifi_request_wps_scan(NetconfigWifi *wifi, + GError **error) +{ + int err, enabled = 0; + enum netconfig_wifi_tech_state wifi_tech_state; + + g_return_val_if_fail(wifi != NULL, FALSE); + + wifi_tech_state = netconfig_wifi_state_get_technology_state(); + if (wifi_tech_state <= NETCONFIG_WIFI_TECH_OFF) { + vconf_get_int(VCONF_WIFI_ALWAYS_ALLOW_SCANNING, &enabled); + + if (enabled == 0) { + netconfig_error_permission_denied(error); + return FALSE; + } + } + + __netconfig_wps_set_mode(TRUE); + + err = __netconfig_wifi_wps_scan(); + if (err < 0) { + if (err == -EINPROGRESS) + netconfig_error_inprogress(error); + else + netconfig_error_wifi_driver_failed(error); + + return FALSE; + } + + return TRUE; +} diff --git a/wearable/src/wifi.c b/wearable/src/wifi.c new file mode 100644 index 0000000..681c812 --- /dev/null +++ b/wearable/src/wifi.c @@ -0,0 +1,139 @@ +/* + * Network Configuration Module + * + * Copyright (c) 2000 - 2012 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 "log.h" +#include "wifi.h" +#include "util.h" +#include "netdbus.h" +#include "neterror.h" +#include "wifi-eap.h" +#include "wifi-wps.h" +#include "wifi-power.h" +#include "wifi-agent.h" +#include "wifi-firmware.h" +#include "wifi-ssid-scan.h" +#include "wifi-passpoint.h" +#include "wifi-eap-config.h" +#include "wifi-background-scan.h" + +#include "netconfig-iface-wifi-glue.h" + +#define PROP_DEFAULT FALSE +#define PROP_DEFAULT_STR NULL + +enum { + PROP_O, + PROP_WIFI_CONN, + PROP_WIFI_PATH, +}; + +struct NetconfigWifiClass { + GObjectClass parent; +}; + +struct NetconfigWifi { + GObject parent; + + DBusGConnection *connection; + gchar *path; +}; + +G_DEFINE_TYPE(NetconfigWifi, netconfig_wifi, G_TYPE_OBJECT); + +static void __netconfig_wifi_gobject_get_property(GObject *object, guint prop_id, + GValue *value, GParamSpec *pspec) +{ + return; +} + +static void __netconfig_wifi_gobject_set_property(GObject *object, guint prop_id, + const GValue *value, GParamSpec *pspec) +{ + NetconfigWifi *wifi = NETCONFIG_WIFI(object); + + switch (prop_id) { + case PROP_WIFI_CONN: + { + wifi->connection = g_value_get_boxed(value); + break; + } + + case PROP_WIFI_PATH: + { + if (wifi->path) + g_free(wifi->path); + + wifi->path = g_value_dup_string(value); + break; + } + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + +static void netconfig_wifi_init(NetconfigWifi *wifi) +{ + wifi->connection = NULL; + wifi->path = g_strdup(PROP_DEFAULT_STR); +} + +static void netconfig_wifi_class_init(NetconfigWifiClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->get_property = __netconfig_wifi_gobject_get_property; + object_class->set_property = __netconfig_wifi_gobject_set_property; + + /* DBus register */ + dbus_g_object_type_install_info(NETCONFIG_TYPE_WIFI, + &dbus_glib_netconfig_iface_wifi_object_info); + + /* property */ + g_object_class_install_property(object_class, PROP_WIFI_CONN, + g_param_spec_boxed("connection", "CONNECTION", "DBus connection", + DBUS_TYPE_G_CONNECTION, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); + + g_object_class_install_property(object_class, PROP_WIFI_PATH, + g_param_spec_string("path", "Path", "Object path", + PROP_DEFAULT_STR, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); +} + +gpointer netconfig_wifi_create_and_init(DBusGConnection *connection) +{ + GObject *object; + + g_return_val_if_fail(connection != NULL, NULL); + + object = g_object_new(NETCONFIG_TYPE_WIFI, "connection", connection, "path", + NETCONFIG_WIFI_PATH, NULL); + + dbus_g_connection_register_g_object(connection, NETCONFIG_WIFI_PATH, object); + + netconfig_wifi_power_initialize(); + + return object; +} -- 2.7.4