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](GUID-80B572B8-A68C-400D-8CDE-1C23753F195D-low.png)
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 Name | TFTP Option Code (Used in Request Messages) | Description |
---|---|---|
Block Size | blksize | The option allows the Client and the Server to send data blocks of a size different than 512 bytes |
Timeout Interval | interval | The option permits the client /server to agree on a specified number of seconds to use for their retransmission. |
Transfer Size | tsize | The 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](GUID-23C771ED-99E8-4691-8E03-2A33FBB0DA03-low.png)
TFTP Read Request (RRQ)
The following diagram illustrates a read request
![TFT_client_read_req](GUID-73724EB7-D583-412A-96EF-9A45816FC909-low.png)
Flow chart for the TFTP server processing incoming requests
![TFT_server_read_write_flowchart](GUID-18F372DF-2890-4D13-940D-35C5BF3BDB42-low.png)
Library Interface
Name | Description |
---|---|
Macros | |
TCPIP_TFTPS_CLIENT_NUMBER | The number of Clients requests will be processed for the TFTP server stack. |
TCPIP_TFTPS_DEFAULT_BLOCK_SIZE | The 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_FILESIZE | The maximum size for a file in bytes to be accepted.TFTP Opcode defined by RFC 2347. |
TCPIP_TFTPS_DEFAULT_TIMEOUT | This time is used during the TFTP retransmission and TFTP Client wait for these many seconds before retransmitting . |
TCPIP_TFTPS_RETRANSMIT_COUNT | The number of attempts to retransmit the previous packet before declaring a TIMEOUT error. |
TCPIP_TFTPS_TASK_TICK_RATE | The 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_LEN | The default length of the file name is defined to 64 bytes. |
TCPIP_TFTPS_USER_NOTIFICATION | allow TFTP Server user notification if enabled, the TCPIP_TFTPS_HandlerRegister/TCPIP_TFTPS_HandlerDeRegister functions exist and can be used |
Functions | |
TCPIP_TFTPS_ClientsNumber | Determines the number of clients running for this server. |
TCPIP_TFTPS_Disable | Disables the TFTP server for the specified interface. |
TCPIP_TFTPS_Enable | Enables the TFTP server for the specified interface. |
TCPIP_TFTPS_HandlerDeRegister | De-registers a previously registered TFTP Server handler. |
TCPIP_TFTPS_HandlerRegister | Registers a TFTP Server Handler. |
TCPIP_TFTPS_IsEnabled | Determines if a TFTP server is active or not. |
TCPIP_TFTPS_Task | Standard TCP/IP stack module task function. |
Data Types and Constants | |
TCPIP_TFTPS_EVENT_TYPE | List of events for the TFTPS module. |
TCPIP_TFTPS_RESULT | Provides a list of possible results for the TFTPS module. |
TCPIP_TFTPS_MODULE_CONFIG | Placeholder for TFTPS Module Configuration |
TCPIP_TFTPS_EVENT_HANDLER | Notification handler that can be called when there is a TFTP process for a client. |
TCPIP_TFTPS_HANDLE | TFTP server handle. |