• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef	_GPXE_TFTP_H
2 #define	_GPXE_TFTP_H
3 
4 /** @file
5  *
6  * TFTP protocol
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER );
11 
12 #include <stdint.h>
13 
14 #define TFTP_PORT	       69 /**< Default TFTP server port */
15 #define	TFTP_DEFAULT_BLKSIZE  512 /**< Default TFTP data block size */
16 #define	TFTP_MAX_BLKSIZE     1432
17 
18 #define TFTP_RRQ		1 /**< Read request opcode */
19 #define TFTP_WRQ		2 /**< Write request opcode */
20 #define TFTP_DATA		3 /**< Data block opcode */
21 #define TFTP_ACK		4 /**< Data block acknowledgement opcode */
22 #define TFTP_ERROR		5 /**< Error opcode */
23 #define TFTP_OACK		6 /**< Options acknowledgement opcode */
24 
25 #define TFTP_ERR_FILE_NOT_FOUND	1 /**< File not found */
26 #define TFTP_ERR_ACCESS_DENIED	2 /**< Access violation */
27 #define TFTP_ERR_DISK_FULL	3 /**< Disk full or allocation exceeded */
28 #define TFTP_ERR_ILLEGAL_OP	4 /**< Illegal TFTP operation */
29 #define TFTP_ERR_UNKNOWN_TID	5 /**< Unknown transfer ID */
30 #define TFTP_ERR_FILE_EXISTS	6 /**< File already exists */
31 #define TFTP_ERR_UNKNOWN_USER	7 /**< No such user */
32 #define TFTP_ERR_BAD_OPTS	8 /**< Option negotiation failed */
33 
34 #define MTFTP_PORT	     1759 /**< Default MTFTP server port */
35 
36 /** A TFTP read request (RRQ) packet */
37 struct tftp_rrq {
38 	uint16_t opcode;
39 	char data[0];
40 } __attribute__ (( packed ));
41 
42 /** A TFTP data (DATA) packet */
43 struct tftp_data {
44 	uint16_t opcode;
45 	uint16_t block;
46 	uint8_t data[0];
47 } __attribute__ (( packed ));
48 
49 /** A TFTP acknowledgement (ACK) packet */
50 struct tftp_ack {
51 	uint16_t opcode;
52 	uint16_t block;
53 } __attribute__ (( packed ));
54 
55 /** A TFTP error (ERROR) packet */
56 struct tftp_error {
57 	uint16_t opcode;
58 	uint16_t errcode;
59 	char errmsg[0];
60 } __attribute__ (( packed ));
61 
62 /** A TFTP options acknowledgement (OACK) packet */
63 struct tftp_oack {
64 	uint16_t opcode;
65 	char data[0];
66 } __attribute__ (( packed ));
67 
68 /** The common header of all TFTP packets */
69 struct tftp_common {
70 	uint16_t opcode;
71 } __attribute__ (( packed ));
72 
73 /** A union encapsulating all TFTP packet types */
74 union tftp_any {
75 	struct tftp_common	common;
76 	struct tftp_rrq		rrq;
77 	struct tftp_data	data;
78 	struct tftp_ack		ack;
79 	struct tftp_error	error;
80 	struct tftp_oack	oack;
81 };
82 
83 extern void tftp_set_request_blksize ( unsigned int blksize );
84 
85 #endif /* _GPXE_TFTP_H */
86