xref: /titanic_52/usr/src/grub/grub-0.97/netboot/tftp.h (revision e802abbda8c322f24d47835734f4a793ef15ddc8)
1 #ifndef	_TFTP_H
2 #define	_TFTP_H
3 
4 #include "if_ether.h"
5 #include "ip.h"
6 #include "udp.h"
7 
8 #ifndef	MAX_TFTP_RETRIES
9 #define MAX_TFTP_RETRIES	20
10 #endif
11 
12 /* These settings have sense only if compiled with -DCONGESTED */
13 /* total retransmission timeout in ticks */
14 #define TFTP_TIMEOUT		(30*TICKS_PER_SEC)
15 /* packet retransmission timeout in ticks */
16 #define TFTP_REXMT		(3*TICKS_PER_SEC)
17 
18 #define TFTP_PORT	69
19 #define	TFTP_DEFAULTSIZE_PACKET	512
20 #define	TFTP_MAX_PACKET		1432 /* 512 */
21 
22 #define TFTP_RRQ	1
23 #define TFTP_WRQ	2
24 #define TFTP_DATA	3
25 #define TFTP_ACK	4
26 #define TFTP_ERROR	5
27 #define TFTP_OACK	6
28 
29 #define TFTP_CODE_EOF	1
30 #define TFTP_CODE_MORE	2
31 #define TFTP_CODE_ERROR	3
32 #define TFTP_CODE_BOOT	4
33 #define TFTP_CODE_CFG	5
34 
35 struct tftp_t {
36 	struct iphdr ip;
37 	struct udphdr udp;
38 	uint16_t opcode;
39 	union {
40 		uint8_t rrq[TFTP_DEFAULTSIZE_PACKET];
41 		struct {
42 			uint16_t block;
43 			uint8_t  download[TFTP_MAX_PACKET];
44 		} data;
45 		struct {
46 			uint16_t block;
47 		} ack;
48 		struct {
49 			uint16_t errcode;
50 			uint8_t  errmsg[TFTP_DEFAULTSIZE_PACKET];
51 		} err;
52 		struct {
53 			uint8_t  data[TFTP_DEFAULTSIZE_PACKET+2];
54 		} oack;
55 	} u;
56 };
57 
58 /* define a smaller tftp packet solely for making requests to conserve stack
59    512 bytes should be enough */
60 struct tftpreq_t {
61 	struct iphdr ip;
62 	struct udphdr udp;
63 	uint16_t opcode;
64 	union {
65 		uint8_t rrq[512];
66 		struct {
67 			uint16_t block;
68 		} ack;
69 		struct {
70 			uint16_t errcode;
71 			uint8_t  errmsg[512-2];
72 		} err;
73 	} u;
74 };
75 
76 #define TFTP_MIN_PACKET	(sizeof(struct iphdr) + sizeof(struct udphdr) + 4)
77 
78 typedef int (*read_actor_t)(unsigned char *, unsigned int, unsigned int, int);
79 
80 int tftp_file_read(const char *name, read_actor_t);
81 
82 #endif	/* _TFTP_H */
83