From e78d57101abac90389498d699747cd1483550184 Mon Sep 17 00:00:00 2001 From: Seonah Moon Date: Fri, 16 Oct 2015 11:21:21 +0900 Subject: [PATCH] Base Code merged to SPIN 2.4 Change-Id: I54c8b6f8f85ca38b4e218a495c885b522a21ebc0 Signed-off-by: Seonah Moon --- CMakeLists.txt | 21 +- capi-network-tethering.manifest | 5 + capi-network-tethering.pc.in | 2 +- debian/capi-network-tethering-dev.install | 4 - debian/capi-network-tethering.install | 1 - debian/capi-network-tethering.postinst | 1 - debian/changelog | 25 - debian/compat | 1 - debian/control | 21 - debian/rules | 64 - include/tethering.h | 94 -- include/tethering.xml | 107 +- include/tethering_private.h | 128 +- packaging/capi-network-tethering.changes | 56 - packaging/capi-network-tethering.manifest | 5 - packaging/capi-network-tethering.spec | 72 +- src/tethering.c | 2542 +++++++++++++++++++++-------- src/tethering_client.c | 33 +- src/tethering_private.c | 46 + test/tethering_test.c | 221 ++- 20 files changed, 2367 insertions(+), 1082 deletions(-) mode change 100644 => 100755 CMakeLists.txt create mode 100644 capi-network-tethering.manifest delete mode 100644 debian/capi-network-tethering-dev.install delete mode 100644 debian/capi-network-tethering.install delete mode 100644 debian/capi-network-tethering.postinst delete mode 100644 debian/changelog delete mode 100644 debian/compat delete mode 100644 debian/control delete mode 100755 debian/rules delete mode 100644 packaging/capi-network-tethering.changes delete mode 100644 packaging/capi-network-tethering.manifest mode change 100644 => 100755 src/tethering.c create mode 100644 src/tethering_private.c diff --git a/CMakeLists.txt b/CMakeLists.txt old mode 100644 new mode 100755 index 153cb1a..457d8d2 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,12 +9,24 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog glib-2.0 capi-base-common dbus-glib-1 vconf") +SET(dependents "dlog gio-2.0 gio-unix-2.0 glib-2.0 capi-base-common dbus-1 vconf key-manager libssl capi-system-info") IF("${CMAKE_BUILD_TYPE}" STREQUAL "") SET(CMAKE_BUILD_TYPE "Release") ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "") +IF("${CMAKE_BUILD_TYPE}" STREQUAL "Private") + SET(CMAKE_BUILD_TYPE "Release") +ENDIF("${CMAKE_BUILD_TYPE}" STREQUAL "Private") + +IF(TIZEN_WEARABLE) + ADD_DEFINITIONS(-DTIZEN_WEARABLE) +ENDIF(TIZEN_WEARABLE) + +IF(TIZEN_MOBILE) + ADD_DEFINITIONS(-DTIZEN_MOBILE) +ENDIF(TIZEN_MOBILE) + INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) FOREACH(flag ${${fw_name}_CFLAGS}) @@ -33,13 +45,6 @@ ADD_DEFINITIONS("-DTIZEN_DEBUG") SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--as-needed -Wl,--rpath=%{_libdir}") -FIND_PROGRAM(MARSHALTOOL NAMES glib-genmarshal) -EXEC_PROGRAM("${MARSHALTOOL}" ARGS "--prefix=marshal ${INC_DIR}/marshal.list --header > ${INC_DIR}/marshal.h") -EXEC_PROGRAM("${MARSHALTOOL}" ARGS "--prefix=marshal ${INC_DIR}/marshal.list --body > src/marshal.c") - -FIND_PROGRAM(DBUS_BINDING_TOOL NAMES dbus-binding-tool) -EXEC_PROGRAM("${DBUS_BINDING_TOOL}" ARGS "--prefix=tethering ${INC_DIR}/tethering.xml --mode=glib-client --output=${INC_DIR}/tethering-client-stub.h") - aux_source_directory(src SOURCES) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) diff --git a/capi-network-tethering.manifest b/capi-network-tethering.manifest new file mode 100644 index 0000000..75b0fa5 --- /dev/null +++ b/capi-network-tethering.manifest @@ -0,0 +1,5 @@ + + + + + diff --git a/capi-network-tethering.pc.in b/capi-network-tethering.pc.in index ea3b753..fc8c18b 100644 --- a/capi-network-tethering.pc.in +++ b/capi-network-tethering.pc.in @@ -2,7 +2,7 @@ prefix=@PREFIX@ exec_prefix=/usr -libdir=@LIB_INSTALL_DIR@ +libdir=/usr/lib includedir=/usr/include/network Name: @PC_NAME@ diff --git a/debian/capi-network-tethering-dev.install b/debian/capi-network-tethering-dev.install deleted file mode 100644 index 761a28b..0000000 --- a/debian/capi-network-tethering-dev.install +++ /dev/null @@ -1,4 +0,0 @@ -/usr/include/* -/usr/include/*/* -/usr/lib/pkgconfig/*.pc - diff --git a/debian/capi-network-tethering.install b/debian/capi-network-tethering.install deleted file mode 100644 index 4a755a4..0000000 --- a/debian/capi-network-tethering.install +++ /dev/null @@ -1 +0,0 @@ -/usr/lib/lib*.so* diff --git a/debian/capi-network-tethering.postinst b/debian/capi-network-tethering.postinst deleted file mode 100644 index 1a24852..0000000 --- a/debian/capi-network-tethering.postinst +++ /dev/null @@ -1 +0,0 @@ -#!/bin/sh diff --git a/debian/changelog b/debian/changelog deleted file mode 100644 index 764f434..0000000 --- a/debian/changelog +++ /dev/null @@ -1,25 +0,0 @@ -capi-network-tethering (0.0.3-1) unstable; urgency=low - - * Deprecated API from Glib2-2.32.3 is replaced with new one - * Git: slp/api/tethering - * Tag: capi-network-tethering_0.0.3-1 - - -- Seungyoun Ju Fri, 15 Jun 2012 14:30:39 +0900 - -capi-network-tethering (0.0.1-2) unstable; urgency=low - - * Getting USB Interface API is implemented - Use of handle for getting client information is implemented - Some API's prototypes are changed - * Git: slp/api/tethering - * Tag: capi-network-tethering_0.0.1-2 - - -- Seungyoun Ju Thu, 31 May 2012 13:54:34 +0900 - -capi-network-tethering (0.0.1-1) unstable; urgency=low - - * Initial upload - * Git: slp/api/tethering - * Tag: capi-network-tethering_0.0.1-1 - - -- Seungyoun Ju Thu, 29 Mar 2012 10:33:07 +0900 diff --git a/debian/compat b/debian/compat deleted file mode 100644 index 7ed6ff8..0000000 --- a/debian/compat +++ /dev/null @@ -1 +0,0 @@ -5 diff --git a/debian/control b/debian/control deleted file mode 100644 index ce02659..0000000 --- a/debian/control +++ /dev/null @@ -1,21 +0,0 @@ -Source: capi-network-tethering -Section: libs -Priority: extra -Maintainer: Kangho Hur , ByungWoo Lee , Seungyoun Ju , Hocheol Seo -Build-Depends: debhelper (>= 5), dlog-dev, capi-base-common-dev, libglib2.0-dev, libmobile-ap-dev - -Package: capi-network-tethering -Architecture: any -Depends: ${misc:Depends} -Description: The library package for tethering - -Package: capi-network-tethering-dev -Architecture: any -Depends: ${misc:Depends}, capi-network-tethering (= ${Source-Version}), dlog-dev, capi-base-common-dev, libglib2.0-dev, libmobile-ap-dev -Description: The development package for tethering library - -Package: capi-network-tethering-dbg -Architecture: any -Depends: ${misc:Depends}, capi-network-tethering (= ${Source-Version}) -Description: The debug package for tethering library - diff --git a/debian/rules b/debian/rules deleted file mode 100755 index beda1a7..0000000 --- a/debian/rules +++ /dev/null @@ -1,64 +0,0 @@ -#!/usr/bin/make -f - -CFLAGS = -Wall -g - -ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS))) - CFLAGS += -O0 -else - CFLAGS += -O2 -endif -CMAKE_ROOT_DIR ?= $(CURDIR) -CMAKE_BUILD_DIR ?= $(CURDIR)/cmake_build_tmp - -configure: configure-stamp -configure-stamp: - dh_testdir - mkdir -p $(CMAKE_BUILD_DIR) && cd $(CMAKE_BUILD_DIR) && cmake .. - touch configure-stamp - -build: build-stamp -build-stamp: configure-stamp - dh_testdir - cd $(CMAKE_BUILD_DIR) && $(MAKE) - touch $@ - -clean: - cd $(CMAKE_ROOT_DIR) - dh_testdir - dh_testroot - rm -f build-stamp configure-stamp - rm -f `find . -name *.pc` - rm -rf $(CMAKE_BUILD_DIR) - dh_clean - -install: build - dh_testdir - dh_testroot - dh_clean -k - dh_installdirs - - cd $(CMAKE_BUILD_DIR) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install - -binary-indep: build install - -binary-arch: build install - dh_testdir - dh_testroot - dh_installchangelogs - dh_installdocs - dh_installexamples - dh_install --sourcedir=debian/tmp - dh_installman - dh_link - dh_strip --dbg-package=capi-network-tethering-dbg - dh_fixperms - dh_makeshlibs - dh_installdeb - dh_shlibdeps - dh_gencontrol - dh_md5sums - dh_builddeb - -binary: binary-indep binary-arch -.PHONY: build clean binary-indep binary-arch binary install configure - diff --git a/include/tethering.h b/include/tethering.h index 2bd8fe3..738f447 100644 --- a/include/tethering.h +++ b/include/tethering.h @@ -29,20 +29,17 @@ extern "C" { */ /** - * @internal * @addtogroup CAPI_NETWORK_TETHERING_MANAGER_MODULE * @{ */ /** - * @internal * @brief The tethering handle. * @since_tizen 2.3 */ typedef void * tethering_h; /** - * @internal * @brief Enumeration for the tethering. * @since_tizen 2.3 */ @@ -60,7 +57,6 @@ typedef enum { } tethering_error_e; /** - * @internal * @brief Enumeration for the type of tethering. * @since_tizen 2.3 */ @@ -73,7 +69,6 @@ typedef enum { } tethering_type_e; /** - * @internal * @brief Enumeration for the cause of disabling the tethering. * @since_tizen 2.3 */ @@ -88,7 +83,6 @@ typedef enum TETHERING_DISABLED_BY_REQUEST, /**< Disabled by your request */ TETHERING_DISABLED_BY_WIFI_ON, /**< Disabled due to Wi-Fi on */ TETHERING_DISABLED_BY_BT_OFF, /**< Disabled due to Bluetooth off */ - TETHERING_DISABLED_BY_POWER_SAVE_MODE, /**< Disabled due to power save mode */ } tethering_disabled_cause_e; /** @@ -97,13 +91,11 @@ typedef enum /** - * @internal * @addtogroup CAPI_NETWORK_TETHERING_WIFI_MODULE * @{ */ /** - * @internal * @brief Enumeration for the Wi-Fi security. * @since_tizen 2.3 */ @@ -118,20 +110,17 @@ typedef enum { /** - * @internal * @addtogroup CAPI_NETWORK_TETHERING_CLIENT_MODULE * @{ */ /** - * @internal * @brief The tethering client handle. * @since_tizen 2.3 */ typedef void * tethering_client_h; /** - * @internal * @brief Enumeration for address family. * @since_tizen 2.3 */ @@ -145,13 +134,11 @@ typedef enum { /** - * @internal * @addtogroup CAPI_NETWORK_TETHERING_MANAGER_MODULE * @{ */ /** - * @internal * @brief Called when the tethering is enabled. * @since_tizen 2.3 * @param[in] result The result of enabling the tethering @@ -165,7 +152,6 @@ typedef enum { typedef void (*tethering_enabled_cb)(tethering_error_e result, tethering_type_e type, bool is_requested, void *user_data); /** - * @internal * @brief Called when the tethering is disabled. * @since_tizen 2.3 * @param[in] result The result of disabling the tethering @@ -179,7 +165,6 @@ typedef void (*tethering_enabled_cb)(tethering_error_e result, tethering_type_e typedef void (*tethering_disabled_cb)(tethering_error_e result, tethering_type_e type, tethering_disabled_cause_e cause, void *user_data); /** - * @internal * @brief Called when the connection state is changed. * @since_tizen 2.3 * @remarks @a client is valid only in this function. In order to use it outside this function, a user must copy the client with tethering_client_clone(). @@ -193,7 +178,6 @@ typedef void (*tethering_disabled_cb)(tethering_error_e result, tethering_type_e typedef void (*tethering_connection_state_changed_cb)(tethering_client_h client, bool opened, void *user_data); /** - * @internal * @brief Called when you get the connected client repeatedly. * @since_tizen 2.3 * @remarks @a client is valid only in this function. In order to use the client outside this function, a user must copy the client with tethering_client_clone(). @@ -206,7 +190,6 @@ typedef void (*tethering_connection_state_changed_cb)(tethering_client_h client, typedef bool(*tethering_connected_client_cb)(tethering_client_h client, void *user_data); /** - * @internal * @brief Called when you get the data usage. * @since_tizen 2.3 * @param[in] result The result of getting the data usage @@ -218,7 +201,6 @@ typedef bool(*tethering_connected_client_cb)(tethering_client_h client, void *us typedef void (*tethering_data_usage_cb)(tethering_error_e result, unsigned long long received_data, unsigned long long sent_data, void *user_data); /** - * @internal * @brief Called when the security type of Wi-Fi tethering is changed. * @since_tizen 2.3 * @param[in] changed_type The changed security type of Wi-Fi tethering @@ -229,7 +211,6 @@ typedef void (*tethering_data_usage_cb)(tethering_error_e result, unsigned long typedef void (*tethering_wifi_security_type_changed_cb)(tethering_wifi_security_type_e changed_type, void *user_data); /** - * @internal * @brief Called when the visibility of SSID is changed. * @since_tizen 2.3 * @param[in] changed_visible The changed visibility of SSID @@ -240,7 +221,6 @@ typedef void (*tethering_wifi_security_type_changed_cb)(tethering_wifi_security_ typedef void (*tethering_wifi_ssid_visibility_changed_cb)(bool changed_visible, void *user_data); /** - * @internal * @brief Called when the passphrase of Wi-Fi tethering is changed. * @since_tizen 2.3 * @param[in] user_data The user data passed from the register function @@ -250,7 +230,6 @@ typedef void (*tethering_wifi_ssid_visibility_changed_cb)(bool changed_visible, typedef void (*tethering_wifi_passphrase_changed_cb)(void *user_data); /** - * @internal * @brief Called when the settings are reloaded. * @since_tizen 2.3 * @param[in] result The result of reloading the settings @@ -260,7 +239,6 @@ typedef void (*tethering_wifi_passphrase_changed_cb)(void *user_data); typedef void (*tethering_wifi_settings_reloaded_cb)(tethering_error_e result, void *user_data); /** - * @internal * @brief Called when Wi-Fi AP settings are reloaded. * @since_tizen 2.3 * @param[in] result The result of reloading the settings @@ -270,7 +248,6 @@ typedef void (*tethering_wifi_settings_reloaded_cb)(tethering_error_e result, vo typedef void (*tethering_wifi_ap_settings_reloaded_cb)(tethering_error_e result, void *user_data); /** - * @internal * @brief Creates the handle for tethering. * @since_tizen 2.3 * @privlevel platform @@ -287,7 +264,6 @@ typedef void (*tethering_wifi_ap_settings_reloaded_cb)(tethering_error_e result, int tethering_create(tethering_h *tethering); /** - * @internal * @brief Destroys the handle for tethering. * @since_tizen 2.3 * @privlevel platform @@ -301,7 +277,6 @@ int tethering_create(tethering_h *tethering); int tethering_destroy(tethering_h tethering); /** - * @internal * @brief Enables the tethering, asynchronously. * @since_tizen 2.3 * @privlevel platform @@ -318,7 +293,6 @@ int tethering_destroy(tethering_h tethering); int tethering_enable(tethering_h tethering, tethering_type_e type); /** - * @internal * @brief Disables the tethering, asynchronously. * @since_tizen 2.3 * @privlevel platform @@ -335,7 +309,6 @@ int tethering_enable(tethering_h tethering, tethering_type_e type); int tethering_disable(tethering_h tethering, tethering_type_e type); /** - * @internal * @brief Checks whether the tethering is enabled or not. * @since_tizen 2.3 * @privlevel platform @@ -347,7 +320,6 @@ int tethering_disable(tethering_h tethering, tethering_type_e type); bool tethering_is_enabled(tethering_h tethering, tethering_type_e type); /** - * @internal * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1". * @since_tizen 2.3 * @privlevel platform @@ -369,7 +341,6 @@ bool tethering_is_enabled(tethering_h tethering, tethering_type_e type); int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address); /** - * @internal * @brief Gets the name of network interface (e.g. usb0). * @since_tizen 2.3 * @privlevel platform @@ -391,7 +362,6 @@ int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name); /** - * @internal * @brief Gets the local IP address. * @since_tizen 2.3 * @privlevel platform @@ -414,7 +384,6 @@ int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address); /** - * @internal * @brief Gets the Gateway address. * @since_tizen 2.3 * @privlevel platform @@ -437,7 +406,6 @@ int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethe int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address); /** - * @internal * @brief Gets the Subnet Mask. * @since_tizen 2.3 * @privlevel platform @@ -460,7 +428,6 @@ int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask); /** - * @internal * @brief Gets the data usage. * @since_tizen 2.3 * @privlevel platform @@ -479,7 +446,6 @@ int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, teth int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data); /** - * @internal * @brief Gets the clients which are connected. * @since_tizen 2.3 * @privlevel platform @@ -499,28 +465,6 @@ int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb call int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data); /** - * @brief Set the ip forward status - * @param[in] tethering The handle of tethering - * @param[in] status The ip forward status: (@c true = enable, @c false = disable) - * @retval #TETHERING_ERROR_NONE Successful - * @reztval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter - * @see tethering_get_ip_forward_status() - */ -int tethering_set_ip_forward_status(tethering_h tethering, bool status); - -/** - * @brief Get the ip forward status - * @param[in] tethering The handle of tethering - * @param[out] status The ip forward status: (@c true = enable, @c false = disable) - * @retval #TETHERING_ERROR_NONE Successful - * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed - * @see tethering_set_ip_forward_status() - */ -int tethering_get_ip_forward_status(tethering_h tethering, bool *status); - -/** - * @internal * @brief Registers the callback function, which is called when tethering is enabled. * @since_tizen 2.3 * @privlevel platform @@ -536,7 +480,6 @@ int tethering_get_ip_forward_status(tethering_h tethering, bool *status); int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data); /** - * @internal * @brief Unregisters the callback function, which is called when tethering is enabled. * @since_tizen 2.3 * @privlevel platform @@ -550,7 +493,6 @@ int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethe int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type); /** - * @internal * @brief Registers the callback function called when tethering is disabled. * @since_tizen 2.3 * @privlevel platform @@ -566,7 +508,6 @@ int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type); int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data); /** - * @internal * @brief Unregisters the callback function, which is called when tethering is disabled. * @since_tizen 2.3 * @privlevel platform @@ -580,7 +521,6 @@ int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, teth int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type); /** - * @internal * @brief Registers the callback function, which is called when the state of connection is changed. * @since_tizen 2.3 * @privlevel platform @@ -596,7 +536,6 @@ int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type); int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data); /** - * @internal * @brief Unregisters the callback function, which is called when the state of connection is changed. * @since_tizen 2.3 * @privlevel platform @@ -610,7 +549,6 @@ int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_t int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type); /** - * @internal * @brief Registers the callback function, which is called when the security type of Wi-Fi tethering is changed. * @since_tizen 2.3 * @privlevel platform @@ -625,7 +563,6 @@ int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data); /** - * @internal * @brief Unregisters the callback function, which is called when the security type of Wi-Fi tethering is changed. * @since_tizen 2.3 * @privlevel platform @@ -639,7 +576,6 @@ int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering); /** - * @internal * @brief Registers the callback function , which iscalled when the visibility of SSID is changed. * @since_tizen 2.3 * @privlevel platform @@ -654,7 +590,6 @@ int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering); int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data); /** - * @internal * @brief Unregisters the callback function, which is called when the visibility of SSID is changed. * @since_tizen 2.3 * @privlevel platform @@ -667,7 +602,6 @@ int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tetheri int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering); /** - * @internal * @brief Registers the callback function, which is called when the passphrase of Wi-Fi tethering is changed. * @since_tizen 2.3 * @privlevel platform @@ -682,7 +616,6 @@ int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering); int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data); /** - * @internal * @brief Unregisters the callback function, which is called when the passphrase of Wi-Fi tethering is changed. * @since_tizen 2.3 * @privlevel platform @@ -700,13 +633,11 @@ int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering); /** - * @internal * @addtogroup CAPI_NETWORK_TETHERING_WIFI_MODULE * @{ */ /** - * @internal * @brief Sets the security type of Wi-Fi tethering. * @since_tizen 2.3 * @privlevel platform @@ -723,7 +654,6 @@ int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering); int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type); /** - * @internal * @brief Gets the security type of Wi-Fi tethering. * @since_tizen 2.3 * @privlevel platform @@ -739,7 +669,6 @@ int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_secur int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type); /** - * @internal * @brief Sets the SSID (service set identifier). * @details The SSID cannot exceed 32 bytes. If SSID is not set, device name is used as SSID. * @since_tizen 2.3 @@ -756,7 +685,6 @@ int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_secur int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid); /** - * @internal * @brief Gets the SSID (service set identifier). * @since_tizen 2.3 * @privlevel platform @@ -773,7 +701,6 @@ int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid); int tethering_wifi_get_ssid(tethering_h tethering, char **ssid); /** - * @internal * @brief Sets the visibility of SSID (service set identifier). * @details If the visibility is set to invisible, then the SSID of this device is hidden and Wi-Fi scan will not find the device. * @since_tizen 2.3 @@ -791,7 +718,6 @@ int tethering_wifi_get_ssid(tethering_h tethering, char **ssid); int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible); /** - * @internal * @brief Gets the visibility of SSID (service set identifier). * @details If the visibility is set to invisible, then the SSID of this device is hidden and Wi-Fi scan will not find the device. * @since_tizen 2.3 @@ -808,7 +734,6 @@ int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible); int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible); /** - * @internal * @brief Sets the passphrase. * @since_tizen 2.3 * @privlevel platform @@ -825,7 +750,6 @@ int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible); int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase); /** - * @internal * @brief Gets the passphrase. * @since_tizen 2.3 * @privlevel platform @@ -843,7 +767,6 @@ int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase) int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase); /** - * @internal * @brief Reloads the settings (SSID / Passphrase / Security type / SSID visibility). * @since_tizen 2.3 * @privlevel platform @@ -860,7 +783,6 @@ int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase); int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data); /** - * @internal * @brief Sets the security type of Wi-Fi AP. * @details If security type is not set, WPA2_PSK is used. * @since_tizen 2.3 @@ -877,7 +799,6 @@ int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_setting int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type); /** - * @internal * @brief Gets the security type of Wi-Fi AP. * @details If security type is not set, WPA2_PSK is used. * @since_tizen 2.3 @@ -893,7 +814,6 @@ int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_se int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type); /** - * @internal * @brief Sets the SSID (service set identifier) for Wi-Fi AP. * @details The SSID cannot exceed 32 bytes. If SSID is not set, device name is used as SSID. * @since_tizen 2.3 @@ -909,7 +829,6 @@ int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_se int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid); /** - * @internal * @brief Gets the SSID (service set identifier) for Wi-Fi AP. * @details If SSID is not set, Device name is used as SSID. * @since_tizen 2.3 @@ -926,7 +845,6 @@ int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid); int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid); /** - * @internal * @brief Sets the visibility of SSID (service set identifier) for Wi-Fi AP. * @details If you set the visibility to invisible, then the SSID of this device is hidden and Wi-Fi scan won't find your device. * @details By default visibility is set to @c true. @@ -945,7 +863,6 @@ int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid); int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible); /** - * @internal * @brief Gets the visibility of SSID (service set identifier) for Wi-Fi AP. * @details If the visibility is set to invisible, then the SSID of this device is hidden and Wi-Fi scan won't find your device. * @details By default visibility is set to @c true. @@ -962,7 +879,6 @@ int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible); int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible); /** - * @internal * @brief Sets the passphrase for Wi-Fi AP. * @details If the passphrase is not set, random string of 8 characters will be used. * @since_tizen 2.3 @@ -978,7 +894,6 @@ int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible); int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase); /** - * @internal * @brief Gets the passphrase for Wi-Fi AP. * @details If the passphrase is not set, random string of 8 characters will be used. * @since_tizen 2.3 @@ -996,7 +911,6 @@ int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphra int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase); /** - * @internal * @brief Reloads the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP. * @since_tizen 2.3 * @privlevel platform @@ -1018,13 +932,11 @@ int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_s /** - * @internal * @addtogroup CAPI_NETWORK_TETHERING_CLIENT_MODULE * @{ */ /** - * @internal * @brief Clones the handle of a client. * @since_tizen 2.3 * @privlevel platform @@ -1041,7 +953,6 @@ int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_s int tethering_client_clone(tethering_client_h *dest, tethering_client_h origin); /** - * @internal * @brief Destroys the handle of a client. * @since_tizen 2.3 * @privlevel platform @@ -1055,7 +966,6 @@ int tethering_client_clone(tethering_client_h *dest, tethering_client_h origin); int tethering_client_destroy(tethering_client_h client); /** - * @internal * @brief Gets the tethering type of client. * @since_tizen 2.3 * @privlevel platform @@ -1071,7 +981,6 @@ int tethering_client_destroy(tethering_client_h client); int tethering_client_get_tethering_type(tethering_client_h client, tethering_type_e *type); /** - * @internal * @brief Gets the name of a client. * @since_tizen 2.3 * @privlevel platform @@ -1089,7 +998,6 @@ int tethering_client_get_tethering_type(tethering_client_h client, tethering_typ int tethering_client_get_name(tethering_client_h client, char **name); /** - * @internal * @brief Gets the IP address of a client. * @since_tizen 2.3 * @privlevel platform @@ -1108,7 +1016,6 @@ int tethering_client_get_name(tethering_client_h client, char **name); int tethering_client_get_ip_address(tethering_client_h client, tethering_address_family_e address_family, char **ip_address); /** - * @internal * @brief Gets the MAC address of a client such as "FC:A1:3E:D6:B1:B1". * @since_tizen 2.3 * @privlevel platform @@ -1126,7 +1033,6 @@ int tethering_client_get_ip_address(tethering_client_h client, tethering_address int tethering_client_get_mac_address(tethering_client_h client, char **mac_address); /** - * @internal * @brief Gets the connection time of a client. * @since_tizen 2.3 * @privlevel platform diff --git a/include/tethering.xml b/include/tethering.xml index 4aee14e..4636834 100644 --- a/include/tethering.xml +++ b/include/tethering.xml @@ -9,12 +9,6 @@ - - - - - - @@ -26,6 +20,7 @@ + @@ -60,74 +55,51 @@ - + + + + + - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + + + + + - + - + + + + + - + - - + + - + - - + + + @@ -167,38 +139,25 @@ - + - + - - - - - - - - - - - - - + - + - + - diff --git a/include/tethering_private.h b/include/tethering_private.h index d614da1..29c9e4d 100644 --- a/include/tethering_private.h +++ b/include/tethering_private.h @@ -20,9 +20,8 @@ #define LOG_TAG "CAPI_NETWORK_TETHERING" #include -#include #include - +#include #include "tethering.h" #ifdef __cplusplus @@ -34,12 +33,14 @@ extern "C" { #endif #ifndef DEPRECATED_API -# define DEPRECATED_API __attribute__ ((deprecated)) +#define DEPRECATED_API __attribute__ ((deprecated)) #endif -#define DBG(fmt, args...) LOGD(fmt, ##args) -#define WARN(fmt, args...) LOGW(fmt, ##args) -#define ERR(fmt, args...) LOGE(fmt, ##args) +#define DBG(fmt, args...) LOGD(fmt, ##args) +#define WARN(fmt, args...) LOGW(fmt, ##args) +#define ERR(fmt, args...) LOGE(fmt, ##args) +#define SDBG(fmt, args...) SECURE_LOGD(fmt, ##args) +#define SERR(fmt, args...) SECURE_LOGE(fmt, ##args) #define _warn_if(expr, fmt, arg...) do { \ if (expr) { \ @@ -74,6 +75,27 @@ extern "C" { } while (0) /** + * To check supported feature + */ + +#define TETHERING_FEATURE "http://tizen.org/feature/network.tethering" +#define TETHERING_BT_FEATURE "http://tizen.org/feature/network.tethering.bluetooth" +#define TETHERING_USB_FEATURE "http://tizen.org/feature/network.tethering.usb" +#define TETHERING_WIFI_FEATURE "http://tizen.org/feature/network.tethering.wifi" + +#define CHECK_FEATURE_SUPPORTED(...) \ + do { \ + int rv = tethering_check_feature_supported(__VA_ARGS__, NULL); \ + if(rv != TETHERING_ERROR_NONE) { \ + ERR("Not supported\n"); \ + set_last_result(TETHERING_ERROR_NOT_SUPPORT_API); \ + return TETHERING_ERROR_NOT_SUPPORT_API; \ + } \ + } while (0) + +int tethering_check_feature_supported(const char* feature, ...); + +/** * Start of mobileap-agent common values * When these values are changed, mobileap-agent should be also changed. * But some of those will be removed. @@ -86,9 +108,8 @@ extern "C" { /** * Common configuration */ -#define TETHERING_TYPE_MAX 4 /**< All, USB, Wi-Fi, BT */ +#define TETHERING_TYPE_MAX 5 /**< All, USB, Wi-Fi, BT, Wi-Fi AP */ #define TETHERING_STR_INFO_LEN 20 /**< length of the ip or mac address */ -#define TETHERING_STR_HOSTNAME_LEN 32 /**< length of the hostname */ /** * Mobile AP error code @@ -127,6 +148,9 @@ typedef enum { MOBILE_AP_ENABLE_BT_TETHERING_CFM, MOBILE_AP_DISABLE_BT_TETHERING_CFM, + MOBILE_AP_ENABLE_WIFI_AP_CFM, + MOBILE_AP_DISABLE_WIFI_AP_CFM, + MOBILE_AP_GET_STATION_INFO_CFM, MOBILE_AP_GET_DATA_PACKET_USAGE_CFM } mobile_ap_event_e; @@ -139,29 +163,32 @@ typedef enum { MOBILE_AP_TYPE_MAX, } mobile_ap_type_e; - -/* -* from mobileap_internal.h -*/ -#define DBUS_STRUCT_UINT_STRING (dbus_g_type_get_struct ("GValueArray", \ - G_TYPE_UINT, G_TYPE_STRING, G_TYPE_INVALID)) - -#define DBUS_STRUCT_STATIONS (dbus_g_type_get_struct ("GValueArray", \ - G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING, \ - G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID)) - -#define DBUS_STRUCT_STATION (dbus_g_type_get_struct ("GValueArray", \ - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \ - G_TYPE_INVALID)) - -#define DBUS_STRUCT_INTERFACE (dbus_g_type_get_struct ("GValueArray", \ - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, \ - G_TYPE_STRING, G_TYPE_INVALID)) +typedef enum { + E_SIGNAL_NET_CLOSED = 0, + E_SIGNAL_WIFI_TETHER_ON, + E_SIGNAL_WIFI_TETHER_OFF, + E_SIGNAL_USB_TETHER_ON, + E_SIGNAL_USB_TETHER_OFF, + E_SIGNAL_BT_TETHER_ON, + E_SIGNAL_BT_TETHER_OFF, + E_SIGNAL_WIFI_AP_ON, + E_SIGNAL_WIFI_AP_OFF, + E_SIGNAL_NO_DATA_TIMEOUT, + E_SIGNAL_LOW_BATTERY_MODE, + E_SIGNAL_FLIGHT_MODE, + E_SIGNAL_POWER_SAVE_MODE, + E_SIGNAL_SECURITY_TYPE_CHANGED, + E_SIGNAL_SSID_VISIBILITY_CHANGED, + E_SIGNAL_PASSPHRASE_CHANGED, + E_SIGNAL_DHCP_STATUS, + E_SIGNAL_MAX +} mobile_ap_sig_e; #define TETHERING_SERVICE_OBJECT_PATH "/Tethering" #define TETHERING_SERVICE_NAME "org.tizen.tethering" #define TETHERING_SERVICE_INTERFACE "org.tizen.tethering" +#define TETHERING_SIGNAL_MATCH_RULE "type='signal',interface='org.tizen.tethering'" #define TETHERING_SIGNAL_NAME_LEN 64 #define SIGNAL_NAME_NET_CLOSED "net_closed" @@ -173,13 +200,15 @@ typedef enum { #define SIGNAL_NAME_USB_TETHER_OFF "usb_off" #define SIGNAL_NAME_BT_TETHER_ON "bluetooth_on" #define SIGNAL_NAME_BT_TETHER_OFF "bluetooth_off" +#define SIGNAL_NAME_WIFI_AP_ON "wifi_ap_on" +#define SIGNAL_NAME_WIFI_AP_OFF "wifi_ap_off" #define SIGNAL_NAME_NO_DATA_TIMEOUT "no_data_timeout" #define SIGNAL_NAME_LOW_BATTERY_MODE "low_batt_mode" #define SIGNAL_NAME_FLIGHT_MODE "flight_mode" -#define SIGNAL_NAME_DHCP_STATUS "dhcp_status" #define SIGNAL_NAME_SECURITY_TYPE_CHANGED "security_type_changed" #define SIGNAL_NAME_SSID_VISIBILITY_CHANGED "ssid_visibility_changed" #define SIGNAL_NAME_PASSPHRASE_CHANGED "passphrase_changed" +#define SIGNAL_NAME_DHCP_STATUS "dhcp_status" #define SIGNAL_MSG_NOT_AVAIL_INTERFACE "Interface is not available" #define SIGNAL_MSG_TIMEOUT "There is no connection for a while" @@ -193,34 +222,47 @@ typedef enum { #define TETHERING_USB_GATEWAY "192.168.129.1" #define TETHERING_WIFI_IF "wlan0" -#define TETHERING_WIFI_GATEWAY "192.168.61.1" +#define TETHERING_WIFI_GATEWAY "192.168.43.1" #define TETHERING_BT_IF "bnep0" #define TETHERING_BT_GATEWAY "192.168.130.1" -#define TETHERING_WIFI_SSID_MAX_LEN 31 /**< Maximum length of ssid */ +#define TETHERING_WIFI_SSID_MAX_LEN 32 /**< Maximum length of ssid */ #define TETHERING_WIFI_KEY_MIN_LEN 8 /**< Minimum length of wifi key */ -#define TETHERING_WIFI_KEY_MAX_LEN 63 /**< Maximum length of wifi key */ +#define TETHERING_WIFI_KEY_MAX_LEN 64 /**< Maximum length of wifi key */ +#define TETHERING_WIFI_HASH_KEY_MAX_LEN 64 + +#define VCONFKEY_MOBILE_HOTSPOT_SSID "memory/private/mobileap-agent/ssid" +#define TETHERING_PASSPHRASE_PATH "wifi_tethering.txt" +#define TETHERING_WIFI_PASSPHRASE_STORE_KEY "tethering_wifi_passphrase" +#define MAX_ALIAS_LEN 256 + /** * End of mobileap-agent common values */ -#define TETHERING_DBUS_MAX_RETRY_COUNT 3 #define TETHERING_DEFAULT_SSID "Redwood" #define TETHERING_DEFAULT_PASSPHRASE "eoiugkl!" #define TETHERING_WIFI_SECURITY_TYPE_OPEN_STR "open" #define TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR "wpa2-psk" +#define TETHERING_ERROR_RECOVERY_MAX 3 +#define SECURITY_TYPE_LEN 32 +#define PSK_ITERATION_COUNT 4096 +typedef void (*__handle_cb_t)(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); -typedef void (*__handle_cb_t)(DBusGProxy *proxy, const char *name, gpointer data); typedef struct { + int sig_id; char name[TETHERING_SIGNAL_NAME_LEN]; __handle_cb_t cb; } __tethering_sig_t; typedef struct { - DBusGConnection *client_bus; - DBusGProxy *client_bus_proxy; + GDBusConnection *client_bus; + GDBusProxy *client_bus_proxy; + GCancellable *cancellable; tethering_enabled_cb enabled_cb[TETHERING_TYPE_MAX]; void *enabled_user_data[TETHERING_TYPE_MAX]; @@ -236,15 +278,22 @@ typedef struct { void *ssid_visibility_user_data; tethering_wifi_passphrase_changed_cb passphrase_changed_cb; void *passphrase_user_data; - + tethering_wifi_settings_reloaded_cb settings_reloaded_cb; + void *settings_reloaded_user_data; + tethering_wifi_ap_settings_reloaded_cb ap_settings_reloaded_cb; + void *ap_settings_reloaded_user_data; char *ssid; + char *ap_ssid; + char passphrase[TETHERING_WIFI_KEY_MAX_LEN + 1]; + tethering_wifi_security_type_e sec_type; + bool visibility; } __tethering_h; typedef struct { tethering_type_e interface; /**< interface type */ char ip[TETHERING_STR_INFO_LEN]; /**< assigned IP address */ char mac[TETHERING_STR_INFO_LEN]; /**< MAC Address */ - char hostname[TETHERING_STR_HOSTNAME_LEN]; /**< alphanumeric name */ + char *hostname; time_t tm; /**< connection time */ } __tethering_client_h; @@ -256,6 +305,13 @@ typedef struct { char subnet_mask[TETHERING_STR_INFO_LEN]; /**< subnet mask of interface */ } __tethering_interface_t; +typedef struct { + char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1]; + char key[TETHERING_WIFI_KEY_MAX_LEN + 1]; + tethering_wifi_security_type_e sec_type; + bool visibility; +} _softap_settings_t; + #ifdef __cplusplus } #endif diff --git a/packaging/capi-network-tethering.changes b/packaging/capi-network-tethering.changes deleted file mode 100644 index db65220..0000000 --- a/packaging/capi-network-tethering.changes +++ /dev/null @@ -1,56 +0,0 @@ -* Fri May 31 2013 Anas Nashif accepted/tizen/20130520.100833@326c598 -- Remove placeholders and cleanup spec - -* Wed May 29 2013 Baptiste DURAND accepted/tizen/20130520.100833@2391ebf -- Fix PC file : remove hardcoded lib path - -* Wed Apr 10 2013 Seungyoun Ju 0.0.15-1 -- Fix : Stations data structure for dbus - -* Tue Apr 09 2013 Seungyoun Ju 0.0.14-1 -- TETHERING_ERROR_NOT_PERMITTED is added -- Implement connection timer -- Reference count is used -- Add API : tethering_xxx_ip_forward_status() -- TETHERING_ERROR_NOT_SUPPORT_API is added for tethering_create() -- TETHERING_ERROR_NOT_SUPPORT_API is returned when API is not supported -- sysinfo-tethering.xml is installed depending on build machine - -* Sat Feb 16 2013 Seungyoun Ju 0.0.13-1 -- Wrong linker flags are fixed -- Add API : tethering_wifi_set_ssid() - -* Thu Feb 14 2013 Seungyoun Ju 0.0.12-1 -- APIs are exported -- LOG Format is changed -- fvisibility=hidden is applied and API's return value is checked - -* Thu Jan 24 2013 Seungyoun Ju 0.0.11-1 -- Indications for Wi-Fi tethering setting change are added -- Dbus service / interface / object names are changed - -* Tue Jan 15 2013 Seungyoun Ju 0.0.10-1 -- Wi-Fi tethering state is not checked when its settings are modified - -* Fri Nov 02 2012 Seungyoun Ju 0.0.9-1 -- Manifest file is added for SMACK - -* Mon Aug 20 2012 Seungyoun Ju 0.0.8-1 -- Deprecated APIs are removed - -* Wed Aug 01 2012 Seungyoun Ju 0.0.7-1 -- Managed APIs are implemented for Wi-Fi tethering settings - -* Sat Jul 21 2012 Seungyoun Ju 0.0.6-1 -- Fix tethering callback issue (JIRA S1-6197) - -* Tue Jul 10 2012 Seungyoun Ju 0.0.5 -- Getting MAC address API is implemented -- TETHERING_TYPE_ALL case is implemented -- Test code is implemented - -* Tue Jun 26 2012 Seungyoun Ju 0.0.4 -- All internal APIs are implemented - -* Fri Jun 15 2012 Seungyoun Ju 0.0.3 -- Deprecated API from Glib2-2.32.3 is replaced with new one diff --git a/packaging/capi-network-tethering.manifest b/packaging/capi-network-tethering.manifest deleted file mode 100644 index 017d22d..0000000 --- a/packaging/capi-network-tethering.manifest +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/packaging/capi-network-tethering.spec b/packaging/capi-network-tethering.spec index 6a00912..a3678f2 100644 --- a/packaging/capi-network-tethering.spec +++ b/packaging/capi-network-tethering.spec @@ -1,59 +1,80 @@ -Name: capi-network-tethering -Summary: Tethering Framework -Version: 0.0.16 -Release: 1 -Group: Connectivity/API -License: Apache-2.0 -Source0: %{name}-%{version}.tar.gz -Source1001: capi-network-tethering.manifest - -BuildRequires: pkgconfig(dlog) -BuildRequires: pkgconfig(dbus-glib-1) -BuildRequires: pkgconfig(capi-base-common) -BuildRequires: pkgconfig(glib-2.0) -BuildRequires: pkgconfig(vconf) -BuildRequires: cmake +Name: capi-network-tethering +Summary: Tethering Framework +Version: 1.0.19 +Release: 1 +Group: System/Network +License: Apache-2.0 +Source0: %{name}-%{version}.tar.gz +BuildRequires: pkgconfig(dlog) +BuildRequires: pkgconfig(dbus-1) +BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(glib-2.0) +BuildRequires: pkgconfig(gio-2.0) +BuildRequires: pkgconfig(vconf) +BuildRequires: pkgconfig(key-manager) +BuildRequires: pkgconfig(libssl) +BuildRequires: pkgconfig(capi-system-info) +BuildRequires: cmake +Requires(post): /sbin/ldconfig +Requires(postun): /sbin/ldconfig %description Tethering framework library for CAPI %package devel Summary: Development package for Tethering framework library -Group: Connectivity/Development +Group: Development/Libraries Requires: %{name} = %{version}-%{release} %description devel Development package for Tethering framework library %prep %setup -q -cp %{SOURCE1001} . + %build +export CFLAGS="$CFLAGS -DTIZEN_DEBUG_ENABLE" +export CXXFLAGS="$CXXFLAGS -DTIZEN_DEBUG_ENABLE" +export FFLAGS="$FFLAGS -DTIZEN_DEBUG_ENABLE" + +%cmake -DCMAKE_BUILD_TYPE="Private" \ +%if "%{?tizen_profile_name}" == "wearable" + -DTIZEN_WEARABLE=1 \ +%else +%if "%{?tizen_profile_name}" == "mobile" + -DTIZEN_MOBILE=1 \ +%endif +%endif %ifarch %{arm} -%cmake . -DARCH=arm + -DCMAKE_BUILD_TYPE="Private" -DARCH=arm \ %else %if 0%{?simulator} -%cmake . -DARCH=emul + -DCMAKE_BUILD_TYPE="Private" -DARCH=emul \ %else -%cmake . -DARCH=i586 + -DCMAKE_BUILD_TYPE="Private" -DARCH=i586 \ %endif %endif -make %{?jobs:-j%jobs} + . + +make %{?_smp_mflags} + %install %make_install + mkdir -p %{buildroot}/usr/share/license -cp LICENSE.APLv2.0 %{buildroot}/usr/share/license/%{name} +cp LICENSE.APLv2.0 %{buildroot}/usr/share/license/capi-network-tethering +cp LICENSE.APLv2.0 %{buildroot}/usr/share/license/capi-network-tethering-devel %post -p /sbin/ldconfig %postun -p /sbin/ldconfig %files -%manifest %{name}.manifest +%manifest capi-network-tethering.manifest %defattr(-,root,root,-) %{_libdir}/*.so.* -/usr/share/license/%{name} +/usr/share/license/capi-network-tethering %ifarch %{arm} /etc/config/connectivity/sysinfo-tethering.xml %else @@ -65,9 +86,8 @@ cp LICENSE.APLv2.0 %{buildroot}/usr/share/license/%{name} %endif %files devel -%manifest %{name}.manifest %defattr(-,root,root,-) %{_includedir}/network/*.h %{_libdir}/pkgconfig/*.pc %{_libdir}/*.so - +/usr/share/license/capi-network-tethering-devel diff --git a/src/tethering.c b/src/tethering.c old mode 100644 new mode 100755 index 49d3b41..2ed6b9a --- a/src/tethering.c +++ b/src/tethering.c @@ -23,53 +23,309 @@ #include #include #include - +#include +#include #include - -#include "tethering-client-stub.h" -#include "marshal.h" +#include +#include +#include #include "tethering_private.h" -static void __handle_wifi_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_wifi_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_usb_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_usb_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_bt_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_bt_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_net_closed(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_no_data_timeout(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_low_battery_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_flight_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_security_type_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_ssid_visibility_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data); -static void __handle_passphrase_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data); +static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data); + +static void __get_key_manager_alias(char* alias, size_t buff_len); static __tethering_sig_t sigs[] = { - {SIGNAL_NAME_NET_CLOSED, __handle_net_closed}, - {SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on}, - {SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off}, - {SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on}, - {SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off}, - {SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on}, - {SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off}, - {SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout}, - {SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode}, - {SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode}, - {SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed}, - {SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed}, - {SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed}, - {"", NULL}}; + {0, SIGNAL_NAME_NET_CLOSED, __handle_net_closed}, + {0, SIGNAL_NAME_WIFI_TETHER_ON, __handle_wifi_tether_on}, + {0, SIGNAL_NAME_WIFI_TETHER_OFF, __handle_wifi_tether_off}, + {0, SIGNAL_NAME_USB_TETHER_ON, __handle_usb_tether_on}, + {0, SIGNAL_NAME_USB_TETHER_OFF, __handle_usb_tether_off}, + {0, SIGNAL_NAME_BT_TETHER_ON, __handle_bt_tether_on}, + {0, SIGNAL_NAME_BT_TETHER_OFF, __handle_bt_tether_off}, + {0, SIGNAL_NAME_WIFI_AP_ON, __handle_wifi_ap_on}, + {0, SIGNAL_NAME_WIFI_AP_OFF, __handle_wifi_ap_off}, + {0, SIGNAL_NAME_NO_DATA_TIMEOUT, __handle_no_data_timeout}, + {0, SIGNAL_NAME_LOW_BATTERY_MODE, __handle_low_battery_mode}, + {0, SIGNAL_NAME_FLIGHT_MODE, __handle_flight_mode}, + {0, SIGNAL_NAME_SECURITY_TYPE_CHANGED, __handle_security_type_changed}, + {0, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, __handle_ssid_visibility_changed}, + {0, SIGNAL_NAME_PASSPHRASE_CHANGED, __handle_passphrase_changed}, + {0, SIGNAL_NAME_DHCP_STATUS, __handle_dhcp}, + {0, "", NULL}}; + +static int retry = 0; + +static void __send_dbus_signal(GDBusConnection *conn, const char *signal_name, const char *arg) +{ + if (conn == NULL || signal_name == NULL) + return; + + GVariant *message = NULL; + GError *error = NULL; + + if (arg) { + message = g_variant_new("(s)", arg); + } + + g_dbus_connection_emit_signal(conn, NULL, TETHERING_SERVICE_OBJECT_PATH, + TETHERING_SERVICE_INTERFACE, signal_name, message, &error); + if (error) { + ERR("g_dbus_connection_emit_signal is failed because %s\n", error->message); + g_error_free(error); + } + g_variant_unref(message); +} static bool __any_tethering_is_enabled(tethering_h tethering) { if (tethering_is_enabled(tethering, TETHERING_TYPE_USB) || tethering_is_enabled(tethering, TETHERING_TYPE_WIFI) || - tethering_is_enabled(tethering, TETHERING_TYPE_BT)) + tethering_is_enabled(tethering, TETHERING_TYPE_BT) || + tethering_is_enabled(tethering, TETHERING_TYPE_RESERVED)) return true; return false; } +static tethering_error_e __set_security_type(const tethering_wifi_security_type_e security_type) +{ + if (security_type != TETHERING_WIFI_SECURITY_TYPE_NONE && + security_type != TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) { + ERR("Invalid param\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + + if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, security_type) < 0) { + ERR("vconf_set_int is failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + + return TETHERING_ERROR_NONE; +} + +static tethering_error_e __get_security_type(tethering_wifi_security_type_e *security_type) +{ + if (security_type == NULL) { + ERR("Invalid param\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + + if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_SECURITY, + (int *)security_type) < 0) { + ERR("vconf_get_int is failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + + return TETHERING_ERROR_NONE; +} + +static bool __get_ssid_from_vconf(const char *path, char *ssid, unsigned int size) +{ + if (path == NULL || ssid == NULL || size == 0) + return false; + + char *ptr = NULL; + char *ptr_tmp = NULL; + + ptr = vconf_get_str(path); + if (ptr == NULL) + return false; + + if (!g_utf8_validate(ptr, -1, (const char **)&ptr_tmp)) + *ptr_tmp = '\0'; + + g_strlcpy(ssid, ptr, size); + free(ptr); + + return true; +} + +static tethering_error_e __set_visible(const bool visible) +{ + if (vconf_set_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, visible ? 0 : 1) < 0) { + ERR("vconf_set_int is failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + + return TETHERING_ERROR_NONE; +} + +static tethering_error_e __get_visible(bool *visible) +{ + if (visible == NULL) { + ERR("Invalid param\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + + int hide = 0; + + if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_HIDE, &hide) < 0) { + ERR("vconf_get_int is failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + + if (hide) + *visible = false; + else + *visible = true; + return TETHERING_ERROR_NONE; +} + +static unsigned int __generate_initial_passphrase(char *passphrase, unsigned int size) +{ + if (passphrase == NULL || + size == 0 || size < TETHERING_WIFI_KEY_MIN_LEN + 1) + return 0; + + guint32 rand_int = 0; + int index = 0; + + for (index = 0; index < TETHERING_WIFI_KEY_MIN_LEN; index++) { + rand_int = g_random_int_range('a', 'z'); + passphrase[index] = rand_int; + } + passphrase[index] = '\0'; + + return index; +} + +static tethering_error_e __set_passphrase(const char *passphrase, const unsigned int size) +{ + if (passphrase == NULL || size == 0) + return TETHERING_ERROR_INVALID_PARAMETER; + + int ret = -1; + char alias[MAX_ALIAS_LEN] = {0, }; + ckmc_raw_buffer_s ckmc_buf; + ckmc_policy_s ckmc_policy; + + ckmc_policy.password = NULL; + ckmc_policy.extractable = true; + + ckmc_buf.data = (unsigned char *) passphrase; + ckmc_buf.size = strlen(passphrase); + + __get_key_manager_alias(alias, sizeof(alias)); + ret = ckmc_save_data(alias, ckmc_buf, ckmc_policy); + if (ret != CKMC_ERROR_NONE) { + ERR("Fail to save the passphrase : %d\n", ret); + return TETHERING_ERROR_OPERATION_FAILED; + } + + return TETHERING_ERROR_NONE; +} + +static void __get_key_manager_alias(char* alias, size_t buff_len) +{ + snprintf(alias, buff_len, "%s%s%s", ckmc_owner_id_system, + ckmc_owner_id_separator, + TETHERING_WIFI_PASSPHRASE_STORE_KEY); +} + +static tethering_error_e __get_passphrase(char *passphrase, + unsigned int passphrase_size, unsigned int *passphrase_len) +{ + if (passphrase == NULL || passphrase_size == 0) { + ERR("Invalid parameter\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + + int ret = 0; + char tmp[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; + char alias[MAX_ALIAS_LEN] = {0, }; + ckmc_raw_buffer_s *ckmc_buf; + + __get_key_manager_alias(alias, sizeof(alias)); + ret = ckmc_get_data(alias, NULL, &ckmc_buf); + if (ret < 0) { + DBG("Create new password\n"); + ret = __generate_initial_passphrase(tmp, sizeof(tmp)); + + if (ret == 0) { + ERR("generate_initial_passphrase failed : %d\n", *passphrase_len); + return TETHERING_ERROR_OPERATION_FAILED; + } else { + *passphrase_len = ret; + g_strlcpy(passphrase,tmp,(*passphrase_len)+1); + + if (__set_passphrase(passphrase, *passphrase_len) != TETHERING_ERROR_NONE) { + DBG("set_passphrase is failed : %s, %d",passphrase, *passphrase_len); + return TETHERING_ERROR_OPERATION_FAILED; + } + } + } else { + *passphrase_len = ckmc_buf->size; + g_strlcpy(passphrase, (char *)ckmc_buf->data, (*passphrase_len) + 1); + } + + g_free(alias); + + return TETHERING_ERROR_NONE; +} + static tethering_error_e __get_error(int agent_error) { tethering_error_e err = TETHERING_ERROR_NONE; @@ -119,6 +375,10 @@ static tethering_error_e __get_error(int agent_error) err = TETHERING_ERROR_NOT_PERMITTED; break; + case MOBILE_AP_ERROR_PERMISSION_DENIED: + err = TETHERING_ERROR_PERMISSION_DENIED; + break; + default: ERR("Not defined error : %d\n", agent_error); err = TETHERING_ERROR_OPERATION_FAILED; @@ -128,9 +388,9 @@ static tethering_error_e __get_error(int agent_error) return err; } -static void __handle_dhcp(DBusGProxy *proxy, const char *member, - guint interface, const char *ip, const char *mac, - const char *name, guint timestamp, gpointer user_data) +static void __handle_dhcp(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -139,47 +399,66 @@ static void __handle_dhcp(DBusGProxy *proxy, const char *member, __tethering_h *th = (__tethering_h *)user_data; bool opened = false; tethering_type_e type = 0; + mobile_ap_type_e ap_type = 0; tethering_connection_state_changed_cb ccb = NULL; - __tethering_client_h client = {0, }; + __tethering_client_h client; void *data = NULL; + char *buf = NULL; + char *name = NULL; + char *mac= NULL; + char *ip= NULL; + guint timestamp; - if (!g_strcmp0(member, "DhcpConnected")) { + memset(&client, 0, sizeof(__tethering_client_h)); + g_variant_get(parameters, "(susssu)", &buf, &ap_type, &ip, &mac, &name, ×tamp); + + if (!g_strcmp0(buf, "DhcpConnected")) { opened = true; - } else if (!g_strcmp0(member, "DhcpLeaseDeleted")) { + } else if (!g_strcmp0(buf, "DhcpLeaseDeleted")) { opened = false; } else { - ERR("Unknown event [%s]\n", member); - return; + ERR("Unknown event [%s]\n", buf); + goto DONE; } - if (interface == MOBILE_AP_TYPE_USB) + if (ap_type == MOBILE_AP_TYPE_USB) type = TETHERING_TYPE_USB; - else if (interface == MOBILE_AP_TYPE_WIFI) + else if (ap_type == MOBILE_AP_TYPE_WIFI) type = TETHERING_TYPE_WIFI; - else if (interface == MOBILE_AP_TYPE_BT) + else if (ap_type == MOBILE_AP_TYPE_BT) type = TETHERING_TYPE_BT; - else { - ERR("Not supported tethering type [%d]\n", interface); - return; + else if (ap_type == MOBILE_AP_TYPE_WIFI_AP) { + type = TETHERING_TYPE_RESERVED; + } else { + ERR("Not supported tethering type [%d]\n", ap_type); + goto DONE; } ccb = th->changed_cb[type]; if (ccb == NULL) - return; + goto DONE; data = th->changed_user_data[type]; client.interface = type; g_strlcpy(client.ip, ip, sizeof(client.ip)); g_strlcpy(client.mac, mac, sizeof(client.mac)); - g_strlcpy(client.hostname, name, sizeof(client.hostname)); + if (name != NULL) + client.hostname = g_strdup(name); client.tm = (time_t)timestamp; ccb((tethering_client_h)&client, opened, data); - - return; + g_free(client.hostname); +DONE : + g_free(buf); + g_free(ip); + g_free(mac); + g_free(name); + DBG("-\n"); } -static void __handle_net_closed(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_net_closed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -200,10 +479,12 @@ static void __handle_net_closed(DBusGProxy *proxy, const char *value_name, gpoin dcb(TETHERING_ERROR_NONE, type, code, data); } - return; + DBG("-\n"); } -static void __handle_wifi_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_wifi_tether_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -221,9 +502,12 @@ static void __handle_wifi_tether_on(DBusGProxy *proxy, const char *value_name, g data = th->enabled_user_data[type]; ecb(TETHERING_ERROR_NONE, type, is_requested, data); + DBG("-\n"); } -static void __handle_wifi_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_wifi_tether_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -234,23 +518,27 @@ static void __handle_wifi_tether_off(DBusGProxy *proxy, const char *value_name, tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS; tethering_disabled_cb dcb = NULL; void *data = NULL; + char *buf = NULL; dcb = th->disabled_cb[type]; if (dcb == NULL) return; data = th->disabled_user_data[type]; - - if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE)) + g_variant_get(parameters, "(s)", &buf); + if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE)) code = TETHERING_DISABLED_BY_WIFI_ON; - else if (!g_strcmp0(value_name, SIGNAL_MSG_TIMEOUT)) + else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT)) code = TETHERING_DISABLED_BY_TIMEOUT; + g_free(buf); dcb(TETHERING_ERROR_NONE, type, code, data); - return; + DBG("-\n"); } -static void __handle_usb_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_usb_tether_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -268,9 +556,12 @@ static void __handle_usb_tether_on(DBusGProxy *proxy, const char *value_name, gp data = th->enabled_user_data[type]; ecb(TETHERING_ERROR_NONE, type, is_requested, data); + DBG("-\n"); } -static void __handle_usb_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_usb_tether_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -281,21 +572,25 @@ static void __handle_usb_tether_off(DBusGProxy *proxy, const char *value_name, g tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS; tethering_disabled_cb dcb = NULL; void *data = NULL; + char *buf = NULL; dcb = th->disabled_cb[type]; if (dcb == NULL) return; data = th->disabled_user_data[type]; - if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE)) + g_variant_get(parameters, "(s)", &buf); + if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE)) code = TETHERING_DISABLED_BY_USB_DISCONNECTION; dcb(TETHERING_ERROR_NONE, type, code, data); - - return; + g_free(buf); + DBG("-\n"); } -static void __handle_bt_tether_on(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_bt_tether_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -313,9 +608,12 @@ static void __handle_bt_tether_on(DBusGProxy *proxy, const char *value_name, gpo data = th->enabled_user_data[type]; ecb(TETHERING_ERROR_NONE, type, is_requested, data); + DBG("-\n"); } -static void __handle_bt_tether_off(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_bt_tether_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -326,23 +624,81 @@ static void __handle_bt_tether_off(DBusGProxy *proxy, const char *value_name, gp tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS; tethering_disabled_cb dcb = NULL; void *data = NULL; + char *buf = NULL; dcb = th->disabled_cb[type]; if (dcb == NULL) return; data = th->disabled_user_data[type]; - - if (!g_strcmp0(value_name, SIGNAL_MSG_NOT_AVAIL_INTERFACE)) + g_variant_get(parameters, "(s)", &buf); + if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE)) code = TETHERING_DISABLED_BY_BT_OFF; - else if (!g_strcmp0(value_name, SIGNAL_MSG_TIMEOUT)) + else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT)) code = TETHERING_DISABLED_BY_TIMEOUT; dcb(TETHERING_ERROR_NONE, type, code, data); - return; + g_free(buf); + DBG("-\n"); +} + +static void __handle_wifi_ap_on(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) +{ + DBG("+\n"); + + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + + __tethering_h *th = (__tethering_h *)user_data; + tethering_type_e type = TETHERING_TYPE_RESERVED; + bool is_requested = false; + tethering_enabled_cb ecb = NULL; + void *data = NULL; + + ecb = th->enabled_cb[type]; + if (ecb == NULL) + return; + data = th->enabled_user_data[type]; + + ecb(TETHERING_ERROR_NONE, type, is_requested, data); + DBG("-\n"); +} + +static void __handle_wifi_ap_off(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) +{ + DBG("+\n"); + + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + + __tethering_h *th = (__tethering_h *)user_data; + tethering_type_e type = TETHERING_TYPE_RESERVED; + tethering_disabled_cause_e code = TETHERING_DISABLED_BY_OTHERS; + tethering_disabled_cb dcb = NULL; + void *data = NULL; + char *buf= NULL; + + dcb = th->disabled_cb[type]; + if (dcb == NULL) + return; + data = th->disabled_user_data[type]; + g_variant_get(parameters, "(s)", &buf); + if (!g_strcmp0(buf, SIGNAL_MSG_NOT_AVAIL_INTERFACE)) + code = TETHERING_DISABLED_BY_WIFI_ON; + else if (!g_strcmp0(buf, SIGNAL_MSG_TIMEOUT)) + code = TETHERING_DISABLED_BY_TIMEOUT; + g_free(buf); + + dcb(TETHERING_ERROR_NONE, type, code, data); + + DBG("-\n"); } -static void __handle_no_data_timeout(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_no_data_timeout(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -362,9 +718,12 @@ static void __handle_no_data_timeout(DBusGProxy *proxy, const char *value_name, dcb(TETHERING_ERROR_NONE, type, code, data); } + DBG("-\n"); } -static void __handle_low_battery_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_low_battery_mode(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -376,7 +735,7 @@ static void __handle_low_battery_mode(DBusGProxy *proxy, const char *value_name, void *data = NULL; tethering_disabled_cause_e code = TETHERING_DISABLED_BY_LOW_BATTERY; - for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) { + for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) { dcb = th->disabled_cb[type]; if (dcb == NULL) continue; @@ -384,9 +743,12 @@ static void __handle_low_battery_mode(DBusGProxy *proxy, const char *value_name, dcb(TETHERING_ERROR_NONE, type, code, data); } + DBG("-\n"); } -static void __handle_flight_mode(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_flight_mode(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); @@ -398,7 +760,7 @@ static void __handle_flight_mode(DBusGProxy *proxy, const char *value_name, gpoi void *data = NULL; tethering_disabled_cause_e code = TETHERING_DISABLED_BY_FLIGHT_MODE; - for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) { + for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_RESERVED; type++) { dcb = th->disabled_cb[type]; if (dcb == NULL) continue; @@ -406,69 +768,83 @@ static void __handle_flight_mode(DBusGProxy *proxy, const char *value_name, gpoi dcb(TETHERING_ERROR_NONE, type, code, data); } + DBG("-\n"); } -static void __handle_security_type_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_security_type_changed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) + { DBG("+\n"); _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); - __tethering_h *th = (__tethering_h *)user_data; + tethering_wifi_security_type_changed_cb scb = NULL; void *data = NULL; tethering_wifi_security_type_e security_type; + char *buf = NULL; scb = th->security_type_changed_cb; if (scb == NULL) return; + g_variant_get(parameters, "(s)", &buf); data = th->security_type_user_data; - if (g_strcmp0(value_name, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0) + if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0) security_type = TETHERING_WIFI_SECURITY_TYPE_NONE; - else if (g_strcmp0(value_name, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0) + else if (g_strcmp0(buf, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0) security_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK; else { - ERR("Unknown security type : %s\n", value_name); + SERR("Unknown type : %s\n", buf); + g_free(buf); return; } - + g_free(buf); scb(security_type, data); return; } -static void __handle_ssid_visibility_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_ssid_visibility_changed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); - __tethering_h *th = (__tethering_h *)user_data; + tethering_wifi_ssid_visibility_changed_cb scb = NULL; void *data = NULL; bool visible = false; + char *buf = NULL; scb = th->ssid_visibility_changed_cb; - if (scb == NULL) + if (scb == NULL) { + DBG("-\n"); return; - + } + g_variant_get(parameters, "(s)", &buf); data = th->ssid_visibility_user_data; - if (g_strcmp0(value_name, SIGNAL_MSG_SSID_VISIBLE) == 0) + if (g_strcmp0(buf, SIGNAL_MSG_SSID_VISIBLE) == 0) visible = true; scb(visible, data); - - return; + g_free(buf); + DBG("-\n"); } -static void __handle_passphrase_changed(DBusGProxy *proxy, const char *value_name, gpointer user_data) +static void __handle_passphrase_changed(GDBusConnection *connection, const gchar *sender_name, + const gchar *object_path, const gchar *interface_name, const gchar *signal_name, + GVariant *parameters, gpointer user_data) { DBG("+\n"); _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); - __tethering_h *th = (__tethering_h *)user_data; + tethering_wifi_passphrase_changed_cb pcb = NULL; void *data = NULL; @@ -479,105 +855,302 @@ static void __handle_passphrase_changed(DBusGProxy *proxy, const char *value_nam data = th->passphrase_user_data; pcb(data); - - return; + DBG("-\n"); } -static void __cfm_cb(DBusGProxy *remoteobj, guint event, guint info, - GError *g_error, gpointer user_data) +static void __wifi_enabled_cfm_cb(GObject *source_object, GAsyncResult *res, + gpointer user_data) { DBG("+\n"); _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + GError *g_error = NULL; + GVariant *g_var; + guint info; + tethering_error_e error; + __tethering_h *th = (__tethering_h *)user_data; + tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_WIFI]; + void *data = th->enabled_user_data[TETHERING_TYPE_WIFI]; - tethering_h tethering = (tethering_h)user_data; - __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); + if (g_error) { + ERR("DBus error [%s]\n", g_error->message); + if (g_error->code == G_DBUS_ERROR_NO_REPLY && + ++retry < TETHERING_ERROR_RECOVERY_MAX) { + g_error_free(g_error); + tethering_enable((tethering_h)th, TETHERING_TYPE_WIFI); + return; + } else if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED) + error = TETHERING_ERROR_PERMISSION_DENIED; + else + error = TETHERING_ERROR_OPERATION_FAILED; + g_error_free(g_error); + } else { + g_variant_get(g_var, "(u)", &info); + error = __get_error(info); + } + retry = 0; - tethering_type_e type = 0; - tethering_error_e error = __get_error(info); - bool is_requested = true; - tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST; + sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_ON].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_WIFI_TETHER_ON].cb, (gpointer)th, NULL); - tethering_enabled_cb ecb = NULL; - tethering_disabled_cb dcb = NULL; - void *data = NULL; + if (!ecb) { + DBG("-\n"); + return; + } + ecb(error, TETHERING_TYPE_WIFI, true, data); + g_variant_unref(g_var); + DBG("-\n"); +} + +static void __bt_enabled_cfm_cb (GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + DBG("+\n"); + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + GError *g_error = NULL; + GVariant *g_var; + guint info; + tethering_error_e error; + + __tethering_h *th = (__tethering_h *)user_data; + tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_BT]; + void *data = th->enabled_user_data[TETHERING_TYPE_BT]; + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); if (g_error) { ERR("DBus error [%s]\n", g_error->message); + if (g_error->code == G_DBUS_ERROR_NO_REPLY && + ++retry < TETHERING_ERROR_RECOVERY_MAX) { + g_error_free(g_error); + tethering_enable((tethering_h)th, TETHERING_TYPE_BT); + DBG("-\n"); + return; + } + if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED) + error = TETHERING_ERROR_PERMISSION_DENIED; + else + error = TETHERING_ERROR_OPERATION_FAILED; g_error_free(g_error); - return; + } else { + g_variant_get(g_var, "(u)", &info); + g_variant_unref(g_var); + error = __get_error(info); } + retry = 0; - DBG("cfm event : %d info : %d\n", event, info); - switch (event) { - case MOBILE_AP_ENABLE_WIFI_TETHERING_CFM: - type = TETHERING_TYPE_WIFI; - ecb = th->enabled_cb[type]; - data = th->enabled_user_data[type]; - if (ecb) - ecb(error, type, is_requested, data); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON, - G_CALLBACK(__handle_wifi_tether_on), - (gpointer)tethering, NULL); - break; + sigs[E_SIGNAL_BT_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_ON].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_BT_TETHER_ON].cb, (gpointer)th, NULL); - case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM: - type = TETHERING_TYPE_WIFI; - dcb = th->disabled_cb[type]; - data = th->disabled_user_data[type]; - if (dcb) - dcb(error, type, code, data); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF, - G_CALLBACK(__handle_wifi_tether_off), - (gpointer)tethering, NULL); - break; + if (!ecb) { + DBG("-\n"); + return; + } - case MOBILE_AP_ENABLE_BT_TETHERING_CFM: - type = TETHERING_TYPE_BT; - ecb = th->enabled_cb[type]; - data = th->enabled_user_data[type]; - if (ecb) - ecb(error, type, is_requested, data); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON, - G_CALLBACK(__handle_bt_tether_on), - (gpointer)tethering, NULL); - break; + ecb(error, TETHERING_TYPE_BT, true, data); + DBG("-\n"); +} - case MOBILE_AP_DISABLE_BT_TETHERING_CFM: - type = TETHERING_TYPE_BT; +static void __usb_enabled_cfm_cb (GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + DBG("+\n"); + + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + __tethering_h *th = (__tethering_h *)user_data; + GError *g_error = NULL; + GVariant *g_var; + guint info; + tethering_error_e error; + tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_USB]; + void *data = th->enabled_user_data[TETHERING_TYPE_USB]; + + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); + if (g_error) { + ERR("DBus error [%s]\n", g_error->message); + if (g_error->code == G_DBUS_ERROR_NO_REPLY && + ++retry < TETHERING_ERROR_RECOVERY_MAX) { + g_error_free(g_error); + tethering_enable((tethering_h)th, TETHERING_TYPE_USB); + DBG("-\n"); + return; + } + if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED) + error = TETHERING_ERROR_PERMISSION_DENIED; + else + error = TETHERING_ERROR_OPERATION_FAILED; + g_error_free(g_error); + } else { + g_variant_get(g_var, "(u)", &info); + g_variant_unref(g_var); + error = __get_error(info); + } + retry = 0; + + sigs[E_SIGNAL_USB_TETHER_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_ON].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_USB_TETHER_ON].cb, (gpointer)th, NULL); + + if (!ecb) { + DBG("-\n"); + return; + } + + ecb(error, TETHERING_TYPE_USB, true, data); + DBG("-\n"); +} + +static void __wifi_ap_enabled_cfm_cb (GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + DBG("+\n"); + + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + __tethering_h *th = (__tethering_h *)user_data; + GError *g_error = NULL; + GVariant *g_var; + guint info; + tethering_error_e error; + tethering_enabled_cb ecb = th->enabled_cb[TETHERING_TYPE_RESERVED]; + void *data = th->enabled_user_data[TETHERING_TYPE_RESERVED]; + + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); + if (g_error) { + ERR("DBus error [%s]\n", g_error->message); + if (g_error->code == G_DBUS_ERROR_NO_REPLY && + ++retry < TETHERING_ERROR_RECOVERY_MAX) { + g_error_free(g_error); + tethering_enable((tethering_h)th, TETHERING_TYPE_RESERVED); + DBG("-\n"); + return; + } + if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED) + error = TETHERING_ERROR_PERMISSION_DENIED; + else + error = TETHERING_ERROR_OPERATION_FAILED; + g_error_free(g_error); + } else { + g_variant_get(g_var, "(u)", &info); + g_variant_unref(g_var); + error = __get_error(info); + } + retry = 0; + + sigs[E_SIGNAL_WIFI_AP_ON].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_ON].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_WIFI_AP_ON].cb, (gpointer)th, NULL); + + if (!ecb) { + DBG("-\n"); + return; + } + + ecb(error, TETHERING_TYPE_RESERVED, true, data); + DBG("-\n"); +} + +static void __disabled_cfm_cb(GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + DBG("+\n"); + + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + GError *g_error = NULL; + GVariant *g_var; + guint info, event_type; + tethering_error_e error; + tethering_type_e type; + tethering_h tethering = (tethering_h)user_data; + __tethering_h *th = (__tethering_h *)tethering; + tethering_disabled_cause_e code = TETHERING_DISABLED_BY_REQUEST; + tethering_disabled_cb dcb = NULL; + void *data = NULL; + + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); + if (g_error) { + ERR("DBus error [%s]\n", g_error->message); + g_error_free(g_error); + return; + } + g_variant_get(g_var, "(uu)", &event_type, &info); + DBG("cfm event : %d info : %d\n", event_type, info); + g_variant_unref(g_var); + error = __get_error(info); + DBG("cfm event : %d info : %d\n", event_type, error); + switch (event_type) { + case MOBILE_AP_DISABLE_WIFI_TETHERING_CFM: + sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL); + + type = TETHERING_TYPE_WIFI; dcb = th->disabled_cb[type]; data = th->disabled_user_data[type]; if (dcb) dcb(error, type, code, data); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF, - G_CALLBACK(__handle_bt_tether_off), - (gpointer)tethering, NULL); break; - case MOBILE_AP_ENABLE_USB_TETHERING_CFM: - type = TETHERING_TYPE_USB; - ecb = th->enabled_cb[type]; - data = th->enabled_user_data[type]; - if (ecb) - ecb(error, type, is_requested, data); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON, - G_CALLBACK(__handle_usb_tether_on), - (gpointer)tethering, NULL); + case MOBILE_AP_DISABLE_BT_TETHERING_CFM: + sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL); + + type = TETHERING_TYPE_BT; + dcb = th->disabled_cb[type]; + data = th->disabled_user_data[type]; + if (dcb) + dcb(error, type, code, data); break; case MOBILE_AP_DISABLE_USB_TETHERING_CFM: + sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL); + type = TETHERING_TYPE_USB; dcb = th->disabled_cb[type]; data = th->disabled_user_data[type]; if (dcb) dcb(error, type, code, data); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF, - G_CALLBACK(__handle_usb_tether_off), - (gpointer)tethering, NULL); + break; + + case MOBILE_AP_DISABLE_WIFI_AP_CFM: + sigs[E_SIGNAL_WIFI_AP_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_AP_OFF].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_WIFI_AP_OFF].cb, (gpointer)th, NULL); + + type = TETHERING_TYPE_RESERVED; + dcb = th->disabled_cb[type]; + data = th->disabled_user_data[type]; + if (dcb) + dcb(error, type, code, data); break; case MOBILE_AP_DISABLE_CFM: + + sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_WIFI_TETHER_OFF].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_WIFI_TETHER_OFF].cb, (gpointer)th, NULL); + sigs[E_SIGNAL_BT_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_BT_TETHER_OFF].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_BT_TETHER_OFF].cb, (gpointer)th, NULL); + sigs[E_SIGNAL_USB_TETHER_OFF].sig_id = g_dbus_connection_signal_subscribe(th->client_bus, + NULL, TETHERING_SERVICE_INTERFACE, sigs[E_SIGNAL_USB_TETHER_OFF].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[E_SIGNAL_USB_TETHER_OFF].cb, (gpointer)th, NULL); + for (type = TETHERING_TYPE_USB; type <= TETHERING_TYPE_BT; type++) { dcb = th->disabled_cb[type]; if (dcb == NULL) @@ -586,122 +1159,168 @@ static void __cfm_cb(DBusGProxy *remoteobj, guint event, guint info, dcb(error, type, code, data); } - - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF, - G_CALLBACK(__handle_usb_tether_off), - (gpointer)tethering, NULL); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF, - G_CALLBACK(__handle_wifi_tether_off), - (gpointer)tethering, NULL); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF, - G_CALLBACK(__handle_bt_tether_off), - (gpointer)tethering, NULL); break; default: ERR("Invalid event\n"); - return; + break; } - - return; + DBG("-\n"); } -static void __get_data_usage_cb(DBusGProxy *remoteobj, guint event, - guint64 tx_bytes, guint64 rx_bytes, - GError *error, gpointer user_data) +static void __get_data_usage_cb(GObject *source_object, GAsyncResult *res, + gpointer user_data) { + DBG("+\n"); + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + GError *g_error = NULL; + GVariant *g_var; + guint event_type; + guint64 tx_bytes, rx_bytes; __tethering_h *th = (__tethering_h *)user_data; + tethering_error_e tethering_error = TETHERING_ERROR_NONE; + bool flag = false; + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); + if (g_error) { + ERR("DBus fail [%s]\n", g_error->message); + if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED) + tethering_error = TETHERING_ERROR_PERMISSION_DENIED; + else + tethering_error = TETHERING_ERROR_OPERATION_FAILED; + + flag = true; + } if (th->data_usage_cb == NULL) { ERR("There is no data_usage_cb\n"); return; } + if (flag) { + th->data_usage_cb(tethering_error, 0LL, 0LL, th->data_usage_user_data); + } else { + g_variant_get(g_var, "(utt)", &event_type, &tx_bytes, &rx_bytes); + th->data_usage_cb(TETHERING_ERROR_NONE, + rx_bytes, tx_bytes, th->data_usage_user_data); + g_variant_unref(g_var); + } + th->data_usage_cb = NULL; + th->data_usage_user_data = NULL; - if (error || event != MOBILE_AP_GET_DATA_PACKET_USAGE_CFM) { - if (error) { - ERR("DBus fail [%s]\n", error->message); - g_error_free(error); - } + DBG("-\n"); +} - th->data_usage_cb(TETHERING_ERROR_OPERATION_FAILED, - 0LL, 0LL, th->data_usage_user_data); +static void __settings_reloaded_cb(GObject *source_object, GAsyncResult *res, + gpointer user_data) +{ + DBG("+\n"); - th->data_usage_cb = NULL; - th->data_usage_user_data = NULL; + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + GError *g_error = NULL; + GVariant *g_var; + guint info; + __tethering_h *th = (__tethering_h *)user_data; + tethering_error_e tethering_error; + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); + if (g_error) { + ERR("DBus fail [%s]\n", g_error->message); + if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED) + tethering_error = TETHERING_ERROR_PERMISSION_DENIED; + else + tethering_error = TETHERING_ERROR_OPERATION_FAILED; + g_error_free(g_error); + } + if (th->settings_reloaded_cb == NULL) { + DBG("There is no settings_reloaded_cb\n-\n"); return; } + g_variant_get(g_var, "(u)", &info); + tethering_error = __get_error(info); + g_variant_unref(g_var); - th->data_usage_cb(TETHERING_ERROR_NONE, - rx_bytes, tx_bytes, th->data_usage_user_data); - - th->data_usage_cb = NULL; - th->data_usage_user_data = NULL; + th->settings_reloaded_cb(tethering_error, + th->settings_reloaded_user_data); - return; + th->settings_reloaded_cb = NULL; + th->settings_reloaded_user_data = NULL; + DBG("-\n"); } -static void __ip_forward_cb(DBusGProxy *remoteobj, gint result, - GError *error, gpointer user_data) +static void __ap_settings_reloaded_cb(GObject *source_object, GAsyncResult *res, + gpointer user_data) { + DBG("+\n"); + _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + GError *g_error = NULL; + GVariant *g_var; + guint info; + __tethering_h *th = (__tethering_h *)user_data; + tethering_error_e tethering_error; - if (error) { - ERR("DBus fail [%s]\n", error->message); - g_error_free(error); + g_var = g_dbus_proxy_call_finish(th->client_bus_proxy, res, &g_error); + if (g_error) { + ERR("DBus fail [%s]\n", g_error->message); + if (g_error->code == G_DBUS_ERROR_ACCESS_DENIED) + tethering_error = TETHERING_ERROR_PERMISSION_DENIED; + else + tethering_error = TETHERING_ERROR_OPERATION_FAILED; + g_error_free(g_error); + } + if (th->ap_settings_reloaded_cb == NULL) { + DBG("There is no settings_reloaded_cb\n-\n"); + return; } + g_variant_get(g_var, "(u)", &info); + tethering_error = __get_error(info); + g_variant_unref(g_var); - return; + th->ap_settings_reloaded_cb(tethering_error, + th->ap_settings_reloaded_user_data); + + th->ap_settings_reloaded_cb = NULL; + th->ap_settings_reloaded_user_data = NULL; + DBG("-\n"); } static void __connect_signals(tethering_h tethering) { + DBG("+\n"); _retm_if(tethering == NULL, "parameter(tethering) is NULL\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + GDBusConnection *connection = th->client_bus; int i = 0; - for (i = 0; sigs[i].cb != NULL; i++) { - dbus_g_proxy_add_signal(proxy, sigs[i].name, - G_TYPE_STRING, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(proxy, sigs[i].name, - G_CALLBACK(sigs[i].cb), (gpointer)tethering, NULL); + for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) { + sigs[i].sig_id = g_dbus_connection_signal_subscribe(connection, + NULL, TETHERING_SERVICE_INTERFACE, sigs[i].name, + TETHERING_SERVICE_OBJECT_PATH, NULL, G_DBUS_SIGNAL_FLAGS_NONE, + sigs[i].cb, tethering, NULL); } - - dbus_g_object_register_marshaller(marshal_VOID__STRING_UINT_STRING_STRING_STRING_UINT, - G_TYPE_NONE, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_add_signal(proxy, SIGNAL_NAME_DHCP_STATUS, - G_TYPE_STRING, G_TYPE_UINT, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_DHCP_STATUS, - G_CALLBACK(__handle_dhcp), (gpointer)tethering, NULL); - - return; + DBG("-\n"); } static void __disconnect_signals(tethering_h tethering) { + DBG("+\n"); + _retm_if(tethering == NULL, "parameter(tethering) is NULL\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + GDBusConnection *connection = th->client_bus; int i = 0; - for (i = 0; sigs[i].cb != NULL; i++) { - dbus_g_proxy_disconnect_signal(proxy, sigs[i].name, - G_CALLBACK(sigs[i].cb), (gpointer)tethering); + for (i = E_SIGNAL_NET_CLOSED; i < E_SIGNAL_MAX; i++) { + g_dbus_connection_signal_unsubscribe(connection, sigs[i].sig_id); } + DBG("-\n"); +} - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_DHCP_STATUS, - G_CALLBACK(__handle_dhcp), (gpointer)tethering); - return; -} static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len) { @@ -720,11 +1339,14 @@ static bool __get_intf_name(tethering_type_e type, char *buf, unsigned int len) g_strlcpy(buf, TETHERING_BT_IF, len); break; + case TETHERING_TYPE_RESERVED: + g_strlcpy(buf, TETHERING_WIFI_IF, len); + break; + default: ERR("Not supported type : %d\n", type); return false; } - return true; } @@ -745,92 +1367,150 @@ static bool __get_gateway_addr(tethering_type_e type, char *buf, unsigned int le g_strlcpy(buf, TETHERING_BT_GATEWAY, len); break; + case TETHERING_TYPE_RESERVED: + g_strlcpy(buf, TETHERING_WIFI_GATEWAY, len); + break; + default: ERR("Not supported type : %d\n", type); return false; } - return true; } -static void __deinit_cb(DBusGProxy *remoteobj, - GError *error, gpointer user_data) +static int __get_common_ssid(char *ssid, unsigned int size) { - _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + if (ssid == NULL) { + ERR("ssid is null\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } - if (error) { - ERR("DBus fail [%s]\n", error->message); - g_error_free(error); + char *ptr = NULL; + char *ptr_tmp = NULL; + + ptr = vconf_get_str(VCONFKEY_SETAPPL_DEVICE_NAME_STR); + if (ptr == NULL) { + ERR("vconf_get_str is failed\n"); + DBG("-\n"); + return TETHERING_ERROR_OPERATION_FAILED; } - return; + g_strlcpy(ssid, ptr, size); + free(ptr); + + if (!g_utf8_validate(ssid, -1, (const char **)&ptr_tmp)) + *ptr_tmp = '\0'; + + return TETHERING_ERROR_NONE; } -static void __wifi_set_security_type_cb(DBusGProxy *remoteobj, - GError *error, gpointer user_data) +static int __prepare_wifi_settings(tethering_h tethering, _softap_settings_t *set) { - _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + DBG("+\n"); - tethering_h tethering = (tethering_h)user_data; __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + tethering_error_e ret = TETHERING_ERROR_NONE; - if (error) { - ERR("DBus fail [%s]\n", error->message); - g_error_free(error); + if (th == NULL || set == NULL) { + ERR("null parameter\n-\n"); + return TETHERING_ERROR_INVALID_PARAMETER; } - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_SECURITY_TYPE_CHANGED, - G_CALLBACK(__handle_security_type_changed), - (gpointer)tethering, NULL); + if (th->ssid == NULL) { + __get_common_ssid(set->ssid, sizeof(set->ssid)); + } else { + g_strlcpy(set->ssid, th->ssid, sizeof(set->ssid)); + } - return; + ret = __get_security_type(&set->sec_type); + if (ret != TETHERING_ERROR_NONE) { + set->sec_type = th->sec_type; + } + + ret = __get_visible(&set->visibility); + if (ret != TETHERING_ERROR_NONE) { + set->visibility = th->visibility; + } + + if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) { + g_strlcpy(set->key, "", sizeof(set->key)); + } else { + char pass[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; + unsigned int len = 0; + + ret = __get_passphrase(pass, sizeof(pass), &len); + if (ret != TETHERING_ERROR_NONE) { + ERR("getting passphrase failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + g_strlcpy(set->key, pass, sizeof(set->key)); + } + DBG("-\n"); + return TETHERING_ERROR_NONE; } -static void __wifi_set_ssid_visibility_cb(DBusGProxy *remoteobj, - GError *error, gpointer user_data) +static int __prepare_wifi_ap_settings(tethering_h tethering, _softap_settings_t *set) { - _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); + DBG("+\n"); - tethering_h tethering = (tethering_h)user_data; __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - if (error) { - ERR("DBus fail [%s]\n", error->message); - g_error_free(error); + if (th == NULL || set == NULL) { + ERR("null parameter\n"); + return TETHERING_ERROR_INVALID_PARAMETER; } - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, - G_CALLBACK(__handle_ssid_visibility_changed), - (gpointer)tethering, NULL); + g_strlcpy(set->ssid, th->ap_ssid, sizeof(set->ssid)); + set->sec_type = th->sec_type; + set->visibility = th->visibility; - return; + if (set->sec_type == TETHERING_WIFI_SECURITY_TYPE_NONE) { + g_strlcpy(set->key, "", sizeof(set->key)); + } else { + g_strlcpy(set->key, th->passphrase, sizeof(set->key)); + } + DBG("-\n"); + return TETHERING_ERROR_NONE; } -static void __wifi_set_passphrase_cb(DBusGProxy *remoteobj, - GError *error, gpointer user_data) +static bool __check_precondition(tethering_type_e type) { - _retm_if(user_data == NULL, "parameter(user_data) is NULL\n"); - - tethering_h tethering = (tethering_h)user_data; - __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + int dnet_state = 0; + int cellular_state = 0; + int wifi_state = 0; + + // data network through cellular + vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &cellular_state); + if(cellular_state == VCONFKEY_NETWORK_CELLULAR_ON) { + ERR("Data Network can be connected later"); + return TRUE; + } - if (error) { - ERR("DBus fail [%s]\n", error->message); - g_error_free(error); + vconf_get_int(VCONFKEY_DNET_STATE, &dnet_state); + if(dnet_state > VCONFKEY_DNET_OFF) { + ERR("Data Network is connected"); + return TRUE; } - dbus_g_proxy_connect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED, - G_CALLBACK(__handle_passphrase_changed), - (gpointer)tethering, NULL); + // data network through wifi + if(type != TETHERING_TYPE_WIFI) { + vconf_get_int(VCONFKEY_WIFI_STATE, &wifi_state); + if(wifi_state > VCONFKEY_WIFI_UNCONNECTED) { + ERR("Wi-Fi is connected!"); + return TRUE; + } + } - return; + ERR("Network is not available!"); + return FALSE; } /** + * @internal * @brief Creates the handle of tethering. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks The @a tethering must be released tethering_destroy() by you. * @param[out] tethering A handle of a new mobile ap handle on success * @return 0 on success, otherwise a negative error value. @@ -842,77 +1522,86 @@ static void __wifi_set_passphrase_cb(DBusGProxy *remoteobj, */ API int tethering_create(tethering_h *tethering) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); + DBG("+\n"); __tethering_h *th = NULL; GError *error = NULL; - int retry = TETHERING_DBUS_MAX_RETRY_COUNT; + char ssid[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, }; th = (__tethering_h *)malloc(sizeof(__tethering_h)); + _retvm_if(th == NULL, TETHERING_ERROR_OUT_OF_MEMORY, "malloc is failed\n"); memset(th, 0x00, sizeof(__tethering_h)); + th->sec_type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK; + th->visibility = true; + + if (__generate_initial_passphrase(th->passphrase, + sizeof(th->passphrase)) == 0) { + ERR("random passphrase generation failed\n"); + free(th); + return TETHERING_ERROR_OPERATION_FAILED; + } + + if (__get_common_ssid(ssid, sizeof(ssid)) != TETHERING_ERROR_NONE) { + ERR("common ssid get failed\n"); + free(th); + return TETHERING_ERROR_OPERATION_FAILED; + } + + th->ap_ssid = g_strdup(ssid); + if (th->ap_ssid == NULL) { + ERR("g_strdup failed\n"); + free(th); + return TETHERING_ERROR_OPERATION_FAILED; + } -#if !GLIB_CHECK_VERSION(2,35,0) +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); #endif - th->client_bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); + GCancellable *cancellable = g_cancellable_new(); + th->client_bus = g_bus_get_sync(DBUS_BUS_SYSTEM, cancellable, &error); if (error) { ERR("Couldn't connect to the System bus[%s]", error->message); g_error_free(error); + g_cancellable_cancel(cancellable); + g_object_unref(cancellable); + g_free(th->ap_ssid); free(th); return TETHERING_ERROR_OPERATION_FAILED; } + th->cancellable = cancellable; - th->client_bus_proxy = dbus_g_proxy_new_for_name(th->client_bus, - TETHERING_SERVICE_NAME, - TETHERING_SERVICE_OBJECT_PATH, - TETHERING_SERVICE_INTERFACE); + th->client_bus_proxy = g_dbus_proxy_new_sync(th->client_bus, G_DBUS_PROXY_FLAGS_NONE, + NULL, TETHERING_SERVICE_NAME, TETHERING_SERVICE_OBJECT_PATH, + TETHERING_SERVICE_INTERFACE, th->cancellable, &error); if (!th->client_bus_proxy) { - ERR("Couldn't create the proxy object"); - dbus_g_connection_unref(th->client_bus); + ERR("Couldn't create the proxy object because of %s\n", error->message); + g_cancellable_cancel(th->cancellable); + g_object_unref(th->cancellable); + g_object_unref(th->client_bus); + g_free(th->ap_ssid); free(th); return TETHERING_ERROR_OPERATION_FAILED; } - while (retry--) { - org_tizen_tethering_init(th->client_bus_proxy, &error); - if (error != NULL) { - ERR("Couldn't connect to the System bus[%s]", - error->message); - - if (error->code == DBUS_GERROR_SERVICE_UNKNOWN) { - DBG("Tethering is not supported\n"); - g_error_free(error); - error = NULL; - dbus_g_connection_unref(th->client_bus); - free(th); - return TETHERING_ERROR_NOT_SUPPORT_API; - } - - g_error_free(error); - error = NULL; - if (retry == 0) { - dbus_g_connection_unref(th->client_bus); - free(th); - return TETHERING_ERROR_OPERATION_FAILED; - } - } else { - break; - } - } - __connect_signals((tethering_h)th); *tethering = (tethering_h)th; DBG("Tethering Handle : 0x%X\n", th); - + DBG("-\n"); return TETHERING_ERROR_NONE; } /** + * @internal * @brief Destroys the handle of tethering. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @return 0 on success, otherwise a negative error value. * @retval #TETHERING_ERROR_NONE Successful @@ -921,6 +1610,8 @@ API int tethering_create(tethering_h *tethering) */ API int tethering_destroy(tethering_h tethering) { + DBG("+\n"); + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -929,21 +1620,27 @@ API int tethering_destroy(tethering_h tethering) DBG("Tethering Handle : 0x%X\n", th); __disconnect_signals(tethering); - org_tizen_tethering_deinit_async(th->client_bus_proxy, __deinit_cb, - (gpointer)tethering); - if (th->ssid) free(th->ssid); + if (th->ap_ssid) + free(th->ap_ssid); + + g_object_unref(th->cancellable); g_object_unref(th->client_bus_proxy); - dbus_g_connection_unref(th->client_bus); + g_object_unref(th->client_bus); memset(th, 0x00, sizeof(__tethering_h)); free(th); + DBG("-\n"); return TETHERING_ERROR_NONE; } /** + * @internal * @brief Enables the tethering, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @return 0 on success, otherwise negative error value. @@ -955,75 +1652,139 @@ API int tethering_destroy(tethering_h tethering) */ API int tethering_enable(tethering_h tethering, tethering_type_e type) { - DBG("+\n"); + DBG("+ type : %d\n", type); + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_BT_FEATURE); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); + tethering_error_e ret = TETHERING_ERROR_NONE; __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + GDBusProxy *proxy = th->client_bus_proxy; + GDBusConnection *connection = th->client_bus; + + g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_INFINITE); + + if(type != TETHERING_TYPE_RESERVED + && __check_precondition(type) == FALSE) { + DBG("-\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } switch (type) { case TETHERING_TYPE_USB: - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON, - G_CALLBACK(__handle_usb_tether_on), - (gpointer)tethering); - org_tizen_tethering_enable_usb_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_USB_TETHER_ON].sig_id); + + g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering); break; - case TETHERING_TYPE_WIFI: - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON, - G_CALLBACK(__handle_wifi_tether_on), - (gpointer)tethering); - org_tizen_tethering_enable_wifi_tethering_async(proxy, - th->ssid ? th->ssid : "", "", false, - __cfm_cb, (gpointer)tethering); + case TETHERING_TYPE_WIFI: { + _softap_settings_t set = {"", "", 0, false}; + + ret = __prepare_wifi_settings(tethering, &set); + if (ret != TETHERING_ERROR_NONE) { + ERR("softap settings initialization failed\n"); + DBG("-\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id); + + g_dbus_proxy_call(proxy, "enable_wifi_tethering", + g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering); break; + } case TETHERING_TYPE_BT: - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON, - G_CALLBACK(__handle_bt_tether_on), - (gpointer)tethering); - org_tizen_tethering_enable_bt_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_BT_TETHER_ON].sig_id); + + g_dbus_proxy_call(proxy, "enable_bt_tethering", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering); break; - case TETHERING_TYPE_ALL: + case TETHERING_TYPE_RESERVED: { + _softap_settings_t set = {"", "", 0, false}; + + ret = __prepare_wifi_ap_settings(tethering, &set); + if (ret != TETHERING_ERROR_NONE) { + ERR("softap settings initialization failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_AP_ON].sig_id); + + g_dbus_proxy_call(proxy, "enable_wifi_ap", + g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, (GAsyncReadyCallback) __wifi_ap_enabled_cfm_cb, (gpointer)tethering); + break; + } + case TETHERING_TYPE_ALL: { + _softap_settings_t set = {"", "", 0, false}; + + ret = __prepare_wifi_settings(tethering, &set); + if (ret != TETHERING_ERROR_NONE) { + ERR("softap settings initialization failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + /* TETHERING_TYPE_USB */ - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_ON, - G_CALLBACK(__handle_usb_tether_on), - (gpointer)tethering); - org_tizen_tethering_enable_usb_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_USB_TETHER_ON].sig_id); + + g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __usb_enabled_cfm_cb, (gpointer)tethering); /* TETHERING_TYPE_WIFI */ - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_ON, - G_CALLBACK(__handle_wifi_tether_on), - (gpointer)tethering); - org_tizen_tethering_enable_wifi_tethering_async(proxy, - th->ssid ? th->ssid : "", "", false, - __cfm_cb, (gpointer)tethering); + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_TETHER_ON].sig_id); + + g_dbus_proxy_call(proxy, "enable_wifi_tethering", + g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __wifi_enabled_cfm_cb, (gpointer)tethering); /* TETHERING_TYPE_BT */ - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_ON, - G_CALLBACK(__handle_bt_tether_on), - (gpointer)tethering); - org_tizen_tethering_enable_bt_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); - break; + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_BT_TETHER_ON].sig_id); + g_dbus_proxy_call(proxy, "enable_usb_tethering", NULL, + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __bt_enabled_cfm_cb, (gpointer)tethering); + break; + } default: ERR("Unknown type : %d\n", type); + + g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT); + + DBG("-\n"); return TETHERING_ERROR_INVALID_PARAMETER; } + g_dbus_proxy_set_default_timeout(proxy, DBUS_TIMEOUT_USE_DEFAULT); + DBG("-\n"); return TETHERING_ERROR_NONE; } /** + * @internal * @brief Disables the tethering, asynchronously. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @return 0 on success, otherwise negative error value. @@ -1035,67 +1796,96 @@ API int tethering_enable(tethering_h tethering, tethering_type_e type) */ API int tethering_disable(tethering_h tethering, tethering_type_e type) { + DBG("+ type : %d\n", type); + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + GDBusProxy *proxy = th->client_bus_proxy; + GDBusConnection *connection = th->client_bus; switch (type) { case TETHERING_TYPE_USB: - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF, - G_CALLBACK(__handle_usb_tether_off), - (gpointer)tethering); - org_tizen_tethering_disable_usb_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_USB_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_usb_tethering", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); + break; case TETHERING_TYPE_WIFI: - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF, - G_CALLBACK(__handle_wifi_tether_off), - (gpointer)tethering); - org_tizen_tethering_disable_wifi_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); - break; + + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_wifi_tethering", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); + break; + case TETHERING_TYPE_BT: - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF, - G_CALLBACK(__handle_bt_tether_off), - (gpointer)tethering); - org_tizen_tethering_disable_bt_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); + + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_BT_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_bt_tethering", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); + break; + + case TETHERING_TYPE_RESERVED: + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_AP_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_wifi_ap", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); break; case TETHERING_TYPE_ALL: - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_USB_TETHER_OFF, - G_CALLBACK(__handle_usb_tether_off), - (gpointer)tethering); - org_tizen_tethering_disable_usb_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); - - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_WIFI_TETHER_OFF, - G_CALLBACK(__handle_wifi_tether_off), - (gpointer)tethering); - org_tizen_tethering_disable_wifi_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); - - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_BT_TETHER_OFF, - G_CALLBACK(__handle_bt_tether_off), - (gpointer)tethering); - org_tizen_tethering_disable_bt_tethering_async(proxy, - __cfm_cb, (gpointer)tethering); + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_USB_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_usb_tethering", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); + + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_WIFI_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_wifi_tethering", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); + + g_dbus_connection_signal_unsubscribe(connection, + sigs[E_SIGNAL_BT_TETHER_OFF].sig_id); + + g_dbus_proxy_call(proxy, "disable_bt_tethering", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __disabled_cfm_cb, (gpointer)tethering); break; default : ERR("Not supported tethering type [%d]\n", type); + DBG("-\n"); return TETHERING_ERROR_INVALID_PARAMETER; - break; } - + DBG("-\n"); return TETHERING_ERROR_NONE; } /** + * @internal * @brief Checks whetehr the tethering is enabled or not. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @return @c true if tethering is enabled, \n @c false if tethering is disabled. @@ -1105,6 +1895,8 @@ API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type) int is_on = 0; int vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_NONE; + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + if (vconf_get_int(VCONFKEY_MOBILE_HOTSPOT_MODE, &is_on) != 0) { return FALSE; } @@ -1122,16 +1914,23 @@ API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type) vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_BT; break; + case TETHERING_TYPE_RESERVED: + vconf_type = VCONFKEY_MOBILE_HOTSPOT_MODE_WIFI_AP; + break; + default: ERR("Not supported type : %d\n", type); break; } - return is_on & vconf_type ? true : false; } /** + * @internal * @brief Gets the MAC address of local device as "FC:A1:3E:D6:B1:B1". + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks @a mac_address must be released with free() by you. * @param[in] tethering The handle of tethering * @param[in] type The type of tethering @@ -1148,13 +1947,17 @@ API bool tethering_is_enabled(tethering_h tethering, tethering_type_e type) */ API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, char **mac_address) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + + _retvm_if(tethering_is_enabled(tethering, type) == false, + TETHERING_ERROR_NOT_ENABLED, + "tethering type[%d] is not enabled\n", type); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(mac_address) is NULL\n"); - _retvm_if(tethering_is_enabled(tethering, type) == false, - TETHERING_ERROR_NOT_ENABLED, - "tethering type[%d] is not enabled\n", type); struct ifreq ifr; int s = 0; @@ -1191,7 +1994,11 @@ API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, } /** + * @internal * @brief Gets the name of network interface. For example, usb0. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks @a interface_name must be released with free() by you. * @param[in] tethering The handle of tethering * @param[in] type The type of tethering @@ -1208,13 +2015,17 @@ API int tethering_get_mac_address(tethering_h tethering, tethering_type_e type, */ API int tethering_get_network_interface_name(tethering_h tethering, tethering_type_e type, char **interface_name) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + + _retvm_if(tethering_is_enabled(tethering, type) == false, + TETHERING_ERROR_NOT_ENABLED, + "tethering type[%d] is not enabled\n", type); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(interface_name == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(interface_name) is NULL\n"); - _retvm_if(tethering_is_enabled(tethering, type) == false, - TETHERING_ERROR_NOT_ENABLED, - "tethering type[%d] is not enabled\n", type); char intf[TETHERING_STR_INFO_LEN] = {0, }; @@ -1229,7 +2040,11 @@ API int tethering_get_network_interface_name(tethering_h tethering, tethering_ty } /** + * @internal * @brief Gets the local IP address. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks @a ip_address must be released with free() by you. * @param[in] tethering The handle of tethering * @param[in] type The type of tethering @@ -1247,13 +2062,18 @@ API int tethering_get_network_interface_name(tethering_h tethering, tethering_ty */ API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **ip_address) { + + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + + _retvm_if(tethering_is_enabled(tethering, type) == false, + TETHERING_ERROR_NOT_ENABLED, + "tethering type[%d] is not enabled\n", type); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(ip_address) is NULL\n"); - _retvm_if(tethering_is_enabled(tethering, type) == false, - TETHERING_ERROR_NOT_ENABLED, - "tethering type[%d] is not enabled\n", type); struct ifreq ifr; int s = 0; @@ -1282,7 +2102,11 @@ API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, t } /** + * @internal * @brief Gets the Gateway address. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks @a gateway_address must be released with free() by you. * @param[in] tethering The handle of tethering * @param[in] type The type of tethering @@ -1300,13 +2124,18 @@ API int tethering_get_ip_address(tethering_h tethering, tethering_type_e type, t */ API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **gateway_address) { + + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + + _retvm_if(tethering_is_enabled(tethering, type) == false, + TETHERING_ERROR_NOT_ENABLED, + "tethering type[%d] is not enabled\n", type); _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(gateway_address == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(gateway_address) is NULL\n"); - _retvm_if(tethering_is_enabled(tethering, type) == false, - TETHERING_ERROR_NOT_ENABLED, - "tethering type[%d] is not enabled\n", type); char gateway_buf[TETHERING_STR_INFO_LEN] = {0, }; @@ -1320,7 +2149,11 @@ API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e ty } /** + * @internal * @brief Gets the Subnet Mask. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks @a subnet_mask must be released with free() by you. * @param[in] tethering The handle of tethering * @param[in] type The type of tethering @@ -1338,11 +2171,15 @@ API int tethering_get_gateway_address(tethering_h tethering, tethering_type_e ty */ API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, tethering_address_family_e address_family, char **subnet_mask) { - _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, - "parameter(tethering) is NULL\n"); + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering_is_enabled(tethering, type) == false, TETHERING_ERROR_NOT_ENABLED, "tethering is not enabled\n"); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); _retvm_if(subnet_mask == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(subnet_mask) is NULL\n"); @@ -1354,7 +2191,11 @@ API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, } /** + * @internal * @brief Gets the data usage. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[out] usage The data usage * @return 0 on success, otherwise negative error value. @@ -1368,6 +2209,8 @@ API int tethering_get_subnet_mask(tethering_h tethering, tethering_type_e type, */ API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb callback, void *user_data) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1377,19 +2220,24 @@ API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb "tethering is not enabled\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; + GDBusProxy *proxy = th->client_bus_proxy; th->data_usage_cb = callback; th->data_usage_user_data = user_data; - org_tizen_tethering_get_data_packet_usage_async(proxy, - __get_data_usage_cb, (gpointer)th); + g_dbus_proxy_call(proxy, "get_data_packet_usage", + NULL, G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __get_data_usage_cb, (gpointer)tethering); return TETHERING_ERROR_NONE; } /** - * @brief Gets the client which is connected by USB tethering. + * @internal + * @brief Gets the client which is connected by tethering "type". + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @param[in] callback The callback function to invoke @@ -1404,6 +2252,11 @@ API int tethering_get_data_usage(tethering_h tethering, tethering_data_usage_cb */ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_type_e type, tethering_connected_client_cb callback, void *user_data) { + DBG("+\n"); + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1412,125 +2265,104 @@ API int tethering_foreach_connected_clients(tethering_h tethering, tethering_typ TETHERING_ERROR_NOT_ENABLED, "tethering is not enabled\n"); + mobile_ap_type_e interface; __tethering_h *th = (__tethering_h *)tethering; __tethering_client_h client = {0, }; - - guint event = 0; - GPtrArray *array = NULL; - GValue value = {0, {{0}}}; - GError *error = NULL; - int i = 0; - int no_of_client = 0; - guint interface = 0; gchar *ip = NULL; gchar *mac = NULL; gchar *hostname = NULL; guint timestamp = 0; - - org_tizen_tethering_get_station_info(th->client_bus_proxy, &event, - &array, &error); - if (error != NULL) { - ERR("DBus fail : %s\n", error->message); - g_error_free(error); - return TETHERING_ERROR_OPERATION_FAILED; + GError *error = NULL; + GVariant *result = NULL; + GVariantIter *outer_iter = NULL; + GVariantIter *inner_iter = NULL; + GVariant *station = NULL; + GVariant *value = NULL; + gchar *key = NULL; + + result = g_dbus_proxy_call_sync(th->client_bus_proxy, "get_station_info", + NULL, G_DBUS_CALL_FLAGS_NONE, + -1, th->cancellable, &error); + if (error) { + ERR("g_dbus_proxy_call_sync is failed and error is %s\n", error->message); } - - g_value_init(&value, DBUS_STRUCT_STATIONS); - no_of_client = array->len; - for (i = 0; i < no_of_client; i++) { - g_value_set_boxed(&value, g_ptr_array_index(array, i)); - - dbus_g_type_struct_get(&value, 0, &interface, 1, &ip, - 2, &mac, 3, &hostname, 4, ×tamp, G_MAXUINT); - - if (interface == MOBILE_AP_TYPE_USB) - client.interface = TETHERING_TYPE_USB; - else if (interface == MOBILE_AP_TYPE_WIFI) - client.interface = TETHERING_TYPE_WIFI; - else if (interface == MOBILE_AP_TYPE_BT) - client.interface = TETHERING_TYPE_BT; - - if (client.interface != type && TETHERING_TYPE_ALL != type) - continue; - - g_strlcpy(client.ip, ip, sizeof(client.ip)); - g_strlcpy(client.mac, mac, sizeof(client.mac)); - g_strlcpy(client.hostname, hostname, sizeof(client.hostname)); - client.tm = (time_t)timestamp; - + g_variant_get(result, "(a(a{sv}))", &outer_iter); + while (g_variant_iter_loop(outer_iter, "(@a{sv})", &station)) { + g_variant_get(station, "a{sv}", &inner_iter); + while (g_variant_iter_loop(inner_iter, "{sv}", &key, &value)) { + if (g_strcmp0(key, "Type") == 0) { + interface = g_variant_get_int32(value); + if (interface == MOBILE_AP_TYPE_USB) + client.interface = TETHERING_TYPE_USB; + else if (interface == MOBILE_AP_TYPE_WIFI) + client.interface = TETHERING_TYPE_WIFI; + else if (interface == MOBILE_AP_TYPE_BT) + client.interface = TETHERING_TYPE_BT; + else if (interface == MOBILE_AP_TYPE_WIFI_AP) + client.interface = TETHERING_TYPE_RESERVED; + else { + ERR("Invalid interface\n"); + g_free(key); + g_variant_unref(value); + break; + } + DBG("interface is %d\n", client.interface); + if (client.interface != type && (TETHERING_TYPE_ALL != type && + client.interface != TETHERING_TYPE_RESERVED)) { + g_free(key); + g_variant_unref(value); + break; + } + } else if (g_strcmp0(key, "IP") == 0) { + g_variant_get(value, "s", &ip); + SDBG("ip is %s\n", ip); + g_strlcpy(client.ip, ip, sizeof(client.ip)); + } else if (g_strcmp0(key, "MAC") == 0) { + g_variant_get(value, "s", &mac); + SDBG("mac is %s\n", mac); + g_strlcpy(client.mac, mac, sizeof(client.mac)); + } else if (g_strcmp0(key, "Name") == 0) { + g_variant_get(value, "s", &hostname); + SDBG("hsotname is %s\n", hostname); + if (hostname) { + client.hostname = g_strdup(hostname); + } + } else if (g_strcmp0(key, "Time") == 0) { + timestamp = g_variant_get_int32(value); + DBG("timestamp is %d\n", timestamp); + client.tm = (time_t)timestamp; + } else { + ERR("Key %s not required\n", key); + } + } + g_free(hostname); + g_free(ip); + g_free(mac); + g_variant_iter_free(inner_iter); if (callback((tethering_client_h)&client, user_data) == false) { DBG("iteration is stopped\n"); - return TETHERING_ERROR_NONE; + g_free(client.hostname); + g_variant_iter_free(outer_iter); + g_variant_unref(station); + g_variant_unref(result); + DBG("-\n"); + return TETHERING_ERROR_OPERATION_FAILED; } + g_free(client.hostname); } - - if (array->len > 0) - g_ptr_array_free(array, TRUE); - - return TETHERING_ERROR_NONE; -} - -/** - * @brief Set the ip forward status - * @param[in] tethering The handle of tethering - * @param[in] status The ip forward status: (@c true = enable, @c false = disable) - * @retval #TETHERING_ERROR_NONE Successful - * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter - * @see tethering_get_ip_forward_status() - */ -API int tethering_set_ip_forward_status(tethering_h tethering, bool status) -{ - _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, - "parameter(tethering) is NULL\n"); - - __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - - org_tizen_tethering_set_ip_forward_status_async(proxy, status, - __ip_forward_cb, (gpointer)tethering); - - return TETHERING_ERROR_NONE; -} - -/** - * @brief Get the ip forward status - * @param[in] tethering The handle of tethering - * @param[out] status The ip forward status: (@c true = enable, @c false = disable) - * @retval #TETHERING_ERROR_NONE Successful - * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed - * @see tethering_set_ip_forward_status() - */ -API int tethering_get_ip_forward_status(tethering_h tethering, bool *status) -{ - _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, - "parameter(tethering) is NULL\n"); - _retvm_if(status == NULL, TETHERING_ERROR_INVALID_PARAMETER, - "parameter(status) is NULL\n"); - - __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - GError *error = NULL; - int forward_mode = 0; - - org_tizen_tethering_get_ip_forward_status(proxy, &forward_mode, &error); - if (error != NULL) { - ERR("DBus fail : %s\n", error->message); - g_error_free(error); - return TETHERING_ERROR_OPERATION_FAILED; - } - - if (forward_mode == 1) - *status = true; - else - *status = false; - + g_variant_iter_free(outer_iter); + g_variant_unref(station); + g_variant_unref(result); + DBG("-\n"); return TETHERING_ERROR_NONE; } - /** + * @internal * @brief Registers the callback function called when tethering is enabled. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @param[in] callback The callback function to invoke @@ -1541,6 +2373,10 @@ API int tethering_get_ip_forward_status(tethering_h tethering, bool *status) */ API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, tethering_enabled_cb callback, void *user_data) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1566,7 +2402,11 @@ API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, t } /** + * @internal * @brief Unregisters the callback function called when tethering is disabled. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @retval #TETHERING_ERROR_NONE Successful @@ -1575,6 +2415,10 @@ API int tethering_set_enabled_cb(tethering_h tethering, tethering_type_e type, t */ API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -1598,7 +2442,11 @@ API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type) } /** + * @internal * @brief Registers the callback function called when tethering is disabled. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @param[in] callback The callback function to invoke @@ -1609,6 +2457,10 @@ API int tethering_unset_enabled_cb(tethering_h tethering, tethering_type_e type) */ API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, tethering_disabled_cb callback, void *user_data) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1634,7 +2486,11 @@ API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, } /** + * @internal * @brief Unregisters the callback function called when tethering is disabled. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @retval #TETHERING_ERROR_NONE Successful @@ -1643,6 +2499,10 @@ API int tethering_set_disabled_cb(tethering_h tethering, tethering_type_e type, */ API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -1666,7 +2526,11 @@ API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type } /** + * @internal * @brief Registers the callback function called when the state of connection is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @param[in] callback The callback function to invoke @@ -1677,6 +2541,10 @@ API int tethering_unset_disabled_cb(tethering_h tethering, tethering_type_e type */ API int tethering_set_connection_state_changed_cb(tethering_h tethering, tethering_type_e type, tethering_connection_state_changed_cb callback, void *user_data) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1702,7 +2570,11 @@ API int tethering_set_connection_state_changed_cb(tethering_h tethering, tetheri } /** + * @internal * @brief Unregisters the callback function called when the state of connection is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @retval #TETHERING_ERROR_NONE Successful @@ -1711,6 +2583,10 @@ API int tethering_set_connection_state_changed_cb(tethering_h tethering, tetheri */ API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethering_type_e type) { + if (type == TETHERING_TYPE_USB) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_USB_FEATURE); + else if (type == TETHERING_TYPE_WIFI) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + else if (type == TETHERING_TYPE_BT) CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_BT_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -1734,7 +2610,11 @@ API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethe } /** + * @internal * @brief Registers the callback function called when the security type of Wi-Fi tethering is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function @@ -1744,6 +2624,8 @@ API int tethering_unset_connection_state_changed_cb(tethering_h tethering, tethe */ API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethering_wifi_security_type_changed_cb callback, void *user_data) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1759,7 +2641,11 @@ API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethe } /** + * @internal * @brief Unregisters the callback function called when the security type of Wi-Fi tethering is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] type The type of tethering * @retval #TETHERING_ERROR_NONE Successful @@ -1768,6 +2654,8 @@ API int tethering_wifi_set_security_type_changed_cb(tethering_h tethering, tethe */ API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -1780,7 +2668,11 @@ API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering) } /** + * @internal * @brief Registers the callback function called when the visibility of SSID is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function @@ -1790,6 +2682,8 @@ API int tethering_wifi_unset_security_type_changed_cb(tethering_h tethering) */ API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tethering_wifi_ssid_visibility_changed_cb callback, void *user_data) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1804,7 +2698,11 @@ API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tet } /** + * @internal * @brief Unregisters the callback function called when the visibility of SSID is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @retval #TETHERING_ERROR_NONE Successful * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter @@ -1812,6 +2710,8 @@ API int tethering_wifi_set_ssid_visibility_changed_cb(tethering_h tethering, tet */ API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -1824,7 +2724,11 @@ API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering) } /** + * @internal * @brief Registers the callback function called when the passphrase of Wi-Fi tethering is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function @@ -1834,6 +2738,8 @@ API int tethering_wifi_unset_ssid_visibility_changed_cb(tethering_h tethering) */ API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tethering_wifi_passphrase_changed_cb callback, void *user_data) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -1848,7 +2754,11 @@ API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tetherin } /** + * @internal * @brief Unregisters the callback function called when the passphrase of Wi-Fi tethering is changed. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @retval #TETHERING_ERROR_NONE Successful * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter @@ -1856,6 +2766,8 @@ API int tethering_wifi_set_passphrase_changed_cb(tethering_h tethering, tetherin */ API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); @@ -1868,7 +2780,11 @@ API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering) } /** + * @internal * @brief Sets the security type of Wi-Fi tethering. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks This change is applied next time Wi-Fi tethering is enabled * @param[in] tethering The handle of tethering * @param[in] type The security type @@ -1880,36 +2796,32 @@ API int tethering_wifi_unset_passphrase_changed_cb(tethering_h tethering) */ API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); - DBG("+\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - char *type_str = NULL; - - if (type == TETHERING_WIFI_SECURITY_TYPE_NONE) { - type_str = TETHERING_WIFI_SECURITY_TYPE_OPEN_STR; - } else if (type == TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK) { - type_str = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR; - } else { - ERR("Unsupported type\n"); - return TETHERING_ERROR_INVALID_PARAMETER; - } - - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SECURITY_TYPE_CHANGED, - G_CALLBACK(__handle_security_type_changed), - (gpointer)tethering); + tethering_error_e ret = TETHERING_ERROR_NONE; - org_tizen_tethering_set_wifi_tethering_security_type_async(proxy, type_str, - __wifi_set_security_type_cb, (gpointer)tethering); + ret = __set_security_type(type); + if (ret == TETHERING_ERROR_NONE) { - DBG("-\n"); - return TETHERING_ERROR_NONE; + __send_dbus_signal(th->client_bus, + SIGNAL_NAME_SECURITY_TYPE_CHANGED, + type == TETHERING_WIFI_SECURITY_TYPE_NONE ? + TETHERING_WIFI_SECURITY_TYPE_OPEN_STR : + TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR); + } + return ret; } /** + * @internal * @brief Gets the security type of Wi-Fi tethering. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @param[in] tethering The handle of tethering * @param[out] type The security type * @return 0 on success, otherwise negative error value. @@ -1920,46 +2832,20 @@ API int tethering_wifi_set_security_type(tethering_h tethering, tethering_wifi_s */ API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type) { - _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, - "parameter(tethering) is NULL\n"); + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(type) is NULL\n"); - DBG("+\n"); - __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - GError *error = NULL; - char *type_str = NULL; - - org_tizen_tethering_get_wifi_tethering_security_type(proxy, &type_str, &error); - if (error != NULL) { - ERR("DBus fail : %s\n", error->message); - g_error_free(error); - return TETHERING_ERROR_OPERATION_FAILED; - } - - if (type_str == NULL) - return TETHERING_ERROR_OPERATION_FAILED; - - DBG("security type : %s\n", type_str); - if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_OPEN_STR) == 0) - *type = TETHERING_WIFI_SECURITY_TYPE_NONE; - else if (strcmp(type_str, TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK_STR) == 0) - *type = TETHERING_WIFI_SECURITY_TYPE_WPA2_PSK; - else { - ERR("Unknown security type : %s\n", type_str); - g_free(type_str); - return TETHERING_ERROR_OPERATION_FAILED; - } - - g_free(type_str); - - DBG("-\n"); - return TETHERING_ERROR_NONE; + return __get_security_type(type); } /** + * @internal * @brief Sets the SSID (service set identifier). + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @details If SSID is not set, Device name is used as SSID * @remarks This change is applied next time Wi-Fi tethering is enabled with same @a tethering handle * @param[in] tethering The handle of tethering @@ -1971,14 +2857,16 @@ API int tethering_wifi_get_security_type(tethering_h tethering, tethering_wifi_s */ API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(ssid) is NULL\n"); __tethering_h *th = (__tethering_h *)tethering; - char *p_ssid; - int ssid_len; + char *p_ssid = NULL; + int ssid_len = 0; ssid_len = strlen(ssid); if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) { @@ -1998,7 +2886,11 @@ API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid) } /** + * @internal * @brief Gets the SSID (service set identifier). + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks @a ssid must be released with free() by you. * @param[in] tethering The handle of tethering * @param[out] ssid The SSID @@ -2010,6 +2902,8 @@ API int tethering_wifi_set_ssid(tethering_h tethering, const char *ssid) */ API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -2017,46 +2911,41 @@ API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid) DBG("+\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - GError *error = NULL; - char *ssid_buf = NULL; - - if (tethering_is_enabled(NULL, TETHERING_TYPE_WIFI) == false && - th->ssid != NULL) { - DBG("Private SSID is set : %s\n", th->ssid); - *ssid = strdup(th->ssid); - if (*ssid == NULL) { - ERR("Memory allocation failed\n"); - return TETHERING_ERROR_OUT_OF_MEMORY; - } - DBG("-\n"); - return TETHERING_ERROR_NONE; - } + char val[TETHERING_WIFI_SSID_MAX_LEN + 1] = {0, }; - org_tizen_tethering_get_wifi_tethering_ssid(proxy, &ssid_buf, &error); - if (error != NULL) { - ERR("dbus fail : %s\n", error->message); - g_error_free(error); - return TETHERING_ERROR_OPERATION_FAILED; + if (!tethering_is_enabled(NULL, TETHERING_TYPE_WIFI)) { + if (th->ssid != NULL) { + DBG("Private SSID is set\n"); + *ssid = strdup(th->ssid); + } else { + if (__get_ssid_from_vconf(VCONFKEY_SETAPPL_DEVICE_NAME_STR, + val, sizeof(val)) == false) { + return TETHERING_ERROR_OPERATION_FAILED; + } + *ssid = strdup(val); + } + } else { + if (__get_ssid_from_vconf(VCONFKEY_MOBILE_HOTSPOT_SSID, + val, sizeof(val)) == false) { + return TETHERING_ERROR_OPERATION_FAILED; + } + *ssid = strdup(val); } - if (ssid_buf == NULL) - return TETHERING_ERROR_OPERATION_FAILED; - - *ssid = strdup(ssid_buf); if (*ssid == NULL) { - ERR("Memory allocation failed\n"); + ERR("strdup is failed\n"); return TETHERING_ERROR_OUT_OF_MEMORY; } - g_free(ssid_buf); - - DBG("-\n"); return TETHERING_ERROR_NONE; } /** + * @internal * @brief Sets the visibility of SSID(service set identifier). + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device. * @remarks This change is applied next time Wi-Fi tethering is enabled * @param[in] tethering The handle of tethering @@ -2069,32 +2958,31 @@ API int tethering_wifi_get_ssid(tethering_h tethering, char **ssid) */ API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); - DBG("+\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - int hide_mode = 0; - - if (visible) - hide_mode = VCONFKEY_MOBILE_AP_HIDE_OFF; - else - hide_mode = VCONFKEY_MOBILE_AP_HIDE_ON; - - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_SSID_VISIBILITY_CHANGED, - G_CALLBACK(__handle_ssid_visibility_changed), - (gpointer)tethering); + tethering_error_e ret = TETHERING_ERROR_NONE; - org_tizen_tethering_set_wifi_tethering_hide_mode_async(proxy, hide_mode, - __wifi_set_ssid_visibility_cb, (gpointer)tethering); + ret = __set_visible(visible); + if (ret == TETHERING_ERROR_NONE) { - DBG("-\n"); - return TETHERING_ERROR_NONE; + __send_dbus_signal(th->client_bus, + SIGNAL_NAME_SSID_VISIBILITY_CHANGED, + visible ? SIGNAL_MSG_SSID_VISIBLE : + SIGNAL_MSG_SSID_HIDE); + } + return ret; } /** + * @internal * @brief Gets the visibility of SSID(service set identifier). + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device. * @param[in] tethering The handle of tethering * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible) @@ -2106,36 +2994,20 @@ API int tethering_wifi_set_ssid_visibility(tethering_h tethering, bool visible) */ API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible) { - _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, - "parameter(tethering) is NULL\n"); + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(visible) is NULL\n"); - DBG("+\n"); - - __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - GError *error = NULL; - int hide_mode = 0; - org_tizen_tethering_get_wifi_tethering_hide_mode(proxy, &hide_mode, &error); - if (error != NULL) { - ERR("dbus fail : %s\n", error->message); - g_error_free(error); - return TETHERING_ERROR_OPERATION_FAILED; - } - DBG("hide mode : %d\n", hide_mode); - - if (hide_mode == VCONFKEY_MOBILE_AP_HIDE_OFF) - *visible = true; - else - *visible = false; - - DBG("-\n"); - return TETHERING_ERROR_NONE; + return __get_visible(visible); } /** + * @internal * @brief Sets the passphrase. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks This change is applied next time Wi-Fi tethering is enabled * @param[in] tethering The handle of tethering * @param[in] passphrase The passphrase @@ -2147,15 +3019,19 @@ API int tethering_wifi_get_ssid_visibility(tethering_h tethering, bool *visible) */ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphrase) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(passphrase) is NULL\n"); - DBG("+\n"); __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - int passphrase_len; + int passphrase_len = 0; + + char old_passphrase[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; + unsigned int old_len = 0; + tethering_error_e ret = TETHERING_ERROR_NONE; passphrase_len = strlen(passphrase); if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN || @@ -2164,20 +3040,26 @@ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphr return TETHERING_ERROR_INVALID_PARAMETER; } - dbus_g_proxy_disconnect_signal(proxy, SIGNAL_NAME_PASSPHRASE_CHANGED, - G_CALLBACK(__handle_passphrase_changed), - (gpointer)tethering); - - org_tizen_tethering_set_wifi_tethering_passphrase_async(proxy, - passphrase, passphrase_len, - __wifi_set_passphrase_cb, (gpointer)tethering); + ret = __get_passphrase(old_passphrase, sizeof(old_passphrase), &old_len); + if (ret == TETHERING_ERROR_NONE && old_len == passphrase_len && + !g_strcmp0(old_passphrase, passphrase)) { + return TETHERING_ERROR_NONE; + } - DBG("-\n"); - return TETHERING_ERROR_NONE; + ret = __set_passphrase(passphrase, passphrase_len); + if (ret == TETHERING_ERROR_NONE) { + __send_dbus_signal(th->client_bus, + SIGNAL_NAME_PASSPHRASE_CHANGED, NULL); + } + return ret; } /** + * @internal * @brief Gets the passphrase. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin * @remarks @a passphrase must be released with free() by you. * @param[in] tethering The handle of tethering * @param[out] passphrase The passphrase @@ -2190,37 +3072,403 @@ API int tethering_wifi_set_passphrase(tethering_h tethering, const char *passphr */ API int tethering_wifi_get_passphrase(tethering_h tethering, char **passphrase) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(tethering) is NULL\n"); _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER, "parameter(passphrase) is NULL\n"); - DBG("+\n"); - __tethering_h *th = (__tethering_h *)tethering; - DBusGProxy *proxy = th->client_bus_proxy; - GError *error = NULL; - char *passphrase_buf = NULL; + char passphrase_buf[TETHERING_WIFI_KEY_MAX_LEN + 1] = {0, }; unsigned int len = 0; + tethering_error_e ret = TETHERING_ERROR_NONE; - org_tizen_tethering_get_wifi_tethering_passphrase(proxy, - &passphrase_buf, &len, &error); - if (error != NULL) { - ERR("dbus fail : %s\n", error->message); - g_error_free(error); + ret = __get_passphrase(passphrase_buf, sizeof(passphrase_buf), &len); + if (ret != TETHERING_ERROR_NONE) + return ret; + + *passphrase = strdup(passphrase_buf); + if (*passphrase == NULL) { + ERR("strdup is failed\n"); + return TETHERING_ERROR_OUT_OF_MEMORY; + } + + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility). + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @remarks Connected devices via Wi-Fi tethering or MobileAP will be disconnected when the settings are reloaded + * @param[in] tethering The handle of tethering + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed + */ +API int tethering_wifi_reload_settings(tethering_h tethering, tethering_wifi_settings_reloaded_cb callback, void *user_data) + +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(callback) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + _softap_settings_t set = {"", "", 0, false}; + GDBusProxy *proxy = th->client_bus_proxy; + int ret = 0; + + DBG("+\n"); + + if (th->settings_reloaded_cb) { + ERR("Operation in progress\n"); return TETHERING_ERROR_OPERATION_FAILED; } - if (passphrase_buf == NULL) + ret = __prepare_wifi_settings(tethering, &set); + if (ret != TETHERING_ERROR_NONE) { + ERR("softap settings initialization failed\n"); return TETHERING_ERROR_OPERATION_FAILED; + } - *passphrase = strdup(passphrase_buf); + th->settings_reloaded_cb = callback; + th->settings_reloaded_user_data = user_data; + + g_dbus_proxy_call(proxy, "reload_wifi_settings", + g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __settings_reloaded_cb, (gpointer)tethering); + + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Sets the security type of Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If security type is not set, WPA2_PSK is used + * @param[in] tethering The handle of tethering + * @param[in] type The security type + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed + * @see tethering_wifi_ap_get_security_type() + */ +API int tethering_wifi_ap_set_security_type(tethering_h tethering, tethering_wifi_security_type_e type) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + th->sec_type = type; + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Gets the security type of Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If security type is not set, WPA2_PSK is used + * @param[in] tethering The handle of tethering + * @param[out] type The security type + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @see tethering_wifi_ap_set_security_type() + */ +API int tethering_wifi_ap_get_security_type(tethering_h tethering, tethering_wifi_security_type_e *type) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(type) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + + *type = th->sec_type; + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Sets the SSID (service set identifier) for Wi-Fi AP. The SSID cannot exceed 32 bytes. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If SSID is not set, Device name is used as SSID + * @param[in] tethering The handle of tethering + * @param[in] ssid The SSID + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory + */ +API int tethering_wifi_ap_set_ssid(tethering_h tethering, const char *ssid) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(ssid) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + char *p_ssid = NULL; + int ssid_len = 0; + + ssid_len = strlen(ssid); + if (ssid_len > TETHERING_WIFI_SSID_MAX_LEN) { + ERR("parameter(ssid) is too long"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + + p_ssid = strdup(ssid); + if (p_ssid == NULL) { + ERR("strdup failed\n"); + return TETHERING_ERROR_OUT_OF_MEMORY; + } + + if (th->ap_ssid) + g_free(th->ap_ssid); + th->ap_ssid = p_ssid; + + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Gets the SSID (service set identifier) for Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If SSID is not set, Device name is used as SSID + * @remarks @a ssid must be released with free() by you. + * @param[in] tethering The handle of tethering + * @param[out] ssid The SSID + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory + */ +API int tethering_wifi_ap_get_ssid(tethering_h tethering, char **ssid) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(ssid == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(ssid) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + + *ssid = g_strdup(th->ap_ssid); + if (*ssid == NULL) { + ERR("strdup failed\n"); + return TETHERING_ERROR_OUT_OF_MEMORY; + } + + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Sets the visibility of SSID(service set identifier) for Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If you set the visibility invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device. + * @details by default visibility is set to true. + * @remarks This change is applied next time Wi-Fi tethering is enabled + * @param[in] tethering The handle of tethering + * @param[in] visible The visibility of SSID: (@c true = visible, @c false = invisible) + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed + * @see tethering_wifi_ap_get_ssid_visibility() + */ +API int tethering_wifi_ap_set_ssid_visibility(tethering_h tethering, bool visible) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + th->visibility = visible; + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Gets the visibility of SSID(service set identifier) for Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If the visibility is set invisible, then the SSID of this device is hidden. So, Wi-Fi scan can't find your device. + * @details by default visibility is set to true. + * @param[in] tethering The handle of tethering + * @param[out] visible The visibility of SSID: (@c true = visible, @c false = invisible) + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @see tethering_wifi_ap_set_ssid_visibility() + */ +API int tethering_wifi_ap_get_ssid_visibility(tethering_h tethering, bool *visible) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(visible == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(visible) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + + *visible = th->visibility; + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Sets the passphrase for Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If the passphrase is not set, random string of 8 alphabets will be used. + * @param[in] tethering The handle of tethering + * @param[in] passphrase The passphrase + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @see tethering_wifi_ap_get_passphrase() + */ +API int tethering_wifi_ap_set_passphrase(tethering_h tethering, const char *passphrase) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(passphrase) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + int passphrase_len = 0; + + passphrase_len = strlen(passphrase); + + if (passphrase_len < TETHERING_WIFI_KEY_MIN_LEN || + passphrase_len > TETHERING_WIFI_KEY_MAX_LEN) { + ERR("parameter(passphrase) is too short or long\n"); + return TETHERING_ERROR_INVALID_PARAMETER; + } + + if (!g_strcmp0(passphrase, th->passphrase)) + return TETHERING_ERROR_NONE; + + g_strlcpy(th->passphrase, passphrase, sizeof(th->passphrase)); + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Gets the passphrase for Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @details If the passphrase is not set, random string of 8 alphabets will be used. + * @remarks @a passphrase must be released with free() by you. + * @param[in] tethering The handle of tethering + * @param[out] passphrase The passphrase + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OUT_OF_MEMORY Out of memory + * @see tethering_wifi_ap_set_passphrase() + */ +API int tethering_wifi_ap_get_passphrase(tethering_h tethering, char **passphrase) +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(passphrase == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(passphrase) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + + *passphrase = g_strdup(th->passphrase); if (*passphrase == NULL) { - ERR("Memory allocation failed\n"); + ERR("strdup is failed\n"); return TETHERING_ERROR_OUT_OF_MEMORY; } - g_free(passphrase_buf); + return TETHERING_ERROR_NONE; +} + +/** + * @internal + * @brief Reload the settings (SSID / Passphrase / Security type / SSID visibility) for Wi-Fi AP. + * @since_tizen 2.3 + * @privlevel platform + * @privilege http://tizen.org/privilege/tethering.admin + * @remarks Connected devices via MobileAP will be disconnected when the settings are reloaded + * @param[in] tethering The handle of tethering + * @param[in] callback The callback function to invoke + * @param[in] user_data The user data to be passed to the callback function + * @return 0 on success, otherwise negative error value. + * @retval #TETHERING_ERROR_NONE Successful + * @retval #TETHERING_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #TETHERING_ERROR_OPERATION_FAILED Operation failed + */ +API int tethering_wifi_ap_reload_settings(tethering_h tethering, tethering_wifi_ap_settings_reloaded_cb callback, void *user_data) + +{ + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE, TETHERING_WIFI_FEATURE); + + _retvm_if(tethering == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(tethering) is NULL\n"); + _retvm_if(callback == NULL, TETHERING_ERROR_INVALID_PARAMETER, + "parameter(callback) is NULL\n"); + + __tethering_h *th = (__tethering_h *)tethering; + _softap_settings_t set = {"", "", 0, false}; + GDBusProxy *proxy = th->client_bus_proxy; + int ret = 0; + + DBG("+\n"); + + if (th->ap_settings_reloaded_cb) { + ERR("Operation in progress\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + + ret = __prepare_wifi_ap_settings(tethering, &set); + if (ret != TETHERING_ERROR_NONE) { + ERR("softap settings initialization failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + + th->ap_settings_reloaded_cb = callback; + th->ap_settings_reloaded_user_data = user_data; + + g_dbus_proxy_call(proxy, "reload_wifi_ap_settings", + g_variant_new("(ssii)", set.ssid, set.key, set.visibility, set.sec_type), + G_DBUS_CALL_FLAGS_NONE, -1, th->cancellable, + (GAsyncReadyCallback) __ap_settings_reloaded_cb, (gpointer)tethering); - DBG("-\n"); return TETHERING_ERROR_NONE; } diff --git a/src/tethering_client.c b/src/tethering_client.c index c8a7cd9..ec4d7e2 100644 --- a/src/tethering_client.c +++ b/src/tethering_client.c @@ -20,10 +20,15 @@ API int tethering_client_clone(tethering_client_h *dest, tethering_client_h origin) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(dest == NULL, TETHERING_ERROR_INVALID_PARAMETER, "Parameter(dest) is NULL\n"); __tethering_client_h *si = NULL; + __tethering_client_h *source = NULL; + + source = (__tethering_client_h *)origin; si = malloc(sizeof(__tethering_client_h)); if (si == NULL) { @@ -31,8 +36,13 @@ API int tethering_client_clone(tethering_client_h *dest, tethering_client_h orig return TETHERING_ERROR_OUT_OF_MEMORY; } - memcpy(si, (__tethering_client_h *)origin, - sizeof(__tethering_client_h)); + memcpy(si, source, sizeof(__tethering_client_h)); + si->hostname = g_strdup(source->hostname); + if (si->hostname == NULL) { + ERR("malloc is failed\n"); + free(si); + return TETHERING_ERROR_OUT_OF_MEMORY; + } *dest = (tethering_client_h)si; @@ -41,9 +51,17 @@ API int tethering_client_clone(tethering_client_h *dest, tethering_client_h orig API int tethering_client_destroy(tethering_client_h client) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER, "Parameter(client) is NULL\n"); + __tethering_client_h *si = NULL; + + si = (__tethering_client_h *)client; + + g_free(si->hostname); + free(client); return TETHERING_ERROR_NONE; @@ -51,6 +69,8 @@ API int tethering_client_destroy(tethering_client_h client) API int tethering_client_get_tethering_type(tethering_client_h client, tethering_type_e *type) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER, "Parameter(client) is NULL\n"); _retvm_if(type == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -65,6 +85,8 @@ API int tethering_client_get_tethering_type(tethering_client_h client, tethering API int tethering_client_get_name(tethering_client_h client, char **name) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER, "Parameter(client) is NULL\n"); _retvm_if(name == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -83,6 +105,8 @@ API int tethering_client_get_name(tethering_client_h client, char **name) API int tethering_client_get_ip_address(tethering_client_h client, tethering_address_family_e address_family, char **ip_address) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER, "Parameter(client) is NULL\n"); _retvm_if(ip_address == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -101,6 +125,8 @@ API int tethering_client_get_ip_address(tethering_client_h client, tethering_add API int tethering_client_get_mac_address(tethering_client_h client, char **mac_address) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER, "Parameter(client) is NULL\n"); _retvm_if(mac_address == NULL, TETHERING_ERROR_INVALID_PARAMETER, @@ -119,10 +145,11 @@ API int tethering_client_get_mac_address(tethering_client_h client, char **mac_a API int tethering_client_get_time(tethering_client_h client, time_t *timestamp) { + CHECK_FEATURE_SUPPORTED(TETHERING_FEATURE); + _retvm_if(client == NULL, TETHERING_ERROR_INVALID_PARAMETER, "Parameter(client) is NULL\n"); - __tethering_client_h *si = (__tethering_client_h *)client; *timestamp = si->tm; diff --git a/src/tethering_private.c b/src/tethering_private.c new file mode 100644 index 0000000..b01c80e --- /dev/null +++ b/src/tethering_private.c @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#include +#include +#include +#include "tethering_private.h" + +int tethering_check_feature_supported(const char* feature, ...) +{ + va_list list; + const char *key; + int ret; + bool value, supported = false; + + va_start(list, feature); + key = feature; + while(1) { + ret = system_info_get_platform_bool(key, &value); + if (ret < 0) { + ERR("Get feature is failed\n"); + return TETHERING_ERROR_OPERATION_FAILED; + } + supported |= value; + key = va_arg(list, const char *); + if (!key) break; + } + + if (!supported) + return TETHERING_ERROR_NOT_SUPPORT_API; + + return TETHERING_ERROR_NONE; +} diff --git a/test/tethering_test.c b/test/tethering_test.c index c0b316b..153e9e3 100644 --- a/test/tethering_test.c +++ b/test/tethering_test.c @@ -87,15 +87,19 @@ static const char *__convert_tethering_type_to_str(const tethering_type_e type) switch (type) { case TETHERING_TYPE_USB: - g_strlcpy(str_buf, "USB", sizeof(str_buf)); + g_strlcpy(str_buf, "USB Tethering", sizeof(str_buf)); break; case TETHERING_TYPE_WIFI: - g_strlcpy(str_buf, "Wi-Fi", sizeof(str_buf)); + g_strlcpy(str_buf, "Wi-Fi Tethering", sizeof(str_buf)); break; case TETHERING_TYPE_BT: - g_strlcpy(str_buf, "Bluetooth", sizeof(str_buf)); + g_strlcpy(str_buf, "Bluetooth Tethering", sizeof(str_buf)); + break; + + case TETHERING_TYPE_RESERVED: + g_strlcpy(str_buf, "Wi-Fi AP", sizeof(str_buf)); break; default: @@ -165,18 +169,36 @@ static void __register_cbs(tethering_h th, __tethering_cbs *cbs, void *user_data g_print("tethering_set_enabled_cb is failed\n"); } + ret = tethering_set_enabled_cb(th, TETHERING_TYPE_RESERVED, + cbs->enabled_cb, user_data); + if (__is_err(ret) == true) { + g_print("tethering_set_enabled_cb is failed\n"); + } + ret = tethering_set_disabled_cb(th, TETHERING_TYPE_ALL, cbs->disabled_cb, user_data); if (__is_err(ret) == true) { g_print("tethering_set_disabled_cb is failed\n"); } + ret = tethering_set_disabled_cb(th, TETHERING_TYPE_RESERVED, + cbs->disabled_cb, user_data); + if (__is_err(ret) == true) { + g_print("tethering_set_disabled_cb is failed\n"); + } + ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_ALL, cbs->changed_cb, user_data); if (__is_err(ret) == true) { g_print("tethering_set_connection_state_changed_cb is failed\n"); } + ret = tethering_set_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED, + cbs->changed_cb, user_data); + if (__is_err(ret) == true) { + g_print("tethering_set_connection_state_changed_cb is failed\n"); + } + ret = tethering_wifi_set_security_type_changed_cb(th, cbs->security_type_changed_cb, user_data); if (__is_err(ret) == true) { @@ -207,16 +229,31 @@ static void __deregister_cbs(tethering_h th) g_print("tethering_unset_enabled_cb is failed\n"); } + ret = tethering_unset_enabled_cb(th, TETHERING_TYPE_RESERVED); + if (__is_err(ret) == true) { + g_print("tethering_unset_enabled_cb is failed\n"); + } + ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_ALL); if (__is_err(ret) == true) { g_print("tethering_unset_disabled_cb is failed\n"); } + ret = tethering_unset_disabled_cb(th, TETHERING_TYPE_RESERVED); + if (__is_err(ret) == true) { + g_print("tethering_unset_disabled_cb is failed\n"); + } + ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_ALL); if (__is_err(ret) == true) { g_print("tethering_unset_connection_state_changed_cb is failed\n"); } + ret = tethering_unset_connection_state_changed_cb(th, TETHERING_TYPE_RESERVED); + if (__is_err(ret) == true) { + g_print("tethering_unset_connection_state_changed_cb is failed\n"); + } + ret = tethering_wifi_unset_security_type_changed_cb(th); if (__is_err(ret) == true) { g_print("tethering_wifi_unset_security_type_changed_cb is failed\n"); @@ -243,17 +280,17 @@ static void __enabled_cb(tethering_error_e error, tethering_type_e type, bool is return; } - g_print("## %s tethering is not enabled. error code[0x%X]\n", + g_print("## %s is not enabled. error code[0x%X]\n", __convert_tethering_type_to_str(type), error); return; } if (is_requested) - g_print("## %s tethering is enabled successfully\n", + g_print("## %s is enabled successfully\n", __convert_tethering_type_to_str(type)); else - g_print("## %s tethering is enabled by other app\n", + g_print("## %s is enabled by other app\n", __convert_tethering_type_to_str(type)); return; @@ -266,12 +303,12 @@ static void __disabled_cb(tethering_error_e error, tethering_type_e type, tether return; } - g_print("## %s tethering is not disabled. error code[0x%X]\n", + g_print("## %s is not disabled. error code[0x%X]\n", __convert_tethering_type_to_str(type), error); return; } - g_print("## %s tethering is %s\n", + g_print("## %s is %s\n", __convert_tethering_type_to_str(type), __convert_disabled_code_to_str(code)); @@ -336,6 +373,20 @@ static void __data_usage_cb(tethering_error_e result, unsigned long long receive return; } +static void __settings_reloaded_cb(tethering_error_e result, void *user_data) +{ + g_print("__settings_reloaded_cb\n"); + + if (result != TETHERING_ERROR_NONE) { + g_print("tethering_wifi_reload_settings is failed. error[0x%X]\n", result); + return; + } + + g_print("## Wi-Fi tethering setting is reloaded\n"); + + return; +} + static bool __clients_foreach_cb(tethering_client_h client, void *data) { tethering_client_h clone = NULL; @@ -445,7 +496,7 @@ static void __print_interface_info(tethering_h th, tethering_type_e type) char *subnet_mask = NULL; if (tethering_is_enabled(th, type) == FALSE) { - g_print("%s tethering is not enabled\n", + g_print("%s is not enabled\n", __convert_tethering_type_to_str(type)); return; } @@ -524,17 +575,69 @@ static void __print_wifi_tethering_setting(tethering_h th) return; } +static void __print_wifi_ap_setting(tethering_h th) +{ + char *ssid = NULL; + char *passphrase = NULL; + bool visibility = false; + tethering_wifi_security_type_e security_type = TETHERING_WIFI_SECURITY_TYPE_NONE; + + int error = TETHERING_ERROR_NONE; + + error = tethering_wifi_ap_get_ssid(th, &ssid); + if (error != TETHERING_ERROR_NONE) + __is_err(error); + else + g_print("\n\t** WiFi AP SSID : %s\n", ssid); + + error = tethering_wifi_ap_get_passphrase(th, &passphrase); + if (error != TETHERING_ERROR_NONE) + __is_err(error); + else + g_print("\t** WiFi AP passphrase : %s\n", passphrase); + + error = tethering_wifi_ap_get_ssid_visibility(th, &visibility); + if (error != TETHERING_ERROR_NONE) + __is_err(error); + else + g_print("\t** WiFi AP ssid visibility : %s\n", + visibility ? "visible" : "invisible"); + + error = tethering_wifi_ap_get_security_type(th, &security_type); + if (error != TETHERING_ERROR_NONE) + __is_err(error); + else + g_print("\t** WiFi AP security_type : %s\n", + security_type == + TETHERING_WIFI_SECURITY_TYPE_NONE ? + "open" : "wpa2-psk"); + + if (ssid) + free(ssid); + if (passphrase) + free(passphrase); + + return; +} + void print_menu(void) { - g_print("\nTo get client information, enter 'clients [USB | WIFI | BT | ALL]'"); - g_print("\nTo get interface information, enter 'info [USB | WIFI | BT]'"); + g_print("\nTo get client information, enter 'clients [USB | WIFI | BT | AP | ALL]'"); + g_print("\nTo get interface information, enter 'info [USB | WIFI | BT | AP]'"); g_print("\nTo get data usage, enter 'get data_usage'"); - g_print("\nTo enable tethering, enter 'enable [USB | WIFI | BT | ALL]'"); - g_print("\nTo disable tethering, enter 'disable [USB | WIFI | BT | ALL]'"); + g_print("\nTo enable tethering, enter 'enable [USB | WIFI | BT | AP | ALL]'"); + g_print("\nTo disable tethering, enter 'disable [USB | WIFI | BT | AP | ALL]'"); g_print("\nTo get Wi-Fi tethering setting, enter 'get wifi_setting'"); + g_print("\nTo get Wi-Fi AP setting, enter 'get wifi_ap_setting'"); + g_print("\nTo reload Wi-Fi tethering setting, enter 'reload wifi_setting'"); + g_print("\nTo reload Wi-Fi AP setting, enter 'reload wifi_ap_setting'"); g_print("\nTo set Wi-Fi tethering setting, enter '[set_security_type | set_visibility] [0 | 1]'"); + g_print("\nTo set Wi-Fi AP setting, enter '[set_ap_security_type | set_ap_visibility] [0 | 1]'"); g_print("\nTo set Wi-Fi tethering passphrase, enter 'set_passphrase [passphrase]'"); + g_print("\nTo set Wi-Fi AP passphrase, enter 'set_ap_passphrase [passphrase]'"); g_print("\nTo set Wi-Fi tethering SSID, enter 'set_ssid [SSID]'"); + g_print("\nTo set Wi-Fi AP SSID, enter 'set_ap_ssid [SSID]'"); + g_print("\nTo do testing multiple time to create and destroy tethering enter 'do handle_creation_test [number_of_times]'"); g_print("\nTo quit, enter 'quit'\n> "); return; @@ -549,6 +652,10 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) gchar *cmd = NULL; gchar *param = NULL; gsize read = 0; + __tethering_cbs cbs = { + __enabled_cb, __disabled_cb, + __connection_state_changed_cb, __security_type_changed_cb, + __ssid_visibility_changed_cb, __passphrase_changed_cb}; #if !GLIB_CHECK_VERSION(2, 31, 0) if (g_io_channel_read(channel, buf, INPUT_BUF_LEN, &read) != G_IO_ERROR_NONE) { @@ -604,6 +711,27 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) goto DONE; } + if (!strcmp(cmd, "get") && !strcmp(param, "wifi_ap_setting")) { + __print_wifi_ap_setting(th); + goto DONE; + } + + if (!strcmp(cmd, "reload") && !strcmp(param, "wifi_setting")) { + error = tethering_wifi_reload_settings(th, __settings_reloaded_cb, NULL); + if (error != TETHERING_ERROR_NONE) + g_print("tethering_wifi_reload_settings is failed [0x%X]\n", + error); + goto DONE; + } + + if (!strcmp(cmd, "reload") && !strcmp(param, "wifi_ap_setting")) { + error = tethering_wifi_ap_reload_settings(th, __settings_reloaded_cb, NULL); + if (error != TETHERING_ERROR_NONE) + g_print("tethering_wifi_ap_reload_settings is failed [0x%X]\n", + error); + goto DONE; + } + if (!strcmp(cmd, "set_visibility")) { error = tethering_wifi_set_ssid_visibility(th, atoi(param)); if (error != TETHERING_ERROR_NONE) @@ -612,6 +740,14 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) goto DONE; } + if (!strcmp(cmd, "set_ap_visibility")) { + error = tethering_wifi_ap_set_ssid_visibility(th, atoi(param)); + if (error != TETHERING_ERROR_NONE) + g_print("tethering_wifi_ap_set_ssid_visibility is failed [0x%X]\n", + error); + goto DONE; + } + if (!strcmp(cmd, "set_security_type")) { error = tethering_wifi_set_security_type(th, atoi(param)); if (error != TETHERING_ERROR_NONE) @@ -620,6 +756,14 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) goto DONE; } + if (!strcmp(cmd, "set_ap_security_type")) { + error = tethering_wifi_ap_set_security_type(th, atoi(param)); + if (error != TETHERING_ERROR_NONE) + g_print("tethering_wifi_ap_set_security_type is failed [0x%X]\n", + error); + goto DONE; + } + /* This should be removed */ if (!strcmp(cmd, "set_passphrase")) { error = tethering_wifi_set_passphrase(th, param); @@ -629,6 +773,14 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) goto DONE; } + if (!strcmp(cmd, "set_ap_passphrase")) { + error = tethering_wifi_ap_set_passphrase(th, param); + if (error != TETHERING_ERROR_NONE) + g_print("tethering_wifi_ap_set_passphrase is failed [0x%X]\n", + error); + goto DONE; + } + if (!strcmp(cmd, "set_ssid")) { error = tethering_wifi_set_ssid(th, param); if (error != TETHERING_ERROR_NONE) @@ -637,6 +789,44 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) goto DONE; } + if (!strcmp(cmd, "set_ap_ssid")) { + error = tethering_wifi_ap_set_ssid(th, param); + if (error != TETHERING_ERROR_NONE) + g_print("tethering_wifi_ap_set_ssid is failed [0x%X]\n", + error); + goto DONE; + } + + if (!strcmp(cmd, "do handle_creation_test")) { + int count = 0; + int i = 0; + count = atoi(param); + g_print("testing %d times....\n", count); + while (count > 0) { + sleep(3); + g_print("Destroying tethering %dth time\n", i); + if (NULL != th) { + __deregister_cbs(th); + + error = tethering_destroy(th); + + if (__is_err(error) == true) { + return 0; + } + } + sleep(3); + g_print("Creating tethering %dth time\n", i); + error = tethering_create(&th); + if (__is_err(error) == true) { + return 0; + } + __register_cbs(th, &cbs, NULL); + i++; + count--; + } + goto DONE; + } + /* One parameter(type) */ if (!strcmp(param, "USB")) type = TETHERING_TYPE_USB; @@ -644,6 +834,8 @@ gboolean input(GIOChannel *channel, GIOCondition condition, gpointer data) type = TETHERING_TYPE_WIFI; else if (!strcmp(param, "BT")) type = TETHERING_TYPE_BT; + else if (!strcmp(param, "AP")) + type = TETHERING_TYPE_RESERVED; else if (!strcmp(param, "ALL")) type = TETHERING_TYPE_ALL; else { @@ -681,7 +873,7 @@ int main(int argc, char *argv[]) __connection_state_changed_cb, __security_type_changed_cb, __ssid_visibility_changed_cb, __passphrase_changed_cb}; -#if !GLIB_CHECK_VERSION(2,35,0) +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); #endif @@ -719,4 +911,3 @@ int main(int argc, char *argv[]) return 0; } - -- 2.7.4