nterface-ip: remove superfluous iface check in interface_ip_set_enabled()
[project/netifd.git] / wireless.c
index 7a03ce8..387f4ba 100644 (file)
@@ -35,12 +35,16 @@ static const struct uci_blob_param_list wdev_param = {
 enum {
        VIF_ATTR_DISABLED,
        VIF_ATTR_NETWORK,
 enum {
        VIF_ATTR_DISABLED,
        VIF_ATTR_NETWORK,
+       VIF_ATTR_ISOLATE,
+       VIF_ATTR_MODE,
        __VIF_ATTR_MAX,
 };
 
 static const struct blobmsg_policy vif_policy[__VIF_ATTR_MAX] = {
        [VIF_ATTR_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
        __VIF_ATTR_MAX,
 };
 
 static const struct blobmsg_policy vif_policy[__VIF_ATTR_MAX] = {
        [VIF_ATTR_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
-       [VIF_ATTR_NETWORK] = { .name = "network", .type = BLOBMSG_TYPE_STRING },
+       [VIF_ATTR_NETWORK] = { .name = "network", .type = BLOBMSG_TYPE_ARRAY },
+       [VIF_ATTR_ISOLATE] = { .name = "isolate", .type = BLOBMSG_TYPE_BOOL },
+       [VIF_ATTR_MODE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
 };
 
 static const struct uci_blob_param_list vif_param = {
 };
 
 static const struct uci_blob_param_list vif_param = {
@@ -51,32 +55,49 @@ static const struct uci_blob_param_list vif_param = {
 static void
 put_container(struct blob_buf *buf, struct blob_attr *attr, const char *name)
 {
 static void
 put_container(struct blob_buf *buf, struct blob_attr *attr, const char *name)
 {
-       void *c = blobmsg_open_table(&b, name);
-       blob_put_raw(&b, blob_data(attr), blob_len(attr));
-       blobmsg_close_table(&b, c);
+       void *c = blobmsg_open_table(buf, name);
+       blob_put_raw(buf, blob_data(attr), blob_len(attr));
+       blobmsg_close_table(buf, c);
 }
 
 static void
 }
 
 static void
-vif_config_add_bridge(struct blob_buf *buf, const char *network, bool prepare)
+vif_config_add_bridge(struct blob_buf *buf, struct blob_attr *networks, bool prepare)
 {
        struct interface *iface;
 {
        struct interface *iface;
-       struct device *dev;
+       struct device *dev = NULL;
+       struct blob_attr *cur;
+       const char *network;
+       int rem;
 
 
-       if (!network)
+       if (!networks)
                return;
 
                return;
 
-       iface = vlist_find(&interfaces, network, iface, node);
-       if (!iface)
-               return;
+       blobmsg_for_each_attr(cur, networks, rem) {
+               network = blobmsg_data(cur);
+
+               iface = vlist_find(&interfaces, network, iface, node);
+               if (!iface)
+                       continue;
+
+               dev = iface->main_dev.dev;
+               if (!dev)
+                       return;
+
+               if (!dev->type->bridge_capability)
+                       return;
+       }
 
 
-       dev = iface->main_dev.dev;
        if (!dev)
                return;
 
        if (!dev)
                return;
 
-       if (dev->type != &bridge_device_type)
-               return;
+       if (dev->hotplug_ops && dev->hotplug_ops->prepare)
+               dev->hotplug_ops->prepare(dev);
 
        blobmsg_add_string(buf, "bridge", dev->ifname);
 
        blobmsg_add_string(buf, "bridge", dev->ifname);
+
+       if (dev->settings.flags & DEV_OPT_MULTICAST_TO_UNICAST)
+               blobmsg_add_u8(buf, "multicast_to_unicast",
+                              dev->settings.multicast_to_unicast);
 }
 
 static void
 }
 
 static void
@@ -167,6 +188,8 @@ wireless_device_free_state(struct wireless_device *wdev)
 {
        struct wireless_interface *vif;
 
 {
        struct wireless_interface *vif;
 
+       uloop_timeout_cancel(&wdev->script_check);
+       uloop_timeout_cancel(&wdev->timeout);
        wireless_complete_kill_request(wdev);
        free(wdev->data);
        wdev->data = NULL;
        wireless_complete_kill_request(wdev);
        free(wdev->data);
        wdev->data = NULL;
@@ -180,15 +203,31 @@ wireless_device_free_state(struct wireless_device *wdev)
 static void wireless_interface_handle_link(struct wireless_interface *vif, bool up)
 {
        struct interface *iface;
 static void wireless_interface_handle_link(struct wireless_interface *vif, bool up)
 {
        struct interface *iface;
+       struct blob_attr *cur;
+       const char *network;
+       int rem;
 
        if (!vif->network || !vif->ifname)
                return;
 
 
        if (!vif->network || !vif->ifname)
                return;
 
-       iface = vlist_find(&interfaces, vif->network, iface, node);
-       if (!iface)
-               return;
+       if (up) {
+               struct device *dev = device_get(vif->ifname, 2);
+               if (dev) {
+                       dev->wireless_isolate = vif->isolate;
+                       dev->wireless = true;
+                       dev->wireless_ap = vif->ap_mode;
+               }
+       }
 
 
-       interface_handle_link(iface, vif->ifname, up);
+       blobmsg_for_each_attr(cur, vif->network, rem) {
+               network = blobmsg_data(cur);
+
+               iface = vlist_find(&interfaces, network, iface, node);
+               if (!iface)
+                       continue;
+
+               interface_handle_link(iface, vif->ifname, up, true);
+       }
 }
 
 static void
 }
 
 static void
@@ -197,6 +236,7 @@ wireless_device_setup_cancel(struct wireless_device *wdev)
        if (wdev->cancel)
                return;
 
        if (wdev->cancel)
                return;
 
+       D(WIRELESS, "Cancel wireless device '%s' setup\n", wdev->name);
        wdev->cancel = true;
        uloop_timeout_set(&wdev->timeout, 10 * 1000);
 }
        wdev->cancel = true;
        uloop_timeout_set(&wdev->timeout, 10 * 1000);
 }
@@ -211,8 +251,14 @@ wireless_device_run_handler(struct wireless_device *wdev, bool up)
        int fds[2] = { -1, -1 };
 
        D(WIRELESS, "Wireless device '%s' run %s handler\n", wdev->name, action);
        int fds[2] = { -1, -1 };
 
        D(WIRELESS, "Wireless device '%s' run %s handler\n", wdev->name, action);
-       prepare_config(wdev, &b, up);
-       config = blobmsg_format_json(b.head, true);
+       if (!up && wdev->prev_config) {
+               config = blobmsg_format_json(wdev->prev_config, true);
+               free(wdev->prev_config);
+               wdev->prev_config = NULL;
+       } else {
+               prepare_config(wdev, &b, up);
+               config = blobmsg_format_json(b.head, true);
+       }
 
        argv[i++] = wdev->drv->script;
        argv[i++] = wdev->drv->name;
 
        argv[i++] = wdev->drv->script;
        argv[i++] = wdev->drv->name;
@@ -238,14 +284,53 @@ wireless_device_run_handler(struct wireless_device *wdev, bool up)
 static void
 __wireless_device_set_up(struct wireless_device *wdev)
 {
 static void
 __wireless_device_set_up(struct wireless_device *wdev)
 {
+       if (wdev->disabled)
+               return;
+
+       if (wdev->retry_setup_failed)
+               return;
+
+       if (!wdev->autostart)
+               return;
+
        if (wdev->state != IFS_DOWN || config_init)
                return;
 
        if (wdev->state != IFS_DOWN || config_init)
                return;
 
+       free(wdev->prev_config);
+       wdev->prev_config = NULL;
        wdev->state = IFS_SETUP;
        wireless_device_run_handler(wdev, true);
 }
 
 static void
        wdev->state = IFS_SETUP;
        wireless_device_run_handler(wdev, true);
 }
 
 static void
+wireless_device_free(struct wireless_device *wdev)
+{
+       vlist_flush_all(&wdev->interfaces);
+       avl_delete(&wireless_devices.avl, &wdev->node.avl);
+       free(wdev->config);
+       free(wdev->prev_config);
+       free(wdev);
+}
+
+static void
+wdev_handle_config_change(struct wireless_device *wdev)
+{
+       enum interface_config_state state = wdev->config_state;
+
+       switch(state) {
+       case IFC_NORMAL:
+       case IFC_RELOAD:
+               __wireless_device_set_up(wdev);
+
+               wdev->config_state = IFC_NORMAL;
+               break;
+       case IFC_REMOVE:
+               wireless_device_free(wdev);
+               break;
+       }
+}
+
+static void
 wireless_device_mark_down(struct wireless_device *wdev)
 {
        struct wireless_interface *vif;
 wireless_device_mark_down(struct wireless_device *wdev)
 {
        struct wireless_interface *vif;
@@ -257,22 +342,10 @@ wireless_device_mark_down(struct wireless_device *wdev)
 
        wireless_process_kill_all(wdev, SIGTERM, true);
 
 
        wireless_process_kill_all(wdev, SIGTERM, true);
 
+       wdev->cancel = false;
        wdev->state = IFS_DOWN;
        wireless_device_free_state(wdev);
        wdev->state = IFS_DOWN;
        wireless_device_free_state(wdev);
-
-       if (wdev->autostart)
-               __wireless_device_set_up(wdev);
-}
-
-static void
-wireless_device_mark_up(struct wireless_device *wdev)
-{
-       struct wireless_interface *vif;
-
-       D(WIRELESS, "Wireless device '%s' is now up\n", wdev->name);
-       wdev->state = IFS_UP;
-       vlist_for_each_element(&wdev->interfaces, vif, node)
-               wireless_interface_handle_link(vif, true);
+       wdev_handle_config_change(wdev);
 }
 
 static void
 }
 
 static void
@@ -309,10 +382,30 @@ __wireless_device_set_down(struct wireless_device *wdev)
 }
 
 static void
 }
 
 static void
+wireless_device_mark_up(struct wireless_device *wdev)
+{
+       struct wireless_interface *vif;
+
+       if (wdev->cancel) {
+               wdev->cancel = false;
+               __wireless_device_set_down(wdev);
+               return;
+       }
+
+       D(WIRELESS, "Wireless device '%s' is now up\n", wdev->name);
+       wdev->state = IFS_UP;
+       vlist_for_each_element(&wdev->interfaces, vif, node)
+               wireless_interface_handle_link(vif, true);
+}
+
+static void
 wireless_device_retry_setup(struct wireless_device *wdev)
 {
 wireless_device_retry_setup(struct wireless_device *wdev)
 {
+       if (wdev->state == IFS_TEARDOWN || wdev->state == IFS_DOWN || wdev->cancel)
+               return;
+
        if (--wdev->retry < 0)
        if (--wdev->retry < 0)
-               wdev->autostart = false;
+               wdev->retry_setup_failed = true;
 
        __wireless_device_set_down(wdev);
 }
 
        __wireless_device_set_down(wdev);
 }
@@ -337,43 +430,18 @@ wireless_device_script_task_cb(struct netifd_process *proc, int ret)
 void
 wireless_device_set_down(struct wireless_device *wdev)
 {
 void
 wireless_device_set_down(struct wireless_device *wdev)
 {
+       wdev->retry_setup_failed = false;
        wdev->autostart = false;
        __wireless_device_set_down(wdev);
 }
 
 static void
        wdev->autostart = false;
        __wireless_device_set_down(wdev);
 }
 
 static void
-wireless_device_free(struct wireless_device *wdev)
-{
-    vlist_flush_all(&wdev->interfaces);
-    free(wdev->config);
-    free(wdev);
-}
-
-static void
-wdev_handle_config_change(struct wireless_device *wdev)
-{
-       switch(wdev->config_state) {
-       case IFC_NORMAL:
-               break;
-       case IFC_RELOAD:
-               if (wdev->autostart)
-                       __wireless_device_set_up(wdev);
-               break;
-       case IFC_REMOVE:
-               wireless_device_free(wdev);
-               break;
-       }
-}
-
-static void
 wdev_set_config_state(struct wireless_device *wdev, enum interface_config_state s)
 {
 wdev_set_config_state(struct wireless_device *wdev, enum interface_config_state s)
 {
-       enum interface_config_state old_state = wdev->config_state;
-
-       wdev->config_state = s;
-       if (old_state != IFC_NORMAL)
+       if (wdev->config_state != IFC_NORMAL)
                return;
 
                return;
 
+       wdev->config_state = s;
        if (wdev->state == IFS_DOWN)
                wdev_handle_config_change(wdev);
        else
        if (wdev->state == IFS_DOWN)
                wdev_handle_config_change(wdev);
        else
@@ -381,18 +449,32 @@ wdev_set_config_state(struct wireless_device *wdev, enum interface_config_state
 }
 
 static void
 }
 
 static void
+wdev_prepare_prev_config(struct wireless_device *wdev)
+{
+       if (wdev->prev_config)
+               return;
+
+       prepare_config(wdev, &b, false);
+       wdev->prev_config = blob_memdup(b.head);
+}
+
+static void
 wdev_change_config(struct wireless_device *wdev, struct wireless_device *wd_new)
 {
        struct blob_attr *new_config = wd_new->config;
 wdev_change_config(struct wireless_device *wdev, struct wireless_device *wd_new)
 {
        struct blob_attr *new_config = wd_new->config;
+       bool disabled = wd_new->disabled;
 
        free(wd_new);
 
 
        free(wd_new);
 
-       if (blob_attr_equal(wdev->config, new_config))
+       wdev_prepare_prev_config(wdev);
+       if (blob_attr_equal(wdev->config, new_config) && wdev->disabled == disabled)
                return;
 
        D(WIRELESS, "Update configuration of wireless device '%s'\n", wdev->name);
        free(wdev->config);
        wdev->config = blob_memdup(new_config);
                return;
 
        D(WIRELESS, "Update configuration of wireless device '%s'\n", wdev->name);
        free(wdev->config);
        wdev->config = blob_memdup(new_config);
+       wdev->disabled = disabled;
+       wdev->retry_setup_failed = false;
        wdev_set_config_state(wdev, IFC_RELOAD);
 }
 
        wdev_set_config_state(wdev, IFC_RELOAD);
 }
 
@@ -436,10 +518,10 @@ wireless_add_handler(const char *script, const char *name, json_object *obj)
                return;
 
        drv = calloc_a(sizeof(*drv),
                return;
 
        drv = calloc_a(sizeof(*drv),
-               &name_str, strlen(name) + 1,
-               &script_str, strlen(script) + 1,
                &dev_config, sizeof(*dev_config) + sizeof(void *),
                &dev_config, sizeof(*dev_config) + sizeof(void *),
-               &iface_config, sizeof(*iface_config) + sizeof(void *));
+               &iface_config, sizeof(*iface_config) + sizeof(void *),
+               &name_str, strlen(name) + 1,
+               &script_str, strlen(script) + 1);
 
        drv->name = strcpy(name_str, name);
        drv->script = strcpy(script_str, script);
 
        drv->name = strcpy(name_str, name);
        drv->script = strcpy(script_str, script);
@@ -460,8 +542,7 @@ wireless_add_handler(const char *script, const char *name, json_object *obj)
        D(WIRELESS, "Add handler for script %s: %s\n", script, name);
 }
 
        D(WIRELESS, "Add handler for script %s: %s\n", script, name);
 }
 
-static void __init
-wireless_init_list(void)
+void wireless_init(void)
 {
        vlist_init(&wireless_devices, avl_strcmp, wdev_update);
        wireless_devices.keep_old = true;
 {
        vlist_init(&wireless_devices, avl_strcmp, wdev_update);
        wireless_devices.keep_old = true;
@@ -485,7 +566,15 @@ wireless_interface_init_config(struct wireless_interface *vif)
        blobmsg_parse(vif_policy, __VIF_ATTR_MAX, tb, blob_data(vif->config), blob_len(vif->config));
 
        if ((cur = tb[VIF_ATTR_NETWORK]))
        blobmsg_parse(vif_policy, __VIF_ATTR_MAX, tb, blob_data(vif->config), blob_len(vif->config));
 
        if ((cur = tb[VIF_ATTR_NETWORK]))
-               vif->network = blobmsg_data(cur);
+               vif->network = cur;
+
+       cur = tb[VIF_ATTR_ISOLATE];
+       if (cur)
+               vif->isolate = blobmsg_get_bool(cur);
+
+       cur = tb[VIF_ATTR_MODE];
+       if (cur)
+               vif->ap_mode = !strcmp(blobmsg_get_string(cur), "ap");
 }
 
 static void
 }
 
 static void
@@ -502,23 +591,30 @@ vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
                wdev = vif_new->wdev;
 
        if (vif_old && vif_new) {
                wdev = vif_new->wdev;
 
        if (vif_old && vif_new) {
-               vif_old->section = vif_new->section;
+               free((void *) vif_old->section);
+               vif_old->section = strdup(vif_new->section);
                if (blob_attr_equal(vif_old->config, vif_new->config)) {
                        free(vif_new);
                        return;
                }
 
                D(WIRELESS, "Update wireless interface %s on device %s\n", vif_new->name, wdev->name);
                if (blob_attr_equal(vif_old->config, vif_new->config)) {
                        free(vif_new);
                        return;
                }
 
                D(WIRELESS, "Update wireless interface %s on device %s\n", vif_new->name, wdev->name);
+               wireless_interface_handle_link(vif_old, false);
                free(vif_old->config);
                vif_old->config = blob_memdup(vif_new->config);
                free(vif_old->config);
                vif_old->config = blob_memdup(vif_new->config);
+               vif_old->isolate = vif_new->isolate;
+               vif_old->ap_mode = vif_new->ap_mode;
                wireless_interface_init_config(vif_old);
                free(vif_new);
        } else if (vif_new) {
                D(WIRELESS, "Create new wireless interface %s on device %s\n", vif_new->name, wdev->name);
                wireless_interface_init_config(vif_old);
                free(vif_new);
        } else if (vif_new) {
                D(WIRELESS, "Create new wireless interface %s on device %s\n", vif_new->name, wdev->name);
+               vif_new->section = strdup(vif_new->section);
                vif_new->config = blob_memdup(vif_new->config);
                wireless_interface_init_config(vif_new);
        } else if (vif_old) {
                D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name);
                vif_new->config = blob_memdup(vif_new->config);
                wireless_interface_init_config(vif_new);
        } else if (vif_old) {
                D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name);
+               wireless_interface_handle_link(vif_old, false);
+               free((void *) vif_old->section);
                free(vif_old->config);
                free(vif_old);
        }
                free(vif_old->config);
                free(vif_old);
        }
@@ -585,22 +681,20 @@ wireless_device_create(struct wireless_driver *drv, const char *name, struct blo
        struct blob_attr *disabled;
 
        blobmsg_parse(&wdev_policy, 1, &disabled, blob_data(data), blob_len(data));
        struct blob_attr *disabled;
 
        blobmsg_parse(&wdev_policy, 1, &disabled, blob_data(data), blob_len(data));
-       if (disabled && blobmsg_get_bool(disabled))
-               return;
 
        wdev = calloc_a(sizeof(*wdev), &name_buf, strlen(name) + 1);
 
        wdev = calloc_a(sizeof(*wdev), &name_buf, strlen(name) + 1);
+       if (disabled && blobmsg_get_bool(disabled))
+               wdev->disabled = true;
        wdev->drv = drv;
        wdev->state = IFS_DOWN;
        wdev->config_state = IFC_NORMAL;
        wdev->name = strcpy(name_buf, name);
        wdev->config = data;
        wdev->drv = drv;
        wdev->state = IFS_DOWN;
        wdev->config_state = IFC_NORMAL;
        wdev->name = strcpy(name_buf, name);
        wdev->config = data;
-       wdev->config_autostart = true;
-       wdev->autostart = wdev->config_autostart;
+       wdev->retry_setup_failed = false;
+       wdev->autostart = true;
        INIT_LIST_HEAD(&wdev->script_proc);
        vlist_init(&wdev->interfaces, avl_strcmp, vif_update);
        wdev->interfaces.keep_old = true;
        INIT_LIST_HEAD(&wdev->script_proc);
        vlist_init(&wdev->interfaces, avl_strcmp, vif_update);
        wdev->interfaces.keep_old = true;
-       wdev->interfaces.no_delete = true;
-       vlist_add(&wireless_devices, &wdev->node, wdev->name);
 
        wdev->timeout.cb = wireless_device_setup_timeout;
        wdev->script_task.cb = wireless_device_script_task_cb;
 
        wdev->timeout.cb = wireless_device_setup_timeout;
        wdev->script_task.cb = wireless_device_script_task_cb;
@@ -611,6 +705,8 @@ wireless_device_create(struct wireless_driver *drv, const char *name, struct blo
        wdev->script_proc_fd.cb = wireless_proc_poll_fd;
 
        wdev->script_check.cb = wireless_device_check_script_tasks;
        wdev->script_proc_fd.cb = wireless_proc_poll_fd;
 
        wdev->script_check.cb = wireless_device_check_script_tasks;
+
+       vlist_add(&wireless_devices, &wdev->node, wdev->name);
 }
 
 void wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section)
 }
 
 void wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section)
@@ -629,11 +725,14 @@ void wireless_interface_create(struct wireless_device *wdev, struct blob_attr *d
 
        sprintf(name, "%d", wdev->vif_idx++);
 
 
        sprintf(name, "%d", wdev->vif_idx++);
 
-       vif = calloc_a(sizeof(*vif), &name_buf, strlen(name) + 1);
+       vif = calloc_a(sizeof(*vif),
+                      &name_buf, strlen(name) + 1);
        vif->name = strcpy(name_buf, name);
        vif->wdev = wdev;
        vif->config = data;
        vif->section = section;
        vif->name = strcpy(name_buf, name);
        vif->wdev = wdev;
        vif->config = data;
        vif->section = section;
+       vif->isolate = false;
+
        vlist_add(&wdev->interfaces, &vif->node, vif->name);
 }
 
        vlist_add(&wdev->interfaces, &vif->node, vif->name);
 }
 
@@ -642,13 +741,12 @@ wireless_interface_status(struct wireless_interface *iface, struct blob_buf *b)
 {
        void *i;
 
 {
        void *i;
 
-       i = blobmsg_open_table(b, iface->name);
+       i = blobmsg_open_table(b, NULL);
        if (iface->section)
                blobmsg_add_string(b, "section", iface->section);
        if (iface->ifname)
                blobmsg_add_string(b, "ifname", iface->ifname);
        if (iface->section)
                blobmsg_add_string(b, "section", iface->section);
        if (iface->ifname)
                blobmsg_add_string(b, "ifname", iface->ifname);
-       if (iface->data)
-               blob_put_raw(b, blob_data(iface->data), blob_len(iface->data));
+       put_container(b, iface->config, "config");
        blobmsg_close_table(b, i);
 }
 
        blobmsg_close_table(b, i);
 }
 
@@ -662,10 +760,38 @@ wireless_device_status(struct wireless_device *wdev, struct blob_buf *b)
        blobmsg_add_u8(b, "up", wdev->state == IFS_UP);
        blobmsg_add_u8(b, "pending", wdev->state == IFS_SETUP || wdev->state == IFS_TEARDOWN);
        blobmsg_add_u8(b, "autostart", wdev->autostart);
        blobmsg_add_u8(b, "up", wdev->state == IFS_UP);
        blobmsg_add_u8(b, "pending", wdev->state == IFS_SETUP || wdev->state == IFS_TEARDOWN);
        blobmsg_add_u8(b, "autostart", wdev->autostart);
-       i = blobmsg_open_table(b, "interfaces");
+       blobmsg_add_u8(b, "disabled", wdev->disabled);
+       blobmsg_add_u8(b, "retry_setup_failed", wdev->retry_setup_failed);
+       put_container(b, wdev->config, "config");
+
+       i = blobmsg_open_array(b, "interfaces");
        vlist_for_each_element(&wdev->interfaces, iface, node)
                wireless_interface_status(iface, b);
        vlist_for_each_element(&wdev->interfaces, iface, node)
                wireless_interface_status(iface, b);
-       blobmsg_close_table(b, i);
+       blobmsg_close_array(b, i);
+       blobmsg_close_table(b, c);
+}
+
+void
+wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b)
+{
+       struct uci_blob_param_list *p;
+       void *c, *d;
+       int i;
+
+       c = blobmsg_open_table(b, wdev->name);
+
+       d = blobmsg_open_table(b, "device");
+       p = wdev->drv->device.config;
+       for (i = 0; i < p->n_params; i++)
+               blobmsg_add_string(b, p->params[i].name, uci_get_validate_string(p, i));
+       blobmsg_close_table(b, d);
+
+       d = blobmsg_open_table(b, "interface");
+       p = wdev->drv->interface.config;
+       for (i = 0; i < p->n_params; i++)
+               blobmsg_add_string(b, p->params[i].name, uci_get_validate_string(p, i));
+       blobmsg_close_table(b, d);
+
        blobmsg_close_table(b, c);
 }
 
        blobmsg_close_table(b, c);
 }
 
@@ -706,6 +832,7 @@ wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data
        struct blob_attr *tb[__PROC_ATTR_MAX];
        struct wireless_process *proc;
        char *name;
        struct blob_attr *tb[__PROC_ATTR_MAX];
        struct wireless_process *proc;
        char *name;
+       int pid;
 
        if (!data)
                return UBUS_STATUS_INVALID_ARGUMENT;
 
        if (!data)
                return UBUS_STATUS_INVALID_ARGUMENT;
@@ -714,10 +841,14 @@ wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data
        if (!tb[PROC_ATTR_PID] || !tb[PROC_ATTR_EXE])
                return UBUS_STATUS_INVALID_ARGUMENT;
 
        if (!tb[PROC_ATTR_PID] || !tb[PROC_ATTR_EXE])
                return UBUS_STATUS_INVALID_ARGUMENT;
 
+       pid = blobmsg_get_u32(tb[PROC_ATTR_PID]);
+       if (pid < 2)
+               return UBUS_STATUS_INVALID_ARGUMENT;
+
        proc = calloc_a(sizeof(*proc),
                &name, strlen(blobmsg_data(tb[PROC_ATTR_EXE])) + 1);
 
        proc = calloc_a(sizeof(*proc),
                &name, strlen(blobmsg_data(tb[PROC_ATTR_EXE])) + 1);
 
-       proc->pid = blobmsg_get_u32(tb[PROC_ATTR_PID]);
+       proc->pid = pid;
        proc->exe = strcpy(name, blobmsg_data(tb[PROC_ATTR_EXE]));
 
        if (tb[PROC_ATTR_REQUIRED])
        proc->exe = strcpy(name, blobmsg_data(tb[PROC_ATTR_EXE]));
 
        if (tb[PROC_ATTR_REQUIRED])
@@ -754,7 +885,7 @@ wireless_device_process_kill_all(struct wireless_device *wdev, struct blob_attr
                signal = blobmsg_get_u32(cur);
 
        if ((cur = tb[KILL_ATTR_IMMEDIATE]))
                signal = blobmsg_get_u32(cur);
 
        if ((cur = tb[KILL_ATTR_IMMEDIATE]))
-               immediate = blobmsg_get_u32(cur);
+               immediate = blobmsg_get_bool(cur);
 
        if (wdev->state != IFS_TEARDOWN || wdev->kill_request)
                return UBUS_STATUS_PERMISSION_DENIED;
 
        if (wdev->state != IFS_TEARDOWN || wdev->kill_request)
                return UBUS_STATUS_PERMISSION_DENIED;
@@ -836,9 +967,6 @@ wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data,
                if (wdev->state != IFS_SETUP)
                        return UBUS_STATUS_PERMISSION_DENIED;
 
                if (wdev->state != IFS_SETUP)
                        return UBUS_STATUS_PERMISSION_DENIED;
 
-               if (wdev->cancel)
-                       return 0;
-
                wireless_device_mark_up(wdev);
                break;
        case NOTIFY_CMD_SET_DATA:
                wireless_device_mark_up(wdev);
                break;
        case NOTIFY_CMD_SET_DATA:
@@ -873,6 +1001,5 @@ wireless_start_pending(void)
        struct wireless_device *wdev;
 
        vlist_for_each_element(&wireless_devices, wdev, node)
        struct wireless_device *wdev;
 
        vlist_for_each_element(&wireless_devices, wdev, node)
-               if (wdev->autostart)
-                       __wireless_device_set_up(wdev);
+               __wireless_device_set_up(wdev);
 }
 }