Chapter 6. Trivial File Transfer Protocol

Table of Contents
tftp_decode_packet()
fill_tftp_request()
Other RFCs

The TFTP protocol is documented in RFC 1350, and is used to load a file over the network. For PXE compatability, Intels has an enhanced TFTP daemon called MTFTP. The main difference is that MTFTP uses larger packet sizes.

Initially a TFTP session starts by transmiting a TFTP_RRQ packet the the server that was returned during the DHCP session. The packet is transmitted to port 69, and the source IP number must be set, commonly to a value more than 1000. (Nilo starts with 2000) Once the TFTP server has receceived a TFTP_RRQ packet, it then starts by sending a TFTP_DATA packet to Nilo. Nilo then replies to this packet with a TFTP_ACK, with the block number set to the same block number that was in the data packet. Each TFTP_DATA packet is a set size. 512 bytes is the default TFTP size used by most TFTP servers. MTFTP uses a size of 1432 bytes. If a packet is received that is smaller than the default size, then this is the final packet in the downloaded file.

Example 6-1. TFTP Packet Fields


      typedef struct tftp {
          u_int16_t opcode;
	  union {
	      int8_t rrq[TFTP_DEFAULTSIZE_PACKET];
	      struct {
                  u_int16_t block;
                  int8_t download[TFTP_MAX_PACKET];
	      } data;
	      struct {
	          u_int16_t block;
	      } ack;
	      struct {
                  u_int16_t errcode;
                  int8_t errmsg[TFTP_DEFAULTSIZE_PACKET];
	      } err;
	      struct {
                  int8_t data[TFTP_DEFAULTSIZE_PACKET+2];
	      } oack;
	  } u;
      } tftp_t;

      

opcode

This is an 8 bit value that represents operation to perform. This is either typically TFTP_REQUEST, TFTP_DATA, or TFTP_ACK.

rrq

This is the filename being requested.

data.block

The number of this block.

data.download

This is the download data.

ack.block

This is the block number of the last data packet receieved.

err.errcode

This is the error code from the TFTP server

err.errmsg

This is the error message from the server.

oack.data

This is the data.

tftp_decode_packet()

int tftp_decode_packet(tftp_t *pkt, oskit_size_t pkt_size);

pkt

This is a pointer to the TFTP packet.

pkt_size

This is the size of the TFTP packet that was received. This is a standard size, and if the packet size is less than the standard, then it is the last packet of the file being loaded.