+static void
+ubus_notify_complete_cb(struct ubus_request *req, int ret)
+{
+ struct ubus_notify_request *nreq;
+
+ nreq = container_of(req, struct ubus_notify_request, req);
+ if (!nreq->complete_cb)
+ return;
+
+ nreq->complete_cb(nreq, 0, 0);
+}
+
+static int
+__ubus_notify_async(struct ubus_context *ctx, struct ubus_object *obj,
+ const char *type, struct blob_attr *msg,
+ struct ubus_notify_request *req, bool reply)
+{
+ memset(req, 0, sizeof(*req));
+
+ blob_buf_init(&b, 0);
+ blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id);
+ blob_put_string(&b, UBUS_ATTR_METHOD, type);
+
+ if (!reply)
+ blob_put_int8(&b, UBUS_ATTR_NO_REPLY, true);
+
+ if (msg)
+ blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
+
+ if (ubus_start_request(ctx, &req->req, b.head, UBUS_MSG_NOTIFY, obj->id) < 0)
+ return UBUS_STATUS_INVALID_ARGUMENT;
+
+ /* wait for status message from ubusd first */
+ req->req.notify = true;
+ req->pending = 1;
+ req->id[0] = obj->id;
+ req->req.complete_cb = ubus_notify_complete_cb;
+
+ return 0;
+}
+
+int ubus_notify_async(struct ubus_context *ctx, struct ubus_object *obj,
+ const char *type, struct blob_attr *msg,
+ struct ubus_notify_request *req)
+{
+ return __ubus_notify_async(ctx, obj, type, msg, req, true);
+}
+
+int ubus_notify(struct ubus_context *ctx, struct ubus_object *obj,
+ const char *type, struct blob_attr *msg, int timeout)
+{
+ struct ubus_notify_request req;
+ int ret;
+
+ ret = __ubus_notify_async(ctx, obj, type, msg, &req, timeout >= 0);
+ if (ret < 0)
+ return ret;
+
+ if (timeout < 0)
+ return 0;
+
+ return ubus_complete_request(ctx, &req.req, timeout);
+}
+