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