1 #include "tx_api.h"
2 #include "nx_api.h"
3
4 extern void test_control_return(UINT status);
5
6 #if defined __PRODUCT_NETXDUO__ && (NX_MAX_PHYSICAL_INTERFACES > 1) && !defined NX_DISABLE_IPV4 && !defined NX_MDNS_DISABLE_SERVER && !defined NX_MDNS_DISABLE_CLIENT
7 #include "nxd_mdns.h"
8
9 #define DEMO_STACK_SIZE 2048
10 #define BUFFER_SIZE 10240
11 #define LOCAL_FULL_SERVICE_COUNT 16
12 #define PEER_FULL_SERVICE_COUNT 16
13 #define PEER_PARTIAL_SERVICE_COUNT 32
14
15 /* Define the ThreadX and NetX object control blocks... */
16
17 TX_THREAD thread_0;
18
19 static NX_PACKET_POOL pool_0;
20 static NX_IP ip_0;
21
22 /* Define the NetX MDNS object control blocks. */
23
24 static NX_MDNS mdns_0;
25 static UCHAR buffer[BUFFER_SIZE];
26 static ULONG current_buffer_size;
27
28 /* Define the counters used in the test application... */
29
30 static ULONG error_counter;
31 static CHAR *pointer;
32 static CHAR host_registered = NX_FALSE;
33 static CHAR service_registered = NX_FALSE;
34 static CHAR packet_count = 0;
35
36 /* Define thread prototypes. */
37
38 static void thread_0_entry(ULONG thread_input);
39 extern VOID _nx_ram_network_driver_1500(NX_IP_DRIVER *driver_req_ptr);
40 extern UINT (*advanced_packet_process_callback)(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr);
41 static UINT my_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr);
42 static VOID probing_notify(NX_MDNS *mdns_ptr, UCHAR *name, UINT state);
43
44
45 /* Define service. */
46
47 #define SERVICE_INSTANCE_NAME "NETXDUO_MDNS_Test1"
48 #define SERVICE_TYPE_HTTP "_http._tcp"
49 #define SERVICE_SUB_TYPE_NULL NX_NULL
50 #define SERVICE_TXT_NULL NX_NULL
51 #define SERVICE_TTL 120
52 #define SERVICE_PRIORITY 0
53 #define SERVICE_WEIGHTS 0
54 #define SERVICE_PORT 80
55
56 #define SERVICE_TYPE_IPP "_ipp._tcp"
57
58 /* Define what the initial system looks like. */
59
60 #ifdef CTEST
test_application_define(void * first_unused_memory)61 VOID test_application_define(void *first_unused_memory)
62 #else
63 void netx_mdns_second_interface_test(void *first_unused_memory)
64 #endif
65 {
66
67 UINT status;
68
69 /* Setup the working pointer. */
70 pointer = (CHAR *) first_unused_memory;
71 error_counter = 0;
72
73 /* Initialize the NetX system. */
74 nx_system_initialize();
75
76 /* Create a packet pool. */
77 status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 512, pointer, 8192);
78 pointer = pointer + 8192;
79
80 if(status)
81 error_counter++;
82
83 /* Create an IP instance. */
84 status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1, 2, 3, 4), 0xFFFFFF00UL, &pool_0,
85 _nx_ram_network_driver_1500, pointer, 2048, 1);
86 pointer = pointer + 2048;
87 status += nx_ip_interface_attach(&ip_0, "Second Interface", IP_ADDRESS(2, 2, 3, 4), 0xFFFFFF00UL, _nx_ram_network_driver_1500);
88
89 /* Check for IP create errors. */
90 if (status)
91 error_counter++;
92
93 /* Enable ARP and supply ARP cache memory for IP Instance 0. */
94 status = nx_arp_enable(&ip_0, (void *) pointer, 1024);
95 pointer = pointer + 1024;
96
97 if(status)
98 error_counter++;
99
100 /* Enable UDP processing for both IP instances. */
101 status = nx_udp_enable(&ip_0);
102
103 /* Check UDP enable status. */
104 if(status)
105 error_counter++;
106
107 /* Enable IGMP processing for both IP instances. */
108 status = nx_igmp_enable(&ip_0);
109
110 /* Check status. */
111 if(status)
112 error_counter++;
113
114 /* Create the main thread. */
115 tx_thread_create(&thread_0, "mDNS Client", thread_0_entry, 0,
116 pointer, DEMO_STACK_SIZE,
117 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
118 pointer = pointer + DEMO_STACK_SIZE;
119 }
120
121 /* Define the test threads. */
122
thread_0_entry(ULONG thread_input)123 void thread_0_entry(ULONG thread_input)
124 {
125 UINT status;
126 ULONG actual_status;
127
128
129 NX_PARAMETER_NOT_USED(thread_input);
130
131 printf("NetX Test: MDNS Second Interface Test................................");
132
133 /* Check early error. */
134 if (error_counter)
135 {
136 printf("ERROR!\n");
137 test_control_return(1);
138 }
139
140 advanced_packet_process_callback = my_packet_process;
141
142 /* Ensure the IP instance has been initialized. */
143 status = nx_ip_interface_status_check(&ip_0, 1, NX_IP_INITIALIZE_DONE, &actual_status, 100);
144
145 /* Check status. */
146 if(status != NX_SUCCESS)
147 {
148 printf("ERROR!\n");
149 test_control_return(1);
150 }
151
152 /* Create mDNS. */
153 current_buffer_size = (BUFFER_SIZE >> 1);
154 status = nx_mdns_create(&mdns_0, &ip_0, &pool_0, 2, pointer, DEMO_STACK_SIZE, (UCHAR *)"NETX-MDNS-CLIENT",
155 buffer, current_buffer_size, buffer + current_buffer_size, current_buffer_size, probing_notify);
156 pointer = pointer + DEMO_STACK_SIZE;
157
158 /* Check status. */
159 if(status != NX_SUCCESS)
160 {
161 printf("ERROR!\n");
162 test_control_return(1);
163 }
164
165 /* Enable mDNS. */
166 status = nx_mdns_enable(&mdns_0, 1);
167
168 /* Check status. */
169 if(status != NX_SUCCESS)
170 {
171 printf("ERROR!\n");
172 test_control_return(1);
173 }
174
175 /* Register service. */
176 status = nx_mdns_service_add(&mdns_0, (UCHAR *)SERVICE_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUB_TYPE_NULL,
177 SERVICE_TXT_NULL, SERVICE_TTL, (USHORT)SERVICE_PRIORITY, (USHORT)SERVICE_WEIGHTS,
178 (USHORT)SERVICE_PORT, NX_TRUE, 1);
179
180 /* Check status. */
181 if(status != NX_SUCCESS)
182 {
183 printf("ERROR!\n");
184 test_control_return(1);
185 }
186
187 /* Wait for host register and service register. */
188 tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);
189
190 /* Check status. */
191 if ((packet_count == 0) || (host_registered != NX_TRUE) || (service_registered != NX_TRUE))
192 {
193 printf("ERROR!\n");
194 test_control_return(1);
195 }
196
197 /* Reset packet count. */
198 packet_count = 0;
199
200 /* Perform mDNS continuous query. */
201 status = nx_mdns_service_continuous_query(&mdns_0, NX_NULL, (UCHAR *)SERVICE_TYPE_IPP, NX_NULL);
202
203 /* Check status. */
204 if(status != NX_SUCCESS)
205 {
206 printf("ERROR!\n");
207 test_control_return(1);
208 }
209
210 tx_thread_sleep(2 * NX_IP_PERIODIC_RATE);
211
212 /* Determine if the test was successful. */
213 if((error_counter) || (packet_count == 0))
214 {
215 printf("ERROR!\n");
216 test_control_return(1);
217 }
218 else
219 {
220 printf("SUCCESS!\n");
221 test_control_return(0);
222 }
223 }
224
my_packet_process(NX_IP * ip_ptr,NX_PACKET * packet_ptr,UINT * operation_ptr,UINT * delay_ptr)225 static UINT my_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UINT *operation_ptr, UINT *delay_ptr)
226 {
227
228
229 NX_PARAMETER_NOT_USED(delay_ptr);
230
231 /* Check the packet interface. */
232 if (packet_ptr -> nx_packet_address.nx_packet_interface_ptr != &ip_ptr -> nx_ip_interface[1])
233 error_counter++;
234
235 packet_count++;
236
237 *operation_ptr = NX_NULL;
238 return NX_TRUE;
239 }
240
probing_notify(struct NX_MDNS_STRUCT * mdns_ptr,UCHAR * name,UINT state)241 static VOID probing_notify(struct NX_MDNS_STRUCT *mdns_ptr, UCHAR *name, UINT state)
242 {
243
244 NX_PARAMETER_NOT_USED(mdns_ptr);
245 NX_PARAMETER_NOT_USED(name);
246
247 switch(state)
248 {
249 case NX_MDNS_LOCAL_SERVICE_REGISTERED_SUCCESS:
250 {
251 service_registered = NX_TRUE;
252 break;
253 }
254 case NX_MDNS_LOCAL_SERVICE_REGISTERED_FAILURE:
255 {
256 service_registered = NX_FALSE;
257 break;
258 }
259 case NX_MDNS_LOCAL_HOST_REGISTERED_SUCCESS:
260 {
261 host_registered = NX_TRUE;
262 break;
263 }
264 case NX_MDNS_LOCAL_HOST_REGISTERED_FAILURE:
265 {
266
267 host_registered = NX_FALSE;
268 break;
269 }
270 }
271 }
272 #else
273 #ifdef CTEST
test_application_define(void * first_unused_memory)274 VOID test_application_define(void *first_unused_memory)
275 #else
276 void netx_mdns_second_interface_test(void *first_unused_memory)
277 #endif
278 {
279 printf("NetX Test: MDNS Second Interface Test................................N/A\n");
280 test_control_return(3);
281 }
282 #endif
283