diff options
-rw-r--r-- | .gitignore | 51 | ||||
-rw-r--r-- | AUTHORS | 4 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | debian/changelog | 285 | ||||
-rw-r--r-- | debian/control | 4 | ||||
-rw-r--r-- | include/connection_profile.h | 722 | ||||
-rwxr-xr-x | include/net_connection.h | 355 | ||||
-rw-r--r-- | include/net_connection_private.h | 62 | ||||
-rw-r--r-- | packaging/capi-network-connection.spec | 9 | ||||
-rwxr-xr-x | src/connection.c | 505 | ||||
-rwxr-xr-x | src/connection_profile.c | 1209 | ||||
-rwxr-xr-x | src/internal.c | 53 | ||||
-rwxr-xr-x | src/libnetwork.c | 612 | ||||
-rw-r--r-- | test/connection_test.c | 336 |
14 files changed, 3874 insertions, 335 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85209fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,51 @@ +CMakeCache.txt +*/CMakeFiles/* +*.cmake +CMakeFiles* +*.a +*.so +Testing +cmake.depends +cmake.check_depends +cmake.check_cache +core +core.* +gmon.out +install_manifest.txt +doc/html/* +*~ +.kdev_include_paths +src.kdev4 +.cproject +.project +tet_captured +tet_lock +*.pc +Makefile +*-test +TC/config +samples/.metadata +TC/results/ +TC/testcase/connection_test +build-stamp +cmake_build_tmp/ +config.cfg +configure-stamp +debian/capi-network-connection-dbg.debhelper.log +debian/capi-network-connection-dbg.substvars +debian/capi-network-connection-dbg/ +debian/capi-network-connection-dev.debhelper.log +debian/capi-network-connection-dev.substvars +debian/capi-network-connection-dev/ +debian/debhelper.log +debian/files +debian/substvars +debian/tmp/ +debian/capi-network-connection.debhelper.log +debian/capi-network-connection.postinst.debhelper +debian/capi-network-connection.postrm.debhelper +debian/capi-network-connection.substvars +debian/capi-network-connection/ +test/connection_test +test/connection_test_regress + @@ -1,2 +1,2 @@ -Sanjeev Ba <as2902.b@samsung.com> -Kangho Hur <kangho.hur@samsung.com> +JaeHyun Kim <jeik01.kim@samsung.com> +ByungWoo Lee <bw1212.lee@samsung.com> diff --git a/CMakeLists.txt b/CMakeLists.txt index ddc07f3..30ba177 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ SET(PREFIX ${CMAKE_INSTALL_PREFIX}) SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog vconf capi-base-common glib-2.0") +SET(dependents "dlog vconf capi-base-common glib-2.0 network") SET(pc_dependents "capi-base-common") INCLUDE(FindPkgConfig) diff --git a/debian/changelog b/debian/changelog index 82a0f6c..edc96c5 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,102 @@ +capi-network-connection (0.1.1-9) unstable; urgency=low + + * Remove deprecated APIs + * Git: api/connection + * Tag: capi-network-connection_0.1.1-9 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Fri, 03 Aug 2012 16:51:25 +0900 + +capi-network-connection (0.1.1-8) unstable; urgency=low + + * Modify connection_create() and connection_destroy() API to assure thread safety + * Git: api/connection + * Tag: capi-network-connection_0.1.1-8 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Fri, 27 Jul 2012 12:36:54 +0900 + +capi-network-connection (0.1.1-7) unstable; urgency=low + + * Modify set/get statistics API to support dbus interface of net-config + * Git: api/connection + * Tag: capi-network-connection_0.1.1-7 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Fri, 06 Jul 2012 18:13:11 +0900 + +capi-network-connection (0.1.1-6) unstable; urgency=low + + * Modify connection_reset_statistics() to avoid vconf permission error + * Git: api/connection + * Tag: capi-network-connection_0.1.1-6 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Wed, 27 Jun 2012 19:06:32 +0900 + +capi-network-connection (0.1.1-5) unstable; urgency=low + + * Update TC + * Git: api/connection + * Tag: capi-network-connection_0.1.1-5 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Tue, 12 Jun 2012 18:49:08 +0900 + +capi-network-connection (0.1.1-4) unstable; urgency=low + + * Add profile initialization functions for user creation + * Git: api/connection + * Tag: capi-network-connection_0.1.1-4 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Tue, 12 Jun 2012 17:17:00 +0900 + +capi-network-connection (0.1.1-3) unstable; urgency=low + + * Implementation of connection_reset_statistics() + * Git: api/connection + * Tag: capi-network-connection_0.1.1-3 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Tue, 12 Jun 2012 16:34:52 +0900 + +capi-network-connection (0.1.1-2) unstable; urgency=low + + * Implementation of extened APIs again + * Git: api/connection + * Tag: capi-network-connection_0.1.1-2 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Tue, 29 May 2012 17:00:36 +0900 + +capi-network-connection (0.1.1-1) unstable; urgency=low + + * Rollback to capi-network-connection_0.1.0-23 + * Git: api/connection + * Tag: capi-network-connection_0.1.1-1 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Wed, 23 May 2012 20:56:07 +0900 + +capi-network-connection (0.1.1-0) unstable; urgency=low + + * Implementation of extened APIs + * Git: api/connection + * Tag: capi-network-connection_0.1.1-0 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Fri, 18 May 2012 14:57:49 +0900 + +capi-network-connection (0.1.0-23) unstable; urgency=low + + * Fix a bug which don't set user data in proxy callback setter + * Git: api/connection + * Tag: capi-network-connection_0.1.0-23 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Mon, 16 Apr 2012 12:02:47 +0900 + +capi-network-connection (0.1.0-22) unstable; urgency=low + + * Fix connection destroy bug + * Git: api/connection + * Tag: capi-network-connection_0.1.0-22 + + -- JaeHyun Kim <jeik01.kim@samsung.com> Mon, 09 Apr 2012 20:54:57 +0900 + capi-network-connection (0.1.0-21) unstable; urgency=low - * Add ipv6 feature + * Add ipv6 feature and update DTS code * Git: api/connection * Tag: capi-network-connection_0.1.0-21 @@ -8,7 +104,7 @@ capi-network-connection (0.1.0-21) unstable; urgency=low capi-network-connection (0.1.0-20) unstable; urgency=low - * Update DTS + * Update DTS code * Git: api/connection * Tag: capi-network-connection_0.1.0-20 @@ -24,7 +120,7 @@ capi-network-connection (0.1.0-19) unstable; urgency=low capi-network-connection (0.1.0-18) unstable; urgency=low - * Implementation of new APIs + * Implementation of new APIs and TC code * Git: api/connection * Tag: capi-network-connection_0.1.0-18 @@ -64,14 +160,187 @@ capi-network-connection (0.1.0-14) unstable; urgency=low capi-network-connection (0.1.0-13) unstable; urgency=low - * Update version + * License and Boilerplate update. * Git: api/connection * Tag: capi-network-connection_0.1.0-13 - -- Sanjeev BA <as2902.b@samsung.com> Thu, 15 Dec 2011 13:30:49 +0900 + -- Sanjeev BA <as2902.b@samsung.com> Tue, 06 Dec 2011 18:48:48 +0900 + +capi-network-connection (0.1.0-12) unstable; urgency=low + + * Bump up version. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-12 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 01 Dec 2011 19:40:16 +0900 + +capi-network-connection (0.1.0-11) unstable; urgency=low + + * Add data connection statistics. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-11 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 01 Dec 2011 19:18:24 +0900 + +capi-network-connection (0.1.0-10) unstable; urgency=low + + * Cleanup of vconf notifications. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-10 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 01 Dec 2011 11:08:59 +0900 + +capi-network-connection (0.1.0-9) unstable; urgency=low + + * Renaming for tizen. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-9 + + -- Sanjeev BA <as2902.b@samsung.com> Wed, 30 Nov 2011 15:10:59 +0900 + +capi-network-connection (0.1.0-8) unstable; urgency=low + + * Renaming for tizen. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-8 -capi-network-connection (0.0.1-1) unstable; urgency=low + -- Sanjeev BA <as2902.b@samsung.com> Wed, 23 Nov 2011 15:07:23 +0900 - * Initial Release. +capi-network-connection (0.1.0-7) unstable; urgency=low + + * Correct status updates. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-7 + + -- Sanjeev BA <as2902.b@samsung.com> Wed, 23 Nov 2011 13:46:23 +0900 + +capi-network-connection (0.1.0-6) unstable; urgency=low + + * Correct status updates. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-6 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 17 Nov 2011 15:10:55 +0900 + +capi-network-connection (0.1.0-5) unstable; urgency=low + + * Correct status updates. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-5 + + -- Sanjeev BA <as2902.b@samsung.com> Fri, 04 Nov 2011 17:55:49 +0900 + +capi-network-connection (0.1.0-4) unstable; urgency=low + + * Fix boilerplate. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-4 + + -- Sanjeev BA <as2902.b@samsung.com> Fri, 04 Nov 2011 11:22:10 +0900 + +capi-network-connection (0.1.0-3) unstable; urgency=low + + * Fix doxygen comments. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-3 + + -- Sanjeev BA <as2902.b@samsung.com> Mon, 31 Oct 2011 20:13:02 +0900 + +capi-network-connection (0.1.0-2) unstable; urgency=low + + * Add new mappings between vconf and connection_network_param_e. + * Git: api/connection + * Tag: capi-network-connection_0.1.0-2 + + -- Sanjeev BA <as2902.b@samsung.com> Fri, 14 Oct 2011 19:37:05 +0900 + +capi-network-connection (0.1.0-1) unstable; urgency=low + + * Alpha Release + * Git: api/connection + * Tag: capi-network-connection_0.1.0-1 + + -- Kangho Hur <kangho.hur@samsung.com> Tue, 27 Sep 2011 20:35:08 +0900 + +capi-network-connection (0.0.1-11) unstable; urgency=low + + * Fix build error from sbs using (sbs --clean-build). + * Updated debian/control file to add build depedency. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-11 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 08 Sep 2011 17:36:05 +0900 + +capi-network-connection (0.0.1-10) unstable; urgency=low + + * Fix as per new libnetwork API. + * remove dnet dependency, use only vconf. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-10 + + -- Sanjeev BA <as2902.b@samsung.com> Wed, 07 Sep 2011 14:19:30 +0900 + +capi-network-connection (0.0.1-9) unstable; urgency=low + + * Add param_name to callbacks. Will help apps identify what has changed. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-9 + + -- Sanjeev BA <as2902.b@samsung.com> Fri, 02 Sep 2011 10:20:09 +0900 + +capi-network-connection (0.0.1-8) unstable; urgency=low + + * Cleanup unused code. Fix documentation. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-8 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 01 Sep 2011 20:03:11 +0900 + +capi-network-connection (0.0.1-7) unstable; urgency=low + + * Fix handles. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-7 + + + -- Sanjeev BA <as2902.b@samsung.com> Mon, 22 Aug 2011 14:31:53 +0900 + +capi-network-connection (0.0.1-6) unstable; urgency=low + + * Fix handles. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-6 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 18 Aug 2011 09:50:20 +0900 + +capi-network-connection (0.0.1-5) unstable; urgency=low + + * Fix debain packaging issue. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-5 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 11 Aug 2011 19:28:50 +0900 + +capi-network-connection (0.0.1-4) unstable; urgency=low + + * Fix regression test case that was never used before. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-4 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 04 Aug 2011 19:04:04 +0900 + +capi-network-connection (0.0.1-3) unstable; urgency=low + + * Add missing pc.in file. + * Git: api/connection + * Tag: capi-network-connection_0.0.1-3 + + -- Sanjeev BA <as2902.b@samsung.com> Thu, 04 Aug 2011 18:04:33 +0900 + +capi-network-connection (0.0.1-2) unstable; urgency=low + + * Initial Upload + * Git: api/connection + * Tag: capi-network-connection_0.0.1-2 - -- Sanjeev BA <as2902.b@samsung.com> Wed, 07 Dec 2011 13:03:56 +0900 + -- Sanjeev BA <as2902.b@samsung.com> Thu, 04 Aug 2011 17:32:41 +0900 diff --git a/debian/control b/debian/control index d31a37f..085178b 100644 --- a/debian/control +++ b/debian/control @@ -1,8 +1,8 @@ Source: capi-network-connection Section: libs Priority: extra -Maintainer: Sanjeev BA <as2902.b@samsung.com> -Build-Depends: debhelper (>= 5), dlog-dev, capi-base-common-dev, libvconf-dev, libglib2.0-dev +Maintainer: JaeHyun Kim <jeik01.kim@samsung.com> +Build-Depends: debhelper (>= 5), dlog-dev, capi-base-common-dev, libvconf-dev, libglib2.0-dev, libdbus-glib-1-dev, libnetwork-dev Package: capi-network-connection Architecture: any diff --git a/include/connection_profile.h b/include/connection_profile.h new file mode 100644 index 0000000..02cc11d --- /dev/null +++ b/include/connection_profile.h @@ -0,0 +1,722 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TIZEN_NETWORK_CONNECTION_PROFILE_H__ +#define __TIZEN_NETWORK_CONNECTION_PROFILE_H__ + +#include <tizen.h> + +#ifdef __cplusplus +extern "C" { +#endif + +/** +* @addtogroup CAPI_NETWORK_CONNECTION_WIFI_PROFILE_MODULE +* @{ +*/ + +/** +* @brief Security type of Wi-Fi +*/ +typedef enum +{ + CONNECTION_WIFI_SECURITY_TYPE_NONE = 0, /**< Security disabled */ + CONNECTION_WIFI_SECURITY_TYPE_WEP = 1, /**< WEP */ + CONNECTION_WIFI_SECURITY_TYPE_WPA_PSK = 2, /**< WPA-PSK */ + CONNECTION_WIFI_SECURITY_TYPE_WPA2_PSK = 3, /**< WPA2-PSK */ + CONNECTION_WIFI_SECURITY_TYPE_EAP = 4, /**< EAP */ +} connection_wifi_security_type_e; + +/** +* @brief Below encryption modes are used in infrastructure and ad-hoc mode +*/ +typedef enum +{ + CONNECTION_WIFI_ENCRYPTION_TYPE_NONE = 0, /**< Encryption disabled */ + CONNECTION_WIFI_ENCRYPTION_TYPE_WEP = 1, /**< WEP */ + CONNECTION_WIFI_ENCRYPTION_TYPE_TKIP = 2, /**< TKIP */ + CONNECTION_WIFI_ENCRYPTION_TYPE_AES = 3, /**< AES */ + CONNECTION_WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED = 4, /**< TKIP and AES are both supported */ +} connection_wifi_encryption_type_e; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_CONNECTION_CELLULAR_PROFILE_MODULE +* @{ +*/ + +/** +* @brief This enumeration defines the cellular protocol type. +*/ +typedef enum +{ + CONNECTION_CELLULAR_NETWORK_TYPE_UNKNOWN = 0, /**< Not defined */ + CONNECTION_CELLULAR_NETWORK_TYPE_GPRS = 1, /**< GPRS type */ + CONNECTION_CELLULAR_NETWORK_TYPE_EDGE = 2, /**< EDGE type */ + CONNECTION_CELLULAR_NETWORK_TYPE_UMTS = 3, /**< UMTS type */ +} connection_cellular_network_type_e; + +/** +* @breif This enum indicates cellular service type +*/ +typedef enum +{ + CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN = 0, /**< Unknown */ + CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET = 1, /**< Established for Internet */ + CONNECTION_CELLULAR_SERVICE_TYPE_MMS = 2, /**< Established for MMS */ + CONNECTION_CELLULAR_SERVICE_TYPE_WAP = 3, /**< Established for WAP */ + CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET = 4, /**< Established for prepaid internet service */ + CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS = 5, /**< Established for prepaid MMS service */ +} connection_cellular_service_type_e; + +/** +* @brief Cellular Authentication Type +*/ +typedef enum +{ + CONNECTION_CELLULAR_AUTH_TYPE_NONE = 0, /**< No authentication */ + CONNECTION_CELLULAR_AUTH_TYPE_PAP = 1, /**< PAP authentication */ + CONNECTION_CELLULAR_AUTH_TYPE_CHAP = 2, /**< CHAP authentication */ +} connection_cellular_auth_type_e; + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_CONNECTION_PROFILE_MODULE +* @{ +*/ + +/** +* @brief The handle of profile +*/ +typedef void* connection_profile_h; + +/** +* @brief This enumeration defines the profile state type. +*/ +typedef enum +{ + CONNECTION_PROFILE_STATE_DISCONNECTED = 0, /**< Disconnected state */ + CONNECTION_PROFILE_STATE_ASSOCIATION = 1, /**< Association state */ + CONNECTION_PROFILE_STATE_CONFIGURATION = 2, /**< Configuration state */ + CONNECTION_PROFILE_STATE_CONNECTED = 3, /**< Connected state */ +} connection_profile_state_e; + +/** +* @brief Enumerations of Address family +*/ +typedef enum +{ + CONNECTION_ADDRESS_FAMILY_IPV4 = 0, /**< IPV4 Address type */ + CONNECTION_ADDRESS_FAMILY_IPV6 = 1, /**< IPV6 Address type */ +} connection_address_family_e; + +/** +* @brief Net IP configuration Type +*/ +typedef enum +{ + CONNECTION_IP_CONFIG_TYPE_NONE = 0, /**< Not defined */ + CONNECTION_IP_CONFIG_TYPE_STATIC = 1, /**< Manual IP configuration */ + CONNECTION_IP_CONFIG_TYPE_DYNAMIC = 2, /**< Config IP using DHCP client*/ + CONNECTION_IP_CONFIG_TYPE_AUTO = 3, /**< Config IP from Auto IP pool (169.254/16). Later with DHCP client, if available */ + CONNECTION_IP_CONFIG_TYPE_FIXED = 4, /**< Indicates an IP address that can not be modified */ +} connection_ip_config_type_e; + +/** +* @brief This enumeration defines the proxy method type. +*/ +typedef enum +{ + CONNECTION_PROXY_TYPE_DIRECT = 0, /**< Direct connection */ + CONNECTION_PROXY_TYPE_AUTO = 1, /**< Auto configuration(Use PAC file). If URL property is not set, DHCP/WPAD auto-discover will be tried */ + CONNECTION_PROXY_TYPE_MANUAL = 2, /**< Manual configuration */ +} connection_proxy_type_e; + +/** +* @enum connection_profile_type_e +* @brief Enumerations of network connection type. +*/ +typedef enum{ + CONNECTION_PROFILE_TYPE_CELLULAR = 0, /**< Cellular type */ + CONNECTION_PROFILE_TYPE_WIFI = 1, /**< Wi-Fi type */ + CONNECTION_PROFILE_TYPE_ETHERNET = 2, /**< Ethernet type */ +} connection_profile_type_e; + +/** +* @brief Creates the profile handle. +* @remarks @a profile must be released with connection_profile_destroy(). +* @param[in] type The type of profile +* @param[out] profile The handle of the profile +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @see connection_profile_destroy() +*/ +int connection_profile_create(connection_profile_type_e type, connection_profile_h* profile); + +/** +* @brief Destroys the profile handle. +* @param[out] connection The handle to the connection +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @see connection_profile_create() +*/ +int connection_profile_destroy(connection_profile_h profile); + +/** +* @brief Clons the profile handle. +* @remarks @a cloned_profile must be released with connection_profile_destroy(). +* @param[in] origin_profile The handle of origin profile +* @param[out] cloned_profile The handle of cloned profile +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @see connection_profile_destroy() +*/ +int connection_profile_clone(connection_profile_h* cloned_profile, connection_profile_h origin_profile); + +/** +* @brief Gets the profile name. +* @remarks @a profile_name must be released with free() by you. +* @param[in] profile The handle of profile +* @param[out] profile_name The name of profile +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +*/ +int connection_profile_get_name(connection_profile_h profile, char** profile_name); + +/** +* @brief Gets the network type. +* @param[in] profile The handle of profile +* @param[out] type The type of profile +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_type(connection_profile_h profile, connection_profile_type_e* type); + +/** +* @brief Gets the name of network interface. For example, eth0 and pdp0. +* @remarks @a interface_name must be released with free() by you. +* @param[in] profile The handle of profile +* @param[out] interface_name The name of network interface +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +*/ +int connection_profile_get_network_interface_name(connection_profile_h profile, char** interface_name); + +/** +* @brief Gets the network type. +* @param[in] profile The handle of profile +* @param[out] state The state of profile +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_state(connection_profile_h profile, connection_profile_state_e* state); + +/** +* @brief Gets the IP config type. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[out] type The type of IP config +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_ip_config_type(connection_profile_h profile, connection_address_family_e address_family, connection_ip_config_type_e* type); + +/** +* @brief Gets the IP address. +* @remarks @a ip_address must be released with free() by you. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[out] ip_address The IP address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_ip_address(connection_profile_h profile, connection_address_family_e address_family, char** ip_address); + +/** +* @brief Gets the Subnet Mask. +* @remarks @a subnet_mask must be released with free() by you. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[out] subnet_mask The subnet mask +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_subnet_mask(connection_profile_h profile, connection_address_family_e address_family, char** subnet_mask); + +/** +* @brief Gets the Gateway address. +* @remarks @a gateway_address must be released with free() by you. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[out] gateway_address The gateway address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_gateway_address(connection_profile_h profile, connection_address_family_e address_family, char** gateway_address); + +/** +* @brief Gets the DNS address. +* @remarks The allowance of DNS address is 2. @a dns_address must be released with free() by you. +* @param[in] profile The handle of profile +* @param[in] order The order of DNS address. It starts from 1, which means first DNS address. +* @param[in] address_family The address family +* @param[out] dns_address The DNS address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_dns_address(connection_profile_h profile, int order, connection_address_family_e address_family, char** dns_address); + +/** +* @brief Gets the Proxy type. +* @param[in] profile The handle of profile +* @param[out] type The type of proxy +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_proxy_type(connection_profile_h profile, connection_proxy_type_e* type); + +/** +* @brief Gets the Proxy address. +* @remarks @a proxy_address must be released with free() by you. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[out] proxy_address The proxy address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_proxy_address(connection_profile_h profile, connection_address_family_e address_family, char** proxy_address); + +/** +* @brief Sets the IP config type. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[in] type The type of IP config +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_ip_config_type(connection_profile_h profile, connection_address_family_e address_family, connection_ip_config_type_e type); + +/** +* @brief Sets the IP address. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[in] ip_address The IP address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_ip_address(connection_profile_h profile, connection_address_family_e address_family, const char* ip_address); + +/** +* @brief Sets the Subnet Mask. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[in] subnet_mask The subnet mask +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_subnet_mask(connection_profile_h profile, connection_address_family_e address_family, const char* subnet_mask); + +/** +* @brief Sets the Gateway address. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[in] gateway_address The gateway address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_gateway_address(connection_profile_h profile, connection_address_family_e address_family, const char* gateway_address); + +/** +* @brief Sets the DNS address. +* @remarks The allowance of DNS address is 2. +* @param[in] profile The handle of profile +* @param[in] order The order of DNS address. It starts from 1, which means first DNS address. +* @param[in] address_family The address family +* @param[in] dns_address The DNS address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_dns_address(connection_profile_h profile, int order, connection_address_family_e address_family, const char* dns_address); + +/** +* @brief Sets the Proxy type. +* @param[in] profile The handle of profile +* @param[in] type The type of proxy +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_proxy_type(connection_profile_h profile, connection_proxy_type_e type); + +/** +* @brief Sets the Proxy address. +* @param[in] profile The handle of profile +* @param[in] address_family The address family +* @param[in] gateway_address The gateway address +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_proxy_address(connection_profile_h profile, connection_address_family_e address_family, const char* proxy_address); + +/** +* @brief Called when the state of profile is changed. +* @param[in] profile The handle of profile +* @param[in] is_requested Indicates whether this change is requested or not +* @param[in] user_data The user data passed from the callback registration function +* @see connection_profile_set_state_changed_cb() +* @see connection_profile_unset_state_changed_cb() +*/ +typedef void(*connection_profile_state_changed_cb)(connection_profile_h profile, bool is_requested, void* user_data); + +/** +* @brief Registers the callback called when the state of profile is changed. +* @param[in] profile The handle of profile +* @param[in] callback The callback function to be called +* @param[in] user_data The user data passed to the callback function +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @see connection_profile_state_changed_cb() +* @see connection_profile_unset_state_changed_cb() +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_set_state_changed_cb(connection_profile_h profile, connection_profile_state_changed_cb callback, void* user_data); + +/** +* @brief Unregisters the callback called when the state of profile is changed. +* @param[in] profile The handle of profile +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @see connection_profile_state_changed_cb() +* @see connection_profile_set_state_changed_cb() +*/ +int connection_profile_unset_state_changed_cb(connection_profile_h profile); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_CONNECTION_WIFI_PROFILE_MODULE +* @{ +*/ + +/** +* @brief Gets the ESSID(Extended Service Set Identifier). +* @remarks @a essid must be released with free() by you. +* @param[in] profile The handle of profile +* @param[out] essid The ESSID +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +*/ +int connection_profile_get_wifi_essid(connection_profile_h profile, char** essid); + +/** +* @brief Gets the BSSID(Basic Service Set Identifier). +* @remarks @a bssid must be released with free() by you. +* @param[in] profile The handle of profile +* @param[out] bssid The BSSID +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +*/ +int connection_profile_get_wifi_bssid(connection_profile_h profile, char** bssid); + +/** +* @brief Gets the RSSI. +* @param[in] profile The handle of profile +* @param[out] rssi The RSSI +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_get_wifi_rssi(connection_profile_h profile, int* rssi); + +/** +* @brief Gets the frequency (MHz). +* @param[in] profile The handle of profile +* @param[out] frequency The frequency +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_get_wifi_frequency(connection_profile_h profile, int* frequency); + +/** +* @brief Gets the max speed (Mbps). +* @param[in] profile The handle of profile +* @param[out] max_speed The max speed +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_get_wifi_max_speed(connection_profile_h profile, int* max_speed); + +/** +* @brief Gets the security mode of Wi-Fi. +* @param[in] profile The handle of profile +* @param[out] type The type of Wi-Fi security +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_wifi_security_type(connection_profile_h profile, connection_wifi_security_type_e* type); + +/** +* @brief Gets the security mode of Wi-Fi. +* @param[in] profile The handle of profile +* @param[out] type The type of Wi-Fi security +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_wifi_encryption_type(connection_profile_h profile, connection_wifi_encryption_type_e* type); + +/** +* @brief Checks whether passphrase is required. +* @param[in] profile The handle of profile +* @param[out] required Indicates whether passphrase is required or not +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_is_wifi_passphrase_required(connection_profile_h profile, bool* required); + +/** +* @brief Sets the passphrase of Wi-Fi WPA. +* @param[in] profile The handle of profile +* @param[in] passphrase The passphrase of Wi-Fi security +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_set_wifi_passphrase(connection_profile_h profile, const char* passphrase); + +/** +* @brief Checks whether WPS(Wi-Fi Protected Setup) is supported. +* @remarks If WPS is supported, you can connect access point with WPS by wifi_connect_with_wps(). +* @param[in] profile The handle of profile +* @param[out] supported Indicates whether WPS is supported or not +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_is_wifi_wps_supported(connection_profile_h profile, bool* supported); + +/** +* @} +*/ + + +/** +* @addtogroup CAPI_NETWORK_CONNECTION_CELLULAR_PROFILE_MODULE +* @{ +*/ + +/** +* @brief Gets the cellular network type. +* @param[in] profile The handle of profile +* @param[out] type The type of cellular +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_cellular_network_type(connection_profile_h profile, connection_cellular_network_type_e* type); + +/** +* @brief Gets the service type. +* @param[in] profile The handle of profile +* @param[out] type The type of cellular service +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_cellular_service_type(connection_profile_h profile, connection_cellular_service_type_e* type); + +/** +* @brief Gets the APN(access point name). +* @remarks @a apn must be released with free() by you. +* @param[in] profile The handle of profile +* @param[out] apn The name of APN +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +*/ +int connection_profile_get_cellular_apn(connection_profile_h profile, char** apn); + +/** +* @brief Gets the authentication information. +* @remarks @a user_name and @a password must be released with free() by you. +* @param[in] profile The handle of profile +* @param[out] type The type of authentication +* @param[out] user_name The user name +* @param[out] password The password +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +* @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed +*/ +int connection_profile_get_cellular_auth_info(connection_profile_h profile, connection_cellular_auth_type_e* type, char** user_name, char** password); + +/** +* @brief Gets the home URL. +* @remarks @a home_url must be released with free() by you. +* @param[in] profile The handle of profile +* @param[out] home_url The home URL +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +* @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory +*/ +int connection_profile_get_cellular_home_url(connection_profile_h profile, char** home_url); + +/** +* @brief Gets the state of roaming. +* @param[in] profile The handle of profile +* @param[out] is_roaming Indicates whether cellular is in roaming or not +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_is_cellular_roaming(connection_profile_h profile, bool* is_roaming); + +/** +* @brief Sets the service type. +* @param[in] profile The handle of profile +* @param[out] type The type of cellular service +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_set_cellular_service_type(connection_profile_h profile, connection_cellular_service_type_e service_type); + +/** +* @brief Sets the APN(Access Point Name). +* @param[in] profile The handle of profile +* @param[out] apn The name of APN +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_set_cellular_apn(connection_profile_h profile, const char* apn); + +/** +* @brief Sets the Athentication information. +* @param[in] profile The handle of profile +* @param[out] type The type of authentication +* @param[out] user_name The user name +* @param[out] password The password +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_set_cellular_auth_info(connection_profile_h profile, connection_cellular_auth_type_e type, const char* user_name, const char* password); + +/** +* @brief Sets the home URL. +* @param[in] profile The handle of profile +* @param[out] home_url The home URL +* @return 0 on success, otherwise negative error value. +* @retval #CONNECTION_ERROR_NONE Successful +* @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter +*/ +int connection_profile_set_cellular_home_url(connection_profile_h profile, const char* home_url); + +/** +* @} +*/ + + +#ifdef __cplusplus +} + +#endif + +#endif /* __TIZEN_NETWORK_CONNECTION_PROFILE_H__ */ diff --git a/include/net_connection.h b/include/net_connection.h index 6159cfa..3963d48 100755 --- a/include/net_connection.h +++ b/include/net_connection.h @@ -18,49 +18,41 @@ #ifndef __NET_CONNECTION_INTF_H__ /* To prevent inclusion of a header file twice */ #define __NET_CONNECTION_INTF_H__ -#include <tizen.h> +#include "connection_profile.h" #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +#ifndef DEPRECATED +#define DEPRECATED __attribute__((deprecated)) +#endif /** - * @addtogroup CAPI_NETWORK_CONNECTION_MODULE + * @addtogroup CAPI_NETWORK_CONNECTION_MANAGER_MODULE * @{ */ - /** - * @brief Enumerations of connection errors. - */ -typedef enum -{ - CONNECTION_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - CONNECTION_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - CONNECTION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */ - CONNECTION_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */ - CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED = TIZEN_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED, /**< Address family not supported */ -}connection_error_e; + * @brief The connection handle for all connection functions. +*/ +typedef void* connection_h; /** - * @brief Enumerations of network status. - */ -typedef enum -{ - CONNECTION_NETWORK_STATE_DISCONNECTED = 0, /**< Disconnected */ - CONNECTION_NETWORK_STATE_WIFI = 1, /**< Wi-Fi is used for default connection */ - CONNECTION_NETWORK_STATE_CELLULAR = 2, /**< Cellular is used for default connection */ -}connection_network_state_e; + * @brief The iterator handle for profiles. +*/ +typedef void* connection_profile_iterator_h; /** - * @brief Enumerations of Address type + * @brief Enumerations of connection type. */ typedef enum { - CONNECTION_ADDRESS_FAMILY_IPV4 = 0, /**< IPV4 Address type */ - CONNECTION_ADDRESS_FAMILY_IPV6 = 1, /**< IPV6 Address type */ -} connection_address_family_e; + CONNECTION_TYPE_DISCONNECTED = 0, /**< Disconnected */ + CONNECTION_TYPE_WIFI = 1, /**< Wi-Fi is used for default connection */ + CONNECTION_TYPE_CELLULAR = 2, /**< Cellular is used for default connection */ + CONNECTION_TYPE_ETHERNET = 3, /**< Ethernet is used for default connection */ +} connection_type_e; /** * @brief Enumerations of cellular network state. @@ -72,7 +64,7 @@ typedef enum CONNECTION_CELLULAR_STATE_ROAMING_OFF = 2, /**< Roaming is turned off */ CONNECTION_CELLULAR_STATE_CALL_ONLY_AVAILABLE = 3, /**< Call is only available. */ CONNECTION_CELLULAR_STATE_AVAILABLE = 4, /**< Available */ -}connection_cellular_state_e; +} connection_cellular_state_e; /** * @brief This enumeration defines the Wi-Fi state. @@ -85,35 +77,73 @@ typedef enum } connection_wifi_state_e; /** - * @brief The connection handle for all connection functions. -*/ -typedef struct connection_handle_s * connection_h; + * @brief This enumeration defines the ethernet state. + */ +typedef enum +{ + CONNECTION_ETHERNET_STATE_DEACTIVATED = 0, /**< Deactivated state */ + CONNECTION_ETHERNET_STATE_DISCONNECTED = 1, /**< disconnected state */ + CONNECTION_ETHERNET_STATE_CONNECTED = 2, /**< Connected state */ +} connection_ethernet_state_e; /** - * @brief Called when the state of network is changed. - * @param[in] connection_network_state_e The state of current network connection - * @param[in] user_data The user data passed from the callback registration function - * @see connection_set_network_status_changed_cb() - * @see connection_unset_network_status_changed_cb() + * @brief This enumeration defines the type of connection iterator. */ -typedef void(*connection_network_state_changed_cb)(connection_network_state_e state, void* user_data); +typedef enum +{ + CONNECTION_ITERATOR_TYPE_REGISTERED = 0, /**< The iterator of registered profile */ + CONNECTION_ITERATOR_TYPE_CONNECTED = 1, /**< The iterator of connected profile */ +} connection_iterator_type_e; /** - * @brief Called when the address is changed. - * @param[in] ipv4_address The ipv4 address of current network connection - * @param[in] ipv6_address The ipv6 address of current network connection - * @param[in] user_data The user data passed from the callback registration function - * @see connection_set_ip_address_changed_cb() - * @see connection_unset_ip_address_changed_cb() - * @see connection_set_proxy_address_changed_cb() - * @see connection_unset_proxy_address_changed_cb() + * @brief Enumerations of connection errors. */ -typedef void(*connection_address_changed_cb)(const char* ipv4_address, const char* ipv6_address, void* user_data); +typedef enum +{ + CONNECTION_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + CONNECTION_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + CONNECTION_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory error */ + CONNECTION_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid Operation */ + CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED = TIZEN_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED, /**< Address family not supported */ + CONNECTION_ERROR_OPERATION_FAILED = TIZEN_ERROR_NETWORK_CLASS|0x0401, /**< Operation failed */ + CONNECTION_ERROR_ITERATOR_END = TIZEN_ERROR_NETWORK_CLASS|0x0402, /**< End of iteration */ + CONNECTION_ERROR_NO_CONNECTION = TIZEN_ERROR_NETWORK_CLASS|0x0403, /**< There is no connection */ +} connection_error_e; + +/** + * @} +*/ + +/** + * @addtogroup CAPI_NETWORK_CONNECTION_STATISTICS_MODULE + * @{ +*/ + +/** + * @brief Enumerations of statistics type. + */ +typedef enum +{ + CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA = 0, /**< Last received data */ + CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA = 1, /**< Last sent data */ + CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA = 2, /**< Total received data */ + CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA = 3, /**< Total sent data */ +} connection_statistics_type_e; + +/** + * @} +*/ + +/** + * @addtogroup CAPI_NETWORK_CONNECTION_MANAGER_MODULE + * @{ +*/ + /** * @brief Creates a handle for managing data connections. * @remarks @a handle must be released with connection_destroy(). - * @param[out] connection The handle to the connection + * @param[out] connection The handle of the connection * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter @@ -124,7 +154,7 @@ int connection_create(connection_h* connection); /** * @brief Destroys the connection handle. - * @param[in] connection The handle to the connection + * @param[in] connection The handle of the connection * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter @@ -133,40 +163,64 @@ int connection_create(connection_h* connection); int connection_destroy(connection_h connection); /** - * @brief Gets the network state. - * @details The returned status is for the current connection. - * @param[in] connection The handle to the connection + * @brief Called when the type of connection is changed. + * @param[in] type The type of current network connection + * @param[in] user_data The user data passed from the callback registration function + * @see connection_set_network_type_changed_cb() + * @see connection_unset_network_type_changed_cb() + */ +typedef void(*connection_type_changed_cb)(connection_type_e type, void* user_data); + +/** + * @brief Called when the address is changed. + * @param[in] ipv4_address The IP address for IPv4 + * @param[in] ipv6_address The IP address for IPv6 + * @param[in] user_data The user data passed from the callback registration function + * @see connection_set_ip_address_changed_cb() + * @see connection_unset_ip_address_changed_cb() + * @see connection_set_proxy_address_changed_cb() + * @see connection_unset_proxy_address_changed_cb() + */ +typedef void(*connection_address_changed_cb)(const char* ipv4_address, const char* ipv6_address, void* user_data); + + +/** + * @brief Gets the type. + * @details The returned type is for the current connection. + * @param[in] connection The handle of the connection * @param[out] state The state of network * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the state due to internal error + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_get_network_state(connection_h connection, connection_network_state_e* state); +int connection_get_type(connection_h connection, connection_type_e* type); /** * @brief Gets the IP address of the current connection. * @remarks @a ip_address must be released with free() by you. - * @param[in] connection The handle to the connection + * @param[in] connection The handle of the connection * @param[in] address_family The address family * @param[out] ip_address The pointer to IP address string. * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the ip address due to internal error + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + * @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family */ int connection_get_ip_address(connection_h connection, connection_address_family_e address_family, char** ip_address); /** * @brief Gets the proxy address of the current connection. * @remarks @a proxy must be released with free() by you. - * @param[in] connection The handle to the connection + * @param[in] connection The handle of the connection * @param[in] address_family The address family * @param[out] proxy The proxy address * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the proxy due to internal error + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + * @retval #CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED Not supported address family */ int connection_get_proxy(connection_h connection, connection_address_family_e address_family, char** proxy); @@ -178,7 +232,7 @@ int connection_get_proxy(connection_h connection, connection_address_family_e ad * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the state due to internal error + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state); @@ -190,47 +244,63 @@ int connection_get_cellular_state(connection_h connection, connection_cellular_s * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the state due to internal error + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state); /** - * @brief Registers the callback called when the state of current connection is changed. + * @brief Gets the state of ethernet. + * @details The returned state is for the ethernet connection state. + * @param[in] connection The handle of connection + * @param[out] state The state of Ethernet connection + * @return 0 on success, otherwise negative error value. + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + */ +int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state); + +/** + * @brief Registers the callback called when the type of current connection is changed. * @param[in] connection The handle of connection * @param[in] callback The callback function to be called * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_set_network_state_changed_cb(connection_h connection, connection_network_state_changed_cb callback, void* user_data); +int connection_set_type_changed_cb(connection_h connection, connection_type_changed_cb callback, void* user_data); /** - * @brief Unregisters the callback called when the state of current connection is changed. + * @brief Unregisters the callback called when the type of current connection is changed. * @param[in] connection The handle of connection * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_unset_network_state_changed_cb(connection_h connection); +int connection_unset_type_changed_cb(connection_h connection); /** - * @brief Registers the callback called when the ip address is changed. + * @brief Registers the callback called when the IP address is changed. * @param[in] connection The handle of connection * @param[in] callback The callback function to be called * @param[in] user_data The user data passed to the callback function * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ int connection_set_ip_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data); /** - * @brief Unregisters the callback called when the ip address is changed. + * @brief Unregisters the callback called when the IP address is changed. * @param[in] connection The handle of connection * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ int connection_unset_ip_address_changed_cb(connection_h connection); @@ -242,6 +312,7 @@ int connection_unset_ip_address_changed_cb(connection_h connection); * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ int connection_set_proxy_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data); @@ -251,97 +322,165 @@ int connection_set_proxy_address_changed_cb(connection_h connection, connection_ * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ int connection_unset_proxy_address_changed_cb(connection_h connection); /** - * @brief Gets the received data size of the last cellular packet data connection. - * @param[in] connection The handle to the connection - * @param[out] size The received data size of the last cellular packet data connection ( bytes ) + * @brief Adds new profile which is created by connection_profile_created(). + * @param[in] connection The handle of connection + * @param[in] profile The handle of profile * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful - * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_get_last_received_data_size(connection_h connection, int* size); +int connection_add_profile(connection_h connection, connection_profile_h profile); /** - * @brief Gets the sent data size of the last cellular packet data connection. - * @param[in] connection The handle to the connection - * @param[out] size The sent data size of the last cellular packet data connection. + * @brief Removes existing profile. + * @param[in] connection The handle of connection + * @param[in] profile The handle of profile * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful - * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_get_last_sent_data_size(connection_h connection, int* size); +int connection_remove_profile(connection_h connection, connection_profile_h profile); /** - * @brief Gets the total received data size of all cellular packet data connections. - * @param[in] connection The handle to the connection - * @param[out] size The total received data size of all cellular packet data connections (bytes) + * @brief Updates existing profile. + * @param[in] connection The handle of connection + * @param[in] profile The handle of profile * @return 0 on success, otherwise negative error value. - * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_get_total_received_data_size (connection_h connection, int* size); +int connection_update_profile(connection_h connection, connection_profile_h profile); /** - * @brief Gets the total sent data size of all cellular packet data connections. - * @param[in] connection The handle to the connection - * @param[out] size The total sent data size of all cellular packet data connections (bytes) + * @brief Gets a iterator of the profiles. + * @remarks @a profile_iterator must be released with connection_destroy(). + * @param[in] connection The handle of connection + * @param[in] type The type of connetion iterator + * @param[out] profile_iterator The iterator of profile * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error + * @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_get_total_sent_data_size (connection_h connection, int* size); +int connection_get_profile_iterator(connection_h connection, connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator); /** - * @brief Gets the received data size of the last Wi-Fi packet data connection. - * @param[in] connection The handle to the connection - * @param[out] size The received data size of the last Wi-Fi packet data connection ( bytes ) + * @brief Moves the profile iterator to the next position and gets a profile handle. + * @param[in] profile_iterator The iterator of profile + * @param[out] profile The handle of profile * @return 0 on success, otherwise negative error value. - * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error + * @retval #CONNECTION_ERROR_ITERATOR_END End of iteration */ -int connection_get_wifi_last_received_data_size(connection_h connection, int* size); +int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator, connection_profile_h* profile); /** - * @brief Gets the sent data size of the last Wi-Fi packet data connection. - * @param[in] connection The handle to the connection - * @param[out] size The sent data size of the last Wi-Fi packet data connection. + * @brief Checks whether the next element of profile iterator exists or not. + * @param[in] profile_iterator The iterator of profile + * @return @c true if next element exists, \n @c false if next element doesn't exist + */ +bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator); + +/** + * @brief Destroys a iterator of the profiles. + * @param[in] profile_iterator The iterator of profile * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error */ -int connection_get_wifi_last_sent_data_size(connection_h connection, int* size); +int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator); /** - * @brief Gets the total received data size of all Wi-Fi packet data connections. - * @param[in] connection The handle to the connection - * @param[out] size The total received data size of all Wi-Fi packet data connections (bytes) + * @brief Gets the name of default profile. + * @remarks @a profile must be released with connection_profile_destroy(). + * @param[in] connection The handle of connection + * @param[out] profile The handle of profile * @return 0 on success, otherwise negative error value. - * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error + * @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + * @retval #CONNECTION_ERROR_NO_CONNECTION There is no connection */ -int connection_get_wifi_total_received_data_size (connection_h connection, int* size); +int connection_get_current_profile(connection_h connection, connection_profile_h* profile); /** - * @brief Gets the total sent data size of all Wi-Fi packet data connections. - * @param[in] connection The handle to the connection - * @param[out] size The total sent data size of all Wi-Fi packet data connections (bytes) + * @brief Opens the connection with the profile, asynchronously. + * @param[in] connection The handle of connection + * @param[in] profile The handle of profile * @return 0 on success, otherwise negative error value. * @retval #CONNECTION_ERROR_NONE Successful * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #CONNECTION_ERROR_INVALID_OPERATION Cannot retrieve the size due to internal error + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed */ -int connection_get_wifi_total_sent_data_size (connection_h connection, int* size); +int connection_open_profile(connection_h connection, connection_profile_h profile); +/** + * @brief Opens the connection with service type, asynchronously. + * @remarks @a profile must be released with connection_profile_destroy(). + * @param[in] connection The handle of connection + * @param[in] type The type of cellular service + * @param[out] profile The handle of profile + * @return 0 on success, otherwise negative error value. + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + */ +int connection_open_cellular_service_type(connection_h connection, connection_cellular_service_type_e type, connection_profile_h* profile); + +/** + * @brief Closes the connection with the profile. + * @param[in] connection The handle of connection + * @param[in] profile The handle of profile + * @return 0 on success, otherwise negative error value. + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + */ +int connection_close_profile(connection_h connection, connection_profile_h profile); + +/** + * @} +*/ + +/** + * @addtogroup CAPI_NETWORK_CONNECTION_STATISTICS_MODULE + * @{ +*/ + +/** + * @brief Gets the statistics information. + * @param[in] connection_type The type of connection. CONNECTION_TYPE_WIFI and CONNECTION_TYPE_CELLULAR are only supported. + * @param[in] statistics_type The type of statistics + * @param[out] size The received data size of the last cellular packet data connection (bytes) + * @return 0 on success, otherwise negative error value. + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + */ +int connection_get_statistics(connection_type_e connection_type, connection_statistics_type_e statistics_type, long long* size); + +/** + * @brief Resets the statistics information + * @param[in] connection_type The type of connection. CONNECTION_TYPE_WIFI and CONNECTION_TYPE_CELLULAR are only supported. + * @param[in] statistics_type The type of statistics + * @return 0 on success, otherwise negative error value. + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + */ +int connection_reset_statistics(connection_type_e connection_type, connection_statistics_type_e statistics_type); /** * @} diff --git a/include/net_connection_private.h b/include/net_connection_private.h index b74d6a1..40f198c 100644 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -19,7 +19,23 @@ #ifndef __NET_CONNECTION_PRIVATE_H__ /* To prevent inclusion of a header file twice */ #define __NET_CONNECTION_PRIVATE_H__ -#include <net_connection.h> +#include <dlog.h> +#include <network-cm-intf.h> +#include <network-wifi-intf.h> +#include "net_connection.h" + +#define TIZEN_NET_CONNECTION "net_connection" + +#define CONNECTION_INFO LOG_VERBOSE +#define CONNECTION_ERROR LOG_ERROR +#define CONNECTION_WARN LOG_WARN + +#define CONNECTION_LOG(log_level, format, args...) \ + SLOG(log_level,TIZEN_NET_CONNECTION, "[%s][Ln: %d] " format, __FILE__, __LINE__, ##args) + +#define CONNECTION_MUTEX_LOCK _connection_inter_mutex_lock() + +#define CONNECTION_MUTEX_UNLOCK _connection_inter_mutex_unlock() #ifdef __cplusplus extern "C" { @@ -27,7 +43,7 @@ extern "C" { typedef struct _connection_handle_s { - connection_network_state_changed_cb state_changed_callback; + connection_type_changed_cb state_changed_callback; connection_address_changed_cb ip_changed_callback; connection_address_changed_cb proxy_changed_callback; void *state_changed_user_data; @@ -35,21 +51,33 @@ typedef struct _connection_handle_s void *proxy_changed_user_data; } connection_handle_s; -/** - * @internal - * @brief same as number of callbacks in connection_event_callbacks_s - */ -typedef enum -{ - LAST_SENT_DATA_SIZE, - LAST_RECEIVED_DATA_SIZE, - TOTAL_SENT_DATA_SIZE, - TOTAL_RECEIVED_DATA_SIZE, - LAST_WIFI_SENT_DATA_SIZE, - LAST_WIFI_RECEIVED_DATA_SIZE, - TOTAL_WIFI_SENT_DATA_SIZE, - TOTAL_WIFI_RECEIVED_DATA_SIZE, -} stat_request_e; + +bool _connection_libnet_init(void); +bool _connection_libnet_deinit(void); +bool _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state); +bool _connection_libnet_check_profile_validity(connection_profile_h profile); +int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, + connection_profile_iterator_h* profile_iterator); +bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iterator); +int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile); +int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h); +int _connection_libnet_get_current_profile(connection_profile_h *profile); +int _connection_libnet_open_profile(connection_profile_h profile); +int _connection_libnet_open_cellular_service_type(connection_cellular_service_type_e type, connection_profile_h *profile); +int _connection_libnet_close_profile(connection_profile_h profile); +void _connection_libnet_add_to_profile_list(connection_profile_h profile); +void _connection_libnet_remove_from_profile_list(connection_profile_h profile); +bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile, + connection_profile_state_changed_cb callback, void *user_data); +void _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile); +int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type); +int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size); + +net_service_type_t _connection_profile_convert_to_libnet_cellular_service_type(connection_cellular_service_type_e svc_type); +net_state_type_t _connection_profile_convert_to_net_state(connection_profile_state_e state); + +void _connection_inter_mutex_lock(void); +void _connection_inter_mutex_unlock(void); #ifdef __cplusplus } diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index f26a06a..4a87075 100644 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -2,8 +2,8 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 0.1.0 -Release: 19 +Version: 0.1.1_9 +Release: 1 Group: System/Network License: Apache License Version 2.0 Source0: %{name}-%{version}.tar.gz @@ -12,6 +12,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(vconf) BuildRequires: pkgconfig(capi-base-common) +BuildRequires: pkgconfig(network) Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -20,7 +21,7 @@ Network Connection library in Tizen C API %package devel Summary: Network Connection library in Tizen C API (Development) -Group: TO_BE/FILLED_IN +Group: System/Network Requires: %{name} = %{version}-%{release} %description devel @@ -53,4 +54,4 @@ rm -rf %{buildroot} %files devel %{_includedir}/network/*.h %{_libdir}/pkgconfig/*.pc -%{_libdir}/libcapi-network-connection.so
\ No newline at end of file +%{_libdir}/libcapi-network-connection.so diff --git a/src/connection.c b/src/connection.c index c18a1bd..ffa0193 100755 --- a/src/connection.c +++ b/src/connection.c @@ -11,17 +11,14 @@ * 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. + * limitations under the License. */ #include <stdio.h> #include <string.h> -#include <dlog.h> #include <glib.h> #include <vconf/vconf.h> -#include <net_connection_private.h> - -#define TIZEN_NET_CONNECTION "CAPI_NETWORK_CONNECTION" +#include "net_connection_private.h" static GSList *conn_handle_list = NULL; @@ -34,11 +31,11 @@ static int __connection_convert_net_state(int status) { switch (status) { case VCONFKEY_NETWORK_CELLULAR: - return CONNECTION_NETWORK_STATE_CELLULAR; + return CONNECTION_TYPE_CELLULAR; case VCONFKEY_NETWORK_WIFI: - return CONNECTION_NETWORK_STATE_WIFI; + return CONNECTION_TYPE_WIFI; default: - return CONNECTION_NETWORK_STATE_DISCONNECTED; + return CONNECTION_TYPE_DISCONNECTED; } } @@ -115,16 +112,17 @@ static int __connection_set_state_changed_callback(connection_h connection, void if (callback) { if (__connection_get_state_changed_callback_count() == 0) - vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS , - __connection_cb_state_change_cb, - NULL); + if (vconf_notify_key_changed(VCONFKEY_NETWORK_STATUS , + __connection_cb_state_change_cb, NULL)) + return CONNECTION_ERROR_OPERATION_FAILED; local_handle->state_changed_user_data = user_data; } else { if (local_handle->state_changed_callback && __connection_get_state_changed_callback_count() == 1) - vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS, - __connection_cb_state_change_cb); + if (vconf_ignore_key_changed(VCONFKEY_NETWORK_STATUS, + __connection_cb_state_change_cb)) + return CONNECTION_ERROR_OPERATION_FAILED; } local_handle->state_changed_callback = callback; @@ -137,16 +135,17 @@ static int __connection_set_ip_changed_callback(connection_h connection, void *c if (callback) { if (__connection_get_ip_changed_callback_count() == 0) - vconf_notify_key_changed(VCONFKEY_NETWORK_IP, - __connection_cb_ip_change_cb, - NULL); + if (vconf_notify_key_changed(VCONFKEY_NETWORK_IP, + __connection_cb_ip_change_cb, NULL)) + return CONNECTION_ERROR_OPERATION_FAILED; local_handle->ip_changed_user_data = user_data; } else { if (local_handle->ip_changed_callback && __connection_get_ip_changed_callback_count() == 1) - vconf_ignore_key_changed(VCONFKEY_NETWORK_IP, - __connection_cb_ip_change_cb); + if (vconf_ignore_key_changed(VCONFKEY_NETWORK_IP, + __connection_cb_ip_change_cb)) + return CONNECTION_ERROR_OPERATION_FAILED; } local_handle->ip_changed_callback = callback; @@ -159,16 +158,17 @@ static int __connection_set_proxy_changed_callback(connection_h connection, void if (callback) { if (__connection_get_proxy_changed_callback_count() == 0) - vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY, - __connection_cb_proxy_change_cb, - NULL); + if (vconf_notify_key_changed(VCONFKEY_NETWORK_PROXY, + __connection_cb_proxy_change_cb, NULL)) + return CONNECTION_ERROR_OPERATION_FAILED; - local_handle->proxy_changed_callback = user_data; + local_handle->proxy_changed_user_data = user_data; } else { if (local_handle->proxy_changed_callback && __connection_get_proxy_changed_callback_count() == 1) - vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY, - __connection_cb_proxy_change_cb); + if (vconf_ignore_key_changed(VCONFKEY_NETWORK_PROXY, + __connection_cb_proxy_change_cb)) + return CONNECTION_ERROR_OPERATION_FAILED; } local_handle->proxy_changed_callback = callback; @@ -177,7 +177,7 @@ static int __connection_set_proxy_changed_callback(connection_h connection, void static void __connection_cb_state_change_cb(keynode_t *node, void *user_data) { - LOGI(TIZEN_NET_CONNECTION,"Net Status Changed Indication\n"); + CONNECTION_LOG(CONNECTION_INFO, "Net Status Changed Indication\n"); GSList *list; int state = vconf_keynode_get_int(node); @@ -193,7 +193,7 @@ static void __connection_cb_state_change_cb(keynode_t *node, void *user_data) static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data) { - LOGI(TIZEN_NET_CONNECTION,"Net IP Changed Indication\n"); + CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n"); GSList *list; char *ip_addr = vconf_keynode_get_str(node); @@ -209,7 +209,7 @@ static void __connection_cb_ip_change_cb(keynode_t *node, void *user_data) static void __connection_cb_proxy_change_cb(keynode_t *node, void *user_data) { - LOGI(TIZEN_NET_CONNECTION,"Net IP Changed Indication\n"); + CONNECTION_LOG(CONNECTION_INFO, "Net IP Changed Indication\n"); GSList *list; char *proxy = vconf_keynode_get_str(node); @@ -233,62 +233,95 @@ static bool __connection_check_handle_validity(connection_h connection) return false; } +static int __connection_get_handle_count(void) +{ + GSList *list; + int count = 0; + + if (!conn_handle_list) + return count; + + for (list = conn_handle_list; list; list = list->next) count++; + + return count; +} + +/* Connection Manager module ********************************************************************/ + int connection_create(connection_h* connection) { + CONNECTION_MUTEX_LOCK; + if (connection == NULL || __connection_check_handle_validity(*connection)) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + CONNECTION_MUTEX_UNLOCK; return CONNECTION_ERROR_INVALID_PARAMETER; } + if (_connection_libnet_init() == false) { + CONNECTION_LOG(CONNECTION_ERROR, "Creation failed!\n"); + CONNECTION_MUTEX_UNLOCK; + return CONNECTION_ERROR_OPERATION_FAILED; + } + *connection = g_try_malloc0(sizeof(connection_handle_s)); if (*connection != NULL) { - LOGI(TIZEN_NET_CONNECTION, "New Handle Created %p\n", *connection); + CONNECTION_LOG(CONNECTION_INFO, "New Handle Created %p\n", *connection); } else { + CONNECTION_MUTEX_UNLOCK; return CONNECTION_ERROR_OUT_OF_MEMORY; } conn_handle_list = g_slist_append(conn_handle_list, *connection); + CONNECTION_MUTEX_UNLOCK; return CONNECTION_ERROR_NONE; } int connection_destroy(connection_h connection) { + CONNECTION_MUTEX_LOCK; + if (connection == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + CONNECTION_MUTEX_UNLOCK; return CONNECTION_ERROR_INVALID_PARAMETER; } - conn_handle_list = g_slist_remove(conn_handle_list, connection); - - LOGI(TIZEN_NET_CONNECTION, "Destroy Handle : %p\n", connection); + CONNECTION_LOG(CONNECTION_INFO, "Destroy Handle : %p\n", connection); __connection_set_state_changed_callback(connection, NULL, NULL); __connection_set_ip_changed_callback(connection, NULL, NULL); __connection_set_proxy_changed_callback(connection, NULL, NULL); + conn_handle_list = g_slist_remove(conn_handle_list, connection); + g_free(connection); + if (__connection_get_handle_count() == 0) + _connection_libnet_deinit(); + + CONNECTION_MUTEX_UNLOCK; return CONNECTION_ERROR_NONE; } -int connection_get_network_state(connection_h connection, connection_network_state_e* state) +int connection_get_type(connection_h connection, connection_type_e* type) { int status = 0; - if (state == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + if (type == NULL || !(__connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) { - LOGI(TIZEN_NET_CONNECTION,"vconf_get_int Failed = %d\n", status); - return CONNECTION_ERROR_INVALID_OPERATION; + CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status); + return CONNECTION_ERROR_OPERATION_FAILED; } - LOGI(TIZEN_NET_CONNECTION,"Connected Network = %d\n", status); + CONNECTION_LOG(CONNECTION_INFO, "Connected Network = %d\n", status); - *state = __connection_convert_net_state(status); + *type = __connection_convert_net_state(status); return CONNECTION_ERROR_NONE; } @@ -296,7 +329,7 @@ int connection_get_network_state(connection_h connection, connection_network_sta int connection_get_ip_address(connection_h connection, connection_address_family_e address_family, char** ip_address) { if (ip_address == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } @@ -305,20 +338,20 @@ int connection_get_ip_address(connection_h connection, connection_address_family *ip_address = vconf_get_str(VCONFKEY_NETWORK_IP); break; case CONNECTION_ADDRESS_FAMILY_IPV6: - LOGI(TIZEN_NET_CONNECTION, "Not supported yet\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n"); return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; break; default: - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } if (*ip_address == NULL) { - LOGI(TIZEN_NET_CONNECTION,"vconf_get_str Failed\n"); - return CONNECTION_ERROR_INVALID_OPERATION; + CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n"); + return CONNECTION_ERROR_OPERATION_FAILED; } - LOGI(TIZEN_NET_CONNECTION,"IP Address %s\n", *ip_address); + CONNECTION_LOG(CONNECTION_INFO, "IP Address %s\n", *ip_address); return CONNECTION_ERROR_NONE; } @@ -326,7 +359,7 @@ int connection_get_ip_address(connection_h connection, connection_address_family int connection_get_proxy(connection_h connection, connection_address_family_e address_family, char** proxy) { if (proxy == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } @@ -335,20 +368,20 @@ int connection_get_proxy(connection_h connection, connection_address_family_e ad *proxy = vconf_get_str(VCONFKEY_NETWORK_PROXY); break; case CONNECTION_ADDRESS_FAMILY_IPV6: - LOGI(TIZEN_NET_CONNECTION, "Not supported yet\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Not supported yet\n"); return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; break; default: - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } if (*proxy == NULL) { - LOGI(TIZEN_NET_CONNECTION,"vconf_get_str Failed\n"); - return CONNECTION_ERROR_INVALID_OPERATION; + CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_str Failed\n"); + return CONNECTION_ERROR_OPERATION_FAILED; } - LOGI(TIZEN_NET_CONNECTION,"Proxy Address %s\n", *proxy); + CONNECTION_LOG(CONNECTION_INFO, "Proxy Address %s\n", *proxy); return CONNECTION_ERROR_NONE; } @@ -358,17 +391,17 @@ int connection_get_cellular_state(connection_h connection, connection_cellular_s int status = 0; if (state == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } if (!vconf_get_int(VCONFKEY_NETWORK_CELLULAR_STATE, &status)) { - LOGI(TIZEN_NET_CONNECTION,"Cellular = %d\n", status); + CONNECTION_LOG(CONNECTION_INFO, "Cellular = %d\n", status); *state = __connection_convert_cellular_state(status); return CONNECTION_ERROR_NONE; } else { - LOGI(TIZEN_NET_CONNECTION,"vconf_get_int Failed = %d\n", status); - return CONNECTION_ERROR_INVALID_OPERATION; + CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status); + return CONNECTION_ERROR_OPERATION_FAILED; } } @@ -377,35 +410,48 @@ int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* int status = 0; if (state == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } if (!vconf_get_int(VCONFKEY_NETWORK_WIFI_STATE, &status)) { - LOGI(TIZEN_NET_CONNECTION,"WiFi = %d\n", status); + CONNECTION_LOG(CONNECTION_INFO, "WiFi = %d\n", status); *state = __connection_convert_wifi_state(status); return CONNECTION_ERROR_NONE; } else { - LOGI(TIZEN_NET_CONNECTION,"vconf_get_int Failed = %d\n", status); - return CONNECTION_ERROR_INVALID_OPERATION; + CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d\n", status); + return CONNECTION_ERROR_OPERATION_FAILED; + } +} + +int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state) +{ + if (state == NULL || !(__connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; } + + if (_connection_libnet_get_ethernet_state(state) == false) + return CONNECTION_ERROR_OPERATION_FAILED; + + return CONNECTION_ERROR_NONE; } -int connection_set_network_state_changed_cb(connection_h connection, - connection_network_state_changed_cb callback, void* user_data) +int connection_set_type_changed_cb(connection_h connection, + connection_type_changed_cb callback, void* user_data) { if (callback == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } return __connection_set_state_changed_callback(connection, callback, user_data); } -int connection_unset_network_state_changed_cb(connection_h connection) +int connection_unset_type_changed_cb(connection_h connection) { if (!(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } @@ -416,7 +462,7 @@ int connection_set_ip_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data) { if (callback == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } @@ -426,7 +472,7 @@ int connection_set_ip_address_changed_cb(connection_h connection, int connection_unset_ip_address_changed_cb(connection_h connection) { if (!(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } @@ -437,7 +483,7 @@ int connection_set_proxy_address_changed_cb(connection_h connection, connection_address_changed_cb callback, void* user_data) { if (callback == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } @@ -447,142 +493,263 @@ int connection_set_proxy_address_changed_cb(connection_h connection, int connection_unset_proxy_address_changed_cb(connection_h connection) { if (!(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } return __connection_set_proxy_changed_callback(connection, NULL, NULL); } -static int __fill_call_statistic(connection_h connection, stat_request_e member, int *size) +int connection_add_profile(connection_h connection, connection_profile_h profile) { - if (size == NULL || !(__connection_check_handle_validity(connection))) { - LOGI(TIZEN_NET_CONNECTION, "Wrong Parameter Passed\n"); + if (!(__connection_check_handle_validity(connection)) || + !(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); return CONNECTION_ERROR_INVALID_PARAMETER; } - switch (member) { - case LAST_SENT_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get LAST_SENT_DATA_SIZE = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"LAST_SENT_DATA_SIZE:%d bytes\n", *size); + int rv = 0; - break; - case LAST_RECEIVED_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get LAST_RECEIVED_DATA_SIZE: = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"LAST_RECEIVED_DATA_SIZE:%d bytes\n", *size); - break; - case TOTAL_SENT_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get TOTAL_SENT_DATA_SIZE: = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"TOTAL_SENT_DATA_SIZE:%d bytes\n", *size); - break; - case TOTAL_RECEIVED_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get TOTAL_RECEIVED_DATA_SIZE: = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"TOTAL_RECEIVED_DATA_SIZE:%d bytes\n", *size); - break; - case LAST_WIFI_SENT_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_SNT, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get LAST_WIFI_SENT_DATA_SIZE: = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"LAST_WIFI_SENT_DATA_SIZE:%d bytes\n", *size); - break; - case LAST_WIFI_RECEIVED_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_LAST_RCV, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get LAST_WIFI_RECEIVED_DATA_SIZE: = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"LAST_WIFI_RECEIVED_DATA_SIZE:%d bytes\n", *size); - break; - case TOTAL_WIFI_SENT_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_SNT, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get TOTAL_WIFI_SENT_DATA_SIZE: = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"TOTAL_WIFI_SENT_DATA_SIZE:%d bytes\n", *size); - break; - case TOTAL_WIFI_RECEIVED_DATA_SIZE: - if (vconf_get_int(VCONFKEY_NETWORK_WIFI_PKT_TOTAL_RCV, size)) { - LOGI(TIZEN_NET_CONNECTION, - "Cannot Get TOTAL_WIFI_RECEIVED_DATA_SIZE: = %d\n", - *size); - *size = 0; - return CONNECTION_ERROR_INVALID_OPERATION; - } - LOGI(TIZEN_NET_CONNECTION,"TOTAL_WIFI_RECEIVED_DATA_SIZE:%d bytes\n", *size); - break; + net_profile_info_t *profile_info = profile; + + rv = net_add_profile(profile_info->ProfileInfo.Pdp.ServiceType, (net_profile_info_t*)profile); + if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "net_add_profile Failed = %d\n", rv); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_remove_profile(connection_h connection, connection_profile_h profile) +{ + if (!(__connection_check_handle_validity(connection)) || + !(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + int rv = 0; + net_profile_info_t *profile_info = profile; + + rv = net_delete_profile(profile_info->ProfileName); + if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "net_delete_profile Failed = %d\n", rv); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_update_profile(connection_h connection, connection_profile_h profile) +{ + if (!(__connection_check_handle_validity(connection)) || + !(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; } + + int rv = 0; + net_profile_info_t *profile_info = profile; + + rv = net_modify_profile(profile_info->ProfileName, (net_profile_info_t*)profile); + if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "net_modify_profile Failed = %d\n", rv); + return CONNECTION_ERROR_OPERATION_FAILED; + } + return CONNECTION_ERROR_NONE; } -int connection_get_last_received_data_size(connection_h connection, int *size) +int connection_get_profile_iterator(connection_h connection, + connection_iterator_type_e type, connection_profile_iterator_h* profile_iterator) +{ + if (!(__connection_check_handle_validity(connection)) || + (type != CONNECTION_ITERATOR_TYPE_REGISTERED && + type != CONNECTION_ITERATOR_TYPE_CONNECTED)) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return _connection_libnet_get_profile_iterator(type, profile_iterator); +} + +int connection_profile_iterator_next(connection_profile_iterator_h profile_iterator, connection_profile_h* profile) +{ + return _connection_libnet_get_iterator_next(profile_iterator, profile); +} + +bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator) +{ + return _connection_libnet_iterator_has_next(profile_iterator); +} + +int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator) { - return __fill_call_statistic(connection, LAST_RECEIVED_DATA_SIZE, size); + return _connection_libnet_destroy_iterator(profile_iterator); } -int connection_get_last_sent_data_size(connection_h connection, int *size) +int connection_get_current_profile(connection_h connection, connection_profile_h* profile) { - return __fill_call_statistic(connection, LAST_SENT_DATA_SIZE, size); + if (!(__connection_check_handle_validity(connection)) || profile == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return _connection_libnet_get_current_profile(profile); +} + +int connection_open_profile(connection_h connection, connection_profile_h profile) +{ + if (!(__connection_check_handle_validity(connection)) || profile == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return _connection_libnet_open_profile(profile); } -int connection_get_total_received_data_size (connection_h connection, int *size) +int connection_open_cellular_service_type(connection_h connection, + connection_cellular_service_type_e type, connection_profile_h* profile) { - return __fill_call_statistic(connection, TOTAL_RECEIVED_DATA_SIZE, size); + if (!(__connection_check_handle_validity(connection)) || profile == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return _connection_libnet_open_cellular_service_type(type, profile); } -int connection_get_total_sent_data_size (connection_h connection, int *size) +int connection_close_profile(connection_h connection, connection_profile_h profile) { - return __fill_call_statistic(connection, TOTAL_SENT_DATA_SIZE, size); + if (!(__connection_check_handle_validity(connection)) || profile == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return _connection_libnet_close_profile(profile); } -int connection_get_wifi_last_received_data_size(connection_h connection, int *size) + +/* Connection Statistics module ******************************************************************/ + +static int __get_statistic(connection_type_e connection_type, connection_statistics_type_e statistics_type, long long* llsize) { - return __fill_call_statistic(connection, LAST_WIFI_RECEIVED_DATA_SIZE, size); + int size; + unsigned long long ull_size; + int stat_type; + char *key = NULL; + + if (llsize == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + if (connection_type == CONNECTION_TYPE_CELLULAR) { + switch (statistics_type) { + case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA: + key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_SNT; + break; + case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA: + key = VCONFKEY_NETWORK_CELLULAR_PKT_LAST_RCV; + break; + case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA: + key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_SNT; + break; + case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA: + key = VCONFKEY_NETWORK_CELLULAR_PKT_TOTAL_RCV; + break; + default: + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + if (vconf_get_int(key, &size)) { + CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get %s = %d\n", key, size); + *llsize = 0; + return CONNECTION_ERROR_OPERATION_FAILED; + } + + CONNECTION_LOG(CONNECTION_INFO,"%s:%d bytes\n", key, size); + *llsize = (long long)size; + } else if (connection_type == CONNECTION_TYPE_WIFI) { + switch (statistics_type) { + case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA: + stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA; + break; + case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA: + stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA; + break; + case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA: + stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA; + break; + case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA: + stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA; + break; + default: + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + if (_connection_libnet_get_statistics(stat_type, &ull_size) != CONNECTION_ERROR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Cannot Get Wi-Fi statistics : %d\n", ull_size); + *llsize = 0; + return CONNECTION_ERROR_OPERATION_FAILED; + } + + CONNECTION_LOG(CONNECTION_INFO,"%d bytes\n", ull_size); + *llsize = (long long)ull_size; + } else + return CONNECTION_ERROR_INVALID_PARAMETER; + + return CONNECTION_ERROR_NONE; } -int connection_get_wifi_last_sent_data_size(connection_h connection, int *size) +static int __reset_statistic(connection_type_e connection_type, connection_statistics_type_e statistics_type) { - return __fill_call_statistic(connection, LAST_WIFI_SENT_DATA_SIZE, size); + int conn_type; + int stat_type; + int rv; + + if (connection_type == CONNECTION_TYPE_CELLULAR) + conn_type = NET_DEVICE_CELLULAR; + else if (connection_type == CONNECTION_TYPE_WIFI) + conn_type = NET_DEVICE_WIFI; + else + return CONNECTION_ERROR_INVALID_PARAMETER; + + switch (statistics_type) { + case CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA: + stat_type = NET_STATISTICS_TYPE_LAST_SENT_DATA; + break; + case CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA: + stat_type = NET_STATISTICS_TYPE_LAST_RECEIVED_DATA; + break; + case CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA: + stat_type = NET_STATISTICS_TYPE_TOTAL_SENT_DATA; + break; + case CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA: + stat_type = NET_STATISTICS_TYPE_TOTAL_RECEIVED_DATA; + break; + default: + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + rv = _connection_libnet_set_statistics(conn_type, stat_type); + if(rv != CONNECTION_ERROR_NONE) + return rv; + + + CONNECTION_LOG(CONNECTION_INFO,"connection_reset_statistics success\n"); + + return CONNECTION_ERROR_NONE; } -int connection_get_wifi_total_received_data_size (connection_h connection, int *size) +int connection_get_statistics(connection_type_e connection_type, connection_statistics_type_e statistics_type, long long* size) { - return __fill_call_statistic(connection, TOTAL_WIFI_RECEIVED_DATA_SIZE, size); + return __get_statistic(connection_type, statistics_type, size); } -int connection_get_wifi_total_sent_data_size (connection_h connection, int *size) +int connection_reset_statistics(connection_type_e connection_type, connection_statistics_type_e statistics_type) { - return __fill_call_statistic(connection, TOTAL_WIFI_SENT_DATA_SIZE, size); + return __reset_statistic(connection_type, statistics_type); } + diff --git a/src/connection_profile.c b/src/connection_profile.c new file mode 100755 index 0000000..6f4f9e9 --- /dev/null +++ b/src/connection_profile.c @@ -0,0 +1,1209 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <glib.h> +#include <vconf/vconf.h> +#include "net_connection_private.h" + + +static connection_cellular_service_type_e __profile_convert_to_connection_cellular_service_type(net_service_type_t svc_type) +{ + switch (svc_type) { + case NET_SERVICE_INTERNET: + return CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET; + case NET_SERVICE_MMS: + return CONNECTION_CELLULAR_SERVICE_TYPE_MMS; + case NET_SERVICE_WAP: + return CONNECTION_CELLULAR_SERVICE_TYPE_WAP; + case NET_SERVICE_PREPAID_INTERNET: + return CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET; + case NET_SERVICE_PREPAID_MMS: + return CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS; + default: + return CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN; + } +} + +static net_dev_info_t* __profile_get_net_info(net_profile_info_t *profile_info) +{ + switch (profile_info->profile_type) { + case NET_DEVICE_CELLULAR: + return &profile_info->ProfileInfo.Pdp.net_info; + case NET_DEVICE_WIFI: + return &profile_info->ProfileInfo.Wlan.net_info; + case NET_DEVICE_ETHERNET: + return &profile_info->ProfileInfo.Ethernet.net_info; + case NET_DEVICE_DEFAULT: + case NET_DEVICE_USB: + case NET_DEVICE_UNKNOWN: + case NET_DEVICE_MAX: + default: + return NULL; + } +} + +static connection_profile_state_e __profile_convert_to_cp_state(net_state_type_t state) +{ + connection_profile_state_e cp_state; + + switch (state) { + case NET_STATE_TYPE_ONLINE: + case NET_STATE_TYPE_READY: + cp_state = CONNECTION_PROFILE_STATE_CONNECTED; + break; + case NET_STATE_TYPE_IDLE: + case NET_STATE_TYPE_FAILURE: + case NET_STATE_TYPE_DISCONNECT: + cp_state = CONNECTION_PROFILE_STATE_DISCONNECTED; + break; + case NET_STATE_TYPE_ASSOCIATION: + cp_state = CONNECTION_PROFILE_STATE_ASSOCIATION; + break; + case NET_STATE_TYPE_CONFIGURATION: + cp_state = CONNECTION_PROFILE_STATE_CONFIGURATION; + break; + default: + cp_state = -1; + } + + return cp_state; +} + +static char* __profile_convert_ip_to_string(net_addr_t *ip_addr) +{ + unsigned char *ipaddr = (unsigned char *)&ip_addr->Data.Ipv4.s_addr; + + char *ipstr = g_try_malloc0(16); + if (ipstr == NULL) + return NULL; + + snprintf(ipstr, 16, "%d.%d.%d.%d", ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); + + return ipstr; +} + +net_service_type_t _connection_profile_convert_to_libnet_cellular_service_type(connection_cellular_service_type_e svc_type) +{ + switch (svc_type) { + case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET: + return NET_SERVICE_INTERNET; + case CONNECTION_CELLULAR_SERVICE_TYPE_MMS: + return NET_SERVICE_MMS; + case CONNECTION_CELLULAR_SERVICE_TYPE_WAP: + return NET_SERVICE_WAP; + case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET: + return NET_SERVICE_PREPAID_INTERNET; + case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS: + return NET_SERVICE_PREPAID_MMS; + default: + return NET_SERVICE_UNKNOWN; + } +} + +net_state_type_t _connection_profile_convert_to_net_state(connection_profile_state_e state) +{ + net_state_type_t libnet_state = NET_STATE_TYPE_UNKNOWN; + + switch (state) { + case CONNECTION_PROFILE_STATE_CONNECTED: + libnet_state = NET_STATE_TYPE_ONLINE; + break; + case CONNECTION_PROFILE_STATE_DISCONNECTED: + libnet_state = NET_STATE_TYPE_IDLE; + break; + case CONNECTION_PROFILE_STATE_ASSOCIATION: + libnet_state = NET_STATE_TYPE_ASSOCIATION; + break; + case CONNECTION_PROFILE_STATE_CONFIGURATION: + libnet_state = NET_STATE_TYPE_CONFIGURATION; + break; + } + + return libnet_state; +} + +static void __profile_init_cellular_profile(net_profile_info_t *profile_info) +{ + profile_info->profile_type = NET_DEVICE_CELLULAR; + profile_info->ProfileState = NET_STATE_TYPE_IDLE; + profile_info->ProfileInfo.Pdp.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF; + profile_info->ProfileInfo.Pdp.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT; +} + +static void __profile_init_wifi_profile(net_profile_info_t *profile_info) +{ + profile_info->profile_type = NET_DEVICE_WIFI; + profile_info->ProfileState = NET_STATE_TYPE_IDLE; + profile_info->ProfileInfo.Wlan.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF; + profile_info->ProfileInfo.Wlan.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT; + profile_info->ProfileInfo.Wlan.wlan_mode = NETPM_WLAN_CONNMODE_AUTO; + profile_info->ProfileInfo.Wlan.security_info.sec_mode = WLAN_SEC_MODE_NONE; + profile_info->ProfileInfo.Wlan.security_info.enc_mode = WLAN_ENC_MODE_NONE; +} + +static void __profile_init_ethernet_profile(net_profile_info_t *profile_info) +{ + profile_info->profile_type = NET_DEVICE_ETHERNET; + profile_info->ProfileState = NET_STATE_TYPE_IDLE; + profile_info->ProfileInfo.Ethernet.net_info.IpConfigType = NET_IP_CONFIG_TYPE_OFF; + profile_info->ProfileInfo.Ethernet.net_info.ProxyMethod = NET_PROXY_TYPE_DIRECT; +} + +/* Connection profile module *********************************************************************/ + +int connection_profile_create(connection_profile_type_e type, connection_profile_h* profile) +{ + if ((type != CONNECTION_PROFILE_TYPE_CELLULAR && + type != CONNECTION_PROFILE_TYPE_WIFI && + type != CONNECTION_PROFILE_TYPE_ETHERNET) || profile == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = g_try_malloc0(sizeof(net_profile_info_t)); + if (profile_info == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + switch (type) { + case CONNECTION_PROFILE_TYPE_CELLULAR: + __profile_init_cellular_profile(profile_info); + break; + case CONNECTION_PROFILE_TYPE_WIFI: + __profile_init_wifi_profile(profile_info); + break; + case CONNECTION_PROFILE_TYPE_ETHERNET: + __profile_init_ethernet_profile(profile_info); + break; + } + + *profile = (connection_profile_h)profile_info; + _connection_libnet_add_to_profile_list(*profile); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_destroy(connection_profile_h profile) +{ + if (!(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + _connection_libnet_remove_from_profile_list(profile); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_clone(connection_profile_h* cloned_profile, connection_profile_h origin_profile) +{ + if (!(_connection_libnet_check_profile_validity(origin_profile)) || cloned_profile == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + *cloned_profile = g_try_malloc0(sizeof(net_profile_info_t)); + if (*cloned_profile == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + memcpy(*cloned_profile, origin_profile, sizeof(net_profile_info_t)); + _connection_libnet_add_to_profile_list(*cloned_profile); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_name(connection_profile_h profile, char** profile_name) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || profile_name == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + *profile_name = g_strdup(profile_info->ProfileName); + if (*profile_name == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_type(connection_profile_h profile, connection_profile_type_e* type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + switch (profile_info->profile_type) { + case NET_DEVICE_CELLULAR: + *type = CONNECTION_PROFILE_TYPE_CELLULAR; + break; + case NET_DEVICE_WIFI: + *type = CONNECTION_PROFILE_TYPE_WIFI; + break; + case NET_DEVICE_ETHERNET: + *type = CONNECTION_PROFILE_TYPE_ETHERNET; + break; + default: + CONNECTION_LOG(CONNECTION_ERROR, "Invalid profile type\n"); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_network_interface_name(connection_profile_h profile, char** interface_name) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || interface_name == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *interface_name = g_strdup(net_info->DevName); + if (*interface_name == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_state(connection_profile_h profile, connection_profile_state_e* state) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || state == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + *state = __profile_convert_to_cp_state(profile_info->ProfileState); + if (*state < 0) + return CONNECTION_ERROR_OPERATION_FAILED; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_ip_config_type(connection_profile_h profile, connection_address_family_e address_family, connection_ip_config_type_e* type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + switch (net_info->IpConfigType) { + case NET_IP_CONFIG_TYPE_STATIC: + *type = CONNECTION_IP_CONFIG_TYPE_STATIC; + break; + case NET_IP_CONFIG_TYPE_DYNAMIC: + *type = CONNECTION_IP_CONFIG_TYPE_DYNAMIC; + break; + case NET_IP_CONFIG_TYPE_AUTO_IP: + *type = CONNECTION_IP_CONFIG_TYPE_AUTO; + break; + case NET_IP_CONFIG_TYPE_FIXED: + *type = CONNECTION_IP_CONFIG_TYPE_FIXED; + break; + case NET_IP_CONFIG_TYPE_OFF: + *type = CONNECTION_IP_CONFIG_TYPE_NONE; + break; + default: + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_ip_address(connection_profile_h profile, + connection_address_family_e address_family, char** ip_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + ip_address == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + *ip_address = __profile_convert_ip_to_string(&net_info->IpAddr); + if (*ip_address == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_subnet_mask(connection_profile_h profile, + connection_address_family_e address_family, char** subnet_mask) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + subnet_mask == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + *subnet_mask = __profile_convert_ip_to_string(&net_info->SubnetMask); + if (*subnet_mask == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_gateway_address(connection_profile_h profile, + connection_address_family_e address_family, char** gateway_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + gateway_address == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + *gateway_address = __profile_convert_ip_to_string(&net_info->GatewayAddr); + if (*gateway_address == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_dns_address(connection_profile_h profile, int order, + connection_address_family_e address_family, char** dns_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + dns_address == NULL || + order <= 0 || + order > NET_DNS_ADDR_MAX) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + *dns_address = __profile_convert_ip_to_string(&net_info->DnsAddr[order-1]); + if (*dns_address == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_proxy_type(connection_profile_h profile, connection_proxy_type_e* type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + switch (net_info->ProxyMethod) { + case NET_PROXY_TYPE_DIRECT: + *type = CONNECTION_PROXY_TYPE_DIRECT; + break; + case NET_PROXY_TYPE_AUTO: + *type = CONNECTION_PROXY_TYPE_AUTO; + break; + case NET_PROXY_TYPE_MANUAL: + *type = CONNECTION_PROXY_TYPE_MANUAL; + break; + case NET_PROXY_TYPE_UNKNOWN: + default: + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_proxy_address(connection_profile_h profile, + connection_address_family_e address_family, char** proxy_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + proxy_address == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + *proxy_address = g_strdup(net_info->ProxyAddr); + if (*proxy_address == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_ip_config_type(connection_profile_h profile, connection_address_family_e address_family, connection_ip_config_type_e type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + switch (type) { + case CONNECTION_IP_CONFIG_TYPE_STATIC: + net_info->IpConfigType = NET_IP_CONFIG_TYPE_STATIC; + break; + case CONNECTION_IP_CONFIG_TYPE_DYNAMIC: + net_info->IpConfigType = NET_IP_CONFIG_TYPE_DYNAMIC; + break; + case CONNECTION_IP_CONFIG_TYPE_AUTO: + net_info->IpConfigType = NET_IP_CONFIG_TYPE_AUTO_IP; + break; + case CONNECTION_IP_CONFIG_TYPE_FIXED: + net_info->IpConfigType = NET_IP_CONFIG_TYPE_FIXED; + break; + case CONNECTION_IP_CONFIG_TYPE_NONE: + net_info->IpConfigType = NET_IP_CONFIG_TYPE_OFF; + break; + default: + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_ip_address(connection_profile_h profile, + connection_address_family_e address_family, const char* ip_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + ip_address == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + inet_aton(ip_address, &(net_info->IpAddr.Data.Ipv4)); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_subnet_mask(connection_profile_h profile, + connection_address_family_e address_family, const char* subnet_mask) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + subnet_mask == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + inet_aton(subnet_mask, &(net_info->SubnetMask.Data.Ipv4)); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_gateway_address(connection_profile_h profile, + connection_address_family_e address_family, const char* gateway_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + gateway_address == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + inet_aton(gateway_address, &(net_info->GatewayAddr.Data.Ipv4)); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_dns_address(connection_profile_h profile, int order, + connection_address_family_e address_family, const char* dns_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + dns_address == NULL || + order <= 0 || + order > NET_DNS_ADDR_MAX) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + inet_aton(dns_address, &(net_info->DnsAddr[order-1].Data.Ipv4)); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_proxy_type(connection_profile_h profile, connection_proxy_type_e type) +{ + if (!(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + switch (type) { + case CONNECTION_PROXY_TYPE_DIRECT: + net_info->ProxyMethod = NET_PROXY_TYPE_DIRECT; + break; + case CONNECTION_PROXY_TYPE_AUTO: + net_info->ProxyMethod = NET_PROXY_TYPE_AUTO; + break; + case CONNECTION_PROXY_TYPE_MANUAL: + net_info->ProxyMethod = NET_PROXY_TYPE_MANUAL; + break; + default: + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_proxy_address(connection_profile_h profile, + connection_address_family_e address_family, const char* proxy_address) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && + address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || + proxy_address == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + net_dev_info_t *net_info = __profile_get_net_info(profile_info); + if (net_info == NULL) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) + return CONNECTION_ERROR_ADDRESS_FAMILY_NOT_SUPPORTED; + + g_strlcpy(net_info->ProxyAddr, proxy_address, NET_PROXY_LEN_MAX); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_state_changed_cb(connection_profile_h profile, + connection_profile_state_changed_cb callback, void* user_data) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || callback == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + if (_connection_libnet_add_to_profile_cb_list(profile, callback, user_data)) + return CONNECTION_ERROR_NONE; + + return CONNECTION_ERROR_OPERATION_FAILED; +} + +int connection_profile_unset_state_changed_cb(connection_profile_h profile) +{ + if (!(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + _connection_libnet_remove_from_profile_cb_list(profile); + + return CONNECTION_ERROR_NONE; +} + + +/* Wi-Fi profile module **************************************************************************/ + +int connection_profile_get_wifi_essid(connection_profile_h profile, char** essid) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || essid == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *essid = g_strdup(profile_info->ProfileInfo.Wlan.essid); + if (*essid == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_wifi_bssid(connection_profile_h profile, char** bssid) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || bssid == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *bssid = g_strdup(profile_info->ProfileInfo.Wlan.bssid); + if (*bssid == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_wifi_rssi(connection_profile_h profile, int* rssi) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || rssi == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *rssi = (int)profile_info->ProfileInfo.Wlan.Strength; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_wifi_frequency(connection_profile_h profile, int* frequency) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || frequency == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *frequency = (int)profile_info->ProfileInfo.Wlan.frequency; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_wifi_max_speed(connection_profile_h profile, int* max_speed) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || max_speed == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *max_speed = (int)profile_info->ProfileInfo.Wlan.max_rate; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_wifi_security_type(connection_profile_h profile, connection_wifi_security_type_e* type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + switch (profile_info->ProfileInfo.Wlan.security_info.sec_mode) { + case WLAN_SEC_MODE_NONE: + *type = CONNECTION_WIFI_SECURITY_TYPE_NONE; + break; + case WLAN_SEC_MODE_WEP: + *type = CONNECTION_WIFI_SECURITY_TYPE_WEP; + break; + case WLAN_SEC_MODE_IEEE8021X: + *type = CONNECTION_WIFI_SECURITY_TYPE_EAP; + break; + case WLAN_SEC_MODE_WPA_PSK: + *type = CONNECTION_WIFI_SECURITY_TYPE_WPA_PSK; + break; + case WLAN_SEC_MODE_WPA2_PSK: + *type = CONNECTION_WIFI_SECURITY_TYPE_WPA2_PSK; + break; + default: + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_wifi_encryption_type(connection_profile_h profile, connection_wifi_encryption_type_e* type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + switch (profile_info->ProfileInfo.Wlan.security_info.enc_mode) { + case WLAN_ENC_MODE_NONE: + *type = CONNECTION_WIFI_ENCRYPTION_TYPE_NONE; + break; + case WLAN_ENC_MODE_WEP: + *type = CONNECTION_WIFI_ENCRYPTION_TYPE_WEP; + break; + case WLAN_ENC_MODE_TKIP: + *type = CONNECTION_WIFI_ENCRYPTION_TYPE_TKIP; + break; + case WLAN_ENC_MODE_AES: + *type = CONNECTION_WIFI_ENCRYPTION_TYPE_AES; + break; + case WLAN_ENC_MODE_TKIP_AES_MIXED: + *type = CONNECTION_WIFI_ENCRYPTION_TYPE_TKIP_AES_MIXED; + break; + default: + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_is_wifi_passphrase_required(connection_profile_h profile, bool* required) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || required == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + if (profile_info->ProfileInfo.Wlan.PassphraseRequired) + *required = true; + else + *required = false; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_wifi_passphrase(connection_profile_h profile, const char* passphrase) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || passphrase == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + g_strlcpy(profile_info->ProfileInfo.Wlan.security_info.authentication.psk.pskKey, + passphrase, NETPM_WLAN_MAX_PSK_PASSPHRASE_LEN); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_is_wifi_wps_supported(connection_profile_h profile, bool* supported) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || supported == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_WIFI) + return CONNECTION_ERROR_INVALID_PARAMETER; + + if (profile_info->ProfileInfo.Wlan.security_info.wps_support) + *supported = true; + else + *supported = false; + + return CONNECTION_ERROR_NONE; +} + + +/* Cellular profile module ***********************************************************************/ + +int connection_profile_get_cellular_network_type(connection_profile_h profile, connection_cellular_network_type_e* type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + switch (profile_info->ProfileInfo.Pdp.ProtocolType) { + case NET_PDP_TYPE_NONE: + *type = CONNECTION_CELLULAR_NETWORK_TYPE_UNKNOWN; + break; + case NET_PDP_TYPE_GPRS: + *type = CONNECTION_CELLULAR_NETWORK_TYPE_GPRS; + break; + case NET_PDP_TYPE_EDGE: + *type = CONNECTION_CELLULAR_NETWORK_TYPE_EDGE; + break; + case NET_PDP_TYPE_UMTS: + *type = CONNECTION_CELLULAR_NETWORK_TYPE_UMTS; + break; + default: + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_cellular_service_type(connection_profile_h profile, + connection_cellular_service_type_e* type) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || type == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid profile type Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + *type = __profile_convert_to_connection_cellular_service_type(profile_info->ProfileInfo.Pdp.ServiceType); + + if (*type == CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid service type Passed\n"); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_cellular_apn(connection_profile_h profile, char** apn) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || apn == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *apn = g_strdup(profile_info->ProfileInfo.Pdp.Apn); + if (*apn == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_cellular_auth_info(connection_profile_h profile, + connection_cellular_auth_type_e* type, char** user_name, char** password) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + type == NULL || user_name == NULL || password == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + switch (profile_info->ProfileInfo.Pdp.AuthInfo.AuthType) { + case NET_PDP_AUTH_NONE: + *type = CONNECTION_CELLULAR_AUTH_TYPE_NONE; + break; + case NET_PDP_AUTH_PAP: + *type = CONNECTION_CELLULAR_AUTH_TYPE_PAP; + break; + case NET_PDP_AUTH_CHAP: + *type = CONNECTION_CELLULAR_AUTH_TYPE_CHAP; + break; + default: + return CONNECTION_ERROR_OPERATION_FAILED; + } + + *user_name = g_strdup(profile_info->ProfileInfo.Pdp.AuthInfo.UserName); + if (*user_name == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + *password = g_strdup(profile_info->ProfileInfo.Pdp.AuthInfo.Password); + if (*password == NULL) { + g_free(*user_name); + return CONNECTION_ERROR_OUT_OF_MEMORY; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_get_cellular_home_url(connection_profile_h profile, char** home_url) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || home_url == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + *home_url = g_strdup(profile_info->ProfileInfo.Pdp.HomeURL); + if (*home_url == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_is_cellular_roaming(connection_profile_h profile, bool* is_roaming) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || is_roaming == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + if (profile_info->ProfileInfo.Pdp.Roaming) + *is_roaming = true; + else + *is_roaming = false; + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_cellular_service_type(connection_profile_h profile, + connection_cellular_service_type_e service_type) +{ + if (!(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + switch (service_type) { + case CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET: + profile_info->ProfileInfo.Pdp.ServiceType = NET_SERVICE_INTERNET; + break; + case CONNECTION_CELLULAR_SERVICE_TYPE_MMS: + profile_info->ProfileInfo.Pdp.ServiceType = NET_SERVICE_MMS; + break; + case CONNECTION_CELLULAR_SERVICE_TYPE_WAP: + profile_info->ProfileInfo.Pdp.ServiceType = NET_SERVICE_WAP; + break; + case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET: + profile_info->ProfileInfo.Pdp.ServiceType = NET_SERVICE_PREPAID_INTERNET; + break; + case CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS: + profile_info->ProfileInfo.Pdp.ServiceType = NET_SERVICE_PREPAID_MMS; + break; + case CONNECTION_CELLULAR_SERVICE_TYPE_UNKNOWN: + default: + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_cellular_apn(connection_profile_h profile, const char* apn) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || apn == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + g_strlcpy(profile_info->ProfileInfo.Pdp.Apn, apn, NET_PDP_APN_LEN_MAX+1); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_cellular_auth_info(connection_profile_h profile, + connection_cellular_auth_type_e type, const char* user_name, const char* password) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || + user_name == NULL || password == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + switch (type) { + case CONNECTION_CELLULAR_AUTH_TYPE_NONE: + profile_info->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_NONE; + break; + case CONNECTION_CELLULAR_AUTH_TYPE_PAP: + profile_info->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_PAP; + break; + case CONNECTION_CELLULAR_AUTH_TYPE_CHAP: + profile_info->ProfileInfo.Pdp.AuthInfo.AuthType = NET_PDP_AUTH_CHAP; + break; + default: + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + g_strlcpy(profile_info->ProfileInfo.Pdp.AuthInfo.UserName, user_name, NET_PDP_AUTH_USERNAME_LEN_MAX+1); + g_strlcpy(profile_info->ProfileInfo.Pdp.AuthInfo.Password, password, NET_PDP_AUTH_PASSWORD_LEN_MAX+1); + + return CONNECTION_ERROR_NONE; +} + +int connection_profile_set_cellular_home_url(connection_profile_h profile, const char* home_url) +{ + if (!(_connection_libnet_check_profile_validity(profile)) || home_url == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (profile_info->profile_type != NET_DEVICE_CELLULAR) + return CONNECTION_ERROR_INVALID_PARAMETER; + + g_strlcpy(profile_info->ProfileInfo.Pdp.HomeURL, home_url, NET_HOME_URL_LEN_MAX); + + return CONNECTION_ERROR_NONE; +} + diff --git a/src/internal.c b/src/internal.c new file mode 100755 index 0000000..e104bcd --- /dev/null +++ b/src/internal.c @@ -0,0 +1,53 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <glib.h> +#include "net_connection_private.h" + + +static pthread_mutex_t connection_mutex; +static int connection_flag = 0; + + +static void __inter_mutex_init(void) +{ + if (g_atomic_int_get(&connection_flag) == 0) + if (pthread_mutex_init(&connection_mutex, NULL) != 0) + CONNECTION_LOG(CONNECTION_ERROR, "Mutex initialization failed!\n"); + + g_atomic_int_inc(&connection_flag); +} + +void __inter_mutex_destroy(void) +{ + if (g_atomic_int_dec_and_test(&connection_flag)) + pthread_mutex_destroy(&connection_mutex); +} + +void _connection_inter_mutex_lock(void) +{ + __inter_mutex_init(); + pthread_mutex_lock(&connection_mutex); +} + +void _connection_inter_mutex_unlock(void) +{ + pthread_mutex_unlock(&connection_mutex); + __inter_mutex_destroy(); +} + diff --git a/src/libnetwork.c b/src/libnetwork.c new file mode 100755 index 0000000..f92cceb --- /dev/null +++ b/src/libnetwork.c @@ -0,0 +1,612 @@ +/* + * 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 <stdio.h> +#include <string.h> +#include <glib.h> +#include <vconf/vconf.h> +#include "net_connection_private.h" + +static GSList *prof_handle_list = NULL; +static GHashTable *profile_cb_table = NULL; +static bool registered = false; + +struct _profile_cb_s { + connection_profile_state_changed_cb callback; + net_profile_info_t profile; + void *user_data; +}; + +struct _profile_list_s { + int count; + int next; + net_profile_info_t *profiles; +}; + +static struct _profile_list_s profile_iterator = {0, 0, NULL}; + + +static void __libnet_state_changed_cb(char *profile_name, net_profile_info_t *profile_info, + connection_profile_state_e state, bool is_requested) +{ + if (profile_name == NULL) + return; + + struct _profile_cb_s *cb_info; + cb_info = g_hash_table_lookup(profile_cb_table, profile_name); + + if (cb_info == NULL) + return; + + if (profile_info) + memcpy(&cb_info->profile, profile_info, sizeof(net_profile_info_t)); + else if (state >= 0) + cb_info->profile.ProfileState = _connection_profile_convert_to_net_state(state); + + if (cb_info->callback) + cb_info->callback((connection_profile_h)&cb_info->profile, + is_requested, cb_info->user_data); +} + +static void __libnet_clear_profile_list(struct _profile_list_s *profile_list) +{ + if (profile_list->count > 0) + g_free(profile_list->profiles); + + profile_list->count = 0; + profile_list->next = 0; + profile_list->profiles = NULL; +} + +static void __libnet_evt_cb(net_event_info_t* event_cb, void* user_data) +{ + bool is_requested = false; + + switch (event_cb->Event) { + case NET_EVENT_OPEN_RSP: + is_requested = true; + case NET_EVENT_OPEN_IND: + CONNECTION_LOG(CONNECTION_INFO, + "Received ACTIVATION(Open RSP/IND) response: %d \n", event_cb->Error); + + switch (event_cb->Error) { + case NET_ERR_NONE: + case NET_ERR_ACTIVE_CONNECTION_EXISTS: + CONNECTION_LOG(CONNECTION_INFO, "Activation succeeded\n"); + + net_profile_info_t *prof_info = NULL; + + if (event_cb->Datalength == sizeof(net_profile_info_t)) + prof_info = (net_profile_info_t*)event_cb->Data; + + __libnet_state_changed_cb(event_cb->ProfileName, prof_info, + CONNECTION_PROFILE_STATE_CONNECTED, is_requested); + return; + case NET_ERR_TIME_OUT: + CONNECTION_LOG(CONNECTION_ERROR, "Request time out!\n"); + break; + case NET_ERR_OPERATION_ABORTED: + CONNECTION_LOG(CONNECTION_ERROR, "Connction is aborted!\n"); + break; + case NET_ERR_UNKNOWN_METHOD: + CONNECTION_LOG(CONNECTION_ERROR, "Method not found!\n"); + break; + case NET_ERR_UNKNOWN: + CONNECTION_LOG(CONNECTION_ERROR, "Activation Failed!\n"); + break; + default: + CONNECTION_LOG(CONNECTION_ERROR, "Unknown Error!\n"); + break; + } + + __libnet_state_changed_cb(event_cb->ProfileName, NULL, + CONNECTION_PROFILE_STATE_DISCONNECTED, is_requested); + + break; + case NET_EVENT_CLOSE_RSP: + is_requested = true; + case NET_EVENT_CLOSE_IND: + CONNECTION_LOG(CONNECTION_INFO, "Got Close RSP/IND\n"); + + switch (event_cb->Error) { + case NET_ERR_NONE: + /* Successful PDP Deactivation */ + CONNECTION_LOG(CONNECTION_INFO, "Deactivation succeeded!\n"); + + net_profile_info_t prof_info; + + if (net_get_profile_info(event_cb->ProfileName, &prof_info) == NET_ERR_NONE) + __libnet_state_changed_cb(event_cb->ProfileName, &prof_info, + CONNECTION_PROFILE_STATE_DISCONNECTED, is_requested); + else + __libnet_state_changed_cb(event_cb->ProfileName, NULL, + CONNECTION_PROFILE_STATE_DISCONNECTED, is_requested); + return; + case NET_ERR_TIME_OUT: + CONNECTION_LOG(CONNECTION_ERROR, "Request time out!\n"); + break; + case NET_ERR_IN_PROGRESS: + CONNECTION_LOG(CONNECTION_ERROR, "Disconncting is in progress!\n"); + break; + case NET_ERR_OPERATION_ABORTED: + CONNECTION_LOG(CONNECTION_ERROR, "Disconnction is aborted!\n"); + break; + case NET_ERR_UNKNOWN_METHOD: + CONNECTION_LOG(CONNECTION_ERROR, "Service not found!\n"); + break; + case NET_ERR_UNKNOWN: + CONNECTION_LOG(CONNECTION_ERROR, "Deactivation Failed!\n"); + break; + default: + CONNECTION_LOG(CONNECTION_ERROR, "Unknown Error!\n"); + break; + } + + __libnet_state_changed_cb(event_cb->ProfileName, NULL, -1, is_requested); + + break; + case NET_EVENT_NET_STATE_IND: + CONNECTION_LOG(CONNECTION_INFO, "Got State changed IND\n"); + net_state_type_t *profile_state = (net_state_type_t*)event_cb->Data; + + if (event_cb->Error == NET_ERR_NONE && + event_cb->Datalength == sizeof(net_state_type_t)) { + switch (*profile_state) { + case NET_STATE_TYPE_ASSOCIATION: + CONNECTION_LOG(CONNECTION_INFO, + "Profile State : Association, profile name : %s\n", + event_cb->ProfileName); + + __libnet_state_changed_cb(event_cb->ProfileName, NULL, + CONNECTION_PROFILE_STATE_ASSOCIATION, is_requested); + break; + case NET_STATE_TYPE_CONFIGURATION: + CONNECTION_LOG(CONNECTION_INFO, + "Profile State : Configuration, profile name : %s\n", + event_cb->ProfileName); + + __libnet_state_changed_cb(event_cb->ProfileName, NULL, + CONNECTION_PROFILE_STATE_CONFIGURATION, is_requested); + break; + case NET_STATE_TYPE_IDLE: + case NET_STATE_TYPE_FAILURE: + case NET_STATE_TYPE_READY: + case NET_STATE_TYPE_ONLINE: + case NET_STATE_TYPE_DISCONNECT: + case NET_STATE_TYPE_UNKNOWN: + default: + CONNECTION_LOG(CONNECTION_INFO, + "Profile State : %d, profile name : %s\n", *profile_state, + event_cb->ProfileName); + } + } + + break; + case NET_EVENT_WIFI_SCAN_IND: + case NET_EVENT_WIFI_SCAN_RSP: + CONNECTION_LOG(CONNECTION_ERROR, "Got wifi scan IND\n"); + break; + case NET_EVENT_WIFI_POWER_IND: + case NET_EVENT_WIFI_POWER_RSP: + CONNECTION_LOG(CONNECTION_ERROR, "Got wifi power IND\n"); + break; + case NET_EVENT_WIFI_WPS_RSP: + CONNECTION_LOG(CONNECTION_ERROR, "Got wifi WPS RSP\n"); + default : + CONNECTION_LOG(CONNECTION_ERROR, "Error! Unknown Event\n\n"); + break; + } +} + +int __libnet_get_connected_count(struct _profile_list_s *profile_list) +{ + int count = 0; + int i = 0; + + for (;i < profile_list->count;i++) { + if (profile_list->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE || + profile_list->profiles[i].ProfileState == NET_STATE_TYPE_READY) + count++; + } + + return count; +} + +void __libnet_copy_connected_profile(net_profile_info_t **dest, struct _profile_list_s *source) +{ + int i = 0; + + for (;i < source->count;i++) { + if (source->profiles[i].ProfileState == NET_STATE_TYPE_ONLINE || + source->profiles[i].ProfileState == NET_STATE_TYPE_READY) { + memcpy(*dest, &source->profiles[i], sizeof(net_profile_info_t)); + (*dest)++; + } + } +} + +bool _connection_libnet_init(void) +{ + int rv; + + if (!registered) { + rv = net_register_client_ext((net_event_cb_t)__libnet_evt_cb, NET_DEVICE_DEFAULT, NULL); + if (rv != NET_ERR_NONE) + return false; + + registered = true; + + if (profile_cb_table == NULL) + profile_cb_table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); + } + + return true; +} + +bool _connection_libnet_deinit(void) +{ + if (registered) { + if (net_deregister_client_ext(NET_DEVICE_DEFAULT) != NET_ERR_NONE) + return false; + + registered = false; + + if (profile_cb_table) { + g_hash_table_destroy(profile_cb_table); + profile_cb_table = NULL; + } + + __libnet_clear_profile_list(&profile_iterator); + + if (prof_handle_list) { + g_slist_free_full(prof_handle_list, g_free); + prof_handle_list = NULL; + } + } + + return true; +} + +bool _connection_libnet_check_profile_validity(connection_profile_h profile) +{ + GSList *list; + int i = 0; + + for (list = prof_handle_list; list; list = list->next) + if (profile == list->data) return true; + + for (;i < profile_iterator.count;i++) + if (profile == &profile_iterator.profiles[i]) return true; + + struct _profile_cb_s *cb_info; + net_profile_info_t *profile_info = profile; + + cb_info = g_hash_table_lookup(profile_cb_table, profile_info->ProfileName); + if (cb_info == NULL) + return false; + + if (&cb_info->profile == profile) + return true; + + return false; +} + +bool _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state) +{ + struct _profile_list_s ethernet_profiles = {0, 0, NULL}; + net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count); + + if (ethernet_profiles.count == 0) { + *state = CONNECTION_ETHERNET_STATE_DEACTIVATED; + return true; + } + + switch (ethernet_profiles.profiles->ProfileState) { + case NET_STATE_TYPE_ONLINE: + case NET_STATE_TYPE_READY: + *state = CONNECTION_ETHERNET_STATE_CONNECTED; + break; + case NET_STATE_TYPE_IDLE: + case NET_STATE_TYPE_FAILURE: + case NET_STATE_TYPE_ASSOCIATION: + case NET_STATE_TYPE_CONFIGURATION: + case NET_STATE_TYPE_DISCONNECT: + *state = CONNECTION_ETHERNET_STATE_DISCONNECTED; + break; + default: + return false; + } + + __libnet_clear_profile_list(ðernet_profiles); + + return true; +} + +int _connection_libnet_get_profile_iterator(connection_iterator_type_e type, connection_profile_iterator_h* profile_iter_h) +{ + int count = 0; + int rv1, rv2, rv3; + net_profile_info_t *profiles = NULL; + + struct _profile_list_s wifi_profiles = {0, 0, NULL}; + struct _profile_list_s cellular_profiles = {0, 0, NULL}; + struct _profile_list_s ethernet_profiles = {0, 0, NULL}; + + __libnet_clear_profile_list(&profile_iterator); + + rv1 = net_get_profile_list(NET_DEVICE_WIFI, &wifi_profiles.profiles, &wifi_profiles.count); + if (rv1 != NET_ERR_NO_SERVICE && rv1 != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + CONNECTION_LOG(CONNECTION_INFO, "Wifi profile count : %d\n", wifi_profiles.count); + + rv2 = net_get_profile_list(NET_DEVICE_CELLULAR, &cellular_profiles.profiles, &cellular_profiles.count); + if (rv2 != NET_ERR_NO_SERVICE && rv2 != NET_ERR_NONE) { + __libnet_clear_profile_list(&wifi_profiles); + return CONNECTION_ERROR_OPERATION_FAILED; + } + CONNECTION_LOG(CONNECTION_INFO, "Cellular profile count : %d\n", cellular_profiles.count); + + rv3 = net_get_profile_list(NET_DEVICE_ETHERNET, ðernet_profiles.profiles, ðernet_profiles.count); + if (rv3 != NET_ERR_NO_SERVICE && rv3 != NET_ERR_NONE) { + __libnet_clear_profile_list(&wifi_profiles); + __libnet_clear_profile_list(&cellular_profiles); + return CONNECTION_ERROR_OPERATION_FAILED; + } + CONNECTION_LOG(CONNECTION_INFO, "Ethernet profile count : %d\n", ethernet_profiles.count); + + *profile_iter_h = &profile_iterator; + + switch (type) { + case CONNECTION_ITERATOR_TYPE_REGISTERED: + count = wifi_profiles.count + cellular_profiles.count + ethernet_profiles.count; + CONNECTION_LOG(CONNECTION_INFO, "Total profile count : %d\n", count); + if (count == 0) + return CONNECTION_ERROR_NONE; + + profiles = g_try_new0(net_profile_info_t, count); + if (profiles == NULL) { + __libnet_clear_profile_list(&wifi_profiles); + __libnet_clear_profile_list(&cellular_profiles); + __libnet_clear_profile_list(ðernet_profiles); + return CONNECTION_ERROR_OUT_OF_MEMORY; + } + + profile_iterator.profiles = profiles; + + if (wifi_profiles.count > 0) { + memcpy(profiles, wifi_profiles.profiles, + sizeof(net_profile_info_t) * wifi_profiles.count); + profiles += wifi_profiles.count; + } + + if (cellular_profiles.count > 0) { + memcpy(profiles, cellular_profiles.profiles, + sizeof(net_profile_info_t) * cellular_profiles.count); + profiles += cellular_profiles.count; + } + + if (ethernet_profiles.count > 0) + memcpy(profiles, ethernet_profiles.profiles, + sizeof(net_profile_info_t) * ethernet_profiles.count); + + break; + case CONNECTION_ITERATOR_TYPE_CONNECTED: + count = __libnet_get_connected_count(&wifi_profiles); + count += __libnet_get_connected_count(&cellular_profiles); + count += __libnet_get_connected_count(ðernet_profiles); + CONNECTION_LOG(CONNECTION_INFO, "Total connected profile count : %d\n", count); + if (count == 0) + return CONNECTION_ERROR_NONE; + + profiles = g_try_new0(net_profile_info_t, count); + if (profiles == NULL) { + __libnet_clear_profile_list(&wifi_profiles); + __libnet_clear_profile_list(&cellular_profiles); + __libnet_clear_profile_list(ðernet_profiles); + return CONNECTION_ERROR_OUT_OF_MEMORY; + } + + profile_iterator.profiles = profiles; + + if (wifi_profiles.count > 0) + __libnet_copy_connected_profile(&profiles, &wifi_profiles); + + if (cellular_profiles.count > 0) + __libnet_copy_connected_profile(&profiles, &cellular_profiles); + + if (ethernet_profiles.count > 0) + __libnet_copy_connected_profile(&profiles, ðernet_profiles); + + break; + } + + __libnet_clear_profile_list(&wifi_profiles); + __libnet_clear_profile_list(&cellular_profiles); + __libnet_clear_profile_list(ðernet_profiles); + + profile_iterator.count = count; + + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_get_iterator_next(connection_profile_iterator_h profile_iter_h, connection_profile_h *profile) +{ + if (profile_iter_h != &profile_iterator) + return CONNECTION_ERROR_INVALID_PARAMETER; + + if (profile_iterator.count <= profile_iterator.next) + return CONNECTION_ERROR_ITERATOR_END; + + *profile = &profile_iterator.profiles[profile_iterator.next]; + profile_iterator.next++; + + return CONNECTION_ERROR_NONE; +} + +bool _connection_libnet_iterator_has_next(connection_profile_iterator_h profile_iter_h) +{ + if (profile_iter_h != &profile_iterator) + return false; + + if (profile_iterator.count <= profile_iterator.next) + return false; + + return true; +} + +int _connection_libnet_destroy_iterator(connection_profile_iterator_h profile_iter_h) +{ + if (profile_iter_h != &profile_iterator) + return CONNECTION_ERROR_INVALID_PARAMETER; + + __libnet_clear_profile_list(&profile_iterator); + + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_get_current_profile(connection_profile_h *profile) +{ + net_profile_info_t active_profile; + int rv; + + rv = net_get_active_net_info(&active_profile); + if (rv == NET_ERR_NO_SERVICE) + return CONNECTION_ERROR_NO_CONNECTION; + else if (rv != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + *profile = g_try_malloc0(sizeof(net_profile_info_t)); + if (*profile == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + memcpy(*profile, &active_profile, sizeof(net_profile_info_t)); + prof_handle_list = g_slist_append(prof_handle_list, *profile); + + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_open_profile(connection_profile_h profile) +{ + if (!(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (net_open_connection_with_profile(profile_info->ProfileName) != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_open_cellular_service_type(connection_cellular_service_type_e type, connection_profile_h *profile) +{ + if (profile == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_name_t profile_name; + net_profile_info_t profile_info; + net_service_type_t service_type = _connection_profile_convert_to_libnet_cellular_service_type(type); + + if (net_open_connection_with_preference_ext(service_type, &profile_name) != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + if (net_get_profile_info(profile_name.ProfileName, &profile_info) != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + *profile = g_try_malloc0(sizeof(net_profile_info_t)); + if (*profile == NULL) + return CONNECTION_ERROR_OUT_OF_MEMORY; + + memcpy(*profile, &profile_info, sizeof(net_profile_info_t)); + prof_handle_list = g_slist_append(prof_handle_list, *profile); + + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_close_profile(connection_profile_h profile) +{ + if (!(_connection_libnet_check_profile_validity(profile))) { + CONNECTION_LOG(CONNECTION_ERROR, "Wrong Parameter Passed\n"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + net_profile_info_t *profile_info = profile; + + if (net_close_connection(profile_info->ProfileName) != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + return CONNECTION_ERROR_NONE; +} + +void _connection_libnet_add_to_profile_list(connection_profile_h profile) +{ + prof_handle_list = g_slist_append(prof_handle_list, profile); +} + +void _connection_libnet_remove_from_profile_list(connection_profile_h profile) +{ + prof_handle_list = g_slist_remove(prof_handle_list, profile); + g_free(profile); +} + +bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile, + connection_profile_state_changed_cb callback, void *user_data) +{ + net_profile_info_t *profile_info = profile; + char *profile_name = g_strdup(profile_info->ProfileName); + + struct _profile_cb_s *profile_cb_info = g_try_malloc0(sizeof(struct _profile_cb_s)); + if (profile_cb_info == NULL) { + g_free(profile_name); + return false; + } + + profile_cb_info->callback = callback; + profile_cb_info->user_data = user_data; + memcpy(&profile_cb_info->profile, profile_info, sizeof(net_profile_info_t)); + + g_hash_table_insert(profile_cb_table, profile_name, profile_cb_info); + + return true; +} + +void _connection_libnet_remove_from_profile_cb_list(connection_profile_h profile) +{ + net_profile_info_t *profile_info = profile; + g_hash_table_remove(profile_cb_table, profile_info->ProfileName); +} + +int _connection_libnet_set_statistics(net_device_t device_type, net_statistics_type_e statistics_type) +{ + if (net_set_statistics(device_type, statistics_type) != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_get_statistics(net_statistics_type_e statistics_type, unsigned long long *size) +{ + if (net_get_statistics(NET_DEVICE_WIFI, statistics_type, size) != NET_ERR_NONE) + return CONNECTION_ERROR_OPERATION_FAILED; + + return CONNECTION_ERROR_NONE; +} + diff --git a/test/connection_test.c b/test/connection_test.c index b161573..46cfe30 100644 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -28,7 +28,7 @@ #include <signal.h> #include "assert.h" #include "glib.h" -#include <net_connection.h> +#include "net_connection.h" #include <tizen_error.h> @@ -46,9 +46,9 @@ int test_get_wifi_call_statistics_info(void); connection_h connection = NULL; -static void test_state_changed_callback(connection_network_state_e state, void* user_data) +static void test_state_changed_callback(connection_type_e type, void* user_data) { - printf("State changed callback, state : %d\n", state); + printf("Type changed callback, connection type : %d\n", type); } static void test_ip_changed_callback(const char* ipv4_address, const char* ipv6_address, void* user_data) @@ -63,13 +63,111 @@ static void test_proxy_changed_callback(const char* ipv4_address, const char* ip ipv4_address, (ipv6_address ? ipv6_address : "NULL")); } +static void test_profile_state_callback(connection_profile_h profile, bool is_requested, void* user_data) +{ + connection_profile_state_e state; + char *profile_name; + + if (connection_profile_get_state(profile, &state) != CONNECTION_ERROR_NONE) + return; + + if (connection_profile_get_name(profile, &profile_name) != CONNECTION_ERROR_NONE) + return; + + switch (state) { + case CONNECTION_PROFILE_STATE_DISCONNECTED: + printf("[Disconnected] : %s\n", profile_name); + break; + case CONNECTION_PROFILE_STATE_ASSOCIATION: + printf("[Association] : %s\n", profile_name); + break; + case CONNECTION_PROFILE_STATE_CONFIGURATION: + printf("[Configuration] : %s\n", profile_name); + break; + case CONNECTION_PROFILE_STATE_CONNECTED: + printf("[Connected] : %s\n", profile_name); + } + + g_free(profile_name); +} + +static bool test_get_user_selected_profile(connection_profile_h *profile) +{ + int rv = 0; + int input = 0; + char *profile_name; + connection_profile_type_e profile_type; + connection_profile_state_e profile_state; + connection_profile_iterator_h profile_iter; + connection_profile_h profile_h; + + connection_profile_h profile_list[100] = {0,}; + int profile_count = 0; + + rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter); + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get profile iterator [%d]\n", rv); + return false; + } + + while (connection_profile_iterator_has_next(profile_iter)) { + if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile handle\n"); + return false; + } + + if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile name\n"); + return false; + } + + if (connection_profile_get_type(profile_h, &profile_type) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile type\n"); + g_free(profile_name); + return false; + } + + connection_profile_get_state(profile_h, &profile_state); + + if (profile_type == CONNECTION_PROFILE_TYPE_WIFI) { + char *essid; + connection_profile_get_wifi_essid(profile_h, &essid); + printf("%d. state:%d, profile name:%s, essid:%s\n", + profile_count, profile_state, profile_name, (essid)? essid : ""); + g_free(essid); + } else + printf("%d. state:%d, profile name : %s\n", + profile_count, profile_state, profile_name); + + g_free(profile_name); + + if (profile_count >= 100) + break; + + profile_list[profile_count] = profile_h; + profile_count++; + } + + printf("\nInput profile number : \n"); + rv = scanf("%d", &input); + + if (input >= profile_count || input < 0) { + printf("Wrong number!!\n"); + return false; + } + + *profile = profile_list[input]; + + return true; +} + int test_register_client(void) { int err = connection_create(&connection); if (CONNECTION_ERROR_NONE == err) { - connection_set_network_state_changed_cb(connection, test_state_changed_callback, NULL); + connection_set_type_changed_cb(connection, test_state_changed_callback, NULL); connection_set_ip_address_changed_cb(connection, test_ip_changed_callback, NULL); connection_set_proxy_address_changed_cb(connection, test_proxy_changed_callback, NULL); } else { @@ -102,9 +200,9 @@ int test_deregister_client(void) int test_get_network_state(void) { int rv = 0; - connection_network_state_e net_state; + connection_type_e net_state; - rv = connection_get_network_state(connection, &net_state); + rv = connection_get_type(connection, &net_state); if (rv != CONNECTION_ERROR_NONE) { printf("Fail to get network state [%d]\n", rv); @@ -186,37 +284,203 @@ int test_get_current_ip(void) int test_get_call_statistics_info(void) { - int rv = 0; + long long rv = 0; - connection_get_last_received_data_size(connection, &rv); - printf("last recv data size [%d]\n", rv); - connection_get_last_sent_data_size(connection, &rv); - printf("last sent data size [%d]\n",rv ); - connection_get_total_received_data_size (connection, &rv); - printf("total received data size [%d]\n",rv ); - connection_get_total_sent_data_size (connection, &rv); - printf("total sent data size [%d]\n", rv); + connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv); + printf("last recv data size [%lld]\n", rv); + connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv); + printf("last sent data size [%lld]\n",rv ); + connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv); + printf("total received data size [%lld]\n",rv ); + connection_get_statistics(CONNECTION_TYPE_CELLULAR, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv); + printf("total sent data size [%lld]\n", rv); return 1; } int test_get_wifi_call_statistics_info(void) { + long long rv = 0; + + connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_RECEIVED_DATA, &rv); + printf("WiFi last recv data size [%lld]\n", rv); + connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_LAST_SENT_DATA, &rv); + printf("WiFi last sent data size [%lld]\n",rv ); + connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_RECEIVED_DATA, &rv); + printf("WiFi total received data size [%lld]\n",rv ); + connection_get_statistics(CONNECTION_TYPE_WIFI, CONNECTION_STATISTICS_TYPE_TOTAL_SENT_DATA, &rv); + printf("WiFi total sent data size [%lld]\n", rv); + + return 1; +} + +int test_get_profile_list(void) +{ + int rv = 0; + char *profile_name; + connection_profile_iterator_h profile_iter; + connection_profile_h profile_h; + + rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_REGISTERED, &profile_iter); + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get profile iterator [%d]\n", rv); + return -1; + } + + while (connection_profile_iterator_has_next(profile_iter)) { + if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile handle\n"); + return -1; + } + + if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile name\n"); + return -1; + } + printf("profile name : %s\n", profile_name); + g_free(profile_name); + } + + return 1; +} + +int test_get_connected_profile_list(void) +{ + int rv = 0; + char *profile_name; + connection_profile_iterator_h profile_iter; + connection_profile_h profile_h; + + rv = connection_get_profile_iterator(connection, CONNECTION_ITERATOR_TYPE_CONNECTED, &profile_iter); + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get profile iterator [%d]\n", rv); + return -1; + } + + while (connection_profile_iterator_has_next(profile_iter)) { + if (connection_profile_iterator_next(profile_iter, &profile_h) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile handle\n"); + return -1; + } + + if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile name\n"); + return -1; + } + printf("profile name : %s\n", profile_name); + g_free(profile_name); + } + + return 1; +} + +int test_get_current_profile(void) +{ int rv = 0; + char *profile_name; + connection_profile_h profile_h; + + rv = connection_get_current_profile(connection, &profile_h); + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get profile iterator [%d]\n", rv); + return -1; + } + + if (connection_profile_get_name(profile_h, &profile_name) != CONNECTION_ERROR_NONE) { + printf("Fail to get profile name\n"); + return -1; + } + printf("profile name : %s\n", profile_name); + g_free(profile_name); + + connection_profile_destroy(profile_h); + + return 1; +} + +int test_open_profile(void) +{ + connection_profile_h profile; + if (test_get_user_selected_profile(&profile) == false) + return -1; + + if (connection_open_profile(connection, profile) != CONNECTION_ERROR_NONE) { + printf("Connection open Failed!!\n"); + return -1; + } + + if (connection_profile_set_state_changed_cb(profile, + test_profile_state_callback, NULL) != CONNECTION_ERROR_NONE) { + printf("Set profile callback Failed!!\n"); + return -1; + } + + return 1; +} + +int test_open_cellular_service_type(void) +{ + int input; + int rv; + int service_type; + connection_profile_h profile; + printf("\nInput profile type(1:Internet, 2:MMS, 3:WAP, 4:Prepaid internet, 5:Prepaid MMS : \n"); + rv = scanf("%d", &input); + + switch (input) { + case 1: + service_type = CONNECTION_CELLULAR_SERVICE_TYPE_INTERNET; + break; + case 2: + service_type = CONNECTION_CELLULAR_SERVICE_TYPE_MMS; + break; + case 3: + service_type = CONNECTION_CELLULAR_SERVICE_TYPE_WAP; + break; + case 4: + service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_INTERNET; + break; + case 5: + service_type = CONNECTION_CELLULAR_SERVICE_TYPE_PREPAID_MMS; + break; + default: + printf("Wrong number!!\n"); + return -1; + } - connection_get_wifi_last_received_data_size(connection, &rv); - printf("WiFi last recv data size [%d]\n", rv); - connection_get_wifi_last_sent_data_size(connection, &rv); - printf("WiFi last sent data size [%d]\n",rv ); - connection_get_wifi_total_received_data_size (connection, &rv); - printf("WiFi total received data size [%d]\n",rv ); - connection_get_wifi_total_sent_data_size (connection, &rv); - printf("WiFi total sent data size [%d]\n", rv); + if (connection_open_cellular_service_type(connection, service_type, &profile) != CONNECTION_ERROR_NONE) { + printf("Connection open Failed!!\n"); + return -1; + } + + if (connection_profile_set_state_changed_cb(profile, + test_profile_state_callback, NULL) != CONNECTION_ERROR_NONE) { + printf("Set profile callback Failed!!\n"); + connection_profile_destroy(profile); + return -1; + } + + connection_profile_destroy(profile); return 1; } -int main(int argc, char **argv){ +int test_close_profile(void) +{ + connection_profile_h profile; + if (test_get_user_selected_profile(&profile) == false) + return -1; + + if (connection_close_profile(connection, profile) != CONNECTION_ERROR_NONE) { + printf("Connection close Failed!!\n"); + return -1; + } + + return 1; +} + +int main(int argc, char **argv) +{ GMainLoop *mainloop; mainloop = g_main_loop_new (NULL, FALSE); @@ -255,6 +519,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("7 - Get current Ip address\n"); printf("8 - Get cellular data call statistics\n"); printf("9 - Get WiFi data call statistics\n"); + printf("a - Get Profile list\n"); + printf("b - Get Connected Profile list\n"); + printf("c - Get Current profile\n"); + printf("d - Open connection with profile\n"); + printf("e - Open cellular service type\n"); + printf("f - Close connection with profile\n"); printf("0 - Exit \n"); printf("ENTER - Show options menu.......\n"); @@ -288,6 +558,24 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case '9': { rv = test_get_wifi_call_statistics_info(); } break; + case 'a': { + rv = test_get_profile_list(); + } break; + case 'b': { + rv = test_get_connected_profile_list(); + } break; + case 'c': { + rv = test_get_current_profile(); + } break; + case 'd': { + rv = test_open_profile(); + } break; + case 'e': { + rv = test_open_cellular_service_type(); + } break; + case 'f': { + rv = test_close_profile(); + } break; } return TRUE; } |