aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/Kconfig6
-rw-r--r--net/Makefile1
-rw-r--r--net/eth-uclass.c6
-rw-r--r--net/eth_legacy.c4
-rw-r--r--net/mdio-uclass.c4
-rw-r--r--net/net.c44
-rw-r--r--net/sntp.c29
-rw-r--r--net/sntp.h57
-rw-r--r--net/tftp.c9
-rw-r--r--net/udp.c46
10 files changed, 106 insertions, 100 deletions
diff --git a/net/Kconfig b/net/Kconfig
index 6874b55aacb..1b3e420d0d1 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -8,6 +8,12 @@ menuconfig NET
if NET
+config PROT_UDP
+ bool "Enable generic udp framework"
+ help
+ Enable a generic udp framework that allows defining a custom
+ handler for udp protocol.
+
config BOOTP_SEND_HOSTNAME
bool "Send hostname to DNS server"
help
diff --git a/net/Makefile b/net/Makefile
index fef71b940a0..76527f704c4 100644
--- a/net/Makefile
+++ b/net/Makefile
@@ -27,6 +27,7 @@ obj-$(CONFIG_CMD_SNTP) += sntp.o
obj-$(CONFIG_CMD_TFTPBOOT) += tftp.o
obj-$(CONFIG_UDP_FUNCTION_FASTBOOT) += fastboot.o
obj-$(CONFIG_CMD_WOL) += wol.o
+obj-$(CONFIG_PROT_UDP) += udp.o
# Disable this warning as it is triggered by:
# sprintf(buf, index ? "foo%d" : "foo", index)
diff --git a/net/eth-uclass.c b/net/eth-uclass.c
index 0d9b75a9a20..396418eb390 100644
--- a/net/eth-uclass.c
+++ b/net/eth-uclass.c
@@ -273,7 +273,7 @@ int eth_init(void)
if (!current) {
current = eth_get_dev();
if (!current) {
- printf("No ethernet found.\n");
+ log_err("No ethernet found.\n");
return -ENODEV;
}
}
@@ -414,7 +414,7 @@ int eth_initialize(void)
*/
uclass_first_device_check(UCLASS_ETH, &dev);
if (!dev) {
- printf("No ethernet found.\n");
+ log_err("No ethernet found.\n");
bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
} else {
char *ethprime = env_get("ethprime");
@@ -449,7 +449,7 @@ int eth_initialize(void)
} while (dev);
if (!num_devices)
- printf("No ethernet found.\n");
+ log_err("No ethernet found.\n");
putc('\n');
}
diff --git a/net/eth_legacy.c b/net/eth_legacy.c
index 992d1880bf3..6e0c0587616 100644
--- a/net/eth_legacy.c
+++ b/net/eth_legacy.c
@@ -261,7 +261,7 @@ int eth_initialize(void)
}
if (!eth_devices) {
- puts("No ethernet found.\n");
+ log_err("No ethernet found.\n");
bootstage_error(BOOTSTAGE_ID_NET_ETH_START);
} else {
struct eth_device *dev = eth_devices;
@@ -319,7 +319,7 @@ int eth_init(void)
struct eth_device *old_current;
if (!eth_current) {
- puts("No ethernet found.\n");
+ log_err("No ethernet found.\n");
return -ENODEV;
}
diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c
index 66ee2e19763..b5e8e465123 100644
--- a/net/mdio-uclass.c
+++ b/net/mdio-uclass.c
@@ -145,7 +145,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
break;
if (!ofnode_valid(phandle.node)) {
- dev_dbg(dev, "can't find PHY node\n");
+ dev_dbg(ethdev, "can't find PHY node\n");
return NULL;
}
@@ -161,7 +161,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev,
if (uclass_get_device_by_ofnode(UCLASS_MDIO,
ofnode_get_parent(phandle.node),
&mdiodev)) {
- dev_dbg(dev, "can't find MDIO bus for node %s\n",
+ dev_dbg(ethdev, "can't find MDIO bus for node %s\n",
ofnode_get_name(ofnode_get_parent(phandle.node)));
return NULL;
}
diff --git a/net/net.c b/net/net.c
index 28d9eebf9dd..197fde3568d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -72,12 +72,6 @@
* We want: - load the boot file
* Next step: none
*
- * SNTP:
- *
- * Prerequisites: - own ethernet address
- * - own IP address
- * We want: - network time
- * Next step: none
*
* WOL:
*
@@ -102,6 +96,7 @@
#if defined(CONFIG_CMD_PCAP)
#include <net/pcap.h>
#endif
+#include <net/udp.h>
#if defined(CONFIG_LED_STATUS)
#include <miiphy.h>
#include <status_led.h>
@@ -118,9 +113,6 @@
#include "nfs.h"
#include "ping.h"
#include "rarp.h"
-#if defined(CONFIG_CMD_SNTP)
-#include "sntp.h"
-#endif
#if defined(CONFIG_CMD_WOL)
#include "wol.h"
#endif
@@ -184,13 +176,6 @@ u32 net_boot_file_size;
/* Boot file size in blocks as reported by the DHCP server */
u32 net_boot_file_expected_size_in_blocks;
-#if defined(CONFIG_CMD_SNTP)
-/* NTP server IP address */
-struct in_addr net_ntp_server;
-/* offset time from UTC */
-int net_ntp_time_offset;
-#endif
-
static uchar net_pkt_buf[(PKTBUFSRX+1) * PKTSIZE_ALIGN + PKTALIGN];
/* Receive packets */
uchar *net_rx_packets[PKTBUFSRX];
@@ -520,11 +505,6 @@ restart:
nc_start();
break;
#endif
-#if defined(CONFIG_CMD_SNTP)
- case SNTP:
- sntp_start();
- break;
-#endif
#if defined(CONFIG_CMD_DNS)
case DNS:
dns_start();
@@ -544,6 +524,9 @@ restart:
break;
}
+ if (IS_ENABLED(CONFIG_PROT_UDP) && protocol == UDP)
+ udp_start();
+
break;
}
@@ -1348,14 +1331,6 @@ static int net_check_prereq(enum proto_t protocol)
}
goto common;
#endif
-#if defined(CONFIG_CMD_SNTP)
- case SNTP:
- if (net_ntp_server.s_addr == 0) {
- puts("*** ERROR: NTP server address not given\n");
- return 1;
- }
- goto common;
-#endif
#if defined(CONFIG_CMD_DNS)
case DNS:
if (net_dns_server.s_addr == 0) {
@@ -1364,6 +1339,13 @@ static int net_check_prereq(enum proto_t protocol)
}
goto common;
#endif
+#if defined(CONFIG_PROT_UDP)
+ case UDP:
+ if (udp_prereq())
+ return 1;
+ goto common;
+#endif
+
#if defined(CONFIG_CMD_NFS)
case NFS:
#endif
@@ -1374,8 +1356,8 @@ static int net_check_prereq(enum proto_t protocol)
puts("*** ERROR: `serverip' not set\n");
return 1;
}
-#if defined(CONFIG_CMD_PING) || defined(CONFIG_CMD_SNTP) || \
- defined(CONFIG_CMD_DNS)
+#if defined(CONFIG_CMD_PING) || \
+ defined(CONFIG_CMD_DNS) || defined(CONFIG_PROT_UDP)
common:
#endif
/* Fall through */
diff --git a/net/sntp.c b/net/sntp.c
index 39d7664a224..d5d56719331 100644
--- a/net/sntp.c
+++ b/net/sntp.c
@@ -12,12 +12,17 @@
#include <net.h>
#include <rtc.h>
-#include "sntp.h"
+#include <net/sntp.h>
#define SNTP_TIMEOUT 10000UL
static int sntp_our_port;
+/* NTP server IP address */
+struct in_addr net_ntp_server;
+/* offset time from UTC */
+int net_ntp_time_offset;
+
static void sntp_send(void)
{
struct sntp_pkt_t pkt;
@@ -93,7 +98,25 @@ static void sntp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
net_set_state(NETLOOP_SUCCESS);
}
-void sntp_start(void)
+/*
+ * SNTP:
+ *
+ * Prerequisites: - own ethernet address
+ * - own IP address
+ * We want: - network time
+ * Next step: none
+ */
+int sntp_prereq(void *data)
+{
+ if (net_ntp_server.s_addr == 0) {
+ puts("*** ERROR: NTP server address not given\n");
+ return 1;
+ }
+
+ return 0;
+}
+
+int sntp_start(void *data)
{
debug("%s\n", __func__);
@@ -102,4 +125,6 @@ void sntp_start(void)
memset(net_server_ethaddr, 0, sizeof(net_server_ethaddr));
sntp_send();
+
+ return 0;
}
diff --git a/net/sntp.h b/net/sntp.h
deleted file mode 100644
index d3cbfbc69a6..00000000000
--- a/net/sntp.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0+ */
-/*
- * (C) Masami Komiya <mkomiya@sonare.it> 2005
- */
-
-#ifndef __SNTP_H__
-#define __SNTP_H__
-
-#define NTP_SERVICE_PORT 123
-#define SNTP_PACKET_LEN 48
-
-
-/* Leap Indicator */
-#define NTP_LI_NOLEAP 0x0
-#define NTP_LI_61SECS 0x1
-#define NTP_LI_59SECS 0x2
-#define NTP_LI_ALARM 0x3
-
-/* Version */
-
-#define NTP_VERSION 4
-
-/* Mode */
-#define NTP_MODE_RESERVED 0
-#define NTP_MODE_SYMACTIVE 1 /* Symmetric Active */
-#define NTP_MODE_SYMPASSIVE 2 /* Symmetric Passive */
-#define NTP_MODE_CLIENT 3
-#define NTP_MODE_SERVER 4
-#define NTP_MODE_BROADCAST 5
-#define NTP_MODE_NTPCTRL 6 /* Reserved for NTP control message */
-#define NTP_MODE_PRIVATE 7 /* Reserved for private use */
-
-struct sntp_pkt_t {
-#if __LITTLE_ENDIAN
- uchar mode:3;
- uchar vn:3;
- uchar li:2;
-#else
- uchar li:2;
- uchar vn:3;
- uchar mode:3;
-#endif
- uchar stratum;
- uchar poll;
- uchar precision;
- uint root_delay;
- uint root_dispersion;
- uint reference_id;
- unsigned long long reference_timestamp;
- unsigned long long originate_timestamp;
- unsigned long long receive_timestamp;
- unsigned long long transmit_timestamp;
-} __attribute__((packed));
-
-void sntp_start(void); /* Begin SNTP */
-
-#endif /* __SNTP_H__ */
diff --git a/net/tftp.c b/net/tftp.c
index 84e970bec13..6fdb1a821a8 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -159,7 +159,8 @@ static unsigned short tftp_window_size_option = TFTP_WINDOWSIZE;
static inline int store_block(int block, uchar *src, unsigned int len)
{
- ulong offset = block * tftp_block_size + tftp_block_wrap_offset;
+ ulong offset = block * tftp_block_size + tftp_block_wrap_offset -
+ tftp_block_size;
ulong newsize = offset + len;
ulong store_addr = tftp_load_addr + offset;
#ifdef CONFIG_SYS_DIRECT_FLASH_TFTP
@@ -233,7 +234,8 @@ static void new_transfer(void)
static int load_block(unsigned block, uchar *dst, unsigned len)
{
/* We may want to get the final block from the previous set */
- ulong offset = ((int)block - 1) * len + tftp_block_wrap_offset;
+ ulong offset = block * tftp_block_size + tftp_block_wrap_offset -
+ tftp_block_size;
ulong tosend = len;
tosend = min(net_boot_file_size - offset, tosend);
@@ -502,6 +504,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
int block = ntohs(*s);
int ack_ok = (tftp_cur_block == block);
+ tftp_prev_block = tftp_cur_block;
tftp_cur_block = (unsigned short)(block + 1);
update_block_number();
if (ack_ok)
@@ -651,7 +654,7 @@ static void tftp_handler(uchar *pkt, unsigned dest, struct in_addr sip,
timeout_count_max = tftp_timeout_count_max;
net_set_timeout_handler(timeout_ms, tftp_timeout_handler);
- if (store_block(tftp_cur_block - 1, pkt + 2, len)) {
+ if (store_block(tftp_cur_block, pkt + 2, len)) {
eth_halt();
net_set_state(NETLOOP_FAIL);
break;
diff --git a/net/udp.c b/net/udp.c
new file mode 100644
index 00000000000..a93822f511c
--- /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;
+}