+int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req,
+ struct blob_attr *msg, int cmd, uint32_t peer)
+{
+ memset(req, 0, sizeof(*req));
+
+ if (msg && blob_pad_len(msg) > UBUS_MAX_MSGLEN)
+ return -1;
+
+ INIT_LIST_HEAD(&req->list);
+ INIT_LIST_HEAD(&req->pending);
+ req->ctx = ctx;
+ req->peer = peer;
+ req->seq = ++ctx->request_seq;
+ return ubus_send_msg(ctx, req->seq, msg, cmd, peer);
+}
+
+int ubus_lookup(struct ubus_context *ctx, const char *path,
+ ubus_lookup_handler_t cb, void *priv)
+{
+ struct ubus_lookup_request lookup;
+
+ blob_buf_init(&b, 0);
+ if (path)
+ blob_put_string(&b, UBUS_ATTR_OBJPATH, path);
+
+ if (ubus_start_request(ctx, &lookup.req, b.head, UBUS_MSG_LOOKUP, 0) < 0)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ lookup.req.raw_data_cb = ubus_lookup_cb;
+ lookup.req.priv = priv;
+ lookup.cb = cb;
+ return ubus_complete_request(ctx, &lookup.req, 0);
+}
+
+static void ubus_lookup_id_cb(struct ubus_request *req, int type, struct blob_attr *msg)
+{
+ struct blob_attr **attr;
+ uint32_t *id = req->priv;
+
+ attr = ubus_parse_msg(msg);
+
+ if (!attr[UBUS_ATTR_OBJID])
+ return;
+
+ *id = blob_get_u32(attr[UBUS_ATTR_OBJID]);
+}
+
+int ubus_lookup_id(struct ubus_context *ctx, const char *path, uint32_t *id)
+{
+ struct ubus_request req;
+
+ blob_buf_init(&b, 0);
+ if (path)
+ blob_put_string(&b, UBUS_ATTR_OBJPATH, path);
+
+ if (ubus_start_request(ctx, &req, b.head, UBUS_MSG_LOOKUP, 0) < 0)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ req.raw_data_cb = ubus_lookup_id_cb;
+ req.priv = id;
+
+ return ubus_complete_request(ctx, &req, 0);
+}
+
+int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req,
+ struct blob_attr *msg)
+{
+ int ret;
+
+ blob_buf_init(&b, 0);
+ blob_put_int32(&b, UBUS_ATTR_OBJID, req->object);
+ blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
+ ret = ubus_send_msg(ctx, req->seq, b.head, UBUS_MSG_DATA, req->peer);
+ if (ret < 0)
+ return UBUS_STATUS_NO_DATA;
+
+ return 0;
+}
+
+int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method,