/* Test IPv6 prefix with length not equal 64. */ #include "tx_api.h" #include "nx_api.h" #include "nx_ram_network_driver_test_1500.h" extern void test_control_return(UINT status); #if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_LOOPBACK_INTERFACE) && !defined(NX_DISABLE_IPV4) #include "nx_tcp.h" #include "nx_ip.h" #include "nx_ipv6.h" #include "nx_icmp.h" #include "nx_icmpv6.h" #define DEMO_STACK_SIZE 2048 #define TEST_INTERFACE 0 /* Define the ThreadX and NetX object control blocks... */ static TX_THREAD thread_0; static NX_PACKET_POOL pool_0; static NX_IP ip_0; /* Define the counters used in the demo application... */ static ULONG error_counter; /* Define thread prototypes. */ static void thread_0_entry(ULONG thread_input); extern void test_control_return(UINT status); extern void _nx_ram_network_driver_1500(struct NX_IP_DRIVER_STRUCT *driver_req); /* Frame (74 bytes) */ /* IPv4 pakcet with next protocol 60(DESTINATION). */ static char pkt1[74] = { 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /* ...E... */ 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */ 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x3c, /* . nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Set invalid value to test destination protocol. */ packet_ptr -> nx_packet_destination_header = 1; packet_ptr -> nx_packet_option_state = 0; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt2; pkt_len = sizeof(pkt2); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Set invalid value to test destination protocol. */ packet_ptr -> nx_packet_destination_header = 0; packet_ptr -> nx_packet_option_state = ROUTING_HEADER; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt3; pkt_len = sizeof(pkt3); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Set invalid value to test destination protocol. */ packet_ptr -> nx_packet_destination_header = 0; packet_ptr -> nx_packet_option_state = FRAGMENT_HEADER; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } #ifndef NX_IPSEC_ENABLE status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt4; pkt_len = sizeof(pkt4); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt5; pkt_len = sizeof(pkt5); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } #endif /* NX_IPSEC_ENABLE */ status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt6; pkt_len = sizeof(pkt6); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Disable ICMP. */ ip_0.nx_ip_icmpv6_packet_process = NX_NULL; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); /* Disable ICMP. */ ip_0.nx_ip_icmpv6_packet_process = _nx_icmpv6_packet_process; status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt7; pkt_len = sizeof(pkt7); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Disable ICMP. */ ip_0.nx_ip_icmp_packet_receive = NX_NULL; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); /* Disable ICMP. */ ip_0.nx_ip_icmp_packet_receive = _nx_icmp_packet_receive; status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt8; pkt_len = sizeof(pkt8); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt9; pkt_len = sizeof(pkt9); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt10; pkt_len = sizeof(pkt10); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt11; pkt_len = sizeof(pkt11); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE); /* Check status */ if(status) { error_counter++; } else { nx_packet_release(ping_resp); } status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt12; pkt_len = sizeof(pkt12); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt13; pkt_len = sizeof(pkt13); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER); /* Check status */ if(status) error_counter++; /* Fill in the packet with data. Skip the MAC header. */ pkt_data_ptr = pkt14; pkt_len = sizeof(pkt14); memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14); packet_ptr -> nx_packet_length = pkt_len - 14; packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length; /* Directly receive the packet. */ _nx_ip_packet_deferred_receive(&ip_0, packet_ptr); /* Check the error. */ if(error_counter) { printf("ERROR!\n"); test_control_return(1); } else { printf("SUCCESS!\n"); test_control_return(0); } } #else #ifdef CTEST VOID test_application_define(void *first_unused_memory) #else void netx_ip_abnormal_packet_test_application_define(void *first_unused_memory) #endif { /* Print out test information banner. */ printf("NetX Test: IP Abnormal Packet Test...................................N/A\n"); test_control_return(3); } #endif /* FEATURE_NX_IPV6 */