TFTP receiver

The TFTP server receives files from a remote client. Only one connection at a time is supported. See SERVICES\TFTP.FTH.

In order to use the TFTP server, you must define the actions required of the TFTP events.

N.B This is alpha test code.

Ident Block

create $MODULE  \ -- addr
Module name string.

create $VERSION \ -- addr
Version string.

create $COPYRIGHT       \ -- addr
Copyright string

Global data

0 VALUE TFTP_Socket     \ -- n
Socket used by TFTP server.

#512 VALUE TFTP_BLOCKSIZE       \ -- n
TFTP data block size.

TFTP_BLOCKSIZE 4 + VALUE TFTP_MAXPACKETSIZE     \ -- n
TFTP data packet size.

0 VALUE *TFTP_PACKET    \ -- addr
Current TFTP packet address.

0 VALUE TFTP_PACKETSIZE \ -- n
Current TFTP packet data block size.

0 VALUE blockid \ -- n
If blockid is non-zero then we are connected.

STATE_IDLE VALUE TFTPState      \ -- n
Current State Machine state ID.

TFTP State Machine equates

Event action place-holders and defaults

The reciver uses these three DEFERred words to handle incoming TFTP events.

defer TEVENT::BeginReceive      \ c-addr u -- okay?
Process a STARTRX (upload to server) request.

defer TEVENT::RxData            \ addr len --
Process a receive data request. The parameters describe the TFTP data block.

:NONAME         \ c-addr u -- okay?
Default to handle the string that comes with the STARTRX (upload to server) request. Just display the string and return true to carry on.

:NONAME         \ addr len --
Default to process a received data block. Just show the address and length.

Utility Words

: DiscardTFTP   \ --
Discard the current TFTP packet.

: AbortTFTP     \ c-addr u --
Display the TFTP error message and discard the current packet.

: zcount        \ zaddr -- zaddr len
A version of COUNT for zero terminated strings, returning the address of the first character and the length.

TFTP State Handlers

: smIDLE        { | namelen -- }
The TFTP system is idle. Perform a lot of error checks and report them if the equate DIAGS? is true.

: smSTARTRX     \ --
Handles start of receiving a file.

: smSTARTTX     \ --
Handles start of a (refused) transmission request.

: smFINISHEDRX  \ --
Handles the end of file reception.

: smFINISHEDTX  \ --
Handles the end of file transmission.

: smRXDATA      \ --
Handles a received data packet.

: smTXDATA      \ --
Handles transmission of a data packet.

: smACKDATA     \ --
Handles a data acknowledge.

: smWAITFORACK  \ --
Handles waiting for a data acknowledge. TFTP Server Task

task TFTPTask   \ -- addr
The TFTP task data structure.

: TFTP_Install  \ -- flag
Starts the TFTP server, returning true for success or false for failure. SUBJECT TO CHANGE.

Event Action Handlers

This code is currently commented out. Read it as an application example.