tftp_server.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /****************************************************************//**
  2. *
  3. * @file tftp_server.h
  4. *
  5. * @author Logan Gunthorpe <logang@deltatee.com>
  6. *
  7. * @brief Trivial File Transfer Protocol (RFC 1350)
  8. *
  9. * Copyright (c) Deltatee Enterprises Ltd. 2013
  10. * All rights reserved.
  11. *
  12. ********************************************************************/
  13. /*
  14. * Redistribution and use in source and binary forms, with or without
  15. * modification,are permitted provided that the following conditions are met:
  16. *
  17. * 1. Redistributions of source code must retain the above copyright notice,
  18. * this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. * 3. The name of the author may not be used to endorse or promote products
  23. * derived from this software without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  26. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  27. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  28. * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  30. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  31. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  32. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  33. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  34. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35. *
  36. * Author: Logan Gunthorpe <logang@deltatee.com>
  37. *
  38. */
  39. #ifndef LWIP_HDR_APPS_TFTP_SERVER_H
  40. #define LWIP_HDR_APPS_TFTP_SERVER_H
  41. #include "tftp_opts.h"
  42. #include "lwip/err.h"
  43. #include "lwip/pbuf.h"
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. /** @ingroup tftp
  48. * TFTP context containing callback functions for TFTP transfers
  49. */
  50. struct tftp_context {
  51. /**
  52. * Open file for read/write.
  53. * @param fname Filename
  54. * @param mode Mode string from TFTP RFC 1350 (netascii, octet, mail)
  55. * @param write Flag indicating read (0) or write (!= 0) access
  56. * @returns File handle supplied to other functions
  57. */
  58. void* (*open)(const char* fname, const char* mode, u8_t write);
  59. /**
  60. * Close file handle
  61. * @param handle File handle returned by open()
  62. */
  63. void (*close)(void* handle);
  64. /**
  65. * Read from file
  66. * @param handle File handle returned by open()
  67. * @param buf Target buffer to copy read data to
  68. * @param bytes Number of bytes to copy to buf
  69. * @returns &gt;= 0: Success; &lt; 0: Error
  70. */
  71. int (*read)(void* handle, void* buf, int bytes);
  72. /**
  73. * Write to file
  74. * @param handle File handle returned by open()
  75. * @param pbuf PBUF adjusted such that payload pointer points
  76. * to the beginning of write data. In other words,
  77. * TFTP headers are stripped off.
  78. * @returns &gt;= 0: Success; &lt; 0: Error
  79. */
  80. int (*write)(void* handle, struct pbuf* p);
  81. };
  82. err_t tftp_init(const struct tftp_context* ctx);
  83. #ifdef __cplusplus
  84. }
  85. #endif
  86. #endif /* LWIP_HDR_APPS_TFTP_SERVER_H */