3 Copyright (C) Dean Camera, 2015.
5 dean [at] fourwalledcubicle [dot] com
10 Copyright 2015 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 DHCP.c.
43 #include "EthernetProtocols.h"
45 #include "ProtocolDecoders.h"
48 /** DHCP operation constant, indicating a request from a host to a DHCP server. */
49 #define DHCP_OP_BOOTREQUEST 0x01
51 /** DHCP operation constant, indicating a reply from a DHCP server to a host. */
52 #define DHCP_OP_BOOTREPLY 0x02
54 /** Hardware type constant, indicating Ethernet as a carrier. */
55 #define DHCP_HTYPE_ETHERNET 0x01
57 /** Magic boot protocol "cookie", inserted into all BOOTP packets (BOOTP is the carrier of DHCP). */
58 #define DHCP_MAGIC_COOKIE 0x63825363
60 /** DHCP option list entry header, indicating that a subnet mask will follow. */
61 #define DHCP_OPTION_SUBNETMASK 1
63 /** DHCP option list entry header, indicating that the Lease Time will follow. */
64 #define DHCP_OPTION_LEASETIME 51
66 /** DHCP option list entry header, indicating that the DHCP message type constant will follow. */
67 #define DHCP_OPTION_MESSAGETYPE 53
69 /** DHCP option list entry header, indicating that the IP address of the DHCP server will follow. */
70 #define DHCP_OPTION_DHCPSERVER 54
72 /** DHCP option list entry header, used to pad out option data. */
73 #define DHCP_OPTION_PAD 0
75 /** DHCP option list entry header, indicating the end of option data. */
76 #define DHCP_OPTION_END 255
78 /** Message type constant, used in the DHCP option data field, requesting that a DHCP server offer an IP address. */
79 #define DHCP_MESSAGETYPE_DISCOVER 1
81 /** Message type constant, used in the DHCP option data field, indicating that a DHCP server is offering an IP address. */
82 #define DHCP_MESSAGETYPE_OFFER 2
84 /** Message type constant, used in the DHCP option data field, requesting that a DHCP server lease a given IP address. */
85 #define DHCP_MESSAGETYPE_REQUEST 3
87 /** Message type constant, used in the DHCP option data field, declining an offered DHCP server IP address lease. */
88 #define DHCP_MESSAGETYPE_DECLINE 4
90 /** Message type constant, used in the DHCP option data field, ACKing a host IP lease request. */
91 #define DHCP_MESSAGETYPE_ACK 5
93 /** Message type constant, used in the DHCP option data field, NACKing a host IP lease request. */
94 #define DHCP_MESSAGETYPE_NACK 6
96 /** Message type constant, used in the DHCP option data field, indicating that a host is releasing a leased IP address. */
97 #define DHCP_MESSAGETYPE_RELEASE 7
100 /** Type define for a DHCP packet inside an Ethernet frame. */
103 uint8_t Operation
; /**< DHCP operation, either DHCP_OP_BOOTREQUEST or DHCP_OP_BOOTREPLY */
104 uint8_t HardwareType
; /**< Hardware carrier type constant */
105 uint8_t HardwareAddressLength
; /**< Length in bytes of a hardware (MAC) address on the network */
106 uint8_t Hops
; /**< Number of hops required to reach the server, unused */
108 uint32_t TransactionID
; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */
110 uint16_t ElapsedSeconds
; /**< Elapsed seconds since the request was made */
111 uint16_t Flags
; /**< BOOTP packet flags */
113 IP_Address_t ClientIP
; /**< Client IP address, if already leased an IP */
114 IP_Address_t YourIP
; /**< Client IP address */
115 IP_Address_t NextServerIP
; /**< Legacy BOOTP protocol field, unused for DHCP */
116 IP_Address_t RelayAgentIP
; /**< Legacy BOOTP protocol field, unused for DHCP */
118 uint8_t ClientHardwareAddress
[16]; /**< Hardware (MAC) address of the client making a request to the DHCP server */
119 uint8_t ServerHostnameString
[64]; /**< Legacy BOOTP protocol field, unused for DHCP */
120 uint8_t BootFileName
[128]; /**< Legacy BOOTP protocol field, unused for DHCP */
122 uint32_t Cookie
; /**< Magic BOOTP protocol cookie to indicate a valid packet */
125 /* Function Prototypes: */
126 int16_t DHCP_ProcessDHCPPacket(void* IPHeaderInStart
,
127 void* DHCPHeaderInStart
,
128 void* DHCPHeaderOutStart
);