You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tftp.h 1.8KB

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