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,
43 static const struct blobmsg_policy vif_policy[__VIF_ATTR_MAX] = {
44 [VIF_ATTR_DISABLED] = { .name = "disabled", .type = BLOBMSG_TYPE_BOOL },
45 [VIF_ATTR_NETWORK] = { .name = "network", .type = BLOBMSG_TYPE_ARRAY },
46 [VIF_ATTR_ISOLATE] = { .name = "isolate", .type = BLOBMSG_TYPE_BOOL },
47 [VIF_ATTR_MODE] = { .name = "mode", .type = BLOBMSG_TYPE_STRING },
50 static const struct uci_blob_param_list vif_param = {
51 .n_params = ARRAY_SIZE(vif_policy),
56 put_container(struct blob_buf *buf, struct blob_attr *attr, const char *name)
58 void *c = blobmsg_open_table(buf, name);
59 blob_put_raw(buf, blob_data(attr), blob_len(attr));
60 blobmsg_close_table(buf, c);
64 vif_config_add_bridge(struct blob_buf *buf, struct blob_attr *networks, bool prepare)
66 struct interface *iface;
67 struct device *dev = NULL;
68 struct blob_attr *cur;
75 blobmsg_for_each_attr(cur, networks, rem) {
76 network = blobmsg_data(cur);
78 iface = vlist_find(&interfaces, network, iface, node);
82 dev = iface->main_dev.dev;
86 if (dev->type != &bridge_device_type)
93 if (dev->hotplug_ops && dev->hotplug_ops->prepare)
94 dev->hotplug_ops->prepare(dev);
96 blobmsg_add_string(buf, "bridge", dev->ifname);
98 if (dev->settings.flags & DEV_OPT_MULTICAST_TO_UNICAST)
99 blobmsg_add_u8(buf, "multicast_to_unicast",
100 dev->settings.multicast_to_unicast);
104 prepare_config(struct wireless_device *wdev, struct blob_buf *buf, bool up)
106 struct wireless_interface *vif;
109 blob_buf_init(&b, 0);
110 put_container(&b, wdev->config, "config");
112 blobmsg_add_blob(&b, wdev->data);
114 l = blobmsg_open_table(&b, "interfaces");
115 vlist_for_each_element(&wdev->interfaces, vif, node) {
116 i = blobmsg_open_table(&b, vif->name);
117 vif_config_add_bridge(&b, vif->network, up);
118 put_container(&b, vif->config, "config");
120 blobmsg_add_blob(&b, vif->data);
121 blobmsg_close_table(&b, i);
123 blobmsg_close_table(&b, l);
127 wireless_process_check(struct wireless_process *proc)
129 return check_pid_path(proc->pid, proc->exe);
133 wireless_complete_kill_request(struct wireless_device *wdev)
135 if (!wdev->kill_request)
138 ubus_complete_deferred_request(ubus_ctx, wdev->kill_request, 0);
139 free(wdev->kill_request);
140 wdev->kill_request = NULL;
144 wireless_process_free(struct wireless_device *wdev, struct wireless_process *proc)
146 D(WIRELESS, "Wireless device '%s' free pid %d\n", wdev->name, proc->pid);
147 list_del(&proc->list);
150 if (list_empty(&wdev->script_proc))
151 wireless_complete_kill_request(wdev);
155 wireless_close_script_proc_fd(struct wireless_device *wdev)
157 if (wdev->script_proc_fd.fd < 0)
160 uloop_fd_delete(&wdev->script_proc_fd);
161 close(wdev->script_proc_fd.fd);
162 wdev->script_proc_fd.fd = -1;
166 wireless_process_kill_all(struct wireless_device *wdev, int signal, bool free)
168 struct wireless_process *proc, *tmp;
170 list_for_each_entry_safe(proc, tmp, &wdev->script_proc, list) {
171 bool check = wireless_process_check(proc);
174 D(WIRELESS, "Wireless device '%s' kill pid %d\n", wdev->name, proc->pid);
175 kill(proc->pid, signal);
179 wireless_process_free(wdev, proc);
183 wireless_close_script_proc_fd(wdev);
187 wireless_device_free_state(struct wireless_device *wdev)
189 struct wireless_interface *vif;
191 uloop_timeout_cancel(&wdev->script_check);
192 uloop_timeout_cancel(&wdev->timeout);
193 wireless_complete_kill_request(wdev);
196 vlist_for_each_element(&wdev->interfaces, vif, node) {
203 static void wireless_interface_handle_link(struct wireless_interface *vif, bool up)
205 struct interface *iface;
206 struct blob_attr *cur;
210 if (!vif->network || !vif->ifname)
214 struct device *dev = device_get(vif->ifname, 2);
216 dev->wireless_isolate = vif->isolate;
217 dev->wireless = true;
218 dev->wireless_ap = vif->ap_mode;
222 blobmsg_for_each_attr(cur, vif->network, rem) {
223 network = blobmsg_data(cur);
225 iface = vlist_find(&interfaces, network, iface, node);
229 interface_handle_link(iface, vif->ifname, up, true);
234 wireless_device_setup_cancel(struct wireless_device *wdev)
239 D(WIRELESS, "Cancel wireless device '%s' setup\n", wdev->name);
241 uloop_timeout_set(&wdev->timeout, 10 * 1000);
245 wireless_device_run_handler(struct wireless_device *wdev, bool up)
247 const char *action = up ? "setup" : "teardown";
251 int fds[2] = { -1, -1 };
253 D(WIRELESS, "Wireless device '%s' run %s handler\n", wdev->name, action);
254 if (!up && wdev->prev_config) {
255 config = blobmsg_format_json(wdev->prev_config, true);
256 free(wdev->prev_config);
257 wdev->prev_config = NULL;
259 prepare_config(wdev, &b, up);
260 config = blobmsg_format_json(b.head, true);
263 argv[i++] = wdev->drv->script;
264 argv[i++] = wdev->drv->name;
266 argv[i++] = wdev->name;
270 if (up && pipe(fds) == 0) {
271 wdev->script_proc_fd.fd = fds[0];
272 uloop_fd_add(&wdev->script_proc_fd,
273 ULOOP_READ | ULOOP_EDGE_TRIGGER);
276 netifd_start_process(argv, NULL, &wdev->script_task);
285 __wireless_device_set_up(struct wireless_device *wdev)
290 if (wdev->retry_setup_failed)
293 if (!wdev->autostart)
296 if (wdev->state != IFS_DOWN || config_init)
299 free(wdev->prev_config);
300 wdev->prev_config = NULL;
301 wdev->state = IFS_SETUP;
302 wireless_device_run_handler(wdev, true);
306 wireless_device_free(struct wireless_device *wdev)
308 vlist_flush_all(&wdev->interfaces);
309 avl_delete(&wireless_devices.avl, &wdev->node.avl);
311 free(wdev->prev_config);
316 wdev_handle_config_change(struct wireless_device *wdev)
318 enum interface_config_state state = wdev->config_state;
323 __wireless_device_set_up(wdev);
325 wdev->config_state = IFC_NORMAL;
328 wireless_device_free(wdev);
334 wireless_device_mark_down(struct wireless_device *wdev)
336 struct wireless_interface *vif;
338 D(WIRELESS, "Wireless device '%s' is now down\n", wdev->name);
340 vlist_for_each_element(&wdev->interfaces, vif, node)
341 wireless_interface_handle_link(vif, false);
343 wireless_process_kill_all(wdev, SIGTERM, true);
345 wdev->cancel = false;
346 wdev->state = IFS_DOWN;
347 wireless_device_free_state(wdev);
348 wdev_handle_config_change(wdev);
352 wireless_device_setup_timeout(struct uloop_timeout *timeout)
354 struct wireless_device *wdev = container_of(timeout, struct wireless_device, timeout);
356 netifd_kill_process(&wdev->script_task);
357 wdev->script_task.cb(&wdev->script_task, -1);
358 wireless_device_mark_down(wdev);
362 wireless_device_set_up(struct wireless_device *wdev)
364 wdev->retry = WIRELESS_SETUP_RETRY;
365 wdev->autostart = true;
366 __wireless_device_set_up(wdev);
370 __wireless_device_set_down(struct wireless_device *wdev)
372 if (wdev->state == IFS_TEARDOWN || wdev->state == IFS_DOWN)
375 if (wdev->script_task.uloop.pending) {
376 wireless_device_setup_cancel(wdev);
380 wdev->state = IFS_TEARDOWN;
381 wireless_device_run_handler(wdev, false);
385 wireless_device_mark_up(struct wireless_device *wdev)
387 struct wireless_interface *vif;
390 wdev->cancel = false;
391 __wireless_device_set_down(wdev);
395 D(WIRELESS, "Wireless device '%s' is now up\n", wdev->name);
396 wdev->state = IFS_UP;
397 vlist_for_each_element(&wdev->interfaces, vif, node)
398 wireless_interface_handle_link(vif, true);
402 wireless_device_retry_setup(struct wireless_device *wdev)
404 if (wdev->state == IFS_TEARDOWN || wdev->state == IFS_DOWN || wdev->cancel)
407 if (--wdev->retry < 0)
408 wdev->retry_setup_failed = true;
410 __wireless_device_set_down(wdev);
414 wireless_device_script_task_cb(struct netifd_process *proc, int ret)
416 struct wireless_device *wdev = container_of(proc, struct wireless_device, script_task);
418 switch (wdev->state) {
420 wireless_device_retry_setup(wdev);
423 wireless_device_mark_down(wdev);
431 wireless_device_set_down(struct wireless_device *wdev)
433 wdev->retry_setup_failed = false;
434 wdev->autostart = false;
435 __wireless_device_set_down(wdev);
439 wdev_set_config_state(struct wireless_device *wdev, enum interface_config_state s)
441 if (wdev->config_state != IFC_NORMAL)
444 wdev->config_state = s;
445 if (wdev->state == IFS_DOWN)
446 wdev_handle_config_change(wdev);
448 __wireless_device_set_down(wdev);
452 wdev_prepare_prev_config(struct wireless_device *wdev)
454 if (wdev->prev_config)
457 prepare_config(wdev, &b, false);
458 wdev->prev_config = blob_memdup(b.head);
462 wdev_change_config(struct wireless_device *wdev, struct wireless_device *wd_new)
464 struct blob_attr *new_config = wd_new->config;
465 bool disabled = wd_new->disabled;
469 wdev_prepare_prev_config(wdev);
470 if (blob_attr_equal(wdev->config, new_config) && wdev->disabled == disabled)
473 D(WIRELESS, "Update configuration of wireless device '%s'\n", wdev->name);
475 wdev->config = blob_memdup(new_config);
476 wdev->disabled = disabled;
477 wdev->retry_setup_failed = false;
478 wdev_set_config_state(wdev, IFC_RELOAD);
482 wdev_create(struct wireless_device *wdev)
484 wdev->retry = WIRELESS_SETUP_RETRY;
485 wdev->config = blob_memdup(wdev->config);
489 wdev_update(struct vlist_tree *tree, struct vlist_node *node_new,
490 struct vlist_node *node_old)
492 struct wireless_device *wd_old = container_of(node_old, struct wireless_device, node);
493 struct wireless_device *wd_new = container_of(node_new, struct wireless_device, node);
495 if (wd_old && wd_new) {
496 wdev_change_config(wd_old, wd_new);
498 D(WIRELESS, "Delete wireless device '%s'\n", wd_old->name);
499 wdev_set_config_state(wd_old, IFC_REMOVE);
501 D(WIRELESS, "Create wireless device '%s'\n", wd_new->name);
507 wireless_add_handler(const char *script, const char *name, json_object *obj)
509 struct wireless_driver *drv;
510 char *name_str, *script_str;
511 json_object *dev_config_obj, *iface_config_obj;
512 struct uci_blob_param_list *dev_config, *iface_config;
514 dev_config_obj = json_get_field(obj, "device", json_type_array);
515 iface_config_obj = json_get_field(obj, "iface", json_type_array);
517 if (!dev_config_obj || !iface_config_obj)
520 drv = calloc_a(sizeof(*drv),
521 &dev_config, sizeof(*dev_config) + sizeof(void *),
522 &iface_config, sizeof(*iface_config) + sizeof(void *),
523 &name_str, strlen(name) + 1,
524 &script_str, strlen(script) + 1);
526 drv->name = strcpy(name_str, name);
527 drv->script = strcpy(script_str, script);
529 dev_config->n_next = 1;
530 dev_config->next[0] = &wdev_param;
531 drv->device.config = dev_config;
533 iface_config->n_next = 1;
534 iface_config->next[0] = &vif_param;
535 drv->interface.config = iface_config;
537 drv->device.buf = netifd_handler_parse_config(drv->device.config, dev_config_obj);
538 drv->interface.buf = netifd_handler_parse_config(drv->interface.config, iface_config_obj);
540 drv->node.key = drv->name;
541 avl_insert(&wireless_drivers, &drv->node);
542 D(WIRELESS, "Add handler for script %s: %s\n", script, name);
545 void wireless_init(void)
547 vlist_init(&wireless_devices, avl_strcmp, wdev_update);
548 wireless_devices.keep_old = true;
549 wireless_devices.no_delete = true;
551 avl_init(&wireless_drivers, avl_strcmp, false, NULL);
552 drv_fd = netifd_open_subdir("wireless");
556 netifd_init_script_handlers(drv_fd, wireless_add_handler);
560 wireless_interface_init_config(struct wireless_interface *vif)
562 struct blob_attr *tb[__VIF_ATTR_MAX];
563 struct blob_attr *cur;
566 blobmsg_parse(vif_policy, __VIF_ATTR_MAX, tb, blob_data(vif->config), blob_len(vif->config));
568 if ((cur = tb[VIF_ATTR_NETWORK]))
571 cur = tb[VIF_ATTR_ISOLATE];
573 vif->isolate = blobmsg_get_bool(cur);
575 cur = tb[VIF_ATTR_MODE];
577 vif->ap_mode = !strcmp(blobmsg_get_string(cur), "ap");
581 vif_update(struct vlist_tree *tree, struct vlist_node *node_new,
582 struct vlist_node *node_old)
584 struct wireless_interface *vif_old = container_of(node_old, struct wireless_interface, node);
585 struct wireless_interface *vif_new = container_of(node_new, struct wireless_interface, node);
586 struct wireless_device *wdev;
589 wdev = vif_old->wdev;
591 wdev = vif_new->wdev;
593 if (vif_old && vif_new) {
594 free((void *) vif_old->section);
595 vif_old->section = strdup(vif_new->section);
596 if (blob_attr_equal(vif_old->config, vif_new->config)) {
601 D(WIRELESS, "Update wireless interface %s on device %s\n", vif_new->name, wdev->name);
602 wireless_interface_handle_link(vif_old, false);
603 free(vif_old->config);
604 vif_old->config = blob_memdup(vif_new->config);
605 vif_old->isolate = vif_new->isolate;
606 vif_old->ap_mode = vif_new->ap_mode;
607 wireless_interface_init_config(vif_old);
609 } else if (vif_new) {
610 D(WIRELESS, "Create new wireless interface %s on device %s\n", vif_new->name, wdev->name);
611 vif_new->section = strdup(vif_new->section);
612 vif_new->config = blob_memdup(vif_new->config);
613 wireless_interface_init_config(vif_new);
614 } else if (vif_old) {
615 D(WIRELESS, "Delete wireless interface %s on device %s\n", vif_old->name, wdev->name);
616 free((void *) vif_old->section);
617 free(vif_old->config);
621 wdev_set_config_state(wdev, IFC_RELOAD);
625 wireless_proc_poll_fd(struct uloop_fd *fd, unsigned int events)
627 struct wireless_device *wdev = container_of(fd, struct wireless_device, script_proc_fd);
631 int b = read(fd->fd, buf, sizeof(buf));
647 uloop_timeout_set(&wdev->script_check, 0);
648 wireless_close_script_proc_fd(wdev);
652 wireless_device_check_script_tasks(struct uloop_timeout *timeout)
654 struct wireless_device *wdev = container_of(timeout, struct wireless_device, script_check);
655 struct wireless_process *proc, *tmp;
656 bool restart = false;
658 list_for_each_entry_safe(proc, tmp, &wdev->script_proc, list) {
659 if (wireless_process_check(proc))
662 D(WIRELESS, "Wireless device '%s' pid %d has terminated\n", wdev->name, proc->pid);
666 wireless_process_free(wdev, proc);
670 wireless_device_retry_setup(wdev);
672 uloop_timeout_set(&wdev->script_check, 1000);
676 wireless_device_create(struct wireless_driver *drv, const char *name, struct blob_attr *data)
678 struct wireless_device *wdev;
680 struct blob_attr *disabled;
682 blobmsg_parse(&wdev_policy, 1, &disabled, blob_data(data), blob_len(data));
684 wdev = calloc_a(sizeof(*wdev), &name_buf, strlen(name) + 1);
685 if (disabled && blobmsg_get_bool(disabled))
686 wdev->disabled = true;
688 wdev->state = IFS_DOWN;
689 wdev->config_state = IFC_NORMAL;
690 wdev->name = strcpy(name_buf, name);
692 wdev->retry_setup_failed = false;
693 wdev->config_autostart = true;
694 wdev->autostart = wdev->config_autostart;
695 INIT_LIST_HEAD(&wdev->script_proc);
696 vlist_init(&wdev->interfaces, avl_strcmp, vif_update);
697 wdev->interfaces.keep_old = true;
699 wdev->timeout.cb = wireless_device_setup_timeout;
700 wdev->script_task.cb = wireless_device_script_task_cb;
701 wdev->script_task.dir_fd = drv_fd;
702 wdev->script_task.log_prefix = wdev->name;
704 wdev->script_proc_fd.fd = -1;
705 wdev->script_proc_fd.cb = wireless_proc_poll_fd;
707 wdev->script_check.cb = wireless_device_check_script_tasks;
709 vlist_add(&wireless_devices, &wdev->node, wdev->name);
712 void wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section)
714 struct wireless_interface *vif;
715 struct blob_attr *tb[__VIF_ATTR_MAX];
716 struct blob_attr *cur;
720 blobmsg_parse(vif_policy, __VIF_ATTR_MAX, tb, blob_data(data), blob_len(data));
722 cur = tb[VIF_ATTR_DISABLED];
723 if (cur && blobmsg_get_bool(cur))
726 sprintf(name, "%d", wdev->vif_idx++);
728 vif = calloc_a(sizeof(*vif),
729 &name_buf, strlen(name) + 1);
730 vif->name = strcpy(name_buf, name);
733 vif->section = section;
734 vif->isolate = false;
736 vlist_add(&wdev->interfaces, &vif->node, vif->name);
740 wireless_interface_status(struct wireless_interface *iface, struct blob_buf *b)
744 i = blobmsg_open_table(b, NULL);
746 blobmsg_add_string(b, "section", iface->section);
748 blobmsg_add_string(b, "ifname", iface->ifname);
749 put_container(b, iface->config, "config");
750 blobmsg_close_table(b, i);
754 wireless_device_status(struct wireless_device *wdev, struct blob_buf *b)
756 struct wireless_interface *iface;
759 c = blobmsg_open_table(b, wdev->name);
760 blobmsg_add_u8(b, "up", wdev->state == IFS_UP);
761 blobmsg_add_u8(b, "pending", wdev->state == IFS_SETUP || wdev->state == IFS_TEARDOWN);
762 blobmsg_add_u8(b, "autostart", wdev->autostart);
763 blobmsg_add_u8(b, "disabled", wdev->disabled);
764 put_container(b, wdev->config, "config");
766 i = blobmsg_open_array(b, "interfaces");
767 vlist_for_each_element(&wdev->interfaces, iface, node)
768 wireless_interface_status(iface, b);
769 blobmsg_close_array(b, i);
770 blobmsg_close_table(b, c);
774 wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b)
776 struct uci_blob_param_list *p;
780 c = blobmsg_open_table(b, wdev->name);
782 d = blobmsg_open_table(b, "device");
783 p = wdev->drv->device.config;
784 for (i = 0; i < p->n_params; i++)
785 blobmsg_add_string(b, p->params[i].name, uci_get_validate_string(p, i));
786 blobmsg_close_table(b, d);
788 d = blobmsg_open_table(b, "interface");
789 p = wdev->drv->interface.config;
790 for (i = 0; i < p->n_params; i++)
791 blobmsg_add_string(b, p->params[i].name, uci_get_validate_string(p, i));
792 blobmsg_close_table(b, d);
794 blobmsg_close_table(b, c);
798 wireless_interface_set_data(struct wireless_interface *vif)
804 static const struct blobmsg_policy data_policy[__VIF_DATA_MAX] = {
805 [VIF_DATA_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING },
807 struct blob_attr *tb[__VIF_DATA_MAX];
808 struct blob_attr *cur;
810 blobmsg_parse(data_policy, __VIF_DATA_MAX, tb,
811 blobmsg_data(vif->data), blobmsg_data_len(vif->data));
813 if ((cur = tb[VIF_DATA_IFNAME]))
814 vif->ifname = blobmsg_data(cur);
818 wireless_device_add_process(struct wireless_device *wdev, struct blob_attr *data)
826 static const struct blobmsg_policy proc_policy[__PROC_ATTR_MAX] = {
827 [PROC_ATTR_PID] = { .name = "pid", .type = BLOBMSG_TYPE_INT32 },
828 [PROC_ATTR_EXE] = { .name = "exe", .type = BLOBMSG_TYPE_STRING },
829 [PROC_ATTR_REQUIRED] = { .name = "required", .type = BLOBMSG_TYPE_BOOL },
831 struct blob_attr *tb[__PROC_ATTR_MAX];
832 struct wireless_process *proc;
837 return UBUS_STATUS_INVALID_ARGUMENT;
839 blobmsg_parse(proc_policy, __PROC_ATTR_MAX, tb, blobmsg_data(data), blobmsg_data_len(data));
840 if (!tb[PROC_ATTR_PID] || !tb[PROC_ATTR_EXE])
841 return UBUS_STATUS_INVALID_ARGUMENT;
843 pid = blobmsg_get_u32(tb[PROC_ATTR_PID]);
845 return UBUS_STATUS_INVALID_ARGUMENT;
847 proc = calloc_a(sizeof(*proc),
848 &name, strlen(blobmsg_data(tb[PROC_ATTR_EXE])) + 1);
851 proc->exe = strcpy(name, blobmsg_data(tb[PROC_ATTR_EXE]));
853 if (tb[PROC_ATTR_REQUIRED])
854 proc->required = blobmsg_get_bool(tb[PROC_ATTR_REQUIRED]);
856 D(WIRELESS, "Wireless device '%s' add pid %d\n", wdev->name, proc->pid);
857 list_add(&proc->list, &wdev->script_proc);
858 uloop_timeout_set(&wdev->script_check, 0);
864 wireless_device_process_kill_all(struct wireless_device *wdev, struct blob_attr *data,
865 struct ubus_request_data *req)
872 static const struct blobmsg_policy kill_policy[__KILL_ATTR_MAX] = {
873 [KILL_ATTR_SIGNAL] = { .name = "signal", .type = BLOBMSG_TYPE_INT32 },
874 [KILL_ATTR_IMMEDIATE] = { .name = "immediate", .type = BLOBMSG_TYPE_BOOL },
876 struct blob_attr *tb[__KILL_ATTR_MAX];
877 struct blob_attr *cur;
878 bool immediate = false;
879 int signal = SIGTERM;
881 blobmsg_parse(kill_policy, __KILL_ATTR_MAX, tb, blobmsg_data(data), blobmsg_data_len(data));
883 if ((cur = tb[KILL_ATTR_SIGNAL]))
884 signal = blobmsg_get_u32(cur);
886 if ((cur = tb[KILL_ATTR_IMMEDIATE]))
887 immediate = blobmsg_get_bool(cur);
889 if (wdev->state != IFS_TEARDOWN || wdev->kill_request)
890 return UBUS_STATUS_PERMISSION_DENIED;
892 wireless_process_kill_all(wdev, signal, immediate);
894 if (list_empty(&wdev->script_proc))
897 wdev->kill_request = calloc(1, sizeof(*wdev->kill_request));
898 ubus_defer_request(ubus_ctx, req, wdev->kill_request);
904 wireless_device_set_retry(struct wireless_device *wdev, struct blob_attr *data)
906 static const struct blobmsg_policy retry_policy = {
907 .name = "retry", .type = BLOBMSG_TYPE_INT32
909 struct blob_attr *val;
911 blobmsg_parse(&retry_policy, 1, &val, blobmsg_data(data), blobmsg_data_len(data));
913 return UBUS_STATUS_INVALID_ARGUMENT;
915 wdev->retry = blobmsg_get_u32(val);
921 NOTIFY_CMD_SET_DATA = 1,
922 NOTIFY_CMD_PROCESS_ADD = 2,
923 NOTIFY_CMD_PROCESS_KILL_ALL = 3,
924 NOTIFY_CMD_SET_RETRY = 4,
928 wireless_device_notify(struct wireless_device *wdev, struct blob_attr *data,
929 struct ubus_request_data *req)
937 static const struct blobmsg_policy notify_policy[__NOTIFY_MAX] = {
938 [NOTIFY_ATTR_COMMAND] = { .name = "command", .type = BLOBMSG_TYPE_INT32 },
939 [NOTIFY_ATTR_VIF] = { .name = "interface", .type = BLOBMSG_TYPE_STRING },
940 [NOTIFY_ATTR_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
942 struct wireless_interface *vif = NULL;
943 struct blob_attr *tb[__NOTIFY_MAX];
944 struct blob_attr *cur, **pdata;
946 blobmsg_parse(notify_policy, __NOTIFY_MAX, tb, blob_data(data), blob_len(data));
948 if (!tb[NOTIFY_ATTR_COMMAND])
949 return UBUS_STATUS_INVALID_ARGUMENT;
951 if ((cur = tb[NOTIFY_ATTR_VIF]) != NULL) {
952 vif = vlist_find(&wdev->interfaces, blobmsg_data(cur), vif, node);
954 return UBUS_STATUS_NOT_FOUND;
957 cur = tb[NOTIFY_ATTR_DATA];
959 return UBUS_STATUS_INVALID_ARGUMENT;
961 switch (blobmsg_get_u32(tb[NOTIFY_ATTR_COMMAND])) {
964 return UBUS_STATUS_INVALID_ARGUMENT;
966 if (wdev->state != IFS_SETUP)
967 return UBUS_STATUS_PERMISSION_DENIED;
969 wireless_device_mark_up(wdev);
971 case NOTIFY_CMD_SET_DATA:
978 return UBUS_STATUS_INVALID_ARGUMENT;
980 *pdata = blob_memdup(cur);
982 wireless_interface_set_data(vif);
984 case NOTIFY_CMD_PROCESS_ADD:
985 return wireless_device_add_process(wdev, cur);
986 case NOTIFY_CMD_PROCESS_KILL_ALL:
987 return wireless_device_process_kill_all(wdev, cur, req);
988 case NOTIFY_CMD_SET_RETRY:
989 return wireless_device_set_retry(wdev, cur);
991 return UBUS_STATUS_INVALID_ARGUMENT;
998 wireless_start_pending(void)
1000 struct wireless_device *wdev;
1002 vlist_for_each_element(&wireless_devices, wdev, node)
1003 __wireless_device_set_up(wdev);