Fix handling of connect/disconnect for Ethernet devices
authorMarcel Holtmann <marcel@holtmann.org>
Wed, 1 Jul 2009 13:23:55 +0000 (06:23 -0700)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 1 Jul 2009 13:23:55 +0000 (06:23 -0700)
include/device.h
plugins/ethernet.c
src/device.c

index 5b103a289ba4c574864964ac41285b0d6028e100..b03be788c3bb670b115b26dbdfe5d6d1c20a8fbe 100644 (file)
@@ -90,6 +90,8 @@ int connman_device_set_scanning(struct connman_device *device,
                                                connman_bool_t scanning);
 int connman_device_set_disconnected(struct connman_device *device,
                                                connman_bool_t disconnected);
+int connman_device_set_connected(struct connman_device *device,
+                                               connman_bool_t connected);
 
 int connman_device_set_string(struct connman_device *device,
                                        const char *key, const char *value);
index 2851bf50b69ad0d926c04f06a8b7307bee1c6b88..2f9cf0f51f4e13e027bd2b3bd2954a361c35f83e 100644 (file)
@@ -138,9 +138,7 @@ static int ethernet_connect(struct connman_device *device)
        if (!(ethernet->flags & IFF_LOWER_UP))
                return -ENOTCONN;
 
-       connman_device_set_carrier(device, TRUE);
-
-       return 0;
+       return connman_device_set_connected(device, TRUE);
 }
 
 static int ethernet_disconnect(struct connman_device *device)
@@ -152,9 +150,7 @@ static int ethernet_disconnect(struct connman_device *device)
        if (!(ethernet->flags & IFF_LOWER_UP))
                return -ENOTCONN;
 
-       connman_device_set_carrier(device, FALSE);
-
-       return 0;
+       return connman_device_set_connected(device, FALSE);
 }
 
 static struct connman_device_driver ethernet_driver = {
index f086e76c811ef550ed7495f7477f6a2605620ec4..4afb2f44e014a39950d5a2d3e36b8e1ff4a5f038 100644 (file)
@@ -133,14 +133,10 @@ static const char *type2string(enum connman_device_type type)
        return NULL;
 }
 
-static int set_carrier(struct connman_device *device, connman_bool_t carrier)
+static int set_connected(struct connman_device *device,
+                                               connman_bool_t connected)
 {
-       struct connman_service *service;
-
-       service = __connman_service_lookup_from_device(device);
-       __connman_service_set_carrier(service, carrier);
-
-       if (carrier == TRUE) {
+       if (connected == TRUE) {
                enum connman_element_type type = CONNMAN_ELEMENT_TYPE_UNKNOWN;
                struct connman_element *element;
 
@@ -160,6 +156,8 @@ static int set_carrier(struct connman_device *device, connman_bool_t carrier)
 
                element = connman_element_create(NULL);
                if (element != NULL) {
+                       struct connman_service *service;
+
                        element->type  = type;
                        element->index = device->element.index;
 
@@ -169,15 +167,29 @@ static int set_carrier(struct connman_device *device, connman_bool_t carrier)
 
                        device->disconnected = FALSE;
 
+                       service = __connman_service_lookup_from_device(device);
                        __connman_service_indicate_state(service,
                                        CONNMAN_SERVICE_STATE_CONFIGURATION);
                }
-       } else
+       } else {
                connman_element_unregister_children(&device->element);
 
+               device->disconnected = TRUE;
+       }
+
        return 0;
 }
 
+static int set_carrier(struct connman_device *device, connman_bool_t carrier)
+{
+       struct connman_service *service;
+
+       service = __connman_service_lookup_from_device(device);
+       __connman_service_set_carrier(service, carrier);
+
+       return set_connected(device, carrier);
+}
+
 static int set_powered(struct connman_device *device, connman_bool_t powered)
 {
        struct connman_device_driver *driver = device->driver;
@@ -1243,7 +1255,7 @@ int connman_device_set_powered(struct connman_device *device,
 int connman_device_set_carrier(struct connman_device *device,
                                                connman_bool_t carrier)
 {
-       DBG("driver %p carrier %d", device, carrier);
+       DBG("device %p carrier %d", device, carrier);
 
        switch (device->mode) {
        case CONNMAN_DEVICE_MODE_UNKNOWN:
@@ -1400,7 +1412,7 @@ int connman_device_set_scanning(struct connman_device *device,
        DBusMessageIter entry, value;
        const char *key = "Scanning";
 
-       DBG("driver %p scanning %d", device, scanning);
+       DBG("device %p scanning %d", device, scanning);
 
        if (!device->driver || !device->driver->scan)
                return -EINVAL;
@@ -1467,7 +1479,7 @@ int connman_device_set_scanning(struct connman_device *device,
 int connman_device_set_disconnected(struct connman_device *device,
                                                connman_bool_t disconnected)
 {
-       DBG("driver %p disconnected %d", device, disconnected);
+       DBG("device %p disconnected %d", device, disconnected);
 
        switch (device->mode) {
        case CONNMAN_DEVICE_MODE_UNKNOWN:
@@ -1486,6 +1498,33 @@ int connman_device_set_disconnected(struct connman_device *device,
        return 0;
 }
 
+/**
+ * connman_device_set_connected:
+ * @device: device structure
+ * @connected: connected state
+ *
+ * Change connected state of device (for Ethernet like devices)
+ */
+int connman_device_set_connected(struct connman_device *device,
+                                               connman_bool_t connected)
+{
+       DBG("device %p connected %d", device, connected);
+
+       switch (device->mode) {
+       case CONNMAN_DEVICE_MODE_UNKNOWN:
+       case CONNMAN_DEVICE_MODE_NETWORK_SINGLE:
+       case CONNMAN_DEVICE_MODE_NETWORK_MULTIPLE:
+               return -EINVAL;
+       case CONNMAN_DEVICE_MODE_TRANSPORT_IP:
+               break;
+       }
+
+       if (device->carrier == FALSE)
+               return -ENOTCONN;
+
+       return set_connected(device, connected);
+}
+
 /**
  * connman_device_set_string:
  * @device: device structure