mikroSDK Reference Manual
dhcp_common.h
Go to the documentation of this file.
1
31#ifndef _DHCP_COMMON_H
32#define _DHCP_COMMON_H
33
34//Dependencies
35#include "core/net.h"
36#include "core/ethernet.h"
37#include "ipv4/ipv4.h"
38
39//UDP ports used by DHCP servers and clients
40#define DHCP_SERVER_PORT 67
41#define DHCP_CLIENT_PORT 68
42
43//Minimum size of DHCP messages
44#define DHCP_MIN_MSG_SIZE 300
45//Maximum size of DHCP messages
46#define DHCP_MAX_MSG_SIZE 548
47
48//Hardware type
49#define DHCP_HARDWARE_TYPE_ETH 1
50//DHCP magic cookie
51#define DHCP_MAGIC_COOKIE 0x63825363
52//Infinite lifetime representation
53#define DHCP_INFINITE_TIME 0xFFFFFFFF
54
55//C++ guard
56#ifdef __cplusplus
57extern "C" {
58#endif
59
60
65typedef enum
66{
67 DHCP_OPCODE_BOOTREQUEST = 1,
68 DHCP_OPCODE_BOOTREPLY = 2
70
71
76typedef enum
77{
78 DHCP_FLAG_UNICAST = 0x0000,
79 DHCP_FLAG_BROADCAST = 0x8000
80} DhcpFlags;
81
82
87typedef enum
88{
89 DHCP_MSG_TYPE_DISCOVER = 1,
90 DHCP_MSG_TYPE_OFFER = 2,
91 DHCP_MSG_TYPE_REQUEST = 3,
92 DHCP_MSG_TYPE_DECLINE = 4,
93 DHCP_MSG_TYPE_ACK = 5,
94 DHCP_MSG_TYPE_NAK = 6,
95 DHCP_MSG_TYPE_RELEASE = 7,
96 DHCP_MSG_TYPE_INFORM = 8
98
99
104typedef enum
105{
106 DHCP_OPT_PAD = 0,
107 DHCP_OPT_SUBNET_MASK = 1,
108 DHCP_OPT_TIME_OFFSET = 2,
109 DHCP_OPT_ROUTER = 3,
110 DHCP_OPT_TIME_SERVER = 4,
111 DHCP_OPT_NAME_SERVER = 5,
112 DHCP_OPT_DNS_SERVER = 6,
113 DHCP_OPT_LOG_SERVER = 7,
114 DHCP_OPT_COOKIE_SERVER = 8,
115 DHCP_OPT_LPR_SERVER = 9,
116 DHCP_OPT_IMPRESS_SERVER = 10,
117 DHCP_OPT_RESOURCE_LOCATION_SERVER = 11,
118 DHCP_OPT_HOST_NAME = 12,
119 DHCP_OPT_BOOT_FILE_SIZE = 13,
120 DHCP_OPT_MERIT_DUMP_FILE = 14,
121 DHCP_OPT_DOMAIN_NAME = 15,
122 DHCP_OPT_SWAP_SERVER = 16,
123 DHCP_OPT_ROOT_PATH = 17,
124 DHCP_OPT_EXTENSIONS_PATH = 18,
125 DHCP_OPT_IP_FORWARDING = 19,
126 DHCP_OPT_NON_LOCAL_SOURCE_ROUTING = 20,
127 DHCP_OPT_POLICY_FILTER = 21,
128 DHCP_OPT_MAX_DATAGRAM_REASSEMBLY_SIZE = 22,
129 DHCP_OPT_DEFAULT_IP_TTL = 23,
130 DHCP_OPT_PATH_MTU_AGING_TIMEOUT = 24,
131 DHCP_OPT_PATH_MTU_PLATEAU_TABLE = 25,
132 DHCP_OPT_INTERFACE_MTU = 26,
133 DHCP_OPT_ALL_SUBNETS_ARE_LOCAL = 27,
134 DHCP_OPT_BROADCAST_ADDR = 28,
135 DHCP_OPT_PERFORM_MASK_DISCOVERY = 29,
136 DHCP_OPT_MASK_SUPPLIER = 30,
137 DHCP_OPT_PERFORM_ROUTER_DISCOVERY = 31,
138 DHCP_OPT_ROUTER_SOLICITATION_ADDR = 32,
139 DHCP_OPT_STATIC_ROUTE = 33,
140 DHCP_OPT_TRAILER_ENCAPSULATION = 34,
141 DHCP_OPT_ARP_CACHE_TIMEOUT = 35,
142 DHCP_OPT_ETHERNET_ENCAPSULATION = 36,
143 DHCP_OPT_TCP_DEFAULT_TTL = 37,
144 DHCP_OPT_TCP_KEEPALIVE_INTERVAL = 38,
145 DHCP_OPT_TCP_KEEPALIVE_GARBAGE = 39,
146 DHCP_OPT_NIS_DOMAIN = 40,
147 DHCP_OPT_NIS_SERVER = 41,
148 DHCP_OPT_NTP_SERVER = 42,
149 DHCP_OPT_VENDOR_SPECIFIC_INFO = 43,
150 DHCP_OPT_NETBIOS_NBNS_SERVER = 44,
151 DHCP_OPT_NETBIOS_NBDD_SERVER = 45,
152 DHCP_OPT_NETBIOS_NODE_TYPE = 46,
153 DHCP_OPT_NETBIOS_SCOPE = 47,
154 DHCP_OPT_X11_FONT_SERVER = 48,
155 DHCP_OPT_X11_DISPLAY_MANAGER = 49,
156 DHCP_OPT_REQUESTED_IP_ADDR = 50,
157 DHCP_OPT_IP_ADDRESS_LEASE_TIME = 51,
158 DHCP_OPT_OPTION_OVERLOAD = 52,
159 DHCP_OPT_DHCP_MESSAGE_TYPE = 53,
160 DHCP_OPT_SERVER_ID = 54,
161 DHCP_OPT_PARAM_REQUEST_LIST = 55,
162 DHCP_OPT_MESSAGE = 56,
163 DHCP_OPT_MAX_DHCP_MESSAGE_SIZE = 57,
164 DHCP_OPT_RENEWAL_TIME_VALUE = 58,
165 DHCP_OPT_REBINDING_TIME_VALUE = 59,
166 DHCP_OPT_VENDOR_CLASS_ID = 60,
167 DHCP_OPT_CLIENT_ID = 61,
168 DHCP_OPT_NISP_DOMAIN = 64,
169 DHCP_OPT_NISP_SERVER = 65,
170 DHCP_OPT_TFTP_SERVER_NAME = 66,
171 DHCP_OPT_BOOTFILE_NAME = 67,
172 DHCP_OPT_MOBILE_IP_HOME_AGENT = 68,
173 DHCP_OPT_SMTP_SERVER = 69,
174 DHCP_OPT_POP3_SERVER = 70,
175 DHCP_OPT_NNTP_SERVER = 71,
176 DHCP_OPT_DEFAULT_WWW_SERVER = 72,
177 DHCP_OPT_DEFAULT_FINGER_SERVER = 73,
178 DHCP_OPT_DEFAULT_IRC_SERVER = 74,
179 DHCP_OPT_STREET_TALK_SERVER = 75,
180 DHCP_OPT_STDA_SERVER = 76,
181 DHCP_OPT_RAPID_COMMIT = 80,
182 DHCP_OPT_CLIENT_FQDN = 81,
183 DHCP_OPT_RELAY_AGENT_INFO = 82,
184 DHCP_OPT_CAPTIVE_PORTAL = 114,
185 DHCP_OPT_AUTO_CONFIG = 116,
186 DHCP_OPT_NAME_SERVICE_SEARCH = 117,
187 DHCP_OPT_SUBNET_SELECTION = 118,
188 DHCP_OPT_DOMAIN_SEARCH = 119,
189 DHCP_OPT_SIP_SERVER = 120,
190 DHCP_OPT_CLASSLESS_STATIC_ROUTE = 121,
191 DHCP_OPT_END = 255
193
194
195//CodeWarrior or Win32 compiler?
196#if defined(__CWCC__) || defined(_WIN32)
197 #pragma pack(push, 1)
198#endif
199
200
206{
207 uint8_t op; //0
208 uint8_t htype; //1
209 uint8_t hlen; //2
210 uint8_t hops; //3
211 uint32_t xid; //4-7
212 uint16_t secs; //8-9
213 uint16_t flags; //10-11
214 Ipv4Addr ciaddr; //12-15
215 Ipv4Addr yiaddr; //16-19
216 Ipv4Addr siaddr; //20-23
217 Ipv4Addr giaddr; //24-27
218 MacAddr chaddr; //28-33
219 uint8_t unused[10]; //34-43
220 uint8_t sname[64]; //44-107
221 uint8_t file[128]; //108-235
222 uint32_t magicCookie; //236-239
223 uint8_t options[]; //240
224} DhcpMessage;
225
226
231typedef __packed_struct
232{
233 uint8_t code; //0
234 uint8_t length; //1
235 uint8_t value[]; //2
236} DhcpOption;
237
238
239//CodeWarrior or Win32 compiler?
240#if defined(__CWCC__) || defined(_WIN32)
241 #pragma pack(pop)
242#endif
243
244//DHCP related functions
245error_t dhcpAddOption(DhcpMessage *message, size_t *messageLen,
246 uint8_t optionCode, const void *optionValue, size_t optionLen);
247
248DhcpOption *dhcpGetOption(const DhcpMessage *message, size_t length,
249 uint8_t optionCode);
250
251//C++ guard
252#ifdef __cplusplus
253}
254#endif
255
256#endif
DhcpOpcode
DHCP opcodes.
Definition dhcp_common.h:66
DhcpOptionCode
DHCP option codes.
Definition dhcp_common.h:105
DhcpFlags
DHCP flags.
Definition dhcp_common.h:77
DhcpMessageType
DHCP message types.
Definition dhcp_common.h:88
typedef __packed_struct
DHCP message.
Definition dhcp_common.h:206
error_t
Error codes.
Definition error.h:43
Ethernet.
IPv4 (Internet Protocol Version 4)
uint32_t Ipv4Addr
IPv4 network address.
Definition ipv4.h:267
TCP/IP stack core.