transport: Fix event handling

Events were not quite being handled as per the intent of the recent
refactor: The protocol layer was meant to record the raw set of events
and provide the protocol-version-specific mask to the transport layer,
which the transport layer would then use to flush out the state in
accordance with its implementation-specific requirements.

What was going wrong was that the transport implementations were
overwriting the raw set of events with the protocol-specific masked set
of events, meaning that we'd lose the raw state and provide an
incomplete BMC state value on protocol upgrade.

Rework the event handling to make sure the responsibilities are properly
split between the layers.

Change-Id: Iace6615a121e4ce7dcca690d9adf62e5ab9ccee2
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/transport_dbus.c b/transport_dbus.c
index 3ad0dad..c21abda 100644
--- a/transport_dbus.c
+++ b/transport_dbus.c
@@ -19,6 +19,7 @@
 	/* Two properties plus a terminating NULL */
 	char *props[3] = { 0 };
 	int i = 0;
+	int rc;
 
 	if (events & BMC_EVENT_FLASH_CTRL_LOST) {
 		props[i++] = "FlashControlLost";
@@ -28,19 +29,21 @@
 		props[i++] = "DaemonReady";
 	}
 
-	return sd_bus_emit_properties_changed_strv(context->bus,
+	rc = sd_bus_emit_properties_changed_strv(context->bus,
 						 MBOX_DBUS_OBJECT,
 						 /* FIXME: Hard-coding v2 */
 						 MBOX_DBUS_PROTOCOL_IFACE_V2,
 						 props);
+
+	return (rc < 0) ? rc : 0;
 }
 
 static int transport_dbus_set_events(struct mbox_context *context,
-				     uint8_t events)
+				     uint8_t events, uint8_t mask)
 {
 	int rc;
 
-	rc = transport_dbus_property_update(context, events);
+	rc = transport_dbus_property_update(context, events & mask);
 	if (rc < 0) {
 		return rc;
 	}
@@ -89,10 +92,10 @@
 }
 
 static int transport_dbus_clear_events(struct mbox_context *context,
-				       uint8_t events)
+				       uint8_t events, uint8_t mask)
 {
 	/* No need to emit signals for ackable events on clear */
-	return transport_dbus_property_update(context, events);
+	return transport_dbus_property_update(context, events & mask);
 }
 
 static const struct transport_ops transport_dbus_ops = {