Revert "system-linux: re-apply ethtool on phy attachment"
[project/netifd.git] / ubus.c
diff --git a/ubus.c b/ubus.c
index 1d3d71fc0ddc8b3bf96492d481f437ecca5839b6..f8662c2a7b78be1f3a817affdd4a8e17124d5d9c 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -16,7 +16,6 @@
 #include <arpa/inet.h>
 #include <string.h>
 #include <stdio.h>
-#include <udebug.h>
 
 #include "netifd.h"
 #include "interface.h"
@@ -436,12 +435,12 @@ netifd_ubus_reconnect_timer(struct uloop_timeout *timeout)
        int t = 2;
 
        if (ubus_reconnect(ubus_ctx, ubus_path) != 0) {
-               D(SYSTEM, "failed to reconnect, trying again in %d seconds\n", t);
+               D(SYSTEM, "failed to reconnect, trying again in %d seconds", t);
                uloop_timeout_set(&retry, t * 1000);
                return;
        }
 
-       D(SYSTEM, "reconnected to ubus, new id: %08x\n", ubus_ctx->local_id);
+       D(SYSTEM, "reconnected to ubus, new id: %08x", ubus_ctx->local_id);
        netifd_ubus_add_fd();
 }
 
@@ -1367,23 +1366,16 @@ netifd_extdev_invoke(uint32_t id, const char *method, struct blob_attr *msg,
        return ubus_invoke(ubus_ctx, id, method, msg, data_cb, data, 3000);
 }
 
-static void
-netifd_udebug_cb(struct udebug_ubus *ctx, struct blob_attr *data, bool enabled)
-{
-       netifd_udebug_set_enabled(enabled);
-}
-
 int
 netifd_ubus_init(const char *path)
 {
-       uloop_init();
        ubus_path = path;
 
        ubus_ctx = ubus_connect(path);
        if (!ubus_ctx)
                return -EIO;
 
-       D(SYSTEM, "connected as %08x\n", ubus_ctx->local_id);
+       D(SYSTEM, "connected as %08x", ubus_ctx->local_id);
        ubus_ctx->connection_lost = netifd_ubus_connection_lost;
        netifd_ubus_add_fd();
 
@@ -1392,7 +1384,7 @@ netifd_ubus_init(const char *path)
        netifd_add_object(&wireless_object);
        netifd_add_iface_object();
 
-       udebug_ubus_init(&udebug, ubus_ctx, "netifd", netifd_udebug_cb);
+       udebug_ubus_init(&udebug, ubus_ctx, "netifd", netifd_udebug_config);
 
        return 0;
 }
@@ -1438,7 +1430,7 @@ netifd_ubus_add_interface(struct interface *iface)
        obj->methods = iface_object_methods;
        obj->n_methods = ARRAY_SIZE(iface_object_methods);
        if (ubus_add_object(ubus_ctx, &iface->ubus)) {
-               D(SYSTEM, "failed to publish ubus object for interface '%s'\n", iface->name);
+               D(SYSTEM, "failed to publish ubus object for interface '%s'", iface->name);
                free(name);
                obj->name = NULL;
        }
@@ -1453,3 +1445,45 @@ netifd_ubus_remove_interface(struct interface *iface)
        ubus_remove_object(ubus_ctx, &iface->ubus);
        free((void *) iface->ubus.name);
 }
+
+static void
+netifd_ubus_data_cb(struct ubus_request *req, int type, struct blob_attr *msg)
+{
+       struct blob_attr *srv, *in, *t, *data;
+       procd_data_cb cb = req->priv;
+       int rem, rem2, rem3, rem4;
+
+       blobmsg_for_each_attr(srv, msg, rem) {
+               if (!blobmsg_check_attr(srv, true) ||
+                   blobmsg_type(srv) != BLOBMSG_TYPE_TABLE)
+                       continue;
+               blobmsg_for_each_attr(in, srv, rem2) {
+                       if (!blobmsg_check_attr(in , true) ||
+                               blobmsg_type(in) != BLOBMSG_TYPE_TABLE)
+                               continue;
+                       blobmsg_for_each_attr(t, in, rem3) {
+                               if (!blobmsg_check_attr(t, true) ||
+                                       blobmsg_type(t) != BLOBMSG_TYPE_TABLE)
+                                       continue;
+                               blobmsg_for_each_attr(data, t, rem4) {
+                                       if (!blobmsg_check_attr(t, true) ||
+                                               blobmsg_type(t) != BLOBMSG_TYPE_TABLE)
+                                               continue;
+                                       cb(data);
+                               }
+                       }
+               }
+       }
+}
+
+void netifd_ubus_get_procd_data(const char *type, procd_data_cb cb)
+{
+       uint32_t id;
+
+       if (ubus_lookup_id(ubus_ctx, "service", &id))
+               return;
+
+       blob_buf_init(&b, 0);
+       blobmsg_add_string(&b, "type", type);
+       ubus_invoke(ubus_ctx, id, "get_data", b.head, netifd_ubus_data_cb, cb, 30000);
+}