3      Copyright (C) Dean Camera, 2010. 
   5   dean [at] fourwalledcubicle [dot] com 
   6       www.fourwalledcubicle.com 
  10   Copyright 2010  Dean Camera (dean [at] fourwalledcubicle [dot] com) 
  12   Permission to use, copy, modify, distribute, and sell this  
  13   software and its documentation for any purpose is hereby granted 
  14   without fee, provided that the above copyright notice appear in  
  15   all copies and that both that the copyright notice and this 
  16   permission notice and warranty disclaimer appear in supporting  
  17   documentation, and that the name of the author not be used in  
  18   advertising or publicity pertaining to distribution of the  
  19   software without specific, written prior permission. 
  21   The author disclaim all warranties with regard to this 
  22   software, including all implied warranties of merchantability 
  23   and fitness.  In no event shall the author be liable for any 
  24   special, indirect or consequential damages or any damages 
  25   whatsoever resulting from loss of use, data or profits, whether 
  26   in an action of contract, negligence or other tortious action, 
  27   arising out of or in connection with the use or performance of 
  33  *  Header file for DHCPClientApp.c. 
  36 #ifndef _DHCPCLIENT_APP_H_ 
  37 #define _DHCPCLIENT_APP_H_ 
  44                 #include "../Webserver.h" 
  47                 /** UDP listen port for a BOOTP server */ 
  48                 #define DHCPC_SERVER_PORT         67 
  50                 /** UDP listen port for a BOOTP client */ 
  51                 #define DHCPC_CLIENT_PORT         68 
  53                 /** BOOTP message type for a BOOTP REQUEST message */ 
  54                 #define DHCP_OP_BOOTREQUEST       0x01 
  56                 /** BOOTP message type for a BOOTP REPLY message */ 
  57                 #define DHCP_OP_BOOTREPLY         0x02 
  59                 /** BOOTP flag for a BOOTP broadcast message */ 
  60                 #define BOOTP_BROADCAST           0x8000 
  62                 /** Magic DHCP cookie for a BOOTP message to identify it as a DHCP message */ 
  63                 #define DHCP_MAGIC_COOKIE         0x63538263 
  65                 /** Unique transaction ID used to identify DHCP responses to the client */ 
  66                 #define DHCP_TRANSACTION_ID       0x13245466 
  68                 /** DHCP message type for a DISCOVER message */ 
  69                 #define DHCP_DISCOVER             1 
  71                 /** DHCP message type for an OFFER message */ 
  74                 /** DHCP message type for a REQUEST message */ 
  75                 #define DHCP_REQUEST              3 
  77                 /** DHCP message type for a DECLINE message */ 
  78                 #define DHCP_DECLINE              4 
  80                 /** DHCP message type for an ACK message */ 
  83                 /** DHCP message type for a NAK message */ 
  86                 /** DHCP message type for a RELEASE message */ 
  87                 #define DHCP_RELEASE              7 
  89                 /** DHCP medium type for standard Ethernet */ 
  90                 #define DHCP_HTYPE_ETHERNET       1 
  92                 /** DHCP message option for the network subnet mask */ 
  93                 #define DHCP_OPTION_SUBNET_MASK   1 
  95                 /** DHCP message option for the network gateway IP */ 
  96                 #define DHCP_OPTION_ROUTER        3 
  98                 /** DHCP message option for the network DNS server */ 
  99                 #define DHCP_OPTION_DNS_SERVER    6 
 101                 /** DHCP message option for the requested client IP address */ 
 102                 #define DHCP_OPTION_REQ_IPADDR    50 
 104                 /** DHCP message option for the IP address lease time */ 
 105                 #define DHCP_OPTION_LEASE_TIME    51 
 107                 /** DHCP message option for the DHCP message type */ 
 108                 #define DHCP_OPTION_MSG_TYPE      53 
 110                 /** DHCP message option for the DHCP server IP */                
 111                 #define DHCP_OPTION_SERVER_ID     54 
 113                 /** DHCP message option for the list of required options from the server */ 
 114                 #define DHCP_OPTION_REQ_LIST      55 
 116                 /** DHCP message option for the options list terminator */ 
 117                 #define DHCP_OPTION_END           255 
 120                 /** Type define for a DHCP packet inside an Ethernet frame. */ 
 123                         uint8_t  Operation
; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */ 
 124                         uint8_t  HardwareType
; /**< Hardware carrier type constant */ 
 125                         uint8_t  HardwareAddressLength
;  /**< Length in bytes of a hardware (MAC) address on the network */ 
 126                         uint8_t  Hops
; /**< Number of hops required to reach the server, unused */ 
 128                         uint32_t TransactionID
; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */ 
 130                         uint16_t ElapsedSeconds
; /**< Elapsed seconds since the request was made */ 
 131                         uint16_t Flags
; /**< BOOTP packet flags */ 
 133                         uip_ipaddr_t ClientIP
; /**< Client IP address, if already leased an IP */ 
 134                         uip_ipaddr_t YourIP
; /**< Client IP address */ 
 135                         uip_ipaddr_t NextServerIP
; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 136                         uip_ipaddr_t RelayAgentIP
; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 138                         uint8_t ClientHardwareAddress
[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */ 
 139                         uint8_t ServerHostnameString
[64]; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 140                         uint8_t BootFileName
[128]; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 142                         uint32_t Cookie
; /**< Magic BOOTP protocol cookie to indicate a valid packet */ 
 144                         uint8_t  Options
[]; /** DHCP message options */ 
 148                 /** States for each DHCP connection to a DHCP client. */ 
 151                         DHCP_STATE_SendDiscover
,  /**< Send DISCOVER packet to retrieve DHCP lease offers */ 
 152                         DHCP_STATE_WaitForOffer
,  /**< Waiting for OFFER packet giving available DHCP leases */ 
 153                         DHCP_STATE_SendRequest
,   /**< Send REQUEST packet to request a DHCP lease */ 
 154                         DHCP_STATE_WaitForACK
,    /**< Wait for ACK packet to complete the DHCP lease */ 
 155                         DHCP_STATE_AddressLeased
, /**< DHCP address has been leased from a DHCP server */ 
 158         /* Function Prototypes: */ 
 159                 void DHCPClientApp_Init(void); 
 160                 void DHCPClientApp_Callback(void); 
 162                 #if defined(INCLUDE_FROM_DHCPCLIENTAPP_C) 
 163                         static uint16_t DHCPClientApp_FillDHCPHeader(DHCP_Header_t
* const DHCPHeader
, const uint8_t DHCPMessageType
, 
 164                                                                      uip_udp_appstate_t
* AppState
); 
 165                         static uint8_t  DHCPClientApp_SetOption(uint8_t* DHCPOptionList
, uint8_t Option
, uint8_t DataLen
, 
 167                         static bool     DHCPClientApp_GetOption(const uint8_t* DHCPOptionList
, const uint8_t Option
, void* const Destination
);