dhcp.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. #ifndef _PRO_DHCP_H_
  2. #define _PRO_DHCP_H_
  3. /*
  4. * Copyright (C) 2001-2004 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Portions Copyright (c) 1983, 1993 by
  36. * The Regents of the University of California. All rights reserved.
  37. *
  38. * Redistribution and use in source and binary forms, with or without
  39. * modification, are permitted provided that the following conditions
  40. * are met:
  41. * 1. Redistributions of source code must retain the above copyright
  42. * notice, this list of conditions and the following disclaimer.
  43. * 2. Redistributions in binary form must reproduce the above copyright
  44. * notice, this list of conditions and the following disclaimer in the
  45. * documentation and/or other materials provided with the distribution.
  46. * 3. Neither the name of the University nor the names of its contributors
  47. * may be used to endorse or promote products derived from this software
  48. * without specific prior written permission.
  49. *
  50. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  51. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  52. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  53. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  54. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  55. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  56. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  57. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  58. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  59. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  60. * SUCH DAMAGE.
  61. */
  62. /*!
  63. * \file pro/dhcp.h
  64. * \brief DHCP protocol definitions.
  65. *
  66. * \verbatim
  67. *
  68. * $Log$
  69. * Revision 1.10 2008/08/11 07:00:23 haraldkipp
  70. * BSD types replaced by stdint types (feature request #1282721).
  71. *
  72. * Revision 1.9 2006/10/08 16:48:22 haraldkipp
  73. * Documentation fixed
  74. *
  75. * Revision 1.8 2005/08/02 17:46:49 haraldkipp
  76. * Major API documentation update.
  77. *
  78. * Revision 1.7 2005/02/03 14:34:05 haraldkipp
  79. * Several bug fixes and enhancements. The most important fix will
  80. * avoid hanging, when Ethernut is reset while ICMP pings are
  81. * received. A large number of changes make the client to follow
  82. * RFC 2131 more closely, like maintaining renewal and rebind time.
  83. * Two new API calls, NutDhcpStatus() and NutDhcpError(), allow
  84. * to query the current status of the DHCP client. The previously
  85. * introduced API call NutDhcpIsConfigured() has been marked
  86. * deprecated. Another problem was with timeout, because the client
  87. * continued negotiation with the server after the timeout time
  88. * given in the API called elapsed. Now all internal timeouts are
  89. * adjusted to the API timeout. Furthermore the previous version
  90. * let the client continue on fatal errors like UDP receive or UDP
  91. * broadcast failures. Now the client stops on such errors and
  92. * informs the caller. Finally the documentation has been enhanced.
  93. *
  94. * Revision 1.6 2004/12/31 10:52:18 drsung
  95. * Bugfixes from Michel Hendriks applied.
  96. *
  97. * Revision 1.5 2004/03/18 11:22:03 haraldkipp
  98. * Deprecated functions removed
  99. *
  100. * Revision 1.4 2004/02/25 16:24:13 haraldkipp
  101. * DHCP release added
  102. *
  103. * Revision 1.3 2004/01/14 17:51:05 drsung
  104. * Fix for Win2k DHCP server applied. Thanks to Damian Slee
  105. *
  106. * Revision 1.2 2003/08/05 20:20:36 haraldkipp
  107. * Comments added
  108. *
  109. * Revision 1.1.1.1 2003/05/09 14:41:18 haraldkipp
  110. * Initial using 3.2.1
  111. *
  112. * \endverbatim
  113. */
  114. #include <cfg/dhcp.h>
  115. #include <sys/types.h>
  116. #include <stdint.h>
  117. #include <compiler.h> // For NUT_DEPRECATED
  118. /*!
  119. * \addtogroup xgDHCPC
  120. */
  121. /*@{*/
  122. /*!
  123. * \name DHCP Client States.
  124. *
  125. * Applications can request the current state of the DHCP client by
  126. * calling NutDhcpStatus().
  127. */
  128. /*@{*/
  129. /*! \brief DHCP state: Stopped.
  130. *
  131. * Indicates that the DHCP client is inactive. Either it just started,
  132. * gave up the lease or ran into an error. In the latter case the
  133. * application may call NutDhcpError() to retrieve the specific
  134. * error code.
  135. *
  136. * In order to save heap memory, the client will not open the UDP socket
  137. * while inactive.
  138. */
  139. #define DHCPST_IDLE 0
  140. /*! \brief DHCP state: Starting.
  141. *
  142. * Indicates that the DHCP client started to request a configuration from
  143. * the DHCP server. If any previously allocated IP address is available
  144. * in the non-volatile configuration memory, then the client will continue
  145. * with \ref DHCPST_REBOOTING. Otherwise it will move to
  146. * \ref DHCPST_SELECTING.
  147. */
  148. #define DHCPST_INIT 1
  149. /*! \brief DHCP state: Selecting.
  150. *
  151. * In this state the client will transmit a DHCP discover message and
  152. * collect incoming offers from DHCP servers. If at least one acceptable
  153. * offer has been received, it will change to \ref DHCPST_REQUESTING.
  154. */
  155. #define DHCPST_SELECTING 2
  156. /*! \brief DHCP state: Requesting.
  157. *
  158. * Indicates that the client received and selected an offer from a
  159. * DHCP server. It is now sending a request for an offered
  160. * configuration and waiting for an acknowledge, which will change
  161. * the client's state to \ref DHCPST_BOUND.
  162. */
  163. #define DHCPST_REQUESTING 3
  164. /*! \brief DHCP state: Rebooting.
  165. *
  166. * The client enters this state to request a previously assigned
  167. * configuration.
  168. */
  169. #define DHCPST_REBOOTING 4
  170. /*! \brief DHCP state: Bound.
  171. *
  172. * This state indicates, that the DHCP client has successfully allocated
  173. * a network address. Any thread blocked in NutDhcpIfConfig() will be
  174. * woken up.
  175. *
  176. * The client remains in this state until the renewal time elapses, in
  177. * which case it moves to \ref DHCPST_RENEWING.
  178. *
  179. * In order to save heap memory, the client will close the UDP socket
  180. * while in bound state.
  181. */
  182. #define DHCPST_BOUND 5
  183. /*! \brief DHCP state: Renewing.
  184. *
  185. * In this state the client tries to extend its lease by sending
  186. * a request to the DHCP server. If the server responds with an
  187. * acknowledge, the client returns to \ref DHCPST_BOUND.
  188. *
  189. * If no acknowledge is received until the rebind time elapses,
  190. * the client moves to \ref DHCPST_REBINDING.
  191. */
  192. #define DHCPST_RENEWING 6
  193. /*! \brief DHCP state: Rebinding.
  194. *
  195. * The client enters this state after the no acknowledge has been
  196. * received during \ref DHCPST_RENEWING and the rebind time
  197. * elapsed. It will broadcast a request to extend its lease.
  198. *
  199. * If no acknowledge is received until the lease time elapsed,
  200. * the client will move to \ref DHCPST_INIT.
  201. */
  202. #define DHCPST_REBINDING 7
  203. /*! \brief DHCP state: Informing.
  204. *
  205. * The client enters this state when the application calls
  206. * NutDhcpInform().
  207. */
  208. #define DHCPST_INFORMING 8
  209. /*! \brief DHCP state: Releasing.
  210. *
  211. * The client enters this state when the application calls
  212. * NutDhcpRelease().
  213. */
  214. #define DHCPST_RELEASING 9
  215. /*@}*/
  216. /*!
  217. * \name DHCP Error Codes
  218. *
  219. * Applications can request the lastest error code of the DHCP client by
  220. * calling NutDhcpError().
  221. */
  222. /*@{*/
  223. /*!
  224. * \brief DHCP timeout error.
  225. *
  226. * No server response within the specified number of milliseconds. Either
  227. * the timeout value has been too low or no DHCP server is available in
  228. * the local network.
  229. */
  230. #define DHCPERR_TIMEOUT 1
  231. /*!
  232. * \brief DHCP MAC error.
  233. *
  234. * No Ethernet MAC address found in the non-volatile configuration memory
  235. * and none specified by calling NutDhcpIfConfig().
  236. */
  237. #define DHCPERR_NOMAC 2
  238. /*!
  239. * \brief DHCP state error.
  240. *
  241. * Either NutDhcpInform() has been called while not in state
  242. * \ref DHCPST_IDLE or NutDhcpRelease() has been called while not in
  243. * state \ref DHCPST_BOUND.
  244. */
  245. #define DHCPERR_STATE 3
  246. /*!
  247. * \brief DHCP error: Bad device.
  248. *
  249. * The specified device name hasn't been registered or is not an
  250. * Ethernet device.
  251. */
  252. #define DHCPERR_BADDEV 17
  253. /*!
  254. * \brief DHCP system error.
  255. *
  256. * A system error occured during DHCP processing. Most probably the
  257. * system ran out of memory.
  258. */
  259. #define DHCPERR_SYSTEM 18
  260. /*!
  261. * \brief DHCP transmit error.
  262. *
  263. * Failed to send a UDP datagram. The DHCP client considers it a fatal
  264. * error if NutUdpSendTo() to the broadcast address fails.
  265. */
  266. #define DHCPERR_TRANSMIT 19
  267. /*!
  268. * \brief DHCP receive error.
  269. *
  270. * Failed to receive a UDP datagram. The DHCP client considers it a fatal
  271. * error if NutUdpReceiveFrom() fails.
  272. */
  273. #define DHCPERR_RECEIVE 20
  274. /*@}*/
  275. /*@}*/
  276. extern int NutDhcpIfConfig(const char *name, uint8_t * mac, uint32_t timeout);
  277. extern int NutDhcpRelease(const char *name, uint32_t timeout);
  278. extern int NutDhcpInform(const char *name, uint32_t timeout);
  279. extern int NutDhcpStatus(const char *name);
  280. extern int NutDhcpError(const char *name);
  281. extern int NutDhcpIsConfigured(void) NUT_DEPRECATED;
  282. #endif