mboxd: Broadcast the daemon is ready on all transports

The code as it stood only sent the state update at startup on the active
transport, which is somewhat arbitrarily chosen as an implementation
detail of the mbox initialisation function.

If the host firmware is using IPMI, it will not learn of the update
unless it attempts to contact mboxd, which it won't do if it knows the
daemon isn't there, which it may have learned of by receiving a state
update from the daemon's shutdown path. In this circumstance the host
firmware is now stuck.

Relieve the host firmware of this problem by always sending the daemon
state on all supported transports. To avoid some insanity we introduce a
new callback in struct transport_ops that allows use to send the BMC's
entire event state rather than just set or clear updates.

Change-Id: I094ff4089eeebd8be99fbd343b94f7bbef023fb1
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/transport_dbus.c b/transport_dbus.c
index c21abda..d1ef4af 100644
--- a/transport_dbus.c
+++ b/transport_dbus.c
@@ -38,16 +38,11 @@
 	return (rc < 0) ? rc : 0;
 }
 
-static int transport_dbus_set_events(struct mbox_context *context,
-				     uint8_t events, uint8_t mask)
+static int transport_dbus_signal_update(struct mbox_context *context,
+					uint8_t events)
 {
 	int rc;
 
-	rc = transport_dbus_property_update(context, events & mask);
-	if (rc < 0) {
-		return rc;
-	}
-
 	/*
 	 * Handle signals - edge triggered, only necessary when they're
 	 * asserted
@@ -91,6 +86,38 @@
 	return 0;
 }
 
+static int transport_dbus_put_events(struct mbox_context *context, uint8_t mask)
+{
+	int rc;
+
+	/* Always update all properties */
+	rc = transport_dbus_property_update(context, mask);
+	if (rc < 0) {
+		return rc;
+	}
+
+	/*
+	 * Still test signals against the values set as sending them indicates
+	 * the event has been asserted, so we must not send them if the bits
+	 * are not set.
+	 */
+	return transport_dbus_signal_update(context,
+					    context->bmc_events & mask);
+}
+
+static int transport_dbus_set_events(struct mbox_context *context,
+				     uint8_t events, uint8_t mask)
+{
+	int rc;
+
+	rc = transport_dbus_property_update(context, events & mask);
+	if (rc < 0) {
+		return rc;
+	}
+
+	return transport_dbus_signal_update(context, events & mask);
+}
+
 static int transport_dbus_clear_events(struct mbox_context *context,
 				       uint8_t events, uint8_t mask)
 {
@@ -99,6 +126,7 @@
 }
 
 static const struct transport_ops transport_dbus_ops = {
+	.put_events = transport_dbus_put_events,
 	.set_events = transport_dbus_set_events,
 	.clear_events = transport_dbus_clear_events,
 };
@@ -509,7 +537,8 @@
 	SD_BUS_VTABLE_END
 };
 
-int transport_dbus_init(struct mbox_context *context)
+int transport_dbus_init(struct mbox_context *context,
+			const struct transport_ops **ops)
 {
 	int rc;
 
@@ -526,8 +555,15 @@
 					MBOX_DBUS_OBJECT,
 					MBOX_DBUS_PROTOCOL_IFACE_V2,
 					protocol_v2_vtable, context);
+	if (rc < 0) {
+		return rc;
+	}
 
-	return rc;
+	if (ops) {
+		*ops = &transport_dbus_ops;
+	}
+
+	return 0;
 }
 
 #define __unused __attribute__((unused))