dhcp.h 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  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 EGNITE SOFTWARE GMBH 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 EGNITE
  23. * SOFTWARE GMBH 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: dhcp.h,v $
  69. * Revision 1.9 2006/10/08 16:48:22 haraldkipp
  70. * Documentation fixed
  71. *
  72. * Revision 1.8 2005/08/02 17:46:49 haraldkipp
  73. * Major API documentation update.
  74. *
  75. * Revision 1.7 2005/02/03 14:34:05 haraldkipp
  76. * Several bug fixes and enhancements. The most important fix will
  77. * avoid hanging, when Ethernut is reset while ICMP pings are
  78. * received. A large number of changes make the client to follow
  79. * RFC 2131 more closely, like maintaining renewal and rebind time.
  80. * Two new API calls, NutDhcpStatus() and NutDhcpError(), allow
  81. * to query the current status of the DHCP client. The previously
  82. * introduced API call NutDhcpIsConfigured() has been marked
  83. * deprecated. Another problem was with timeout, because the client
  84. * continued negotiation with the server after the timeout time
  85. * given in the API called elapsed. Now all internal timeouts are
  86. * adjusted to the API timeout. Furthermore the previous version
  87. * let the client continue on fatal errors like UDP receive or UDP
  88. * broadcast failures. Now the client stops on such errors and
  89. * informs the caller. Finally the documentation has been enhanced.
  90. *
  91. * Revision 1.6 2004/12/31 10:52:18 drsung
  92. * Bugfixes from Michel Hendriks applied.
  93. *
  94. * Revision 1.5 2004/03/18 11:22:03 haraldkipp
  95. * Deprecated functions removed
  96. *
  97. * Revision 1.4 2004/02/25 16:24:13 haraldkipp
  98. * DHCP release added
  99. *
  100. * Revision 1.3 2004/01/14 17:51:05 drsung
  101. * Fix for Win2k DHCP server applied. Thanks to Damian Slee
  102. *
  103. * Revision 1.2 2003/08/05 20:20:36 haraldkipp
  104. * Comments added
  105. *
  106. * Revision 1.1.1.1 2003/05/09 14:41:18 haraldkipp
  107. * Initial using 3.2.1
  108. *
  109. * \endverbatim
  110. */
  111. #include <cfg/dhcp.h>
  112. #include <sys/types.h>
  113. /*!
  114. * \addtogroup xgDHCPC
  115. */
  116. /*@{*/
  117. /*!
  118. * \name DHCP Client States.
  119. *
  120. * Applications can request the current state of the DHCP client by
  121. * calling NutDhcpStatus().
  122. */
  123. /*@{*/
  124. /*! \brief DHCP state: Stopped.
  125. *
  126. * Indicates that the DHCP client is inactive. Either it just started,
  127. * gave up the lease or ran into an error. In the latter case the
  128. * application may call NutDhcpError() to retrieve the specific
  129. * error code.
  130. *
  131. * In order to save heap memory, the client will not open the UDP socket
  132. * while inactive.
  133. */
  134. #define DHCPST_IDLE 0
  135. /*! \brief DHCP state: Starting.
  136. *
  137. * Indicates that the DHCP client started to request a configuration from
  138. * the DHCP server. If any previously allocated IP address is available
  139. * in the non-volatile configuration memory, then the client will continue
  140. * with \ref DHCPST_REBOOTING. Otherwise it will move to
  141. * \ref DHCPST_SELECTING.
  142. */
  143. #define DHCPST_INIT 1
  144. /*! \brief DHCP state: Selecting.
  145. *
  146. * In this state the client will transmit a DHCP discover message and
  147. * collect incoming offers from DHCP servers. If at least one acceptable
  148. * offer has been received, it will change to \ref DHCPST_REQUESTING.
  149. */
  150. #define DHCPST_SELECTING 2
  151. /*! \brief DHCP state: Requesting.
  152. *
  153. * Indicates that the client received and selected an offer from a
  154. * DHCP server. It is now sending a request for an offered
  155. * configuration and waiting for an acknowledge, which will change
  156. * the client's state to \ref DHCPST_BOUND.
  157. */
  158. #define DHCPST_REQUESTING 3
  159. /*! \brief DHCP state: Rebooting.
  160. *
  161. * The client enters this state to request a previously assigned
  162. * configuration.
  163. */
  164. #define DHCPST_REBOOTING 4
  165. /*! \brief DHCP state: Bound.
  166. *
  167. * This state indicates, that the DHCP client has successfully allocated
  168. * a network address. Any thread blocked in NutDhcpIfConfig() will be
  169. * woken up.
  170. *
  171. * The client remains in this state until the renewal time elapses, in
  172. * which case it moves to \ref DHCPST_RENEWING.
  173. *
  174. * In order to save heap memory, the client will close the UDP socket
  175. * while in bound state.
  176. */
  177. #define DHCPST_BOUND 5
  178. /*! \brief DHCP state: Renewing.
  179. *
  180. * In this state the client tries to extend its lease by sending
  181. * a request to the DHCP server. If the server responds with an
  182. * acknowledge, the client returns to \ref DHCPST_BOUND.
  183. *
  184. * If no acknowledge is received until the rebind time elapses,
  185. * the client moves to \ref DHCPST_REBINDING.
  186. */
  187. #define DHCPST_RENEWING 6
  188. /*! \brief DHCP state: Rebinding.
  189. *
  190. * The client enters this state after the no acknowledge has been
  191. * received during \ref DHCPST_RENEWING and the rebind time
  192. * elapsed. It will broadcast a request to extend its lease.
  193. *
  194. * If no acknowledge is received until the lease time elapsed,
  195. * the client will move to \ref DHCPST_INIT.
  196. */
  197. #define DHCPST_REBINDING 7
  198. /*! \brief DHCP state: Informing.
  199. *
  200. * The client enters this state when the application calls
  201. * NutDhcpInform().
  202. */
  203. #define DHCPST_INFORMING 8
  204. /*! \brief DHCP state: Releasing.
  205. *
  206. * The client enters this state when the application calls
  207. * NutDhcpRelease().
  208. */
  209. #define DHCPST_RELEASING 9
  210. /*@}*/
  211. /*!
  212. * \name DHCP Error Codes
  213. *
  214. * Applications can request the lastest error code of the DHCP client by
  215. * calling NutDhcpError().
  216. */
  217. /*@{*/
  218. /*!
  219. * \brief DHCP timeout error.
  220. *
  221. * No server response within the specified number of milliseconds. Either
  222. * the timeout value has been too low or no DHCP server is available in
  223. * the local network.
  224. */
  225. #define DHCPERR_TIMEOUT 1
  226. /*!
  227. * \brief DHCP MAC error.
  228. *
  229. * No Ethernet MAC address found in the non-volatile configuration memory
  230. * and none specified by calling NutDhcpIfConfig().
  231. */
  232. #define DHCPERR_NOMAC 2
  233. /*!
  234. * \brief DHCP state error.
  235. *
  236. * Either NutDhcpInform() has been called while not in state
  237. * \ref DHCPST_IDLE or NutDhcpRelease() has been called while not in
  238. * state \ref DHCPST_BOUND.
  239. */
  240. #define DHCPERR_STATE 3
  241. /*!
  242. * \brief DHCP error: Bad device.
  243. *
  244. * The specified device name hasn't been registered or is not an
  245. * Ethernet device.
  246. */
  247. #define DHCPERR_BADDEV 17
  248. /*!
  249. * \brief DHCP system error.
  250. *
  251. * A system error occured during DHCP processing. Most probably the
  252. * system ran out of memory.
  253. */
  254. #define DHCPERR_SYSTEM 18
  255. /*!
  256. * \brief DHCP transmit error.
  257. *
  258. * Failed to send a UDP datagram. The DHCP client considers it a fatal
  259. * error if NutUdpSendTo() to the broadcast address fails.
  260. */
  261. #define DHCPERR_TRANSMIT 19
  262. /*!
  263. * \brief DHCP receive error.
  264. *
  265. * Failed to receive a UDP datagram. The DHCP client considers it a fatal
  266. * error if NutUdpReceiveFrom() fails.
  267. */
  268. #define DHCPERR_RECEIVE 20
  269. /*@}*/
  270. /*@}*/
  271. __BEGIN_DECLS
  272. /* Function prototypes. */
  273. extern int NutDhcpIfConfig(CONST char *name, u_char * mac, u_long timeout);
  274. extern int NutDhcpRelease(CONST char *name, u_long timeout);
  275. extern int NutDhcpInform(CONST char *name, u_long timeout);
  276. extern int NutDhcpStatus(CONST char *name);
  277. extern int NutDhcpError(CONST char *name);
  278. extern int NutDhcpIsConfigured(void);
  279. __END_DECLS
  280. /* */
  281. #endif