1.2.1.23 TFTP Server Module

The TCP/IP Stack Library Trivial File Transfer Protocol (TFTP) module is a simple protocol used to transfer files.

The TFTP server waits for client requests to read and write files.

Abstraction Model

The TFTP communication is based on a client/server model. The process of transferring a file consists of three main phases. In highly generalized terms, these phases are:

  • Initial Connection:

    • The TFTP client establishes the connection by sending an initial request to the server.

    • The server responds back to the client and the connection is effectively opened.

  • Data Transfer:

    • Once the connection has been established, the client and server exchange TFTP messages. One device sends data and the other sends acknowledgments.

  • Connection Termination:

    • When the last TFTP message containing data has been sent and acknowledged, the connection is terminated.

TFT_client_server_comm

How the Library Works

Any transfer begins with a request from a client to read or write a file. If the server grants the request, the connection is opened and the file is sent usually in fixed length blocks of 512 bytes. Each data packet contains one block of data, and must be acknowledged by an acknowledgment packet before the next packet can be sent. A data packet of less than 512 bytes, signals termination of a transfer. If a packet gets lost in the network, the intended recipient will time out and may retransmit the last packet (which may be data or an acknowledgment), thus causing the sender of the lost packet to retransmit that lost packet.

TFTP Transfer Set up

  • To set up a TFTP transfer, a TFTP client device can request (get) files from the server and also transfer (put) files to the server.

  • The File System on the server is transparent. Currently the Microchip Harmony devices support MPFS or FAT file systems.

  • The Microchip TFTP server implementation allows the user to start and stop the service dynamically by using the TFTP Application Programming Interface ( API) function.

TFTP Transfer Options

The following options are supported in the current TFTP server implementation (see RFC 2348, 2349):

TFTP Option NameTFTP Option Code (Used in Request Messages)Description
Block SizeblksizeThe option allows the Client and the Server to send data blocks of a size different than 512 bytes
Timeout IntervalintervalThe option permits the client /server to agree on a specified number of seconds to use for their retransmission.
Transfer SizetsizeThe option allows the side receiving the file to determine the ultimate size of the transfer before it begins.

TFTP Client Server Communication

TFTP Write Request (WRQ)

The following diagram illustrates a write request

TFT_client_write_req

TFTP Read Request (RRQ)

The following diagram illustrates a read request

TFT_client_read_req

Flow chart for the TFTP server processing incoming requests

TFT_server_read_write_flowchart

Library Interface

NameDescription
Macros
TCPIP_TFTPS_CLIENT_NUMBERThe number of Clients requests will be processed for the TFTP server stack.
TCPIP_TFTPS_DEFAULT_BLOCK_SIZEThe maximum value for the file name size. Even though the RFC allows blocks of up to 65464 bytes, In practice the limit is set to 1468 bytes: the size of an Ethernet MTU minus the headers of TFTP (4 bytes), UDP (8 bytes) and IP (20 bytes)
TCPIP_TFTPS_DEFAULT_FILESIZEThe maximum size for a file in bytes to be accepted.TFTP Opcode defined by RFC 2347.
TCPIP_TFTPS_DEFAULT_TIMEOUTThis time is used during the TFTP retransmission and TFTP Client wait for these many seconds before retransmitting .
TCPIP_TFTPS_RETRANSMIT_COUNTThe number of attempts to retransmit the previous packet before declaring a TIMEOUT error.
TCPIP_TFTPS_TASK_TICK_RATEThe TFTP server task rate in milliseconds. The default value is 100 milliseconds. The lower the rate (higher the frequency) the higher the module priority and higher module performance can be obtained The value cannot be lower than the TCPIP_STACK_TICK_RATE.
TCPIP_TFTPS_FILENAME_LENThe default length of the file name is defined to 64 bytes.
TCPIP_TFTPS_USER_NOTIFICATIONallow TFTP Server user notification if enabled, the TCPIP_TFTPS_HandlerRegister/TCPIP_TFTPS_HandlerDeRegister functions exist and can be used
Functions
TCPIP_TFTPS_ClientsNumberDetermines the number of clients running for this server.
TCPIP_TFTPS_DisableDisables the TFTP server for the specified interface.
TCPIP_TFTPS_EnableEnables the TFTP server for the specified interface.
TCPIP_TFTPS_HandlerDeRegisterDe-registers a previously registered TFTP Server handler.
TCPIP_TFTPS_HandlerRegisterRegisters a TFTP Server Handler.
TCPIP_TFTPS_IsEnabledDetermines if a TFTP server is active or not.
TCPIP_TFTPS_TaskStandard TCP/IP stack module task function.
Data Types and Constants
TCPIP_TFTPS_EVENT_TYPEList of events for the TFTPS module.
TCPIP_TFTPS_RESULTProvides a list of possible results for the TFTPS module.
TCPIP_TFTPS_MODULE_CONFIGPlaceholder for TFTPS Module Configuration
TCPIP_TFTPS_EVENT_HANDLERNotification handler that can be called when there is a TFTP process for a client.
TCPIP_TFTPS_HANDLETFTP server handle.