Add to get ethernet state 88/31188/2
authorChengyi Zhao <chengyi1.zhao@archermind.com>
Tue, 2 Dec 2014 02:51:48 +0000 (10:51 +0800)
committerChengyi Zhao <chengyi1.zhao@archermind.com>
Wed, 3 Dec 2014 01:46:16 +0000 (09:46 +0800)
This ethernet state is not related to 'tethering'.

Change-Id: Icd714172758e177b4a667f22429d9735439a32ba
Signed-off-by: Chengyi Zhao <chengyi1.zhao@archermind.com>
src/libnetwork.c
test/connection_test.c

index f176a9655cb542e465f6933926f7274f821830fe..63389032ff8958088902d495309bef5d933cc0fa 100755 (executable)
@@ -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, &ethernet_profiles.profiles, &ethernet_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(&ethernet_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;
 }
index b160a6fe6b0b8921bf85d89f964aa5157b8035c6..6f33a9788edd53e294c12d12bde5dc05359226e0 100644 (file)
@@ -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, &eth_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)