DHCP.h

Go to the documentation of this file.
00001 
00002 
00003 
00035 /*********************************************************************
00036  * Software License Agreement
00037  *
00038  * Copyright (C) 2002-2008 Microchip Technology Inc.  All rights 
00039  * reserved.
00040  *
00041  * Microchip licenses to you the right to use, modify, copy, and 
00042  * distribute: 
00043  * (i)  the Software when embedded on a Microchip microcontroller or 
00044  *      digital signal controller product ("Device") which is 
00045  *      integrated into Licensee's product; or
00046  * (ii) ONLY the Software driver source files ENC28J60.c and 
00047  *      ENC28J60.h ported to a non-Microchip device used in 
00048  *      conjunction with a Microchip ethernet controller for the 
00049  *      sole purpose of interfacing with the ethernet controller. 
00050  *
00051  * You should refer to the license agreement accompanying this 
00052  * Software for additional information regarding your rights and 
00053  * obligations.
00054  *
00055  * THE SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT 
00056  * WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT 
00057  * LIMITATION, ANY WARRANTY OF MERCHANTABILITY, FITNESS FOR A 
00058  * PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL 
00059  * MICROCHIP BE LIABLE FOR ANY INCIDENTAL, SPECIAL, INDIRECT OR 
00060  * CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF 
00061  * PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, ANY CLAIMS 
00062  * BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO ANY DEFENSE 
00063  * THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, OR OTHER 
00064  * SIMILAR COSTS, WHETHER ASSERTED ON THE BASIS OF CONTRACT, TORT 
00065  * (INCLUDING NEGLIGENCE), BREACH OF WARRANTY, OR OTHERWISE.
00066  *
00067  *
00068  * Author               Date    Comment
00069  *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00070  * Nilesh Rajbharti     3/21/01  Original        (Rev 1.0)
00071  ********************************************************************/
00072 #ifndef __DHCP_H
00073 #define __DHCP_H
00074 
00075 // UDP client port for DHCP Client transactions
00076 #define DHCP_CLIENT_PORT                (68u)
00077 // UDP listening port for DHCP Server messages
00078 #define DHCP_SERVER_PORT                (67u)
00079 
00080 #define BOOT_REQUEST                    (1u)    // BOOT_REQUEST DHCP type
00081 #define BOOT_REPLY                      (2u)    // BOOT_REPLY DHCP type
00082 #define BOOT_HW_TYPE                    (1u)    // BOOT_HW_TYPE DHCP type
00083 #define BOOT_LEN_OF_HW_TYPE             (6u)    // BOOT_LEN_OF_HW_TYPE DHCP type
00084 
00085 #define DHCP_MESSAGE_TYPE               (53u)   // DHCP Message Type constant
00086 #define DHCP_MESSAGE_TYPE_LEN           (1u)    // Length of DHCP Message Type
00087 
00088 #define DHCP_UNKNOWN_MESSAGE            (0u)    // Code for unknown DHCP message
00089 
00090 #define DHCP_DISCOVER_MESSAGE           (1u)    // DCHP Discover Message
00091 #define DHCP_OFFER_MESSAGE              (2u)    // DHCP Offer Message
00092 #define DHCP_REQUEST_MESSAGE            (3u)    // DHCP Request message
00093 #define DHCP_DECLINE_MESSAGE            (4u)    // DHCP Decline Message
00094 #define DHCP_ACK_MESSAGE                (5u)    // DHCP ACK Message
00095 #define DHCP_NAK_MESSAGE                (6u)    // DHCP NAK Message
00096 #define DHCP_RELEASE_MESSAGE            (7u)    // DCHP Release message
00097 
00098 #define DHCP_SERVER_IDENTIFIER          (54u)   // DHCP Server Identifier
00099 #define DHCP_SERVER_IDENTIFIER_LEN      (4u)    // DHCP Server Identifier length
00100 
00101 #define DHCP_OPTION_ACK_MESSAGE         (53u)   // DHCP_OPTION_ACK_MESSAGE Type
00102 #define DHCP_PARAM_REQUEST_LIST         (55u)   // DHCP_PARAM_REQUEST_LIST Type
00103 #define DHCP_PARAM_REQUEST_LIST_LEN     (4u)    // DHCP_PARAM_REQUEST_LIST_LEN Type
00104 #define DHCP_PARAM_REQUEST_IP_ADDRESS       (50u)   // DHCP_PARAM_REQUEST_IP_ADDRESS Type
00105 #define DHCP_PARAM_REQUEST_IP_ADDRESS_LEN   (4u)    // DHCP_PARAM_REQUEST_IP_ADDRESS_LEN Type
00106 #define DHCP_SUBNET_MASK                (1u)    // DHCP_SUBNET_MASK Type
00107 #define DHCP_ROUTER                     (3u)    // DHCP_ROUTER Type
00108 #define DHCP_DNS                        (6u)    // DHCP_DNS Type
00109 #define DHCP_HOST_NAME                  (12u)   // DHCP_HOST_NAME Type
00110 #define DHCP_IP_LEASE_TIME              (51u)   // DHCP_IP_LEASE_TIME Type
00111 #define DHCP_END_OPTION                 (255u)  // DHCP_END_OPTION Type
00112 
00113 // DHCP or BOOTP Header structure
00114 typedef struct __attribute__((aligned(2), packed))
00115 {
00116     BYTE        MessageType;    // Message type for this message
00117     BYTE        HardwareType;   // Hardware type for this message
00118     BYTE        HardwareLen;    // Length of hardware type
00119     BYTE        Hops;           // Number of hops
00120     DWORD       TransactionID;  // DHCP Transaction ID
00121     WORD        SecondsElapsed; // Number of elapsed seconds
00122     WORD        BootpFlags;     // BOOTP Flags
00123     IP_ADDR     ClientIP;       // Client IP
00124     IP_ADDR     YourIP;         // Your IP
00125     IP_ADDR     NextServerIP;   // Next Server IP
00126     IP_ADDR     RelayAgentIP;   // Relay Agent IP
00127     MAC_ADDR    ClientMAC;      // Client MAC Address
00128 } BOOTP_HEADER;
00129 
00130 // DHCP State Machine
00131 typedef enum _SM_DHCP
00132 {
00133     SM_DHCP_DISABLED = 0,       // DHCP is not currently enabled
00134     SM_DHCP_GET_SOCKET,         // DHCP is trying to obtain a socket
00135     SM_DHCP_AUTOIP,             // MODIFIX: DHCP checks for a Auto IP
00136     SM_DHCP_SEND_DISCOVERY,     // DHCP is sending a DHCP Discover message
00137     SM_DHCP_GET_OFFER,          // DHCP is waiting for a DHCP Offer
00138     SM_DHCP_SEND_REQUEST,       // DHCP is sending a DHCP Send Reequest message
00139     SM_DHCP_GET_REQUEST_ACK,    // DCHP is waiting for a Request ACK message
00140     SM_DHCP_BOUND,              // DHCP is bound
00141     SM_DHCP_SEND_RENEW,         // DHCP is sending a DHCP renew message (first try)
00142     SM_DHCP_GET_RENEW_ACK,      // DHCP is waiting for a renew ACK
00143     SM_DHCP_SEND_RENEW2,        // DHCP is sending a DHCP renew message (second try)
00144     SM_DHCP_GET_RENEW_ACK2,     // DHCP is waiting for a renew ACK
00145     SM_DHCP_SEND_RENEW3,        // DHCP is sending a DHCP renew message (third try)
00146     SM_DHCP_GET_RENEW_ACK3      // DHCP is waiting for a renew ACK
00147 } SM_DHCP;
00148 
00149 
00150 // Flags for the DHCP client
00151 typedef union _DHCP_CLIENT_FLAGS
00152 {
00153     struct
00154     {
00155         unsigned char bIsBound : 1;             // Whether or not DHCP is currently bound
00156         unsigned char bOfferReceived : 1;       // Whether or not an offer has been received
00157         unsigned char bDHCPServerDetected : 1;  // Indicates if a DCHP server has been detected
00158     } bits;
00159     BYTE Val;
00160 } DHCP_CLIENT_FLAGS;
00161 
00163 #if !defined(__DHCP_C)
00164     extern DHCP_CLIENT_FLAGS DHCPFlags;
00165     extern SM_DHCP smDHCPState;
00166     extern BYTE DHCPBindCount;
00167 #endif
00168 
00170 
00186 void DHCPReset( BOOL bNoAutoIP );
00187 
00188 
00190 
00208 void DHCPTask(void);
00209 
00210 
00211 // MODIFIX: ServerTask is not needed for eWicht: void DHCPServerTask(void);
00212 
00214 
00234 void DHCPDisable(void);
00235 
00236 
00238 
00250 void DHCPEnable(void);
00251 
00252 
00254 
00265 IP_ADDR GenerateAutoIP( IP_ADDR * lastIP );
00266 
00267 
00269 
00279 #define DHCPIsBound()       (DHCPFlags.bits.bIsBound)
00280 
00281 #endif

Generated on Sun Nov 27 20:02:38 2011 for eWicht by  doxygen 1.5.5