From 7a723d0c797d28823f3d0eae9c72aca3ae69d976 Mon Sep 17 00:00:00 2001 From: John Crispin Date: Fri, 25 Oct 2019 14:02:03 +0200 Subject: [PATCH] wireless: add ubus method for reloading configuration Signed-off-by: Daniel Golle --- ubus.c | 23 +++++++++++++++++++++++ wireless.c | 18 +++++++++++++----- wireless.h | 1 + 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/ubus.c b/ubus.c index 150d818..5a2a339 100644 --- a/ubus.c +++ b/ubus.c @@ -1081,6 +1081,28 @@ get_wdev(struct blob_attr *msg, int *ret) return wdev; } +static int +netifd_handle_wdev_reconf(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + struct wireless_device *wdev; + int ret; + + wdev = get_wdev(msg, &ret); + if (ret == UBUS_STATUS_NOT_FOUND) + return ret; + + if (wdev) { + wireless_device_reconf(wdev); + } else { + vlist_for_each_element(&wireless_devices, wdev, node) + wireless_device_reconf(wdev); + } + + return 0; +} + static int netifd_handle_wdev_up(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -1189,6 +1211,7 @@ netifd_handle_wdev_notify(struct ubus_context *ctx, struct ubus_object *obj, static struct ubus_method wireless_object_methods[] = { { .name = "up", .handler = netifd_handle_wdev_up }, { .name = "down", .handler = netifd_handle_wdev_down }, + { .name = "reconf", .handler = netifd_handle_wdev_reconf }, { .name = "status", .handler = netifd_handle_wdev_status }, { .name = "notify", .handler = netifd_handle_wdev_notify }, { .name = "get_validate", .handler = netifd_handle_wdev_get_validate }, diff --git a/wireless.c b/wireless.c index 387f4ba..9986e9a 100644 --- a/wireless.c +++ b/wireless.c @@ -282,7 +282,7 @@ wireless_device_run_handler(struct wireless_device *wdev, bool up) } static void -__wireless_device_set_up(struct wireless_device *wdev) +__wireless_device_set_up(struct wireless_device *wdev, int force) { if (wdev->disabled) return; @@ -293,7 +293,7 @@ __wireless_device_set_up(struct wireless_device *wdev) if (!wdev->autostart) return; - if (wdev->state != IFS_DOWN || config_init) + if (!force && (wdev->state != IFS_DOWN || config_init)) return; free(wdev->prev_config); @@ -320,7 +320,7 @@ wdev_handle_config_change(struct wireless_device *wdev) switch(state) { case IFC_NORMAL: case IFC_RELOAD: - __wireless_device_set_up(wdev); + __wireless_device_set_up(wdev, 0); wdev->config_state = IFC_NORMAL; break; @@ -363,7 +363,15 @@ wireless_device_set_up(struct wireless_device *wdev) { wdev->retry = WIRELESS_SETUP_RETRY; wdev->autostart = true; - __wireless_device_set_up(wdev); + __wireless_device_set_up(wdev, 0); +} + +void +wireless_device_reconf(struct wireless_device *wdev) +{ + wdev->retry = WIRELESS_SETUP_RETRY; + wdev->autostart = true; + __wireless_device_set_up(wdev, 1); } static void @@ -1001,5 +1009,5 @@ wireless_start_pending(void) struct wireless_device *wdev; vlist_for_each_element(&wireless_devices, wdev, node) - __wireless_device_set_up(wdev); + __wireless_device_set_up(wdev, 0); } diff --git a/wireless.h b/wireless.h index 3498bd8..bade738 100644 --- a/wireless.h +++ b/wireless.h @@ -93,6 +93,7 @@ struct wireless_process { void wireless_device_create(struct wireless_driver *drv, const char *name, struct blob_attr *data); void wireless_device_set_up(struct wireless_device *wdev); void wireless_device_set_down(struct wireless_device *wdev); +void wireless_device_reconf(struct wireless_device *wdev); void wireless_device_status(struct wireless_device *wdev, struct blob_buf *b); void wireless_device_get_validate(struct wireless_device *wdev, struct blob_buf *b); void wireless_interface_create(struct wireless_device *wdev, struct blob_attr *data, const char *section); -- 2.25.1