build: Generate libmctp-sizes.h

This can be used to allocate static storage for a struct mctp used with
heapless mctp_setup().

core.c internal data structures are moved to core-internal.h so that
sizeof(struct mctp) can be compiled without linking other objects.

Change-Id: I72dcd46ef11d6f4b4f5ba1c9ae6c95e40dda40f8
Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
diff --git a/core-internal.h b/core-internal.h
new file mode 100644
index 0000000..7608a41
--- /dev/null
+++ b/core-internal.h
@@ -0,0 +1,105 @@
+/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
+#pragma once
+
+#include "libmctp.h"
+
+/* 64kb should be sufficient for a single message. Applications
+ * requiring higher sizes can override by setting max_message_size.*/
+#ifndef MCTP_MAX_MESSAGE_SIZE
+#define MCTP_MAX_MESSAGE_SIZE 65536
+#endif
+
+/* Must be >= 2 for bridge busses */
+#ifndef MCTP_MAX_BUSSES
+#define MCTP_MAX_BUSSES 2
+#endif
+
+/* Concurrent reassembly contexts. */
+#ifndef MCTP_REASSEMBLY_CTXS
+#define MCTP_REASSEMBLY_CTXS 16
+#endif
+
+/* Outbound request tags */
+#ifndef MCTP_REQ_TAGS
+#define MCTP_REQ_TAGS MCTP_REASSEMBLY_CTXS
+#endif
+
+/* Internal data structures */
+
+enum mctp_bus_state {
+	mctp_bus_state_constructed = 0,
+	mctp_bus_state_tx_enabled,
+	mctp_bus_state_tx_disabled,
+};
+
+struct mctp_bus {
+	mctp_eid_t eid;
+	struct mctp_binding *binding;
+	enum mctp_bus_state state;
+	struct mctp *mctp;
+
+	/* Current message to transmit */
+	void *tx_msg;
+	/* Position in tx_msg */
+	size_t tx_msgpos;
+	/* Length of tx_msg */
+	size_t tx_msglen;
+	/* Length of current packet payload */
+	size_t tx_pktlen;
+	uint8_t tx_seq;
+	uint8_t tx_src;
+	uint8_t tx_dest;
+	bool tx_to;
+	uint8_t tx_tag;
+
+	/* todo: routing */
+};
+
+struct mctp_msg_ctx {
+	/* NULL buf indicates an unused mctp_msg_ctx */
+	void *buf;
+
+	uint8_t src;
+	uint8_t dest;
+	uint8_t tag;
+	uint8_t last_seq;
+	size_t buf_size;
+	size_t buf_alloc_size;
+	size_t fragment_size;
+};
+
+struct mctp_req_tag {
+	/* 0 is an unused entry */
+	mctp_eid_t local;
+	mctp_eid_t remote;
+	uint8_t tag;
+};
+
+struct mctp {
+	int n_busses;
+	struct mctp_bus busses[MCTP_MAX_BUSSES];
+
+	/* Message RX callback */
+	mctp_rx_fn message_rx;
+	void *message_rx_data;
+
+	/* Packet capture callback */
+	mctp_capture_fn capture;
+	void *capture_data;
+
+	/* Message reassembly. */
+	struct mctp_msg_ctx msg_ctxs[MCTP_REASSEMBLY_CTXS];
+
+	/* Allocated outbound TO tags */
+	struct mctp_req_tag req_tags[MCTP_REQ_TAGS];
+	/* used to avoid always allocating tag 0 */
+	uint8_t tag_round_robin;
+
+	enum {
+		ROUTE_ENDPOINT,
+		ROUTE_BRIDGE,
+	} route_policy;
+	size_t max_message_size;
+
+	void *alloc_ctx;
+};