tftp moved to separate file.
[people/lynusvaz/gpxe.git] / src / include / tftp.h
1 #ifndef TFTP_H
2 #define TFTP_H
3
4 #include "in.h"
5 #include "nic.h"
6
7 #define TFTP_PORT       69
8 #define TFTP_DEFAULTSIZE_PACKET 512
9 #define TFTP_MAX_PACKET         1432 /* 512 */
10
11 #define TFTP_RRQ        1
12 #define TFTP_WRQ        2
13 #define TFTP_DATA       3
14 #define TFTP_ACK        4
15 #define TFTP_ERROR      5
16 #define TFTP_OACK       6
17
18 #define TFTP_CODE_EOF   1
19 #define TFTP_CODE_MORE  2
20 #define TFTP_CODE_ERROR 3
21 #define TFTP_CODE_BOOT  4
22 #define TFTP_CODE_CFG   5
23
24 struct tftp_t {
25         struct iphdr ip;
26         struct udphdr udp;
27         uint16_t opcode;
28         union {
29                 uint8_t rrq[TFTP_DEFAULTSIZE_PACKET];
30                 struct {
31                         uint16_t block;
32                         uint8_t  download[TFTP_MAX_PACKET];
33                 } data;
34                 struct {
35                         uint16_t block;
36                 } ack;
37                 struct {
38                         uint16_t errcode;
39                         uint8_t  errmsg[TFTP_DEFAULTSIZE_PACKET];
40                 } err;
41                 struct {
42                         uint8_t  data[TFTP_DEFAULTSIZE_PACKET+2];
43                 } oack;
44         } u;
45 } PACKED;
46
47 /* define a smaller tftp packet solely for making requests to conserve stack
48    512 bytes should be enough */
49 struct tftpreq_t {
50         struct iphdr ip;
51         struct udphdr udp;
52         uint16_t opcode;
53         union {
54                 uint8_t rrq[512];
55                 struct {
56                         uint16_t block;
57                 } ack;
58                 struct {
59                         uint16_t errcode;
60                         uint8_t  errmsg[512-2];
61                 } err;
62         } u;
63 } PACKED;
64
65 struct tftpreq_info_t {
66         struct sockaddr_in *server;
67         const char *name;
68         unsigned short blksize;
69 } PACKED;
70
71 struct tftpblk_info_t {
72         char *data;
73         unsigned int block;
74         unsigned int len;
75         int eof;
76 } PACKED;
77
78 #define TFTP_MIN_PACKET (sizeof(struct iphdr) + sizeof(struct udphdr) + 4)
79
80 /*
81  * Functions in tftp.c.  Needed for pxe_export.c
82  *
83  */
84 extern int tftp_block ( struct tftpreq_info_t *request,
85                         struct tftpblk_info_t *block );
86 extern int tftp ( char *url,
87                   struct sockaddr_in *server,
88                   char *file,
89                   int ( * process ) ( unsigned char *data,
90                                       unsigned int blocknum,
91                                       unsigned int len, int eof ) );
92
93 #endif  /* TFTP_H */