mboxd: Add backend DBus interface and commandline options

Also implement a backend commandline option to mboxctl: `mboxctl
--backend ...`, to allow easy run-time switching of the backend from the
commandline.

Switching between VPNOR and file backends via mboxctl was tested on
Witherspoon, and MTD and file backends on Romulus.

Change-Id: Iaf0e27ecf1d5cdd9e3a31729fb179096bbc37408
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/control.c b/control.c
index acca924..4b73efa 100644
--- a/control.c
+++ b/control.c
@@ -3,12 +3,12 @@
 #include <errno.h>
 #include <stdlib.h>
 
+#include "backend.h"
 #include "common.h"
 #include "dbus.h"
-#include "mboxd.h"
-#include "backend.h"
 #include "lpc.h"
-#include "transport_mbox.h"
+#include "mboxd.h"
+#include "protocol.h"
 #include "windows.h"
 
 int control_ping(struct mbox_context *context)
@@ -116,3 +116,29 @@
 
 	return rc;
 }
+
+int control_set_backend(struct mbox_context *context, struct backend *backend,
+			void *data)
+{
+	int rc;
+
+	if (context->state & STATE_SUSPENDED)
+		return -EINVAL;
+
+	rc = protocol_events_clear(context, BMC_EVENT_DAEMON_READY);
+	if (rc < 0)
+		return rc;
+
+	backend_free(&context->backend);
+
+	rc = backend_init(&context->backend, backend, data);
+	if (rc < 0)
+		return rc;
+
+	rc = __protocol_reset(context);
+	if (rc < 0)
+		return rc;
+
+	return protocol_events_set(context,
+			BMC_EVENT_DAEMON_READY | BMC_EVENT_PROTOCOL_RESET);
+}