12 #include <gpxe/async.h>
13 #include <gpxe/retry.h>
14 #include <gpxe/buffer.h>
16 #define TFTP_PORT 69 /**< Default TFTP server port */
17 #define TFTP_DEFAULT_BLKSIZE 512 /**< Default TFTP data block size */
18 #define TFTP_MAX_BLKSIZE 1432
20 #define TFTP_RRQ 1 /**< Read request opcode */
21 #define TFTP_WRQ 2 /**< Write request opcode */
22 #define TFTP_DATA 3 /**< Data block opcode */
23 #define TFTP_ACK 4 /**< Data block acknowledgement opcode */
24 #define TFTP_ERROR 5 /**< Error opcode */
25 #define TFTP_OACK 6 /**< Options acknowledgement opcode */
27 #define TFTP_ERR_FILE_NOT_FOUND 1 /**< File not found */
28 #define TFTP_ERR_ACCESS_DENIED 2 /**< Access violation */
29 #define TFTP_ERR_DISK_FULL 3 /**< Disk full or allocation exceeded */
30 #define TFTP_ERR_ILLEGAL_OP 4 /**< Illegal TFTP operation */
31 #define TFTP_ERR_UNKNOWN_TID 5 /**< Unknown transfer ID */
32 #define TFTP_ERR_FILE_EXISTS 6 /**< File already exists */
33 #define TFTP_ERR_UNKNOWN_USER 7 /**< No such user */
34 #define TFTP_ERR_BAD_OPTS 8 /**< Option negotiation failed */
36 /** A TFTP read request (RRQ) packet */
40 } __attribute__ (( packed ));
42 /** A TFTP data (DATA) packet */
47 } __attribute__ (( packed ));
49 /** A TFTP acknowledgement (ACK) packet */
53 } __attribute__ (( packed ));
55 /** A TFTP error (ERROR) packet */
60 } __attribute__ (( packed ));
62 /** A TFTP options acknowledgement (OACK) packet */
66 } __attribute__ (( packed ));
68 /** The common header of all TFTP packets */
71 } __attribute__ (( packed ));
73 /** A union encapsulating all TFTP packet types */
75 struct tftp_common common;
77 struct tftp_data data;
79 struct tftp_error error;
80 struct tftp_oack oack;
86 * This data structure holds the state for an ongoing TFTP transfer.
89 /** URI being fetched */
91 /** Data buffer to fill */
92 struct buffer *buffer;
93 /** Asynchronous operation */
96 /** Requested data block size
98 * This is the "blksize" option requested from the TFTP
99 * server. It may or may not be honoured.
101 unsigned int request_blksize;
105 * This is the "blksize" option negotiated with the TFTP
106 * server. (If the TFTP server does not support TFTP options,
107 * this will default to 512).
109 unsigned int blksize;
112 * This is the value returned in the "tsize" option from the
113 * TFTP server. If the TFTP server does not support the
114 * "tsize" option, this value will be zero.
121 * This is the transfer ID allocated by the server, used as
122 * the server UDP port for all packets except the initial read
128 * This is the block number to be used in the next ACK sent
129 * back to the server, i.e. the number of the last received
130 * data block. The value zero indicates that the last
131 * received block was an OACK (i.e. that the next ACK will
132 * contain a block number of zero), and any value less than
133 * zero indicates that the connection has not yet been opened
134 * (i.e. that no blocks have yet been received).
137 /** UDP connection */
138 struct udp_connection udp;
139 /** Retransmission timer */
140 struct retry_timer timer;
143 /* Function prototypes */
145 extern int tftp_get ( struct uri *uri, struct buffer *buffer,
146 struct async *parent );
148 #endif /* _GPXE_TFTP_H */