1 /* This tests the use of requesting and processing primary and secondary DNS servers
2 as part of the IPCP handshake. */
3
4 #include "tx_api.h"
5 #include "nx_api.h"
6 #include "nx_ppp.h"
7
8 extern void test_control_return(UINT status);
9
10 #if !defined(NX_DISABLE_IPV4)
11
12 /* Define demo stack size. */
13
14 #define DEMO_STACK_SIZE 2048
15
16
17 /* Define the ThreadX and NetX object control blocks... */
18
19 static TX_THREAD thread_0;
20 static TX_THREAD thread_1;
21 static NX_PACKET_POOL pool_0;
22 static NX_IP ip_0;
23 static NX_IP ip_1;
24 static NX_PPP ppp_0;
25 static NX_PPP ppp_1;
26
27
28 /* Define the counters used in the demo application... */
29
30 static ULONG error_counter = 0;
31 static UINT thread_1_alive = NX_TRUE;
32 static ULONG dns_address = 0 ;
33 static ULONG secondary_dns_address = 0;
34
35 /* Define thread prototypes. */
36 static void thread_0_entry(ULONG thread_input);
37 static void thread_1_entry(ULONG thread_input);
38 static void ppp_0_serial_byte_output(UCHAR byte);
39 static void ppp_1_serial_byte_output(UCHAR byte);
40 static void invalid_packet_handler(NX_PACKET *packet_ptr);
41
42
43 /* Define what the initial system looks like. */
44
45 #ifdef CTEST
test_application_define(void * first_unused_memory)46 VOID test_application_define(void *first_unused_memory)
47 #else
48 void netx_ppp_request_dns_server_test_application_define(void *first_unused_memory)
49 #endif
50 {
51
52 CHAR *pointer;
53 UINT status;
54
55
56 /* Setup the working pointer. */
57 pointer = (CHAR *) first_unused_memory;
58
59 /* Create the thread 0. */
60 tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
61 pointer, DEMO_STACK_SIZE,
62 5, 5, TX_NO_TIME_SLICE, TX_AUTO_START);
63 pointer = pointer + DEMO_STACK_SIZE;
64
65 /* Create the thread 1. */
66 tx_thread_create(&thread_1, "thread 1", thread_1_entry, 0,
67 pointer, DEMO_STACK_SIZE,
68 5, 5, TX_NO_TIME_SLICE, TX_AUTO_START);
69 pointer = pointer + DEMO_STACK_SIZE;
70
71 /* Initialize the NetX system. */
72 nx_system_initialize();
73
74
75 /* Create a packet pool. */
76 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", NX_PPP_MIN_PACKET_PAYLOAD, pointer, 2048);
77 pointer = pointer + 2048;
78
79 /* Check for pool creation error. */
80 if (status)
81 {
82 error_counter++;
83 }
84
85 /* Create the first PPP instance. */
86 status = nx_ppp_create(&ppp_0, "PPP 0", &ip_0, pointer, 2048, 1, &pool_0, invalid_packet_handler, ppp_0_serial_byte_output);
87 pointer = pointer + 2048;
88
89 /* Check for PPP create error. */
90 if (status)
91 {
92 error_counter++;
93 }
94
95 /* Define IP address. This PPP instance is effectively the server since it has both IP addresses. */
96 status = nx_ppp_ip_address_assign(&ppp_0, IP_ADDRESS(1, 2, 3, 4), IP_ADDRESS(1, 2, 3, 5));
97
98 /* Check for PPP IP address assign error. */
99 if (status)
100 {
101 error_counter++;
102 }
103
104 /* Create an IP instance. */
105 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(0, 0, 0, 0), 0xFFFFF000UL, &pool_0, nx_ppp_driver,
106 pointer, 2048, 1);
107 pointer = pointer + 2048;
108
109 /* Check for IP create error. */
110 if (status)
111 {
112 error_counter++;
113 }
114
115 /* Create the next PPP instance. */
116 status = nx_ppp_create(&ppp_1, "PPP 1", &ip_1, pointer, 2048, 1, &pool_0, invalid_packet_handler, ppp_1_serial_byte_output);
117 pointer = pointer + 2048;
118
119 /* Check for PPP create error. */
120 if (status)
121 {
122 error_counter++;
123 }
124
125 /* Define IP address. This PPP instance is effectively the client since it doesn't have any IP addresses. */
126 status = nx_ppp_ip_address_assign(&ppp_1, IP_ADDRESS(0, 0, 0, 0), IP_ADDRESS(0, 0, 0, 0));
127
128 /* Check for PPP IP address assign error. */
129 if (status)
130 {
131 error_counter++;
132 }
133
134 /* Create another IP instance. */
135 status = nx_ip_create(&ip_1, "NetX IP Instance 1", IP_ADDRESS(0, 0, 0, 0), 0xFFFFF000UL, &pool_0, nx_ppp_driver,
136 pointer, 2048, 1);
137 pointer = pointer + 2048;
138
139 /* Check for IP create error. */
140 if (status)
141 {
142 error_counter++;
143 }
144
145 /* Enable UDP traffic. */
146 nx_udp_enable(&ip_0);
147 nx_udp_enable(&ip_1);
148
149 /* Set up the PPP0 primary address. */
150 status = nx_ppp_dns_address_set(&ppp_0, IP_ADDRESS(1,2,3,89));
151
152 /* Set the PPP0 secondary DNS server */
153 status += nx_ppp_secondary_dns_address_set(&ppp_0, IP_ADDRESS(1,2,3,88));
154
155 /* Set PP1 primary DNS. Note that PPP_0 will overwrite this with its own primary DNS. */
156 status += nx_ppp_dns_address_set(&ppp_1, IP_ADDRESS(1,2,3,79));
157
158 if (status)
159 {
160 error_counter++;
161 }
162 }
163
164
165 /* Define the test threads. */
166
thread_0_entry(ULONG thread_input)167 void thread_0_entry(ULONG thread_input)
168 {
169
170 UINT status;
171 ULONG ip_status;
172
173
174
175 printf("NetX Test: PPP Request DNS Server Test...............................");
176
177 if (error_counter)
178 {
179
180 printf("ERROR!\n");
181 test_control_return(1);
182 }
183
184 /* Wait for the link to come up. */
185 do
186 {
187
188 status = nx_ip_status_check(&ip_0, NX_IP_LINK_ENABLED, &ip_status, 20 * NX_IP_PERIODIC_RATE);
189 }while(status != NX_SUCCESS);
190
191 /* Wait for the other thread to finish. */
192 while(thread_1_alive)
193 {
194
195 tx_thread_sleep(1 * NX_IP_PERIODIC_RATE);
196 }
197
198 if (!secondary_dns_address || !dns_address || error_counter)
199 {
200
201 printf("ERROR!\n");
202 test_control_return(1);
203
204 }
205
206 printf("SUCCESS!\n");
207 test_control_return(0);
208
209 return;
210 }
211
212
thread_1_entry(ULONG thread_input)213 void thread_1_entry(ULONG thread_input)
214 {
215
216 UINT status;
217 ULONG ip_status;
218
219
220 /* Wait for the link to come up. */
221 do
222 {
223
224 status = nx_ip_status_check(&ip_1, NX_IP_LINK_ENABLED, &ip_status, 20 * NX_IP_PERIODIC_RATE);
225 }while(status != NX_SUCCESS);
226
227
228 status = nx_ppp_dns_address_get(&ppp_1, &dns_address);
229 if (status != NX_SUCCESS)
230 {
231 error_counter++;
232 }
233
234 status = nx_ppp_secondary_dns_address_get(&ppp_1, &secondary_dns_address);
235 if (status != NX_SUCCESS)
236 {
237 error_counter++;
238 }
239
240 thread_1_alive = NX_FALSE;
241
242 return;
243
244 }
245
246 /* Define serial output routines. Normally these routines would
247 map to physical UART routines and the nx_ppp_byte_receive call
248 would be made from a UART receive interrupt. */
249
ppp_0_serial_byte_output(UCHAR byte)250 void ppp_0_serial_byte_output(UCHAR byte)
251 {
252
253 /* Just feed the PPP 1 input routine. */
254 nx_ppp_byte_receive(&ppp_1, byte);
255 }
256
ppp_1_serial_byte_output(UCHAR byte)257 void ppp_1_serial_byte_output(UCHAR byte)
258 {
259
260 /* Just feed the PPP 0 input routine. */
261 nx_ppp_byte_receive(&ppp_0, byte);
262 }
263
264
invalid_packet_handler(NX_PACKET * packet_ptr)265 void invalid_packet_handler(NX_PACKET *packet_ptr)
266 {
267 /* Print out the non-PPP byte. In Windows, the string "CLIENT" will
268 be sent before Windows PPP starts. Once CLIENT is received, we need
269 to send "CLIENTSERVER" to establish communication. It's also possible
270 to receive modem commands here that might need some response to
271 continue. */
272 nx_packet_release(packet_ptr);
273 }
274 #else
275
276 #ifdef CTEST
test_application_define(void * first_unused_memory)277 VOID test_application_define(void *first_unused_memory)
278 #else
279 void netx_ppp_request_dns_server_test_application_define(void *first_unused_memory)
280 #endif
281 {
282
283 /* Print out test information banner. */
284 printf("NetX Test: PPP Request DNS Server Test...............................N/A\n");
285
286 test_control_return(3);
287 }
288 #endif
289
290