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

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik /*! \file dhcp.h \brief DHCP Protocol Library. */
2 //*****************************************************************************
3 //
4 // File Name : 'dhcp.h'
5 // Title : DHCP Protocol Library
6 // Author : Pascal Stang
7 // Created : 9/17/2005
8 // Revised : 9/17/2005
9 // Version : 0.1
10 // Target MCU : Atmel AVR series
11 // Editor Tabs : 4
12 //
13 /// \ingroup network
14 /// \defgroup dhcp DHCP Protocol Library (dhcp.c)
15 /// \code #include "net/dhcp.h" \endcode
16 /// \par Description
17 /// This library provides a limited implementation of DHCP (Dynamic Host
18 /// Configuration Protocol) as described in RFC2131. DHCP allows a
19 /// network device to automatically obtain an IP address and other network
20 /// configuration settings from a DHCP server.
21 ///
22 /// \note This code is currently below version 1.0, and therefore is considered
23 /// to be lacking in some functionality or documentation, or may not be fully
24 /// tested. Nonetheless, you can expect most functions to work.
25 ///
26 // This code is distributed under the GNU Public License
27 // which can be found at http://www.gnu.org/licenses/gpl.txt
28 //*****************************************************************************
29 //@{
30  
31 #ifndef DHCP_H
32 #define DHCP_H
33  
34 #include "global.h"
35 #include "net.h"
36  
37 //#define DHCP_DEBUG_PRINT
38 //#define DHCP_DEBUG
39  
40 /// Bootp Header (DHCP is transported by BOOTP/UDP/IP)
41 struct netBootpHeader
42 {
43 uint8_t op; ///< Message op-code / message type
44 uint8_t htype; ///< Hardware address type (Ethernet=1)
45 uint8_t hlen; ///< Hardware address length (Ethernet=6 byte MAC addr)
46 uint8_t hops; ///< hop count (client set to zero)
47 uint32_t xid; ///< Transaction ID (randomly chosen by client, must remain same)
48 uint16_t secs; ///< Seconds elapsed since DHCP negotiation began (filled by client)
49 uint16_t flags; ///< Flags
50 uint32_t ciaddr; ///< Client IP address (filled only if already bound, renewing, or rebinding)
51 uint32_t yiaddr; ///< 'Your' IP address (client)
52 uint32_t siaddr; ///< Server IP address
53 uint32_t giaddr; ///< Gateway IP address
54 uint8_t chaddr[16]; ///< Client Hardware Address
55 uint8_t sname[64]; ///< Server Host Name
56 uint8_t file[128]; ///< Boot file name (null-term string)
57 } GNUC_PACKED;
58  
59 #define BOOTP_HEADER_LEN 236 ///< length of BOOTP header not including options
60  
61 #define BOOTP_OP_BOOTREQUEST 1 ///< BOOTP Request operation (message from client to server)
62 #define BOOTP_OP_BOOTREPLY 2 ///< BOOTP Reply operation (message from server to client)
63  
64 #define BOOTP_HTYPE_ETHERNET 1
65 #define BOOTP_HLEN_ETHERNET 6
66  
67 /// DHCP Header
68 struct netDhcpHeader
69 {
70 struct netBootpHeader bootp; ///< BOOTP header
71 uint32_t cookie; ///< magic cookie value
72 uint8_t options[]; ///< DHCP options
73 } GNUC_PACKED;
74  
75 #define DHCP_HEADER_LEN 240 ///< length of DHCP header not including options
76  
77 #define DHCP_UDP_SERVER_PORT 67 ///< UDP port where DHCP requests should be sent
78 #define DHCP_UDP_CLIENT_PORT 68 ///< UDP port clients will receive DHCP replies
79  
80  
81 #define DHCP_OPT_PAD 0 ///< token padding value (make be skipped)
82 #define DHCP_OPT_NETMASK 1 ///< subnet mask client should use (4 byte mask)
83 #define DHCP_OPT_ROUTERS 3 ///< routers client should use (IP addr list)
84 #define DHCP_OPT_TIMESERVERS 4 ///< time servers client should use (IP addr list)
85 #define DHCP_OPT_NAMESERVERS 5 ///< name servers client should use (IP addr list)
86 #define DHCP_OPT_DNSSERVERS 6 ///< DNS servers client should use (IP addr list)
87 #define DHCP_OPT_HOSTNAME 12 ///< host name client should use (string)
88 #define DHCP_OPT_DOMAINNAME 15 ///< domain name client should use (string)
89 #define DHCP_OPT_REQUESTEDIP 50 ///< IP address requested by client (IP address)
90 #define DHCP_OPT_LEASETIME 51 ///< DHCP Lease Time (uint32 seconds)
91 #define DHCP_OPT_DHCPMSGTYPE 53 ///< DHCP message type (1 byte)
92 #define DHCP_OPT_SERVERID 54 ///< Server Identifier (IP address)
93 #define DHCP_OPT_PARAMREQLIST 55 ///< Paramerter Request List (n OPT codes)
94 #define DHCP_OPT_RENEWALTIME 58 ///< DHCP Lease Renewal Time (uint32 seconds)
95 #define DHCP_OPT_REBINDTIME 59 ///< DHCP Lease Rebinding Time (uint32 seconds)
96 #define DHCP_OPT_END 255 ///< token end value (marks end of options list)
97  
98 #define DHCP_MSG_DHCPDISCOVER 1 ///< DISCOVER is broadcast by client to solicit OFFER from any/all DHCP servers.
99 #define DHCP_MSG_DHCPOFFER 2 ///< OFFER(s) are made to client by server to offer IP address and config info.
100 #define DHCP_MSG_DHCPREQUEST 3 ///< REQUEST is made my client in response to best/favorite OFFER message.
101 #define DHCP_MSG_DHCPDECLINE 4 ///< DECLINE may be sent by client to server to indicate IP already in use.
102 #define DHCP_MSG_DHCPACK 5 ///< ACK is sent to client by server in confirmation of REQUEST, contains config and IP.
103 #define DHCP_MSG_DHCPNAK 6 ///< NAK is sent to client by server to indicate problem with REQUEST.
104 #define DHCP_MSG_DHCPRELEASE 7 ///< RELEASE is sent by client to server to relinquish DHCP lease on IP address, etc.
105 #define DHCP_MSG_DHCPINFORM 8 ///< INFORM is sent by client to server to request config info, IP address configured locally.
106  
107  
108 /*! Initialize DHCP system.
109 Prepares DHCP for use and initializes lease time to zero. */
110 void dhcpInit(void);
111  
112 /*! Processes incoming DHCP packets from UDP port 68.
113 This function is to be called by the stack when a DHCP packet
114 arrives over the network. The DHCP packet will be parsed, handled,
115 and a response will be generated and sent if needed. When the DHCP
116 process completes, the IP addressing will be automatically updated. */
117 void dhcpIn(unsigned int len, struct netDhcpHeader* packet);
118  
119 /*! Request DHCP assigned network parameters.
120 This function begins the DHCP process. The remainder of operations
121 are handled in dhcpIn(). */
122 void dhcpRequest(void);
123  
124 /*! Release DHCP lease and assigned network parameters.
125 This function releases the DHCP assigned address and allows the
126 DHCP server to reallocate it. */
127 void dhcpRelease(void);
128  
129 /*! Periodic DHCP maintenance.
130 This function is to be called once per second and will
131 expire the DHCP lease. */
132 void dhcpTimer(void);
133  
134 /*! Get a DHCP option from the option list.
135 \param options is a pointer to the options field of a DHCP packet.
136 \param optcode is the desired option number to retrieve.
137 \param optlen is the maximum data length that should be retrieved (less data will be retrieved if option is shorter).
138 \param optvalptr is a pointer to where the option value will be stored.
139 \return actual length of the option data, as stored in the options list. */
140 uint8_t dhcpGetOption(uint8_t* options, uint8_t optcode, uint8_t optlen, void* optvalptr);
141  
142 /*! Set a DHCP option in the option list.
143 \param options is a pointer to the options field of a DHCP packet.
144 \param optcode is the option number to write.
145 \param optlen is the data length of the option value.
146 \param optvalptr is a pointer to the option data to be read.
147 \return pointer to write location of the next option. */
148 uint8_t* dhcpSetOption(uint8_t* options, uint8_t optcode, uint8_t optlen, void* optvalptr);
149  
150 /*! Print diagnotic information about BOOTP/DHCP packet.
151 */
152 void dhcpPrintHeader(struct netDhcpHeader* packet);
153  
154 #endif
155 //@}
156  
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3