2 * netifd - network interface daemon
3 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
20 #define WIRELESS_SETUP_RETRY 3
22 struct vlist_tree wireless_devices;
23 struct avl_tree wireless_drivers;
24 static struct blob_buf b;
27 static const struct blobmsg_policy wdev_policy =
28 { .name = "disabled", .type = BLOBMSG_TYPE_BOOL };
30 static const struct uci_blob_param_list wdev_param = {
32 .params = &wdev_policy,
41 static const struct blobmsg_policy vif_policy[__VIF_ATTR_MAX] = {
42 [VIF_ATTR_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
43 [VIF_ATTR_NETWORK] = { .name = "network", .type = BLOBMSG_TYPE_ARRAY },
46 static const struct uci_blob_param_list vif_param = {
47 .n_params = ARRAY_SIZE(vif_policy),
52 put_container(struct blob_buf *buf, struct blob_attr *attr, const char *name)
54 void *c = blobmsg_open_table(&b, name);
55 blob_put_raw(&b, blob_data(attr), blob_len(attr));
56 blobmsg_close_table(&b, c);
60 vif_config_add_bridge(struct blob_buf *buf, struct blob_attr *networks, bool prepare)
62 struct interface *iface;
63 struct device *dev = NULL;
64 struct blob_attr *cur;
71 blobmsg_for_each_attr(cur, networks, rem) {
72 network = blobmsg_data(cur);
74 iface = vlist_find(&interfaces, network, iface, node);
78 dev = iface->main_dev.dev;
82 if (dev->type != &bridge_device_type)
89 if (dev->hotplug_ops && dev->hotplug_ops->prepare)
90 dev->hotplug_ops->prepare(dev);
92 blobmsg_add_string(buf, "bridge", dev->ifname);
96 prepare_config(struct wireless_device *wdev, struct blob_buf *buf, bool up)
98 struct wireless_interface *vif;
101 blob_buf_init(&b, 0);
102 put_container(&b, wdev->config, "config");
104 blobmsg_add_blob(&b, wdev->data);
106 l = blobmsg_open_table(&b, "interfaces");
107 vlist_for_each_element(&wdev->interfaces, vif, node) {
108 i = blobmsg_open_table(&b, vif->name);
109 vif_config_add_bridge(&b, vif->network, up);
110 put_container(&b, vif->config, "config");
112 blobmsg_add_blob(&b, vif->data);
113 blobmsg_close_table(&b, i);
115 blobmsg_close_table(&b, l);
119 wireless_process_check(struct wireless_process *proc)
121 return check_pid_path(proc->pid, proc->exe);
125 wireless_complete_kill_request(struct wireless_device *wdev)
127 if (!wdev->kill_request)
130 ubus_complete_deferred_request(ubus_ctx, wdev->kill_request, 0);
131 free(wdev->kill_request);
132 wdev->kill_request = NULL;
136 wireless_process_free(struct wireless_device *wdev, struct wireless_process *proc)
138 D(WIRELESS, "Wireless device '%s' free pid %d\n", wdev->name, proc->pid);
139 list_del(&proc->list);
142 if (list_empty(&wdev->script_proc))
143 wireless_complete_kill_request(wdev);
147 wireless_close_script_proc_fd(struct wireless_device *wdev)
149 if (wdev->script_proc_fd.fd < 0)
152 uloop_fd_delete(&wdev->script_proc_fd);
153 close(wdev->script_proc_fd.fd);
154 wdev->script_proc_fd.fd = -1;
158 wireless_process_kill_all(struct wireless_device *wdev, int signal, bool free)
160 struct wireless_process *proc, *tmp;
162 list_for_each_entry_safe(proc, tmp, &wdev->script_proc, list) {
163 bool check = wireless_process_check(proc);
166 D(WIRELESS, "Wireless device '%s' kill pid %d\n", wdev->name, proc->pid);
167 kill(proc->pid, signal);
171 wireless_process_free(wdev, proc);
175 wireless_close_script_proc_fd(wdev);
179 wireless_device_free_state(struct wireless_device *wdev)
181 struct wireless_interface *vif;
183 uloop_timeout_cancel(&wdev->script_check);
184 uloop_timeout_cancel(&wdev->timeout);
185 wireless_complete_kill_request(wdev);
188 vlist_for_each_element(&wdev->interfaces, vif, node) {
195 static void wireless_interface_handle_link(struct wireless_interface *vif, bool up)
197 struct interface *iface;
198 struct blob_attr *cur;
202 if (!vif->network || !vif->ifname)
206 struct device *dev = device_get(vif->ifname, 2);
208 dev->wireless = true;
211 blobmsg_for_each_attr(cur, vif->network, rem) {
212 network = blobmsg_data(cur);
214 iface = vlist_find(&interfaces, network, iface, node);
218 interface_handle_link(iface, vif->ifname, up, true);
223 wireless_device_setup_cancel(struct wireless_device *wdev)
228 D(WIRELESS, "Cancel wireless device '%s' setup\n", wdev->name);
230 uloop_timeout_set(&wdev->timeout, 10 * 1000);
234 wireless_device_run_handler(struct wireless_device *wdev, bool up)
236 const char *action = up ? "setup" : "teardown";
240 int fds[2] = { -1, -1 };
242 D(WIRELESS, "Wireless device '%s' run %s handler\n", wdev->name, action);
243 prepare_config(wdev, &b, up);
244 config = blobmsg_format_json(b.head, true);
246 argv[i++] = wdev->drv->script;
247 argv[i++] = wdev->drv->name;
249 argv[i++] = wdev->name;
253 if (up && pipe(fds) == 0) {
254 wdev->script_proc_fd.fd = fds[0];
255 uloop_fd_add(&wdev->script_proc_fd,
256 ULOOP_READ | ULOOP_EDGE_TRIGGER);
259 netifd_start_process(argv, NULL, &wdev->script_task);
268 __wireless_device_set_up(struct wireless_device *wdev)
273 if (wdev->state != IFS_DOWN || config_init)
276 wdev->state = IFS_SETUP;
277 wireless_device_run_handler(wdev, true);
281 wireless_device_free(struct wireless_device *wdev)
283 vlist_flush_all(&wdev->interfaces);
284 avl_delete(&wireless_devices.avl, &wdev->node.avl);
290 wdev_handle_config_change(struct wireless_device *wdev)
292 enum interface_config_state state = wdev->config_state;
297 wdev->config_state = IFC_NORMAL;
299 __wireless_device_set_up(wdev);
302 wireless_device_free(wdev);
308 wireless_device_mark_down(struct wireless_device *wdev)
310 struct wireless_interface *vif;
312 D(WIRELESS, "Wireless device '%s' is now down\n", wdev->name);
314 vlist_for_each_element(&wdev->interfaces, vif, node)
315 wireless_interface_handle_link(vif, false);
317 wireless_process_kill_all(wdev, SIGTERM, true);
319 wdev->cancel = false;
320 wdev->state = IFS_DOWN;
321 wireless_device_free_state(wdev);
322 wdev_handle_config_change(wdev);
326 wireless_device_setup_timeout(struct uloop_timeout *timeout)
328 struct wireless_device *wdev = container_of(timeout, struct wireless_device, timeout);
330 netifd_kill_process(&wdev->script_task);
331 wdev->script_task.cb(&wdev->script_task, -1);
332 wireless_device_mark_down(wdev);
336 wireless_device_set_up(struct wireless_device *wdev)
338 wdev->retry = WIRELESS_SETUP_RETRY;
339 wdev->autostart = true;
340 __wireless_device_set_up(wdev);
344 __wireless_device_set_down(struct wireless_device *wdev)
346 if (wdev->state == IFS_TEARDOWN || wdev->state == IFS_DOWN)
349 if (wdev->script_task.uloop.pending) {
350 wireless_device_setup_cancel(wdev);
354 wdev->state = IFS_TEARDOWN;
355 wireless_device_run_handler(wdev, false);
359 wireless_device_mark_up(struct wireless_device *wdev)
361 struct wireless_interface *vif;
364 wdev->cancel = false;
365 __wireless_device_set_down(wdev);
369 D(WIRELESS, "Wireless device '%s' is now up\n", wdev->name);
370 wdev->state = IFS_UP;
371 vlist_for_each_element(&wdev->interfaces, vif, node)
372 wireless_interface_handle_link(vif, true);
376 wireless_device_retry_setup(struct wireless_device *wdev)
378 if (wdev->state == IFS_TEARDOWN || wdev->state == IFS_DOWN || wdev->cancel)
381 if (--wdev->retry < 0)
382 wdev->autostart = false;
384 __wireless_device_set_down(wdev);
388 wireless_device_script_task_cb(struct netifd_process *proc, int ret)
390 struct wireless_device *wdev = container_of(proc, struct wireless_device, script_task);
392 switch (wdev->state) {
394 wireless_device_retry_setup(wdev);
397 wireless_device_mark_down(wdev);
405 wireless_device_set_down(struct wireless_device *wdev)
407 wdev->autostart = false;
408 __wireless_device_set_down(wdev);
412 wdev_set_config_state(struct wireless_device *wdev, enum interface_config_state s)
414 if (wdev->config_state != IFC_NORMAL)
417 wdev->config_state = s;
418 if (wdev->state == IFS_DOWN)
419 wdev_handle_config_change(wdev);
421 __wireless_device_set_down(wdev);
425 wdev_change_config(struct wireless_device *wdev, struct wireless_device *wd_new)
427 struct blob_attr *new_config = wd_new->config;
428 bool disabled = wd_new->disabled;
432 if (blob_attr_equal(wdev->config, new_config) && wdev->disabled == disabled)
435 D(WIRELESS, "Update configuration of wireless device '%s'\n", wdev->name);
437 wdev->config = blob_memdup(new_config);
438 wdev->disabled = disabled;
439 wdev_set_config_state(wdev, IFC_RELOAD);
443 wdev_create(struct wireless_device *wdev)
445 wdev->retry = WIRELESS_SETUP_RETRY;
446 wdev->config = blob_memdup(wdev->config);
450 wdev_update(struct vlist_tree *tree, struct vlist_node *node_new,
451 struct vlist_node *node_old)
453 struct wireless_device *wd_old = container_of(node_old, struct wireless_device, node);
454 struct wireless_device *wd_new = container_of(node_new, struct wireless_device, node);
456 if (wd_old && wd_new) {
457 wdev_change_config(wd_old, wd_new);
459 D(WIRELESS, "Delete wireless device '%s'\n", wd_old->name);
460 wdev_set_config_state(wd_old, IFC_REMOVE);
462 D(WIRELESS, "Create wireless device '%s'\n", wd_new->name);
468 wireless_add_handler(const char *script, const char *name, json_object *obj)
470 struct wireless_driver *drv;
471 char *name_str, *script_str;
472 json_object *dev_config_obj, *iface_config_obj;
473 struct uci_blob_param_list *dev_config, *iface_config;
475 dev_config_obj = json_get_field(obj, "device", json_type_array);
476 iface_config_obj = json_get_field(obj, "iface", json_type_array);
478 if (!dev_config_obj || !iface_config_obj)
481 drv = calloc_a(sizeof(*drv),
482 &dev_config, sizeof(*dev_config) + sizeof(void *),
483 &iface_config, sizeof(*iface_config) + sizeof(void *),
484 &name_str, strlen(name) + 1,
485 &script_str, strlen(script) + 1);
487 drv->name = strcpy(name_str, name);
488 drv->script = strcpy(script_str, script);
490 dev_config->n_next = 1;
491 dev_config->next[0] = &wdev_param;
492 drv->device.config = dev_config;
494 iface_config->n_next = 1;
495 iface_config->next[0] = &vif_param;
496 drv->interface.config = iface_config;
498 drv->device.buf = netifd_handler_parse_config(drv->device.config, dev_config_obj);
499 drv->interface.buf = netifd_handler_parse_config(drv->interface.config, iface_config_obj);
501 drv->node.key = drv->name;
502 avl_insert(&wireless_drivers, &drv->node);
503 D(WIRELESS, "Add handler for script %s: %s\n", script, name);
506 void wireless_init(void)
508 vlist_init(&wireless_devices, avl_strcmp, wdev_update);
509 wireless_devices.keep_old = true;
510 wireless_devices.no_delete = true;
512 avl_init(&wireless_drivers, avl_strcmp, false, NULL);
513 drv_fd = netifd_open_subdir("wireless");
517 netifd_init_script_handlers(drv_fd, wireless_add_handler);
521 wireless_interface_init_config(struct wireless_interface *vif)
523 struct blob_attr *tb[__VIF_ATTR_MAX];
524 struct blob_attr *cur;
527 blobmsg_parse(vif_policy, __VIF_ATTR_MAX, tb, blob_data(vif->config), blob_len(vif->config));
529 if ((cur = tb[VIF_ATTR_NETWORK]))
534 vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
535 struct vlist_node *node_old)
537 struct wireless_interface *vif_old = container_of(node_old, struct wireless_interface, node);
538 struct wireless_interface *vif_new = container_of(node_new, struct wireless_interface, node);
539 struct wireless_device *wdev;
542 wdev = vif_old->wdev;
544 wdev = vif_new->wdev;
546 if (vif_old && vif_new) {
547 vif_old->section = vif_new->section;
548 if (blob_attr_equal(vif_old->config, vif_new->config)) {
553 D(WIRELESS, "Update wireless interface %s on device %s\n", vif_new->name, wdev->name);
554 free(vif_old->config);
555 vif_old->config = blob_memdup(vif_new->config);
556 wireless_interface_init_config(vif_old);
558 } else if (vif_new) {
559 D(WIRELESS, "Create new wireless interface %s on device %s\n", vif_new->name, wdev->name);
560 vif_new->config = blob_memdup(vif_new->config);
561 wireless_interface_init_config(vif_new);
562 } else if (vif_old) {
563 D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name);
564 free(vif_old->config);
568 wdev_set_config_state(wdev, IFC_RELOAD);
572 wireless_proc_poll_fd(struct uloop_fd *fd, unsigned int events)
574 struct wireless_device *wdev = container_of(fd, struct wireless_device, script_proc_fd);
578 int b = read(fd->fd, buf, sizeof(buf));
594 uloop_timeout_set(&wdev->script_check, 0);
595 wireless_close_script_proc_fd(wdev);
599 wireless_device_check_script_tasks(struct uloop_timeout *timeout)
601 struct wireless_device *wdev = container_of(timeout, struct wireless_device, script_check);
602 struct wireless_process *proc, *tmp;
603 bool restart = false;
605 list_for_each_entry_safe(proc, tmp, &wdev->script_proc, list) {
606 if (wireless_process_check(proc))
609 D(WIRELESS, "Wireless device '%s' pid %d has terminated\n", wdev->name, proc->pid);
613 wireless_process_free(wdev, proc);
617 wireless_device_retry_setup(wdev);
619 uloop_timeout_set(&wdev->script_check, 1000);
623 wireless_device_create(struct wireless_driver *drv, const char *name, struct blob_attr *data)
625 struct wireless_device *wdev;
627 struct blob_attr *disabled;
629 blobmsg_parse(&wdev_policy, 1, &disabled, blob_data(data), blob_len(data));
631 wdev = calloc_a(sizeof(*wdev), &name_buf, strlen(name) + 1);
632 if (disabled && blobmsg_get_bool(disabled))
633 wdev->disabled = true;
635 wdev->state = IFS_DOWN;
636 wdev->config_state = IFC_NORMAL;
637 wdev->name = strcpy(name_buf, name);
639 wdev->config_autostart = true;
640 wdev->autostart = wdev->config_autostart;
641 INIT_LIST_HEAD(&wdev->script_proc);
642 vlist_init(&wdev->interfaces, avl_strcmp, vif_update);
643 wdev->interfaces.keep_old = true;
645 wdev->timeout.cb = wireless_device_setup_timeout;
646 wdev->script_task.cb = wireless_device_script_task_cb;
647 wdev->script_task.dir_fd = drv_fd;
648 wdev->script_task.log_prefix = wdev->name;
650 wdev->script_proc_fd.fd = -1;
651 wdev->script_proc_fd.cb = wireless_proc_poll_fd;
653 wdev->script_check.cb = wireless_device_check_script_tasks;
655 vlist_add(&wireless_devices, &wdev->node, wdev->name);
658 void wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section)
660 struct wireless_interface *vif;
661 struct blob_attr *tb[__VIF_ATTR_MAX];
662 struct blob_attr *cur;
666 blobmsg_parse(vif_policy, __VIF_ATTR_MAX, tb, blob_data(data), blob_len(data));
668 cur = tb[VIF_ATTR_DISABLED];
669 if (cur && blobmsg_get_bool(cur))
672 sprintf(name, "%d", wdev->vif_idx++);
674 vif = calloc_a(sizeof(*vif), &name_buf, strlen(name) + 1);
675 vif->name = strcpy(name_buf, name);
678 vif->section = section;
679 vlist_add(&wdev->interfaces, &vif->node, vif->name);
683 wireless_interface_status(struct wireless_interface *iface, struct blob_buf *b)
687 i = blobmsg_open_table(b, NULL);
689 blobmsg_add_string(b, "section", iface->section);
691 blobmsg_add_string(b, "ifname", iface->ifname);
693 blob_put_raw(b, blob_data(iface->data), blob_len(iface->data));
694 blobmsg_close_table(b, i);
698 wireless_device_status(struct wireless_device *wdev, struct blob_buf *b)
700 struct wireless_interface *iface;
703 c = blobmsg_open_table(b, wdev->name);
704 blobmsg_add_u8(b, "up", wdev->state == IFS_UP);
705 blobmsg_add_u8(b, "pending", wdev->state == IFS_SETUP || wdev->state == IFS_TEARDOWN);
706 blobmsg_add_u8(b, "autostart", wdev->autostart);
707 blobmsg_add_u8(b, "disabled", wdev->disabled);
709 i = blobmsg_open_array(b, "interfaces");
710 vlist_for_each_element(&wdev->interfaces, iface, node)
711 wireless_interface_status(iface, b);
712 blobmsg_close_array(b, i);
713 blobmsg_close_table(b, c);
717 wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b)
719 struct uci_blob_param_list *p;
723 c = blobmsg_open_table(b, wdev->name);
725 d = blobmsg_open_table(b, "device");
726 p = wdev->drv->device.config;
727 for (i = 0; i < p->n_params; i++)
728 blobmsg_add_string(b, p->params[i].name, uci_get_validate_string(p, i));
729 blobmsg_close_table(b, d);
731 d = blobmsg_open_table(b, "interface");
732 p = wdev->drv->interface.config;
733 for (i = 0; i < p->n_params; i++)
734 blobmsg_add_string(b, p->params[i].name, uci_get_validate_string(p, i));
735 blobmsg_close_table(b, d);
737 blobmsg_close_table(b, c);
741 wireless_interface_set_data(struct wireless_interface *vif)
747 static const struct blobmsg_policy data_policy[__VIF_DATA_MAX] = {
748 [VIF_DATA_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
750 struct blob_attr *tb[__VIF_DATA_MAX];
751 struct blob_attr *cur;
753 blobmsg_parse(data_policy, __VIF_DATA_MAX, tb,
754 blobmsg_data(vif->data), blobmsg_data_len(vif->data));
756 if ((cur = tb[VIF_DATA_IFNAME]))
757 vif->ifname = blobmsg_data(cur);
761 wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data)
769 static const struct blobmsg_policy proc_policy[__PROC_ATTR_MAX] = {
770 [PROC_ATTR_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 },
771 [PROC_ATTR_EXE] = { .name = "exe", .type = BLOBMSG_TYPE_STRING },
772 [PROC_ATTR_REQUIRED] = { .name = "required", .type = BLOBMSG_TYPE_BOOL },
774 struct blob_attr *tb[__PROC_ATTR_MAX];
775 struct wireless_process *proc;
780 return UBUS_STATUS_INVALID_ARGUMENT;
782 blobmsg_parse(proc_policy, __PROC_ATTR_MAX, tb, blobmsg_data(data), blobmsg_data_len(data));
783 if (!tb[PROC_ATTR_PID] || !tb[PROC_ATTR_EXE])
784 return UBUS_STATUS_INVALID_ARGUMENT;
786 pid = blobmsg_get_u32(tb[PROC_ATTR_PID]);
788 return UBUS_STATUS_INVALID_ARGUMENT;
790 proc = calloc_a(sizeof(*proc),
791 &name, strlen(blobmsg_data(tb[PROC_ATTR_EXE])) + 1);
794 proc->exe = strcpy(name, blobmsg_data(tb[PROC_ATTR_EXE]));
796 if (tb[PROC_ATTR_REQUIRED])
797 proc->required = blobmsg_get_bool(tb[PROC_ATTR_REQUIRED]);
799 D(WIRELESS, "Wireless device '%s' add pid %d\n", wdev->name, proc->pid);
800 list_add(&proc->list, &wdev->script_proc);
801 uloop_timeout_set(&wdev->script_check, 0);
807 wireless_device_process_kill_all(struct wireless_device *wdev, struct blob_attr *data,
808 struct ubus_request_data *req)
815 static const struct blobmsg_policy kill_policy[__KILL_ATTR_MAX] = {
816 [KILL_ATTR_SIGNAL] = { .name = "signal", .type = BLOBMSG_TYPE_INT32 },
817 [KILL_ATTR_IMMEDIATE] = { .name = "immediate", .type = BLOBMSG_TYPE_BOOL },
819 struct blob_attr *tb[__KILL_ATTR_MAX];
820 struct blob_attr *cur;
821 bool immediate = false;
822 int signal = SIGTERM;
824 blobmsg_parse(kill_policy, __KILL_ATTR_MAX, tb, blobmsg_data(data), blobmsg_data_len(data));
826 if ((cur = tb[KILL_ATTR_SIGNAL]))
827 signal = blobmsg_get_u32(cur);
829 if ((cur = tb[KILL_ATTR_IMMEDIATE]))
830 immediate = blobmsg_get_bool(cur);
832 if (wdev->state != IFS_TEARDOWN || wdev->kill_request)
833 return UBUS_STATUS_PERMISSION_DENIED;
835 wireless_process_kill_all(wdev, signal, immediate);
837 if (list_empty(&wdev->script_proc))
840 wdev->kill_request = calloc(1, sizeof(*wdev->kill_request));
841 ubus_defer_request(ubus_ctx, req, wdev->kill_request);
847 wireless_device_set_retry(struct wireless_device *wdev, struct blob_attr *data)
849 static const struct blobmsg_policy retry_policy = {
850 .name = "retry", .type = BLOBMSG_TYPE_INT32
852 struct blob_attr *val;
854 blobmsg_parse(&retry_policy, 1, &val, blobmsg_data(data), blobmsg_data_len(data));
856 return UBUS_STATUS_INVALID_ARGUMENT;
858 wdev->retry = blobmsg_get_u32(val);
864 NOTIFY_CMD_SET_DATA = 1,
865 NOTIFY_CMD_PROCESS_ADD = 2,
866 NOTIFY_CMD_PROCESS_KILL_ALL = 3,
867 NOTIFY_CMD_SET_RETRY = 4,
871 wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data,
872 struct ubus_request_data *req)
880 static const struct blobmsg_policy notify_policy[__NOTIFY_MAX] = {
881 [NOTIFY_ATTR_COMMAND] = { .name = "command", .type = BLOBMSG_TYPE_INT32 },
882 [NOTIFY_ATTR_VIF] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
883 [NOTIFY_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
885 struct wireless_interface *vif = NULL;
886 struct blob_attr *tb[__NOTIFY_MAX];
887 struct blob_attr *cur, **pdata;
889 blobmsg_parse(notify_policy, __NOTIFY_MAX, tb, blob_data(data), blob_len(data));
891 if (!tb[NOTIFY_ATTR_COMMAND])
892 return UBUS_STATUS_INVALID_ARGUMENT;
894 if ((cur = tb[NOTIFY_ATTR_VIF]) != NULL) {
895 vif = vlist_find(&wdev->interfaces, blobmsg_data(cur), vif, node);
897 return UBUS_STATUS_NOT_FOUND;
900 cur = tb[NOTIFY_ATTR_DATA];
902 return UBUS_STATUS_INVALID_ARGUMENT;
904 switch (blobmsg_get_u32(tb[NOTIFY_ATTR_COMMAND])) {
907 return UBUS_STATUS_INVALID_ARGUMENT;
909 if (wdev->state != IFS_SETUP)
910 return UBUS_STATUS_PERMISSION_DENIED;
912 wireless_device_mark_up(wdev);
914 case NOTIFY_CMD_SET_DATA:
921 return UBUS_STATUS_INVALID_ARGUMENT;
923 *pdata = blob_memdup(cur);
925 wireless_interface_set_data(vif);
927 case NOTIFY_CMD_PROCESS_ADD:
928 return wireless_device_add_process(wdev, cur);
929 case NOTIFY_CMD_PROCESS_KILL_ALL:
930 return wireless_device_process_kill_all(wdev, cur, req);
931 case NOTIFY_CMD_SET_RETRY:
932 return wireless_device_set_retry(wdev, cur);
934 return UBUS_STATUS_INVALID_ARGUMENT;
941 wireless_start_pending(void)
943 struct wireless_device *wdev;
945 vlist_for_each_element(&wireless_devices, wdev, node)
947 __wireless_device_set_up(wdev);