control: Add basic MCTP Control Protocol handler

This will respond to the 4 mandatory MCTP Control Protocol commands.
Applications can register supported types using mctp_control_add_type().

Change-Id: Ia904bcbe118626adf9254ffa71dd8e17fbdfc9b7
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
diff --git a/core.c b/core.c
index e28f6bc..8a0dc13 100644
--- a/core.c
+++ b/core.c
@@ -19,6 +19,7 @@
 #include "range.h"
 #include "compiler.h"
 #include "core-internal.h"
+#include "control.h"
 
 #if MCTP_DEFAULT_CLOCK_GETTIME
 #include <time.h>
@@ -266,6 +267,9 @@
 #if MCTP_DEFAULT_CLOCK_GETTIME
 	mctp->platform_now = mctp_default_now;
 #endif
+#if MCTP_CONTROL_HANDLER
+	mctp_control_add_type(mctp, MCTP_CTRL_HDR_MSG_TYPE);
+#endif
 	return 0;
 }
 
@@ -360,6 +364,16 @@
 	return rc;
 }
 
+int mctp_bus_set_eid(struct mctp_binding *binding, mctp_eid_t eid)
+{
+	if (eid < 8 || eid == 0xff) {
+		return -EINVAL;
+	}
+
+	binding->bus->eid = eid;
+	return 0;
+}
+
 void mctp_unregister_bus(struct mctp *mctp, struct mctp_binding *binding)
 {
 	/*
@@ -444,6 +458,12 @@
 						 buffer, length);
 			return true;
 		}
+	} else {
+#if MCTP_CONTROL_HANDLER
+		/* libmctp will handle control requests */
+		return mctp_control_handler(bus, src, tag_owner, msg_tag,
+					    buffer, length);
+#endif
 	}
 
 	/*