+enum {
+ DEV_NAME,
+ __DEV_MAX,
+};
+
+static const struct blobmsg_policy dev_policy[__DEV_MAX] = {
+ [DEV_NAME] = { .name = "name", .type = BLOBMSG_TYPE_STRING },
+};
+
+static int
+netifd_dev_status(struct ubus_context *ctx, struct ubus_object *obj,
+ struct ubus_request_data *req, const char *method,
+ struct blob_attr *msg)
+{
+ struct device *dev = NULL;
+ struct blob_attr *tb[__DEV_MAX];
+
+ blobmsg_parse(dev_policy, __DEV_MAX, tb, blob_data(msg), blob_len(msg));
+
+ if (tb[DEV_NAME]) {
+ dev = device_get(blobmsg_data(tb[DEV_NAME]), false);
+ if (!dev)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+ }
+
+ blob_buf_init(&b, 0);
+ device_dump_status(&b, dev);
+ ubus_send_reply(ctx, req, b.head);
+
+ return 0;
+}
+
+static struct ubus_method dev_object_methods[] = {
+ UBUS_METHOD("status", netifd_dev_status, dev_policy)
+};
+
+static struct ubus_object_type dev_object_type =
+ UBUS_OBJECT_TYPE("device", dev_object_methods);
+
+static struct ubus_object dev_object = {
+ .name = "network.device",
+ .type = &dev_object_type,
+ .methods = dev_object_methods,
+ .n_methods = ARRAY_SIZE(dev_object_methods),
+};
+