Add option for interface limitation
[connman] / src / iface.c
index ea8b47b..18c44f6 100644 (file)
@@ -47,6 +47,8 @@
 
 static DBusConnection *connection = NULL;
 
+static gchar *ifname_filter = NULL;
+
 static GSList *drivers = NULL;
 
 int connman_iface_register(struct connman_iface_driver *driver)
@@ -215,14 +217,20 @@ static void switch_policy(struct connman_iface *iface)
                iface->state = CONNMAN_IFACE_STATE_SHUTDOWN;
                state_changed(iface);
                connman_iface_clear_ipv4(iface);
-               __connman_iface_down(iface);
+               if (iface->driver->stop)
+                       iface->driver->stop(iface);
+               else
+                       __connman_iface_down(iface);
                break;
 
        case CONNMAN_IFACE_POLICY_IGNORE:
                break;
 
        case CONNMAN_IFACE_POLICY_AUTO:
-               __connman_iface_up(iface);
+               if (iface->driver->start)
+                       iface->driver->start(iface);
+               else
+                       __connman_iface_up(iface);
                state_changed(iface);
                break;
 
@@ -252,9 +260,13 @@ void connman_iface_indicate_disabled(struct connman_iface *iface)
 
        if (iface->policy == CONNMAN_IFACE_POLICY_AUTO) {
                iface->state = CONNMAN_IFACE_STATE_ENABLED;
-               __connman_iface_up(iface);
+               if (iface->driver->start)
+                       iface->driver->start(iface);
+               else
+                       __connman_iface_up(iface);
        } else
                iface->state = CONNMAN_IFACE_STATE_SHUTDOWN;
+
        state_changed(iface);
 }
 
@@ -562,8 +574,9 @@ static DBusMessage *scan_iface(DBusConnection *conn,
        if (reply == NULL)
                return NULL;
 
-       //if (driver->scan)
-       //      driver->scan(iface);
+       if (driver->scan) {
+               //driver->scan(iface);
+       }
 
        dbus_message_append_args(reply, DBUS_TYPE_INVALID);
 
@@ -1084,7 +1097,7 @@ static int probe_device(LibHalContext *ctx,
 {
        DBusConnection *conn;
        struct connman_iface *iface;
-       char *temp, *sysfs;
+       char *temp, *sysfs, *ifname;
        int err;
 
        DBG("ctx %p driver %p udi %s", ctx, driver, udi);
@@ -1113,10 +1126,20 @@ static int probe_device(LibHalContext *ctx,
 
        iface->index = -1;
 
-       if (g_str_has_prefix(driver->capability, "net") == TRUE)
+       if (g_str_has_prefix(driver->capability, "net") == TRUE) {
                iface->index = libhal_device_get_property_int(ctx, udi,
                                                "net.linux.ifindex", NULL);
 
+               ifname = libhal_device_get_property_string(ctx, udi,
+                                               "net.interface", NULL);
+               if (ifname != NULL && ifname_filter != NULL &&
+                                               *ifname_filter != '\0' &&
+                               g_str_equal(ifname, ifname_filter) == FALSE) {
+                       device_free(iface);
+                       return -1;
+               }
+       }
+
        iface->type = CONNMAN_IFACE_TYPE_UNKNOWN;
        iface->flags = 0;
        iface->state = CONNMAN_IFACE_STATE_UNKNOWN;
@@ -1329,7 +1352,7 @@ static void hal_cleanup(void *data)
 
 static guint hal_watch = 0;
 
-int __connman_iface_init(DBusConnection *conn)
+int __connman_iface_init(DBusConnection *conn, const char *interface)
 {
        DBG("conn %p", conn);
 
@@ -1337,6 +1360,9 @@ int __connman_iface_init(DBusConnection *conn)
        if (connection == NULL)
                return -1;
 
+       if (interface != NULL)
+               ifname_filter = g_strdup(interface);
+
        hal_init(connection);
 
        hal_watch = g_dbus_add_watch(connection, "org.freedesktop.Hal",
@@ -1353,5 +1379,7 @@ void __connman_iface_cleanup(void)
 
        hal_cleanup(connection);
 
+       g_free(ifname_filter);
+
        dbus_connection_unref(connection);
 }