From: Chengyi Zhao Date: Tue, 2 Dec 2014 02:51:48 +0000 (+0800) Subject: Add to get ethernet state X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5aeafe2a7651a4192ec73dc774a19864d99dd260;p=platform%2Fcore%2Fapi%2Fconnection.git Add to get ethernet state This ethernet state is not related to 'tethering'. Change-Id: Icd714172758e177b4a667f22429d9735439a32ba Signed-off-by: Chengyi Zhao --- diff --git a/src/libnetwork.c b/src/libnetwork.c index f176a96..6338903 100755 --- a/src/libnetwork.c +++ b/src/libnetwork.c @@ -350,33 +350,24 @@ bool _connection_libnet_get_wifi_state(connection_wifi_state_e *state) bool _connection_libnet_get_ethernet_state(connection_ethernet_state_e* state) { - struct _profile_list_s ethernet_profiles = {0, 0, NULL}; - /* - TODO: - 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; - } + struct connman_technology *technology; + bool powered; + bool connected; - 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: + technology = connman_get_technology(TECH_TYPE_ETHERNET); + if (technology == NULL) return false; - } - __libnet_clear_profile_list(ðernet_profiles); + *state = CONNECTION_ETHERNET_STATE_DEACTIVATED; + powered = connman_get_technology_powered(technology); + + if (powered) { + connected = connman_get_technology_connected(technology); + if (connected) + *state = CONNECTION_ETHERNET_STATE_CONNECTED; + else + *state = CONNECTION_ETHERNET_STATE_DISCONNECTED; + } return true; } diff --git a/test/connection_test.c b/test/connection_test.c index b160a6f..6f33a97 100644 --- a/test/connection_test.c +++ b/test/connection_test.c @@ -1357,6 +1357,23 @@ int test_get_profile_id(void) return 1; } +int test_get_eth_state(void) +{ + int rv = 0; + connection_ethernet_state_e eth_state; + + rv = connection_get_ethernet_state(connection, ð_state); + + if (rv != CONNECTION_ERROR_NONE) { + printf("Fail to get Ethernet state [%d]\n", rv); + return -1; + } + + printf("Ethernet state [%d]\n", eth_state); + + return 1; +} + int main(int argc, char **argv) { @@ -1421,7 +1438,8 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) printf("q - Add new route\n"); printf("r - Get Bluetooth state\n"); printf("s - Get profile id\n"); - printf("0 - Exit \n"); + printf("t - Get Ethernet state\n"); + printf("0 - Exit\n"); printf("ENTER - Show options menu.......\n"); } @@ -1510,6 +1528,9 @@ gboolean test_thread(GIOChannel *source, GIOCondition condition, gpointer data) case 's': rv = test_get_profile_id(); break; + case 't': + rv = test_get_eth_state(); + break; } if (rv == 1)