summaryrefslogtreecommitdiff
path: root/net/net.c
diff options
context:
space:
mode:
authorYing-Chun Liu (PaulLiu) <paul.liu@linaro.org>2022-11-08 09:17:28 +0300
committerTom Rini <trini@konsulko.com>2022-11-28 21:06:39 +0300
commita3bf193bf4ea8703bcf96b1a34713fb2ae87aa39 (patch)
tree973568df1e1123da531a61776a1040dc982abc02 /net/net.c
parent3cdbbe52f70ff4fdd7aa9b66de2040b9f304c0b2 (diff)
downloadu-boot-a3bf193bf4ea8703bcf96b1a34713fb2ae87aa39.tar.xz
net: Add TCP protocol
Currently file transfers are done using tftp or NFS both over udp. This requires a request to be sent from client (u-boot) to the boot server. The current standard is TCP with selective acknowledgment. Signed-off-by: Duncan Hare <DH@Synoia.com> Signed-off-by: Duncan Hare <DuncanCHare@yahoo.com> Signed-off-by: Ying-Chun Liu (PaulLiu) <paul.liu@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org> Cc: Christian Gmeiner <christian.gmeiner@gmail.com> Cc: Joe Hershberger <joe.hershberger@ni.com> Cc: Michal Simek <michal.simek@xilinx.com> Cc: Ramon Fried <rfried.dev@gmail.com> Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Diffstat (limited to 'net/net.c')
-rw-r--r--net/net.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/net/net.c b/net/net.c
index 6f0a48361c..9cb2aab09d 100644
--- a/net/net.c
+++ b/net/net.c
@@ -117,6 +117,7 @@
#if defined(CONFIG_CMD_WOL)
#include "wol.h"
#endif
+#include <net/tcp.h>
/** BOOTP EXTENTIONS **/
@@ -387,6 +388,8 @@ int net_init(void)
/* Only need to setup buffer pointers once. */
first_call = 0;
+ if (IS_ENABLED(CONFIG_PROT_TCP))
+ tcp_set_tcp_state(TCP_CLOSED);
}
return net_init_loop();
@@ -833,6 +836,16 @@ int net_send_udp_packet(uchar *ether, struct in_addr dest, int dport, int sport,
IPPROTO_UDP, 0, 0, 0);
}
+#if defined(CONFIG_PROT_TCP)
+int net_send_tcp_packet(int payload_len, int dport, int sport, u8 action,
+ u32 tcp_seq_num, u32 tcp_ack_num)
+{
+ return net_send_ip_packet(net_server_ethaddr, net_server_ip, dport,
+ sport, payload_len, IPPROTO_TCP, action,
+ tcp_seq_num, tcp_ack_num);
+}
+#endif
+
int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport,
int payload_len, int proto, u8 action, u32 tcp_seq_num,
u32 tcp_ack_num)
@@ -864,6 +877,14 @@ int net_send_ip_packet(uchar *ether, struct in_addr dest, int dport, int sport,
payload_len);
pkt_hdr_size = eth_hdr_size + IP_UDP_HDR_SIZE;
break;
+#if defined(CONFIG_PROT_TCP)
+ case IPPROTO_TCP:
+ pkt_hdr_size = eth_hdr_size
+ + tcp_set_tcp_header(pkt + eth_hdr_size, dport, sport,
+ payload_len, action, tcp_seq_num,
+ tcp_ack_num);
+ break;
+#endif
default:
return -EINVAL;
}
@@ -1289,6 +1310,15 @@ void net_process_received_packet(uchar *in_packet, int len)
if (ip->ip_p == IPPROTO_ICMP) {
receive_icmp(ip, len, src_ip, et);
return;
+#if defined(CONFIG_PROT_TCP)
+ } else if (ip->ip_p == IPPROTO_TCP) {
+ debug_cond(DEBUG_DEV_PKT,
+ "TCP PH (to=%pI4, from=%pI4, len=%d)\n",
+ &dst_ip, &src_ip, len);
+
+ rxhand_tcp_f((union tcp_build_pkt *)ip, len);
+ return;
+#endif
} else if (ip->ip_p != IPPROTO_UDP) { /* Only UDP packets */
return;
}