1
2 #include "tx_api.h"
3 #include "nx_api.h"
4 #include "nxd_dhcp_client.h"
5 #include "nxd_dhcp_server.h"
6 #include "nx_ram_network_driver_test_1500.h"
7
8 extern void test_control_return(UINT status);
9
10 #if !defined(NX_DISABLE_IPV4) && (NX_MAX_PHYSICAL_INTERFACES >= 2)
11
12 #define DEMO_STACK_SIZE 4096
13 #define NX_PACKET_SIZE 1536
14 #define NX_PACKET_POOL_SIZE NX_PACKET_SIZE * 8
15
16 #define NX_DHCP_SERVER_IP_ADDRESS_0 IP_ADDRESS(1,0,0,1)
17 #define NX_DHCP_SUBNET_MASK_0 IP_ADDRESS(255,255,255,0)
18
19 #define NX_DHCP_SERVER_IP_ADDRESS_1 IP_ADDRESS(10,0,0,1)
20 #define START_IP_ADDRESS_LIST_1 IP_ADDRESS(10,0,0,10)
21 #define END_IP_ADDRESS_LIST_1 IP_ADDRESS(10,0,0,19)
22
23 #define NX_DHCP_SUBNET_MASK_1 IP_ADDRESS(255,255,255,0)
24 #define NX_DHCP_DEFAULT_GATEWAY_1 IP_ADDRESS(10,0,0,1)
25 #define NX_DHCP_DNS_SERVER_1 IP_ADDRESS(10,0,0,1)
26
27 #define NX_DHCP_INTERFACE_INDEX 1
28
29
30 /* Define the ThreadX and NetX object control blocks... */
31 static TX_THREAD client_thread;
32
33 static TX_THREAD server_thread;
34 static NX_PACKET_POOL server_pool;
35 static NX_IP server_ip;
36 static NX_DHCP_SERVER dhcp_server;
37
38 /* Define the counters used in the demo application... */
39
40 static ULONG state_changes;
41 static ULONG error_counter;
42 static CHAR *pointer;
43 static CHAR offer_packet = NX_FALSE;
44 static CHAR ack_packet = NX_FALSE;
45 static CHAR test_done = NX_FALSE;
46
47 static UCHAR message[50] = "My Ping Request!" ;
48
49
50 /* Define thread prototypes. */
51
52 static void server_thread_entry(ULONG thread_input);
53 static void client_thread_entry(ULONG thread_input);
54 extern UINT (*advanced_packet_process_callback)(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr);
55 static UINT my_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr);
56
57 /******** Optionally substitute your Ethernet driver here. ***********/
58 extern void _nx_ram_network_driver_1024(struct NX_IP_DRIVER_STRUCT *driver_req);
59 extern void _nx_ram_network_driver_1500(struct NX_IP_DRIVER_STRUCT *driver_req);
60
61
62 /* Note that the MAC address of Client is 00:11:22:33:44:56.
63 the MAC address of Server is 00:11:22:33:44:57. */
64
65 /* Frame (342 bytes) */
66 static const unsigned char pkt1[342] = {
67 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x11, /* ........ */
68 0x22, 0x33, 0x44, 0x56, 0x08, 0x00, 0x45, 0x00, /* "3DV..E. */
69 0x01, 0x48, 0x00, 0x01, 0x40, 0x00, 0x80, 0x11, /* .H..@... */
70 0xf9, 0xa4, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* ........ */
71 0xff, 0xff, 0x00, 0x44, 0x00, 0x43, 0x01, 0x34, /* ...D.C.4 */
72 0x59, 0x2a, 0x01, 0x01, 0x06, 0x00, 0x22, 0x33, /* Y*...."3 */
73 0x44, 0x6e, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* Dn...... */
74 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
75 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, /* ........ */
76 0x22, 0x33, 0x44, 0x56, 0x00, 0x00, 0x00, 0x00, /* "3DV.... */
77 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
78 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
79 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
80 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
81 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
83 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
84 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
85 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
86 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
87 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
88 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
89 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
90 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
91 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
92 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
93 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
94 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
95 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
96 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
97 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
98 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
99 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
100 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
101 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, /* ......c. */
102 0x53, 0x63, 0x35, 0x01, 0x01, 0x33, 0x04, 0xff, /* Sc5..3.. */
103 0xff, 0xff, 0xff, 0x0c, 0x0b, 0x64, 0x68, 0x63, /* .....dhc */
104 0x70, 0x5f, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, /* p_client */
105 0x37, 0x03, 0x01, 0x03, 0x06, 0xff, 0x00, 0x00, /* 7....... */
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
107 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
108 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
109 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* ...... */
110 };
111
112 /* Frame (342 bytes) */
113 static const unsigned char pkt2[342] = {
114 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x11, /* ........ */
115 0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
116 0x01, 0x48, 0x00, 0x01, 0x40, 0x00, 0x80, 0x11, /* .H..@... */
117 0xef, 0xa3, 0x0a, 0x00, 0x00, 0x01, 0xff, 0xff, /* ........ */
118 0xff, 0xff, 0x00, 0x43, 0x00, 0x44, 0x01, 0x34, /* ...C.D.4 */
119 0xbd, 0x6f, 0x02, 0x01, 0x06, 0x00, 0x22, 0x33, /* .o...."3 */
120 0x44, 0x6e, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* Dn...... */
121 0x00, 0x00, 0x0a, 0x00, 0x00, 0x0a, 0x00, 0x00, /* ........ */
122 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, /* ........ */
123 0x22, 0x33, 0x44, 0x56, 0x00, 0x00, 0x00, 0x00, /* "3DV.... */
124 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
125 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
126 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
127 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
128 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
129 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
130 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
131 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
132 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
133 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
134 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
135 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
136 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
137 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
138 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
139 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
140 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
141 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
142 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
143 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
144 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
145 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
146 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
147 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
148 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, /* ......c. */
149 0x53, 0x63, 0x35, 0x01, 0x02, 0x36, 0x04, 0x0a, /* Sc5..6.. */
150 0x00, 0x00, 0x01, 0x01, 0x04, 0xff, 0xff, 0xff, /* ........ */
151 0x00, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x01, 0x06, /* ........ */
152 0x04, 0x0a, 0x00, 0x00, 0x01, 0x33, 0x04, 0x00, /* .....3.. */
153 0x00, 0x27, 0x10, 0x3a, 0x04, 0x00, 0x00, 0x13, /* .'.:.... */
154 0x88, 0x3b, 0x04, 0x00, 0x00, 0x22, 0x2e, 0xff, /* .;...".. */
155 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
156 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* ...... */
157 };
158
159 /* Frame (342 bytes) */
160 static const unsigned char pkt3[342] = {
161 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x11, /* ........ */
162 0x22, 0x33, 0x44, 0x56, 0x08, 0x00, 0x45, 0x00, /* "3DV..E. */
163 0x01, 0x48, 0x00, 0x02, 0x40, 0x00, 0x80, 0x11, /* .H..@... */
164 0xf9, 0xa3, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, /* ........ */
165 0xff, 0xff, 0x00, 0x44, 0x00, 0x43, 0x01, 0x34, /* ...D.C.4 */
166 0xdf, 0x49, 0x01, 0x01, 0x06, 0x00, 0x22, 0x33, /* .I...."3 */
167 0x44, 0x6e, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* Dn...... */
168 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
169 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, /* ........ */
170 0x22, 0x33, 0x44, 0x56, 0x00, 0x00, 0x00, 0x00, /* "3DV.... */
171 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
172 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
173 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
174 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
175 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
176 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
177 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
182 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
183 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
184 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
185 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
186 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
187 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
188 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
189 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
190 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
191 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
192 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
193 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
195 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, /* ......c. */
196 0x53, 0x63, 0x35, 0x01, 0x03, 0x0c, 0x0b, 0x64, /* Sc5....d */
197 0x68, 0x63, 0x70, 0x5f, 0x63, 0x6c, 0x69, 0x65, /* hcp_clie */
198 0x6e, 0x74, 0x32, 0x04, 0x0a, 0x00, 0x00, 0x0a, /* nt2..... */
199 0x36, 0x04, 0x0a, 0x00, 0x00, 0x01, 0x37, 0x03, /* 6.....7. */
200 0x01, 0x03, 0x06, 0xff, 0x00, 0x00, 0x00, 0x00, /* ........ */
201 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
202 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
203 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* ...... */
204 };
205
206 /* Frame (342 bytes) */
207 static const unsigned char pkt4[342] = {
208 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x11, /* ........ */
209 0x22, 0x33, 0x44, 0x57, 0x08, 0x00, 0x45, 0x00, /* "3DW..E. */
210 0x01, 0x48, 0x00, 0x02, 0x40, 0x00, 0x80, 0x11, /* .H..@... */
211 0xef, 0xa2, 0x0a, 0x00, 0x00, 0x01, 0xff, 0xff, /* ........ */
212 0xff, 0xff, 0x00, 0x43, 0x00, 0x44, 0x01, 0x34, /* ...C.D.4 */
213 0xba, 0x6f, 0x02, 0x01, 0x06, 0x00, 0x22, 0x33, /* .o...."3 */
214 0x44, 0x6e, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, /* Dn...... */
215 0x00, 0x00, 0x0a, 0x00, 0x00, 0x0a, 0x00, 0x00, /* ........ */
216 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, /* ........ */
217 0x22, 0x33, 0x44, 0x56, 0x00, 0x00, 0x00, 0x00, /* "3DV.... */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
219 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
220 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
221 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
222 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
223 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
224 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
225 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
226 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
227 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
229 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
239 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
240 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
241 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x82, /* ......c. */
243 0x53, 0x63, 0x35, 0x01, 0x05, 0x36, 0x04, 0x0a, /* Sc5..6.. */
244 0x00, 0x00, 0x01, 0x01, 0x04, 0xff, 0xff, 0xff, /* ........ */
245 0x00, 0x03, 0x04, 0x0a, 0x00, 0x00, 0x01, 0x06, /* ........ */
246 0x04, 0x0a, 0x00, 0x00, 0x01, 0x33, 0x04, 0x00, /* .....3.. */
247 0x00, 0x27, 0x10, 0x3a, 0x04, 0x00, 0x00, 0x13, /* .'.:.... */
248 0x88, 0x3b, 0x04, 0x00, 0x00, 0x22, 0x2e, 0xff, /* .;...".. */
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* ...... */
251 };
252
253 /* Define what the initial system looks like. */
254
255 #ifdef CTEST
test_application_define(void * first_unused_memory)256 VOID test_application_define(void *first_unused_memory)
257 #else
258 void netx_dhcp_server_second_interface_test_application_define(void *first_unused_memory)
259 #endif
260 {
261
262 UINT status;
263
264
265 /* Setup the working pointer. */
266 pointer = (CHAR *) first_unused_memory;
267
268 /* Create the client thread. */
269 tx_thread_create(&client_thread, "thread client", client_thread_entry, 0,
270 pointer, DEMO_STACK_SIZE,
271 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
272 pointer = pointer + DEMO_STACK_SIZE;
273
274 /* Create the server thread. */
275 tx_thread_create(&server_thread, "thread server", server_thread_entry, 0,
276 pointer, DEMO_STACK_SIZE,
277 3, 3, TX_NO_TIME_SLICE, TX_AUTO_START);
278 pointer = pointer + DEMO_STACK_SIZE;
279
280 /* Initialize the NetX system. */
281 nx_system_initialize();
282
283 /* Create the server packet pool. */
284 status = nx_packet_pool_create(&server_pool, "NetX Main Packet Pool", 1024, pointer, NX_PACKET_POOL_SIZE);
285 pointer = pointer + NX_PACKET_POOL_SIZE;
286
287 /* Check for pool creation error. */
288 if (status)
289 error_counter++;
290
291 /* Create an IP instance for the DHCP Server. */
292 status = nx_ip_create(&server_ip, "DHCP Server", NX_DHCP_SERVER_IP_ADDRESS_0, NX_DHCP_SUBNET_MASK_0, &server_pool, _nx_ram_network_driver_1024, pointer, 2048, 1);
293
294 pointer = pointer + 2048;
295
296 /* Check for IP create errors. */
297 if (status)
298 error_counter++;
299
300 /* Attach the second interface. */
301 status = nx_ip_interface_attach(&server_ip, "DHCP Server Secondary Interface", NX_DHCP_SERVER_IP_ADDRESS_1, NX_DHCP_SUBNET_MASK_1, _nx_ram_network_driver_1500);
302
303 if (status)
304 {
305 error_counter++;
306 }
307
308 /* Enable ARP and supply ARP cache memory for DHCP Server IP. */
309 status = nx_arp_enable(&server_ip, (void *) pointer, 1024);
310 pointer = pointer + 1024;
311
312 /* Check for ARP enable errors. */
313 if (status)
314 error_counter++;
315
316 /* Enable UDP traffic. */
317 status = nx_udp_enable(&server_ip);
318
319 /* Check for UDP enable errors. */
320 if (status)
321 error_counter++;
322
323 /* Enable ICMP. */
324 status = nx_icmp_enable(&server_ip);
325
326 /* Check for errors. */
327 if (status)
328 error_counter++;
329
330 return;
331 }
332
333 /* Define the test threads. */
334
server_thread_entry(ULONG thread_input)335 void server_thread_entry(ULONG thread_input)
336 {
337
338 UINT status;
339 UINT addresses_added;
340
341 NX_PARAMETER_NOT_USED(thread_input);
342
343 printf("NetX Test: NetX DHCP Server Second Interface Test....................");
344
345 advanced_packet_process_callback = my_packet_process;
346
347 #ifdef __PRODUCT_NETXDUO__
348 /* Update the MAC address. */
349 status = nx_ip_interface_physical_address_set(&server_ip, 0, 0x00000011, 0x22334455, NX_TRUE);
350 status += nx_ip_interface_physical_address_set(&server_ip, 1, 0x00000011, 0x22334457, NX_TRUE);
351
352 /* Check for errors. */
353 if (status)
354 {
355 printf("ERROR!\n");
356 test_control_return(1);
357 }
358 #else
359 server_ip.nx_ip_interface[0].nx_interface_physical_address_msw = 0x00000011;
360 server_ip.nx_ip_interface[0].nx_interface_physical_address_lsw = 0x22334455;
361
362 server_ip.nx_ip_interface[1].nx_interface_physical_address_msw = 0x00000011;
363 server_ip.nx_ip_interface[1].nx_interface_physical_address_lsw = 0x22334457;
364
365 #endif
366
367 /* Create the DHCP Server. */
368 status = nx_dhcp_server_create(&dhcp_server, &server_ip, pointer, DEMO_STACK_SIZE,
369 "DHCP Server", &server_pool);
370
371 pointer = pointer + DEMO_STACK_SIZE;
372
373 /* Check for errors creating the DHCP Server. */
374 if (status)
375 {
376 printf("ERROR!\n");
377 test_control_return(1);
378 }
379
380 /* Load the assignable DHCP IP addresses. */
381 status = nx_dhcp_create_server_ip_address_list(&dhcp_server, NX_DHCP_INTERFACE_INDEX, START_IP_ADDRESS_LIST_1,
382 END_IP_ADDRESS_LIST_1, &addresses_added);
383
384 /* Check for errors creating the list. */
385 if (status)
386 {
387 printf("ERROR!\n");
388 test_control_return(1);
389 }
390
391 /* Verify all the addresses were added to the list. */
392 if (addresses_added != 10)
393 {
394 printf("ERROR!\n");
395 test_control_return(1);
396 }
397
398 status = nx_dhcp_set_interface_network_parameters(&dhcp_server, NX_DHCP_INTERFACE_INDEX, NX_DHCP_SUBNET_MASK_1,
399 NX_DHCP_DEFAULT_GATEWAY_1, NX_DHCP_DNS_SERVER_1);
400
401 /* Check for errors setting network parameters. */
402 if (status)
403 {
404 printf("ERROR!\n");
405 test_control_return(1);
406 }
407
408 /* Start DHCP Server task. */
409 status = nx_dhcp_server_start(&dhcp_server);
410
411 /* Check for errors starting up the DHCP server. */
412 if (status)
413 {
414 printf("ERROR!\n");
415 test_control_return(1);
416 }
417
418 tx_thread_sleep(20 * NX_IP_PERIODIC_RATE);
419
420 if ((error_counter != 0) || (offer_packet != NX_TRUE) || (ack_packet != NX_TRUE))
421 {
422 printf("ERROR!\n");
423 test_control_return(1);
424 }
425 else
426 {
427 printf("SUCCESS!\n");
428 test_control_return(0);
429 }
430
431 return;
432 }
433
434
435 /* Define the test threads. */
436
client_thread_entry(ULONG thread_input)437 void client_thread_entry(ULONG thread_input)
438 {
439
440 UINT status;
441 NX_PACKET *discover_packet;
442
443 NX_PARAMETER_NOT_USED(thread_input);
444
445 /* Allocate a Discover packet. */
446 status = nx_packet_allocate(&server_pool, &discover_packet, NX_UDP_PACKET, NX_NO_WAIT);
447
448 /* Check status. */
449 if (status)
450 {
451 error_counter++;
452 }
453
454 /* Append the data. */
455 status = nx_packet_data_append(discover_packet, (void *)&pkt1[14], (sizeof(pkt1) - 14), &server_pool, NX_NO_WAIT);
456
457 if (status)
458 {
459 error_counter++;
460 }
461
462 /* Set the interface. */
463 discover_packet -> nx_packet_ip_interface = &server_ip.nx_ip_interface[1];
464
465 /* Call API to receive the packet. */
466 _nx_ip_packet_receive(&server_ip, discover_packet);
467 }
468
my_packet_process(NX_IP * ip_ptr,NX_PACKET * packet_ptr,UINT * operation_ptr,UINT * delay_ptr)469 static UINT my_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr)
470 {
471
472 UINT status;
473 NX_PACKET *request_packet;
474
475 NX_PARAMETER_NOT_USED(ip_ptr);
476 NX_PARAMETER_NOT_USED(operation_ptr);
477 NX_PARAMETER_NOT_USED(delay_ptr);
478
479 /* Check the packet interface. */
480 if (packet_ptr -> nx_packet_ip_interface == &server_ip.nx_ip_interface[1])
481 {
482
483 /* Check the offer_packet flag. */
484 if (offer_packet == NX_FALSE)
485 {
486
487 /* Compare the packet. */
488 if ((packet_ptr -> nx_packet_length == sizeof(pkt2) - 14) &&
489 (memcmp(packet_ptr -> nx_packet_prepend_ptr, &pkt2[14], packet_ptr -> nx_packet_length) == 0))
490 {
491 offer_packet = NX_TRUE;
492
493 /* Allocate a Request packet. */
494 status = nx_packet_allocate(&server_pool, &request_packet, NX_UDP_PACKET, NX_NO_WAIT);
495
496 /* Check status. */
497 if (status)
498 {
499 error_counter++;
500 }
501
502 /* Append the data. */
503 status = nx_packet_data_append(request_packet, (void *)&pkt3[14], sizeof(pkt3) - 14, &server_pool, NX_NO_WAIT);
504
505 if (status)
506 {
507 error_counter++;
508 }
509
510 /* Set the interface. */
511 request_packet -> nx_packet_ip_interface = &server_ip.nx_ip_interface[1];
512
513 /* Call API to receive the packet. */
514 _nx_ip_packet_receive(&server_ip, request_packet);
515 }
516 }
517 else
518 {
519
520 /* Compare the packet. */
521 if ((packet_ptr -> nx_packet_length == sizeof(pkt4) - 14) &&
522 (memcmp(packet_ptr -> nx_packet_prepend_ptr, &pkt4[14], packet_ptr -> nx_packet_length) == 0))
523 {
524 ack_packet = NX_TRUE;
525 }
526 }
527 }
528
529 nx_packet_release(packet_ptr);
530 return NX_FALSE;
531 }
532
533 #else
534
535 #ifdef CTEST
test_application_define(void * first_unused_memory)536 VOID test_application_define(void *first_unused_memory)
537 #else
538 void netx_dhcp_server_second_interface_test_application_define(void *first_unused_memory)
539 #endif
540 {
541
542 /* Print out test information banner. */
543 printf("NetX Test: NetX DHCP Server Second Interface Test....................N/A\n");
544
545 test_control_return(3);
546 }
547 #endif
548