aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/wip/private.h96
-rw-r--r--include/wip/types.h44
-rw-r--r--include/wip/wip.h28
3 files changed, 168 insertions, 0 deletions
diff --git a/include/wip/private.h b/include/wip/private.h
new file mode 100644
index 0000000..6de3733
--- /dev/null
+++ b/include/wip/private.h
@@ -0,0 +1,96 @@
+/*
+ * wip, a small TCP/IP stack.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef WIP_PRIVATE_H
+#define WIP_PRIVATE_H
+
+#include <stddef.h>
+
+#if !defined(WIP_H) && !defined(WIP_TYPES_H)
+#error Do not #include <wip/private.h> directly. \
+ Please either #include <wip/wip.h> or <wip/types.h>
+#endif
+
+struct wip;
+
+typedef void *(*wip_prot_alloc)(struct wip *);
+typedef enum wip_state (*wip_prot_rx)(struct wip *, const void *, size_t, void *);
+typedef int (*wip_prot_tx)(struct wip *, void *, size_t, void *);
+typedef void (*wip_prot_free)(struct wip *, void *);
+
+enum wip_protocol
+{
+ WIP_P_ICMP = 1,
+ WIP_P_IGMP,
+ WIP_P_TCP = 6,
+ WIP_P_UDP = 17
+};
+
+struct wip_prot_ops
+{
+ unsigned char id;
+ wip_prot_alloc alloc;
+ wip_prot_free free;
+ wip_prot_rx rx;
+ wip_prot_tx tx;
+};
+
+struct wip_sm_io
+{
+ void *buf;
+ size_t n, read;
+};
+
+struct wip_be16
+{
+ unsigned char v[2];
+};
+
+struct wip_be32
+{
+ unsigned char v[4];
+};
+
+union wip_rx_sm
+{
+ struct wip_rx_sm_h
+ {
+ unsigned short chksum;
+ unsigned char ttl, protocol;
+ size_t header_sz, i;
+ struct wip_sm_io io;
+ struct wip_be16 len, id, fl_off, rchksum;
+ struct wip_be32 src, dst;
+ const struct wip_prot_ops *prot;
+ void *args;
+ } h;
+};
+
+struct wip_rx
+{
+ char buf[192];
+ union wip_rx_sm sm;
+ enum wip_state (*next)(struct wip *);
+};
+
+struct wip_tx
+{
+ char buf[192];
+ enum wip_state (*next)(struct wip *);
+};
+
+struct wip
+{
+ const char *exception;
+ struct wip_rx rx;
+ struct wip_tx tx;
+ struct wip_cfg cfg;
+};
+
+#endif
diff --git a/include/wip/types.h b/include/wip/types.h
new file mode 100644
index 0000000..b97f7b9
--- /dev/null
+++ b/include/wip/types.h
@@ -0,0 +1,44 @@
+/*
+ * wip, a small TCP/IP stack.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef WIP_TYPES_H
+#define WIP_TYPES_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+enum wip_state
+{
+ WIP_OK,
+ WIP_AGAIN,
+ WIP_INVALID,
+ WIP_FATAL
+};
+
+struct wip_cfg
+{
+ void *(*alloc)(size_t n, void *user);
+ void *(*realloc)(void *p, size_t n, void *user);
+ void (*free)(void *p, void *user);
+ int (*read)(void *buf, size_t n, void *user);
+ int (*write)(const void *buf, size_t n, void *user);
+ void *user;
+};
+
+#include <wip/private.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/include/wip/wip.h b/include/wip/wip.h
new file mode 100644
index 0000000..22c9f8c
--- /dev/null
+++ b/include/wip/wip.h
@@ -0,0 +1,28 @@
+/*
+ * wip, a small TCP/IP stack.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef WIP_H
+#define WIP_H
+
+#include <wip/types.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+void wip_init(struct wip *w, const struct wip_cfg *cfg);
+int wip_run(struct wip *w);
+const char *wip_exc(const struct wip *w);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif