tftp.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @file tftp.h
  3. * @brief TFTP Header File.
  4. * @version 0.1.0
  5. * @author Sang-sik Kim
  6. */
  7. #ifndef __TFTP_H__
  8. #define __TFTP_H__
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. #include <stdint.h>
  13. #define F_APP_TFTP
  14. #define __TFTP_DEBUG__
  15. #define F_STORAGE // If your target support a storage, you have to activate this feature and implement.
  16. #define SOCK_TFTP 1
  17. #define INFO_DBG 0x01
  18. #define ERROR_DBG 0x02
  19. #define DEBUG_DBG 0x04
  20. #define IPC_DBG 0x08
  21. #define DBG_PRINT(level, format, args...) { \
  22. if(dbg_level & level) \
  23. printf(format, ##args); \
  24. }
  25. #define NORMAL_MODE 0
  26. #define TFTP_MODE 1
  27. extern int dbg_level;
  28. /* tftp message */
  29. #define TFTP_RRQ 1
  30. #define TFTP_WRQ 2
  31. #define TFTP_DATA 3
  32. #define TFTP_ACK 4
  33. #define TFTP_ERROR 5
  34. #define TFTP_OACK 6
  35. /* tftp state */
  36. #define STATE_NONE 0
  37. #define STATE_RRQ 1
  38. #define STATE_WRQ 2
  39. #define STATE_DATA 3
  40. #define STATE_ACK 4
  41. #define STATE_OACK 5
  42. /* tftp transfer mode */
  43. #define TRANS_ASCII "netascii"
  44. #define TRANS_BINARY "octet"
  45. /* tftp progress state */
  46. #define TFTP_PROGRESS 0
  47. #define TFTP_FAIL 1
  48. #define TFTP_SUCCESS 2
  49. /* define */
  50. #define TFTP_SERVER_PORT 69
  51. #define TFTP_TEMP_PORT 51000
  52. #define TFTP_BLK_SIZE 512
  53. #define MAX_MTU_SIZE 1514
  54. #define FILE_NAME_SIZE 20
  55. //#define __TFTP_DEBUG__
  56. /* typedef */
  57. typedef struct tftp_data {
  58. uint16_t opcode;
  59. uint16_t block_num;
  60. uint8_t data[0];
  61. } TFTP_DATA_T;
  62. typedef struct tftp_error {
  63. uint16_t opcode;
  64. uint16_t error_code;
  65. uint8_t error_msg[0];
  66. } TFTP_ERROR_T;
  67. typedef struct tftp_option {
  68. uint8_t *code;
  69. uint8_t *value;
  70. } TFTP_OPTION;
  71. /* Functions */
  72. void TFTP_init(uint8_t socket, uint8_t *buf);
  73. void TFTP_exit(void);
  74. int TFTP_run(void);
  75. void TFTP_read_request(uint32_t server_ip, uint8_t *filename);
  76. void tftp_timeout_handler(void);
  77. #ifdef __cplusplus
  78. }
  79. #endif
  80. #endif /*__TFTP_H__ */