ftpc.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #ifndef _FTPC_H_
  2. #define _FTPC_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdint.h>
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <string.h>
  10. #include <limits.h>
  11. #include <stdarg.h>
  12. #include <stdlib.h>
  13. #include "socket.h"
  14. /* If you need this header, use it. */
  15. //#include "stdio_private.h"
  16. #define F_APP_FTPC
  17. /* If your target support a file system, you have to activate this feature and implement. */
  18. //#define F_FILESYSTEM
  19. /* Change to your Chipset Uart function, you have to activate this feature and implement.
  20. * Change!! -> Board_UARTGetCharBlocking()
  21. * Below is an example of a function of lpc_chip library. */
  22. //#define ftp_getc() Board_UARTGetCharBlocking()
  23. #ifdef F_FILESYSTEM
  24. #include "ff.h"
  25. #endif
  26. #ifndef ftp_getc()
  27. #define Need_UARTGetCharBlocking_func
  28. #else
  29. /* Change library
  30. * Change!! -> board_api.h,
  31. * Below is an example of a function of lpc_chip library. */
  32. #include "board_api.h"
  33. #endif
  34. #define LINELEN 100
  35. #ifndef F_FILESYSTEM
  36. #define _MAX_SS 512
  37. #endif
  38. #define CTRL_SOCK 2
  39. #define DATA_SOCK 3
  40. /* FTP Responses */
  41. #define R_150 150 /* File status ok; opening data conn */
  42. #define R_200 200 /* 'Generic' command ok */
  43. #define R_220 220 /* Service ready for new user. */
  44. #define R_226 226 /* Closing data connection. File transfer/abort successful */
  45. #define R_227 227 /* Entering passive mode (h1,h2,h3,h4,p1,p2) */
  46. #define R_230 230 /* User logged in, proceed */
  47. #define R_331 331 /* User name okay, need password. */
  48. #define TransferAscii 'A'
  49. #define TransferBinary 'I'
  50. enum ftpc_type {
  51. ASCII_TYPE,
  52. IMAGE_TYPE,
  53. };
  54. enum ftpc_datasock_state{
  55. DATASOCK_IDLE,
  56. DATASOCK_READY,
  57. DATASOCK_START
  58. };
  59. enum ftpc_datasock_mode{
  60. PASSIVE_MODE,
  61. ACTIVE_MODE
  62. };
  63. enum CommandFirst {
  64. f_nocmd,
  65. f_dir,
  66. f_put,
  67. f_get,
  68. };
  69. enum CommandSecond {
  70. s_nocmd,
  71. s_dir,
  72. s_put,
  73. s_get,
  74. };
  75. struct Command {
  76. enum CommandFirst First;
  77. enum CommandSecond Second;
  78. };
  79. struct ftpc {
  80. uint8_t control; /* Control stream */
  81. uint8_t data; /* Data stream */
  82. enum ftpc_type type; /* Transfer type */
  83. enum ftpc_datasock_state dsock_state;
  84. enum ftpc_datasock_mode dsock_mode;
  85. char workingdir[LINELEN];
  86. char filename[LINELEN];
  87. #ifdef F_FILESYSTEM
  88. FIL fil; // FatFs File objects
  89. FRESULT fr; // FatFs function common result code
  90. #endif
  91. };
  92. #ifndef un_I2cval
  93. typedef union _un_l2cval {
  94. uint32_t lVal;
  95. uint8_t cVal[4];
  96. }un_l2cval;
  97. #endif
  98. void ftpc_init(uint8_t * src_ip);
  99. uint8_t ftpc_run(uint8_t * dbuf);
  100. char proc_ftpc(char * buf);
  101. int pportc(char * arg);
  102. uint8_t* User_Keyboard_MSG();
  103. #ifdef __cplusplus
  104. }
  105. #endif
  106. #endif // _FTPC_H_