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