1 
2 #include   "tx_api.h"
3 #include   "nx_api.h"
4 #include   "nx_api.h"
5 
6 extern void    test_control_return(UINT status);
7 
8 #if !defined(NX_DISABLE_ERROR_CHECKING) && defined(__PRODUCT_NETXDUO__) && !defined(NX_DISABLE_IPV4)
9 #include   "nxd_dhcp_client.h"
10 #include   "nxd_dhcp_server.h"
11 #include   "tx_timer.h"
12 #include   "tx_thread.h"
13 #include   "tx_mutex.h"
14 #include   "tx_event_flags.h"
15 
16 #define     DEMO_STACK_SIZE             4096
17 #define     NX_PACKET_SIZE              1536
18 #define     NX_PACKET_POOL_SIZE         NX_PACKET_SIZE * 8
19 
20 #define     NX_DHCP_SERVER_IP_ADDRESS_0 IP_ADDRESS(10,0,0,1)
21 #define     START_IP_ADDRESS_LIST_0     IP_ADDRESS(10,0,0,10)
22 #define     END_IP_ADDRESS_LIST_0       IP_ADDRESS(10,0,0,19)
23 
24 #define     NX_DHCP_SUBNET_MASK_0       IP_ADDRESS(255,255,255,0)
25 #define     NX_DHCP_DEFAULT_GATEWAY_0   IP_ADDRESS(10,0,0,1)
26 #define     NX_DHCP_DNS_SERVER_0        IP_ADDRESS(10,0,0,1)
27 
28 #define     DHCP_TEST_LONG_NAME         "dhcp_client_make_the_string_length_exceed_255_to_test_the_corner_case_in_function \
29                                          netx_dhcp_send_request_internal__________________________________________________ \
30                                          _________________________________________________________________________________ \
31                                          _________________________________________________________________________________ \
32                                          _________________________________________________________________________________ \
33                                          _________________________________________________________________________________ \
34                                          _________________________________________________________________________________ \
35                                          _________________________________________________________________________________"
36 
37 #define     NX_DHCP_OPTION_ARP_TIMEOUT  35
38 
39 /* If defined, the host requests a (previous) client IP address. */
40 /*
41 #define REQUEST_CLIENT_IP
42 */
43 
44 /* If defined the client requests to jump to the boot state and skip the DISCOVER message.
45    If REQUEST_CLIENT_IP is not defined, this has no effect. */
46 /*
47 #define SKIP_DISCOVER_MESSAGE
48 */
49 
50 /* Define the ThreadX and NetX object control blocks...  */
51 static TX_THREAD               client_thread;
52 static NX_PACKET_POOL          client_pool;
53 static NX_IP                   client_ip;
54 static NX_DHCP                 dhcp_client;
55 static NX_DHCP                 dhcp_client2;
56 static NX_DHCP                 dhcp_client3;
57 static ULONG dhcp_your_address = 0;
58 
59 /* Frame (342 bytes) */
60 static unsigned char option_message[60] = {
61 0x35, 0x01, 0x02,                               /* DHCP message type */
62 0x01, 0x04, 0xff, 0xff, 0xff, 0x00,             /* Subnet Mask */
63 0x36, 0x04, 0xe0, 0xa8, 0x02, 0x01,             /* Server identifier */
64 0x33, 0x04, 0xff, 0xff, 0xff, 0xff,             /* IP address lease time */
65 0x03, 0x04, 0xc0, 0x02, 0x00, 0x00,             /* Router/gateway */
66 0x06, 0x04, 0xc0, 0xa8, 0x02, 0x01,             /* DNS server */
67 0x2a, 0x04, 0x7c, 0x6c, 0x14, 0x01,             /* NTP server */
68 0x3a, 0x04, 0xff, 0xff, 0xff, 0xff,             /* Renewal time */
69 0x3b, 0x04, 0xff, 0xff, 0xff, 0xff,             /* Rebind time */
70 0x23, 0x04, 0x00, 0x00, 0x01, 0x02,             /* ........ */
71 0xff, 0x00, 0x00
72 };
73 
74 /* Define the counters used in the demo application...  */
75 
76 static ULONG                   state_changes;
77 static ULONG                   error_counter;
78 static CHAR                    *pointer;
79 
80 extern VOID  _nx_dhcp_packet_process(NX_DHCP *dhcp_ptr, NX_DHCP_INTERFACE_RECORD *interface_record, NX_PACKET *packet_ptr);
81 extern UINT  _nx_dhcp_packet_pool_set(NX_DHCP *dhcp_ptr, NX_PACKET_POOL *packet_pool_ptr);
82 extern UINT  _nx_dhcp_decline(NX_DHCP *dhcp_ptr);
83 /* Define thread prototypes.  */
84 
85 static void    client_thread_entry(ULONG thread_input);
86 static void    dhcp_state_change(NX_DHCP *dhcp_ptr, UCHAR new_state);
87 
88 /******** Optionally substitute your Ethernet driver here. ***********/
89 extern void    _nx_ram_network_driver_1024(struct NX_IP_DRIVER_STRUCT *driver_req);
90 
91 /* Define what the initial system looks like.  */
92 
93 #ifdef CTEST
test_application_define(void * first_unused_memory)94 VOID test_application_define(void *first_unused_memory)
95 #else
96 void    netx_dhcp_coverage_test_applicaiton_define(void *first_unused_memory)
97 #endif
98 {
99 
100 UINT    status;
101 
102 
103     /* Setup the working pointer.  */
104     pointer =  (CHAR *) first_unused_memory;
105 
106     /* Create the client thread.  */
107     tx_thread_create(&client_thread, "thread client", client_thread_entry, 0,
108             pointer, DEMO_STACK_SIZE,
109             4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
110     pointer =  pointer + DEMO_STACK_SIZE;
111 
112     /* Initialize the NetX system.  */
113     nx_system_initialize();
114 
115     /* Create the client packet pool.  */
116     status =  nx_packet_pool_create(&client_pool, "NetX Main Packet Pool", 1024, pointer, NX_PACKET_POOL_SIZE);
117     pointer = pointer + NX_PACKET_POOL_SIZE;
118 
119     /* Check for pool creation error.  */
120     if (status)
121         error_counter++;
122 
123     /* Create an IP instance for the DHCP Client.  */
124     status = nx_ip_create(&client_ip, "DHCP Client", IP_ADDRESS(0, 0, 0, 0), 0xFFFFFF00UL, &client_pool, _nx_ram_network_driver_1024, pointer, 2048, 1);
125 
126     pointer =  pointer + 2048;
127 
128     /* Check for IP create errors.  */
129     if (status)
130         error_counter++;
131 
132     /* Enable UDP traffic.  */
133     status =  nx_udp_enable(&client_ip);
134 
135     /* Check for UDP enable errors.  */
136     if (status)
137         error_counter++;
138 
139     return;
140 }
141 
state_change_cb(NX_DHCP * dhcp_ptr,UCHAR state)142 static void state_change_cb(NX_DHCP *dhcp_ptr, UCHAR state)
143 {
144     return;
145 }
146 
dhcp_user_option_add_with_false_return(NX_DHCP * dhcp_ptr,UINT iface_index,UINT message_type,UCHAR * user_option_ptr,UINT * user_option_length)147 static UINT dhcp_user_option_add_with_false_return(NX_DHCP *dhcp_ptr, UINT iface_index, UINT message_type, UCHAR *user_option_ptr, UINT *user_option_length)
148 {
149     return NX_FALSE;
150 }
151 
dhcp_user_option_add(NX_DHCP * dhcp_ptr,UINT iface_index,UINT message_type,UCHAR * user_option_ptr,UINT * user_option_length)152 static UINT dhcp_user_option_add(NX_DHCP *dhcp_ptr, UINT iface_index, UINT message_type, UCHAR *user_option_ptr, UINT *user_option_length)
153 {
154     *user_option_length = 301;
155 
156     return NX_TRUE;
157 }
158 
interface_state_change_cb(NX_DHCP * dhcp_ptr,UINT iface,UCHAR state)159 static void interface_state_change_cb(NX_DHCP *dhcp_ptr, UINT iface, UCHAR state)
160 {
161     return;
162 }
163 
create_dhcp_packet(int length)164 static NX_PACKET * create_dhcp_packet(int length)
165 {
166     NX_PACKET* packet_ptr;
167 #ifdef __PRODUCT_NETXDUO__
168     nx_packet_allocate(&client_pool, &packet_ptr, NX_IPv4_UDP_PACKET, NX_NO_WAIT);
169 #else
170     nx_packet_allocate(&client_pool, &packet_ptr, NX_UDP_PACKET, NX_NO_WAIT);
171 #endif
172 #ifdef __PRODUCT_NETXDUO__
173     packet_ptr->nx_packet_ip_version = NX_IP_VERSION_V4;
174 #endif
175     packet_ptr->nx_packet_queue_next = NX_NULL;
176     packet_ptr->nx_packet_length = length;
177 #ifdef __PRODUCT_NETXDUO__
178     packet_ptr->nx_packet_address.nx_packet_interface_ptr = &client_ip.nx_ip_interface[0];
179 #else
180     packet_ptr->nx_packet_ip_interface = &client_ip.nx_ip_interface[0];
181 #endif
182 #ifdef __PRODUCT_NETXDUO__
183     packet_ptr->nx_packet_ip_header = packet_ptr->nx_packet_prepend_ptr - sizeof(NX_IPV4_HEADER);
184 #endif
185     packet_ptr->nx_packet_append_ptr += packet_ptr->nx_packet_length;
186     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_XID] = ((dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_xid) >> 24) & 0xFF;
187     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_XID + 1] = ((dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_xid) >> 16) & 0xFF;
188     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_XID + 2] = ((dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_xid) >> 8) & 0xFF;
189     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_XID + 3] = (dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_xid) & 0xFF;
190     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW] = 0;
191     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW + 1] = 0x11;
192     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW + 2] = 0x22;
193     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW + 3] = 0x33;
194     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW + 4] = 0x44;
195     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW + 5] = 0x56;
196     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_YOUR_IP] = dhcp_your_address >> 24;
197     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_YOUR_IP + 1] = (dhcp_your_address >> 16) & 0xFF ;
198     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_YOUR_IP + 2] = (dhcp_your_address >> 8) & 0xFF;
199     packet_ptr->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_YOUR_IP + 3] = dhcp_your_address & 0xFF;
200 
201     dhcp_client.nx_dhcp_socket.nx_udp_socket_receive_head = packet_ptr;
202     dhcp_client.nx_dhcp_socket.nx_udp_socket_receive_count++;
203     packet_ptr->nx_packet_prepend_ptr -=8;
204     packet_ptr->nx_packet_length += 8;
205     return(packet_ptr);
206 
207 }
208 
build_dhcp_packet(int length,UCHAR option_type,UCHAR val_len,UCHAR val)209 static NX_PACKET * build_dhcp_packet(int length, UCHAR option_type, UCHAR val_len,  UCHAR val)
210 {
211     NX_PACKET *my_packet;
212 
213     my_packet = create_dhcp_packet(length);
214     my_packet->nx_packet_prepend_ptr[8+NX_BOOTP_OFFSET_OPTIONS]=option_type;
215     my_packet->nx_packet_prepend_ptr[8+NX_BOOTP_OFFSET_OPTIONS+1]=val_len;
216     my_packet->nx_packet_prepend_ptr[8+NX_BOOTP_OFFSET_OPTIONS+2]=val;
217 
218     return(my_packet);
219 }
220 
221 extern VOID _nx_dhcp_timeout_process(NX_DHCP* dhcp_ptr);
222 extern TX_THREAD _tx_timer_thread;
223 /* Define the test threads.  */
client_thread_entry(ULONG thread_input)224 void    client_thread_entry(ULONG thread_input)
225 {
226 ULONG       current_system_state;
227 TX_THREAD  *current_thread_ptr;
228 UCHAR       buffer[4];
229 UINT        buffer_size = 4;
230 ULONG       long_val;
231 ULONG       payload_size = 0;
232 
233 #ifdef REQUEST_CLIENT_IP
234 ULONG       requested_ip;
235 #endif
236 
237 TX_TIMER *timer_ptr;
238 TX_MUTEX *mutex_ptr;
239 TX_THREAD *thread_ptr;
240 TX_EVENT_FLAGS_GROUP *event_flags;
241 NX_PACKET *my_packet = NX_NULL;
242     printf("NetX Test:   DHCP coverage Test........................................");
243 
244     /* Force timer create to fail. */
245     timer_ptr = _tx_timer_created_ptr;
246     _tx_timer_created_ptr = &dhcp_client.nx_dhcp_timer;
247     _tx_timer_created_count++;
248 
249     /* Create the DHCP instance.  */
250     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
251 
252     /* Restore the timer structure. */
253     _tx_timer_created_ptr = timer_ptr;
254     _tx_timer_created_count--;
255 
256     /*  Force mutex create to fail. */
257     mutex_ptr = _tx_mutex_created_ptr;
258     _tx_mutex_created_ptr = &dhcp_client.nx_dhcp_mutex;
259     _tx_mutex_created_count++;
260     /* Create the DHCP instance.  */
261     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
262 
263     /* Restore mutex. */
264     _tx_mutex_created_ptr = mutex_ptr;
265     _tx_mutex_created_count--;
266 
267     /* Force Thread create to fail.*/
268     thread_ptr = _tx_thread_created_ptr;
269     _tx_thread_created_ptr = &dhcp_client.nx_dhcp_thread;
270     _tx_thread_created_count++;
271     /* Create the DHCP instance.  */
272     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
273 
274     /* Restore thread list. */
275     _tx_thread_created_ptr = thread_ptr;
276     _tx_thread_created_count--;
277 
278     /* Force event flag create to fail */
279     event_flags = _tx_event_flags_created_ptr;
280     _tx_event_flags_created_count ++;
281     _tx_event_flags_created_ptr = &dhcp_client.nx_dhcp_events;
282     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
283 
284 
285     /* Restore event flasg */
286     _tx_event_flags_created_ptr = event_flags;
287     _tx_event_flags_created_count--;
288 
289     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
290     nx_dhcp_stop(&dhcp_client);
291 
292     /* All done. Return resources to NetX and ThreadX. */
293     nx_dhcp_delete(&dhcp_client);
294 
295     /* Test nx_dhcp_interface_clear_broadcast_flag */
296     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
297 
298     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
299     nx_dhcp_interface_clear_broadcast_flag(&dhcp_client, 0, 0);
300 
301     /* Enable one record */
302     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
303     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_interface_index = 0;
304     nx_dhcp_interface_clear_broadcast_flag(&dhcp_client, 0, 0);
305 
306 #ifdef NX_DHCP_CLIENT_USER_CREATE_PACKET_POOL
307     /* Cover _nx_dhcp_packet_pool_set */
308     nx_dhcp_packet_pool_set(&dhcp_client, NX_NULL);
309     _nx_dhcp_packet_pool_set(&dhcp_client, NX_NULL);
310     nx_dhcp_packet_pool_set(&dhcp_client, &client_pool);
311 #endif
312 
313     /* Cover _nxe_dhcp_reinitialize */
314     nx_dhcp_reinitialize(&dhcp_client);
315 
316     /* Cover nx_dhcp_interface_reinitialize */
317     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
318     nx_dhcp_interface_reinitialize(&dhcp_client, 0);
319     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
320     nx_dhcp_interface_reinitialize(&dhcp_client, 0);
321 
322 
323     /* Cover nx_dhcp_(interface_)request_client_ip */
324     nx_dhcp_request_client_ip(&dhcp_client, 1, 0);
325     nx_dhcp_interface_request_client_ip(&dhcp_client, 0, 1, 0);
326     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
327     nx_dhcp_request_client_ip(&dhcp_client, 1, 0);
328     nx_dhcp_interface_request_client_ip(&dhcp_client, 0, 1, 0);
329 
330 
331     /* Cover nx_dhcp_force_renew */
332     dhcp_client.nx_dhcp_id = NX_DHCP_ID;
333     nx_dhcp_force_renew(&dhcp_client);
334     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
335     nx_dhcp_force_renew(&dhcp_client);
336     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
337     nx_dhcp_force_renew(&dhcp_client);
338 
339     /* Cover nx_dhcp_interface_force_renew */
340     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
341     nx_dhcp_interface_force_renew(&dhcp_client, 0);
342     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
343     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
344     nx_dhcp_interface_force_renew(&dhcp_client, 0);
345     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
346     dhcp_client.nx_dhcp_state_change_callback = state_change_cb;
347     dhcp_client.nx_dhcp_interface_state_change_callback = interface_state_change_cb;
348     nx_dhcp_interface_force_renew(&dhcp_client, 0);
349 
350     /* Cover _nx_dhcp_update_renewal_timeout through calling nx_dhcp_interface_force_renew */
351     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
352     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_rebind_time = 8000;
353     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_renewal_time = 1000;
354     nx_dhcp_interface_force_renew(&dhcp_client, 0);
355 
356     /* Cover the static function _nx_dhcp_send_request_interval through calling API functions */
357     payload_size = dhcp_client.nx_dhcp_packet_pool_ptr->nx_packet_pool_payload_size;
358     dhcp_client.nx_dhcp_packet_pool_ptr->nx_packet_pool_payload_size = 0;
359     nx_dhcp_interface_force_renew(&dhcp_client, 0);
360     dhcp_client.nx_dhcp_packet_pool_ptr->nx_packet_pool_payload_size = payload_size;
361     dhcp_client.nx_dhcp_name = DHCP_TEST_LONG_NAME;
362     nx_dhcp_interface_force_renew(&dhcp_client, 0);
363     dhcp_client.nx_dhcp_name = "dhcp_client";
364     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_ip_address = NX_BOOTP_BC_ADDRESS;
365     nx_dhcp_interface_force_renew(&dhcp_client, 0);
366     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_server_ip = NX_BOOTP_BC_ADDRESS;
367     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
368     nx_dhcp_send_request(&dhcp_client, NX_DHCP_TYPE_DHCPREQUEST);
369     dhcp_client.nx_dhcp_name = NULL;
370     nx_dhcp_send_request(&dhcp_client, NX_DHCP_TYPE_DHCPINFORM);
371     dhcp_client.nx_dhcp_name = DHCP_TEST_LONG_NAME;
372     nx_dhcp_send_request(&dhcp_client, NX_DHCP_TYPE_DHCPINFORM);
373     nx_dhcp_user_option_add_callback_set(&dhcp_client, dhcp_user_option_add_with_false_return);
374     nx_dhcp_send_request(&dhcp_client, NX_DHCP_TYPE_DHCPINFORM);
375     dhcp_client.nx_dhcp_name = DHCP_TEST_LONG_NAME;
376     nx_dhcp_send_request(&dhcp_client, NX_DHCP_TYPE_DHCPDISCOVER);
377     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_ip_address = 1;
378     nx_dhcp_decline(&dhcp_client);
379     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_ip_address = NX_BOOTP_BC_ADDRESS;
380     nx_dhcp_decline(&dhcp_client);
381     nx_dhcp_user_option_add_callback_set(&dhcp_client, dhcp_user_option_add);
382     nx_dhcp_send_request(&dhcp_client, NX_DHCP_TYPE_DHCPINFORM);
383 
384     /* Cover nx_dhcp_decline */
385     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
386     nx_dhcp_decline(&dhcp_client);
387     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
388     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
389     nx_dhcp_decline(&dhcp_client);
390     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
391     nx_dhcp_decline(&dhcp_client);
392     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
393     nx_dhcp_interface_decline(&dhcp_client, 0);
394     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
395     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
396     nx_dhcp_interface_decline(&dhcp_client, 0);
397     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
398     dhcp_client.nx_dhcp_state_change_callback = NX_NULL;
399     dhcp_client.nx_dhcp_interface_state_change_callback = NX_NULL;
400     nx_dhcp_interface_decline(&dhcp_client, 0);
401 
402     /* Test _nx_dhcp_release */
403     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
404     nx_dhcp_release(&dhcp_client);
405 
406     /* Test nx_dhcp_interface_start */
407     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
408     nx_dhcp_interface_start(&dhcp_client, 0);
409 
410     /* Test nx_dhcp_interface_release */
411     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
412     nx_dhcp_interface_release(&dhcp_client, 0);
413     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
414     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
415     nx_dhcp_interface_release(&dhcp_client, 0);
416     dhcp_client.nx_dhcp_state_change_callback = state_change_cb;
417     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
418     nx_dhcp_interface_release(&dhcp_client, 0);
419 
420     /* Test nx_dhcp_interface_stop */
421     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
422     nx_dhcp_interface_stop(&dhcp_client, 0);
423     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_NOT_STARTED;
424     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
425     nx_dhcp_interface_stop(&dhcp_client, 0);
426 
427     /* Test nx_dhcp_user_option_retrieve*/
428     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
429     buffer_size = sizeof(buffer);
430     nx_dhcp_user_option_retrieve(&dhcp_client, 0, buffer, &buffer_size);
431     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
432     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
433     buffer_size = sizeof(buffer);
434     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, buffer, &buffer_size);
435     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
436     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
437     buffer_size = sizeof(buffer);
438     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, buffer, &buffer_size);
439     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
440     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, buffer, &buffer_size);
441     buffer_size = 1;
442     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
443     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_options_size = 4;
444     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0, buffer, &buffer_size);
445     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_options_buffer[0] = 1;
446     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_options_buffer[1] = 2;
447     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 1, buffer, &buffer_size);
448     buffer_size = 4;
449     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_options_buffer[0] = 0xFF;
450     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 0xFF, buffer, &buffer_size);
451 
452     /* Test _nx_dhcp_search_buffer through nx_dhcp_interface_user_option_retrieve */
453     dhcp_client.nx_dhcp_interface_record->nx_dhcp_options_buffer[0] = 1;
454     dhcp_client.nx_dhcp_interface_record->nx_dhcp_options_buffer[1] = 5;
455     dhcp_client.nx_dhcp_interface_record->nx_dhcp_options_size = 4;
456     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, 1, buffer, &buffer_size);
457     memcpy(dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_options_buffer, option_message, 60);
458     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_options_size = 60;
459     nx_dhcp_interface_user_option_retrieve(&dhcp_client, 0, NX_DHCP_OPTION_ARP_TIMEOUT, buffer, &buffer_size);
460 
461     /* Test _nx_dhcp_interface_disable*/
462     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
463     nx_dhcp_interface_disable(&dhcp_client, 0);
464 
465     /* Test _nx_dhcp_user_option_retrieve*/
466     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
467     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
468     nx_dhcp_user_option_retrieve(&dhcp_client, 0, NX_NULL, NX_NULL);
469 
470     /* Test nx_dhcp_user_option_convert*/
471     long_val = nx_dhcp_user_option_convert(buffer);
472 
473     /* Test nx_dhcp_send_request*/
474     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
475     nx_dhcp_send_request(&dhcp_client, 1);
476 
477     /* Test nx_dhcp_interface_send_request*/
478     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
479     nx_dhcp_interface_send_request(&dhcp_client, 0, 0);
480     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
481     nx_dhcp_interface_send_request(&dhcp_client, 0, NX_DHCP_TYPE_DHCPRELEASE);
482     nx_dhcp_interface_send_request(&dhcp_client, 0, NX_DHCP_TYPE_DHCPDECLINE);
483     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_NOT_STARTED;
484     nx_dhcp_interface_send_request(&dhcp_client, 0, NX_DHCP_TYPE_DHCPACK);
485     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
486     nx_dhcp_interface_send_request(&dhcp_client, 0, NX_DHCP_TYPE_DHCPACK);
487 
488     /*Test nx_dhcp_server_address_get*/
489     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
490     nx_dhcp_server_address_get(&dhcp_client, &long_val);
491     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
492     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
493     nx_dhcp_server_address_get(&dhcp_client, &long_val);
494     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
495     nx_dhcp_server_address_get(&dhcp_client, &long_val);
496 
497     /* Test nx_dhcp_interface_server_address_get*/
498     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
499     nx_dhcp_interface_server_address_get(&dhcp_client, 0, &long_val);
500     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
501     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND;
502     nx_dhcp_interface_server_address_get(&dhcp_client, 0, &long_val);
503     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOUND - 1;
504     nx_dhcp_interface_server_address_get(&dhcp_client, 0, &long_val);
505 
506     /* Test DHCP delete */
507     current_system_state = _tx_thread_system_state;
508     _tx_thread_system_state = 1;
509     nx_dhcp_delete(&dhcp_client);
510     _tx_thread_system_state = current_system_state;
511     current_thread_ptr = _tx_thread_current_ptr;
512     _tx_thread_current_ptr = TX_NULL;
513     nx_dhcp_delete(&dhcp_client);
514     _tx_thread_current_ptr = &_tx_timer_thread;
515     nx_dhcp_delete(&dhcp_client);
516     _tx_thread_current_ptr = current_thread_ptr;
517     nx_dhcp_delete(&dhcp_client);
518 
519     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
520     nx_dhcp_create(&dhcp_client2, &client_ip, "dhcp_client2");
521     nx_dhcp_create(&dhcp_client3, &client_ip, "dhcp_client3");
522 
523     nx_dhcp_delete(&dhcp_client);
524     nx_dhcp_delete(&dhcp_client2);
525     nx_dhcp_delete(&dhcp_client3);
526 
527 
528     current_system_state = _tx_thread_system_state;
529     _tx_thread_system_state = 1;
530     nx_dhcp_force_renew(&dhcp_client);
531     _tx_thread_system_state = current_system_state;
532     current_thread_ptr = _tx_thread_current_ptr;
533     _tx_thread_current_ptr = TX_NULL;
534     nx_dhcp_force_renew(&dhcp_client);
535     _tx_thread_current_ptr = &_tx_timer_thread;
536     nx_dhcp_force_renew(&dhcp_client);
537     _tx_thread_current_ptr = current_thread_ptr;
538     nx_dhcp_force_renew(&dhcp_client);
539     nx_dhcp_delete(&dhcp_client);
540     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
541     /* Force nx_dhcp_start to fail. */
542     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_FALSE;
543 
544     /* Start the DHCP Client.  */
545     nx_dhcp_start(&dhcp_client);
546 
547     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
548     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_BOOT;
549     /* Start the DHCP Client.  */
550     nx_dhcp_start(&dhcp_client);
551 
552     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = 0;
553     dhcp_client.nx_dhcp_socket.nx_udp_socket_bind_in_progress = _tx_thread_current_ptr;
554     /* Start the DHCP Client.  */
555     nx_dhcp_start(&dhcp_client);
556     dhcp_client.nx_dhcp_socket.nx_udp_socket_bind_in_progress = TX_NULL;
557     dhcp_client.nx_dhcp_thread.tx_thread_id = 0;
558     nx_dhcp_start(&dhcp_client);
559     dhcp_client.nx_dhcp_thread.tx_thread_id = TX_THREAD_ID;
560     dhcp_client.nx_dhcp_timer.tx_timer_id = 0;
561     nx_dhcp_start(&dhcp_client);
562     dhcp_client.nx_dhcp_timer.tx_timer_id = TX_TIMER_ID;
563     nx_dhcp_delete(&dhcp_client);
564 
565     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
566 
567     /* Test nx_dhcp_interface_enable */
568     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_record_valid = NX_TRUE;
569     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_interface_index = 0;
570     nx_dhcp_interface_enable(&dhcp_client, 0);
571     dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_interface_index = 1;
572 #if(NX_MAX_PHYSICAL_INTERFACES > 1)
573     dhcp_client.nx_dhcp_interface_record[1].nx_dhcp_record_valid = NX_TRUE;
574     dhcp_client.nx_dhcp_interface_record[1].nx_dhcp_interface_index = 2;
575 #endif
576     nx_dhcp_interface_enable(&dhcp_client, 0);
577     nx_dhcp_delete(&dhcp_client);
578 
579     /* Test nx_dhcp_packet_process */
580     nx_dhcp_create(&dhcp_client, &client_ip, "dhcp_client");
581     nx_dhcp_start(&dhcp_client);
582     dhcp_client.nx_dhcp_socket.nx_udp_socket_disable_checksum = NX_TRUE;
583 
584 #ifndef NX_ENABLE_INTERFACE_CAPABILITY
585     /* Inject a packet that causes nx_udp_packet_info_extract() to fail. */
586     my_packet = create_dhcp_packet(30);
587 #ifdef __PRODUCT_NETXDUO__
588     my_packet->nx_packet_ip_version = 0;
589 #endif
590     tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
591     tx_thread_sleep(1);
592 #endif /* NX_ENABLE_INTERFACE_CAPABILITY */
593 
594     /* Now test nx_dhcp_packet_process, test failures on the 1st check. */
595     my_packet = create_dhcp_packet(30);
596 #ifdef __PRODUCT_NETXDUO__
597     my_packet->nx_packet_ip_version = NX_IP_VERSION_V4;
598 #endif
599     dhcp_client.nx_dhcp_socket.nx_udp_socket_receive_head = my_packet;
600     dhcp_client.nx_dhcp_socket.nx_udp_socket_receive_count++;
601     tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
602     tx_thread_sleep(1);
603 
604 #ifdef NX_DHCP_CLIENT_USER_CREATE_PACKET_POOL
605     nx_dhcp_packet_pool_set(&dhcp_client, &client_pool);
606 #endif
607 
608     /* Attempt to cause the DHCP internal packet allocate to fail.*/
609     {
610         UINT status;
611         NX_PACKET* packet1, * packet2, * packet3, * packet4, * packet5;
612 #ifdef __PRODUCT_NETXDUO__
613         status = nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet1, NX_IPv4_UDP_PACKET, NX_NO_WAIT);
614         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet2, NX_IPv4_UDP_PACKET, NX_NO_WAIT);
615         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet3, NX_IPv4_UDP_PACKET, NX_NO_WAIT);
616         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet4, NX_IPv4_UDP_PACKET, NX_NO_WAIT);
617         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet5, NX_IPv4_UDP_PACKET, NX_NO_WAIT);
618 #else
619         status = nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet1, NX_UDP_PACKET, NX_NO_WAIT);
620         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet2, NX_UDP_PACKET, NX_NO_WAIT);
621         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet3, NX_UDP_PACKET, NX_NO_WAIT);
622         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet4, NX_UDP_PACKET, NX_NO_WAIT);
623         status += nx_packet_allocate(dhcp_client.nx_dhcp_packet_pool_ptr, &packet5, NX_UDP_PACKET, NX_NO_WAIT);
624 #endif
625 
626         my_packet = create_dhcp_packet(1000);
627         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
628         tx_thread_sleep(1);
629 
630         nx_packet_release(packet1); nx_packet_release(packet2); nx_packet_release(packet3); nx_packet_release(packet4); nx_packet_release(packet5);
631 
632     }
633 
634     /* Attemp to send a bigger packet to test the case incoming packet bigger than DHCP packets.*/
635     my_packet = create_dhcp_packet(1000);
636     tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
637     tx_thread_sleep(1);
638 
639     my_packet = create_dhcp_packet(400);
640     my_packet->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW + 1] = 2;
641     tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
642     tx_thread_sleep(1);
643 
644     my_packet = create_dhcp_packet(400);
645     my_packet->nx_packet_prepend_ptr[NX_BOOTP_OFFSET_CLIENT_HW + 5] = 0x55;
646     tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
647     tx_thread_sleep(1);
648 
649     {
650         build_dhcp_packet(400, 0, 0, 0);
651         /* intentionally set incorrect state.*/
652         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_ADDRESS_PROBING + 1;
653         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
654         tx_thread_sleep(1);
655     }
656     {
657         build_dhcp_packet(400, 0, 0, 0);
658         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_SELECTING;
659         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
660         tx_thread_sleep(1);
661     }
662     {
663 
664         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPOFFER+1);
665         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_SELECTING;
666         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
667         tx_thread_sleep(1);
668     }
669     {
670 
671         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPOFFER);
672         dhcp_your_address = 0;
673         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_SELECTING;
674         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
675         tx_thread_sleep(1);
676 
677 
678         dhcp_your_address = 0xFFFFFFFF;
679         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPOFFER);
680         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_SELECTING;
681         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
682         tx_thread_sleep(1);
683 
684         dhcp_your_address = 0x7F010001;
685         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPOFFER);
686         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_SELECTING;
687         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
688         tx_thread_sleep(1);
689 
690         dhcp_your_address = 0x80010001;
691         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPOFFER);
692         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_SELECTING;
693         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
694         tx_thread_sleep(1);
695 
696         dhcp_your_address = 0xC0010100;
697         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPOFFER);
698         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_SELECTING;
699         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
700         tx_thread_sleep(1);
701     }
702     {
703 
704         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_SERVER, 1, NX_DHCP_TYPE_DHCPOFFER);
705         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REBINDING;
706         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
707         tx_thread_sleep(1);
708 
709         dhcp_your_address = 0;
710         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPACK);
711         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REBINDING;
712         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
713         tx_thread_sleep(1);
714 
715         dhcp_your_address = 0x10203040;
716         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPACK);
717         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REBINDING;
718         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
719         tx_thread_sleep(1);
720 
721         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPNACK);
722         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REBINDING;
723         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
724         tx_thread_sleep(1);
725 
726         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPRELEASE);
727 
728         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REBINDING;
729         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
730         tx_thread_sleep(1);
731 
732     }
733 
734     {
735         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_SERVER, 1, NX_DHCP_TYPE_DHCPOFFER);
736         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_RENEWING;
737         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
738         tx_thread_sleep(1);
739 
740         dhcp_your_address = 0;
741         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPACK);
742         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_RENEWING;
743         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
744         tx_thread_sleep(1);
745 
746         dhcp_your_address = 0x10203040;
747         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPACK);
748         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_RENEWING;
749         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
750         tx_thread_sleep(1);
751 
752         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPNACK);
753         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_RENEWING;
754         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
755         tx_thread_sleep(1);
756 
757         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPRELEASE);
758 
759         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_RENEWING;
760         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
761         tx_thread_sleep(1);
762     }
763 
764     {
765         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_SERVER, 1, NX_DHCP_TYPE_DHCPOFFER);
766         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
767         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
768         tx_thread_sleep(1);
769 
770         dhcp_your_address = 0;
771         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPACK);
772         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
773         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
774         tx_thread_sleep(1);
775 
776         dhcp_your_address = 0x10203040;
777         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPACK);
778         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
779         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
780         tx_thread_sleep(1);
781 
782         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPNACK);
783         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
784         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
785         tx_thread_sleep(1);
786 
787         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPRELEASE);
788         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
789         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
790         tx_thread_sleep(1);
791 
792         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPNACK);
793         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
794         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_timeout = 1;
795         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
796         tx_thread_sleep(1);
797 
798 
799         build_dhcp_packet(400, NX_DHCP_OPTION_DHCP_TYPE, 1, NX_DHCP_TYPE_DHCPNACK);
800         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
801         dhcp_client.nx_dhcp_interface_record[0].nx_dhcp_renewal_time = NX_IP_PERIODIC_RATE + 1;
802         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_RECEIVE_EVENT, TX_OR);
803         tx_thread_sleep(1);
804     }
805 
806     {
807         NX_DHCP_INTERFACE_RECORD *interface_record = &dhcp_client.nx_dhcp_interface_record[0];
808 
809         interface_record->nx_dhcp_record_valid = NX_TRUE;
810         interface_record->nx_dhcp_timeout = 1;
811         interface_record->nx_dhcp_state = NX_DHCP_STATE_INIT;
812         interface_record->nx_dhcp_ip_address = 1;
813         interface_record->nx_dhcp_skip_discovery = NX_FALSE;
814         interface_record->nx_dhcp_rtr_interval = 1;
815         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
816         tx_thread_sleep(1);
817 
818         interface_record->nx_dhcp_record_valid = NX_TRUE;
819         interface_record->nx_dhcp_timeout = 1;
820         interface_record->nx_dhcp_state = NX_DHCP_STATE_SELECTING;
821         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
822         tx_thread_sleep(1);
823 
824 
825         interface_record->nx_dhcp_record_valid = NX_TRUE;
826         interface_record->nx_dhcp_timeout = 1;
827         interface_record->nx_dhcp_state = NX_DHCP_STATE_REQUESTING;
828         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
829         tx_thread_sleep(1);
830 
831         interface_record->nx_dhcp_record_valid = NX_TRUE;
832         interface_record->nx_dhcp_timeout = 1;
833         interface_record->nx_dhcp_state = NX_DHCP_STATE_ADDRESS_PROBING;
834         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
835         tx_thread_sleep(1);
836 
837         interface_record->nx_dhcp_record_valid = NX_TRUE;
838         interface_record->nx_dhcp_timeout = 1;
839         interface_record->nx_dhcp_state = NX_DHCP_STATE_RENEWING;
840         interface_record->nx_dhcp_rtr_interval = 2;
841         interface_record->nx_dhcp_renewal_remain_time = 1;
842         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
843         tx_thread_sleep(1);
844 
845         interface_record->nx_dhcp_record_valid = NX_TRUE;
846         interface_record->nx_dhcp_timeout = 1;
847         interface_record->nx_dhcp_state = NX_DHCP_STATE_RENEWING;
848         interface_record->nx_dhcp_rtr_interval = 2;
849         interface_record->nx_dhcp_renewal_remain_time = 7;
850         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
851         tx_thread_sleep(1);
852 
853         interface_record->nx_dhcp_record_valid = NX_TRUE;
854         interface_record->nx_dhcp_timeout = 1;
855         interface_record->nx_dhcp_state = NX_DHCP_STATE_REBINDING;
856         interface_record->nx_dhcp_rtr_interval = 2;
857         interface_record->nx_dhcp_rebind_remain_time = 1;
858         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
859         tx_thread_sleep(1);
860 
861         interface_record->nx_dhcp_record_valid = NX_TRUE;
862         interface_record->nx_dhcp_timeout = 1;
863         interface_record->nx_dhcp_state = NX_DHCP_STATE_REBINDING;
864         interface_record->nx_dhcp_rtr_interval = 2;
865         interface_record->nx_dhcp_rebind_remain_time = 10;
866         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
867         tx_thread_sleep(1);
868 
869         interface_record->nx_dhcp_record_valid = NX_TRUE;
870         interface_record->nx_dhcp_timeout = 1;
871         interface_record->nx_dhcp_state = 0xFF;
872         interface_record->nx_dhcp_rtr_interval = 2;
873         interface_record->nx_dhcp_renewal_remain_time = 3;
874         tx_event_flags_set(&dhcp_client.nx_dhcp_events, NX_DHCP_CLIENT_TIMER_EVENT, TX_OR);
875         tx_thread_sleep(1);
876 
877     }
878 
879     printf("SUCCESS!\n");
880     test_control_return(0);
881     return;
882 }
883 
884 
dhcp_state_change(NX_DHCP * dhcp_ptr,UCHAR new_state)885 void dhcp_state_change(NX_DHCP *dhcp_ptr, UCHAR new_state)
886 {
887 
888     /* Increment state changes counter.  */
889     state_changes++;
890 
891     return;
892 }
893 #else
894 
895 #ifdef CTEST
test_application_define(void * first_unused_memory)896 VOID test_application_define(void *first_unused_memory)
897 #else
898 void    netx_dhcp_coverage_test_applicaiton_define(void *first_unused_memory)
899 #endif
900 {
901 
902     /* Print out test information banner.  */
903     printf("NetX Test:   NetX DHCP Coverage Test...................................N/A\n");
904 
905     test_control_return(3);
906 }
907 #endif
908