1 /* This is a small demo of NetX Duo mDNS/DNS-SD on the high-performance NetX Duo TCP/IP stack.  */
2 
3 
4 #include "tx_api.h"
5 #include "nx_api.h"
6 #include "nxd_mdns.h"
7 
8 
9 #define     DEMO_STACK_SIZE         4096
10 #define     NX_PACKET_SIZE          1536
11 #define     NX_PACKET_POOL_SIZE     ((1536 + sizeof(NX_PACKET)) * 64)
12 
13 
14 /* Define the ThreadX, NetX control blocks...  */
15 
16 static TX_THREAD                    thread_0;
17 static NX_PACKET_POOL               pool_0;
18 static NX_IP                        ip_0;
19 static NX_MDNS                      mdns;
20 static UCHAR                        pool_memory[NX_PACKET_POOL_SIZE];
21 
22 
23 /* Define the counters used in the demo application...  */
24 
25 static UINT                         status;
26 static UCHAR                       *pointer;
27 static ULONG                        error_counter = 0;
28 
29 
30 /* Define the services for mDNS.  */
31 
32 #define MDNS_PRIORITY                   3
33 #define MDNS_LOCAL_SERVICE_CACHE_SIZE   4096
34 #define MDNS_PEER_SERVICE_CACHE_SIZE    4096
35 
36 static CHAR*        mdns_host_name = "mDNS-HOST";
37 
38 #define PRIMARY_INTERFACE 0
39 #define SERVICE1_INSTANCE_NAME  "NETXDUO_MDNS_Test1"
40 #define SERVICE_TYPE_HTTP "_http._tcp"
41 #define SERVICE_INSTANCE_NULL  NX_NULL
42 #define SERVICE_TYPE_NULL      NX_NULL
43 #define SERVICE_SUBTYPE_NULL   NX_NULL
44 #define SERVICE_TXT_NULL       NX_NULL
45 #define SERVICE_SUBTYPE_PRINTER "_printer"
46 #ifndef NX_MDNS_DISABLE_SERVER
47 static      UINT     service1_ttl = 120;
48 static      UINT     service1_priority = 0;
49 static      UINT     service1_weights = 0;
50 static      UINT     service1_port = 80;
51 
52 #define SERVICE2_INSTANCE_NAME  "NETXDUO_MDNS_Test2"
53 
54 static      UINT     service2_ttl = 120;
55 static      UINT     service2_priority = 0;
56 static      UINT     service2_weights = 0;
57 static      UINT     service2_port = 1026;
58 
59 #define SERVICE3_INSTANCE_NAME "NETXDUO_MDNS_Test3"
60 #define SERVICE_TYPE_IPP  "_ipp._tcp"
61 #define SERVICE3_TXT_INFO  "paper=A4;version=01"
62 static      UINT     service3_ttl = 120;
63 static      UINT     service3_priority = 0;
64 static      UINT     service3_weights = 0;
65 static      UINT     service3_port = 1028;
66 
67 #define SERVICE4_INSTANCE_NAME "NETXDUO_MDNS_Test4"
68 #define SERVICE4_TXT_INFO "paper=A3;version=02"
69 static      UINT     service4_ttl = 120;
70 static      UINT     service4_priority = 0;
71 static      UINT     service4_weights = 0;
72 static      UINT     service4_port = 1030;
73 #endif /* NX_MDNS_DISABLE_SERVER */
74 #define SERVICE_INSTANCE_NAME_NULL NX_NULL
75 
76 #ifndef NX_MDNS_DISABLE_CLIENT
77 static      NX_MDNS_SERVICE  service_instance;
78 static      ULONG            query_timeout = 500;
79 #endif /* NX_MDNS_DISABLE_CLIENT */
80 
81 #define WIN_MDNS_INSTANCE_1 "WIN_MDNS_Test1"
82 #define WIN_MDNS_INSTANCE_2 "WIN_MDNS_Test2"
83 
84 #define SERVICE_TYPE_SMB "_smb._tcp"
85 
86 static ULONG mdns_thread_stack[DEMO_STACK_SIZE / sizeof(ULONG)];
87 static ULONG local_service_cache[MDNS_LOCAL_SERVICE_CACHE_SIZE / sizeof(ULONG)];
88 static ULONG peer_service_cache[MDNS_PEER_SERVICE_CACHE_SIZE / sizeof(ULONG)];
89 
90 /* Define thread prototypes.  */
91 
92 static VOID thread_0_entry(ULONG thread_input);
93 
94 /******** Optionally substitute your Ethernet driver here. ***********/
95 
96 extern VOID _nx_ram_network_driver(NX_IP_DRIVER *);
97 
98 
99 /* Define main entry point.  */
100 
main()101 int main()
102 {
103 
104     /* Enter the ThreadX kernel.  */
105     tx_kernel_enter();
106 }
107 
108 
109 /* Define what the initial system looks like.  */
110 
tx_application_define(void * first_unused_memory)111 void    tx_application_define(void *first_unused_memory)
112 {
113 
114     /* Initialize the NetX system.  */
115     nx_system_initialize();
116 
117     /* Setup the working pointer.  */
118     pointer = (UCHAR *) first_unused_memory;
119 
120     /* Create a packet pool for the mDNS.  */
121     status =  nx_packet_pool_create(&pool_0, "NetX Client Packet Pool", NX_PACKET_SIZE, pool_memory, NX_PACKET_POOL_SIZE);
122 
123     /* Check status.  */
124     if (status != NX_SUCCESS)
125     {
126         error_counter++;
127         return;
128     }
129 
130     /* Create an IP instance for the mDNS.  */
131     status = nx_ip_create(&ip_0, "NetX Client IP Instance", IP_ADDRESS(192, 168, 100, 34), 0xFFFFFF00UL,
132                           &pool_0, _nx_ram_network_driver, pointer, 2048, 1);
133     pointer =  pointer + 2048;
134 
135     /* Check status.  */
136     if (status != NX_SUCCESS)
137     {
138         error_counter++;
139         return;
140     }
141 
142 #ifndef NX_DISABLE_IPV4
143     /* Enable ARP and supply ARP cache memory for the FTP Client IP.  */
144     nx_arp_enable(&ip_0, (void *) pointer, 1024);
145     pointer = pointer + 1024;
146 
147     /* Check status.  */
148     if (status != NX_SUCCESS)
149     {
150         error_counter++;
151         return;
152     }
153 
154     /* Enable ICMP for client IP instance.  */
155     status = nx_icmp_enable(&ip_0);
156 
157     /* Enable ICMP for client IP instance.  */
158     status += nx_igmp_enable(&ip_0);
159 
160     /* Check status.  */
161     if (status != NX_SUCCESS)
162     {
163         error_counter++;
164         return;
165     }
166 #endif /* NX_DISABLE_IPV4  */
167 
168     /* Enable fragment */
169     status = nx_ip_fragment_enable(&ip_0);
170 
171     /* Check for fragment enable errors.  */
172     if(status)
173         error_counter++;
174 
175     /* Enable UDP traffic.  */
176     status =  nx_udp_enable(&ip_0);
177 
178     /* Check for UDP enable errors.  */
179     if (status)
180         error_counter++;
181 
182     /* Create the main thread.  */
183     tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
184                      pointer, DEMO_STACK_SIZE,
185                      4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
186     pointer =  pointer + DEMO_STACK_SIZE;
187 }
188 
189 
190 #ifndef NX_MDNS_DISABLE_SERVER
register_local_service(UCHAR * instance,UCHAR * type,UCHAR * subtype,UCHAR * txt,UINT ttl,UINT priority,UINT weight,UINT port,UINT is_unique)191 static void register_local_service(UCHAR *instance, UCHAR *type, UCHAR *subtype, UCHAR *txt, UINT ttl,
192                                    UINT priority, UINT weight, UINT port, UINT is_unique)
193 {
194 
195 
196     status = nx_mdns_service_add(&mdns, instance, type, subtype, txt, ttl, (USHORT)priority, (USHORT)weight, (USHORT)port,
197                                  (UCHAR)is_unique, PRIMARY_INTERFACE);
198 
199     printf("Local Service Added: %s %s ", instance, type);
200     if(subtype)
201         printf("%s ", subtype);
202     if(status)
203         printf("failed\n");
204     else
205         printf("successfully\n");
206 }
207 
delete_local_service(UCHAR * instance,UCHAR * type,UCHAR * subtype)208 static void delete_local_service(UCHAR *instance, UCHAR *type, UCHAR *subtype)
209 {
210 
211     printf("Delete local service: ");
212     if(instance)
213         printf("instance: %s ", instance);
214     if(type)
215         printf("type %s ", type);
216     if(subtype)
217         printf("subtype %s ", subtype);
218 
219     status = nx_mdns_service_delete(&mdns, instance, type, subtype);
220     if(status)
221         printf("failed\n");
222     else
223         printf("successfully\n");
224 
225 }
226 #endif /* NX_MDNS_DISABLE_SERVER  */
227 
228 #ifndef NX_MDNS_DISABLE_CLIENT
clear_service_cache(void)229 static void clear_service_cache(void)
230 {
231 
232     status = nx_mdns_peer_cache_clear(&mdns);
233 
234     printf("Clear service cache ");
235 
236     if(status)
237         printf("Failed\n\n\n");
238     else
239         printf("Successful\n\n\n");
240 
241 }
perform_oneshot_query(UCHAR * instance,UCHAR * type,UCHAR * subtype,UINT timeout)242 static void perform_oneshot_query(UCHAR *instance, UCHAR *type, UCHAR *subtype, UINT timeout)
243 {
244 
245     /* Print the query instance.  */
246     printf("Send One Shot query: ");
247     if(instance)
248         printf("instance: %s ", instance);
249     if(type)
250         printf("type %s ", type);
251     if(subtype)
252         printf("subtype %s ", subtype);
253     printf("timeout %d ticks\n", timeout);
254 
255     status = nx_mdns_service_one_shot_query(&mdns, instance, type, subtype, &service_instance, timeout);
256 
257     if (status == NX_MDNS_SUCCESS)
258     {
259          printf("Service Get: \n");
260          printf("Name: %s\n",service_instance.service_name);
261          printf("Type: %s\n",service_instance.service_type);
262          printf("Domain: %s\n",service_instance.service_domain);
263          printf("TXT Info: %s\n",service_instance.service_text);
264          printf("Priority: %d\n",service_instance.service_priority);
265          printf("Weight: %d\n",service_instance.service_weight);
266          printf("Port: %d\n",service_instance.service_port);
267          printf("Target Host: %s\n",service_instance.service_host);
268          printf("IPv4 Address: %lu.%lu.%lu.%lu\n",
269                  service_instance.service_ipv4 >> 24,
270                  service_instance.service_ipv4 >> 16 & 0xFF,
271                  service_instance.service_ipv4 >> 8 & 0xFF,
272                  service_instance.service_ipv4 & 0xFF);
273          printf("Interface: %d\n\n\n",service_instance.interface_index);
274     }
275     else
276     {
277         printf("No Service!!!\n\n\n");
278     }
279 }
280 
start_continous_query(UCHAR * instance,UCHAR * type,UCHAR * subtype)281 static void start_continous_query(UCHAR *instance, UCHAR *type, UCHAR *subtype)
282 {
283 
284     status = nx_mdns_service_continuous_query(&mdns, instance, type, subtype);
285 
286     printf("Start continous query: ");
287     if(instance)
288         printf("instance %s ", instance);
289     if(type)
290         printf("type %s ", type);
291     if(subtype)
292         printf("subtype %s ", subtype);
293 
294     /* CHECK FOR ERROR.  */
295     if (status)
296     {
297         printf("failed\n");
298         error_counter++;
299     }
300     else
301         printf("successfully\n");
302 }
303 
stop_continous_query(UCHAR * instance,UCHAR * type,UCHAR * subtype)304 static void stop_continous_query(UCHAR *instance, UCHAR *type, UCHAR *subtype)
305 {
306 
307     status = nx_mdns_service_query_stop(&mdns, instance, type, subtype);
308 
309     printf("Query stop: ");
310     if(instance)
311         printf("instance %s ", instance);
312     if(type)
313         printf("type %s ", type);
314     if(subtype)
315         printf("subtype %s ", subtype);
316 
317     if(status)
318         printf("failed\n");
319     else
320         printf("successful\n");
321 
322 }
323 UINT service_map = 0;
perform_service_lookup(UCHAR * instance,UCHAR * type,UCHAR * subtype,UINT show_all)324 static void perform_service_lookup(UCHAR *instance, UCHAR *type, UCHAR *subtype, UINT show_all)
325 {
326 
327 UINT service_index = 0;
328 UINT num_info_incomplete = 0;
329 ULONG   ipv4_address;
330 ULONG   ipv6_address[4];
331 
332 
333     printf("Perform Service Lookup for type:%s \n", type);
334 
335     /* Get the all services.  */
336     while (1)
337     {
338 
339         status = nx_mdns_service_lookup(&mdns, instance, type, subtype,  service_index, &service_instance);
340 
341         if (status == NX_MDNS_SUCCESS)
342         {
343 
344             if(service_instance.service_name &&
345                service_instance.service_type &&
346                service_instance.service_domain &&
347                service_instance.service_port &&
348                service_instance.service_host[0] &&
349                service_instance.service_ipv4)
350             {
351                 if(show_all || ((service_map & (UINT)(1 << service_index)) == 0))
352                 {
353                     /* The service index may not be the same with query index. */
354                     printf("Service Get: %d \n", service_index);
355                     printf("  Name: %s\n",service_instance.service_name);
356                     printf("  Type: %s\n",service_instance.service_type);
357                     printf("  Domain: %s\n",service_instance.service_domain);
358                     if(service_instance.service_text != NX_NULL)
359                         printf("  TXT Info: %s\n",service_instance.service_text);
360                     else
361                         printf("  TXT Info: None!\n");
362 
363                     printf("  Priority: %d\n",service_instance.service_priority);
364                     printf("  Weight: %d\n",service_instance.service_weight);
365                     printf("  Port: %d\n",service_instance.service_port);
366                     printf("  Target Host: %s\n",service_instance.service_host);
367                     printf("  IPv4 Address: %lu.%lu.%lu.%lu\n",
368                            service_instance.service_ipv4 >> 24,
369                            service_instance.service_ipv4 >> 16 & 0xFF,
370                            service_instance.service_ipv4 >> 8 & 0xFF,
371                            service_instance.service_ipv4 & 0xFF);
372                     printf("  Interface: %d\n\n\n",service_instance.interface_index);
373                     service_map = service_map | (UINT)(1 << service_index);
374                 }
375             }
376             else
377             {
378 
379                 /* Check if have all service info except address.  */
380                 if(service_instance.service_name &&
381                    service_instance.service_type &&
382                    service_instance.service_domain &&
383                    service_instance.service_port &&
384                    service_instance.service_host[0])
385                 {
386 
387                     /* Start to get the host address.  */
388                     status = nx_mdns_host_address_get(&mdns, service_instance.service_host, &ipv4_address, ipv6_address, query_timeout);
389 
390                     if(show_all || ((service_map & (UINT)(1 << service_index)) == 0))
391                     {
392                         /* The service index may not be the same with query index. */
393                         printf("Service Get: %d \n", service_index);
394                         printf("  Name: %s\n",service_instance.service_name);
395                         printf("  Type: %s\n",service_instance.service_type);
396                         printf("  Domain: %s\n",service_instance.service_domain);
397                         if(service_instance.service_text != NX_NULL)
398                             printf("  TXT Info: %s\n",service_instance.service_text);
399                         else
400                             printf("  TXT Info: None!\n");
401 
402                         printf("  Priority: %d\n",service_instance.service_priority);
403                         printf("  Weight: %d\n",service_instance.service_weight);
404                         printf("  Port: %d\n",service_instance.service_port);
405                         printf("  Target Host: %s\n",service_instance.service_host);
406                         printf("  IPv4 Address: %lu.%lu.%lu.%lu\n",
407                                service_instance.service_ipv4 >> 24,
408                                service_instance.service_ipv4 >> 16 & 0xFF,
409                                service_instance.service_ipv4 >> 8 & 0xFF,
410                                service_instance.service_ipv4 & 0xFF);
411                         printf("  Interface: %d\n\n\n",service_instance.interface_index);
412                         service_map = service_map | (UINT)(1 << service_index);
413                     }
414                 }
415                 else
416                 {
417                     nx_mdns_service_continuous_query(&mdns, service_instance.service_name, service_instance.service_type, NX_NULL);
418                     printf("Start continuous query:%d \n", service_index);
419                     if (service_instance.service_name)
420                     {
421                         printf("Service Name: %s\n",  service_instance.service_name);
422                     }
423                     printf("Service Type: %s\n",  service_instance.service_type);
424                     num_info_incomplete ++;
425                 }
426             }
427             service_index ++;
428         }
429         else
430             return;
431 
432     }
433 }
434 
service_change_notify(NX_MDNS * mdns_ptr,NX_MDNS_SERVICE * service_ptr,UINT state)435 static VOID  service_change_notify(NX_MDNS *mdns_ptr, NX_MDNS_SERVICE *service_ptr, UINT state)
436 {
437 
438     NX_PARAMETER_NOT_USED(mdns_ptr);
439 
440     switch(state)
441     {
442         case NX_MDNS_PEER_SERVICE_RECEIVED:
443         {
444               printf("Received the new Service!!! \n");
445               printf("Name: %s\n",service_ptr -> service_name);
446               printf("Type: %s\n",service_ptr -> service_type);
447               printf("Domain: %s\n",service_ptr -> service_domain);
448               printf("TXT Info: %s\n",service_ptr -> service_text);
449               printf("Priority: %d\n",service_ptr -> service_priority);
450               printf("Weight: %d\n",service_ptr -> service_weight);
451               printf("Port: %d\n",service_ptr -> service_port);
452               printf("Target Host: %s\n",service_ptr -> service_host);
453               printf("IPv4 Address: %lu.%lu.%lu.%lu\n",
454                   service_ptr -> service_ipv4 >> 24,
455                   service_ptr -> service_ipv4 >> 16 & 0xFF,
456                   service_ptr -> service_ipv4 >> 8 & 0xFF,
457                   service_ptr -> service_ipv4 & 0xFF);
458               printf("Interface: %d\n\n\n",service_ptr -> interface_index);
459               break;
460         }
461         case NX_MDNS_PEER_SERVICE_UPDATED:
462         {
463 
464               printf("Update the Service address!!! \n");
465               printf("Name: %s\n",service_ptr -> service_name);
466               printf("Type: %s\n",service_ptr -> service_type);
467               printf("Domain: %s\n",service_ptr -> service_domain);
468               printf("TXT Info: %s\n",service_ptr -> service_text);
469               printf("Priority: %d\n",service_ptr -> service_priority);
470               printf("Weight: %d\n",service_ptr -> service_weight);
471               printf("Port: %d\n",service_ptr -> service_port);
472               printf("Target Host: %s\n",service_ptr -> service_host);
473               printf("IPv4 Address: %lu.%lu.%lu.%lu\n",
474                   service_ptr -> service_ipv4 >> 24,
475                   service_ptr -> service_ipv4 >> 16 & 0xFF,
476                   service_ptr -> service_ipv4 >> 8 & 0xFF,
477                   service_ptr -> service_ipv4 & 0xFF);
478               printf("Interface: %d\n\n\n",service_ptr -> interface_index);
479               break;
480         }
481         case NX_MDNS_PEER_SERVICE_DELETED:
482         {
483 
484               printf("Delete the old Service!!! \n");
485               printf("Name: %s\n",service_ptr -> service_name);
486               printf("Type: %s\n",service_ptr -> service_type);
487               printf("Domain: %s\n",service_ptr -> service_domain);
488               printf("TXT Info: %s\n",service_ptr -> service_text);
489               printf("Priority: %d\n",service_ptr -> service_priority);
490               printf("Weight: %d\n",service_ptr -> service_weight);
491               printf("Port: %d\n",service_ptr -> service_port);
492               printf("Target Host: %s\n",service_ptr -> service_host);
493               printf("IPv4 Address: %lu.%lu.%lu.%lu\n",
494                   service_ptr -> service_ipv4 >> 24,
495                   service_ptr -> service_ipv4 >> 16 & 0xFF,
496                   service_ptr -> service_ipv4 >> 8 & 0xFF,
497                   service_ptr -> service_ipv4 & 0xFF);
498               printf("Interface: %d\n\n\n",service_ptr -> interface_index);
499               break;
500         }
501     }
502 }
503 #endif /* NX_MDNS_DISABLE_CLIENT  */
504 
probing_notify(struct NX_MDNS_STRUCT * mdns_ptr,UCHAR * name,UINT state)505 static VOID  probing_notify(struct NX_MDNS_STRUCT *mdns_ptr, UCHAR *name, UINT state)
506 {
507 
508     NX_PARAMETER_NOT_USED(mdns_ptr);
509 
510     switch(state)
511     {
512         case NX_MDNS_LOCAL_SERVICE_REGISTERED_SUCCESS:
513           {
514 
515               printf("Service Name: %s\n",name);
516               printf("Registered success!!! \n\n");
517               break;
518           }
519         case NX_MDNS_LOCAL_SERVICE_REGISTERED_FAILURE:
520           {
521 
522               printf("Service Name: %s\n",name);
523               printf("Registered failure! \n\n");
524               break;
525           }
526         case NX_MDNS_LOCAL_HOST_REGISTERED_SUCCESS:
527           {
528 
529               printf("Host Name: %s\n",name);
530               printf("Registered success!!! \n\n");
531               break;
532           }
533         case NX_MDNS_LOCAL_HOST_REGISTERED_FAILURE:
534           {
535 
536               printf("Host Name: %s\n",name);
537               printf("Registered failure! \n\n");
538               break;
539           }
540     }
541 }
542 
cache_full_notify(NX_MDNS * mdns_ptr,UINT state,UINT cache_type)543 static VOID  cache_full_notify(NX_MDNS *mdns_ptr, UINT state, UINT cache_type)
544 {
545 
546     NX_PARAMETER_NOT_USED(mdns_ptr);
547 
548     /* Check cache type.  */
549     if (cache_type == NX_MDNS_CACHE_TYPE_LOCAL)
550     {
551         printf("Local Cache: ");
552     }
553     else
554     {
555         printf("Peer Cache: ");
556     }
557 
558     /* Check cache state.  */
559     if (state == NX_MDNS_CACHE_STATE_FULL)
560     {
561         printf("Cache Full!!!\n");
562     }
563     else
564     {
565         printf("Cache Full With Fragment!!!\n");
566     }
567 }
568 
569 /* Define a test thread.  */
thread_0_entry(ULONG thread_input)570 static void    thread_0_entry(ULONG thread_input)
571 {
572 
573 UINT     test_case = 0;
574 UINT     time_count = 0;
575 UINT     i = 200;
576 #ifndef NX_MDNS_DISABLE_CLIENT
577 UINT     j = 0;
578 #endif /* NX_MDNS_DISABLE_CLIENT  */
579 #ifndef NX_MDNS_DISABLE_CLIENT
580 ULONG    service_mask = 0x00000000;     /* Set the service mask to select service types it wishes to monitor.
581                                            A list of services being monitored ar hard-coded
582                                            in the table nx_mdns_service_types in nxd_mdns.c.  */
583 #endif /* NX_MDNS_DISABLE_CLIENT  */
584 
585 
586     NX_PARAMETER_NOT_USED(thread_input);
587 
588     /* Create a mDNS instance for mDNS.  */
589     status =  nx_mdns_create(&mdns, &ip_0, &pool_0, MDNS_PRIORITY, mdns_thread_stack,
590                              sizeof(mdns_thread_stack), (UCHAR *)mdns_host_name,
591                              (VOID *)local_service_cache, sizeof(local_service_cache),
592                              (VOID *)peer_service_cache, sizeof(peer_service_cache), probing_notify);
593 
594     /* Check for error.  */
595     if (status)
596     {
597 
598         error_counter++;
599         return;
600     }
601 
602     /* Set the cache notify callback function.  */
603     status = nx_mdns_cache_notify_set(&mdns, cache_full_notify);
604     if (status)
605     {
606         error_counter++;
607         return;
608     }
609 
610 #ifndef NX_MDNS_DISABLE_CLIENT
611     /* Set the service change callback function to listen the service.  */
612     status = nx_mdns_service_notify_set(&mdns, service_mask, service_change_notify);
613     if (status)
614     {
615         error_counter++;
616         return;
617     }
618 #endif /* NX_MDNS_DISABLE_CLIENT  */
619 
620     /* Enable the mDNS function.  */
621     nx_mdns_enable(&mdns, PRIMARY_INTERFACE);
622 
623     /* Waiting for host name register. */
624     tx_thread_sleep(500);
625 
626     while(1)
627     {
628 
629         tx_thread_sleep(100);
630 
631         test_case = 0;
632         switch(test_case)
633         {
634 
635         case 0:
636 
637             time_count++;
638 
639 #ifndef NX_MDNS_DISABLE_SERVER
640             if ((time_count % i) == 1)
641             {
642 
643                 /* Register local service.  */
644                 register_local_service((UCHAR *)SERVICE1_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL,
645                                        SERVICE_TXT_NULL, service1_ttl, service1_priority, service1_weights,
646                                        service1_port, NX_TRUE);
647 
648 
649                 register_local_service((UCHAR *)SERVICE2_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER,
650                                        SERVICE_TXT_NULL, service2_ttl, service2_priority, service2_weights,
651                                        service2_port, NX_TRUE);
652 
653                 register_local_service((UCHAR *)SERVICE3_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL,
654                                        (UCHAR *)SERVICE3_TXT_INFO, service3_ttl, service3_priority, service3_weights,
655                                        service3_port, NX_TRUE);
656 
657                 register_local_service((UCHAR *)SERVICE4_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL,
658                                        (UCHAR *)SERVICE4_TXT_INFO, service4_ttl, service4_priority, service4_weights,
659                                        service4_port,  NX_TRUE);
660             }
661 
662             if((time_count % i) == 60)
663                 delete_local_service((UCHAR *)SERVICE1_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL);
664             else if((time_count % i) == 70)
665                 delete_local_service((UCHAR *)SERVICE2_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER);
666             else if((time_count % i) == 80)
667                 delete_local_service((UCHAR *)SERVICE3_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL);
668             else if((time_count % i) == 90)
669                 delete_local_service((UCHAR *)SERVICE4_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL);
670 #else
671             i = 100;
672 #ifndef NX_MDNS_DISABLE_CLIENT
673             j = 100;
674 #endif /* NX_MDNS_DISABLE_CLIENT  */
675 #endif /*NX_MDNS_DISABLE_SERVER*/
676 
677 #ifndef NX_MDNS_DISABLE_CLIENT
678             if ((time_count % i) == (101 - j))
679             {
680                 clear_service_cache();
681                 perform_oneshot_query((UCHAR *)SERVICE_INSTANCE_NULL, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL, query_timeout);
682             }
683             else if ((time_count % i) == (110 - j))
684             {
685                 perform_oneshot_query((UCHAR *)SERVICE_INSTANCE_NULL, (UCHAR *)SERVICE_TYPE_SMB, SERVICE_SUBTYPE_NULL, query_timeout);
686             }
687             else if ((time_count % i) == (120 - j))
688             {
689                 start_continous_query((UCHAR *)SERVICE_INSTANCE_NULL, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL);
690             }
691             else if ((time_count % i) == (130 - j))
692             {
693                 stop_continous_query((UCHAR *)SERVICE_INSTANCE_NULL, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL);
694                 perform_service_lookup(NX_NULL, (UCHAR *)SERVICE_TYPE_HTTP, NX_NULL, 1);
695             }
696             else if ((time_count % i) == (140 - j))
697             {
698                 perform_service_lookup(NX_NULL, (UCHAR *)SERVICE_TYPE_SMB, NX_NULL, 1);
699             }
700 #else
701             i = 100;
702 #endif /* NX_MDNS_DISABLE_CLIENT  */
703             break;
704 
705 #ifndef NX_MDNS_DISABLE_SERVER
706         case 1: /* Register local service: NETXDUO_MDNS_Test1._http._tcp */
707 
708             register_local_service((UCHAR *)SERVICE1_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL,
709                                    SERVICE_TXT_NULL, service1_ttl, service1_priority, service1_weights,
710                                    service1_port, NX_TRUE);
711             break;
712 
713         case 2: /* Register local service: NETXDUO_MDNS_Test2._printer._sub._http._tcp */
714             register_local_service((UCHAR *)SERVICE2_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER,
715                                    SERVICE_TXT_NULL, service2_ttl, service2_priority, service2_weights,
716                                    service2_port, NX_TRUE);
717             break;
718 
719         case 3: /* Register local service: NETXDUO_MDNS_Test3._http._tcp */
720             register_local_service((UCHAR *)SERVICE3_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL,
721                                    (UCHAR *)SERVICE3_TXT_INFO, service3_ttl, service3_priority, service3_weights,
722                                    service3_port, NX_TRUE);
723             break;
724 
725         case 4: /* Register local service: NETXDUO_MDNS_Test4._ipp._tcp */
726             register_local_service((UCHAR *)SERVICE4_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL,
727                                    (UCHAR *)SERVICE4_TXT_INFO, service4_ttl, service4_priority, service4_weights,
728                                    service4_port,  NX_TRUE);
729             break;
730 #endif /* NX_MDNS_DISABLE_SERVER  */
731 
732 #ifndef NX_MDNS_DISABLE_CLIENT
733         case 5: /* One shot query for HTTP type. */
734             perform_oneshot_query((UCHAR *)SERVICE_INSTANCE_NULL, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL, query_timeout);
735 
736             break;
737 
738         case 6: /* One shot query for _printer._sub._http._tcp */
739             perform_oneshot_query((UCHAR *)SERVICE_INSTANCE_NULL, (UCHAR *)SERVICE_TYPE_HTTP,
740                                   (UCHAR *)SERVICE_SUBTYPE_PRINTER, query_timeout);
741             break;
742 
743         case 7: /* Clear service cache */
744             clear_service_cache();
745             break;
746 
747         case 8: /* Continous query for all services. */
748             {
749             start_continous_query(NX_NULL, NX_NULL, NX_NULL);
750 
751             /* Waiting for Service response.  */
752             tx_thread_sleep(500);
753 
754             /* Perform the lookup.  */
755             perform_service_lookup(NX_NULL, NX_NULL, NX_NULL, 1);
756             break;
757             }
758         case 81: /* Stop continous query.  */
759             stop_continous_query(NX_NULL, NX_NULL, NX_NULL);
760             break;
761         case 9: /* Continous query for _http._tcp.local. */
762             {
763             start_continous_query(NX_NULL, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL);
764 
765             /* Waiting for Service response.  */
766             tx_thread_sleep(500);
767 
768             /* Perform the lookup.  */
769             perform_service_lookup(NX_NULL, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL, 1);
770 
771             break;
772             }
773         case 91:
774 
775             /* Stop continous query.  */
776             stop_continous_query(NX_NULL, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL);
777             break;
778         case 10: /* Continous query for _smb._tcp */
779             {
780             start_continous_query(NX_NULL, (UCHAR *)SERVICE_TYPE_SMB, SERVICE_SUBTYPE_NULL);
781 
782             /* Waiting for Service response.  */
783             tx_thread_sleep(500);
784 
785             /* Perform the lookup.  */
786             perform_service_lookup(NX_NULL, (UCHAR *)SERVICE_TYPE_SMB, SERVICE_SUBTYPE_NULL, 1);
787 
788             break;
789             }
790         case 101: /* Stop continous query.  */
791             stop_continous_query(NX_NULL, (UCHAR *)SERVICE_TYPE_SMB, SERVICE_SUBTYPE_NULL);
792             break;
793 
794         case 11: /* Continous_query for _printer._sub._http._tcp */
795             {
796             start_continous_query(NX_NULL, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER);
797 
798             /* Waiting for Service response.  */
799             tx_thread_sleep(500);
800 
801             /* Perform the lookup.  */
802             perform_service_lookup(NX_NULL, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER, 1);
803 
804             break;
805             }
806         case 111: /* Stop continous query.  */
807             stop_continous_query(NX_NULL, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER);
808             break;
809         case 12: /* Continous_query for WIN_MDNS_Test_2._printer._sub._http._tcp */
810             {
811             start_continous_query((UCHAR *)WIN_MDNS_INSTANCE_2, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER);
812 
813             /* Waiting for Service response.  */
814             tx_thread_sleep(500);
815 
816             /* Perform the lookup.  */
817             perform_service_lookup((UCHAR *)WIN_MDNS_INSTANCE_2, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER, 1);
818 
819             break;
820             }
821         case 121: /* Stop continous query.  */
822             stop_continous_query((UCHAR *)WIN_MDNS_INSTANCE_2, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER);
823             break;
824 #endif /* NX_MDNS_DISABLE_CLIENT  */
825 
826             /* When the service name is changed due to conflict, we need delete the new service. */
827 
828 #ifndef NX_MDNS_DISABLE_SERVER
829         case 13: /* Delete local service: NETXDUO_MDNS_Test1._http._tcp */
830             delete_local_service((UCHAR *)SERVICE1_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, SERVICE_SUBTYPE_NULL);
831             break;
832 
833         case 14: /* Delete local service NETXDUO_MDNS_Test2._printer._sub._http._tcp */
834             delete_local_service((UCHAR *)SERVICE2_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_HTTP, (UCHAR *)SERVICE_SUBTYPE_PRINTER);
835             break;
836 
837         case 15: /* Delete local service: NETXDUO_MDNS_Test3._http._tcp */
838             delete_local_service((UCHAR *)SERVICE3_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL);
839             break;
840 
841         case 16: /* Delete local service: NETXDUO_MDNS_Test4._ipp._tcp */
842             delete_local_service((UCHAR *)SERVICE4_INSTANCE_NAME, (UCHAR *)SERVICE_TYPE_IPP, SERVICE_SUBTYPE_NULL);
843             break;
844 #endif /* NX_MDNS_DISABLE_SERVER  */
845 
846         default:
847             tx_thread_sleep(100);
848             break;
849         }
850     }
851 }
852 
853