dhcp.h 5.2 KB

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