diff options
-rw-r--r-- | include/device.h | 2 | ||||
-rw-r--r-- | plugins/ethernet.c | 8 | ||||
-rw-r--r-- | src/device.c | 61 |
3 files changed, 54 insertions, 17 deletions
diff --git a/include/device.h b/include/device.h index 5b103a28..b03be788 100644 --- a/include/device.h +++ b/include/device.h @@ -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); diff --git a/plugins/ethernet.c b/plugins/ethernet.c index 2851bf50..2f9cf0f5 100644 --- a/plugins/ethernet.c +++ b/plugins/ethernet.c @@ -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 = { diff --git a/src/device.c b/src/device.c index f086e76c..4afb2f44 100644 --- a/src/device.c +++ b/src/device.c @@ -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: @@ -1487,6 +1499,33 @@ int connman_device_set_disconnected(struct connman_device *device, } /** + * 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 * @key: unique identifier |