transport: dbus: Implement ack

Change-Id: I15de434610b0f2a3cd54061c353dcc4d9434352b
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/transport_dbus.c b/transport_dbus.c
index 544494d..1f8287a 100644
--- a/transport_dbus.c
+++ b/transport_dbus.c
@@ -179,6 +179,39 @@
 	return sd_bus_send(NULL, n, NULL);
 }
 
+static int transport_dbus_ack(sd_bus_message *m, void *userdata,
+			      sd_bus_error *ret_error)
+{
+	struct mbox_context *context = userdata;
+	struct protocol_ack io;
+	sd_bus_message *n;
+	int rc;
+
+	if (!context) {
+		MSG_ERR("DBUS Internal Error\n");
+		return -EINVAL;
+	}
+
+	rc = sd_bus_message_read_basic(m, 'y', &io.req.flags);
+	if (rc < 0) {
+		MSG_ERR("DBUS error reading message: %s\n", strerror(-rc));
+		return rc;
+	}
+
+	rc = context->protocol->ack(context, &io);
+	if (rc < 0) {
+		return rc;
+	}
+
+	rc = sd_bus_message_new_method_return(m, &n);
+	if (rc < 0) {
+		MSG_ERR("sd_bus_message_new_method_return failed: %d\n", rc);
+		return rc;
+	}
+
+	return sd_bus_send(NULL, n, NULL);
+}
+
 static int transport_dbus_get_property(sd_bus *bus,
 				       const char *path,
 				       const char *interface,
@@ -211,6 +244,8 @@
 		      SD_BUS_VTABLE_UNPRIVILEGED),
 	SD_BUS_METHOD("GetInfo", "y", "yyq", &transport_dbus_get_info,
 		      SD_BUS_VTABLE_UNPRIVILEGED),
+	SD_BUS_METHOD("Ack", "y", NULL, &transport_dbus_ack,
+		      SD_BUS_VTABLE_UNPRIVILEGED),
 	SD_BUS_VTABLE_END
 };
 
@@ -220,6 +255,8 @@
 		      SD_BUS_VTABLE_UNPRIVILEGED),
 	SD_BUS_METHOD("GetInfo", "y", "yyq", &transport_dbus_get_info,
 		      SD_BUS_VTABLE_UNPRIVILEGED),
+	SD_BUS_METHOD("Ack", "y", NULL, &transport_dbus_ack,
+		      SD_BUS_VTABLE_UNPRIVILEGED),
 	SD_BUS_PROPERTY("FlashControlLost", "b", transport_dbus_get_property,
 			0, /* Just a pointer to struct mbox_context */
 			SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),