summaryrefslogtreecommitdiff
path: root/net/udp.c
diff options
context:
space:
mode:
authorPhilippe Reynes <philippe.reynes@softathome.com>2020-09-18 14:13:00 +0200
committerTom Rini <trini@konsulko.com>2020-09-30 16:55:03 -0400
commitb43ea1bf18bf4ba5eeec7131c1a19d864399e422 (patch)
tree5ae63ab33c462f8c016a61f31eea62c8240dd6e5 /net/udp.c
parentcafaa301c98aa8f1b81cf61a91d22d5d68b4b1d3 (diff)
downloadu-boot-b43ea1bf18bf4ba5eeec7131c1a19d864399e422.tar.gz
u-boot-b43ea1bf18bf4ba5eeec7131c1a19d864399e422.tar.bz2
u-boot-b43ea1bf18bf4ba5eeec7131c1a19d864399e422.zip
net: add a generic udp protocol
This commit adds a generic udp protocol framework in the network loop. So protocol based on udp may be implemented without modifying the network loop (for example custom wait magic packet). Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'net/udp.c')
-rw-r--r--net/udp.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/net/udp.c b/net/udp.c
new file mode 100644
index 0000000000..a93822f511
--- /dev/null
+++ b/net/udp.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
+ */
+
+#include <common.h>
+#include <net.h>
+#include <net/udp.h>
+
+static struct udp_ops *udp_ops;
+
+int udp_prereq(void)
+{
+ int ret = 0;
+
+ if (udp_ops->prereq)
+ ret = udp_ops->prereq(udp_ops->data);
+
+ return ret;
+}
+
+int udp_start(void)
+{
+ return udp_ops->start(udp_ops->data);
+}
+
+int udp_loop(struct udp_ops *ops)
+{
+ int ret = -1;
+
+ if (!ops) {
+ printf("%s: ops should not be null\n", __func__);
+ goto out;
+ }
+
+ if (!ops->start) {
+ printf("%s: no start function defined\n", __func__);
+ goto out;
+ }
+
+ udp_ops = ops;
+ ret = net_loop(UDP);
+
+ out:
+ return ret;
+}