Add interface index and state variables
[framework/connectivity/connman.git] / src / iface.c
index ce6ab38..9dc0c80 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include <string.h>
+#include <arpa/inet.h>
 
 #include <glib.h>
 #include <gdbus.h>
@@ -52,6 +53,33 @@ void connman_iface_unregister(struct connman_iface_driver *driver)
 
 static GSList *interfaces = NULL;
 
+int connman_iface_update(struct connman_iface *iface,
+                                        enum connman_iface_state state)
+{
+       switch (state) {
+       case CONNMAN_IFACE_STATE_ACTIVE:
+               if (iface->type == CONNMAN_IFACE_TYPE_80211) {
+                       if (iface->driver->scan)
+                               iface->driver->scan(iface);
+
+                       if (iface->driver->connect)
+                               iface->driver->connect(iface, NULL);
+               }
+               break;
+
+       case CONNMAN_IFACE_STATE_CONNECTED:
+               __connman_dhcp_request(iface);
+               break;
+
+       default:
+               break;
+        }
+
+       iface->state = state;
+
+       return 0;
+}
+
 static void device_free(void *data)
 {
        struct connman_iface *iface = data;
@@ -97,8 +125,15 @@ static int probe_device(LibHalContext *ctx,
        if (sysfs != NULL)
                iface->sysfs = g_strdup(sysfs);
 
+       iface->index = -1;
+
+       if (g_str_has_prefix(driver->capability, "net") == TRUE)
+               iface->index = libhal_device_get_property_int(ctx, udi,
+                                               "net.linux.ifindex", NULL);
+
        iface->type = CONNMAN_IFACE_TYPE_UNKNOWN;
        iface->flags = 0;
+       iface->state = CONNMAN_IFACE_STATE_UNKNOWN;
 
        DBG("iface %p", iface);
 
@@ -116,6 +151,16 @@ static int probe_device(LibHalContext *ctx,
 
        interfaces = g_slist_append(interfaces, iface);
 
+       if ((iface->flags & CONNMAN_IFACE_FLAG_IPV4) &&
+                                               driver->get_ipv4) {
+               driver->get_ipv4(iface, &iface->ipv4);
+
+               DBG("address %s", inet_ntoa(iface->ipv4.address));
+       }
+
+       if (driver->activate)
+               driver->activate(iface);
+
        return 0;
 }