Minor documentation cleanups.
[pub/USBasp.git] / Projects / Webserver / Lib / DHCPClientApp.h
1 /*
2 LUFA Library
3 Copyright (C) Dean Camera, 2010.
4
5 dean [at] fourwalledcubicle [dot] com
6 www.fourwalledcubicle.com
7 */
8
9 /*
10 Copyright 2010 Dean Camera (dean [at] fourwalledcubicle [dot] com)
11
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.
20
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
28 this software.
29 */
30
31 /** \file
32 *
33 * Header file for DHCPClientApp.c.
34 */
35
36 #ifndef _DHCPCLIENT_APP_H_
37 #define _DHCPCLIENT_APP_H_
38
39 /* Includes: */
40 #include <stdio.h>
41
42 #include <uip.h>
43
44 #include "../Webserver.h"
45
46 /* Macros: */
47 /** UDP listen port for a BOOTP server. */
48 #define DHCPC_SERVER_PORT 67
49
50 /** UDP listen port for a BOOTP client. */
51 #define DHCPC_CLIENT_PORT 68
52
53 /** BOOTP message type for a BOOTP REQUEST message. */
54 #define DHCP_OP_BOOTREQUEST 0x01
55
56 /** BOOTP message type for a BOOTP REPLY message. */
57 #define DHCP_OP_BOOTREPLY 0x02
58
59 /** BOOTP flag for a BOOTP broadcast message. */
60 #define BOOTP_BROADCAST 0x8000
61
62 /** Magic DHCP cookie for a BOOTP message to identify it as a DHCP message. */
63 #define DHCP_MAGIC_COOKIE 0x63538263
64
65 /** Unique transaction ID used to identify DHCP responses to the client. */
66 #define DHCP_TRANSACTION_ID 0x13245466
67
68 /** DHCP message type for a DISCOVER message. */
69 #define DHCP_DISCOVER 1
70
71 /** DHCP message type for an OFFER message. */
72 #define DHCP_OFFER 2
73
74 /** DHCP message type for a REQUEST message. */
75 #define DHCP_REQUEST 3
76
77 /** DHCP message type for a DECLINE message. */
78 #define DHCP_DECLINE 4
79
80 /** DHCP message type for an ACK message. */
81 #define DHCP_ACK 5
82
83 /** DHCP message type for a NAK message. */
84 #define DHCP_NAK 6
85
86 /** DHCP message type for a RELEASE message. */
87 #define DHCP_RELEASE 7
88
89 /** DHCP medium type for standard Ethernet. */
90 #define DHCP_HTYPE_ETHERNET 1
91
92 /** DHCP message option for the network subnet mask. */
93 #define DHCP_OPTION_SUBNET_MASK 1
94
95 /** DHCP message option for the network gateway IP. */
96 #define DHCP_OPTION_ROUTER 3
97
98 /** DHCP message option for the network DNS server. */
99 #define DHCP_OPTION_DNS_SERVER 6
100
101 /** DHCP message option for the requested client IP address. */
102 #define DHCP_OPTION_REQ_IPADDR 50
103
104 /** DHCP message option for the IP address lease time. */
105 #define DHCP_OPTION_LEASE_TIME 51
106
107 /** DHCP message option for the DHCP message type. */
108 #define DHCP_OPTION_MSG_TYPE 53
109
110 /** DHCP message option for the DHCP server IP. */
111 #define DHCP_OPTION_SERVER_ID 54
112
113 /** DHCP message option for the list of required options from the server. */
114 #define DHCP_OPTION_REQ_LIST 55
115
116 /** DHCP message option for the options list terminator. */
117 #define DHCP_OPTION_END 255
118
119 /* Type Defines: */
120 /** Type define for a DHCP packet inside an Ethernet frame. */
121 typedef struct
122 {
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 */
127
128 uint32_t TransactionID; /**< Unique ID of the DHCP packet, for positive matching between sent and received packets */
129
130 uint16_t ElapsedSeconds; /**< Elapsed seconds since the request was made */
131 uint16_t Flags; /**< BOOTP packet flags */
132
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 */
137
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 */
141
142 uint32_t Cookie; /**< Magic BOOTP protocol cookie to indicate a valid packet */
143
144 uint8_t Options[]; /**< DHCP message options */
145 } DHCP_Header_t;
146
147 /* Enums: */
148 /** States for each DHCP connection to a DHCP client. */
149 enum DHCP_States_t
150 {
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 */
156 };
157
158 /* Function Prototypes: */
159 void DHCPClientApp_Init(void);
160 void DHCPClientApp_Callback(void);
161
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,
166 void* OptionData);
167 static bool DHCPClientApp_GetOption(const uint8_t* DHCPOptionList, const uint8_t Option, void* const Destination);
168 #endif
169 #endif