wireless: add ubus method for reloading configuration
authorJohn Crispin <john@phrozen.org>
Fri, 25 Oct 2019 12:02:03 +0000 (14:02 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Fri, 25 Oct 2019 12:07:01 +0000 (14:07 +0200)
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
ubus.c
wireless.c
wireless.h

diff --git a/ubus.c b/ubus.c
index 150d818c978ed070e58efefb73f0655f4eb93295..5a2a339982ea66bf7a8d2d2b667feea8128235e7 100644 (file)
--- 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 },
index 387f4baf709b6242fe8f0100daf49e3c7c75b94f..9986e9a4455f7081a451c0d2ca2d03c30c168513 100644 (file)
@@ -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);
 }
index 3498bd8308d00168719b6f8aa81bd35e366a60d7..bade738d9a8c59bc5991eceafcea638a34fd63c2 100644 (file)
@@ -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);