From a76977af62010a392c16010c367185e61e856ffe Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Wed, 30 Oct 2019 20:04:56 +0100 Subject: mv to docs --- docs/j1demo/firmware/tftp.fs | 67 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 docs/j1demo/firmware/tftp.fs (limited to 'docs/j1demo/firmware/tftp.fs') diff --git a/docs/j1demo/firmware/tftp.fs b/docs/j1demo/firmware/tftp.fs new file mode 100644 index 0000000..da40aa2 --- /dev/null +++ b/docs/j1demo/firmware/tftp.fs @@ -0,0 +1,67 @@ +( TFTP JCB 09:16 11/11/10) + +variable blocknum + +: tftp-ack ( -- ) + d# 2 ETH.IP.SRCIP mac-inoffset mac@n arp-lookup if + ETH.IP.UDP.SOURCEPORT packet@ + d# 1077 + d# 2 ETH.IP.SRCIP mac-inoffset mac@n + net-my-ip + 2over arp-lookup + ( dst-port src-port dst-ip src-ip *ethaddr ) + udp-header + d# 4 mac-pkt-, + blocknum @ mac-pkt-, + udp-wrapup mac-send + then +; + +: tftp-handler ( -- ) + IP_PROTO_UDP ip-isproto if + OFFSET_UDP_DESTPORT packet@ d# 69 = if + udp-checksum? if + ETH.IP.UDP.TFTP.OPCODE packet@ + s" tftp opcode=" type dup hex4 cr + dup d# 2 = if + s" WRQ filename: " type + ETH.IP.UDP.TFTP.RWRQ.FILENAME mac-inoffset d# 32 mac-dump + + d# 0 blocknum ! + tftp-ack + then + drop + then + then + OFFSET_UDP_DESTPORT packet@ d# 1077 = if + udp-checksum? if + ETH.IP.UDP.TFTP.OPCODE packet@ + s" tftp opcode=" type dup hex4 cr + dup d# 3 = if + s" tftp recv=" type ETH.IP.UDP.TFTP.DATA.BLOCK packet@ hex4 s" expected=" type blocknum @ 1+ hex4 cr + blocknum @ 1+ + ETH.IP.UDP.TFTP.DATA.BLOCK packet@ = if + \ data at ETH.IP.UDP.TFTP.DATA.DATA + ETH.IP.UDP.TFTP.DATA.DATA mac-inoffset + blocknum @ d# 9 lshift h# 2000 + + d# 256 0do + over mac@ h# 5555 xor over h# 3ffe min ! + 2+ swap 2+ swap + loop + 2drop + d# 1 blocknum +! + tftp-ack + ETH.IP.UDP.LENGTH packet@ d# 12 - 0= if + h# 2000 h# 100 dump + bootloader + then + else + s" unexpected blocknum" type cr + tftp-ack + then + then + drop + then + then + then +; -- cgit v1.2.3