From: taesub kim Date: Fri, 29 May 2015 07:06:26 +0000 (-0700) Subject: Merge "Add test case for ethernet profile" into tizen X-Git-Tag: submit/tizen/20150530.015007~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8433592fea2c60f6909d138b2ecacf5bd2ddab79;hp=f526008a9cc4c26dbbcdb70f6df03036044d68c1;p=platform%2Fcore%2Fapi%2Fconnection.git Merge "Add test case for ethernet profile" into tizen --- diff --git a/include/connection_profile.h b/include/connection_profile.h index 2cfd0a5..ebcc3d8 100644 --- a/include/connection_profile.h +++ b/include/connection_profile.h @@ -183,10 +183,8 @@ typedef enum{ * @details The profile name, which you get from connection_profile_get_name(), will include the keyword you set. * @since_tizen 2.3 * @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 diff --git a/include/net_connection.h b/include/net_connection.h old mode 100755 new mode 100644 index 964f21a..6b29fe0 --- 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 2.3 + * @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 2.3 */ @@ -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 2.3 @@ -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 2.3 + * @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 2.3 @@ -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 2.3 * @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 2.3 * @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 @@ -711,13 +784,11 @@ int connection_close_profile(connection_h connection, connection_profile_h profi int connection_reset_profile(connection_h connection, connection_reset_option_e type, int id, connection_reset_cb callback, void *user_data); /** - * @brief Adds a route to the routing table. + * @brief Adds a IPv4 route to the routing table. * @details You can get the @a interface_name from connection_profile_get_network_interface_name() of opened profile. * @since_tizen 2.3 * @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 @@ -732,19 +803,36 @@ int connection_reset_profile(connection_h connection, connection_reset_option_e int connection_add_route(connection_h connection, const char* interface_name, const char* host_address); /** - * @brief Removes a route from the routing table. + * @brief Removes a IPv4 route from the routing table. * @details You can get the @a interface_name from connection_profile_get_network_interface_name() of opened profile. * @since_tizen 2.3 * @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 * @return @c 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_PERMISSION_DENIED Permission Denied + * @see connection_profile_get_network_interface_name() + */ +int connection_remove_route(connection_h connection, const char* interface_name, const char* host_address); + +/** + * @brief Adds a IPv6 route to the routing table. + * @details You can get the @a interface_name from connection_profile_get_network_interface_name() of opened profile. + * @since_tizen 2.3.1 + * @privlevel public + * @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 + * @param[in] gateway The gateway address + * @return @c 0 on success, otherwise negative error value + * @retval #CONNECTION_ERROR_NONE Successful + * @retval #CONNECTION_ERROR_INVALID_PARAMETER Invalid parameter * @retval #CONNECTION_ERROR_ALREADY_EXISTS Already exists * @retval #CONNECTION_ERROR_OPERATION_FAILED Operation failed * @retval #CONNECTION_ERROR_PERMISSION_DENIED Permission Denied @@ -782,8 +870,7 @@ int connection_get_statistics(connection_h connection, connection_type_e connect * @brief Resets the statistics information. * @since_tizen 2.3 * @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 old mode 100755 new mode 100644 index e78c5d6..997dd34 --- a/include/net_connection_private.h +++ b/include/net_connection_private.h @@ -34,6 +34,10 @@ 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" + typedef enum { FEATURE_TYPE_TELEPHONY = 0, @@ -81,23 +85,29 @@ typedef enum #define VCONF_TELEPHONY_DEFAULT_DATA_SERVICE \ "db/telephony/dualsim/default_data_service" -bool _connection_is_created(void); - -typedef struct _connection_handle_s -{ +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 *state_changed_user_data; + 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 1b2bba8..58c0569 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: 0.1.3_21 +Version: 0.1.3_22 Release: 1 Group: System/Network License: Apache-2.0 @@ -53,6 +53,7 @@ cp LICENSE.APLv2 %{buildroot}%{_datadir}/license/capi-network-connection %manifest %{name}.manifest %attr(644,-,-) %{_libdir}/libcapi-network-connection.so.* %{_datadir}/license/capi-network-connection +%{_bindir}/connection_test %files devel %manifest %{name}.manifest diff --git a/src/connection.c b/src/connection.c index 55cbda8..0c057ef 100644 --- a/src/connection.c +++ b/src/connection.c @@ -97,6 +97,33 @@ static int __connection_get_proxy_changed_callback_count(void) return count; } +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) { @@ -108,7 +135,7 @@ static int __connection_set_type_changed_callback(connection_h connection, __connection_cb_state_change_cb, NULL)) return CONNECTION_ERROR_OPERATION_FAILED; - local_handle->state_changed_user_data = user_data; + local_handle->type_changed_user_data = user_data; } else { if (local_handle->type_changed_callback && __connection_get_type_changed_callback_count() == 1) @@ -181,7 +208,7 @@ static void __connection_cb_state_change_cb(keynode_t *node, void *user_data) if (local_handle->type_changed_callback) local_handle->type_changed_callback( __connection_convert_net_state(state), - local_handle->state_changed_user_data); + local_handle->type_changed_user_data); } } @@ -230,6 +257,26 @@ static bool __connection_check_handle_validity(connection_h connection) return ret; } +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) { GSList *list; @@ -295,6 +342,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); @@ -386,6 +434,84 @@ 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]; + + 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: + 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); + 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 status = 0; @@ -452,6 +578,39 @@ 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) +{ + 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) +{ + 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) +{ + 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) { if (state == NULL || !(__connection_check_handle_validity(connection))) { diff --git a/src/internal.c b/src/internal.c old mode 100755 new mode 100644 diff --git a/src/libnetwork.c b/src/libnetwork.c old mode 100755 new mode 100644 index cf94dce..be77887 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -41,6 +41,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; @@ -242,6 +243,19 @@ static void __libnet_default_cb(connection_error_e result) libnet.set_default_user_data = NULL; } +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 void __libnet_state_changed_cb(char *profile_name, connection_profile_state_e state) { if (profile_name == NULL) @@ -366,6 +380,15 @@ 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); + + 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 : CONNECTION_LOG(CONNECTION_ERROR, "Error! Unknown Event\n\n"); break; @@ -537,6 +560,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; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f2f801..c44ab56 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -17,3 +17,5 @@ FOREACH(src ${sources}) ADD_EXECUTABLE(${src_name} ${src}) TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) ENDFOREACH() + +INSTALL(TARGETS connection_test RUNTIME DESTINATION bin/) diff --git a/test/connection_test.c b/test/connection_test.c index 09f01d0..b11a5a0 100755 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -189,6 +189,15 @@ static void test_connection_set_default_callback(connection_error_e result, void printf("Default profile setting Failed, err : %d\n", 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; @@ -717,6 +726,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 %d\n", err); return -1; @@ -1502,6 +1513,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; @@ -1588,8 +1650,13 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("o - Reset cellular data call statistics\n"); printf("p - Reset WiFi data call statistics\n"); printf("q - Add new route\n"); - printf("r - Get Bluetooth state\n"); - printf("s - Get profile id\n"); + printf("r - Remove a route\n"); + printf("s - Get Bluetooth state\n"); + 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("0 - Exit \n"); printf("ENTER - Show options menu.......\n"); } @@ -1688,6 +1755,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; } if (rv == 1)