element: Remove device code
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Thu, 2 Jun 2011 17:29:08 +0000 (19:29 +0200)
committerDaniel Wagner <daniel.wagner@bmw-carit.de>
Tue, 7 Jun 2011 12:57:52 +0000 (14:57 +0200)
include/element.h
src/connman.h
src/device.c
src/element.c
src/inet.c
src/main.c
src/manager.c
src/service.c

index df8431e..57a7632 100644 (file)
@@ -42,7 +42,6 @@ extern "C" {
 enum connman_element_type {
        CONNMAN_ELEMENT_TYPE_UNKNOWN    = 0,
        CONNMAN_ELEMENT_TYPE_ROOT       = 1,
-       CONNMAN_ELEMENT_TYPE_DEVICE     = 3,
        CONNMAN_ELEMENT_TYPE_NETWORK    = 4,
 };
 
@@ -81,7 +80,6 @@ struct connman_element {
 
        union {
                void *private;
-               struct connman_device *device;
                struct connman_network *network;
        };
 
index e2441ec..198b1f7 100644 (file)
@@ -181,7 +181,7 @@ void __connman_driver_rescan(struct connman_driver *driver);
 
 #include <connman/element.h>
 
-int __connman_element_init(const char *device, const char *nodevice);
+int __connman_element_init(void);
 void __connman_element_start(void);
 void __connman_element_stop(void);
 void __connman_element_cleanup(void);
@@ -198,20 +198,9 @@ void __connman_element_list(struct connman_element *element,
                                        enum connman_element_type type,
                                                        DBusMessageIter *iter);
 
-struct connman_device *__connman_element_get_device(struct connman_element *element);
-
-struct connman_device *__connman_element_find_device(enum connman_service_type type);
-int __connman_element_request_scan(enum connman_service_type type);
-int __connman_element_enable_technology(enum connman_service_type type);
-int __connman_element_disable_technology(enum connman_service_type type);
-
-gboolean __connman_element_device_isfiltered(const char *devname);
-
 int __connman_detect_init(void);
 void __connman_detect_cleanup(void);
 
-void __connman_element_set_driver(struct connman_element *element);
-
 #include <connman/proxy.h>
 
 int __connman_proxy_init(void);
@@ -361,12 +350,18 @@ connman_bool_t __connman_technology_get_blocked(enum connman_service_type type);
 
 #include <connman/device.h>
 
-int __connman_device_init(void);
+int __connman_device_init(const char *device, const char *nodevice);
 void __connman_device_cleanup(void);
 
 void __connman_device_list(DBusMessageIter *iter, void *user_data);
 
 enum connman_service_type __connman_device_get_service_type(struct connman_device *device);
+struct connman_device *__connman_device_find_device(enum connman_service_type type);
+int __connman_device_request_scan(enum connman_service_type type);
+int __connman_device_enable_technology(enum connman_service_type type);
+int __connman_device_disable_technology(enum connman_service_type type);
+
+connman_bool_t __connman_device_isfiltered(const char *devname);
 
 int __connman_device_get_phyindex(struct connman_device *device);
 void __connman_device_set_phyindex(struct connman_device *device,
index a9f4330..48be10f 100644 (file)
 
 #include "connman.h"
 
+static GSList *device_list = NULL;
+static gchar **device_filter = NULL;
+static gchar **nodevice_filter = NULL;
+
 struct connman_device {
-       struct connman_element element;
+       gint refcount;
        enum connman_device_type type;
        connman_bool_t offlinemode;
        connman_bool_t blocked;
@@ -47,7 +51,9 @@ struct connman_device {
        char *interface;
        char *ident;
        char *path;
+       char *devname;
        int phyindex;
+       int index;
        unsigned int connections;
        guint scan_timeout;
 
@@ -308,29 +314,28 @@ static int setup_device(struct connman_device *device)
        return 0;
 }
 
-static void probe_driver(struct connman_element *element, gpointer user_data)
+static void probe_driver(struct connman_device_driver *driver)
 {
-       struct connman_device_driver *driver = user_data;
-
-       DBG("element %p name %s", element, element->name);
+       GSList *list;
 
-       if (element->device == NULL)
-               return;
+       DBG("driver %p name %s", driver, driver->name);
 
-       if (element->device->driver != NULL)
-               return;
+       for (list = device_list; list != NULL; list = list->next) {
+               struct connman_device *device = list->data;
 
-       if (driver->type != element->device->type)
-               return;
+               if (device->driver != NULL)
+                       continue;
 
-       if (driver->probe(element->device) < 0)
-               return;
+               if (driver->type != device->type)
+                       continue;
 
-       element->device->driver = driver;
+               if (driver->probe(device) < 0)
+                       continue;
 
-       __connman_element_set_driver(element);
+               device->driver = driver;
 
-       setup_device(element->device);
+               setup_device(device);
+       }
 }
 
 static void remove_device(struct connman_device *device)
@@ -347,17 +352,18 @@ static void remove_device(struct connman_device *device)
        device->driver = NULL;
 }
 
-static void remove_driver(struct connman_element *element, gpointer user_data)
+static void remove_driver(struct connman_device_driver *driver)
 {
-       struct connman_device_driver *driver = user_data;
+       GSList *list;
 
-       DBG("element %p name %s", element, element->name);
+       DBG("driver %p name %s", driver, driver->name);
 
-       if (element->device == NULL)
-               return;
+       for (list = device_list; list != NULL; list = list->next) {
+               struct connman_device *device = list->data;
 
-       if (element->device->driver == driver)
-               remove_device(element->device);
+               if (device->driver == driver)
+                       remove_device(device);
+       }
 }
 
 connman_bool_t __connman_device_has_driver(struct connman_device *device)
@@ -392,9 +398,7 @@ int connman_device_driver_register(struct connman_device_driver *driver)
 
        driver_list = g_slist_insert_sorted(driver_list, driver,
                                                        compare_priority);
-
-       __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
-                                               probe_driver, driver);
+       probe_driver(driver);
 
        return 0;
 }
@@ -411,8 +415,7 @@ void connman_device_driver_unregister(struct connman_device_driver *driver)
 
        driver_list = g_slist_remove(driver_list, driver);
 
-       __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
-                                               remove_driver, driver);
+       remove_driver(driver);
 }
 
 static void unregister_network(gpointer data)
@@ -428,11 +431,9 @@ static void unregister_network(gpointer data)
        connman_network_unref(network);
 }
 
-static void device_destruct(struct connman_element *element)
+static void device_destruct(struct connman_device *device)
 {
-       struct connman_device *device = element->device;
-
-       DBG("element %p name %s", element, element->name);
+       DBG("device %p name %s", device, device->name);
 
        clear_scan_trigger(device);
 
@@ -442,11 +443,14 @@ static void device_destruct(struct connman_element *element)
        g_free(device->address);
        g_free(device->interface);
        g_free(device->path);
+       g_free(device->devname);
 
        g_free(device->last_network);
 
        g_hash_table_destroy(device->networks);
        device->networks = NULL;
+
+       g_free(device);
 }
 
 /**
@@ -462,7 +466,6 @@ struct connman_device *connman_device_create(const char *node,
                                                enum connman_device_type type)
 {
        struct connman_device *device;
-       const char *str;
        enum connman_service_type service_type;
        connman_bool_t bg_scan;
 
@@ -474,20 +477,9 @@ struct connman_device *connman_device_create(const char *node,
 
        DBG("device %p", device);
 
-       bg_scan = connman_setting_get_bool("BackgroundScanning");
-
-       __connman_element_initialize(&device->element);
+       device->refcount = 1;
 
-       device->element.name = g_strdup(node);
-       device->element.type = CONNMAN_ELEMENT_TYPE_DEVICE;
-
-       device->element.device = device;
-       device->element.destruct = device_destruct;
-
-       str = type2string(type);
-       if (str != NULL)
-               connman_element_set_string(&device->element,
-                                       CONNMAN_PROPERTY_ID_TYPE, str);
+       bg_scan = connman_setting_get_bool("BackgroundScanning");
 
        device->type = type;
        device->name = g_strdup(type2description(device->type));
@@ -522,6 +514,8 @@ struct connman_device *connman_device_create(const char *node,
        device->networks = g_hash_table_new_full(g_str_hash, g_str_equal,
                                                g_free, unregister_network);
 
+       device_list = g_slist_append(device_list, device);
+
        return device;
 }
 
@@ -533,8 +527,9 @@ struct connman_device *connman_device_create(const char *node,
  */
 struct connman_device *connman_device_ref(struct connman_device *device)
 {
-       if (connman_element_ref(&device->element) == NULL)
-               return NULL;
+       DBG("%p", device);
+
+       g_atomic_int_inc(&device->refcount);
 
        return device;
 }
@@ -547,7 +542,17 @@ struct connman_device *connman_device_ref(struct connman_device *device)
  */
 void connman_device_unref(struct connman_device *device)
 {
-       connman_element_unref(&device->element);
+       if (g_atomic_int_dec_and_test(&device->refcount) == FALSE)
+               return;
+
+       if (device->driver) {
+               device->driver->remove(device);
+               device->driver = NULL;
+       }
+
+       device_list = g_slist_remove(device_list, device);
+
+       device_destruct(device);
 }
 
 const char *__connman_device_get_type(struct connman_device *device)
@@ -575,7 +580,7 @@ enum connman_device_type connman_device_get_type(struct connman_device *device)
  */
 void connman_device_set_index(struct connman_device *device, int index)
 {
-       device->element.index = index;
+       device->index = index;
 }
 
 /**
@@ -586,7 +591,7 @@ void connman_device_set_index(struct connman_device *device, int index)
  */
 int connman_device_get_index(struct connman_device *device)
 {
-       return device->element.index;
+       return device->index;
 }
 
 int __connman_device_get_phyindex(struct connman_device *device)
@@ -610,8 +615,8 @@ void __connman_device_set_phyindex(struct connman_device *device,
 void connman_device_set_interface(struct connman_device *device,
                                                const char *interface)
 {
-       g_free(device->element.devname);
-       device->element.devname = g_strdup(interface);
+       g_free(device->devname);
+       device->devname = g_strdup(interface);
 
        g_free(device->interface);
        device->interface = g_strdup(interface);
@@ -806,7 +811,7 @@ int __connman_device_disconnect(struct connman_device *device)
 }
 
 static void mark_network_available(gpointer key, gpointer value,
-                                                        gpointer user_data)
+                                                       gpointer user_data)
 {
        struct connman_network *network = value;
 
@@ -989,13 +994,12 @@ const char *connman_device_get_string(struct connman_device *device,
        return NULL;
 }
 
-static void set_offlinemode(struct connman_element *element, gpointer user_data)
+static void set_offlinemode(struct connman_device *device,
+                               connman_bool_t offlinemode)
 {
-       struct connman_device *device = element->device;
-       connman_bool_t offlinemode = GPOINTER_TO_UINT(user_data);
        connman_bool_t powered;
 
-       DBG("element %p name %s", element, element->name);
+       DBG("device %p name %s", device, device->name);
 
        if (device == NULL)
                return;
@@ -1018,10 +1022,15 @@ static void set_offlinemode(struct connman_element *element, gpointer user_data)
 
 int __connman_device_set_offlinemode(connman_bool_t offlinemode)
 {
+       GSList *list;
+
        DBG("offlinmode %d", offlinemode);
 
-       __connman_element_foreach(NULL, CONNMAN_ELEMENT_TYPE_DEVICE,
-                       set_offlinemode, GUINT_TO_POINTER(offlinemode));
+       for (list = device_list; list != NULL; list = list->next) {
+               struct connman_device *device = list->data;
+
+               set_offlinemode(device, offlinemode);
+       }
 
        __connman_notifier_offlinemode(offlinemode);
 
@@ -1068,7 +1077,7 @@ int connman_device_add_network(struct connman_device *device,
        __connman_network_set_device(network, device);
 
        err = connman_element_register((struct connman_element *) network,
-                                                       &device->element);
+                               NULL);
        if (err < 0) {
                __connman_network_set_device(network, NULL);
                return err;
@@ -1105,8 +1114,15 @@ struct connman_network *connman_device_get_network(struct connman_device *device
 int connman_device_remove_network(struct connman_device *device,
                                                        const char *identifier)
 {
+       struct connman_network *network;
+
        DBG("device %p identifier %s", device, identifier);
 
+       network = connman_device_get_network(device, identifier);
+       if (network == NULL)
+               return 0;
+
+       connman_element_unregister((struct connman_element *) network);
        g_hash_table_remove(device->networks, identifier);
 
        return 0;
@@ -1158,6 +1174,55 @@ connman_bool_t  __connman_device_get_reconnect(
        return device->reconnect;
 }
 
+static gboolean match_driver(struct connman_device *device,
+                                       struct connman_device_driver *driver)
+{
+       if (device->type == driver->type ||
+                       driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
+               return TRUE;
+
+       return FALSE;
+}
+
+static int device_probe(struct connman_device *device)
+{
+       GSList *list;
+
+       DBG("device %p name %s", device, device->name);
+
+       if (device->driver != NULL)
+               return -EALREADY;
+
+       for (list = driver_list; list; list = list->next) {
+               struct connman_device_driver *driver = list->data;
+
+               if (match_driver(device, driver) == FALSE)
+                       continue;
+
+               DBG("driver %p name %s", driver, driver->name);
+
+               if (driver->probe(device) == 0) {
+                       device->driver = driver;
+                       break;
+               }
+       }
+
+       if (device->driver == NULL)
+               return -ENODEV;
+
+       return setup_device(device);
+}
+
+static void device_remove(struct connman_device *device)
+{
+       DBG("device %p name %s", device, device->name);
+
+       if (device->driver == NULL)
+               return;
+
+       remove_device(device);
+}
+
 /**
  * connman_device_register:
  * @device: device structure
@@ -1170,7 +1235,7 @@ int connman_device_register(struct connman_device *device)
 
        device->offlinemode = __connman_profile_get_offlinemode();
 
-       return connman_element_register(&device->element, NULL);
+       return device_probe(device);
 }
 
 /**
@@ -1183,7 +1248,7 @@ void connman_device_unregister(struct connman_device *device)
 {
        __connman_storage_save_device(device);
 
-       connman_element_unregister(&device->element);
+       device_remove(device);
 }
 
 /**
@@ -1209,71 +1274,150 @@ void connman_device_set_data(struct connman_device *device, void *data)
        device->driver_data = data;
 }
 
-static gboolean match_driver(struct connman_device *device,
-                                       struct connman_device_driver *driver)
+struct connman_device *__connman_device_find_device(
+                               enum connman_service_type type)
 {
-       if (device->type == driver->type ||
-                       driver->type == CONNMAN_DEVICE_TYPE_UNKNOWN)
-               return TRUE;
+       GSList *list;
 
-       return FALSE;
+       for (list = device_list; list != NULL; list = list->next) {
+               struct connman_device *device = list->data;
+               enum connman_service_type service_type =
+                       connman_device_get_type(device);
+
+               if (service_type != type)
+                       continue;
+
+               return device;
+       }
+
+       return NULL;
 }
 
-static int device_probe(struct connman_element *element)
+int __connman_device_request_scan(enum connman_service_type type)
 {
-       struct connman_device *device = element->device;
        GSList *list;
+       int err;
 
-       DBG("element %p name %s", element, element->name);
+       switch (type) {
+       case CONNMAN_SERVICE_TYPE_UNKNOWN:
+       case CONNMAN_SERVICE_TYPE_SYSTEM:
+       case CONNMAN_SERVICE_TYPE_ETHERNET:
+       case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+       case CONNMAN_SERVICE_TYPE_CELLULAR:
+       case CONNMAN_SERVICE_TYPE_GPS:
+       case CONNMAN_SERVICE_TYPE_VPN:
+       case CONNMAN_SERVICE_TYPE_GADGET:
+               return 0;
+       case CONNMAN_SERVICE_TYPE_WIFI:
+       case CONNMAN_SERVICE_TYPE_WIMAX:
+               break;
+       }
 
-       if (device == NULL)
-               return -ENODEV;
+       for (list = device_list; list != NULL; list = list->next) {
+               struct connman_device *device = list->data;
+               enum connman_service_type service_type =
+                       __connman_device_get_service_type(device);
 
-       if (device->driver != NULL)
-               return -EALREADY;
+               if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
+                               service_type != type) {
+                       continue;
+               }
 
-       for (list = driver_list; list; list = list->next) {
-               struct connman_device_driver *driver = list->data;
+               err = __connman_device_scan(device);
+               if (err < 0 && err != -EINPROGRESS) {
+                       DBG("err %d", err);
+                       /* XXX maybe only a continue? */
+                       return err;
+               }
+       }
 
-               if (match_driver(device, driver) == FALSE)
+       return 0;
+}
+
+static int set_technology(enum connman_service_type type, connman_bool_t enable)
+{
+       GSList *list;
+       int err;
+
+       DBG("type %d enable %d", type, enable);
+
+       switch (type) {
+       case CONNMAN_SERVICE_TYPE_UNKNOWN:
+       case CONNMAN_SERVICE_TYPE_SYSTEM:
+       case CONNMAN_SERVICE_TYPE_GPS:
+       case CONNMAN_SERVICE_TYPE_VPN:
+       case CONNMAN_SERVICE_TYPE_GADGET:
+               return 0;
+       case CONNMAN_SERVICE_TYPE_ETHERNET:
+       case CONNMAN_SERVICE_TYPE_WIFI:
+       case CONNMAN_SERVICE_TYPE_WIMAX:
+       case CONNMAN_SERVICE_TYPE_BLUETOOTH:
+       case CONNMAN_SERVICE_TYPE_CELLULAR:
+               break;
+       }
+
+       for (list = device_list; list != NULL; list = list->next) {
+               struct connman_device *device = list->data;
+               enum connman_service_type service_type =
+                       __connman_device_get_service_type(device);
+
+               if (service_type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
+                               service_type != type) {
                        continue;
+               }
 
-               DBG("driver %p name %s", driver, driver->name);
+               if (enable == TRUE)
+                       err = __connman_device_enable_persistent(device);
+               else
+                       err = __connman_device_disable_persistent(device);
 
-               if (driver->probe(device) == 0) {
-                       device->driver = driver;
-                       break;
+               if (err < 0 && err != -EINPROGRESS) {
+                       DBG("err %d", err);
+                       /* XXX maybe only a continue? */
+                       return err;
                }
        }
 
-       if (device->driver == NULL)
-               return -ENODEV;
+       return 0;
+}
 
-       return setup_device(device);
+int __connman_device_enable_technology(enum connman_service_type type)
+{
+       return set_technology(type, TRUE);
 }
 
-static void device_remove(struct connman_element *element)
+int __connman_device_disable_technology(enum connman_service_type type)
 {
-       struct connman_device *device = element->device;
+       return set_technology(type, FALSE);
+}
 
-       DBG("element %p name %s", element, element->name);
+connman_bool_t __connman_device_isfiltered(const char *devname)
+{
+       char **pattern;
 
-       if (device == NULL)
-               return;
+       if (device_filter == NULL)
+               goto nodevice;
 
-       if (device->driver == NULL)
-               return;
+       for (pattern = device_filter; *pattern; pattern++) {
+               if (g_pattern_match_simple(*pattern, devname) == FALSE) {
+                       DBG("ignoring device %s (match)", devname);
+                       return TRUE;
+               }
+       }
 
-       remove_device(device);
-}
+nodevice:
+       if (nodevice_filter == NULL)
+               return FALSE;
 
-static struct connman_driver device_driver = {
-       .name           = "device",
-       .type           = CONNMAN_ELEMENT_TYPE_DEVICE,
-       .priority       = CONNMAN_DRIVER_PRIORITY_LOW,
-       .probe          = device_probe,
-       .remove         = device_remove,
-};
+       for (pattern = nodevice_filter; *pattern; pattern++) {
+               if (g_pattern_match_simple(*pattern, devname) == TRUE) {
+                       DBG("ignoring device %s (no match)", devname);
+                       return TRUE;
+               }
+       }
+
+       return FALSE;
+}
 
 static int device_load(struct connman_device *device)
 {
@@ -1289,7 +1433,7 @@ static int device_load(struct connman_device *device)
        if (keyfile == NULL)
                return 0;
 
-       identifier = g_strdup_printf("device_%s", device->element.name);
+       identifier = g_strdup_printf("device_%s", device->name);
        if (identifier == NULL)
                goto done;
 
@@ -1319,7 +1463,7 @@ static int device_save(struct connman_device *device)
        if (keyfile == NULL)
                return 0;
 
-       identifier = g_strdup_printf("device_%s", device->element.name);
+       identifier = g_strdup_printf("device_%s", device->name);
        if (identifier == NULL)
                goto done;
 
@@ -1341,21 +1485,25 @@ static struct connman_storage device_storage = {
        .device_save    = device_save,
 };
 
-int __connman_device_init(void)
+int __connman_device_init(const char *device, const char *nodevice)
 {
        DBG("");
 
-       if (connman_storage_register(&device_storage) < 0)
-               connman_error("Failed to register device storage");
+       if (device != NULL)
+               device_filter = g_strsplit(device, ",", -1);
+
+       if (nodevice != NULL)
+               nodevice_filter = g_strsplit(nodevice, ",", -1);
 
-       return connman_driver_register(&device_driver);
+       return connman_storage_register(&device_storage);
 }
 
 void __connman_device_cleanup(void)
 {
        DBG("");
 
-       connman_driver_unregister(&device_driver);
+       g_strfreev(nodevice_filter);
+       g_strfreev(device_filter);
 
        connman_storage_unregister(&device_storage);
 }
index 04d92ee..a9a643b 100644 (file)
@@ -36,8 +36,6 @@ static DBusConnection *connection;
 
 static GNode *element_root = NULL;
 static GSList *driver_list = NULL;
-static gchar **device_filter = NULL;
-static gchar **nodevice_filter = NULL;
 
 static gboolean started = FALSE;
 
@@ -48,8 +46,6 @@ static const char *type2string(enum connman_element_type type)
                return "unknown";
        case CONNMAN_ELEMENT_TYPE_ROOT:
                return "root";
-       case CONNMAN_ELEMENT_TYPE_DEVICE:
-               return "device";
        case CONNMAN_ELEMENT_TYPE_NETWORK:
                return "network";
        }
@@ -123,10 +119,6 @@ static gboolean append_path(GNode *node, gpointer user_data)
                                        filter->type != element->type)
                return FALSE;
 
-       if (filter->type == CONNMAN_ELEMENT_TYPE_DEVICE &&
-                       __connman_device_has_driver(element->device) == FALSE)
-               return FALSE;
-
        if (filter->type == CONNMAN_ELEMENT_TYPE_NETWORK &&
                        __connman_network_has_driver(element->network) == FALSE)
                return FALSE;
@@ -158,206 +150,6 @@ void __connman_element_list(struct connman_element *element,
                                                append_path, &filter);
 }
 
-struct connman_device *__connman_element_get_device(struct connman_element *element)
-{
-       if (element->type == CONNMAN_ELEMENT_TYPE_DEVICE &&
-                                               element->device != NULL)
-               return element->device;
-
-       if (element->parent == NULL)
-               return NULL;
-
-       return __connman_element_get_device(element->parent);
-}
-
-struct find_data {
-       enum connman_service_type type;
-       struct connman_device *device;
-       connman_bool_t error;
-};
-
-static gboolean find_device(GNode *node, gpointer user_data)
-{
-       struct connman_element *element = node->data;
-       struct find_data *data = user_data;
-
-       if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
-               return FALSE;
-
-       if (element->device == NULL)
-               return FALSE;
-
-       if (data->type != __connman_device_get_service_type(element->device))
-               return FALSE;
-
-       data->device = element->device;
-
-       return TRUE;
-}
-
-struct connman_device *__connman_element_find_device(enum connman_service_type type)
-{
-       struct find_data data = { .type = type, .device = NULL };
-
-       g_node_traverse(element_root, G_PRE_ORDER,
-                               G_TRAVERSE_ALL, -1, find_device, &data);
-
-       return data.device;
-}
-
-static gboolean request_scan(GNode *node, gpointer user_data)
-{
-       struct connman_element *element = node->data;
-       struct find_data *data = user_data;
-       enum connman_service_type type;
-
-       if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
-               return FALSE;
-
-       if (element->device == NULL)
-               return FALSE;
-
-       type = __connman_device_get_service_type(element->device);
-
-       switch (type) {
-       case CONNMAN_SERVICE_TYPE_UNKNOWN:
-       case CONNMAN_SERVICE_TYPE_SYSTEM:
-       case CONNMAN_SERVICE_TYPE_ETHERNET:
-       case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-       case CONNMAN_SERVICE_TYPE_CELLULAR:
-       case CONNMAN_SERVICE_TYPE_GPS:
-       case CONNMAN_SERVICE_TYPE_VPN:
-       case CONNMAN_SERVICE_TYPE_GADGET:
-               return FALSE;
-       case CONNMAN_SERVICE_TYPE_WIFI:
-       case CONNMAN_SERVICE_TYPE_WIMAX:
-               if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
-                                                       data->type != type)
-                       return FALSE;
-               break;
-       }
-
-       __connman_device_scan(element->device);
-
-       return FALSE;
-}
-
-int __connman_element_request_scan(enum connman_service_type type)
-{
-       struct find_data data = { .type = type, .device = NULL };
-
-       g_node_traverse(element_root, G_PRE_ORDER,
-                               G_TRAVERSE_ALL, -1, request_scan, &data);
-
-       return 0;
-}
-
-static gboolean enable_technology(GNode *node, gpointer user_data)
-{
-       struct connman_element *element = node->data;
-       struct find_data *data = user_data;
-       enum connman_service_type type;
-       int err;
-
-       if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
-               return FALSE;
-
-       if (element->device == NULL)
-               return FALSE;
-
-       type = __connman_device_get_service_type(element->device);
-
-       switch (type) {
-       case CONNMAN_SERVICE_TYPE_UNKNOWN:
-       case CONNMAN_SERVICE_TYPE_SYSTEM:
-       case CONNMAN_SERVICE_TYPE_GPS:
-       case CONNMAN_SERVICE_TYPE_VPN:
-       case CONNMAN_SERVICE_TYPE_GADGET:
-               return FALSE;
-       case CONNMAN_SERVICE_TYPE_ETHERNET:
-       case CONNMAN_SERVICE_TYPE_WIFI:
-       case CONNMAN_SERVICE_TYPE_WIMAX:
-       case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-       case CONNMAN_SERVICE_TYPE_CELLULAR:
-               if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
-                                                       data->type != type)
-                       return FALSE;
-               break;
-       }
-
-       err = __connman_device_enable_persistent(element->device);
-       if (err == 0 || (err < 0 && err == -EINPROGRESS))
-               data->error = FALSE;
-
-       return FALSE;
-}
-
-int __connman_element_enable_technology(enum connman_service_type type)
-{
-       struct find_data data = { .type = type, .device = NULL, .error = TRUE };
-
-       g_node_traverse(element_root, G_PRE_ORDER,
-                               G_TRAVERSE_ALL, -1, enable_technology, &data);
-
-       if (data.error == TRUE)
-               return -ENODEV;
-
-       return 0;
-}
-
-static gboolean disable_technology(GNode *node, gpointer user_data)
-{
-       struct connman_element *element = node->data;
-       struct find_data *data = user_data;
-       enum connman_service_type type;
-       int err;
-
-       if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
-               return FALSE;
-
-       if (element->device == NULL)
-               return FALSE;
-
-       type = __connman_device_get_service_type(element->device);
-
-       switch (type) {
-       case CONNMAN_SERVICE_TYPE_UNKNOWN:
-       case CONNMAN_SERVICE_TYPE_SYSTEM:
-       case CONNMAN_SERVICE_TYPE_GPS:
-       case CONNMAN_SERVICE_TYPE_VPN:
-       case CONNMAN_SERVICE_TYPE_GADGET:
-               return FALSE;
-       case CONNMAN_SERVICE_TYPE_ETHERNET:
-       case CONNMAN_SERVICE_TYPE_WIFI:
-       case CONNMAN_SERVICE_TYPE_WIMAX:
-       case CONNMAN_SERVICE_TYPE_BLUETOOTH:
-       case CONNMAN_SERVICE_TYPE_CELLULAR:
-               if (data->type != CONNMAN_SERVICE_TYPE_UNKNOWN &&
-                                                       data->type != type)
-                       return FALSE;
-               break;
-       }
-
-       err = __connman_device_disable_persistent(element->device);
-       if (err == 0 || (err < 0 && err == -EINPROGRESS))
-               data->error = FALSE;
-
-       return FALSE;
-}
-
-int __connman_element_disable_technology(enum connman_service_type type)
-{
-       struct find_data data = { .type = type, .device = NULL, .error = TRUE };
-
-       g_node_traverse(element_root, G_PRE_ORDER,
-                               G_TRAVERSE_ALL, -1, disable_technology, &data);
-
-       if (data.error == TRUE)
-               return -ENODEV;
-
-       return 0;
-}
-
 static gint compare_priority(gconstpointer a, gconstpointer b)
 {
        const struct connman_driver *driver1 = a;
@@ -893,34 +685,6 @@ static void register_element(gpointer data, gpointer user_data)
        probe_element(element);
 }
 
-gboolean __connman_element_device_isfiltered(const char *devname)
-{
-       char **pattern;
-
-       if (device_filter == NULL)
-               goto nodevice;
-
-       for (pattern = device_filter; *pattern; pattern++) {
-               if (g_pattern_match_simple(*pattern, devname) == FALSE) {
-                       DBG("ignoring device %s (match)", devname);
-                       return TRUE;
-               }
-       }
-
-nodevice:
-       if (nodevice_filter == NULL)
-               return FALSE;
-
-       for (pattern = nodevice_filter; *pattern; pattern++) {
-               if (g_pattern_match_simple(*pattern, devname) == TRUE) {
-                       DBG("ignoring device %s (no match)", devname);
-                       return TRUE;
-               }
-       }
-
-       return FALSE;
-}
-
 /**
  * connman_element_register:
  * @element: the element to register
@@ -939,13 +703,6 @@ int connman_element_register(struct connman_element *element,
        if (element->devname == NULL)
                element->devname = g_strdup(element->name);
 
-       if (element->type != CONNMAN_ELEMENT_TYPE_DEVICE)
-               goto setup;
-
-       if (__connman_element_device_isfiltered(element->devname) == TRUE)
-               return -EPERM;
-
-setup:
        if (connman_element_ref(element) == NULL)
                return -EINVAL;
 
@@ -1015,29 +772,7 @@ void connman_element_unregister_children(struct connman_element *element)
                                G_TRAVERSE_ALL, -1, remove_element, element);
 }
 
-void __connman_element_set_driver(struct connman_element *element)
-{
-       GSList *list;
-
-       DBG("element %p name %s driver %p", element, element->name,
-                                               element->driver);
-
-       if (element->driver)
-               return;
-
-       for (list = driver_list; list; list = list->next) {
-               struct connman_driver *driver = list->data;
-
-               if (match_driver(element, driver) == FALSE)
-                       continue;
-
-               element->driver = driver;
-
-               break;
-       }
-}
-
-int __connman_element_init(const char *device, const char *nodevice)
+int __connman_element_init()
 {
        struct connman_element *element;
 
@@ -1046,13 +781,6 @@ int __connman_element_init(const char *device, const char *nodevice)
        connection = connman_dbus_get_connection();
        if (connection == NULL)
                return -EIO;
-
-       if (device)
-               device_filter = g_strsplit(device, ",", -1);
-
-       if (nodevice)
-               nodevice_filter = g_strsplit(nodevice, ",", -1);
-
        element = connman_element_create("root");
 
        element->path = g_strdup("/");
@@ -1066,7 +794,6 @@ int __connman_element_init(const char *device, const char *nodevice)
        __connman_service_init();
        __connman_provider_init();
        __connman_network_init();
-       __connman_device_init();
 
        return 0;
 }
@@ -1152,7 +879,6 @@ void __connman_element_cleanup(void)
 {
        DBG("");
 
-       __connman_device_cleanup();
        __connman_network_cleanup();
        __connman_service_cleanup();
        __connman_location_cleanup();
@@ -1170,9 +896,6 @@ void __connman_element_cleanup(void)
        g_node_destroy(element_root);
        element_root = NULL;
 
-       g_strfreev(nodevice_filter);
-       g_strfreev(device_filter);
-
        if (connection == NULL)
                return;
 
index ec2dc52..12c87e7 100644 (file)
@@ -462,7 +462,7 @@ struct connman_device *connman_inet_create_device(int index)
        if (devname == NULL)
                return NULL;
 
-       if (__connman_element_device_isfiltered(devname) == TRUE) {
+       if (__connman_device_isfiltered(devname) == TRUE) {
                connman_info("Ignoring interface %s (filtered)", devname);
                free(devname);
                return NULL;
index 1162167..0de8cd1 100644 (file)
@@ -264,7 +264,8 @@ int main(int argc, char *argv[])
        parse_config(config);
 
        __connman_storage_init();
-       __connman_element_init(option_device, option_nodevice);
+       __connman_element_init();
+       __connman_device_init(option_device, option_nodevice);
 
        __connman_agent_init();
        __connman_iptables_init();
@@ -326,6 +327,7 @@ int main(int argc, char *argv[])
        __connman_tethering_cleanup();
        __connman_iptables_cleanup();
 
+       __connman_device_cleanup();
        __connman_element_cleanup();
        __connman_storage_cleanup();
 
index 4fd966a..40736af 100644 (file)
@@ -192,7 +192,7 @@ static DBusMessage *request_scan(DBusConnection *conn,
        else
                return __connman_error_invalid_arguments(msg);
 
-       err = __connman_element_request_scan(type);
+       err = __connman_device_request_scan(type);
        if (err < 0) {
                if (err == -EINPROGRESS) {
                        connman_error("Invalid return code from scan");
@@ -304,7 +304,7 @@ static DBusMessage *enable_technology(DBusConnection *conn,
        technology_enabled = TRUE;
        technology_pending = dbus_message_ref(msg);
 
-       err = __connman_element_enable_technology(type);
+       err = __connman_device_enable_technology(type);
        if (err < 0 && err != -EINPROGRESS)
                technology_reply(-err);
        else
@@ -352,7 +352,7 @@ static DBusMessage *disable_technology(DBusConnection *conn,
        technology_enabled = FALSE;
        technology_pending = dbus_message_ref(msg);
 
-       err = __connman_element_disable_technology(type);
+       err = __connman_device_disable_technology(type);
        if (err < 0 && err != -EINPROGRESS)
                technology_reply(-err);
        else
index a7ebf05..1b45f74 100644 (file)
@@ -3424,7 +3424,7 @@ static void report_error_cb(struct connman_service *service,
        else {
                service_complete(service);
                __connman_profile_changed(FALSE);
-               __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
+               __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
        }
 }
 
@@ -3655,7 +3655,7 @@ int __connman_service_indicate_state(struct connman_service *service,
 
        if (service_state == CONNMAN_SERVICE_STATE_IDLE ||
                        service_state == CONNMAN_SERVICE_STATE_FAILURE)
-               __connman_element_request_scan(CONNMAN_ELEMENT_TYPE_UNKNOWN);
+               __connman_device_request_scan(CONNMAN_DEVICE_TYPE_UNKNOWN);
 
        return 0;
 }
@@ -4185,7 +4185,7 @@ int __connman_service_create_and_connect(DBusMessage *msg)
                                g_strcmp0(security, "ieee8021x") != 0)
                return -EINVAL;
 
-       device = __connman_element_find_device(CONNMAN_SERVICE_TYPE_WIFI);
+       device = __connman_device_find_device(CONNMAN_SERVICE_TYPE_WIFI);
        if (device == NULL)
                return -EOPNOTSUPP;