1 /* This case tests if compile works with old APIs. */
2
3 #include "nx_api.h"
4 #include "tx_api.h"
5
6 extern void test_control_return(UINT status);
7
8 #if defined(__PRODUCT_NETXDUO__)
9
10 #define DEMO_STACK_SIZE 2048
11
12 /* Define the ThreadX and NetX object control blocks... */
13
14 static NX_PACKET_POOL pool_0;
15 static NX_IP ip_0;
16 static TX_THREAD ntest_0;
17
18 /* Define the counters used in the test application... */
19
20 static ULONG error_counter;
21
22 /* Define thread prototypes. */
23
24 extern void _nx_ram_network_driver(struct NX_IP_DRIVER_STRUCT *driver_req);
25 static void ntest_0_entry(ULONG thread_input);
26
27 /* Define what the initial system looks like. */
28
29 #ifdef CTEST
test_application_define(void * first_unused_memory)30 VOID test_application_define(void *first_unused_memory)
31 #else
32 void netx_old_api_application_define(void *first_unused_memory)
33 #endif
34 {
35 UCHAR *pointer;
36 UINT status;
37
38
39 /* Setup the working pointer. */
40 pointer = (UCHAR *) first_unused_memory;
41
42 error_counter = 0;
43
44 /* Initialize the NetX system. */
45 nx_system_initialize();
46
47 /* Create a packet pool. */
48 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 256, pointer, 8192);
49 pointer = pointer + 8192;
50
51 if(status)
52 error_counter++;
53
54 /* Create an IP instance. */
55 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver,
56 pointer, 2048, 1);
57 pointer = pointer + 2048;
58
59 if(status)
60 error_counter++;
61
62 /* Create the main thread. */
63 tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,
64 pointer, DEMO_STACK_SIZE,
65 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
66
67 pointer = pointer + DEMO_STACK_SIZE;
68 }
69
70 /* Define the test threads. */
71
ntest_0_entry(ULONG thread_input)72 static void ntest_0_entry(ULONG thread_input)
73 {
74 #if defined(__PRODUCT_NETXDUO__)
75 NX_PACKET *packet_ptr;
76 NX_UDP_SOCKET udp_socket;
77 #ifdef FEATURE_NX_IPV6
78
79 NXD_ADDRESS src_address;
80
81 /* Set source and destination address with global address. */
82 src_address.nxd_ip_version = NX_IP_VERSION_V6;
83 src_address.nxd_ip_address.v6[0] = 0x20010DB8;
84 src_address.nxd_ip_address.v6[1] = 0x00010001;
85 src_address.nxd_ip_address.v6[2] = 0x021122FF;
86 src_address.nxd_ip_address.v6[3] = 0xFE334456;
87
88 nxd_ipv6_address_set(&ip_0, 0, &src_address, 64, NX_NULL);
89 #endif
90
91 /* Test old APIs. */
92 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
93 nx_ip_raw_packet_interface_send(&ip_0, packet_ptr, IP_ADDRESS(1, 2, 3, 5), 0, NX_IP_NORMAL);
94
95 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
96 nx_udp_socket_create(&ip_0, &udp_socket, "Socket 0", NX_IP_NORMAL, NX_FRAGMENT_OKAY, 0x80, 5);
97 nx_udp_socket_bind(&udp_socket, 0x88, TX_WAIT_FOREVER);
98 nx_udp_socket_interface_send(&udp_socket, packet_ptr, IP_ADDRESS(1, 2, 3, 5), 87, 0);
99
100 #ifdef FEATURE_NX_IPV6
101 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
102 nxd_ip_raw_packet_interface_send(&ip_0, packet_ptr, &src_address, 0, 100, 255, NX_IP_NORMAL);
103
104 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
105 nxd_udp_socket_interface_send(&udp_socket, packet_ptr, &src_address, 87, 0);
106
107 nxd_icmp_interface_ping(&ip_0, &src_address, 0, "test", 4, &packet_ptr, TX_NO_WAIT);
108 #endif
109
110 /* Test new APIs. */
111 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
112 nx_ip_raw_packet_interface_send(&ip_0, packet_ptr, IP_ADDRESS(1, 2, 3, 5), 0, NX_IP_NORMAL);
113
114 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
115 nx_udp_socket_source_send(&udp_socket, packet_ptr, IP_ADDRESS(1, 2, 3, 5), 87, 0);
116
117 #ifdef FEATURE_NX_IPV6
118 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
119 nxd_ip_raw_packet_source_send(&ip_0, packet_ptr, &src_address, 0, 100, 255, NX_IP_NORMAL);
120
121 nx_packet_allocate(&pool_0, &packet_ptr, NX_UDP_PACKET, TX_NO_WAIT);
122 nxd_udp_socket_source_send(&udp_socket, packet_ptr, &src_address, 87, 0);
123
124 nxd_icmp_source_ping(&ip_0, &src_address, 0, "test", 4, &packet_ptr, TX_NO_WAIT);
125 #endif
126
127 printf("NetX Test: Old APIs Test.............................................SUCCESS!\n");
128 test_control_return(0);
129 #endif
130 }
131 #else
132 #ifdef CTEST
test_application_define(void * first_unused_memory)133 VOID test_application_define(void *first_unused_memory)
134 #else
135 void netx_old_api_application_define(void *first_unused_memory)
136 #endif
137 {
138 printf("NetX Test: Old APIs Test.............................................N/A\n");
139 test_control_return(3);
140 }
141 #endif
142