3      Copyright (C) Dean Camera, 2018. 
   5   dean [at] fourwalledcubicle [dot] com 
  10   Copyright 2018  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 disclaims 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 common DHCP defines. 
  36 #ifndef _DHCP_COMMON_H_ 
  37 #define _DHCP_COMMON_H_ 
  44                 #include "Config/AppConfig.h" 
  49                 /** UDP listen port for a BOOTP server. */ 
  50                 #define DHCP_SERVER_PORT          67 
  52                 /** UDP listen port for a BOOTP client. */ 
  53                 #define DHCP_CLIENT_PORT          68 
  55                 /** BOOTP message type for a BOOTP REQUEST message. */ 
  56                 #define DHCP_OP_BOOTREQUEST       0x01 
  58                 /** BOOTP message type for a BOOTP REPLY message. */ 
  59                 #define DHCP_OP_BOOTREPLY         0x02 
  61                 /** BOOTP flag for a BOOTP broadcast message. */ 
  62                 #define BOOTP_BROADCAST           0x8000 
  64                 /** Magic DHCP cookie for a BOOTP message to identify it as a DHCP message. */ 
  65                 #define DHCP_MAGIC_COOKIE         0x63538263 
  67                 /** Unique transaction ID used to identify DHCP responses to the client. */ 
  68                 #define DHCP_TRANSACTION_ID       0x13245466 
  70                 /** DHCP message type for a DISCOVER message. */ 
  71                 #define DHCP_DISCOVER             1 
  73                 /** DHCP message type for an OFFER message. */ 
  76                 /** DHCP message type for a REQUEST message. */ 
  77                 #define DHCP_REQUEST              3 
  79                 /** DHCP message type for a DECLINE message. */ 
  80                 #define DHCP_DECLINE              4 
  82                 /** DHCP message type for an ACK message. */ 
  85                 /** DHCP message type for a NAK message. */ 
  88                 /** DHCP message type for a RELEASE message. */ 
  89                 #define DHCP_RELEASE              7 
  91                 /** DHCP medium type for standard Ethernet. */ 
  92                 #define DHCP_HTYPE_ETHERNET       1 
  94                 /** DHCP message option for the network subnet mask. */ 
  95                 #define DHCP_OPTION_SUBNET_MASK   1 
  97                 /** DHCP message option for the network gateway IP. */ 
  98                 #define DHCP_OPTION_ROUTER        3 
 100                 /** DHCP message option for the network DNS server. */ 
 101                 #define DHCP_OPTION_DNS_SERVER    6 
 103                 /** DHCP message option for the requested client IP address. */ 
 104                 #define DHCP_OPTION_REQ_IPADDR    50 
 106                 /** DHCP message option for the IP address lease time. */ 
 107                 #define DHCP_OPTION_LEASE_TIME    51 
 109                 /** DHCP message option for the DHCP message type. */ 
 110                 #define DHCP_OPTION_MSG_TYPE      53 
 112                 /** DHCP message option for the DHCP server IP. */ 
 113                 #define DHCP_OPTION_SERVER_ID     54 
 115                 /** DHCP message option for the list of required options from the server. */ 
 116                 #define DHCP_OPTION_REQ_LIST      55 
 118                 /** DHCP message option for the options list terminator. */ 
 119                 #define DHCP_OPTION_END           255 
 122                 /** Type define for a DHCP packet inside an Ethernet frame. */ 
 125                         uint8_t      Operation
; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */ 
 126                         uint8_t      HardwareType
; /**< Hardware carrier type constant */ 
 127                         uint8_t      HardwareAddressLength
;  /**< Length in bytes of a hardware (MAC) address on the network */ 
 128                         uint8_t      Hops
; /**< Number of hops required to reach the server, unused */ 
 130                         uint32_t     TransactionID
; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */ 
 132                         uint16_t     ElapsedSeconds
; /**< Elapsed seconds since the request was made */ 
 133                         uint16_t     Flags
; /**< BOOTP packet flags */ 
 135                         uip_ipaddr_t ClientIP
; /**< Client IP address, if already leased an IP */ 
 136                         uip_ipaddr_t YourIP
; /**< Client IP address */ 
 137                         uip_ipaddr_t NextServerIP
; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 138                         uip_ipaddr_t RelayAgentIP
; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 140                         uint8_t      ClientHardwareAddress
[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */ 
 141                         uint8_t      ServerHostnameString
[64]; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 142                         uint8_t      BootFileName
[128]; /**< Legacy BOOTP protocol field, unused for DHCP */ 
 144                         uint32_t     Cookie
; /**< Magic BOOTP protocol cookie to indicate a valid packet */ 
 146                         uint8_t      Options
[]; /**< DHCP message options */ 
 149         /* Function Prototypes: */ 
 150                 uint8_t  DHCPCommon_SetOption(uint8_t* DHCPOptionList
, 
 151                                                   const uint8_t Option
, 
 152                                                   const uint8_t DataLen
, 
 153                                                   void* const OptionData
); 
 154                 bool     DHCPCommon_GetOption(const uint8_t* DHCPOptionList
, 
 155                                                   const uint8_t Option
, 
 156                                                   void* const Destination
);