static int set_device_state(struct device *dev, bool state)
{
- if (state) {
- broadcast_device_event(dev, DEV_EVENT_SETUP);
+ if (state)
system_if_up(dev);
- broadcast_device_event(dev, DEV_EVENT_UP);
- } else {
- broadcast_device_event(dev, DEV_EVENT_TEARDOWN);
+ else
system_if_down(dev);
- broadcast_device_event(dev, DEV_EVENT_DOWN);
- }
+
return 0;
}
if (++dev->active != 1)
return 0;
+ broadcast_device_event(dev, DEV_EVENT_SETUP);
ret = dev->set_state(dev, true);
- if (ret != 0)
+ if (ret == 0)
+ broadcast_device_event(dev, DEV_EVENT_UP);
+ else
dev->active = 0;
return ret;
DPRINTF("release device %s, new refcount: %d\n", dev->ifname, dev->active);
assert(dev->active >= 0);
- if (!dev->active)
- dev->set_state(dev, false);
+ if (dev->active)
+ return;
+
+ broadcast_device_event(dev, DEV_EVENT_TEARDOWN);
+ dev->set_state(dev, false);
+ broadcast_device_event(dev, DEV_EVENT_DOWN);
}
int check_device_state(struct device *dev)
assert(dev);
assert(type);
- fprintf(stderr, "Initialize interface '%s'\n", dev->ifname);
- INIT_LIST_HEAD(&dev->users);
- dev->type = type;
-
if (name)
strncpy(dev->ifname, name, IFNAMSIZ);
+
+ fprintf(stderr, "Initialize device '%s'\n", dev->ifname);
+ INIT_LIST_HEAD(&dev->users);
+ dev->type = type;
}
int init_device(struct device *dev, const struct device_type *type, const char *ifname)
{
struct device_user *dep, *tmp;
- fprintf(stderr, "Clean up interface '%s'\n", dev->ifname);
+ fprintf(stderr, "Clean up device '%s'\n", dev->ifname);
list_for_each_entry_safe(dep, tmp, &dev->users, list) {
if (!dep->cb)
continue;
list_del(&dep->list);
if (list_empty(&dev->users)) {
- /* all references have gone away, remove this interface */
+ /* all references have gone away, remove this device */
dev->type->free(dev);
}