diff options
author | jk7744.park <jk7744.park@samsung.com> | 2015-10-24 16:22:40 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2015-10-24 16:22:40 +0900 |
commit | 264829e4cbd3d10ba5925bd6022ceaf6e4140ff4 (patch) | |
tree | c6c13b421cf8051c278f9394cdd240183db69627 | |
parent | 3b319fd12772adcf57d31b5f4fc564af6ed7ff4e (diff) | |
download | connection-264829e4cbd3d10ba5925bd6022ceaf6e4140ff4.tar.gz connection-264829e4cbd3d10ba5925bd6022ceaf6e4140ff4.tar.bz2 connection-264829e4cbd3d10ba5925bd6022ceaf6e4140ff4.zip |
tizen 2.4 releasetizen_2.4_mobile_releasesubmit/tizen_2.4/20151028.063527accepted/tizen/2.4/mobile/20151029.034846tizen_2.4accepted/tizen_2.4_mobile
-rw-r--r-- | CMakeLists.txt | 14 | ||||
-rwxr-xr-x | doc/net_connection_doc.h | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | include/connection_profile.h | 10 | ||||
-rwxr-xr-x | include/net_connection.h | 112 | ||||
-rwxr-xr-x | include/net_connection_private.h | 41 | ||||
-rw-r--r-- | packaging/capi-network-connection.spec | 7 | ||||
-rwxr-xr-x | src/connection.c | 206 | ||||
-rwxr-xr-x | src/connection_profile.c | 20 | ||||
-rwxr-xr-x | src/libnetwork.c | 90 | ||||
-rwxr-xr-x | test/connection_test.c | 88 |
10 files changed, 526 insertions, 74 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 2473b3d..2c6b06c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,11 @@ SET(fw_name "capi-network-connection") PROJECT(${fw_name}) -SET(CMAKE_INSTALL_PREFIX /usr) SET(PREFIX ${CMAKE_INSTALL_PREFIX}) +SET(LIB ${LIB_PATH}) +SET(LIBDIR ${PREFIX}/${LIB_PATH}) + SET(INC_DIR include) INCLUDE_DIRECTORIES(${INC_DIR}) @@ -21,6 +23,10 @@ ENDIF(TIZEN_WEARABLE) IF(TIZEN_MOBILE) ADD_DEFINITIONS(-DTIZEN_MOBILE) ENDIF(TIZEN_MOBILE) +IF(TIZEN_TV) + ADD_DEFINITIONS(-DTIZEN_TV) +ENDIF(TIZEN_TV) + INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) @@ -38,7 +44,7 @@ ENDIF("${ARCH}" STREQUAL "arm") ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"") ADD_DEFINITIONS("-DTIZEN_DEBUG") -SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=/usr/lib") +SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIBDIR}") aux_source_directory(src SOURCES) ADD_LIBRARY(${fw_name} SHARED ${SOURCES}) @@ -52,7 +58,7 @@ SET_TARGET_PROPERTIES(${fw_name} CLEAN_DIRECT_OUTPUT 1 ) -INSTALL(TARGETS ${fw_name} DESTINATION lib) +INSTALL(TARGETS ${fw_name} DESTINATION ${LIB}) INSTALL( DIRECTORY ${INC_DIR}/ DESTINATION include/network FILES_MATCHING @@ -69,7 +75,7 @@ CONFIGURE_FILE( ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc @ONLY ) -INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION lib/pkgconfig) +INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${fw_name}.pc DESTINATION ${LIB}/pkgconfig) ADD_SUBDIRECTORY(test) diff --git a/doc/net_connection_doc.h b/doc/net_connection_doc.h index d88113f..cb3446a 100755 --- a/doc/net_connection_doc.h +++ b/doc/net_connection_doc.h @@ -48,6 +48,7 @@ * or any other network library. * @section CAPI_NETWORK_CONNECTION_MANAGER_MODULE_FEATURE Related Features * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth\n * - http://tizen.org/feature/network.wifi\n * - http://tizen.org/feature/network.telephony\n * - http://tizen.org/feature/network.tethering.bluetooth\n @@ -58,7 +59,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from <a href="../org.tizen.gettingstarted/html/native/details/app_filtering_n.htm"><b>Feature List</b>.</a> + * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature List</b>.</a> * */ @@ -75,6 +76,7 @@ * It allows you to use a handle for dealing with a connection profile. You can get details about connection using ‘connection_profile_h’ handle. * @section CAPI_NETWORK_CONNECTION_PROFILE_MODULE_FEATURE Related Features * This API is related with the following features:\n + * - http://tizen.org/feature/network.bluetooth\n * - http://tizen.org/feature/network.wifi\n * - http://tizen.org/feature/network.telephony\n * - http://tizen.org/feature/network.tethering.bluetooth\n @@ -85,7 +87,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from <a href="../org.tizen.gettingstarted/html/native/details/app_filtering_n.htm"><b>Feature List</b>.</a> + * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature List</b>.</a> * */ @@ -108,7 +110,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from <a href="../org.tizen.gettingstarted/html/native/details/app_filtering_n.htm"><b>Feature List</b>.</a> + * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature List</b>.</a> * */ @@ -131,7 +133,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from <a href="../org.tizen.gettingstarted/html/native/details/app_filtering_n.htm"><b>Feature List</b>.</a> + * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature List</b>.</a> * */ @@ -158,7 +160,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from <a href="../org.tizen.gettingstarted/html/native/details/app_filtering_n.htm"><b>Feature List</b>.</a> + * More details on featuring your application can be found from <a href="https://developer.tizen.org/development/tools/native-tools/manifest-text-editor#feature"><b>Feature List</b>.</a> * */ diff --git a/include/connection_profile.h b/include/connection_profile.h index 86860b0..433c4ca 100644..100755 --- a/include/connection_profile.h +++ b/include/connection_profile.h @@ -172,10 +172,8 @@ typedef enum{ * @details The profile name, which you get from connection_profile_get_name(), will include the keyword you set. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/network.profile \n - * %http://tizen.org/privilege/network.get - * @remarks You must release @a profile using connection_profile_destroy(). \n - * This API needs both privileges. + * @privilege %http://tizen.org/privilege/network.get + * @remarks You must release @a profile using connection_profile_destroy(). * @param[in] type The type of profile\n * #CONNECTION_PROFILE_TYPE_CELLULAR and #CONNECTION_PROFILE_TYPE_WIFI are supported. * @param[in] keyword The keyword included in profile name @@ -203,7 +201,7 @@ int connection_profile_destroy(connection_profile_h profile); /** * @brief Clones a profile handle. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @since_tizen 2.3 * @remarks You must release @a cloned_profile using connection_profile_destroy(). * @param[out] cloned_profile The handle of the cloned profile * @param[in] origin_profile The handle of the origin profile @@ -476,7 +474,7 @@ int connection_profile_set_gateway_address(connection_profile_h profile, connect * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @remarks The allowance of the DNS address is @c 2. * @param[in] profile The profile handle - * @param[in] order The order of the DNS address. \n + * @param[in] order The order of the DNS address. \n * It starts from @c 1, which means first DNS address. * @param[in] address_family The address family * @param[in] dns_address The DNS address; if you set this value to NULL, then the existing value will be deleted diff --git a/include/net_connection.h b/include/net_connection.h index 2087ea4..f658d50 100755 --- a/include/net_connection.h +++ b/include/net_connection.h @@ -83,15 +83,14 @@ typedef enum } connection_wifi_state_e; /** - * @internal * @brief Enumeration for ethernet state. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @since_tizen 2.4 */ typedef enum { - CONNECTION_ETHERNET_STATE_DEACTIVATED = 0, /**< @internal There is no Ethernet profile to open */ - CONNECTION_ETHERNET_STATE_DISCONNECTED = 1, /**< @internal Disconnected */ - CONNECTION_ETHERNET_STATE_CONNECTED = 2, /**< @internal Connected */ + CONNECTION_ETHERNET_STATE_DEACTIVATED = 0, /**< There is no Ethernet profile to open */ + CONNECTION_ETHERNET_STATE_DISCONNECTED = 1, /**< Disconnected */ + CONNECTION_ETHERNET_STATE_CONNECTED = 2, /**< Connected */ } connection_ethernet_state_e; /** @@ -127,6 +126,16 @@ typedef enum } connection_reset_option_e; /** + * @brief This enumeration defines the attached or detached state of ethernet cable. + * @since_tizen 2.4 + */ +typedef enum +{ + CONNECTION_ETHERNET_CABLE_DETACHED = 0, /**< Ethernet cable is detached */ + CONNECTION_ETHERNET_CABLE_ATTACHED = 1, /**< Ethernet cable is attached */ +} connection_ethernet_cable_state_e; + +/** * @brief Enumeration for connection errors. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif */ @@ -283,6 +292,23 @@ 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); /** + * @brief Gets the MAC address of the Wi-Fi or ethernet. + * @since_tizen 2.4 + * @remarks @a mac_addr must be released with free() by you. + * @param[in] connection The handle of the connection + * @param[in] type The type of current network connection + * @param[out] mac_addr The MAC 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 Invalid operation + * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed + * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported + * @retval #CONNECTION_ERROR_OUT_OF_MEMORY Out of memory + */ +int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr); + +/** * @brief Gets the state of cellular connection. * @details The returned state is for the cellular connection state. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -314,10 +340,9 @@ int connection_get_cellular_state(connection_h connection, connection_cellular_s int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* state); /** - * @internal * @brief Gets the state of the Ethernet. * @details The returned state is for the Ethernet connection state. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif + * @since_tizen 2.4 * @privlevel public * @privilege %http://tizen.org/privilege/network.get * @param[in] connection The connection handle @@ -332,6 +357,58 @@ int connection_get_wifi_state(connection_h connection, connection_wifi_state_e* int connection_get_ethernet_state(connection_h connection, connection_ethernet_state_e* state); /** +* @brief Checks for ethernet cable is attached or not. +* @details The returned state is for the ethernet cable state. +* @since_tizen 2.4 +* @privlevel public +* @privilege %http://tizen.org/privilege/network.get +* @param[in] connection The handle of the connection +* @param[in] state - Enum connection_ethernet_cable_state_e +* @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 +* @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported +* @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission Denied +*/ +int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state); + +/** + * @brief Called when ethernet cable is plugged [in/out]. + * @since_tizen 2.4 + * @param[in] state The ethernet cable state (connection_ethernet_cable_state_e) + * @param[in] user_data The user data passed to callback registration function + */ +typedef void(*connection_ethernet_cable_state_chaged_cb)( + connection_ethernet_cable_state_e state, void* user_data); + +/** + * @brief Registers callback for ethernet cable is plugged [in/out] event. + * @since_tizen 2.4 + * @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 + * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported + */ +int connection_set_ethernet_cable_state_chaged_cb( connection_h connection, + connection_ethernet_cable_state_chaged_cb callback, void *user_data); + +/** + * @brief Unregisters callback for ethernet cable is plugged [in/out] event. + * @since_tizen 2.4 + * @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 + * @retval #CONNECTION_ERROR_NOT_SUPPORTED Not supported + */ +int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection); + +/** * @brief Gets the state of the Bluetooth. * @details The returned state is for the Bluetooth connection state. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif @@ -424,10 +501,8 @@ int connection_unset_proxy_address_changed_cb(connection_h connection); * @brief Adds a new profile which is created by connection_profile_create(). * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/network.profile \n - * %http://tizen.org/privilege/network.get - * @remarks You can only add a profile of the cellular type. \n - * This API needs both privileges. + * @privilege %http://tizen.org/privilege/network.profile + * @remarks You can only add a profile of the cellular type. * @param[in] connection The connection handle * @param[in] profile The profile handle * @return @c 0 on success, otherwise a negative error value @@ -667,9 +742,7 @@ int connection_open_profile(connection_h connection, connection_profile_h profil * @brief Closes a connection of profile. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/network.set \n - * %http://tizen.org/privilege/network.get - * @remarks This API needs both privileges. + * @privilege %http://tizen.org/privilege/network.set * @param[in] connection The connection handle * @param[in] profile The profile handle * @param[in] callback The callback function to be called @@ -715,9 +788,7 @@ int connection_reset_profile(connection_h connection, connection_reset_option_e * @details You can get the @a interface_name from connection_profile_get_network_interface_name() of opened profile. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/network.set \n - * %http://tizen.org/privilege/network.get - * @remarks This API needs both privileges. + * @privilege %http://tizen.org/privilege/network.set * @param[in] connection The connection handle * @param[in] interface_name The name of network interface * @param[in] host_address The IP address of the host @@ -736,9 +807,7 @@ int connection_add_route(connection_h connection, const char* interface_name, co * @details You can get the @a interface_name from connection_profile_get_network_interface_name() of opened profile. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/network.set \n - * %http://tizen.org/privilege/network.get - * @remarks This API needs both privileges. + * @privilege %http://tizen.org/privilege/network.set * @param[in] connection The connection handle * @param[in] interface_name The name of network interface * @param[in] host_address The IP address of the host @@ -820,8 +889,7 @@ int connection_get_statistics(connection_h connection, connection_type_e connect * @brief Resets the statistics information. * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @privlevel public - * @privilege %http://tizen.org/privilege/network.set \n - * %http://tizen.org/privilege/network.get + * @privilege %http://tizen.org/privilege/network.set * @remarks This API needs both privileges. * @param[in] connection The connection handle * @param[in] connection_type The type of connection (only CONNECTION_TYPE_WIFI and CONNECTION_TYPE_CELLULAR are supported) diff --git a/include/net_connection_private.h b/include/net_connection_private.h index 831ee54..0a389c4 100755 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -11,7 +11,7 @@ * 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. */ #ifndef __NET_CONNECTION_PRIVATE_H__ @@ -34,10 +34,14 @@ extern "C" { #define CONNECTION_ERROR 2 #define CONNECTION_WARN 3 +#define CONNECTION_MAC_INFO_LENGTH 17 +#define ETHERNET_MAC_INFO_FILE "/sys/class/net/eth0/address" +#define WIFI_MAC_INFO_FILE "/sys/class/net/wlan0/address" + #define TELEPHONY_FEATURE "http://tizen.org/feature/network.telephony" #define WIFI_FEATURE "http://tizen.org/feature/network.wifi" -#define TETHERING_BLUETOOTH_FEATURE "http://tizen.org/feature/network.tethering.bluetooth" -#define ETHERNET_FEATURE "http://tizen.org/feature/network.ethernet" +#define TETHERING_BLUETOOTH_FEATURE "http://tizen.org/feature/network.tethering.bluetooth" +#define ETHERNET_FEATURE "http://tizen.org/feature/network.ethernet" typedef enum { @@ -45,13 +49,25 @@ typedef enum CONNECTION_CELLULAR_SUBSCRIBER_2 = 0x01, } connection_cellular_subscriber_id_e; - +typedef enum +{ + CONNECTION_SUPPORTED_FEATURE_TELEPHONY, + CONNECTION_SUPPORTED_FEATURE_WIFI, + CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH, + CONNECTION_SUPPORTED_FEATURE_ETHERNET, + CONNECTION_SUPPORTED_FEATURE_MAX, +} connection_supported_feature_e; + +#if !defined TIZEN_TV #define CHECK_FEATURE_SUPPORTED(...) \ do { \ int rv = _connection_check_feature_supported(__VA_ARGS__, NULL); \ if( rv != CONNECTION_ERROR_NONE ) \ return rv; \ } while(0) +#else +#define CHECK_FEATURE_SUPPORTED(...) +#endif #define CONNECTION_LOG(log_level, format, args...) \ do { \ @@ -84,12 +100,29 @@ typedef enum #define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE \ "db/telephony/dualsim/default_data_service" +typedef struct _connection_handle_s { + connection_type_changed_cb type_changed_callback; + connection_address_changed_cb ip_changed_callback; + connection_address_changed_cb proxy_changed_callback; + connection_ethernet_cable_state_chaged_cb ethernet_cable_state_changed_callback; + void *type_changed_user_data; + void *ip_changed_user_data; + void *proxy_changed_user_data; + void *ethernet_cable_state_changed_user_data; +} connection_handle_s; + +typedef void(*libnet_ethernet_cable_state_changed_cb) + (connection_ethernet_cable_state_e state); + bool _connection_is_created(void); int _connection_libnet_init(void); bool _connection_libnet_deinit(void); int _connection_libnet_get_wifi_state(connection_wifi_state_e *state); int _connection_libnet_get_ethernet_state(connection_ethernet_state_e *state); +int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state); +int _connection_libnet_set_ethernet_cable_state_changed_cb( + libnet_ethernet_cable_state_changed_cb callback); int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state); bool _connection_libnet_check_profile_validity(connection_profile_h profile); bool _connection_libnet_check_profile_cb_validity(connection_profile_h profile); diff --git a/packaging/capi-network-connection.spec b/packaging/capi-network-connection.spec index 298c472..9400d20 100644 --- a/packaging/capi-network-connection.spec +++ b/packaging/capi-network-connection.spec @@ -1,6 +1,6 @@ Name: capi-network-connection Summary: Network Connection library in TIZEN C API -Version: 1.0.58 +Version: 1.0.72 Release: 1 Group: System/Network License: Apache-2.0 @@ -35,6 +35,7 @@ Network Connection library in Tizen C API (Development) export CFLAGS+=' -Wno-unused-local-typedefs' MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` cmake -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \ + -DLIB_PATH=%{_lib} \ %if 0%{?model_build_feature_network_dsds} == 1 -DTIZEN_DUALSIM_ENABLE=1 \ %endif @@ -43,6 +44,10 @@ cmake -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \ %else %if "%{?tizen_profile_name}" == "mobile" -DTIZEN_MOBILE=1 \ +%else +%if "%{?tizen_profile_name}" == "tv" + -DTIZEN_TV=1 \ +%endif %endif %endif . diff --git a/src/connection.c b/src/connection.c index 0cb4f82..da5e609 100755 --- a/src/connection.c +++ b/src/connection.c @@ -21,15 +21,6 @@ #include "net_connection_private.h" -typedef struct _connection_handle_s { - connection_type_changed_cb type_changed_callback; - connection_address_changed_cb ip_changed_callback; - connection_address_changed_cb proxy_changed_callback; - void *type_changed_user_data; - void *ip_changed_user_data; - void *proxy_changed_user_data; -} connection_handle_s; - static __thread GSList *conn_handle_list = NULL; static int __connection_convert_net_state(int status) @@ -129,6 +120,33 @@ static void __connection_cb_type_change_cb(keynode_t *node, void *user_data) } } +static void __connection_cb_ethernet_cable_state_changed_cb(connection_ethernet_cable_state_e state) +{ + CONNECTION_LOG(CONNECTION_INFO, "Ethernet Cable state Indication"); + + GSList *list; + + for (list = conn_handle_list; list; list = list->next) { + connection_handle_s *local_handle = (connection_handle_s *)list->data; + if (local_handle->ethernet_cable_state_changed_callback) + local_handle->ethernet_cable_state_changed_callback(state, + local_handle->ethernet_cable_state_changed_user_data); + } +} + +static int __connection_get_ethernet_cable_state_changed_callback_count(void) +{ + GSList *list; + int count = 0; + + for (list = conn_handle_list; list; list = list->next) { + connection_handle_s *local_handle = (connection_handle_s *)list->data; + if (local_handle->ethernet_cable_state_changed_callback) count++; + } + + return count; +} + static int __connection_set_type_changed_callback(connection_h connection, void *callback, void *user_data) { @@ -340,6 +358,26 @@ static int __connection_set_proxy_changed_callback(connection_h connection, return CONNECTION_ERROR_NONE; } +static int __connection_set_ethernet_cable_state_changed_cb(connection_h connection, + connection_ethernet_cable_state_chaged_cb callback, void *user_data) +{ + connection_handle_s *local_handle = (connection_handle_s *)connection; + + if (callback) { + if (__connection_get_ethernet_cable_state_changed_callback_count() == 0) + _connection_libnet_set_ethernet_cable_state_changed_cb( + __connection_cb_ethernet_cable_state_changed_cb); + + } else { + if (__connection_get_ethernet_cable_state_changed_callback_count() == 1) + _connection_libnet_set_ethernet_cable_state_changed_cb(NULL); + } + + local_handle->ethernet_cable_state_changed_callback = callback; + local_handle->ethernet_cable_state_changed_user_data = user_data; + return CONNECTION_ERROR_NONE; +} + static int __connection_get_handle_count(void) { return ((int)g_slist_length(conn_handle_list)); @@ -390,6 +428,7 @@ EXPORT_API int connection_destroy(connection_h connection) __connection_set_type_changed_callback(connection, NULL, NULL); __connection_set_ip_changed_callback(connection, NULL, NULL); __connection_set_proxy_changed_callback(connection, NULL, NULL); + __connection_set_ethernet_cable_state_changed_cb(connection, NULL, NULL); conn_handle_list = g_slist_remove(conn_handle_list, connection); @@ -406,6 +445,9 @@ EXPORT_API int connection_destroy(connection_h connection) EXPORT_API int connection_get_type(connection_h connection, connection_type_e* type) { + int rv = 0; + int status = 0; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); if (type == NULL || !(__connection_check_handle_validity(connection))) { @@ -413,8 +455,8 @@ EXPORT_API int connection_get_type(connection_h connection, connection_type_e* t return CONNECTION_ERROR_INVALID_PARAMETER; } - int status = 0; - if (vconf_get_int(VCONFKEY_NETWORK_STATUS, &status)) { + rv = vconf_get_int(VCONFKEY_NETWORK_STATUS, &status); + if (rv != VCONF_OK) { CONNECTION_LOG(CONNECTION_ERROR, "vconf_get_int Failed = %d", status); return CONNECTION_ERROR_OPERATION_FAILED; } @@ -482,6 +524,100 @@ EXPORT_API int connection_get_proxy(connection_h connection, return CONNECTION_ERROR_NONE; } +EXPORT_API int connection_get_mac_address(connection_h connection, connection_type_e type, char** mac_addr) +{ + FILE *fp; + char buf[CONNECTION_MAC_INFO_LENGTH + 1]; + + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE, ETHERNET_FEATURE); + + if(type == CONNECTION_TYPE_WIFI) + CHECK_FEATURE_SUPPORTED(WIFI_FEATURE); + else if(type == CONNECTION_TYPE_ETHERNET) + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + + if (mac_addr == NULL || !(__connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + switch (type) { + case CONNECTION_TYPE_WIFI: +#if defined TIZEN_TV + fp = fopen(WIFI_MAC_INFO_FILE, "r"); + if (fp == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", WIFI_MAC_INFO_FILE); + return CONNECTION_ERROR_OUT_OF_MEMORY; + } + + if (fgets(buf, sizeof(buf), fp) == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", WIFI_MAC_INFO_FILE); + fclose(fp); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + CONNECTION_LOG(CONNECTION_INFO, "%s : %s", WIFI_MAC_INFO_FILE, buf); + + *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1); + if (*mac_addr == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); + fclose(fp); + return CONNECTION_ERROR_OUT_OF_MEMORY; + } + g_strlcpy(*mac_addr, buf, CONNECTION_MAC_INFO_LENGTH + 1); + fclose(fp); +#else + *mac_addr = vconf_get_str(VCONFKEY_WIFI_BSSID_ADDRESS); + + if(*mac_addr == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to get vconf from %s", VCONFKEY_WIFI_BSSID_ADDRESS); + return CONNECTION_ERROR_OPERATION_FAILED; + } +#endif + break; + case CONNECTION_TYPE_ETHERNET: + fp = fopen(ETHERNET_MAC_INFO_FILE, "r"); + if (fp == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to open file %s", ETHERNET_MAC_INFO_FILE); + return CONNECTION_ERROR_OUT_OF_MEMORY; + } + + if (fgets(buf, sizeof(buf), fp) == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to get MAC info from %s", ETHERNET_MAC_INFO_FILE); + fclose(fp); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + CONNECTION_LOG(CONNECTION_INFO, "%s : %s", ETHERNET_MAC_INFO_FILE, buf); + + *mac_addr = (char *)malloc(CONNECTION_MAC_INFO_LENGTH + 1); + if (*mac_addr == NULL) { + CONNECTION_LOG(CONNECTION_ERROR, "malloc() failed"); + fclose(fp); + return CONNECTION_ERROR_OUT_OF_MEMORY; + } + + g_strlcpy(*mac_addr, buf,CONNECTION_MAC_INFO_LENGTH + 1); + fclose(fp); + + break; + default: + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + /* Checking Invalid MAC Address */ + if((strcmp(*mac_addr, "00:00:00:00:00:00") == 0) || + (strcmp(*mac_addr, "ff:ff:ff:ff:ff:ff") == 0)) { + CONNECTION_LOG(CONNECTION_ERROR, "MAC Address(%s) is invalid", *mac_addr); + return CONNECTION_ERROR_INVALID_OPERATION; + } + + CONNECTION_LOG(CONNECTION_INFO, "MAC Address %s", *mac_addr); + + return CONNECTION_ERROR_NONE; +} + EXPORT_API int connection_get_cellular_state(connection_h connection, connection_cellular_state_e* state) { int rv = 0; @@ -580,6 +716,45 @@ EXPORT_API int connection_get_ethernet_state(connection_h connection, connection return _connection_libnet_get_ethernet_state(state); } +EXPORT_API int connection_get_ethernet_cable_state(connection_h connection, connection_ethernet_cable_state_e *state) +{ + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + + if (state == NULL || !(__connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return _connection_libnet_get_ethernet_cable_state(state); +} + +EXPORT_API int connection_set_ethernet_cable_state_chaged_cb(connection_h connection, + connection_ethernet_cable_state_chaged_cb callback, void *user_data) +{ + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + + if (callback == NULL || !(__connection_check_handle_validity(connection))) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return __connection_set_ethernet_cable_state_changed_cb(connection, + callback, user_data); +} + +EXPORT_API int connection_unset_ethernet_cable_state_chaged_cb(connection_h connection) +{ + CHECK_FEATURE_SUPPORTED(ETHERNET_FEATURE); + + if ( !(__connection_check_handle_validity(connection)) ) { + CONNECTION_LOG(CONNECTION_ERROR, "Invalid parameter"); + return CONNECTION_ERROR_INVALID_PARAMETER; + } + + return __connection_set_ethernet_cable_state_changed_cb(connection, + NULL, NULL); +} + EXPORT_API int connection_get_bt_state(connection_h connection, connection_bt_state_e* state) { CHECK_FEATURE_SUPPORTED(TETHERING_BLUETOOTH_FEATURE); @@ -740,7 +915,7 @@ EXPORT_API int connection_update_profile(connection_h connection, connection_pro int rv = 0; net_profile_info_t *profile_info = profile; - CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE); + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE); if (!(__connection_check_handle_validity(connection)) || !(_connection_libnet_check_profile_validity(profile))) { @@ -780,18 +955,21 @@ EXPORT_API int connection_profile_iterator_next(connection_profile_iterator_h pr connection_profile_h* profile) { CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + return _connection_libnet_get_iterator_next(profile_iterator, profile); } EXPORT_API bool connection_profile_iterator_has_next(connection_profile_iterator_h profile_iterator) { CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + return _connection_libnet_iterator_has_next(profile_iterator); } EXPORT_API int connection_destroy_profile_iterator(connection_profile_iterator_h profile_iterator) { CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + return _connection_libnet_destroy_iterator(profile_iterator); } @@ -923,7 +1101,7 @@ EXPORT_API int connection_remove_route(connection_h connection, const char* inte EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway) { - CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE); + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE); if (!(__connection_check_handle_validity(connection)) || interface_name == NULL || host_address == NULL) { @@ -936,7 +1114,7 @@ EXPORT_API int connection_add_route_ipv6(connection_h connection, const char *in EXPORT_API int connection_remove_route_ipv6(connection_h connection, const char *interface_name, const char *host_address, const char * gateway) { - CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE); + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, ETHERNET_FEATURE); if (!(__connection_check_handle_validity(connection)) || interface_name == NULL || host_address == NULL) { diff --git a/src/connection_profile.c b/src/connection_profile.c index d6a9f49..3005b69 100755 --- a/src/connection_profile.c +++ b/src/connection_profile.c @@ -411,6 +411,8 @@ EXPORT_API int connection_profile_get_network_interface_name(connection_profile_ EXPORT_API int connection_profile_refresh(connection_profile_h profile) { + int rv; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); if (!(_connection_libnet_check_profile_validity(profile))) { @@ -421,7 +423,7 @@ EXPORT_API int connection_profile_refresh(connection_profile_h profile) net_profile_info_t profile_info_local; net_profile_info_t *profile_info = profile; - int rv = net_get_profile_info(profile_info->ProfileName, &profile_info_local); + rv = net_get_profile_info(profile_info->ProfileName, &profile_info_local); if (rv == NET_ERR_ACCESS_DENIED) { CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); return CONNECTION_ERROR_PERMISSION_DENIED; @@ -455,9 +457,10 @@ EXPORT_API int connection_profile_get_state(connection_profile_h profile, connec EXPORT_API int connection_profile_get_ip_config_type(connection_profile_h profile, connection_address_family_e address_family, connection_ip_config_type_e* type) { - CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); net_ip_config_type_t profile_type; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -557,9 +560,10 @@ EXPORT_API int connection_profile_get_ip_address(connection_profile_h profile, EXPORT_API int connection_profile_get_subnet_mask(connection_profile_h profile, connection_address_family_e address_family, char** subnet_mask) { - CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); char* prefixlen; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6) || @@ -575,8 +579,11 @@ EXPORT_API int connection_profile_get_subnet_mask(connection_profile_h profile, if (address_family == CONNECTION_ADDRESS_FAMILY_IPV6) { prefixlen = g_try_malloc0(MAX_PREFIX_LENGTH); - snprintf(prefixlen, MAX_PREFIX_LENGTH, "%d", net_info->PrefixLen6); - *subnet_mask = prefixlen; + if (prefixlen != NULL) { + snprintf(prefixlen, MAX_PREFIX_LENGTH, "%d", net_info->PrefixLen6); + *subnet_mask = prefixlen; + } else + *subnet_mask = NULL; } else *subnet_mask = __profile_convert_ip_to_string(&net_info->SubnetMask, address_family); @@ -725,9 +732,10 @@ EXPORT_API int connection_profile_get_proxy_address(connection_profile_h profile EXPORT_API int connection_profile_set_ip_config_type(connection_profile_h profile, connection_address_family_e address_family, connection_ip_config_type_e type) { - CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); net_ip_config_type_t *profile_type = NULL; + CHECK_FEATURE_SUPPORTED(TELEPHONY_FEATURE, WIFI_FEATURE, TETHERING_BLUETOOTH_FEATURE, ETHERNET_FEATURE); + if (!(_connection_libnet_check_profile_validity(profile)) || (address_family != CONNECTION_ADDRESS_FAMILY_IPV4 && address_family != CONNECTION_ADDRESS_FAMILY_IPV6)) { diff --git a/src/libnetwork.c b/src/libnetwork.c index 2ac48ba..cda1205 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -11,7 +11,7 @@ * 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 <glib.h> @@ -44,6 +44,7 @@ struct _libnet_s { connection_closed_cb closed_cb; connection_set_default_cb set_default_cb; connection_reset_cb reset_profile_cb; + libnet_ethernet_cable_state_changed_cb ethernet_cable_state_changed_cb; void *opened_user_data; void *closed_user_data; void *set_default_user_data; @@ -66,6 +67,8 @@ struct managed_idle_data { static __thread struct _profile_list_s profile_iterator = {0, 0, NULL}; static __thread struct _libnet_s libnet = {NULL, NULL, NULL, NULL, NULL, NULL, false}; static __thread GSList *managed_idler_list = NULL; +static __thread bool connection_is_feature_checked[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, }; +static __thread bool connection_feature_supported[CONNECTION_SUPPORTED_FEATURE_MAX] = {0, }; bool _connection_is_created(void) { @@ -295,6 +298,19 @@ static void __libnet_default_cb(connection_error_e result) _connection_callback_add(__libnet_default_cb_idle, (gpointer)result); } +static void __libnet_set_ethernet_cable_state_changed_cb( + libnet_ethernet_cable_state_changed_cb user_cb) +{ + libnet.ethernet_cable_state_changed_cb = user_cb; +} + +static void __libnet_ethernet_cable_state_changed_cb( + connection_ethernet_cable_state_e state) +{ + if (libnet.ethernet_cable_state_changed_cb) + libnet.ethernet_cable_state_changed_cb(state); +} + static gboolean __libnet_state_changed_cb_idle(gpointer data) { struct _state_notify *notify = (struct _state_notify *)data; @@ -443,6 +459,16 @@ static void __libnet_evt_cb(net_event_info_t *event_cb, void *user_data) result = __libnet_convert_to_cp_error_type(event_cb->Error); CONNECTION_LOG(CONNECTION_INFO, "Got reset default profile RSP %d", result); __libnet_reset_profile_cb(result); + break; + case NET_EVENT_ETHERNET_CABLE_ATTACHED: + CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable Attached Indication\n"); + __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_ATTACHED); + break; + case NET_EVENT_ETHERNET_CABLE_DETACHED: + CONNECTION_LOG(CONNECTION_INFO, "Got Ethernet cable detached Indication\n"); + __libnet_ethernet_cable_state_changed_cb(CONNECTION_ETHERNET_CABLE_DETACHED); + break; + default : break; } @@ -660,6 +686,35 @@ int _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state) return CONNECTION_ERROR_NONE; } +int _connection_libnet_get_ethernet_cable_state(connection_ethernet_cable_state_e* state) +{ + int rv = 0; + int status = 0; + + rv = net_get_ethernet_cable_state(&status); + if (rv == NET_ERR_ACCESS_DENIED) { + CONNECTION_LOG(CONNECTION_ERROR, "Access denied"); + return CONNECTION_ERROR_PERMISSION_DENIED; + } else if (rv != NET_ERR_NONE) { + CONNECTION_LOG(CONNECTION_ERROR, "Failed to get ethernet cable state[%d]", rv); + return CONNECTION_ERROR_OPERATION_FAILED; + } + + if(status == 1) + *state = CONNECTION_ETHERNET_CABLE_ATTACHED; + else + *state = CONNECTION_ETHERNET_CABLE_DETACHED; + return CONNECTION_ERROR_NONE; +} + +int _connection_libnet_set_ethernet_cable_state_changed_cb( + libnet_ethernet_cable_state_changed_cb callback) +{ + __libnet_set_ethernet_cable_state_changed_cb(callback); + + return CONNECTION_ERROR_NONE; +} + int _connection_libnet_get_bluetooth_state(connection_bt_state_e* state) { int i = 0; @@ -1300,6 +1355,7 @@ bool _connection_libnet_add_to_profile_cb_list(connection_profile_h profile, profile_cb_info->callback = callback; profile_cb_info->user_data = user_data; + profile_cb_info->state = _profile_convert_to_cp_state(profile_info->ProfileState); g_hash_table_replace(profile_cb_table, profile_name, profile_cb_info); @@ -1463,20 +1519,42 @@ int _connection_libnet_check_profile_privilege() return CONNECTION_ERROR_NONE; } +bool __libnet_check_feature_supported(const char *key, connection_supported_feature_e feature) +{ + if(!connection_is_feature_checked[feature]) { + if(system_info_get_platform_bool(key, &connection_feature_supported[feature]) < 0) { + CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); + set_last_result(CONNECTION_ERROR_OPERATION_FAILED); + return CONNECTION_ERROR_OPERATION_FAILED; + } + connection_is_feature_checked[feature] = true; + } + return connection_feature_supported[feature]; +} + int _connection_check_feature_supported(const char *feature_name, ...) { va_list list; const char *key; - bool value, feature_supported = false; + bool value = false; + bool feature_supported = false; va_start(list, feature_name); key = feature_name; while(1) { - if(system_info_get_platform_bool(key, &value) < 0) { - CONNECTION_LOG(CONNECTION_ERROR, "Error - Feature getting from System Info"); - set_last_result(CONNECTION_ERROR_OPERATION_FAILED); - return CONNECTION_ERROR_OPERATION_FAILED; + if((strcmp(key, TELEPHONY_FEATURE) == 0)){ + value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TELEPHONY); + } + if((strcmp(key, WIFI_FEATURE) == 0)){ + value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_WIFI); + } + if((strcmp(key, TETHERING_BLUETOOTH_FEATURE) == 0)){ + value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_TETHERING_BLUETOOTH); } + if((strcmp(key, ETHERNET_FEATURE) == 0)){ + value = __libnet_check_feature_supported(key, CONNECTION_SUPPORTED_FEATURE_ETHERNET); + } + SECURE_CONNECTION_LOG(CONNECTION_INFO, "%s feature is %s", key, (value?"true":"false")); feature_supported |= value; key = va_arg(list, const char *); diff --git a/test/connection_test.c b/test/connection_test.c index 381d0ad..dde3efd 100755 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -48,9 +48,7 @@ static bool test_get_user_string(const char *msg, char *buf, int buf_size) return false; } - if (rv >= 0) - buf[rv] = '\0'; - + buf[rv-1]='\0'; return true; } @@ -191,6 +189,15 @@ static void test_connection_set_default_callback(connection_error_e result, void printf("Default profile setting Failed, err : [%s]\n", test_print_error(result)); } +void test_get_ethernet_cable_state_callback(connection_ethernet_cable_state_e state, + void* user_data) +{ + if(state == CONNECTION_ETHERNET_CABLE_ATTACHED) + printf("Ethernet Cable Connected\n"); + else if(state == CONNECTION_ETHERNET_CABLE_DETACHED) + printf("Ethernet Cable Disconnected\n"); +} + static bool test_get_user_selected_profile(connection_profile_h *profile, bool select) { int rv = 0; @@ -244,8 +251,13 @@ static bool test_get_user_selected_profile(connection_profile_h *profile, bool s profile_list[profile_count] = profile_h; profile_count++; } else { - printf("%d. state:[%s], profile name : %s\n", - profile_count, test_print_state(profile_state), profile_name); + connection_cellular_service_type_e service_type; + if (connection_profile_get_cellular_service_type(profile_h, &service_type) != CONNECTION_ERROR_NONE) { + printf("Fail to get cellular service type!\n"); + } + + printf("%d. state:[%s], profile name:%s[%d]\n", + profile_count, test_print_state(profile_state), profile_name, service_type); profile_list[profile_count] = profile_h; profile_count++; @@ -721,6 +733,8 @@ int test_register_client(void) connection_set_type_changed_cb(connection, test_type_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); + connection_set_ethernet_cable_state_chaged_cb(connection, + test_get_ethernet_cable_state_callback, NULL); } else { printf("Client registration failed [%s]\n", test_print_error(err)); return -1; @@ -1053,7 +1067,7 @@ int test_get_default_cellular_service_type(void) char *profile_name = NULL; rv = test_get_user_int("Input profile type to get" - "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering):", &input); + "(1:Internet, 2:MMS, 3:Prepaid internet, 4:Prepaid MMS, 5:Tethering, 6:Application):", &input); if (rv == false) { printf("Invalid input!!\n"); @@ -1076,6 +1090,9 @@ int test_get_default_cellular_service_type(void) case 5: service_type = CONNECTION_CELLULAR_SERVICE_TYPE_TETHERING; break; + case 6: + service_type = CONNECTION_CELLULAR_SERVICE_TYPE_APPLICATION; + break; default: printf("Wrong number!!\n"); return -1; @@ -1600,6 +1617,57 @@ int test_get_profile_id(void) return 1; } +int test_get_mac_address(void) +{ + int rv = 0, type = 0; + connection_type_e conn_type; + char *mac_addr = NULL; + + test_get_user_int("Input connection type (1:wifi, 2:ethernet)", &type); + + switch (type) { + case 1: + conn_type = CONNECTION_TYPE_WIFI; + break; + case 2: + conn_type = CONNECTION_TYPE_ETHERNET; + break; + default: + printf("Wrong number!!\n"); + return -1; + } + + rv = connection_get_mac_address(connection, conn_type, &mac_addr); + + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get MAC address [%s]\n", test_print_error(rv)); + return -1; + } + + printf("mac address is %s\n", mac_addr); + + g_free(mac_addr); + + return 1; +} + +int test_get_ethernet_cable_state(void) +{ + int rv = 0; + connection_ethernet_cable_state_e cable_state; + + rv = connection_get_ethernet_cable_state(connection, &cable_state); + + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get ethernet cable state [%s]\n", test_print_error(rv)); + return -1; + } + + printf("Retval = [%s], Ethernet cable state [%d]\n", test_print_error(rv), cable_state); + + return 1; +} + int test_reset_profile(void) { int type, sim_id, rv; @@ -1691,6 +1759,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("t - Get profile id\n"); printf("u - Reset profile\n"); printf("v - Get all cellular default profiles\n"); + printf("w - Get mac address\n"); + printf("x - Get ethernet cable state\n"); printf("B - Add IPv6 new route\n"); printf("C - Remove IPv6 route\n"); printf("0 - Exit \n"); @@ -1791,6 +1861,12 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 'v': rv = test_get_default_profile_list(); break; + case 'w': + rv = test_get_mac_address(); + break; + case 'x': + rv = test_get_ethernet_cable_state(); + break; case 'B': rv = test_add_route_ipv6(); break; |