1 
2 
3 /* This is a small demo of the high-performance NetX Duo TCP/IP
4    IPv4/IPv6 dual stack.  This demo concentrates on TCP connection,
5    disconnection, sending, and receiving in IPv4 and IPv6 network
6    in a simulated Ethernet driver in a multihome environment.  */
7 
8 
9 /*
10    IP_0 has two simulated phyiscal interfaces.
11    The primary interface is 1.2.3.4/255.255.255.0
12    the secondary interface is 2.2.3.4/255.255.255.0
13 
14    IP_1 has two simulated physical interface.
15    The primary interface is 1.2.3.5/255.255.255.0
16    the secondary interface is 2.2.3.5/255.255.255.0
17 
18    Each interface has an IPv6 link local address and
19    an IPv6 global address.  The following table lists the IPv6
20    configuration:
21 
22    IP_0 primary interface Link Local Address:  FE80::
23    IP_0 primary interface Global Address:
24 
25    IP_0 secondary interface Link Local Address:  FE80::
26    IP_0 secondary interface Global Address:
27 
28    IP_1 primary interface Link Local Address:  FE80::
29    IP_1 primary interface Global Address:
30 
31    IP_1 secondary interface Link Local Address:  FE80::
32    IP_1 secondary interface Global Address:
33 
34 
35 
36 
37 
38    These four simulated interfaces are connected to the same channel.
39 
40 
41 
42        ---------  Primary                         Primary   ---------
43        |       |  Interface                       Interface |       |
44        | IP_0  |----------------------     |----------------| IP_1  |
45        |       | 1.2.3.4             |     |       1.2.3.5  |       |
46        |       | 2001::4             |     |       2001::5  |       |
47        |       |                     |     |                |       |
48        |       |                     |     |                |       |
49        |       |-------------------  |     |  --------------|       |
50        |       | Secondary        |  |     |  |   Secondary |       |
51        --------- Interface        |  |     |  |   Interface ---------
52                  2.2.3.4          |  |     |  |     2.2.3.5
53                  2002::4          |  |     |  |     2002::5
54                                ------------------
55                                |                |
56                                |   Switch Box   |
57                                |                |
58                                ------------------
59 
60 
61 */
62 
63 #include   "tx_api.h"
64 #include   "nx_api.h"
65 
66 #if (NX_MAX_PHYSICAL_INTERFACES > 1)
67 
68 #define     DEMO_STACK_SIZE         2048
69 #define     DEMO_DATA               "ABCDEFGHIJKLMNOPQRSTUVWXYZ "
70 #define     PACKET_SIZE             1536
71 #define     POOL_SIZE               ((sizeof(NX_PACKET) + PACKET_SIZE) * 16)
72 
73 /* Define the ThreadX and NetX object control blocks...  */
74 
75 TX_THREAD               thread_0;
76 TX_THREAD               thread_1;
77 
78 NX_PACKET_POOL          pool_0;
79 NX_IP                   ip_0;
80 NX_IP                   ip_1;
81 NX_TCP_SOCKET           client_socket;
82 NX_TCP_SOCKET           server_socket;
83 UCHAR                   pool_buffer[POOL_SIZE];
84 
85 
86 /* Define the counters used in the demo application...  */
87 
88 ULONG                   thread_0_counter;
89 ULONG                   thread_1_counter;
90 ULONG                   error_counter;
91 
92 
93 /* Define thread prototypes.  */
94 
95 void thread_0_entry(ULONG thread_input);
96 void thread_1_entry(ULONG thread_input);
97 void thread_1_connect_received(NX_TCP_SOCKET *server_socket, UINT port);
98 void thread_1_disconnect_received(NX_TCP_SOCKET *server_socket);
99 
100 void _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
101 
102 
103 #define PRIMARY_INTERFACE   0
104 #define SECONDARY_INTERFACE 1
105 
106 #ifndef NX_DISABLE_IPV4
107 NXD_ADDRESS ip1_primary_ipv4_address;
108 NXD_ADDRESS ip1_secondary_ipv4_address;
109 #endif /* NX_DISABLE_IPV4 */
110 
111 #ifndef NX_DISABLE_IPV6
112 
113 UINT ip0_primary_linklocal_address_index;
114 UINT ip0_primary_global_address_index;
115 UINT ip0_secondary_linklocal_address_index;
116 UINT ip0_secondary_global_address_index;
117 
118 UINT ip1_primary_linklocal_address_index;
119 UINT ip1_primary_global_address_index;
120 UINT ip1_secondary_linklocal_address_index;
121 UINT ip1_secondary_global_address_index;
122 
123 
124 NXD_ADDRESS ip1_primary_global_address;
125 NXD_ADDRESS ip1_secondary_global_address;
126 #endif /* NX_DISABLE_IPV6 */
127 
128 #ifndef NX_DISABLE_IPV4
129 
130 #ifndef NX_DISABLE_IPV6
131 /*
132    Define the number of TCP tests.  If IPv6 is enabled, there are 4 tests:
133    (1) TCP connection to the IPv4 address of the primary interface on ip_1;
134    (2) TCP connection to the IPv4 address of the secondary interface on ip_1;
135    (3) TCP connection to the IPv6 global  address of the primary interface on ip_1;
136    (4) TCP connection to the IPv6 global address of the secondary interface on ip_1;
137 */
138 #define NUMBER_OF_TESTS 4
139 #else /* !NX_DISABLE_IPV6 */
140 /*
141    Define the number of TCP tests.  If IPv6 is enabled, there are 2 tests:
142    (1) TCP connection to the IPv4 address of the primary interface on ip_1;
143    (2) TCP connection to the IPv4 address of the secondary interface on ip_1;
144 */
145 #define NUMBER_OF_TESTS 2
146 #endif /* !NX_DISABLE_IPV6 */
147 
148 #else  /* !NX_DISABLE_IPV4 */
149 /*
150    Define the number of TCP tests.  If IPv6 is enabled, there are 4 tests:
151    (1) TCP connection to the IPv6 global  address of the primary interface on ip_1;
152    (2) TCP connection to the IPv6 global address of the secondary interface on ip_1;
153 */
154 #define NUMBER_OF_TESTS 2
155 #endif /* !NX_DISABLE_IPV4 */
156 
157 
158 /* Define main entry point.  */
main()159 int main()
160 {
161 
162     /* Enter the ThreadX kernel.  */
163     tx_kernel_enter();
164 }
165 
166 
167 /* Define what the initial system looks like.  */
168 
tx_application_define(void * first_unused_memory)169 void    tx_application_define(void *first_unused_memory)
170 {
171 
172 CHAR *pointer;
173 UINT  status;
174 
175 
176     /* Setup the working pointer.  */
177     pointer =  (CHAR *)first_unused_memory;
178 
179     /* Create the main thread.  */
180     tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
181                      pointer, DEMO_STACK_SIZE,
182                      4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
183 
184     pointer =  pointer + DEMO_STACK_SIZE;
185 
186     /* Create the main thread.  */
187     tx_thread_create(&thread_1, "thread 1", thread_1_entry, 0,
188                      pointer, DEMO_STACK_SIZE,
189                      3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
190 
191     pointer =  pointer + DEMO_STACK_SIZE;
192 
193 
194     /* Initialize the NetX system.  */
195     nx_system_initialize();
196 
197     /* Create a packet pool.  */
198     status =  nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", PACKET_SIZE, pool_buffer, POOL_SIZE);
199 
200     if (status)
201     {
202         error_counter++;
203     }
204 
205     /* Create an IP instance.  */
206     status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
207                           pointer, 2048, 1);
208     pointer =  pointer + 2048;
209 
210     /* Create another IP instance.  */
211     status += nx_ip_create(&ip_1, "NetX IP Instance 1", IP_ADDRESS(1, 2, 3, 5), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
212                            pointer, 2048, 1);
213     pointer =  pointer + 2048;
214 
215     if (status)
216     {
217         error_counter++;
218     }
219 
220 #ifndef NX_DISABLE_IPV4
221     /* Set the server IP address to ip_1 primary IPv4 address. */
222     ip1_primary_ipv4_address.nxd_ip_version = NX_IP_VERSION_V4;
223     ip1_primary_ipv4_address.nxd_ip_address.v4 = IP_ADDRESS(1, 2, 3, 5);
224 #endif /* NX_DISABLE_IPV4 */
225 
226 
227     /* Attach the second interface to IP_0. Note that this interface is attached during initialization time.
228        Alternatively the second interface may also be attached in thread context, as illustrated below
229        in thead_0_entry function. */
230     status = nx_ip_interface_attach(&ip_0, "IP_0 Secondary Interface", IP_ADDRESS(2, 2, 3, 4), 0xFFFFFF00, _nx_ram_network_driver);
231 
232     if (status)
233     {
234         error_counter++;
235     }
236 
237 #ifndef NX_DISABLE_IPV4
238     /* Enable ARP and supply ARP cache memory for IP Instance 0.  */
239     status =  nx_arp_enable(&ip_0, (void *)pointer, 1024);
240     pointer = pointer + 1024;
241 
242     /* Enable ARP and supply ARP cache memory for IP Instance 1.  */
243     status +=  nx_arp_enable(&ip_1, (void *)pointer, 1024);
244     pointer = pointer + 1024;
245 
246     /* Check ARP enable status.  */
247     if (status)
248     {
249         error_counter++;
250     }
251 #endif /* NX_DISABLE_IPV4 */
252 #ifndef NX_DISABLE_IPV6
253 
254     /* Enable IPv6 */
255     status = nxd_ipv6_enable(&ip_0);
256     if (status)
257     {
258         error_counter++;
259     }
260 
261     status = nxd_ipv6_enable(&ip_1);
262     if (status)
263     {
264         error_counter++;
265     }
266 #endif /* !NX_DISABLE_IPV6 */
267 
268     /* Enable ICMP */
269     status = nxd_icmp_enable(&ip_0);
270     if (status)
271     {
272         error_counter++;
273     }
274 
275     status = nxd_icmp_enable(&ip_1);
276     if (status)
277     {
278         error_counter++;
279     }
280 
281 
282     /* Enable TCP processing for both IP instances.  */
283     status =  nx_tcp_enable(&ip_0);
284     status += nx_tcp_enable(&ip_1);
285 
286     if (status)
287     {
288         error_counter++;
289     }
290 }
291 
292 
293 
294 /* Define the test threads.  */
295 
thread_0_entry(ULONG thread_input)296 void    thread_0_entry(ULONG thread_input)
297 {
298 
299 UINT       status;
300 NX_PACKET *my_packet;
301 ULONG      length;
302 
303 #ifndef NX_DISABLE_IPV6
304 NXD_ADDRESS       ip_address;
305 NXD_IPV6_ADDRESS *server_ipv6_ptr;
306 #endif /* !NX_DISABLE_IPV6 */
307 NXD_ADDRESS       peer_address;
308 ULONG             peer_port;
309 
310     NX_PARAMETER_NOT_USED(thread_input);
311 
312     /*
313        At this point, IP_0 already has two interfaces attached during the system initialization phase.
314        Here is a demonstration of attaching a secondary interface to an IP instance (ip_1 in this case)
315        after the IP instance has been created and already started.
316      */
317 
318     /*
319        Attch the second interface to IP_1.  Note that this interface is attached in thread context.
320        Alternatively the second interface may also be attached during system initilization, as illustrated
321        above in tx_application_define.
322      */
323 
324     /* Attach the 2nd interface to IP_1 */
325     status = nx_ip_interface_attach(&ip_1, "IP_1 Secondary Interface", IP_ADDRESS(2, 2, 3, 5), 0xFFFFFF00, _nx_ram_network_driver);
326 
327     /* Check for error.  */
328     if (status)
329     {
330         error_counter++;
331     }
332 
333 
334 #ifndef NX_DISABLE_IPV4
335     /* Set the server IP address to ip_1 primary IPv4 address. */
336     ip1_secondary_ipv4_address.nxd_ip_version = NX_IP_VERSION_V4;
337     ip1_secondary_ipv4_address.nxd_ip_address.v4 = IP_ADDRESS(2, 2, 3, 5);
338 #endif /* NX_DISABLE_IPV4 */
339 
340 #ifndef NX_DISABLE_IPV6
341     /* Set ip_0 primary link local address. */
342     status = nxd_ipv6_address_set(&ip_0, PRIMARY_INTERFACE, NX_NULL, 10, &ip0_primary_linklocal_address_index);
343     if (status)
344     {
345         error_counter++;
346     }
347 
348     /* Set ip_1 primary link local address. */
349     status = nxd_ipv6_address_set(&ip_1, PRIMARY_INTERFACE, NX_NULL, 10, &ip1_primary_linklocal_address_index);
350     if (status)
351     {
352         error_counter++;
353     }
354 
355 
356 
357     /* Set ip_0 primary interface global address. */
358     ip_address.nxd_ip_version = NX_IP_VERSION_V6;
359     ip_address.nxd_ip_address.v6[0] = 0x20010000;
360     ip_address.nxd_ip_address.v6[1] = 0;
361     ip_address.nxd_ip_address.v6[2] = 0;
362     ip_address.nxd_ip_address.v6[3] = 4;
363 
364     status = nxd_ipv6_address_set(&ip_0, PRIMARY_INTERFACE, &ip_address, 64, &ip0_primary_global_address_index);
365 
366     if (status)
367     {
368         error_counter++;
369     }
370 
371     /* Set ip_1 primary interface global address. */
372     ip_address.nxd_ip_version = NX_IP_VERSION_V6;
373     ip_address.nxd_ip_address.v6[0] = 0x20010000;
374     ip_address.nxd_ip_address.v6[1] = 0;
375     ip_address.nxd_ip_address.v6[2] = 0;
376     ip_address.nxd_ip_address.v6[3] = 5;
377 
378     status = nxd_ipv6_address_set(&ip_1, PRIMARY_INTERFACE, &ip_address, 64, &ip1_primary_global_address_index);
379 
380     if (status)
381     {
382         error_counter++;
383     }
384 
385 
386 
387     /* Set ip_0 secondary link local address. */
388     status = nxd_ipv6_address_set(&ip_0, SECONDARY_INTERFACE, NX_NULL, 10, &ip0_secondary_linklocal_address_index);
389     if (status)
390     {
391         error_counter++;
392     }
393 
394     /* Set ip_1 secondary link local address. */
395     status = nxd_ipv6_address_set(&ip_1, SECONDARY_INTERFACE, NX_NULL, 10, &ip1_secondary_linklocal_address_index);
396     if (status)
397     {
398         error_counter++;
399     }
400 
401 
402 
403     /* Set ip_0 secondary interface global address. */
404     ip_address.nxd_ip_version = NX_IP_VERSION_V6;
405     ip_address.nxd_ip_address.v6[0] = 0x20020000;
406     ip_address.nxd_ip_address.v6[1] = 0;
407     ip_address.nxd_ip_address.v6[2] = 0;
408     ip_address.nxd_ip_address.v6[3] = 4;
409 
410     status = nxd_ipv6_address_set(&ip_0, SECONDARY_INTERFACE, &ip_address, 64, &ip0_secondary_global_address_index);
411 
412     if (status)
413     {
414         error_counter++;
415     }
416 
417     /* Set ip_1 primary interface global address. */
418     ip_address.nxd_ip_version = NX_IP_VERSION_V6;
419     ip_address.nxd_ip_address.v6[0] = 0x20020000;
420     ip_address.nxd_ip_address.v6[1] = 0;
421     ip_address.nxd_ip_address.v6[2] = 0;
422     ip_address.nxd_ip_address.v6[3] = 5;
423 
424     status = nxd_ipv6_address_set(&ip_1, SECONDARY_INTERFACE, &ip_address, 64, &ip1_secondary_global_address_index);
425 
426     if (status)
427     {
428         error_counter++;
429     }
430 
431     /* Set the server IP address to ip_1 primary IPv6 global address. */
432     server_ipv6_ptr = &ip_1.nx_ipv6_address[ip1_primary_global_address_index];
433     ip1_primary_global_address.nxd_ip_version = NX_IP_VERSION_V6;
434     ip1_primary_global_address.nxd_ip_address.v6[0] = server_ipv6_ptr -> nxd_ipv6_address[0];
435     ip1_primary_global_address.nxd_ip_address.v6[1] = server_ipv6_ptr -> nxd_ipv6_address[1];
436     ip1_primary_global_address.nxd_ip_address.v6[2] = server_ipv6_ptr -> nxd_ipv6_address[2];
437     ip1_primary_global_address.nxd_ip_address.v6[3] = server_ipv6_ptr -> nxd_ipv6_address[3];
438 
439     /* Set the server IP address to ip_1 secondary IPv6 global address. */
440     server_ipv6_ptr = &ip_1.nx_ipv6_address[ip1_secondary_global_address_index];
441     ip1_secondary_global_address.nxd_ip_version = NX_IP_VERSION_V6;
442     ip1_secondary_global_address.nxd_ip_address.v6[0] = server_ipv6_ptr -> nxd_ipv6_address[0];
443     ip1_secondary_global_address.nxd_ip_address.v6[1] = server_ipv6_ptr -> nxd_ipv6_address[1];
444     ip1_secondary_global_address.nxd_ip_address.v6[2] = server_ipv6_ptr -> nxd_ipv6_address[2];
445     ip1_secondary_global_address.nxd_ip_address.v6[3] = server_ipv6_ptr -> nxd_ipv6_address[3];
446 
447 #endif /* !NX_DISABLE_IPV6 */
448 
449     /* Wait 5 seconds for the IP thread to finish its initilization and
450        for the IPv6 stack to finish DAD process. */
451     tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);
452 
453     /* Loop to repeat things over and over again!  */
454     while (1)
455     {
456 
457         /* Create a socket.  */
458         status =  nx_tcp_socket_create(&ip_0, &client_socket, "Client Socket",
459                                        NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 200,
460                                        NX_NULL, NX_NULL);
461 
462         /* Check for error.  */
463         if (status)
464         {
465             error_counter++;
466         }
467 
468         /* Bind the socket.  */
469         status =  nx_tcp_client_socket_bind(&client_socket, 12, NX_WAIT_FOREVER);
470 
471         /* Check for error.  */
472         if (status)
473         {
474             error_counter++;
475         }
476 
477         /* Attempt to connect the socket.  */
478         /* In this demo, we alternate between IPv4 connections and IPv6 connections. */
479         switch (thread_0_counter & (NUMBER_OF_TESTS - 1))
480         {
481 #ifndef NX_DISABLE_IPV4
482         case 0:
483             status = nxd_tcp_client_socket_connect(&client_socket, &ip1_primary_ipv4_address, 12, NX_IP_PERIODIC_RATE);
484             break;
485         case 1:
486             status = nxd_tcp_client_socket_connect(&client_socket, &ip1_secondary_ipv4_address, 12, NX_IP_PERIODIC_RATE);
487             break;
488 #ifndef NX_DISABLE_IPV6
489         case 2:
490             status = nxd_tcp_client_socket_connect(&client_socket, &ip1_primary_global_address, 12, NX_IP_PERIODIC_RATE);
491             break;
492         case 3:
493             status = nxd_tcp_client_socket_connect(&client_socket, &ip1_secondary_global_address, 12, NX_IP_PERIODIC_RATE);
494             break;
495 #endif /* !NX_DISABLE_IPV6 */
496 #else /* !NX_DISABLE_IPV4  */
497 #ifndef NX_DISABLE_IPV6
498         case 0:
499             status = nxd_tcp_client_socket_connect(&client_socket, &ip1_primary_global_address, 12, NX_IP_PERIODIC_RATE);
500             break;
501         case 1:
502             status = nxd_tcp_client_socket_connect(&client_socket, &ip1_secondary_global_address, 12, NX_IP_PERIODIC_RATE);
503             break;
504 #endif /* !NX_DISABLE_IPV6 */
505 #endif /* NX_DISABLE_IPV4 */
506         default:
507             break;
508         }
509         /* Check for error.  */
510         if (status)
511         {
512             printf("Error with socket connect: 0x%x\n", status);
513             error_counter++;
514         }
515 
516         status = nxd_tcp_socket_peer_info_get(&client_socket, &peer_address, &peer_port);
517 
518         /* Allocate a packet.  */
519         status =  nx_packet_allocate(&pool_0, &my_packet, NX_TCP_PACKET, NX_WAIT_FOREVER);
520 
521         /* Check status.  */
522         if (status != NX_SUCCESS)
523         {
524             break;
525         }
526 
527         /* Write ABCs into the packet payload!  */
528         nx_packet_data_append(my_packet, DEMO_DATA, sizeof(DEMO_DATA), &pool_0, TX_WAIT_FOREVER);
529 
530         status =  nx_packet_length_get(my_packet, &length);
531         if ((status) || (length != sizeof(DEMO_DATA)))
532         {
533             error_counter++;
534         }
535 
536         /* Send the packet out!  */
537         status =  nx_tcp_socket_send(&client_socket, my_packet, NX_IP_PERIODIC_RATE);
538 
539         /* Determine if the status is valid.  */
540         if (status)
541         {
542             error_counter++;
543             nx_packet_release(my_packet);
544         }
545 
546         /* Disconnect this socket.  */
547         status =  nx_tcp_socket_disconnect(&client_socket, NX_IP_PERIODIC_RATE);
548 
549         /* Determine if the status is valid.  */
550         if (status)
551         {
552             error_counter++;
553         }
554 
555         /* Unbind the socket.  */
556         status =  nx_tcp_client_socket_unbind(&client_socket);
557 
558         /* Check for error.  */
559         if (status)
560         {
561             error_counter++;
562         }
563 
564         /* Delete the socket.  */
565         status =  nx_tcp_socket_delete(&client_socket);
566 
567         /* Check for error.  */
568         if (status)
569         {
570             error_counter++;
571         }
572 
573         /* Increment thread 0's counter.  */
574         thread_0_counter++;
575     }
576 }
577 
578 
thread_1_entry(ULONG thread_input)579 void    thread_1_entry(ULONG thread_input)
580 {
581 
582 UINT       status;
583 NX_PACKET *packet_ptr;
584 ULONG      actual_status;
585 
586     NX_PARAMETER_NOT_USED(thread_input);
587 
588 #ifndef NX_DISABLE_IPV6
589 
590     /* Wait 5 seconds for the IP thread to finish its initilization and
591        for the IPv6 stack to finish DAD process. */
592     tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);
593 
594 #else /* !NX_DISABLE_IPV6 */
595     /* Wait 1 second for the IP thread to finish its initilization. */
596     tx_thread_sleep(NX_IP_PERIODIC_RATE);
597 #endif /* !NX_DISABLE_IPV6 */
598 
599 
600     /* Ensure the IP instance has been initialized.  */
601     status =  nx_ip_status_check(&ip_1, NX_IP_INITIALIZE_DONE, &actual_status, NX_IP_PERIODIC_RATE);
602 
603     /* Check status...  */
604     if (status != NX_SUCCESS)
605     {
606 
607         error_counter++;
608         return;
609     }
610 
611     /* Create a socket.  */
612     status =  nx_tcp_socket_create(&ip_1, &server_socket, "Server Socket",
613                                    NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 100,
614                                    NX_NULL, thread_1_disconnect_received);
615 
616     /* Check for error.  */
617     if (status)
618     {
619         error_counter++;
620     }
621 
622     /* Setup this thread to listen.  */
623     status =  nx_tcp_server_socket_listen(&ip_1, 12, &server_socket, 5, thread_1_connect_received);
624 
625     /* Check for error.  */
626     if (status)
627     {
628         error_counter++;
629     }
630 
631     /* Loop to create and establish server connections.  */
632     while (1)
633     {
634 
635         /* Increment thread 1's counter.  */
636         thread_1_counter++;
637 
638         /* Accept a client socket connection.  */
639         status =  nx_tcp_server_socket_accept(&server_socket, NX_WAIT_FOREVER);
640 
641         /* Check for error.  */
642         if (status)
643         {
644             error_counter++;
645         }
646 
647         /* Receive a TCP message from the socket.  */
648         status =  nx_tcp_socket_receive(&server_socket, &packet_ptr, NX_IP_PERIODIC_RATE);
649 
650         /* Check for error.  */
651         if (status)
652         {
653             error_counter++;
654         }
655         else
656         {
657             /* Release the packet.  */
658             nx_packet_release(packet_ptr);
659         }
660 
661         /* Disconnect the server socket.  */
662         status =  nx_tcp_socket_disconnect(&server_socket, NX_IP_PERIODIC_RATE);
663 
664         /* Check for error.  */
665         if (status)
666         {
667             error_counter++;
668         }
669 
670         /* Unaccept the server socket.  */
671         status =  nx_tcp_server_socket_unaccept(&server_socket);
672 
673         /* Check for error.  */
674         if (status)
675         {
676             error_counter++;
677         }
678 
679         /* Setup server socket for listening again.  */
680         status =  nx_tcp_server_socket_relisten(&ip_1, 12, &server_socket);
681 
682         /* Check for error.  */
683         if (status)
684         {
685             error_counter++;
686         }
687     }
688 }
689 
690 
thread_1_connect_received(NX_TCP_SOCKET * socket_ptr,UINT port)691 void  thread_1_connect_received(NX_TCP_SOCKET *socket_ptr, UINT port)
692 {
693 
694     /* Check for the proper socket and port.  */
695     if ((socket_ptr != &server_socket) || (port != 12))
696     {
697         error_counter++;
698     }
699 }
700 
701 
thread_1_disconnect_received(NX_TCP_SOCKET * socket)702 void  thread_1_disconnect_received(NX_TCP_SOCKET *socket)
703 {
704 
705     /* Check for proper disconnected socket.  */
706     if (socket != &server_socket)
707     {
708         error_counter++;
709     }
710 }
711 #endif
712 
713