1 #include "tx_api.h"
2 #include "nx_api.h"
3
4 #if defined __PRODUCT_NETXDUO__ && !defined NX_DISABLE_IPV4
5 #include "netx_mdns_test.h"
6 #include "nx_tcp.h"
7 #include "nx_ip.h"
8
9 #ifdef FEATURE_NX_IPV6
10 #include "nx_ipv6.h"
11 #include "nx_icmpv6.h"
12 #endif /* FEATURE_NX_IPV6 */
13
14 #define DEMO_STACK_SIZE 2048
15 #define TEST_INTERFACE 0
16 #define MAX_PACKET_SIZE 1600
17
18 /* Define the ThreadX and NetX object control blocks... */
19
20 /* Define the counters used in the demo application... */
21
22 static ULONG error_counter;
23
24 /* Define thread prototypes. */
25 extern void test_control_return(UINT status);
26 extern UINT (*packet_process_callback)(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
27 static UINT packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
28 static UINT in_cleanup_process;
29 static TX_MUTEX pkt_capture_mutex;
30 static TX_SEMAPHORE pkt_count_sem;
31 static int pkt_capture_flag = 0;
32 static NX_PACKET *assemble_pkt;
33 static UCHAR assemble_pkt_data[MAX_PACKET_SIZE];
34 static UINT fragment_cnt = 0;
35 static UINT service_callback_invoked;
36 static UINT service_callback_state;
37 static UINT probing_callback_invoked;
38 static UINT probing_callback_state;
39 static UCHAR mdns_stack[DEMO_STACK_SIZE];
40
41
42 static NX_PACKET *incoming_pkts = NX_NULL;
43 static NX_PACKET *incoming_pkts_tail = NX_NULL;
44
service_change_notify(NX_MDNS * mdns_ptr,NX_MDNS_SERVICE * service_ptr,UINT state)45 static VOID service_change_notify(NX_MDNS *mdns_ptr, NX_MDNS_SERVICE *service_ptr, UINT state)
46 {
47
48 /* Check state. */
49 if(service_callback_state == state)
50 service_callback_invoked++;
51 }
52
perform_check(char * pkt_data,int pkt_size,int timeout)53 static void perform_check(char *pkt_data, int pkt_size, int timeout)
54 {
55 UINT status;
56 NX_PACKET *current_pkt;
57 ULONG start_time, current_time, time_remaining;
58
59 /* Compute the amount of time to wait for. */
60 start_time = current_time = tx_time_get();
61
62 /* timeout value is expressed in terms of seconds. Convert it to ticks. */
63 time_remaining = timeout - (current_time - start_time);
64
65
66 while(time_remaining > 0)
67 {
68 /* Wait for a packet. */
69 status = tx_semaphore_get(&pkt_count_sem, time_remaining);
70
71 if(status == NX_SUCCESS)
72 {
73 tx_mutex_get(&pkt_capture_mutex, TX_WAIT_FOREVER);
74 current_pkt = incoming_pkts;
75 if(incoming_pkts)
76 {
77 incoming_pkts = incoming_pkts -> nx_packet_queue_next;
78 }
79 else
80 {
81 incoming_pkts_tail = NX_NULL;
82 }
83 tx_mutex_put(&pkt_capture_mutex);
84
85 if(current_pkt)
86 {
87
88 /* A packet has been queued. Examine the content of the packet. */
89 if(((pkt_size - 14) != current_pkt -> nx_packet_length) ||
90 (memcmp(pkt_data + 14, current_pkt -> nx_packet_prepend_ptr, current_pkt -> nx_packet_length) != 0))
91 {
92 /* Not a match. */
93
94 /* Compute new timeout value. */
95 current_time = tx_time_get();
96 time_remaining = timeout - (current_time - start_time);
97 if(time_remaining > 0x80000000)
98 {
99 /* Underflow */
100 time_remaining = 0;
101 error_counter = 1;
102 }
103 nx_packet_release(current_pkt);
104 continue;
105 }
106 else
107 {
108 /* Packet is a match. Get out of this CHECK state. */
109 time_remaining = 0;
110 nx_packet_release(current_pkt);
111 continue;
112 }
113 }
114 }
115 else
116 {
117 /* Timeout */
118 error_counter = 1;
119 time_remaining = 0;
120 }
121 }
122 }
123
decode_mdns_data(ULONG * current_len,CHAR ** org_data)124 static void decode_mdns_data(ULONG *current_len, CHAR **org_data)
125 {
126 CHAR *character = *org_data;
127 CHAR compressed = NX_FALSE;
128 UINT labelSize;
129
130 /* As long as we haven't found a zero terminating label */
131 while(*character != '\0')
132 {
133
134 labelSize = *character++;
135
136 /* Is this a compression pointer or a count. */
137 if(labelSize <= NX_MDNS_LABEL_MAX)
138 {
139
140 *(assemble_pkt_data + *current_len) = *(character - 1);
141 *current_len = *current_len + 1;
142
143 /* Simple count, check for space and copy the label. */
144 while(labelSize > 0)
145 {
146
147 *(assemble_pkt_data + *current_len) = *character++;
148 *current_len = *current_len + 1;
149 labelSize--;
150 }
151 }
152 else if((labelSize & NX_MDNS_COMPRESS_MASK) == NX_MDNS_COMPRESS_VALUE)
153 {
154
155 /* This is a pointer, just adjust the source. */
156 if(compressed == NX_FALSE)
157 *org_data = character + 1;
158 compressed = NX_TRUE;
159 character = assemble_pkt_data + ((labelSize & NX_MDNS_LABEL_MAX) << 8) + *character;
160 }
161 else
162 {
163
164 /* Not defined, just fail */
165 return;
166 }
167 }
168
169 /* Null terminate name. */
170 *(assemble_pkt_data + *current_len) = '\0';
171 *current_len = *current_len + 1;
172
173 if(compressed == NX_FALSE)
174 *org_data = character + 1;
175 }
176
perform_check_mdns_data(char * pkt_data,int pkt_size,int timeout,int cmd)177 static void perform_check_mdns_data(char *pkt_data, int pkt_size, int timeout, int cmd)
178 {
179 UINT status;
180 NX_PACKET *current_pkt;
181 ULONG start_time, current_time, time_remaining;
182 ULONG offset, assemble_len;
183 USHORT question_cnt;
184 USHORT answer_cnt;
185 USHORT tmp;
186 USHORT type;
187 USHORT data_len;
188 UCHAR *data_len_ptr;
189 UCHAR expect_pkt;
190
191 /* Calculate offset. */
192 if((cmd == MDNS_CHECK_DATA_V4) || (cmd == MDNS_REJECT_DATA_V4))
193 offset = 28;
194 else
195 offset = 48;
196
197 /* Whether this packet is expected. */
198 if((cmd == MDNS_REJECT_DATA_V4) || (cmd == MDNS_REJECT_DATA_V6))
199 expect_pkt = NX_FALSE;
200 else
201 expect_pkt = NX_TRUE;
202
203 /* Copy DNS header. */
204 memcpy(assemble_pkt_data, pkt_data + 14 + offset, 12);
205 assemble_len = 12;
206 pkt_data += (26 + offset);
207
208 /* Get counts of question and answer. */
209 question_cnt = *((USHORT*)(assemble_pkt_data + 4));
210 NX_CHANGE_USHORT_ENDIAN(question_cnt);
211 answer_cnt = *((USHORT*)(assemble_pkt_data + 6));
212 NX_CHANGE_USHORT_ENDIAN(answer_cnt);
213 tmp = *((USHORT*)(assemble_pkt_data + 8));
214 NX_CHANGE_USHORT_ENDIAN(tmp);
215 answer_cnt += tmp;
216 tmp = *((USHORT*)(assemble_pkt_data + 10));
217 NX_CHANGE_USHORT_ENDIAN(tmp);
218 answer_cnt += tmp;
219
220 /* Decode questions. */
221 while(question_cnt)
222 {
223 decode_mdns_data(&assemble_len, &pkt_data);
224
225 /* Copy fixed data. */
226 memcpy(assemble_pkt_data + assemble_len, pkt_data, 4);
227 assemble_len += 4;
228 pkt_data += 4;
229
230 question_cnt--;
231 }
232
233 /* Decode answers. */
234 while(answer_cnt)
235 {
236 decode_mdns_data(&assemble_len, &pkt_data);
237
238 /* Get type. */
239 type = *pkt_data;
240 type = (type << 8) + *(pkt_data + 1);
241
242 /* Copy fixed data. */
243 memcpy(assemble_pkt_data + assemble_len, pkt_data, 10);
244 assemble_len += 10;
245 pkt_data += 10;
246
247 /* Get data length pointer. */
248 data_len_ptr = assemble_pkt_data + assemble_len - 2;
249
250 if((type == NX_MDNS_RR_TYPE_PTR) ||
251 (type == NX_MDNS_RR_TYPE_SRV))
252 {
253
254 /* Need decode. */
255 if(type == NX_MDNS_RR_TYPE_SRV)
256 {
257
258 /* The first 6 bytes of SRV are fixed. */
259 memcpy(assemble_pkt_data + assemble_len, pkt_data, 6);
260 assemble_len += 6;
261 pkt_data += 6;
262 }
263
264 decode_mdns_data(&assemble_len, &pkt_data);
265
266 /* Calculate decoded data length. */
267 data_len = (USHORT)(assemble_pkt_data + assemble_len - data_len_ptr) - 2;
268 *((USHORT*)data_len_ptr) = data_len;
269 NX_CHANGE_USHORT_ENDIAN(*((USHORT*)data_len_ptr));
270 }
271 else
272 {
273
274 /* Nothing to decode. */
275 data_len = (*data_len_ptr << 8) | *(data_len_ptr + 1);
276 memcpy(assemble_pkt_data + assemble_len, pkt_data, data_len);
277 assemble_len += data_len;
278 pkt_data += data_len;
279 }
280
281 answer_cnt--;
282 }
283
284 /* Compute the amount of time to wait for. */
285 start_time = current_time = tx_time_get();
286
287 /* timeout value is expressed in terms of seconds. Convert it to ticks. */
288 time_remaining = timeout - (current_time - start_time);
289
290
291 while(time_remaining > 0)
292 {
293 /* Wait for a packet. */
294 status = tx_semaphore_get(&pkt_count_sem, time_remaining);
295
296 if(status == NX_SUCCESS)
297 {
298 tx_mutex_get(&pkt_capture_mutex, TX_WAIT_FOREVER);
299 current_pkt = incoming_pkts;
300 if(incoming_pkts)
301 {
302 incoming_pkts = incoming_pkts -> nx_packet_queue_next;
303 }
304 else
305 {
306 incoming_pkts_tail = NX_NULL;
307 }
308 tx_mutex_put(&pkt_capture_mutex);
309
310 if(current_pkt)
311 {
312
313 /* A packet has been queued. Examine the content of the packet. */
314 if((assemble_len != current_pkt -> nx_packet_length - offset) ||
315 (memcmp(assemble_pkt_data, current_pkt -> nx_packet_prepend_ptr + offset, assemble_len) != 0))
316 {
317 /* Not a match. */
318
319 /* Compute new timeout value. */
320 current_time = tx_time_get();
321 time_remaining = timeout - (current_time - start_time);
322 if((time_remaining > 0x80000000) && (expect_pkt == NX_TRUE))
323 {
324 /* Underflow */
325 time_remaining = 0;
326 error_counter = 1;
327 }
328 nx_packet_release(current_pkt);
329 continue;
330 }
331 else
332 {
333 /* Packet is a match. Get out of this CHECK state. */
334 time_remaining = 0;
335 nx_packet_release(current_pkt);
336
337 if(expect_pkt == NX_FALSE)
338 error_counter = 1;
339 continue;
340 }
341 }
342 }
343 else
344 {
345 /* Timeout */
346 if(expect_pkt == NX_TRUE)
347 error_counter = 1;
348 time_remaining = 0;
349 }
350 }
351 }
352
perform_check_mdns_any(int pkt_size,int timeout,int cmd)353 static void perform_check_mdns_any(int pkt_size, int timeout, int cmd)
354 {
355 UINT status;
356 NX_PACKET *current_pkt;
357 ULONG start_time, current_time, time_remaining;
358 ULONG offset;
359 USHORT target_flags = pkt_size;
360 USHORT pkt_flags;
361 USHORT src_port, dst_port;
362 UCHAR expect_pkt;
363
364 /* Calculate offset. */
365 if((cmd == MDNS_CHECK_ANY_V4) || (cmd == MDNS_REJECT_ANY_V4))
366 offset = 20;
367 else
368 offset = 40;
369
370 /* Whether this packet is expected. */
371 if((cmd == MDNS_REJECT_ANY_V4) || (cmd == MDNS_REJECT_ANY_V6))
372 expect_pkt = NX_FALSE;
373 else
374 expect_pkt = NX_TRUE;
375
376 /* Compute the amount of time to wait for. */
377 start_time = current_time = tx_time_get();
378
379 /* timeout value is expressed in terms of seconds. Convert it to ticks. */
380 time_remaining = timeout - (current_time - start_time);
381
382
383 while(time_remaining > 0)
384 {
385 /* Wait for a packet. */
386 status = tx_semaphore_get(&pkt_count_sem, time_remaining);
387
388 if(status == NX_SUCCESS)
389 {
390 tx_mutex_get(&pkt_capture_mutex, TX_WAIT_FOREVER);
391 current_pkt = incoming_pkts;
392 if(incoming_pkts)
393 {
394 incoming_pkts = incoming_pkts -> nx_packet_queue_next;
395 }
396 else
397 {
398 incoming_pkts_tail = NX_NULL;
399 }
400 tx_mutex_put(&pkt_capture_mutex);
401
402 if(current_pkt)
403 {
404
405 /* Get UDP port. */
406 src_port = *((USHORT*)(current_pkt -> nx_packet_prepend_ptr + offset));
407 dst_port = *((USHORT*)(current_pkt -> nx_packet_prepend_ptr + offset + 2));
408
409 /* Change endian. */
410 NX_CHANGE_USHORT_ENDIAN(src_port);
411 NX_CHANGE_USHORT_ENDIAN(dst_port);
412
413 /* Get flags in packet. */
414 pkt_flags = *((USHORT*)(current_pkt -> nx_packet_prepend_ptr + offset + 10));
415
416 /* Change endian. */
417 NX_CHANGE_USHORT_ENDIAN(pkt_flags);
418
419 /* A packet has been queued. Examine the content of the packet. */
420 if((src_port != 5353) ||
421 (dst_port != 5353) ||
422 (pkt_flags != target_flags))
423 {
424 /* Not a match. */
425
426 /* Compute new timeout value. */
427 current_time = tx_time_get();
428 time_remaining = timeout - (current_time - start_time);
429 if((time_remaining > 0x80000000) && (expect_pkt == NX_TRUE))
430 {
431 /* Underflow */
432 time_remaining = 0;
433 error_counter = 1;
434 }
435 nx_packet_release(current_pkt);
436 continue;
437 }
438 else
439 {
440 /* Packet is a match. Get out of this CHECK state. */
441 time_remaining = 0;
442 nx_packet_release(current_pkt);
443
444 if(expect_pkt == NX_FALSE)
445 error_counter = 1;
446 continue;
447 }
448 }
449 }
450 else
451 {
452 /* Timeout */
453 if(expect_pkt == NX_TRUE)
454 error_counter = 1;
455 time_remaining = 0;
456 }
457 }
458 }
459
perform_mdns_rr_check(NX_MDNS * mdns_ptr,int pkt_size,int cmd)460 static void perform_mdns_rr_check(NX_MDNS *mdns_ptr, int pkt_size, int cmd)
461 {
462
463 ULONG *head;
464 NX_MDNS_RR *p;
465 UCHAR *record_buffer;
466 UINT buffer_size;
467 UINT rr_count;
468
469 tx_mutex_get(&mdns_ptr -> nx_mdns_mutex, TX_WAIT_FOREVER);
470
471 /* Get buffer. */
472 if(cmd == MDNS_CHECK_RR_COUNT_REMOTE)
473 {
474 record_buffer = mdns_ptr -> nx_mdns_peer_service_cache;
475 buffer_size = mdns_ptr -> nx_mdns_peer_service_cache_size;
476 }
477 else
478 {
479 record_buffer = mdns_ptr -> nx_mdns_local_service_cache;
480 buffer_size = mdns_ptr -> nx_mdns_local_service_cache_size;
481 }
482
483 rr_count = 0;
484
485 /* Get head. */
486 head = (ULONG*)record_buffer;
487 head = (ULONG*)(*head);
488
489 /* Loop to find record. */
490 for(p = (NX_MDNS_RR*)((ULONG*)record_buffer + 1); (ULONG*)p < head; p++)
491 {
492
493 /* Check whether the resource record is valid. */
494 if ((p -> nx_mdns_rr_state == NX_MDNS_RR_STATE_VALID) ||
495 (p -> nx_mdns_rr_state == NX_MDNS_RR_STATE_DELETE))
496 rr_count++;
497 }
498
499 if(pkt_size != rr_count)
500 error_counter = 1;
501
502 tx_mutex_put(&mdns_ptr -> nx_mdns_mutex);
503 }
504
505
506 #ifndef NX_MDNS_DISABLE_CLIENT
perform_mdns_rr_data_check(NX_MDNS * mdns_ptr,char * pkt_data,int pkt_size)507 static void perform_mdns_rr_data_check(NX_MDNS *mdns_ptr, char *pkt_data, int pkt_size)
508 {
509 MDNS_RR_DATA *rr_data_ptr = (MDNS_RR_DATA*)pkt_data;
510 UCHAR *buffer = assemble_pkt_data;
511 UINT index = 0;
512 NX_MDNS_SERVICE service;
513
514 /* Loop to check RR data. */
515 while(pkt_size > 0)
516 {
517
518 /* Get service by type and domain. */
519 if(nx_mdns_service_lookup(mdns_ptr, NX_NULL, rr_data_ptr -> mdns_rr_data_type, NX_NULL, index, &service))
520 error_counter++;
521 else
522 {
523 index++;
524
525 /* Check name fileds. */
526 if(strcmp(service.service_name, rr_data_ptr -> mdns_rr_data_name))
527 error_counter++;
528 }
529
530 pkt_size--;
531 rr_data_ptr++;
532 }
533 }
534 #endif /* NX_MDNS_DISABLE_CLIENT */
535
536
inject_packet(NX_IP * ip_ptr,char * pkt_data,int pkt_size)537 static void inject_packet(NX_IP *ip_ptr, char *pkt_data, int pkt_size)
538 {
539
540 UINT status;
541 NX_PACKET *my_packet;
542
543 /* Now, this packet is a received one, allocate the packet and let the IP stack receives it. */
544 /* Allocate a packet. */
545 status = nx_packet_allocate(ip_ptr -> nx_ip_default_packet_pool, &my_packet, 0, NX_WAIT_FOREVER);
546
547 /* Check status. */
548 if (status != NX_SUCCESS)
549 {
550 error_counter++;
551 return;
552 }
553
554 my_packet -> nx_packet_length = pkt_size - 14;
555 memcpy(my_packet -> nx_packet_prepend_ptr + 16, pkt_data + 14, my_packet -> nx_packet_length);
556
557 /* Mark the packet as IPv6 */
558 my_packet -> nx_packet_ip_version = NX_IP_VERSION_V6;
559
560 my_packet -> nx_packet_append_ptr = my_packet -> nx_packet_prepend_ptr + my_packet -> nx_packet_length;
561
562 my_packet -> nx_packet_prepend_ptr += 16;
563 my_packet -> nx_packet_append_ptr += 16;
564
565 _nx_ip_packet_deferred_receive(ip_ptr, my_packet);
566
567 }
568
dump_packets(void)569 static void dump_packets(void)
570 {
571
572 NX_PACKET *tmp_pkt;
573
574 tx_mutex_get(&pkt_capture_mutex, TX_WAIT_FOREVER);
575 tmp_pkt = incoming_pkts;
576
577 while(tmp_pkt)
578 {
579 tx_semaphore_get(&pkt_count_sem, 0);
580 incoming_pkts = tmp_pkt -> nx_packet_queue_next;
581 nx_packet_release(tmp_pkt);
582 tmp_pkt = incoming_pkts;
583 }
584 incoming_pkts = NX_NULL;
585
586 tx_mutex_put(&pkt_capture_mutex);
587 }
588
netx_mdns_probing_notify(struct NX_MDNS_STRUCT * mdns_ptr,UCHAR * name,UINT state)589 void netx_mdns_probing_notify(struct NX_MDNS_STRUCT *mdns_ptr, UCHAR *name, UINT state)
590 {
591
592
593 /* Check state. */
594 if(probing_callback_state == state)
595 probing_callback_invoked++;
596 }
597
598 extern ULONG test_control_successful_tests;
599 extern ULONG test_control_failed_tests;
netx_mdns_run_test_case(NX_IP * ip_ptr,NX_MDNS * mdns_ptr,MDNS_TEST_SEQ * test_case,int test_case_size)600 void netx_mdns_run_test_case(NX_IP *ip_ptr, NX_MDNS *mdns_ptr, MDNS_TEST_SEQ *test_case, int test_case_size)
601 {
602
603 int steps;
604 int i;
605 MDNS_SERVICE *mdns_service;
606 MDNS_QUERY_INFO *query;
607 ULONG current_time;
608 ULONG v4_address;
609
610 /* Init the semaphore and mutex. */
611 tx_mutex_create(&pkt_capture_mutex, "TAHI PKT CAPTURE", 0);
612 tx_semaphore_create(&pkt_count_sem, "TAHI_PKT COUNT SEM", 0);
613
614
615 packet_process_callback = packet_process;
616
617 in_cleanup_process = 0;
618 error_counter = 0;
619 service_callback_state = 0;
620 service_callback_invoked = 0;
621 for(steps = 0; steps < test_case_size; steps++)
622 {
623 /* If error has occured, skip all the test steps and start the cleanup process. */
624 if(error_counter && !in_cleanup_process)
625 {
626 if(test_case[steps].command != CLEANUP)
627 continue;
628 }
629
630 switch(test_case[steps].command)
631 {
632 case CLEANUP:
633 /* This is a marker. Nothing needs to be done here. */
634 in_cleanup_process = 1;
635 continue;
636
637 case TITLE:
638 printf("NetX Test: MDNS %s TEST", test_case[steps].pkt_data);
639
640 /* Align the output. */
641 for (i = test_case[steps].pkt_size; i <= 47; i++)
642 printf(".");
643
644 /* Set the flag to queue up packets. */
645 tx_mutex_get(&pkt_capture_mutex, TX_WAIT_FOREVER);
646 pkt_capture_flag = 1;
647 tx_mutex_put(&pkt_capture_mutex);
648 break;
649 case INJECT:
650 inject_packet(ip_ptr, test_case[steps].pkt_data, test_case[steps].pkt_size);
651 break;
652 case WAIT:
653 tx_thread_sleep(test_case[steps].timeout * NX_IP_PERIODIC_RATE);
654 break;
655 case MDNS_WAIT_TICK:
656 tx_thread_sleep(test_case[steps].timeout * NX_IP_PERIODIC_RATE / 100);
657 break;
658 case CHECK:
659 perform_check(test_case[steps].pkt_data, test_case[steps].pkt_size, test_case[steps].timeout* NX_IP_PERIODIC_RATE + NX_MDNS_TIMER_COUNT_RANGE);
660 break;
661 case MDNS_SET_IPV4_ADDRESS:
662 nx_ip_address_set(ip_ptr, test_case[steps].pkt_size, 0xFF000000);
663 break;
664 #if defined FEATURE_NX_IPV6 && defined NX_ENABLE_IPV6_MULTICAST
665 case MDNS_LLA_ADD:
666 nx_ip_interface_physical_address_set(ip_ptr, 0, test_case[steps].pkt_size, test_case[steps].timeout, NX_TRUE);
667 nxd_ipv6_address_set(ip_ptr, 0, NX_NULL, 10, NX_NULL);
668 break;
669 case MDNS_LLA_DELETE:
670 nxd_ipv6_address_delete(ip_ptr, 0);
671 break;
672 #endif /* FEATURE_NX_IPV6 && NX_ENABLE_IPV6_MULTICAST */
673 case MDNS_CHECK_DATA_V4:
674 case MDNS_CHECK_DATA_V6:
675 case MDNS_REJECT_DATA_V4:
676 case MDNS_REJECT_DATA_V6:
677 perform_check_mdns_data(test_case[steps].pkt_data, test_case[steps].pkt_size, test_case[steps].timeout* NX_IP_PERIODIC_RATE + NX_MDNS_TIMER_COUNT_RANGE, test_case[steps].command);
678 break;
679 case MDNS_CHECK_ANY_V4:
680 case MDNS_CHECK_ANY_V6:
681 case MDNS_REJECT_ANY_V4:
682 case MDNS_REJECT_ANY_V6:
683 perform_check_mdns_any(test_case[steps].pkt_size, test_case[steps].timeout* NX_IP_PERIODIC_RATE + NX_MDNS_TIMER_COUNT_RANGE, test_case[steps].command);
684 break;
685 #ifndef NX_MDNS_DISABLE_CLIENT
686 case MDNS_QUERY:
687 query = (MDNS_QUERY_INFO *)test_case[steps].pkt_data;
688 nx_mdns_service_continuous_query(mdns_ptr, query -> name, query -> type, query -> sub_type);
689 break;
690 case MDNS_QUERY_HOST_ADDRESS:
691 nx_mdns_host_address_get(mdns_ptr, test_case[steps].pkt_data, &v4_address, NX_NULL, test_case[steps].timeout* NX_IP_PERIODIC_RATE);
692 break;
693 case MDNS_QUERY_DELETE:
694 nx_mdns_service_query_stop(mdns_ptr, query -> name, query -> type, query -> sub_type);
695 break;
696 case MDNS_SET_SERVICE_CALLBACK_STATE:
697 service_callback_state = test_case[steps].pkt_size;
698 service_callback_invoked = test_case[steps].timeout;
699 break;
700 case MDNS_SET_SERVICE_CALLBACK:
701 service_callback_state = test_case[steps].pkt_size;
702 service_callback_invoked = test_case[steps].timeout;
703 nx_mdns_service_notify_set(mdns_ptr, (ULONG)test_case[steps].pkt_data, service_change_notify);
704 break;
705 case MDNS_CHECK_SERVICE_CALLBACK_INVOKED:
706 if(service_callback_invoked != test_case[steps].timeout)
707 error_counter++;
708 break;
709 case MDNS_CHECK_RR_DATA:
710 perform_mdns_rr_data_check(mdns_ptr, test_case[steps].pkt_data, test_case[steps].pkt_size);
711 break;
712 #endif /* NX_MDNS_DISABLE_CLIENT */
713 #ifndef NX_MDNS_DISABLE_SERVER
714 case MDNS_SERVICE_DELETE:
715 mdns_service = (MDNS_SERVICE*)test_case[steps].pkt_data;
716 nx_mdns_service_delete(mdns_ptr, mdns_service -> name, mdns_service -> type, mdns_service -> sub_type);
717 break;
718 case MDNS_SERVICE_ADD:
719 mdns_service = (MDNS_SERVICE*)test_case[steps].pkt_data;
720 nx_mdns_service_add(mdns_ptr, mdns_service -> name, mdns_service -> type, mdns_service -> sub_type, mdns_service -> txt,
721 mdns_service -> ttl, mdns_service -> priority, mdns_service -> weights, mdns_service -> port,
722 mdns_service -> set, mdns_service -> if_index);
723 break;
724 #endif /* NX_MDNS_DISABLE_SERVER */
725 case MDNS_SET_PROBING_CALLBACK_STATE:
726 probing_callback_state = test_case[steps].pkt_size;
727 probing_callback_invoked = test_case[steps].timeout;
728 break;
729 case MDNS_CHECK_PROBING_CALLBACK_INVOKED:
730 if(probing_callback_invoked != test_case[steps].timeout)
731 error_counter++;
732 break;
733 case MDNS_TIMER_RESET:
734 tx_time_set(0);
735 break;
736 case MDNS_TIMER_CHECK:
737 current_time = tx_time_get();
738 if((current_time < (ULONG)((test_case[steps].timeout - test_case[steps].pkt_size) * NX_IP_PERIODIC_RATE / 100)) ||
739 (current_time > (ULONG)((test_case[steps].timeout + test_case[steps].pkt_size) * NX_IP_PERIODIC_RATE / 100)))
740 error_counter++;
741 break;
742 case MDNS_TIMER_MAX_CHECK:
743 current_time = tx_time_get();
744 if(current_time > (ULONG)(test_case[steps].timeout * NX_IP_PERIODIC_RATE / 100))
745 error_counter++;
746 break;
747 case MDNS_INTERFACE_DISABLE:
748 nx_mdns_disable(mdns_ptr, 0);
749 break;
750 case MDNS_INTERFACE_ENABLE:
751 nx_mdns_enable(mdns_ptr, 0);
752 break;
753 case MDNS_RECREATE:
754 {
755 NX_PACKET_POOL *pool_ptr = mdns_ptr -> nx_mdns_packet_pool_ptr;
756 UCHAR *local_buffer = mdns_ptr -> nx_mdns_local_service_cache;
757 UCHAR *remote_buffer = mdns_ptr -> nx_mdns_peer_service_cache;
758 UINT local_buffer_size = mdns_ptr -> nx_mdns_local_service_cache_size;
759 UINT remote_buffer_size = mdns_ptr -> nx_mdns_peer_service_cache_size;
760
761 nx_mdns_delete(mdns_ptr);
762 nx_mdns_create(mdns_ptr, ip_ptr, pool_ptr, 2, mdns_stack, DEMO_STACK_SIZE,
763 test_case[steps].pkt_data, local_buffer, local_buffer_size, remote_buffer, remote_buffer_size, netx_mdns_probing_notify);
764 nx_mdns_enable(mdns_ptr, 0);
765
766 }break;
767 case MDNS_CHECK_RR_COUNT_REMOTE:
768 case MDNS_CHECK_RR_COUNT_LOCAL:
769 perform_mdns_rr_check(mdns_ptr, test_case[steps].pkt_size, test_case[steps].command);
770 break;
771 case DUMP:
772 dump_packets();
773 break;
774 default:
775 break;
776 }
777 }
778 /* Set the flag to queue up packets. */
779 tx_mutex_get(&pkt_capture_mutex, TX_WAIT_FOREVER);
780 pkt_capture_flag = 0;
781 packet_process_callback = NX_NULL;
782 tx_mutex_put(&pkt_capture_mutex);
783 dump_packets();
784 /* Check for earlier error. */
785 if(error_counter)
786 {
787 printf("ERROR!\n");
788 test_control_failed_tests++;
789 }
790 else
791 {
792 printf("SUCCESS!\n");
793 test_control_successful_tests++;
794 }
795
796 tx_mutex_delete(&pkt_capture_mutex);
797 tx_semaphore_delete(&pkt_count_sem);
798 }
799
packet_process(NX_IP * ip_ptr,NX_PACKET * packet_ptr)800 static UINT packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr)
801 {
802
803 tx_mutex_get(&pkt_capture_mutex, TX_WAIT_FOREVER);
804 if(pkt_capture_flag == 0)
805 {
806 nx_packet_release(packet_ptr);
807 tx_mutex_put(&pkt_capture_mutex);
808 return NX_NULL;
809 }
810
811 if(incoming_pkts == NX_NULL)
812 {
813 incoming_pkts = packet_ptr;
814 }
815 else
816 {
817 incoming_pkts_tail -> nx_packet_queue_next = packet_ptr;
818 }
819 incoming_pkts_tail = packet_ptr;
820
821 packet_ptr -> nx_packet_queue_next = NX_NULL;
822
823 tx_mutex_put(&pkt_capture_mutex);
824
825 tx_semaphore_put(&pkt_count_sem);
826
827 return NX_NULL;
828 }
829 #endif
830