?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{FILE START}

library

?curdirlinks? - Rev 6

?prevdifflink? - Blame - ?getfile?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>Procyon AVRlib: net/dhcp.h Source File</title>
<link href="dox.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.2 -->
<div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<div class="nav">
<a class="el" href="dir_000001.html">net</a></div>
<h1>dhcp.h</h1><a href="dhcp_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file dhcp.h \brief DHCP Protocol Library. */</span>
00002 <span class="comment">//*****************************************************************************</span>
00003 <span class="comment">//</span>
00004 <span class="comment">// File Name    : 'dhcp.h'</span>
00005 <span class="comment">// Title        : DHCP Protocol Library</span>
00006 <span class="comment">// Author       : Pascal Stang</span>
00007 <span class="comment">// Created      : 9/17/2005</span>
00008 <span class="comment">// Revised      : 9/17/2005</span>
00009 <span class="comment">// Version      : 0.1</span>
00010 <span class="comment">// Target MCU   : Atmel AVR series</span>
00011 <span class="comment">// Editor Tabs  : 4</span>
00012 <span class="comment">//</span><span class="comment"></span>
00013 <span class="comment">/// \ingroup network</span>
00014 <span class="comment">/// \defgroup dhcp DHCP Protocol Library (dhcp.c)</span>
00015 <span class="comment">/// \code #include "net/dhcp.h" \endcode</span>
00016 <span class="comment">/// \par Description</span>
00017 <span class="comment">///     This library provides a limited implementation of DHCP (Dynamic Host</span>
00018 <span class="comment">///     Configuration Protocol) as described in RFC2131.  DHCP allows a</span>
00019 <span class="comment">///     network device to automatically obtain an IP address and other network</span>
00020 <span class="comment">///     configuration settings from a DHCP server.</span>
00021 <span class="comment">///     </span>
00022 <span class="comment">/// \note This code is currently below version 1.0, and therefore is considered</span>
00023 <span class="comment">/// to be lacking in some functionality or documentation, or may not be fully</span>
00024 <span class="comment">/// tested.  Nonetheless, you can expect most functions to work.</span>
00025 <span class="comment">///</span>
00026 <span class="comment"></span><span class="comment">//  This code is distributed under the GNU Public License</span>
00027 <span class="comment">//      which can be found at http://www.gnu.org/licenses/gpl.txt</span>
00028 <span class="comment">//*****************************************************************************</span><span class="comment"></span>
00029 <span class="comment">//@{</span>
00030 <span class="comment"></span>
00031 <span class="preprocessor">#ifndef DHCP_H</span>
00032 <span class="preprocessor"></span><span class="preprocessor">#define DHCP_H</span>
00033 <span class="preprocessor"></span>
00034 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
00035 <span class="preprocessor">#include "<a class="code" href="net_8h.html">net.h</a>"</span>
00036 
00037 <span class="comment">//#define DHCP_DEBUG_PRINT</span>
00038 <span class="comment">//#define DHCP_DEBUG</span>
00039 <span class="comment"></span>
00040 <span class="comment">/// Bootp Header (DHCP is transported by BOOTP/UDP/IP)</span>
<a name="l00041"></a><a class="code" href="structnetBootpHeader.html">00041</a> <span class="comment"></span><span class="keyword">struct </span><a class="code" href="structnetBootpHeader.html">netBootpHeader</a>
00042 {
<a name="l00043"></a><a class="code" href="structnetBootpHeader.html#o0">00043</a>     uint8_t     <a class="code" href="structnetBootpHeader.html#o0">op</a>;         <span class="comment">///&lt; Message op-code / message type</span>
<a name="l00044"></a><a class="code" href="structnetBootpHeader.html#o1">00044</a> <span class="comment"></span>    uint8_t     <a class="code" href="structnetBootpHeader.html#o1">htype</a>;      <span class="comment">///&lt; Hardware address type   (Ethernet=1)</span>
<a name="l00045"></a><a class="code" href="structnetBootpHeader.html#o2">00045</a> <span class="comment"></span>    uint8_t     <a class="code" href="structnetBootpHeader.html#o2">hlen</a>;       <span class="comment">///&lt; Hardware address length (Ethernet=6 byte MAC addr)</span>
<a name="l00046"></a><a class="code" href="structnetBootpHeader.html#o3">00046</a> <span class="comment"></span>    uint8_t     <a class="code" href="structnetBootpHeader.html#o3">hops</a>;       <span class="comment">///&lt; hop count (client set to zero)</span>
<a name="l00047"></a><a class="code" href="structnetBootpHeader.html#o4">00047</a> <span class="comment"></span>    uint32_t    <a class="code" href="structnetBootpHeader.html#o4">xid</a>;        <span class="comment">///&lt; Transaction ID (randomly chosen by client, must remain same)</span>
<a name="l00048"></a><a class="code" href="structnetBootpHeader.html#o5">00048</a> <span class="comment"></span>    uint16_t    <a class="code" href="structnetBootpHeader.html#o5">secs</a>;       <span class="comment">///&lt; Seconds elapsed since DHCP negotiation began (filled by client)</span>
<a name="l00049"></a><a class="code" href="structnetBootpHeader.html#o6">00049</a> <span class="comment"></span>    uint16_t    <a class="code" href="structnetBootpHeader.html#o6">flags</a>;      <span class="comment">///&lt; Flags</span>
<a name="l00050"></a><a class="code" href="structnetBootpHeader.html#o7">00050</a> <span class="comment"></span>    uint32_t    <a class="code" href="structnetBootpHeader.html#o7">ciaddr</a>;     <span class="comment">///&lt; Client IP address (filled only if already bound, renewing, or rebinding)</span>
<a name="l00051"></a><a class="code" href="structnetBootpHeader.html#o8">00051</a> <span class="comment"></span>    uint32_t    <a class="code" href="structnetBootpHeader.html#o8">yiaddr</a>;     <span class="comment">///&lt; 'Your' IP address (client)</span>
<a name="l00052"></a><a class="code" href="structnetBootpHeader.html#o9">00052</a> <span class="comment"></span>    uint32_t    <a class="code" href="structnetBootpHeader.html#o9">siaddr</a>;     <span class="comment">///&lt; Server IP address</span>
<a name="l00053"></a><a class="code" href="structnetBootpHeader.html#o10">00053</a> <span class="comment"></span>    uint32_t    <a class="code" href="structnetBootpHeader.html#o10">giaddr</a>;     <span class="comment">///&lt; Gateway IP address</span>
<a name="l00054"></a><a class="code" href="structnetBootpHeader.html#o11">00054</a> <span class="comment"></span>    uint8_t     <a class="code" href="structnetBootpHeader.html#o11">chaddr</a>[16]; <span class="comment">///&lt; Client Hardware Address</span>
<a name="l00055"></a><a class="code" href="structnetBootpHeader.html#o12">00055</a> <span class="comment"></span>    uint8_t     <a class="code" href="structnetBootpHeader.html#o12">sname</a>[64];  <span class="comment">///&lt; Server Host Name</span>
<a name="l00056"></a><a class="code" href="structnetBootpHeader.html#o13">00056</a> <span class="comment"></span>    uint8_t     <a class="code" href="structnetBootpHeader.html#o13">file</a>[128];  <span class="comment">///&lt; Boot file name (null-term string)</span>
00057 <span class="comment"></span>} <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;
00058 
<a name="l00059"></a><a class="code" href="group__dhcp.html#ga9">00059</a> <span class="preprocessor">#define BOOTP_HEADER_LEN        236 </span><span class="comment">///&lt; length of BOOTP header not including options</span>
00060 <span class="comment"></span>
<a name="l00061"></a><a class="code" href="group__dhcp.html#ga10">00061</a> <span class="preprocessor">#define BOOTP_OP_BOOTREQUEST    1   </span><span class="comment">///&lt; BOOTP Request operation (message from client to server)</span>
<a name="l00062"></a><a class="code" href="group__dhcp.html#ga11">00062</a> <span class="comment"></span>#define BOOTP_OP_BOOTREPLY      2   <span class="comment">///&lt; BOOTP Reply operation (message from server to client)</span>
00063 <span class="comment"></span>
00064 <span class="preprocessor">#define BOOTP_HTYPE_ETHERNET    1</span>
00065 <span class="preprocessor"></span><span class="preprocessor">#define BOOTP_HLEN_ETHERNET     6</span>
00066 <span class="preprocessor"></span><span class="comment"></span>
00067 <span class="comment">/// DHCP Header</span>
<a name="l00068"></a><a class="code" href="structnetDhcpHeader.html">00068</a> <span class="comment"></span><span class="keyword">struct </span><a class="code" href="structnetDhcpHeader.html">netDhcpHeader</a>
00069 {
<a name="l00070"></a><a class="code" href="structnetDhcpHeader.html#o0">00070</a>     <span class="keyword">struct </span><a class="code" href="structnetBootpHeader.html">netBootpHeader</a> bootp;    <span class="comment">///&lt; BOOTP header</span>
<a name="l00071"></a><a class="code" href="structnetDhcpHeader.html#o1">00071</a> <span class="comment"></span>    uint32_t    <a class="code" href="structnetDhcpHeader.html#o1">cookie</a>;             <span class="comment">///&lt; magic cookie value</span>
<a name="l00072"></a><a class="code" href="structnetDhcpHeader.html#o2">00072</a> <span class="comment"></span>    uint8_t     <a class="code" href="structnetDhcpHeader.html#o2">options</a>[];          <span class="comment">///&lt; DHCP options</span>
00073 <span class="comment"></span>} <a class="code" href="group__dhcp.html#ga41">GNUC_PACKED</a>;
00074 
<a name="l00075"></a><a class="code" href="group__dhcp.html#ga14">00075</a> <span class="preprocessor">#define DHCP_HEADER_LEN         240 </span><span class="comment">///&lt; length of DHCP header not including options</span>
00076 <span class="comment"></span>
<a name="l00077"></a><a class="code" href="group__dhcp.html#ga15">00077</a> <span class="preprocessor">#define DHCP_UDP_SERVER_PORT    67  </span><span class="comment">///&lt; UDP port where DHCP requests should be sent</span>
<a name="l00078"></a><a class="code" href="group__dhcp.html#ga16">00078</a> <span class="comment"></span>#define DHCP_UDP_CLIENT_PORT    68  <span class="comment">///&lt; UDP port clients will receive DHCP replies</span>
00079 <span class="comment"></span>
00080 
<a name="l00081"></a><a class="code" href="group__dhcp.html#ga17">00081</a> <span class="preprocessor">#define DHCP_OPT_PAD            0   </span><span class="comment">///&lt; token padding value (make be skipped)</span>
<a name="l00082"></a><a class="code" href="group__dhcp.html#ga18">00082</a> <span class="comment"></span>#define DHCP_OPT_NETMASK        1   <span class="comment">///&lt; subnet mask client should use (4 byte mask)</span>
<a name="l00083"></a><a class="code" href="group__dhcp.html#ga19">00083</a> <span class="comment"></span>#define DHCP_OPT_ROUTERS        3   <span class="comment">///&lt; routers client should use (IP addr list)</span>
<a name="l00084"></a><a class="code" href="group__dhcp.html#ga20">00084</a> <span class="comment"></span>#define DHCP_OPT_TIMESERVERS    4   <span class="comment">///&lt; time servers client should use (IP addr list)</span>
<a name="l00085"></a><a class="code" href="group__dhcp.html#ga21">00085</a> <span class="comment"></span>#define DHCP_OPT_NAMESERVERS    5   <span class="comment">///&lt; name servers client should use (IP addr list)</span>
<a name="l00086"></a><a class="code" href="group__dhcp.html#ga22">00086</a> <span class="comment"></span>#define DHCP_OPT_DNSSERVERS     6   <span class="comment">///&lt; DNS servers client should use (IP addr list)</span>
<a name="l00087"></a><a class="code" href="group__dhcp.html#ga23">00087</a> <span class="comment"></span>#define DHCP_OPT_HOSTNAME       12  <span class="comment">///&lt; host name client should use (string)</span>
<a name="l00088"></a><a class="code" href="group__dhcp.html#ga24">00088</a> <span class="comment"></span>#define DHCP_OPT_DOMAINNAME     15  <span class="comment">///&lt; domain name client should use (string)</span>
<a name="l00089"></a><a class="code" href="group__dhcp.html#ga25">00089</a> <span class="comment"></span>#define DHCP_OPT_REQUESTEDIP    50  <span class="comment">///&lt; IP address requested by client (IP address)</span>
<a name="l00090"></a><a class="code" href="group__dhcp.html#ga26">00090</a> <span class="comment"></span>#define DHCP_OPT_LEASETIME      51  <span class="comment">///&lt; DHCP Lease Time (uint32 seconds)</span>
<a name="l00091"></a><a class="code" href="group__dhcp.html#ga27">00091</a> <span class="comment"></span>#define DHCP_OPT_DHCPMSGTYPE    53  <span class="comment">///&lt; DHCP message type (1 byte)</span>
<a name="l00092"></a><a class="code" href="group__dhcp.html#ga28">00092</a> <span class="comment"></span>#define DHCP_OPT_SERVERID       54  <span class="comment">///&lt; Server Identifier (IP address)</span>
<a name="l00093"></a><a class="code" href="group__dhcp.html#ga29">00093</a> <span class="comment"></span>#define DHCP_OPT_PARAMREQLIST   55  <span class="comment">///&lt; Paramerter Request List (n OPT codes)</span>
<a name="l00094"></a><a class="code" href="group__dhcp.html#ga30">00094</a> <span class="comment"></span>#define DHCP_OPT_RENEWALTIME    58  <span class="comment">///&lt; DHCP Lease Renewal Time (uint32 seconds)</span>
<a name="l00095"></a><a class="code" href="group__dhcp.html#ga31">00095</a> <span class="comment"></span>#define DHCP_OPT_REBINDTIME     59  <span class="comment">///&lt; DHCP Lease Rebinding Time (uint32 seconds)</span>
<a name="l00096"></a><a class="code" href="group__dhcp.html#ga32">00096</a> <span class="comment"></span>#define DHCP_OPT_END            255 <span class="comment">///&lt; token end value (marks end of options list)</span>
00097 <span class="comment"></span>
<a name="l00098"></a><a class="code" href="group__dhcp.html#ga33">00098</a> <span class="preprocessor">#define DHCP_MSG_DHCPDISCOVER   1   </span><span class="comment">///&lt; DISCOVER is broadcast by client to solicit OFFER from any/all DHCP servers.</span>
<a name="l00099"></a><a class="code" href="group__dhcp.html#ga34">00099</a> <span class="comment"></span>#define DHCP_MSG_DHCPOFFER      2   <span class="comment">///&lt; OFFER(s) are made to client by server to offer IP address and config info.</span>
<a name="l00100"></a><a class="code" href="group__dhcp.html#ga35">00100</a> <span class="comment"></span>#define DHCP_MSG_DHCPREQUEST    3   <span class="comment">///&lt; REQUEST is made my client in response to best/favorite OFFER message.</span>
<a name="l00101"></a><a class="code" href="group__dhcp.html#ga36">00101</a> <span class="comment"></span>#define DHCP_MSG_DHCPDECLINE    4   <span class="comment">///&lt; DECLINE may be sent by client to server to indicate IP already in use.</span>
<a name="l00102"></a><a class="code" href="group__dhcp.html#ga37">00102</a> <span class="comment"></span>#define DHCP_MSG_DHCPACK        5   <span class="comment">///&lt; ACK is sent to client by server in confirmation of REQUEST, contains config and IP.</span>
<a name="l00103"></a><a class="code" href="group__dhcp.html#ga38">00103</a> <span class="comment"></span>#define DHCP_MSG_DHCPNAK        6   <span class="comment">///&lt; NAK is sent to client by server to indicate problem with REQUEST.</span>
<a name="l00104"></a><a class="code" href="group__dhcp.html#ga39">00104</a> <span class="comment"></span>#define DHCP_MSG_DHCPRELEASE    7   <span class="comment">///&lt; RELEASE is sent by client to server to relinquish DHCP lease on IP address, etc.</span>
<a name="l00105"></a><a class="code" href="group__dhcp.html#ga40">00105</a> <span class="comment"></span>#define DHCP_MSG_DHCPINFORM     8   <span class="comment">///&lt; INFORM is sent by client to server to request config info, IP address configured locally.</span>
00106 <span class="comment"></span>
00107 <span class="comment"></span>
00108 <span class="comment">/*! Initialize DHCP system.</span>
00109 <span class="comment">    Prepares DHCP for use and initializes lease time to zero. */</span>
00110 <span class="keywordtype">void</span> <a class="code" href="group__dhcp.html#ga1">dhcpInit</a>(<span class="keywordtype">void</span>);
00111 <span class="comment"></span>
00112 <span class="comment">/*! Processes incoming DHCP packets from UDP port 68.</span>
00113 <span class="comment">    This function is to be called by the stack when a DHCP packet</span>
00114 <span class="comment">    arrives over the network.  The DHCP packet will be parsed, handled,</span>
00115 <span class="comment">    and a response will be generated and sent if needed.  When the DHCP</span>
00116 <span class="comment">    process completes, the IP addressing will be automatically updated. */</span>
00117 <span class="keywordtype">void</span> <a class="code" href="group__dhcp.html#ga2">dhcpIn</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len, <span class="keyword">struct</span> <a class="code" href="structnetDhcpHeader.html">netDhcpHeader</a>* packet);
00118 <span class="comment"></span>
00119 <span class="comment">/*! Request DHCP assigned network parameters.</span>
00120 <span class="comment">    This function begins the DHCP process.  The remainder of operations</span>
00121 <span class="comment">    are handled in dhcpIn(). */</span>
00122 <span class="keywordtype">void</span> <a class="code" href="group__dhcp.html#ga3">dhcpRequest</a>(<span class="keywordtype">void</span>);
00123 <span class="comment"></span>
00124 <span class="comment">/*! Release DHCP lease and assigned network parameters.</span>
00125 <span class="comment">    This function releases the DHCP assigned address and allows the</span>
00126 <span class="comment">    DHCP server to reallocate it. */</span>
00127 <span class="keywordtype">void</span> <a class="code" href="group__dhcp.html#ga4">dhcpRelease</a>(<span class="keywordtype">void</span>);
00128 <span class="comment"></span>
00129 <span class="comment">/*! Periodic DHCP maintenance.</span>
00130 <span class="comment">    This function is to be called once per second and will </span>
00131 <span class="comment">    expire the DHCP lease. */</span>
00132 <span class="keywordtype">void</span> <a class="code" href="group__dhcp.html#ga5">dhcpTimer</a>(<span class="keywordtype">void</span>);
00133 <span class="comment"></span>
00134 <span class="comment">/*! Get a DHCP option from the option list.</span>
00135 <span class="comment">    \param options is a pointer to the options field of a DHCP packet.</span>
00136 <span class="comment">    \param optcode is the desired option number to retrieve.</span>
00137 <span class="comment">    \param optlen is the maximum data length that should be retrieved (less data will be retrieved if option is shorter).</span>
00138 <span class="comment">    \param optvalptr is a pointer to where the option value will be stored.</span>
00139 <span class="comment">    \return actual length of the option data, as stored in the options list. */</span>
00140 uint8_t <a class="code" href="group__dhcp.html#ga6">dhcpGetOption</a>(uint8_t* options, uint8_t optcode, uint8_t optlen, <span class="keywordtype">void</span>* optvalptr);
00141 <span class="comment"></span>
00142 <span class="comment">/*! Set a DHCP option in the option list.</span>
00143 <span class="comment">    \param options is a pointer to the options field of a DHCP packet.</span>
00144 <span class="comment">    \param optcode is the option number to write.</span>
00145 <span class="comment">    \param optlen is the data length of the option value.</span>
00146 <span class="comment">    \param optvalptr is a pointer to the option data to be read.</span>
00147 <span class="comment">    \return pointer to write location of the next option. */</span>
00148 uint8_t* <a class="code" href="group__dhcp.html#ga7">dhcpSetOption</a>(uint8_t* options, uint8_t optcode, uint8_t optlen, <span class="keywordtype">void</span>* optvalptr);
00149 <span class="comment"></span>
00150 <span class="comment">/*! Print diagnotic information about BOOTP/DHCP packet.</span>
00151 <span class="comment">*/</span>
00152 <span class="keywordtype">void</span> <a class="code" href="group__dhcp.html#ga8">dhcpPrintHeader</a>(<span class="keyword">struct</span> <a class="code" href="structnetDhcpHeader.html">netDhcpHeader</a>* packet);
00153 
00154 <span class="preprocessor">#endif</span>
00155 <span class="preprocessor"></span><span class="comment">//@}</span>
00156 <span class="comment"></span>
</pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
</body>
</html>
{FILE END}
{FOOTER START}

Powered by WebSVN v2.8.3