#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
-#include <udebug.h>
#include "netifd.h"
#include "interface.h"
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();
}
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();
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;
}
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;
}
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);
+}