tftpserver.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /**
  2. ******************************************************************************
  3. * @file LwIP/LwIP_TFTP_Server/Inc/tftpserver.h
  4. * @author MCD Application Team
  5. * @brief This file is the header of tftpserver file.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright © 2016 STMicroelectronics International N.V.
  10. * All rights reserved.</center></h2>
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted, provided that the following conditions are met:
  14. *
  15. * 1. Redistribution of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. Neither the name of STMicroelectronics nor the names of other
  21. * contributors to this software may be used to endorse or promote products
  22. * derived from this software without specific written permission.
  23. * 4. This software, including modifications and/or derivative works of this
  24. * software, must execute solely and exclusively on microcontroller or
  25. * microprocessor devices manufactured by or for STMicroelectronics.
  26. * 5. Redistribution and use of this software other than as permitted under
  27. * this license is void and will automatically terminate your rights under
  28. * this license.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  31. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  33. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  34. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  35. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  36. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  37. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  38. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  39. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  40. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  41. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. *
  43. ******************************************************************************
  44. */
  45. #ifndef __TFTPSERVER_H_
  46. #define __TFTPSERVER_H_
  47. #include "lwip/mem.h"
  48. #include "lwip/udp.h"
  49. #define TFTP_OPCODE_LEN 2
  50. #define TFTP_BLKNUM_LEN 2
  51. #define TFTP_DATA_LEN_MAX 512
  52. #define TFTP_DATA_PKT_HDR_LEN (TFTP_OPCODE_LEN + TFTP_BLKNUM_LEN)
  53. #define TFTP_ERR_PKT_HDR_LEN (TFTP_OPCODE_LEN + TFTP_ERRCODE_LEN)
  54. #define TFTP_ACK_PKT_LEN (TFTP_OPCODE_LEN + TFTP_BLKNUM_LEN)
  55. #define TFTP_DATA_PKT_LEN_MAX (TFTP_DATA_PKT_HDR_LEN + TFTP_DATA_LEN_MAX)
  56. #define TFTP_MAX_RETRIES 3
  57. #define TFTP_TIMEOUT_INTERVAL 5
  58. typedef struct
  59. {
  60. int op; /*WRQ */
  61. /* last block read */
  62. char data[TFTP_DATA_PKT_LEN_MAX];
  63. int data_len;
  64. /* destination ip:port */
  65. ip_addr_t to_ip;
  66. int to_port;
  67. /* next block number */
  68. int block;
  69. /* total number of bytes transferred */
  70. int tot_bytes;
  71. /* timer interrupt count when last packet was sent */
  72. /* this should be used to resend packets on timeout */
  73. unsigned long long last_time;
  74. }tftp_connection_args;
  75. /* TFTP opcodes as specified in RFC1350 */
  76. typedef enum {
  77. TFTP_RRQ = 1,
  78. TFTP_WRQ = 2,
  79. TFTP_DATA = 3,
  80. TFTP_ACK = 4,
  81. TFTP_ERROR = 5
  82. } tftp_opcode;
  83. /* TFTP error codes as specified in RFC1350 */
  84. typedef enum {
  85. TFTP_ERR_NOTDEFINED,
  86. TFTP_ERR_FILE_NOT_FOUND,
  87. TFTP_ERR_ACCESS_VIOLATION,
  88. TFTP_ERR_DISKFULL,
  89. TFTP_ERR_ILLEGALOP,
  90. TFTP_ERR_UKNOWN_TRANSFER_ID,
  91. TFTP_ERR_FILE_ALREADY_EXISTS,
  92. TFTP_ERR_NO_SUCH_USER,
  93. } tftp_errorcode;
  94. void IAP_tftpd_init(void);
  95. #endif