1 /**************************************************************************/
2 /*                                                                        */
3 /*       Copyright (c) Microsoft Corporation. All rights reserved.        */
4 /*                                                                        */
5 /*       This software is licensed under the Microsoft Software License   */
6 /*       Terms for Microsoft Azure RTOS. Full text of the license can be  */
7 /*       found in the LICENSE file at https://aka.ms/AzureRTOS_EULA       */
8 /*       and in the root directory of this software.                      */
9 /*                                                                        */
10 /**************************************************************************/
11 
12 
13 /**************************************************************************/
14 /**************************************************************************/
15 /**                                                                       */
16 /** NetX Component                                                        */
17 /**                                                                       */
18 /**   Dynamic Host Configuration Protocol (DHCP)                          */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  APPLICATION INTERFACE DEFINITION                       RELEASE        */
27 /*                                                                        */
28 /*    nxd_dhcp_server.h                                   PORTABLE C      */
29 /*                                                           6.1.9        */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Yuxin Zhou, Microsoft Corporation                                   */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the NetX Dynamic Host Configuration Protocol      */
37 /*    (DHCP) server component, including all data types and external      */
38 /*    references. It is assumed that nx_api.h and nx_port.h have already  */
39 /*    been   included.                                                    */
40 /*                                                                        */
41 /*  RELEASE HISTORY                                                       */
42 /*                                                                        */
43 /*    DATE              NAME                      DESCRIPTION             */
44 /*                                                                        */
45 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
46 /*  09-30-2020     Yuxin Zhou               Modified comment(s), and      */
47 /*                                            modified the type of        */
48 /*                                            nx_dhcp_user_options,       */
49 /*                                            improved buffer length      */
50 /*                                            verification,               */
51 /*                                            resulting in version 6.1    */
52 /*  10-15-2021     Yuxin Zhou               Modified comment(s), included */
53 /*                                            necessary header file,      */
54 /*                                            resulting in version 6.1.9  */
55 /*                                                                        */
56 /**************************************************************************/
57 
58 #ifndef  NXD_DHCP_SERVER_H
59 #define  NXD_DHCP_SERVER_H
60 
61 /* Determine if a C++ compiler is being used.  If so, ensure that standard
62    C is used to process the API information.  */
63 
64 #ifdef   __cplusplus
65 
66 /* Yes, C++ compiler is present.  Use standard C.  */
67 extern   "C" {
68 
69 #endif
70 
71 #include "nx_api.h"
72 
73 /* Define the DHCP Server ID that is used to mark the DHCP Server structure as created.  */
74 
75 #define NX_DHCP_SERVER_ID                       0x44484360UL
76 
77 
78 /* Define the DHCP stack size.  */
79 
80 #ifndef NX_DHCP_SERVER_THREAD_STACK_SIZE
81 #define NX_DHCP_SERVER_THREAD_STACK_SIZE        1024
82 #endif
83 
84 
85 /* Define the DHCP stack priority.  */
86 
87 #ifndef NX_DHCP_SERVER_THREAD_PRIORITY
88 #define NX_DHCP_SERVER_THREAD_PRIORITY          2
89 #endif
90 
91 
92 /* Define the DHCP packet allocation timeout in timer ticks.  */
93 
94 #ifndef NX_DHCP_PACKET_ALLOCATE_TIMEOUT
95 #define NX_DHCP_PACKET_ALLOCATE_TIMEOUT         NX_IP_PERIODIC_RATE
96 #endif
97 
98 
99 /* Define UDP socket create options.  */
100 
101 #ifndef NX_DHCP_TYPE_OF_SERVICE
102 #define NX_DHCP_TYPE_OF_SERVICE                 NX_IP_NORMAL
103 #endif
104 
105 #ifndef NX_DHCP_FRAGMENT_OPTION
106 #define NX_DHCP_FRAGMENT_OPTION                 NX_DONT_FRAGMENT
107 #endif
108 
109 #ifndef NX_DHCP_TIME_TO_LIVE
110 #define NX_DHCP_TIME_TO_LIVE                    0x80
111 #endif
112 
113 #ifndef NX_DHCP_QUEUE_DEPTH
114 #define NX_DHCP_QUEUE_DEPTH                     5
115 #endif
116 
117 
118 /* Define the server interface subnet mask (DHCP Client standard option). */
119 
120 #ifndef NX_DHCP_SUBNET_MASK
121 #define NX_DHCP_SUBNET_MASK                     0xFFFFFF00UL
122 #endif
123 
124 
125 
126 /* Define the client's host name buffer size. */
127 
128 #ifndef NX_DHCP_CLIENT_HOSTNAME_MAX
129 #define NX_DHCP_CLIENT_HOSTNAME_MAX             32
130 #endif
131 
132 
133 /* Define DHCP server's name and buffer size. */
134 #ifndef NX_DHCP_SERVER_HOSTNAME_MAX
135 #define NX_DHCP_SERVER_HOSTNAME_MAX             32
136 #endif
137 
138 #ifndef NX_DHCP_SERVER_NAME
139 #define NX_DHCP_SERVER_NAME                     "NetX DHCP Server"
140 #endif
141 
142 
143 
144 /* Define an interval in seconds for the session timer to check the time remaining on
145    all the active clients in the server database. */
146 
147 #ifndef NX_DHCP_FAST_PERIODIC_TIME_INTERVAL
148 #define NX_DHCP_FAST_PERIODIC_TIME_INTERVAL     10
149 #endif
150 
151 /* Set a length of time in seconds in which server can expect a client response during
152    Client DHCP session. Once a client is BOUND, the session timeout is set
153    to the IP address lease time. Note the maximum wait time between Client retransmissions
154    is 64 seconds, so this timeout should be in that neighborhood. Must be greater than
155    the fast periodic time interva. */
156 
157 #ifndef NX_DHCP_CLIENT_SESSION_TIMEOUT
158 #define NX_DHCP_CLIENT_SESSION_TIMEOUT          (10 * NX_DHCP_FAST_PERIODIC_TIME_INTERVAL)
159 #endif
160 
161 
162 /* Define an interval in seconds for the IP lease timer to check the time remaining on
163    all the assigned IP addresses in the server database. */
164 
165 #ifndef NX_DHCP_SLOW_PERIODIC_TIME_INTERVAL
166 #define NX_DHCP_SLOW_PERIODIC_TIME_INTERVAL     1000
167 #endif
168 
169 
170 /* Set the default lease time in seconds on the IP address the server
171    will assign to the Client. */
172 
173 #ifndef  NX_DHCP_DEFAULT_LEASE_TIME
174 #define  NX_DHCP_DEFAULT_LEASE_TIME            (10 * NX_DHCP_SLOW_PERIODIC_TIME_INTERVAL)
175 #endif
176 
177 
178 
179 /* Set a size of the Server option list requested by the Client. Since the NetX DHCP Server
180    does not as yet support the complete set of options in DHCP, this number can be optimized
181    down to a smaller size that the largest possible number of options a Client could request.
182 */
183 
184 #ifndef NX_DHCP_CLIENT_OPTIONS_MAX
185 #define NX_DHCP_CLIENT_OPTIONS_MAX             12
186 #endif
187 
188 
189 /* There are optional and required elements of the server option list.
190    Use the required plus the user configurable option list for the
191    server list to respond back to the client.
192 */
193 
194 /* At the very least, a DHCP server should supply the
195    Client's subnet mask, router (default gateway) address and dns server. This list must be
196    space separated. The combined required and optional server options
197    should be less than NX_DHCP_CLIENT_OPTIONS_MAX.
198 */
199 
200 #ifndef NX_DHCP_OPTIONAL_SERVER_OPTION_LIST
201 #define NX_DHCP_OPTIONAL_SERVER_OPTION_LIST  "1 3 6"
202 #endif
203 
204 /* Set the number of default options in the optional server list above. */
205 #ifndef NX_DHCP_OPTIONAL_SERVER_OPTION_SIZE
206 #define NX_DHCP_OPTIONAL_SERVER_OPTION_SIZE   3
207 #endif
208 
209 
210 /* The NetX DHCP Server includes its server identifier, message type in all messages. */
211 #define NX_DHCP_REQUIRED_SERVER_OPTION_LIST  "53 54"
212 #define NX_DHCP_REQUIRED_SERVER_OPTION_SIZE   2
213 
214 /* Compute the total option  list size. */
215 #define NX_DHCP_SERVER_OPTION_LIST_SIZE      (NX_DHCP_REQUIRED_SERVER_OPTION_SIZE + NX_DHCP_OPTIONAL_SERVER_OPTION_SIZE)
216 
217 /* Combine the actual lists maintaining a space between all options. */
218 #define NX_DHCP_SERVER_OPTION_LIST           NX_DHCP_REQUIRED_SERVER_OPTION_LIST \
219                                              " "                                 \
220                                              NX_DHCP_OPTIONAL_SERVER_OPTION_LIST
221 
222 
223 /* Define the maximum size of each IP address list.  Each interface the server assigns
224    IP addresses for will be limited to this size. */
225 
226 /* Define the max size of an IP addresses list (applies to each interfaces). */
227 
228 #ifndef NX_DHCP_IP_ADDRESS_MAX_LIST_SIZE
229 #define NX_DHCP_IP_ADDRESS_MAX_LIST_SIZE      20
230 #endif
231 
232 /* Define the size of client record table (All clients e.g.on all interfaces). */
233 
234 #ifndef NX_DHCP_CLIENT_RECORD_TABLE_SIZE
235 #define NX_DHCP_CLIENT_RECORD_TABLE_SIZE      50
236 #endif
237 
238     /* END OF CONFIGURABLE OPTIONS */
239 
240 
241 /* Define the size of the BOOT buffer. This should be large enough for all the
242    required DHCP fields plus the minimum requirement of 312 bytes of option data
243    stated in RFC 2131; 2. Protocol Summary. */
244 #ifndef NX_BOOT_BUFFER_SIZE
245 #define NX_BOOT_BUFFER_SIZE             548
246 #endif
247 
248 /* Define the size of the DHCP header as per RFC 213 Section Protocol Summery, page 10.  */
249 
250 #ifndef NX_DHCP_HEADER_SIZE
251 #define NX_DHCP_HEADER_SIZE             236
252 #endif
253 
254 
255 /*
256    Define the packet payload size, keeping in mind the DHCP Server must support
257    at least a 548 byte DHCP Client message as per RFC 2131 and allow room for Ethernet, UDP and
258    IP headers and 4 byte alignment.
259 */
260 #ifndef NX_DHCP_MINIMUM_PACKET_PAYLOAD
261 #define NX_DHCP_MINIMUM_PACKET_PAYLOAD          (NX_BOOT_BUFFER_SIZE + NX_PHYSICAL_HEADER +  sizeof(NX_IPV4_HEADER) + sizeof(NX_UDP_HEADER))
262 #endif /* NX_DHCP_MINIMUM_PACKET_PAYLOAD */
263 
264 
265 /* Define the DHCP Message Area Offsets.  The DHCP message format is identical to that of BootP, except
266    for the Vendor options that start at the offset specified by NX_DHCP_OFFSET_OPTIONS.  */
267 
268 #define NX_DHCP_OFFSET_OP              0       /* 1 BootP Operation 1=req, 2=reply                         */
269 #define NX_DHCP_OFFSET_HTYPE           1       /* 1 Hardware type 1 = Ethernet                             */
270 #define NX_DHCP_OFFSET_HLEN            2       /* 1 Hardware address length, 6 for Ethernet                */
271 #define NX_DHCP_OFFSET_HOPS            3       /* 1 Number of hops, usually 0                              */
272 #define NX_DHCP_OFFSET_XID             4       /* 4 Transaction ID, pseudo random number                   */
273 #define NX_DHCP_OFFSET_SECS            8       /* 2 Seconds since boot                                     */
274 #define NX_DHCP_OFFSET_FLAGS           10      /* 2 Flags, 0x80 = Broadcast response, 0 = unicast response */
275 #define NX_DHCP_OFFSET_CLIENT_IP       12      /* 4 Initial client IP, used as dest for unicast response   */
276 #define NX_DHCP_OFFSET_YOUR_IP         16      /* 4 Assigned IP, initialized to 0.0.0.0                    */
277 #define NX_DHCP_OFFSET_SERVER_IP       20      /* 4 Server IP, usually initialized to 0.0.0.0              */
278 #define NX_DHCP_OFFSET_RELAY_IP        24      /* 4 Relay IP, usually 0.0.0.0, only for DHCP               */
279 #define NX_DHCP_OFFSET_CLIENT_HW       28      /* 16 Client hardware address                               */
280 #define NX_DHCP_OFFSET_SERVER_NM       44      /* 64 Server name, nulls if unused                          */
281 #define NX_DHCP_OFFSET_BOOT_FILE       108     /* 128 Boot file name, null if unused                       */
282 #define NX_DHCP_OFFSET_VENDOR          236     /* 64 Vendor options, set first 4 bytes to a magic number   */
283 #define NX_DHCP_OFFSET_OPTIONS         240     /* First variable vendor option                             */
284 #define NX_DHCP_OFFSET_END             300     /* End of BOOTP buffer                                      */
285 #define NX_DHCP_SERVER_OPTION_ADDRESS_SIZE     4
286 
287 /* Define the DHCP Specific Vendor Extensions. */
288 
289 #define NX_DHCP_SERVER_OPTION_PAD              0
290 #define NX_DHCP_SERVER_OPTION_PAD_SIZE         0
291 #define NX_DHCP_SERVER_OPTION_SUBNET_MASK      1
292 #define NX_DHCP_SERVER_OPTION_SUBNET_MASK_SIZE NX_DHCP_SERVER_OPTION_ADDRESS_SIZE
293 #define NX_DHCP_SERVER_OPTION_TIME_OFFSET      2
294 #define NX_DHCP_SERVER_OPTION_TIME_OFFSET_SIZE 4
295 #define NX_DHCP_SERVER_OPTION_ROUTER           3
296 #define NX_DHCP_SERVER_OPTION_ROUTER_SIZE      NX_DHCP_SERVER_OPTION_ADDRESS_SIZE
297 #define NX_DHCP_SERVER_OPTION_TIMESVR          4
298 #define NX_DHCP_SERVER_OPTION_DNS_SVR          6
299 #define NX_DHCP_SERVER_OPTION_HOST_NAME        12
300 #define NX_DHCP_SERVER_OPTION_DNS_NAME         15
301 #define NX_DHCP_SERVER_OPTION_NTP_SVR          42
302 #define NX_DHCP_SERVER_OPTION_VENDOR_OPTIONS   43
303 #define NX_DHCP_SERVER_OPTION_DHCP_IP_REQ      50
304 #define NX_DHCP_SERVER_OPTION_DHCP_IP_REQ_SIZE NX_DHCP_SERVER_OPTION_ADDRESS_SIZE
305 #define NX_DHCP_SERVER_OPTION_DHCP_LEASE       51
306 #define NX_DHCP_SERVER_OPTION_DHCP_LEASE_SIZE  4
307 #define NX_DHCP_SERVER_OPTION_DHCP_TYPE        53
308 #define NX_DHCP_SERVER_OPTION_DHCP_TYPE_SIZE   1
309 #define NX_DHCP_SERVER_OPTION_DHCP_SERVER_ID   54
310 #define NX_DHCP_SERVER_OPTION_DHCP_SERVER_SIZE NX_DHCP_SERVER_OPTION_ADDRESS_SIZE
311 #define NX_DHCP_SERVER_OPTION_DHCP_PARAMETERS  55
312 #define NX_DHCP_SERVER_OPTION_DHCP_MESSAGE     56
313 #define NX_DHCP_SERVER_OPTION_RENEWAL          58
314 #define NX_DHCP_SERVER_OPTION_RENEWAL_SIZE     4
315 #define NX_DHCP_SERVER_OPTION_REBIND           59
316 #define NX_DHCP_SERVER_OPTION_REBIND_SIZE      4
317 #define NX_DHCP_SERVER_OPTION_CLIENT_ID        61
318 #define NX_DHCP_SERVER_OPTION_CLIENT_ID_SIZE   7
319 #define NX_DHCP_SERVER_OPTION_FDQN             81
320 #define NX_DHCP_SERVER_OPTION_FDQN_FLAG_N      8
321 #define NX_DHCP_SERVER_OPTION_FDQN_FLAG_E      4
322 #define NX_DHCP_SERVER_OPTION_FDQN_FLAG_O      2
323 #define NX_DHCP_SERVER_OPTION_FDQN_FLAG_S      1
324 #define NX_DHCP_SERVER_OPTION_END              255
325 #define NX_DHCP_SERVER_OPTION_END_SIZE         0
326 
327 #define NX_DHCP_MINIMUM_PACKET          (NX_DHCP_OFFSET_END + NX_UDP_PACKET+ 100)
328 
329 
330 /* Define various BootP/DHCP constants.  */
331 
332 #define NX_DHCP_SERVER_UDP_PORT         67
333 #define NX_DHCP_SERVER_TCP_PORT         67
334 #define NX_DHCP_CLIENT_UDP_PORT         68
335 #define NX_DHCP_CLIENT_TCP_PORT         68
336 
337 #define NX_DHCP_OP_REQUEST             1
338 #define NX_DHCP_OP_REPLY               2
339 #define NX_DHCP_FLAGS_BROADCAST        0x80
340 #define NX_DHCP_FLAGS_UNICAST          0x00
341 #define NX_DHCP_MAGIC_COOKIE           IP_ADDRESS(99, 130, 83, 99)
342 #define NX_DHCP_NO_ADDRESS             IP_ADDRESS(0, 0, 0, 0)
343 #define NX_DHCP_BC_ADDRESS             IP_ADDRESS(255, 255, 255, 255)
344 #define NX_AUTO_IP_ADDRESS             IP_ADDRESS(169, 254, 0, 0)
345 #define NX_AUTO_IP_ADDRESS_MASK        0xFFFF0000UL
346 #define NX_DHCP_SERVER_INFINITE_LEASE  0xFFFFFFFFUL
347 
348 
349 /* Define the DHCP Message Types.  */
350 
351 #define NX_DHCP_TYPE_DHCPDISCOVER       1
352 #define NX_DHCP_TYPE_DHCPOFFER          2
353 #define NX_DHCP_TYPE_DHCPREQUEST        3
354 #define NX_DHCP_TYPE_DHCPDECLINE        4
355 #define NX_DHCP_TYPE_DHCPACK            5
356 #define NX_DHCP_TYPE_DHCPNACK           6
357 #define NX_DHCP_TYPE_DHCPRELEASE        7
358 #define NX_DHCP_TYPE_DHCPINFORM         8
359 #define NX_DHCP_TYPE_DHCPFORCERENEW     9
360 #define NX_DHCP_TYPE_DHCPSILENT         10
361 
362 
363 /* Define the states of the DHCP state machine. */
364 
365 #define NX_DHCP_STATE_BOOT              1       /* Started with a previous address                          */
366 #define NX_DHCP_STATE_INIT              2       /* Started with no previous address                         */
367 #define NX_DHCP_STATE_SELECTING         3       /* Waiting to identify a DHCP server                        */
368 #define NX_DHCP_STATE_REQUESTING        4       /* Address requested, waiting for the Ack                   */
369 #define NX_DHCP_STATE_BOUND             5       /* Address established, no time outs                        */
370 #define NX_DHCP_STATE_RENEWING          6       /* Address established, renewal time out                    */
371 #define NX_DHCP_STATE_REBINDING         7       /* Address established, renewal and rebind time out         */
372 #define NX_DHCP_STATE_FORCERENEW        8       /* Address established, force renewal                       */
373 
374 
375 /* Define error codes from DHCP Server operation.  */
376 
377 #define NX_DHCP_SERVER_ALREADY_STARTED          0x90    /* DHCP Server already started      */
378 #define NX_DHCP_SERVER_NOT_STARTED              0x91    /* DHCP Server not started when stop was issued   */
379 #define NX_DHCP_PARAMETER_ERROR                 0x92    /* Invalid non pointer input   */
380 #define NX_DHCP_INADEQUATE_PACKET_POOL_PAYLOAD  0x93    /* DHCP Server packet pool has inadequate packet payload for DHCP messages. */
381 #define NX_DHCP_BAD_OPTION_LIST_ERROR           0x94    /* Server default option list has invalid characters. */
382 #define NX_DHCP_INTERNAL_OPTION_PARSE_ERROR     0x95    /* Internal error parsing options from string to ULONG. */
383 #define NX_DHCP_NO_SERVER_OPTION_LIST           0x96    /* Server default option list is empty when server is configured to use it. */
384 #define NX_DHCP_IMPROPERLY_TERMINATED_OPTION    0x97    /* Improperly formatted client option data e.g missing terminating symbol 0xFF. */
385 #define NX_DHCP_ADD_OPTION_ERROR                0x98    /* Unable to add option to buffer of server DHCP response packet */
386 #define NX_DHCP_INVALID_IP_ADDRESS_LIST         0x99    /* Invalid start or end IP address list parameter for creating assignable IP address list.   */
387 #define NX_DHCP_NO_AVAILABLE_IP_ADDRESSES       0x9A    /* Server has no available IP addresses for DHCP Clients  */
388 #define NX_DHCP_INVALID_IP_ADDRESS              0x9B    /* Invalid IP address e.g. null address received or obtained from client record. */
389 #define NX_DHCP_IP_ADDRESS_NOT_FOUND            0x9C    /* No match found for IP address search */
390 #define NX_DHCP_IP_ADDRESS_ASSIGNED_TO_OTHER    0x9D    /* IP address not assigned to the current client */
391 #define NX_DHCP_INVALID_UPDATE_ADDRESS_CMD      0x9E    /* Unable to ascertain assigned ip address status (e.g. assign, mark available etc) */
392 #define NX_DHCP_CLIENT_RECORD_NOT_FOUND         0x9F    /* Unable to find client in Client records table. */
393 #define NX_DHCP_CLIENT_TABLE_FULL               0xA0    /* Server unable to add record to client table; table is full. */
394 #define NX_DHCP_SERVER_BAD_INTERFACE_INDEX      0xA1    /* Interface index exceeds the NX_MAX_PHYSICAL_INTERFACES limit.  */
395 #define NX_DHCP_INVALID_HW_ADDRESS              0xA2    /* Invalid hardware address e.g. null or exceeding 6 bytes. */
396 #define NX_DHCP_INVALID_NETWORK_PARAMETERS      0xA3    /* Invalid network parameters (subnet, dns server, default gateway/router). */
397 #define NX_DHCP_MALFORMED_DHCP_PACKET           0xA4    /* DHCP packet was malformed. */
398 
399 
400 /* Define DHCP Server event flags.  These events are processed by the DHCP Server thread. */
401 #define NX_DHCP_SERVER_ALL_EVENTS               0xFFFFFFFFUL    /* All DHCP Server event flags. */
402 #define NX_DHCP_SERVER_RECEIVE_EVENT            0x00000001UL    /* Packet received event.       */
403 #define NX_DHCP_SERVER_FAST_PERIODIC_EVENT      0x00000002UL    /* Fast periodic timer event.   */
404 #define NX_DHCP_SERVER_SLOW_PERIODIC_EVENT      0x00000004UL    /* Slow periodic timer event.   */
405 
406 
407 /* Define Assignable IP status 'commands'. */
408 
409 #define NX_DHCP_ADDRESS_STATUS_NO_ACTION        0x01    /* No change in Client address. */
410 #define NX_DHCP_ADDRESS_STATUS_SERVER_ASSIGN    0x02    /* Server will assign IP address to client. */
411 #define NX_DHCP_ADDRESS_STATUS_ASSIGNED_EXT     0x03    /* Client assigned IP address elesewhere, mark client as owner and IP as not available. */
412 #define NX_DHCP_ADDRESS_STATUS_MARK_AVAILABLE   0x04    /* Mark client's IP address as available and clear owner field. */
413 #define NX_DHCP_ADDRESS_STATUS_ASSIGNED_OTHER   0x05    /* Mark client's IP address as assigned already (owner unknown). */
414 
415 /* Define types of options to load in server response to DHCP client. */
416 
417 #define NX_DHCP_OPTIONS_FOR_ALL_REPLIES         0x01
418 #define NX_DHCP_OPTIONS_FOR_REPLY_TO_OFFER      0x02
419 #define NX_DHCP_OPTIONS_FOR_REPLY_TO_REQUEST    0x03
420 #define NX_DHCP_OPTIONS_FOR_REPLY_TO_INFORM     0x04
421 #define NX_DHCP_OPTIONS_FOR_GENERIC_ACK         0x05
422 #define NX_DHCP_OPTIONS_REQUESTED_BY_CLIENT     0x06
423 
424 /* Define the DHCP structure that contains DHCP client information during DHCP session.  Note
425    this is not the same control block as the NX_DHCP_STRUCT in nx_dhcp.h for the NetX DHCP Client
426    package.  */
427 
428 typedef struct NX_DHCP_CLIENT_STRUCT
429 {
430 
431     UINT            nx_dhcp_client_state;        /* Client DHCP state: e.g. INIT, BOOT, SELECTING, RENEWING etc */
432     UCHAR           nx_dhcp_message_type;        /* DHCP message type (DISCOVER, REQUEST etc) received from Client. */
433     CHAR            nx_dhcp_client_name[NX_DHCP_CLIENT_HOSTNAME_MAX];
434                                                  /* DHCP Client host name buffer. */
435     ULONG           nx_dhcp_xid;                 /* Transaction ID for client DHCP session   */
436     ULONG           nx_dhcp_source_ip_address;   /* Source IP of the client DHCP message. */
437     ULONG           nx_dhcp_destination_ip_address;
438                                                  /* Destination IP of the client DHCP message. */
439     ULONG           nx_dhcp_clientip_address;    /* "Client IP address" (sometimes called "ci-addr" field). */
440     ULONG           nx_dhcp_your_ip_address;     /* "Your IP address" field in client DHCP message. */
441     ULONG           nx_dhcp_requested_ip_address;/* IP address requested in client message option. */
442     ULONG           nx_dhcp_requested_lease_time;/* IP address lease time requested in client message option. */
443     ULONG           nx_dhcp_assigned_ip_address; /* IP address the Server offers/assigns the client. */
444     UINT            nx_dhcp_client_iface_index;  /* Index into the server interface table matching the DHCP client's packet interface. */
445     ULONG           nx_dhcp_clientrec_server_ip; /* Next Server IP Address (may be another DHCP server) for advanced DHCP features */
446     ULONG           nx_dhcp_server_id;           /* Requested/assigned Server ID (usually set to DHCP server IP address) */
447     ULONG           nx_dhcp_router_ip_address;   /* Requested/assigned router on DHCP Client network. */
448     ULONG           nx_dhcp_dns_ip_address;      /* Requested/assigned DNS IP address; usually set to zero. */
449     ULONG           nx_dhcp_relay_ip_address;    /* Requested/assigned Relay IP address; usually set to zero. */
450     ULONG           nx_dhcp_subnet_mask;         /* Requested/assigned network mask */
451     ULONG           nx_dhcp_client_mac_msw;      /* Client MAC address high bits */
452     ULONG           nx_dhcp_client_mac_lsw;      /* Client MAC address low bits */
453     UINT            nx_dhcp_client_hwlen;        /* Length of hardware address. */
454     UINT            nx_dhcp_client_hwtype;       /* Client interface hardware type e.g. Ethernet. */
455     ULONG           nx_dhcp_broadcast_flag_set;  /* Parse broadcast flags from DHCP messages. */
456     UINT            nx_dhcp_client_option_count; /* Number of user options in client request */
457     UCHAR           nx_dhcp_user_options[NX_DHCP_CLIENT_OPTIONS_MAX];
458     ULONG           nx_dhcp_session_timeout;     /* Time out on waiting for client's next response */
459     UINT            nx_dhcp_response_type_to_client;
460                                                  /* DHCP code for response to send back to client. */
461 
462 } NX_DHCP_CLIENT;
463 
464 /* Define the interface address structure which the server will use to assign IP addresses
465    in a previously specified network interface. */
466 typedef struct NX_DHCP_INTERFACE_IP_ADDRESS_STRUCT
467 {
468     ULONG           nx_assignable_ip_address;       /* IP address available to assign to DHCP Client. */
469     UINT            assigned;                       /* IP address status e.g if currently assigned to a client host. */
470     UINT            lease_time;                     /* Lease duration in secs. */
471     UINT            owner_hwtype;                   /* Hardware type.  */
472     UINT            owner_mac_msw;                  /* MAC address high bits.  */
473     UINT            owner_mac_lsw;                  /* MAC address low bits.  */
474 } NX_DHCP_INTERFACE_IP_ADDRESS;
475 
476 
477 typedef struct NX_DHCP_INTERFACE_TABLE_STRUCT
478 {
479     NX_DHCP_INTERFACE_IP_ADDRESS
480                     nx_dhcp_ip_address_list[NX_DHCP_IP_ADDRESS_MAX_LIST_SIZE];
481                                                     /* IP address available to assign to DHCP Client. */
482     NX_INTERFACE    *nx_dhcp_incoming_interface;    /* Pointer to DHCP Server interface. */
483     ULONG           nx_dhcp_server_ip_address;      /* DHCP Server's IP address for this interface. */
484     ULONG           nx_dhcp_dns_ip_address;         /* DHCP server DNS Server Address in message to DHCP Client..  */
485     ULONG           nx_dhcp_subnet_mask;            /* DHCP server interface subnet mask. */
486     ULONG           nx_dhcp_subnet;                 /* DHCP server interface subnet. */
487     ULONG           nx_dhcp_router_ip_address;      /* The router IP Address for DHCP client configuration  */
488     UINT            nx_dhcp_address_list_size;      /* Actual number of assignable addresses for this interface. */
489 
490 } NX_DHCP_INTERFACE_TABLE;
491 
492 /* Define the Interface address list. */
493 
494 /* Define the DHCP structure that contains all the server information necessary for this DHCP
495    instance.  */
496 
497 typedef struct NX_DHCP_SERVER_STRUCT
498 {
499     ULONG           nx_dhcp_id;                     /* DHCP thread ID */
500     CHAR           *nx_dhcp_name;                   /* DHCP server name */
501     NX_PACKET_POOL *nx_dhcp_packet_pool_ptr;        /* Pointer to DHCP server packet pool */
502     TX_TIMER        nx_dhcp_slow_periodic_timer;    /* Timer for watching IP lease time outs. */
503     TX_TIMER        nx_dhcp_fast_periodic_timer;    /* Timer for watching session time outs. */
504     UCHAR           nx_dhcp_started;                /* DHCP started flag */
505     NX_IP          *nx_dhcp_ip_ptr;                 /* The Server IP Instance   */
506     TX_THREAD       nx_dhcp_server_thread;          /* The DHCP server processing thread   */
507     TX_MUTEX        nx_dhcp_mutex;                  /* Mutex protection for client and interface tables. */
508     TX_EVENT_FLAGS_GROUP nx_dhcp_server_events;     /* DHCP Server events. */
509     UINT            nx_dhcp_number_clients;         /* Number of clients currently assigned IP address by this server. */
510     NX_DHCP_CLIENT  client_records[NX_DHCP_CLIENT_RECORD_TABLE_SIZE];   /* Table of DHCP clients.*/
511                                                     /* List of IP addresses server can assign to DHCP Clients */
512     NX_UDP_SOCKET   nx_dhcp_socket;                 /* DHCP server socket to receive DHCP messages on its interfaces. */
513     UINT            nx_dhcp_server_options[NX_DHCP_SERVER_OPTION_LIST_SIZE];
514                                                     /* List of max number of options in supply data to Client */
515     UINT            nx_dhcp_server_option_count;    /* Actual number of options the server is supplying back to client. */
516 
517     NX_DHCP_INTERFACE_TABLE nx_dhcp_interface_table[NX_MAX_PHYSICAL_INTERFACES];
518                                                     /* Interface specific table of addresses available for DHCP clients. */
519     ULONG           nx_dhcp_discoveries_received;   /* The number of Discovery messages received   */
520     ULONG           nx_dhcp_requests_received;      /* The number of Request messages received  */
521     ULONG           nx_dhcp_informs_received;       /* The number of Inform messages received  */
522     ULONG           nx_dhcp_declines_received;      /* The number of Decline messages received  */
523     ULONG           nx_dhcp_releases_received;      /* The number of Release messages received  */
524 
525 } NX_DHCP_SERVER;
526 
527 
528 #ifndef NX_DHCP_SERVER_SOURCE_CODE
529 
530 /* Application caller is present, perform API mapping.  */
531 
532 /* Determine if error checking is desired.  If so, map DHCP API functions
533    to the appropriate error checking front-ends.  Otherwise, map API
534    functions to the core functions that actually perform the work.
535    Note: error checking is enabled by default.  */
536 
537 #ifdef NX_DISABLE_ERROR_CHECKING
538 
539 /* Services without error checking.  */
540 
541 #define nx_dhcp_server_create                  _nx_dhcp_server_create
542 #define nx_dhcp_create_server_ip_address_list  _nx_dhcp_create_server_ip_address_list
543 #define nx_dhcp_set_interface_network_parameters  _nx_dhcp_set_interface_network_parameters
544 #define nx_dhcp_server_delete                  _nx_dhcp_server_delete
545 #define nx_dhcp_server_start                   _nx_dhcp_server_start
546 #define nx_dhcp_server_stop                    _nx_dhcp_server_stop
547 #define nx_dhcp_clear_client_record            _nx_dhcp_clear_client_record
548 
549 #else
550 
551 /* Services with error checking.  */
552 
553 #define nx_dhcp_server_create                  _nxe_dhcp_server_create
554 #define nx_dhcp_create_server_ip_address_list  _nxe_dhcp_create_server_ip_address_list
555 #define nx_dhcp_set_interface_network_parameters  _nxe_dhcp_set_interface_network_parameters
556 #define nx_dhcp_server_delete                  _nxe_dhcp_server_delete
557 #define nx_dhcp_server_start                   _nxe_dhcp_server_start
558 #define nx_dhcp_server_stop                    _nxe_dhcp_server_stop
559 #define nx_dhcp_clear_client_record            _nxe_dhcp_clear_client_record
560 #endif
561 
562 /* Define the prototypes accessible to the application software.  */
563 
564 UINT        nx_dhcp_server_create(NX_DHCP_SERVER *dhcp_ptr, NX_IP *ip_ptr, VOID *stack_ptr, ULONG stack_size, CHAR *name_ptr, NX_PACKET_POOL *packet_pool);
565 UINT        nx_dhcp_create_server_ip_address_list(NX_DHCP_SERVER *dhcp_ptr, UINT iface_index, ULONG start_ip_address, ULONG end_ip_address, UINT *addresses_added);
566 UINT        nx_dhcp_set_interface_network_parameters(NX_DHCP_SERVER *dhcp_ptr, UINT iface_index,  ULONG subnet_mask, ULONG default_gateway_address, ULONG dns_server_address);
567 UINT        nx_dhcp_server_delete(NX_DHCP_SERVER *dhcp_ptr);
568 UINT        nx_dhcp_server_start(NX_DHCP_SERVER *dhcp_ptr);
569 UINT        nx_dhcp_server_stop(NX_DHCP_SERVER *dhcp_ptr);
570 UINT        nx_dhcp_clear_client_record(NX_DHCP_SERVER *dhcp_ptr, NX_DHCP_CLIENT *dhcp_client_ptr);
571 
572 #else
573 
574 /* DHCP source code is being compiled, do not perform any API mapping.  */
575 
576 
577 UINT        _nxe_dhcp_server_create(NX_DHCP_SERVER *dhcp_ptr, NX_IP *ip_ptr, VOID *stack_ptr, ULONG stack_size, CHAR *name_ptr, NX_PACKET_POOL *packet_pool);
578 UINT        _nx_dhcp_server_create(NX_DHCP_SERVER *dhcp_ptr, NX_IP *ip_ptr, VOID *stack_ptr, ULONG stack_size, CHAR *name_ptr, NX_PACKET_POOL *packet_pool);
579 UINT        _nx_dhcp_create_server_ip_address_list(NX_DHCP_SERVER *dhcp_ptr, UINT iface_index, ULONG start_ip_address, ULONG end_ip_address, UINT *addresses_added);
580 UINT        _nxe_dhcp_create_server_ip_address_list(NX_DHCP_SERVER *dhcp_ptr, UINT iface_index, ULONG start_ip_address, ULONG end_ip_address, UINT *addresses_added);
581 UINT        _nxe_dhcp_set_interface_network_parameters(NX_DHCP_SERVER *dhcp_ptr, UINT iface_index,  ULONG subnet_mask, ULONG default_gateway_address, ULONG dns_server_address);
582 UINT        _nx_dhcp_set_interface_network_parameters(NX_DHCP_SERVER *dhcp_ptr, UINT iface_index,  ULONG subnet_mask, ULONG default_gateway_address, ULONG dns_server_address);
583 UINT        _nxe_dhcp_server_delete(NX_DHCP_SERVER *dhcp_ptr);
584 UINT        _nx_dhcp_server_delete(NX_DHCP_SERVER *dhcp_ptr);
585 UINT        _nxe_dhcp_server_start(NX_DHCP_SERVER *dhcp_ptr);
586 UINT        _nx_dhcp_server_start(NX_DHCP_SERVER *dhcp_ptr);
587 UINT        _nxe_dhcp_server_stop(NX_DHCP_SERVER *dhcp_ptr);
588 UINT        _nx_dhcp_server_stop(NX_DHCP_SERVER *dhcp_ptr);
589 UINT        _nxe_dhcp_clear_client_record(NX_DHCP_SERVER *dhcp_ptr, NX_DHCP_CLIENT *dhcp_client_ptr);
590 UINT        _nx_dhcp_clear_client_record(NX_DHCP_SERVER *dhcp_ptr, NX_DHCP_CLIENT *dhcp_client_ptr);
591 
592 
593 #endif
594 
595 /* Determine if a C++ compiler is being used.  If so, complete the standard
596    C conditional started above.  */
597 #ifdef   __cplusplus
598 }
599 #endif  /* __cplusplus */
600 
601 #endif  /* NXD_DHCP_SERVER_H */
602