1 /* This NetX test concentrates on caller check for error checking functions. */
2
3 #include "nx_api.h"
4 #include "tx_thread.h"
5 #include "tx_timer.h"
6 #include "nx_udp.h"
7 #include "nx_tcp.h"
8 #include "nx_rarp.h"
9 #include "nx_ip.h"
10 #include "nx_icmp.h"
11 #include "nx_igmp.h"
12 #include "nx_arp.h"
13 extern void test_control_return(UINT status);
14
15 #if !defined(NX_DISABLE_ERROR_CHECKING) && defined(__PRODUCT_NETXDUO__) && defined(__linux__) && !defined(NX_DISABLE_IPV4)
16 #define DEMO_STACK_SIZE 2048
17
18
19 /* Define the ThreadX and NetX object control blocks... */
20
21 static TX_THREAD thread_0;
22
23 static NX_PACKET_POOL pool_0;
24 static NX_IP ip_0;
25 static NX_IP test_ip;
26 static NX_TCP_SOCKET tcp_socket;
27 static NX_UDP_SOCKET udp_socket;
28 static NXD_ADDRESS address = {NX_IP_VERSION_V6, };
29 static TX_TIMER timer_0;
30
31 /* Define the counters used in the demo application... */
32
33 static ULONG error_counter = 0;
34 static ULONG expected_system_state;
35
36
37 /* Define thread prototypes. */
38
39 static void thread_0_entry(ULONG thread_input);
40 extern void _nx_ram_network_driver_256(struct NX_IP_DRIVER_STRUCT *driver_req);
41 static void link_status_change_notify(NX_IP *ip_ptr, UINT interface_index, UINT link_up);
42 static void tcp_receive_notify(NX_TCP_SOCKET *socket_ptr);
43 static VOID tcp_socket_window_update_notify(NX_TCP_SOCKET *socket_ptr);
44 VOID test_process(ULONG id);
45 VOID test_process_1(ULONG id);
46 VOID test_process_2(ULONG id);
47
48
49 /* Define what the initial system looks like. */
50
51 #ifdef CTEST
test_application_define(void * first_unused_memory)52 VOID test_application_define(void *first_unused_memory)
53 #else
54 void netx_caller_check_test_application_define(void *first_unused_memory)
55 #endif
56 {
57
58 CHAR *pointer;
59 UINT status;
60
61
62 /* Setup the working pointer. */
63 pointer = (CHAR *) first_unused_memory;
64
65 error_counter = 0;
66
67 /* Create the main thread. */
68 tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
69 pointer, DEMO_STACK_SIZE,
70 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
71
72 pointer = pointer + DEMO_STACK_SIZE;
73
74 /* Initialize the NetX system. */
75 nx_system_initialize();
76
77 /* Create a packet pool. */
78 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
79 pointer = pointer + 8192;
80
81 if (status)
82 error_counter++;
83
84 /* Create an IP instance. */
85 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_256,
86 pointer, 2048, 1);
87 pointer = pointer + 2048;
88
89 if (status)
90 error_counter++;
91
92 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
93 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
94 pointer = pointer + 1024;
95
96 /* Check ARP enable status. */
97 if (status)
98 error_counter++;
99
100 /* Enable UDP processing for IP instance. */
101 status = nx_udp_enable(&ip_0);
102
103 /* Check UDP enable status. */
104 if (status)
105 error_counter++;
106
107 /* Enable TCP processing for IP instance. */
108 status = nx_tcp_enable(&ip_0);
109
110 /* Check TCP enable status. */
111 if (status)
112 error_counter++;
113
114 /* Enable IGMP for IP instance. */
115 status = nx_igmp_enable(&ip_0);
116
117 /* Check IGMP enable status. */
118 if (status)
119 error_counter++;
120
121 /* Enable ICMP processing for IP instance. */
122 status = nxd_icmp_enable(&ip_0);
123
124 /* Check TCP enable status. */
125 if (status)
126 error_counter++;
127
128 }
129
test_process(ULONG id)130 VOID test_process(ULONG id)
131 {
132 UINT uint_value;
133 ULONG ulong_value;
134 NX_PACKET_POOL
135 test_pool;
136 ULONG ipv6_addr[4];
137 UINT old_state = _tx_thread_system_state;
138
139
140 _tx_thread_system_state = expected_system_state;
141
142 if (nx_ip_raw_packet_enable(&ip_0) != NX_CALLER_ERROR)
143 {
144 error_counter++;
145 }
146 if (nx_ip_raw_packet_disable(&ip_0) != NX_CALLER_ERROR)
147 {
148 error_counter++;
149 }
150 if (nx_ip_raw_receive_queue_max_set(&ip_0, 0) != NX_CALLER_ERROR)
151 {
152 error_counter++;
153 }
154 if (nx_ip_fragment_disable(&ip_0) != NX_CALLER_ERROR)
155 {
156 error_counter++;
157 }
158 if (nx_rarp_enable(&ip_0) != NX_CALLER_ERROR)
159 {
160 error_counter++;
161 }
162 if (nx_ip_gateway_address_clear(&ip_0) != NX_CALLER_ERROR)
163 {
164 error_counter++;
165 }
166 if (nx_ip_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL,
167 NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
168 {
169 error_counter++;
170 }
171 if (nx_ip_link_status_change_notify_set(&ip_0, link_status_change_notify) != NX_CALLER_ERROR)
172 {
173 error_counter++;
174 }
175 if (nx_ip_address_change_notify(&ip_0, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
176 {
177 error_counter++;
178 }
179 if (nx_rarp_disable(&ip_0) != NX_CALLER_ERROR)
180 {
181 error_counter++;
182 }
183 if (nx_ip_fragment_enable(&ip_0) != NX_CALLER_ERROR)
184 {
185 error_counter++;
186 }
187 ip_0.nx_ip_rarp_queue_process = _nx_rarp_queue_process;
188 if (nx_rarp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
189 {
190 error_counter++;
191 }
192 if (nx_arp_static_entries_delete(&ip_0) != NX_CALLER_ERROR)
193 {
194 error_counter++;
195 }
196 if (nx_icmp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
197 {
198 error_counter++;
199 }
200 if (nx_igmp_loopback_enable(&ip_0) != NX_CALLER_ERROR)
201 {
202 error_counter++;
203 }
204 if (nx_igmp_loopback_disable(&ip_0) != NX_CALLER_ERROR)
205 {
206 error_counter++;
207 }
208 if (nx_ip_driver_direct_command(&ip_0, 0xFFFFFFFF, &ulong_value) != NX_CALLER_ERROR)
209 {
210 error_counter++;
211 }
212 if (nx_ip_driver_interface_direct_command(&ip_0, 0xFFFFFFFF, 0, &ulong_value) != NX_CALLER_ERROR)
213 {
214 error_counter++;
215 }
216 if (nx_ip_interface_physical_address_set(&ip_0, 0, 0, 0, 0) != NX_CALLER_ERROR)
217 {
218 error_counter++;
219 }
220 if (nx_tcp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL,
221 NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
222 {
223 error_counter++;
224 }
225 if (nx_igmp_info_get(&ip_0, 0, 0, 0, 0) != NX_CALLER_ERROR)
226 {
227 error_counter++;
228 }
229 if (nx_ip_interface_mtu_set(&ip_0, 0, 1500) != NX_CALLER_ERROR)
230 {
231 error_counter++;
232 }
233 if (nx_ip_gateway_address_set(&ip_0, 1) != NX_CALLER_ERROR)
234 {
235 error_counter++;
236 }
237 if (nx_arp_entry_delete(&ip_0, 1) != NX_CALLER_ERROR)
238 {
239 error_counter++;
240 }
241 ip_0.nx_ip_arp_allocate = NX_NULL;
242 if (nx_arp_enable(&ip_0, (VOID *)0x20000000, 1024) != NX_CALLER_ERROR)
243 {
244 error_counter++;
245 }
246 ip_0.nx_ip_arp_allocate = _nx_arp_entry_allocate;
247 if (nx_tcp_socket_mss_set(&tcp_socket, 1460) != NX_CALLER_ERROR)
248 {
249 error_counter++;
250 }
251 if (nx_tcp_socket_mss_get(&tcp_socket, &ulong_value) != NX_CALLER_ERROR)
252 {
253 error_counter++;
254 }
255 if (nx_tcp_socket_window_update_notify_set(&tcp_socket, tcp_socket_window_update_notify) != NX_CALLER_ERROR)
256 {
257 error_counter++;
258 }
259 if (nx_ip_gateway_address_get(&ip_0, &ulong_value) != NX_CALLER_ERROR)
260 {
261 error_counter++;
262 }
263 ip_0.nx_ip_icmp_packet_receive = NX_NULL;
264 if (nx_icmp_enable(&ip_0) != NX_CALLER_ERROR)
265 {
266 error_counter++;
267 }
268 ip_0.nx_ip_icmp_packet_receive = _nx_icmp_packet_receive;
269 if (nx_tcp_socket_info_get(&tcp_socket, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL,
270 NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
271 {
272 error_counter++;
273 }
274 ip_0.nx_ip_igmp_packet_receive = NX_NULL;
275 if (nx_igmp_enable(&ip_0) != NX_CALLER_ERROR)
276 {
277 error_counter++;
278 }
279 ip_0.nx_ip_igmp_packet_receive = _nx_igmp_packet_receive;
280 if (nx_ip_interface_address_mapping_configure(&ip_0, 0, 0) != NX_CALLER_ERROR)
281 {
282 error_counter++;
283 }
284 if (nx_ip_interface_info_get(&ip_0, 0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
285 {
286 error_counter++;
287 }
288 if (nx_ip_address_set(&ip_0, 1, 0) != NX_CALLER_ERROR)
289 {
290 error_counter++;
291 }
292 if (nx_ip_address_get(&ip_0, &ulong_value, &ulong_value) != NX_CALLER_ERROR)
293 {
294 error_counter++;
295 }
296 if (nx_ip_interface_address_set(&ip_0, 0, 1, 0) != NX_CALLER_ERROR)
297 {
298 error_counter++;
299 }
300 if (nx_ip_interface_physical_address_get(&ip_0, 0, &ulong_value, &ulong_value) != NX_CALLER_ERROR)
301 {
302 error_counter++;
303 }
304 if (nx_tcp_socket_transmit_configure(&tcp_socket, 1, 1, 1, 1) != NX_CALLER_ERROR)
305 {
306 error_counter++;
307 }
308 if (nx_tcp_socket_receive_notify(&tcp_socket, tcp_receive_notify) != NX_CALLER_ERROR)
309 {
310 error_counter++;
311 }
312 if (nx_packet_pool_create(&test_pool, "Invalid pool", 256, (VOID *)0x20000000, 1024) != NX_CALLER_ERROR)
313 {
314 error_counter++;
315 }
316 if (nx_ip_interface_address_get(&ip_0, 0, &ulong_value, &ulong_value) != NX_CALLER_ERROR)
317 {
318 error_counter++;
319 }
320 if (nx_ip_create(&test_ip, "test ip", 0, 0, &pool_0, _nx_ram_network_driver_256,
321 (VOID *)0x20000000, 1024, 1) != NX_CALLER_ERROR)
322 {
323 error_counter++;
324 }
325 if (nx_arp_static_entry_create(&ip_0, 1, 1, 1) != NX_CALLER_ERROR)
326 {
327 error_counter++;
328 }
329 address.nxd_ip_version = NX_IP_VERSION_V6;
330 if (nx_ip_max_payload_size_find(&ip_0, &address, 0, 1, 1, NX_PROTOCOL_TCP, &ulong_value, &ulong_value) != NX_CALLER_ERROR)
331 {
332 error_counter++;
333 }
334 if (nx_udp_socket_create(&ip_0, &udp_socket, "UDP socket", 0, 0, 0, 0) != NX_CALLER_ERROR)
335 {
336 error_counter++;
337 }
338 if (nx_tcp_socket_create(&ip_0, &tcp_socket, "TCP socket", 0, 0, 0, 0, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
339 {
340 error_counter++;
341 }
342 #if (NX_MAX_PHYSICAL_INTERFACES>1)
343 if (nx_ip_interface_detach(&ip_0, 1) != NX_CALLER_ERROR)
344 {
345 error_counter++;
346 }
347 if (nx_ip_interface_attach(&ip_0, "Second interface", 1, 0, _nx_ram_network_driver_256) != NX_CALLER_ERROR)
348 {
349 error_counter++;
350 }
351 #endif /* (NX_MAX_PHYSICAL_INTERFACES>1) */
352 #ifdef FEATURE_NX_IPV6
353 if (nxd_ipv6_enable(&ip_0) != NX_CALLER_ERROR)
354 {
355 error_counter++;
356 }
357 if (nxd_ipv6_disable(&ip_0) != NX_CALLER_ERROR)
358 {
359 error_counter++;
360 }
361 if (nxd_ipv6_default_router_delete(&ip_0, &address) != NX_CALLER_ERROR)
362 {
363 error_counter++;
364 }
365 if (nxd_ipv6_default_router_entry_get(&ip_0, 0, 0, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
366 {
367 error_counter++;
368 }
369 if (nxd_ipv6_default_router_number_of_entries_get(&ip_0, 0, &uint_value) != NX_CALLER_ERROR)
370 {
371 error_counter++;
372 }
373 if (nxd_icmpv6_ra_flag_callback_set(&ip_0, NX_NULL) != NX_CALLER_ERROR)
374 {
375 error_counter++;
376 }
377 if (nxd_icmp_enable(&ip_0) != NX_CALLER_ERROR)
378 {
379 error_counter++;
380 }
381 if (nxd_ipv6_address_delete(&ip_0, 0) != NX_CALLER_ERROR)
382 {
383 error_counter++;
384 }
385 if (nxd_nd_cache_entry_delete(&ip_0, ipv6_addr) != NX_CALLER_ERROR)
386 {
387 error_counter++;
388 }
389 if (nxd_nd_cache_entry_set(&ip_0, ipv6_addr, 0, "") != NX_CALLER_ERROR)
390 {
391 error_counter++;
392 }
393 if (nxd_ipv6_address_get(&ip_0, 0, &address, &ulong_value, &uint_value) != NX_CALLER_ERROR)
394 {
395 error_counter++;
396 }
397 address.nxd_ip_version = NX_IP_VERSION_V6;
398 if (nxd_ipv6_default_router_add(&ip_0, &address, 1, 0) != NX_CALLER_ERROR)
399 {
400 error_counter++;
401 }
402 if (nxd_ipv6_address_set(&ip_0, 0, NX_NULL, 10, NX_NULL) != NX_CALLER_ERROR)
403 {
404 error_counter++;
405 }
406 #endif /* FEATURE_NX_IPV6 */
407
408 _tx_thread_system_state = old_state;
409
410 /* Deactivate current timer. */
411 tx_timer_deactivate(&timer_0);
412 }
413
test_process_1(ULONG id)414 VOID test_process_1(ULONG id)
415 {
416 NX_PACKET *packet_ptr;
417 ULONG ulong_value;
418 UINT uint_value;
419 ULONG ipv6_addr[4];
420 UINT old_state = _tx_thread_system_state;
421 TX_THREAD *old_thread = _tx_thread_current_ptr;
422
423
424 nx_packet_allocate(&pool_0, &packet_ptr, 0, 0);
425 packet_ptr -> nx_packet_ip_version = 0;
426
427 _tx_thread_system_state = expected_system_state;
428
429 if (id == 1)
430 _tx_thread_current_ptr = TX_NULL;
431
432 if (nxd_udp_packet_info_extract(packet_ptr, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
433 {
434 error_counter++;
435 }
436 if (nx_udp_packet_info_extract(packet_ptr, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
437 {
438 error_counter++;
439 }
440 if (nx_udp_socket_bytes_available(&udp_socket, &ulong_value) != NX_CALLER_ERROR)
441 {
442 error_counter++;
443 }
444 if (nx_udp_socket_port_get(&udp_socket, &uint_value) != NX_CALLER_ERROR)
445 {
446 error_counter++;
447 }
448 ip_0.nx_ip_raw_ip_processing = _nx_ip_raw_packet_processing;
449 if (nx_ip_raw_packet_receive(&ip_0, &packet_ptr, 0) != NX_CALLER_ERROR)
450 {
451 error_counter++;
452 }
453 if (nx_udp_socket_receive(&udp_socket, &packet_ptr, 0) != NX_CALLER_ERROR)
454 {
455 error_counter++;
456 }
457 if (id == 1)
458 _tx_thread_current_ptr = old_thread;
459
460 nx_packet_allocate(&pool_0, &packet_ptr, 0, 0);
461 packet_ptr -> nx_packet_ip_header = packet_ptr -> nx_packet_prepend_ptr;
462
463 if (id == 1)
464 _tx_thread_current_ptr = TX_NULL;
465
466 if (nxd_udp_source_extract(packet_ptr, &address, &uint_value) != NX_CALLER_ERROR)
467 {
468 error_counter++;
469 }
470 if (nx_udp_socket_delete(&udp_socket) != NX_CALLER_ERROR)
471 {
472 error_counter++;
473 }
474 if (nx_udp_socket_unbind(&udp_socket) != NX_CALLER_ERROR)
475 {
476 error_counter++;
477 }
478 if (nx_udp_free_port_find(&ip_0, 1, &uint_value) != NX_CALLER_ERROR)
479 {
480 error_counter++;
481 }
482 if (nx_ip_delete(&ip_0) != NX_CALLER_ERROR)
483 {
484 error_counter++;
485 }
486 if (nx_ipv4_multicast_interface_leave(&ip_0, IP_ADDRESS(224, 0, 0, 1), 0) != NX_CALLER_ERROR)
487 {
488 error_counter++;
489 }
490 if (nx_packet_pool_delete(&pool_0) != NX_CALLER_ERROR)
491 {
492 error_counter++;
493 }
494 if (nx_arp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
495 {
496 error_counter++;
497 }
498 if (nx_arp_dynamic_entries_invalidate(&ip_0) != NX_CALLER_ERROR)
499 {
500 error_counter++;
501 }
502 if (nx_tcp_socket_disconnect(&tcp_socket, 0) != NX_CALLER_ERROR)
503 {
504 error_counter++;
505 }
506 if (nx_tcp_client_socket_unbind(&tcp_socket) != NX_CALLER_ERROR)
507 {
508 error_counter++;
509 }
510 if (nx_tcp_socket_delete(&tcp_socket) != NX_CALLER_ERROR)
511 {
512 error_counter++;
513 }
514 if (nx_tcp_server_socket_accept(&tcp_socket, 0) != NX_CALLER_ERROR)
515 {
516 error_counter++;
517 }
518 if (nx_tcp_server_socket_unaccept(&tcp_socket) != NX_CALLER_ERROR)
519 {
520 error_counter++;
521 }
522 if (nx_tcp_socket_state_wait(&tcp_socket, NX_TCP_CLOSED, 0) != NX_CALLER_ERROR)
523 {
524 error_counter++;
525 }
526 if (nx_ipv4_multicast_interface_join(&ip_0, IP_ADDRESS(224, 0, 0, 1), 0) != NX_CALLER_ERROR)
527 {
528 error_counter++;
529 }
530
531 if (id == 1)
532 _tx_thread_current_ptr = old_thread;
533
534 nx_packet_allocate(&pool_0, &packet_ptr, sizeof(NX_IPV4_HEADER), 0);
535 address.nxd_ip_version = NX_IP_VERSION_V4;
536 address.nxd_ip_address.v4 = 1;
537
538 if (id == 1)
539 _tx_thread_current_ptr = TX_NULL;
540
541 if (nxd_ip_raw_packet_send(&ip_0, packet_ptr, &address, 0, 0, 0) != NX_CALLER_ERROR)
542 {
543 error_counter++;
544 }
545 if (nx_ip_raw_packet_source_send(&ip_0, packet_ptr, 1, 0, 0) != NX_CALLER_ERROR)
546 {
547 error_counter++;
548 }
549 if (nx_ip_raw_packet_send(&ip_0, packet_ptr, 1, 0) != NX_CALLER_ERROR)
550 {
551 error_counter++;
552 }
553
554 if (id == 1)
555 _tx_thread_current_ptr = old_thread;
556
557 nx_packet_release(packet_ptr);
558
559 if (id == 1)
560 _tx_thread_current_ptr = TX_NULL;
561
562 if (nx_igmp_multicast_interface_leave(&ip_0, IP_ADDRESS(224, 0, 0, 1), 0) != NX_CALLER_ERROR)
563 {
564 error_counter++;
565 }
566 if (nx_igmp_multicast_interface_join(&ip_0, IP_ADDRESS(224, 0, 0, 1), 0) != NX_CALLER_ERROR)
567 {
568 error_counter++;
569 }
570 if (nx_ip_status_check(&ip_0, NX_IP_INITIALIZE_DONE, &ulong_value, 0) != NX_CALLER_ERROR)
571 {
572 error_counter++;
573 }
574 if (nx_udp_socket_bind(&udp_socket, 10, 0) != NX_CALLER_ERROR)
575 {
576 error_counter++;
577 }
578 if (nx_tcp_socket_mss_peer_get(&tcp_socket, &ulong_value) != NX_CALLER_ERROR)
579 {
580 error_counter++;
581 }
582 if (nx_tcp_client_socket_bind(&tcp_socket, 1, 0) != NX_CALLER_ERROR)
583 {
584 error_counter++;
585 }
586 if (nx_tcp_socket_bytes_available(&tcp_socket, &ulong_value) != NX_CALLER_ERROR)
587 {
588 error_counter++;
589 }
590 if (nx_tcp_socket_receive(&tcp_socket, &packet_ptr, 0) != NX_CALLER_ERROR)
591 {
592 error_counter++;
593 }
594 if (nx_tcp_client_socket_port_get(&tcp_socket, &uint_value) != NX_CALLER_ERROR)
595 {
596 error_counter++;
597 }
598
599 if (id == 1)
600 _tx_thread_current_ptr = old_thread;
601
602 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, 0);
603
604 if (id == 1)
605 _tx_thread_current_ptr = TX_NULL;
606
607 if (nx_udp_socket_send(&udp_socket, packet_ptr, 1, 0) != NX_CALLER_ERROR)
608 {
609 error_counter++;
610 }
611
612 if (id == 1)
613 _tx_thread_current_ptr = old_thread;
614
615 nx_packet_release(packet_ptr);
616
617 if (id == 1)
618 _tx_thread_current_ptr = TX_NULL;
619
620 if (nx_arp_ip_address_find(&ip_0, ipv6_addr, 1, 0) != NX_CALLER_ERROR)
621 {
622 error_counter++;
623 }
624 if (nx_tcp_free_port_find(&ip_0, 1, &uint_value) != NX_CALLER_ERROR)
625 {
626 error_counter++;
627 }
628 if (nx_igmp_multicast_join(&ip_0, IP_ADDRESS(224, 0, 0, 1)) != NX_CALLER_ERROR)
629 {
630 error_counter++;
631 }
632 if (nx_igmp_multicast_leave(&ip_0, IP_ADDRESS(224, 0, 0, 1)) != NX_CALLER_ERROR)
633 {
634 error_counter++;
635 }
636 if (nx_icmp_ping(&ip_0, 1, "", 0, &packet_ptr, 0) != NX_CALLER_ERROR)
637 {
638 error_counter++;
639 }
640 if (nx_tcp_socket_peer_info_get(&tcp_socket, &ulong_value, &ulong_value) != NX_CALLER_ERROR)
641 {
642 error_counter++;
643 }
644 if (nx_arp_static_entry_delete(&ip_0, 1, 1, 1) != NX_CALLER_ERROR)
645 {
646 error_counter++;
647 }
648 if (nx_tcp_server_socket_unlisten(&ip_0, 1) != NX_CALLER_ERROR)
649 {
650 error_counter++;
651 }
652 if (nxd_tcp_socket_peer_info_get(&tcp_socket, &address, &ulong_value) != NX_CALLER_ERROR)
653 {
654 error_counter++;
655 }
656 if (nxd_tcp_client_socket_connect(&tcp_socket, &address, 1, 0) != NX_CALLER_ERROR)
657 {
658 error_counter++;
659 }
660 if (nx_tcp_client_socket_connect(&tcp_socket, 1, 1, 0) != NX_CALLER_ERROR)
661 {
662 error_counter++;
663 }
664
665 if (id == 1)
666 _tx_thread_current_ptr = old_thread;
667
668 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, 0);
669
670 if (id == 1)
671 _tx_thread_current_ptr = TX_NULL;
672
673 if (nx_udp_socket_source_send(&udp_socket, packet_ptr, 1, 1, 0) != NX_CALLER_ERROR)
674 {
675 error_counter++;
676 }
677
678 if (id == 1)
679 _tx_thread_current_ptr = old_thread;
680
681 nx_packet_release(packet_ptr);
682
683 if (id == 1)
684 _tx_thread_current_ptr = TX_NULL;
685
686 if (nx_ip_interface_status_check(&ip_0, 0, NX_IP_INITIALIZE_DONE, &ulong_value, 0) != NX_CALLER_ERROR)
687 {
688 error_counter++;
689 }
690 if (nx_arp_hardware_address_find(&ip_0, 1, &ulong_value, &ulong_value) != NX_CALLER_ERROR)
691 {
692 error_counter++;
693 }
694 if (nx_arp_dynamic_entry_set(&ip_0, 1, 1, 1) != NX_CALLER_ERROR)
695 {
696 error_counter++;
697 }
698 if (nx_arp_gratuitous_send(&ip_0, NX_NULL) != NX_CALLER_ERROR)
699 {
700 error_counter++;
701 }
702
703 if (id == 1)
704 _tx_thread_current_ptr = old_thread;
705
706 nx_packet_allocate(&pool_0, &packet_ptr, NX_TCP_PACKET, 0);
707 tcp_socket.nx_tcp_socket_connect_ip.nxd_ip_version = NX_IP_VERSION_V4;
708
709 if (id == 1)
710 _tx_thread_current_ptr = TX_NULL;
711
712 if (nx_tcp_socket_send(&tcp_socket, packet_ptr, 0) != NX_CALLER_ERROR)
713 {
714 error_counter++;
715 }
716 if (nxd_udp_socket_source_send(&udp_socket, packet_ptr, &address, 1, 0) != NX_CALLER_ERROR)
717 {
718 error_counter++;
719 }
720 if (nxd_udp_socket_send(&udp_socket, packet_ptr, &address, 1) != NX_CALLER_ERROR)
721 {
722 error_counter++;
723 }
724 if (nxd_ip_raw_packet_source_send(&ip_0, packet_ptr, &address, 0, 0, 0, 0) != NX_CALLER_ERROR)
725 {
726 error_counter++;
727 }
728
729 if (id == 1)
730 _tx_thread_current_ptr = old_thread;
731
732 nx_packet_release(packet_ptr);
733
734 if (id == 1)
735 _tx_thread_current_ptr = TX_NULL;
736
737 if (nx_tcp_server_socket_relisten(&ip_0, 1, &tcp_socket) != NX_CALLER_ERROR)
738 {
739 error_counter++;
740 }
741 if (nx_tcp_server_socket_listen(&ip_0, 1, &tcp_socket, 1, NX_NULL) != NX_CALLER_ERROR)
742 {
743 error_counter++;
744 }
745 if (nxd_icmp_ping(&ip_0, &address, "", 0, &packet_ptr, 0) != NX_CALLER_ERROR)
746 {
747 error_counter++;
748 }
749 #ifdef FEATURE_NX_IPV6
750 if (nxd_nd_cache_invalidate(&ip_0) != NX_CALLER_ERROR)
751 {
752 error_counter++;
753 }
754 if (nxd_nd_cache_ip_address_find(&ip_0, &address, 1, 1, &uint_value) != NX_CALLER_ERROR)
755 {
756 error_counter++;
757 }
758 if (nxd_icmp_source_ping(&ip_0, &address, 0, "", 0, &packet_ptr, 0) != NX_CALLER_ERROR)
759 {
760 error_counter++;
761 }
762 address.nxd_ip_version = NX_IP_VERSION_V6;
763 if (nxd_nd_cache_hardware_address_find(&ip_0, &address, &ulong_value, &ulong_value, &uint_value) != NX_CALLER_ERROR)
764 {
765 error_counter++;
766 }
767 #endif /* FEATURE_NX_IPV6 */
768
769 _tx_thread_system_state = old_state;
770
771 if (id == 1)
772 _tx_thread_current_ptr = old_thread;
773
774 /* Deactivate current timer. */
775 tx_timer_deactivate(&timer_0);
776 }
777
test_process_2(ULONG id)778 VOID test_process_2(ULONG id)
779 {
780 NX_PACKET *packet_ptr;
781 NX_PACKET *test_packet_ptr;
782 ULONG ulong_value;
783 UINT old_state = _tx_thread_system_state;
784 TX_THREAD *old_thread = _tx_thread_current_ptr;
785
786 nx_packet_allocate(&pool_0, &packet_ptr, NX_TCP_PACKET, 0);
787
788 _tx_thread_system_state = expected_system_state;
789
790 if (id == 1)
791 _tx_thread_current_ptr = TX_NULL;
792
793 if (nx_packet_allocate(&pool_0, &test_packet_ptr, 0, 1) != NX_CALLER_ERROR)
794 {
795 error_counter++;
796 }
797 if (nx_packet_copy(packet_ptr, &packet_ptr, &pool_0, 1) != NX_CALLER_ERROR)
798 {
799 error_counter++;
800 }
801 if (nx_packet_data_append(packet_ptr, "", 1, &pool_0, 1) != NX_CALLER_ERROR)
802 {
803 error_counter++;
804 }
805
806 _tx_thread_system_state = old_state;
807
808 if (id == 1)
809 _tx_thread_current_ptr = old_thread;
810
811 nx_packet_release(packet_ptr);
812 }
813
814 /* Define the test threads. */
815
thread_0_entry(ULONG thread_input)816 static void thread_0_entry(ULONG thread_input)
817 {
818 TX_INTERRUPT_SAVE_AREA
819 UINT i;
820 UINT old_state;
821 TX_THREAD *old_thread;
822 NX_PACKET *packet_ptr;
823 ULONG ulong_value;
824 UINT uint_value;
825 ULONG ipv6_addr[4];
826 struct sched_param sp;
827
828 /* Print out some test information banners. */
829 printf("NetX Test: Caller Check Test.........................................");
830
831 /* Check for earlier error. */
832 if (error_counter)
833 {
834 printf("ERROR!\n");
835 test_control_return(1);
836 }
837
838 /* Modify the thread priority so it will pass the check as not a user thread. */
839 sp.sched_priority = 1;
840 pthread_setschedparam(_tx_thread_current_ptr -> tx_thread_linux_thread_id, SCHED_FIFO, &sp);
841
842 /* Create a UDP socket. */
843 nx_udp_socket_create(&ip_0, &udp_socket, "UDP Socket", NX_IP_NORMAL, NX_FRAGMENT_OKAY, 0x80, 5);
844
845 /* Create a TCP socket. */
846 nx_tcp_socket_create(&ip_0, &tcp_socket, "TCP Socket",
847 NX_IP_NORMAL, NX_FRAGMENT_OKAY, NX_IP_TIME_TO_LIVE, 65535,
848 NX_NULL, NX_NULL);
849
850 TX_DISABLE
851 old_state = _tx_thread_system_state;
852 old_thread = _tx_thread_current_ptr;
853
854 /* 1. NX_INIT_AND_THREADS_CALLER_CHECKING checking. */
855
856 /* 1.1 _tx_thread_system_state = 1, _tx_thread_current_ptr != _tx_timer_thread */
857 expected_system_state = 1;
858 test_process(0);
859
860 #ifndef TX_TIMER_PROCESS_IN_ISR
861 /* Restore. */
862 _tx_thread_current_ptr = old_thread;
863 _tx_thread_system_state = old_state;
864
865 /* 1.2 _tx_thread_system_state = 0xF0F0F0F0UL, _tx_thread_current_ptr = _tx_timer_thread */
866 expected_system_state = 0xF0F0F0F0UL;
867 tx_timer_create(&timer_0, "TIMER 0", test_process, 0, 1, 1, TX_AUTO_ACTIVATE);
868 /* Invoke functions in timer thread. */
869 tx_thread_sleep(NX_IP_PERIODIC_RATE);
870 tx_timer_delete(&timer_0);
871 #endif /* TX_TIMER_PROCESS_IN_ISR */
872
873 /* Restore. */
874 _tx_thread_current_ptr = old_thread;
875 _tx_thread_system_state = old_state;
876
877 /* 1.3 _tx_thread_current_ptr = &_tx_timer_thread, _tx_thread_system_state = 0. */
878 expected_system_state = 0;
879 tx_timer_create(&timer_0, "TIMER 1", test_process, 0, 1, 1, TX_AUTO_ACTIVATE);
880 /* Invoke functions in timer thread. */
881 tx_thread_sleep(NX_IP_PERIODIC_RATE);
882 tx_timer_delete(&timer_0);
883
884 /* Restore. */
885 _tx_thread_current_ptr = old_thread;
886 _tx_thread_system_state = old_state;
887
888
889 /* 2. NX_NOT_ISR_CALLER_CHECKING checking. */
890 /* 2.1 _tx_thread_system_state = 0 */
891 _tx_thread_system_state = 0;
892 if (nx_udp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) == NX_CALLER_ERROR)
893 {
894 error_counter++;
895 }
896 if (nx_udp_socket_info_get(&udp_socket, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) == NX_CALLER_ERROR)
897 {
898 error_counter++;
899 }
900 ip_0.nx_ip_udp_packet_receive = NX_NULL;
901 if (nx_udp_enable(&ip_0) == NX_CALLER_ERROR)
902 {
903 error_counter++;
904 }
905 ip_0.nx_ip_udp_packet_receive = _nx_udp_packet_receive;
906 if (nx_udp_socket_checksum_disable(&udp_socket) == NX_CALLER_ERROR)
907 {
908 error_counter++;
909 }
910 if (nx_udp_socket_checksum_enable(&udp_socket) == NX_CALLER_ERROR)
911 {
912 error_counter++;
913 }
914 if (nx_packet_pool_info_get(&pool_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) == NX_CALLER_ERROR)
915 {
916 error_counter++;
917 }
918 if (nx_ip_forwarding_enable(&ip_0) == NX_CALLER_ERROR)
919 {
920 error_counter++;
921 }
922 if (nx_ip_forwarding_disable(&ip_0) == NX_CALLER_ERROR)
923 {
924 error_counter++;
925 }
926
927 /* 2.2 _tx_thread_system_state = 1 */
928 _tx_thread_system_state = 1;
929 if (nx_udp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
930 {
931 error_counter++;
932 }
933 if (nx_udp_socket_info_get(&udp_socket, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
934 {
935 error_counter++;
936 }
937 ip_0.nx_ip_udp_packet_receive = NX_NULL;
938 if (nx_udp_enable(&ip_0) != NX_CALLER_ERROR)
939 {
940 error_counter++;
941 }
942 ip_0.nx_ip_udp_packet_receive = _nx_udp_packet_receive;
943 if (nx_udp_socket_checksum_disable(&udp_socket) != NX_CALLER_ERROR)
944 {
945 error_counter++;
946 }
947 if (nx_udp_socket_checksum_enable(&udp_socket) != NX_CALLER_ERROR)
948 {
949 error_counter++;
950 }
951 if (nx_packet_pool_info_get(&pool_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) != NX_CALLER_ERROR)
952 {
953 error_counter++;
954 }
955 if (nx_ip_forwarding_enable(&ip_0) != NX_CALLER_ERROR)
956 {
957 error_counter++;
958 }
959 if (nx_ip_forwarding_disable(&ip_0) != NX_CALLER_ERROR)
960 {
961 error_counter++;
962 }
963 ip_0.nx_ip_tcp_packet_receive = NX_NULL;
964 if (nx_tcp_enable(&ip_0) != NX_CALLER_ERROR)
965 {
966 error_counter++;
967 }
968 ip_0.nx_ip_tcp_packet_receive = _nx_tcp_packet_receive;
969
970 /* 2.3 _tx_thread_system_state = 0xF0F0F0F0UL */
971 _tx_thread_system_state = 0xF0F0F0F0UL;
972 if (nx_udp_info_get(&ip_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) == NX_CALLER_ERROR)
973 {
974 error_counter++;
975 }
976 if (nx_udp_socket_info_get(&udp_socket, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) == NX_CALLER_ERROR)
977 {
978 error_counter++;
979 }
980 ip_0.nx_ip_udp_packet_receive = NX_NULL;
981 if (nx_udp_enable(&ip_0) == NX_CALLER_ERROR)
982 {
983 error_counter++;
984 }
985 ip_0.nx_ip_udp_packet_receive = _nx_udp_packet_receive;
986 if (nx_udp_socket_checksum_disable(&udp_socket) == NX_CALLER_ERROR)
987 {
988 error_counter++;
989 }
990 if (nx_udp_socket_checksum_enable(&udp_socket) == NX_CALLER_ERROR)
991 {
992 error_counter++;
993 }
994 if (nx_packet_pool_info_get(&pool_0, NX_NULL, NX_NULL, NX_NULL, NX_NULL, NX_NULL) == NX_CALLER_ERROR)
995 {
996 error_counter++;
997 }
998 if (nx_ip_forwarding_enable(&ip_0) == NX_CALLER_ERROR)
999 {
1000 error_counter++;
1001 }
1002 if (nx_ip_forwarding_disable(&ip_0) == NX_CALLER_ERROR)
1003 {
1004 error_counter++;
1005 }
1006 ip_0.nx_ip_tcp_packet_receive = NX_NULL;
1007 if (nx_tcp_enable(&ip_0) == NX_CALLER_ERROR)
1008 {
1009 error_counter++;
1010 }
1011 ip_0.nx_ip_tcp_packet_receive = _nx_tcp_packet_receive;
1012
1013 /* Restore. */
1014 _tx_thread_current_ptr = old_thread;
1015 _tx_thread_system_state = old_state;
1016
1017
1018 /* 3. NX_THREADS_ONLY_CALLER_CHECKING checking. */
1019 /* 3.1 _tx_thread_system_state = 1 */
1020 expected_system_state = 1;
1021 test_process_1(0);
1022
1023 /* Restore. */
1024 _tx_thread_current_ptr = old_thread;
1025 _tx_thread_system_state = old_state;
1026
1027 /* 3.2 _tx_thread_current_ptr = &_tx_timer_thread, _tx_thread_system_state = 0. */
1028 expected_system_state = 0;
1029 tx_timer_create(&timer_0, "TIMER 2", test_process_1, 0, 1, 1, TX_AUTO_ACTIVATE);
1030 /* Invoke functions in timer thread. */
1031 tx_thread_sleep(NX_IP_PERIODIC_RATE);
1032 tx_timer_delete(&timer_0);
1033
1034 /* Restore. */
1035 _tx_thread_current_ptr = old_thread;
1036 _tx_thread_system_state = old_state;
1037
1038 /* 3.3 _tx_thread_current_ptr = TX_NULL, _tx_thread_system_state = 0. */
1039 expected_system_state = 0;
1040 test_process_1(1);
1041
1042 /* Restore. */
1043 _tx_thread_current_ptr = old_thread;
1044 _tx_thread_system_state = old_state;
1045
1046 /* 4. NX_THREAD_WAIT_CALLER_CHECKING checking. */
1047 /* 4.1 _tx_thread_system_state = 1. */
1048 expected_system_state = 1;
1049 test_process_2(0);
1050
1051 /* 4.2 _tx_thread_current_ptr = TX_NULL, _tx_thread_system_state = 0. */
1052 expected_system_state = 0;
1053 test_process_2(1);
1054
1055 /* 4.3 _tx_thread_current_ptr = &_tx_timer_thread, _tx_thread_system_state = 0. */
1056 expected_system_state = 0;
1057 tx_timer_create(&timer_0, "TIMER 3", test_process_2, 0, 1, 1, TX_AUTO_ACTIVATE);
1058 /* Invoke functions in timer thread. */
1059 tx_thread_sleep(NX_IP_PERIODIC_RATE);
1060 tx_timer_delete(&timer_0);
1061
1062 /* Restore. */
1063 _tx_thread_current_ptr = old_thread;
1064 _tx_thread_system_state = old_state;
1065 TX_RESTORE
1066
1067 /* Check status. */
1068 if (error_counter)
1069 {
1070 printf("ERROR!\n");
1071 test_control_return(1);
1072 }
1073 else
1074 {
1075 printf("SUCCESS!\n");
1076 test_control_return(0);
1077 }
1078 }
1079
link_status_change_notify(NX_IP * ip_ptr,UINT interface_index,UINT link_up)1080 static void link_status_change_notify(NX_IP *ip_ptr, UINT interface_index, UINT link_up)
1081 {
1082 }
1083
tcp_receive_notify(NX_TCP_SOCKET * socket_ptr)1084 static void tcp_receive_notify(NX_TCP_SOCKET *socket_ptr)
1085 {
1086 }
1087
tcp_socket_window_update_notify(NX_TCP_SOCKET * socket_ptr)1088 static VOID tcp_socket_window_update_notify(NX_TCP_SOCKET *socket_ptr)
1089 {
1090 }
1091
1092 #else
1093 #ifdef CTEST
test_application_define(void * first_unused_memory)1094 VOID test_application_define(void *first_unused_memory)
1095 #else
1096 void netx_caller_check_test_application_define(void *first_unused_memory)
1097 #endif
1098 {
1099
1100 /* Print out test information banner. */
1101 printf("NetX Test: Caller Check Test.........................................N/A\n");
1102
1103 test_control_return(3);
1104 }
1105 #endif
1106