tftp.h
Go to the documentation of this file.00001
00066 #ifndef TFTP_H
00067 #define TFTP_H
00068
00069 #include <cfg/compiler.h>
00070 #include <lwip/sockets.h>
00071 #include <io/kfile.h>
00072
00073 #define TFTP_RRQ 0x0100
00074 #define TFTP_WRQ 0x0200
00075 #define TFTP_DATA 03
00076 #define TFTP_ACK 0x0400
00077 #define TFTP_PROTOERR 0x0500
00078
00079
00080 #define TFTP_PROTOERR_ACCESS_VIOLATION 0x0200
00081
00082 #define TFTP_SERVER_PORT 69
00083
00084
00085 #define TFTP_ERR_TIMEOUT -2
00086 #define TFTP_ERR -1
00087
00088 struct PACKED TftpHeader
00089 {
00090 short opcode;
00091 union PACKED
00092 {
00093 short block;
00094 short code;
00095 char stuff[1];
00096 } th_u;
00097 };
00098
00099 typedef struct PACKED Tftpframe {
00100 struct TftpHeader hdr;
00101 char data[512];
00102 } Tftpframe;
00103
00104 struct PACKED ackframe
00105 {
00106 short opcode;
00107 short block_num;
00108 };
00109
00110 struct PACKED errframe
00111 {
00112 short opcode;
00113 short errcode;
00114 char str;
00115 };
00116
00117 typedef enum
00118 {
00119 TFTP_READ,
00120 TFTP_WRITE,
00121 } TftpOpenMode;
00122
00123 typedef struct TftpSession
00124 {
00125 struct sockaddr_in addr;
00126 socklen_t addr_len;
00127 int sock;
00128 unsigned short block;
00129 mtime_t timeout;
00130 int error;
00131 Tftpframe frame;
00132 size_t bytes_available;
00133 size_t valid_data;
00134 bool is_xfer_end;
00135 bool pending_ack;
00136 KFile kfile_request;
00137 } TftpSession;
00138
00139 int tftp_init(TftpSession *ctx, unsigned short port, mtime_t timeout);
00140 KFile *tftp_listen(TftpSession *ctx, char *filename, size_t len, TftpOpenMode *mode);
00141
00142 #endif // TFTP_H