wizchip_dhcp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. //*****************************************************************************
  2. //
  3. //! \file wizchip_dhcp.h
  4. //! \brief DHCP APIs Header file.
  5. //! \details Processig DHCP protocol as DISCOVER, OFFER, REQUEST, ACK, NACK and DECLINE.
  6. //! \version 1.1.1
  7. //! \date 2019/10/08
  8. //! \par Revision history
  9. //! <2019/10/08> compare DHCP server ip address
  10. //! <2013/11/18> 1st Release
  11. //! <2012/12/20> V1.1.0
  12. //! 1. Move unreferenced DEFINE to dhcp.c
  13. //! <2012/12/26> V1.1.1
  14. //! \author Eric Jung & MidnightCow
  15. //! \copyright
  16. //!
  17. //! Copyright (c) 2013, WIZnet Co., LTD.
  18. //! All rights reserved.
  19. //!
  20. //! Redistribution and use in source and binary forms, with or without
  21. //! modification, are permitted provided that the following conditions
  22. //! are met:
  23. //!
  24. //! * Redistributions of source code must retain the above copyright
  25. //! notice, this list of conditions and the following disclaimer.
  26. //! * Redistributions in binary form must reproduce the above copyright
  27. //! notice, this list of conditions and the following disclaimer in the
  28. //! documentation and/or other materials provided with the distribution.
  29. //! * Neither the name of the <ORGANIZATION> nor the names of its
  30. //! contributors may be used to endorse or promote products derived
  31. //! from this software without specific prior written permission.
  32. //!
  33. //! THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  34. //! AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  35. //! IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. //! ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  37. //! LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  38. //! CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  39. //! SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  40. //! INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  41. //! CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  42. //! ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  43. //! THE POSSIBILITY OF SUCH DAMAGE.
  44. //
  45. //*****************************************************************************
  46. #ifndef _WIZCHIP_DHCP_H_
  47. #define _WIZCHIP_DHCP_H_
  48. #ifdef __cplusplus
  49. extern "C" {
  50. #endif
  51. /*
  52. * @brief
  53. * @details If you want to display debug & processing message, Define _DHCP_DEBUG_
  54. * @note If defined, it depends on <stdio.h>
  55. */
  56. //#define _DHCP_DEBUG_
  57. /* Retry to processing DHCP */
  58. #define MAX_DHCP_RETRY 2 ///< Maximum retry count
  59. #define DHCP_WAIT_TIME 10 ///< Wait Time 10s
  60. /* UDP port numbers for DHCP */
  61. #define DHCP_SERVER_PORT 67 ///< DHCP server port number
  62. #define DHCP_CLIENT_PORT 68 ///< DHCP client port number
  63. #define MAGIC_COOKIE 0x63825363 ///< You should not modify it number.
  64. #define DCHP_HOST_NAME "WIZnet\0"
  65. /*
  66. * @brief return value of @ref DHCP_run()
  67. */
  68. enum
  69. {
  70. DHCP_FAILED = 0, ///< Processing Fail
  71. DHCP_RUNNING, ///< Processing DHCP protocol
  72. DHCP_IP_ASSIGN, ///< First Occupy IP from DHPC server (if cbfunc == null, act as default default_ip_assign)
  73. DHCP_IP_CHANGED, ///< Change IP address by new ip from DHCP (if cbfunc == null, act as default default_ip_update)
  74. DHCP_IP_LEASED, ///< Stand by
  75. DHCP_STOPPED ///< Stop processing DHCP protocol
  76. };
  77. /*
  78. * @brief DHCP client initialization (outside of the main loop)
  79. * @param s - socket number
  80. * @param buf - buffer for processing DHCP message
  81. */
  82. void DHCP_init(uint8_t s, uint8_t * buf);
  83. /*
  84. * @brief DHCP 1s Tick Timer handler
  85. * @note SHOULD BE register to your system 1s Tick timer handler
  86. */
  87. void DHCP_time_handler(void);
  88. /*
  89. * @brief Register call back function
  90. * @param ip_assign - callback func when IP is assigned from DHCP server first
  91. * @param ip_update - callback func when IP is changed
  92. * @param ip_conflict - callback func when the assigned IP is conflict with others.
  93. */
  94. void reg_dhcp_cbfunc(void(*ip_assign)(void), void(*ip_update)(void), void(*ip_conflict)(void));
  95. /*
  96. * @brief DHCP client in the main loop
  97. * @return The value is as the follow \n
  98. * @ref DHCP_FAILED \n
  99. * @ref DHCP_RUNNING \n
  100. * @ref DHCP_IP_ASSIGN \n
  101. * @ref DHCP_IP_CHANGED \n
  102. * @ref DHCP_IP_LEASED \n
  103. * @ref DHCP_STOPPED \n
  104. *
  105. * @note This function is always called by you main task.
  106. */
  107. uint8_t DHCP_run(void);
  108. /*
  109. * @brief Stop DHCP processing
  110. * @note If you want to restart. call DHCP_init() and DHCP_run()
  111. */
  112. void DHCP_stop(void);
  113. /* Get Network information assigned from DHCP server */
  114. /*
  115. * @brief Get IP address
  116. * @param ip - IP address to be returned
  117. */
  118. void getIPfromDHCP(uint8_t* ip);
  119. /*
  120. * @brief Get Gateway address
  121. * @param ip - Gateway address to be returned
  122. */
  123. void getGWfromDHCP(uint8_t* ip);
  124. /*
  125. * @brief Get Subnet mask value
  126. * @param ip - Subnet mask to be returned
  127. */
  128. void getSNfromDHCP(uint8_t* ip);
  129. /*
  130. * @brief Get DNS address
  131. * @param ip - DNS address to be returned
  132. */
  133. void getDNSfromDHCP(uint8_t* ip);
  134. /*
  135. * @brief Get the leased time by DHCP sever
  136. * @return unit 1s
  137. */
  138. uint32_t getDHCPLeasetime(void);
  139. uint32_t getDHCPTick1s(void);
  140. #ifdef __cplusplus
  141. }
  142. #endif
  143. #endif /* _WIZCHIP_DHCP_H_ */