Add reference to bus from binding
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
diff --git a/core.c b/core.c
index c6896d1..c11564a 100644
--- a/core.c
+++ b/core.c
@@ -229,20 +229,22 @@
return &mctp->busses[0];
}
-unsigned long mctp_register_bus(struct mctp *mctp,
+int mctp_register_bus(struct mctp *mctp,
struct mctp_binding *binding,
mctp_eid_t eid)
{
+ /* todo: multiple busses */
assert(!mctp->busses[0].binding);
mctp->busses[0].binding = binding;
mctp->busses[0].eid = eid;
+ binding->bus = &mctp->busses[0];
return 0;
}
-void mctp_bus_rx(struct mctp *mctp, unsigned long bus_id,
+void mctp_bus_rx(struct mctp *mctp, struct mctp_binding *binding,
struct mctp_pktbuf *pkt)
{
- struct mctp_bus *bus = &mctp->busses[bus_id];
+ struct mctp_bus *bus = binding->bus;
struct mctp_msg_ctx *ctx;
struct mctp_hdr *hdr;
uint8_t flags, seq, tag;
@@ -250,6 +252,8 @@
void *p;
int rc;
+ assert(bus);
+
hdr = mctp_pktbuf_hdr(pkt);
if (hdr->dest != bus->eid)
diff --git a/libmctp.h b/libmctp.h
index 28903d7..c477a2a 100644
--- a/libmctp.h
+++ b/libmctp.h
@@ -57,11 +57,15 @@
/* MCTP core */
struct mctp;
+struct mctp_bus;
struct mctp_binding;
struct mctp *mctp_init(void);
-unsigned long mctp_register_bus(struct mctp *mctp,
+/* Register a binding to the MCTP core, and creates a bus (populating
+ * binding->bus).
+ */
+int mctp_register_bus(struct mctp *mctp,
struct mctp_binding *binding,
mctp_eid_t eid);
@@ -77,11 +81,12 @@
struct mctp_binding {
const char *name;
uint8_t version;
+ struct mctp_bus *bus;
int (*tx)(struct mctp_binding *binding,
struct mctp_pktbuf *pkt);
};
-void mctp_bus_rx(struct mctp *mctp, unsigned long bus_id,
+void mctp_bus_rx(struct mctp *mctp, struct mctp_binding *binding,
struct mctp_pktbuf *pkt);
/* environment-specific allocation */
diff --git a/serial.c b/serial.c
index 87524f6..482cedb 100644
--- a/serial.c
+++ b/serial.c
@@ -138,7 +138,7 @@
assert(pkt);
if (valid)
- mctp_bus_rx(serial->mctp, serial->bus_id, pkt);
+ mctp_bus_rx(serial->mctp, &serial->binding, pkt);
mctp_pktbuf_free(pkt);
serial->rx_pkt = NULL;
@@ -295,7 +295,7 @@
{
assert(serial->fd >= 0);
serial->mctp = mctp;
- serial->bus_id = mctp_register_bus(mctp, &serial->binding, eid);
+ mctp_register_bus(mctp, &serial->binding, eid);
}
struct mctp_binding_serial *mctp_serial_init(void)