1 /* Test IPv6 prefix with length not equal 64. */
2 
3 #include    "tx_api.h"
4 #include    "nx_api.h"
5 #include    "nx_ram_network_driver_test_1500.h"
6 
7 extern void    test_control_return(UINT status);
8 
9 #if defined(FEATURE_NX_IPV6) && !defined(NX_DISABLE_LOOPBACK_INTERFACE)  && !defined(NX_DISABLE_IPV4)
10 
11 #include    "nx_tcp.h"
12 #include    "nx_ip.h"
13 #include    "nx_ipv6.h"
14 #include    "nx_icmp.h"
15 #include    "nx_icmpv6.h"
16 
17 #define     DEMO_STACK_SIZE    2048
18 #define     TEST_INTERFACE     0
19 
20 /* Define the ThreadX and NetX object control blocks...  */
21 
22 static TX_THREAD               thread_0;
23 static NX_PACKET_POOL          pool_0;
24 static NX_IP                   ip_0;
25 
26 /* Define the counters used in the demo application...  */
27 
28 static ULONG                   error_counter;
29 
30 /* Define thread prototypes.  */
31 static void    thread_0_entry(ULONG thread_input);
32 extern void    test_control_return(UINT status);
33 extern void    _nx_ram_network_driver_1500(struct NX_IP_DRIVER_STRUCT *driver_req);
34 
35 /* Frame (74 bytes) */
36 /* IPv4 pakcet with next protocol 60(DESTINATION). */
37 static char pkt1[74] = {
38 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
39 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
40 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x3c, /* .<l1..@< */
41 0x10, 0x53, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* .S...... */
42 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
43 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
44 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
45 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
46 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
47 0x68, 0x69                                      /* hi */
48 };
49 
50 /* Frame (74 bytes) */
51 /* IPv4 pakcet with next protocol 43(ROUTING). */
52 static char pkt2[74] = {
53 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
54 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
55 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x2b, /* .<l1..@+ */
56 0x10, 0x64, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* .d...... */
57 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
58 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
59 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
60 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
61 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
62 0x68, 0x69                                      /* hi */
63 };
64 
65 /* Frame (74 bytes) */
66 /* IPv4 pakcet with next protocol 44(FRAGMENT). */
67 static char pkt3[74] = {
68 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
69 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
70 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x2c, /* .<l1..@, */
71 0x10, 0x63, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* .c...... */
72 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
73 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
74 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
75 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
76 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
77 0x68, 0x69                                      /* hi */
78 };
79 
80 #ifndef NX_IPSEC_ENABLE
81 /* Frame (74 bytes) */
82 /* IPv4 pakcet with next protocol 51(AH). */
83 static char pkt4[74] = {
84 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
85 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
86 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x33, /* .<l1..@3 */
87 0x10, 0x5c, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* .\...... */
88 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
89 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
90 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
91 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
92 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
93 0x68, 0x69                                      /* hi */
94 };
95 
96 /* Frame (74 bytes) */
97 /* IPv4 pakcet with next protocol 50(ESP). */
98 static char pkt5[74] = {
99 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
100 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
101 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x32, /* .<l1..@2 */
102 0x10, 0x5d, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* .]...... */
103 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
104 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
105 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
106 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
107 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
108 0x68, 0x69                                      /* hi */
109 };
110 #endif /* NX_IPSEC_ENABLE */
111 
112 /* IPv6 pakcet with next protocol 58(ICMPv6). */
113 /* Frame (70 bytes) */
114 static char pkt6[70] = {
115 0x00, 0x11, 0x22, 0x33, 0x44, 0x56, 0x00, 0x00, /* .."3DV.. */
116 0x00, 0x00, 0x01, 0x00, 0x86, 0xdd, 0x60, 0x00, /* ......`. */
117 0x00, 0x00, 0x00, 0x10, 0x3a, 0xff, 0xfe, 0x80, /* ....:... */
118 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x02, /* ........ */
120 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
121 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x00, /* ........ */
122 0x09, 0x05, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, /* ........ */
123 0x03, 0x04, 0x05, 0x06, 0x07, 0x08              /* ...... */
124 };
125 
126 /* Frame (74 bytes) */
127 /* IPv4 pakcet with next protocol 1(ICMPv4). */
128 static char pkt7[74] = {
129 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
130 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
131 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x01, /* .<l1..@. */
132 0x10, 0x8e, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* ........ */
133 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
134 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
135 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
136 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
137 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
138 0x68, 0x69                                      /* hi */
139 };
140 
141 /* Frame (74 bytes) */
142 /* IPv4 pakcet with next protocol 2(IGMP). */
143 static char pkt8[74] = {
144 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
145 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
146 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x02, /* .<l1..@. */
147 0x10, 0x8d, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* ........ */
148 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
149 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
150 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
151 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
152 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
153 0x68, 0x69                                      /* hi */
154 };
155 
156 /* Frame (74 bytes) */
157 /* IPv4 pakcet with next protocol 17(UDP). */
158 static char pkt9[74] = {
159 0x20, 0x0b, 0xc7, 0x94, 0x45, 0x96, 0x18, 0x03, /*  ...E... */
160 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x45, 0x00, /* s)_f..E. */
161 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x11, /* .<l1..@. */
162 0x10, 0x7e, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* .~...... */
163 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
164 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
165 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
166 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
167 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
168 0x68, 0x69                                      /* hi */
169 };
170 
171 /* Frame (78 bytes) */
172 /* IPv6 pakcet with extension headers 0(hop by hop). */
173 /* The length in hop by hop header is larger than the packet length. */
174 static char pkt10[78] = {
175 0x00, 0x11, 0x22, 0x33, 0x44, 0x56, 0x00, 0x00, /* .."3DV.. */
176 0x00, 0x00, 0x01, 0x00, 0x86, 0xdd, 0x60, 0x00, /* ......`. */
177 0x00, 0x00, 0x00, 0x18, 0x2b, 0xff, 0xfe, 0x80, /* ....+... */
178 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
179 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0x02, /* ........ */
180 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
181 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x3a, 0xff, /* ......:. */
182 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00, /* !....... */
183 0x72, 0x1b, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, /* r....... */
184 0x03, 0x04, 0x05, 0x06, 0x07, 0x08              /* ...... */
185 };
186 
187 
188 /* Frame (62 bytes) */
189 /* IPv6 packet with ICMPv6 redirect content. But the length of ICMPv6 is 8. */
190 static char pkt11[62] = {
191 0x00, 0x11, 0x22, 0x33, 0x44, 0x56, 0x00, 0x00, /* .."3DV.. */
192 0x00, 0x00, 0xa0, 0xa0, 0x86, 0xdd, 0x60, 0x00, /* ......`. */
193 0x00, 0x00, 0x00, 0x08, 0x3a, 0xff, 0xfe, 0x80, /* ...(:... */
194 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, /* ........ */
195 0x00, 0xff, 0xfe, 0x00, 0xa0, 0xa0, 0xff, 0x02, /* ........ */
196 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
197 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x89, 0x00, /* ........ */
198 0xd7, 0x97, 0x00, 0x00, 0x00, 0x00              /* .w...... */
199 };
200 
201 /* Frame (126 bytes) */
202 /* IPv6 packet with two hop by hop extension headers. */
203 static char pkt12[] = {
204 0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0x8c, 0xec, /* 33...... */
205 0x4b, 0x68, 0xd1, 0xfe, 0x86, 0xdd, 0x60, 0x07, /* Kh....`. */
206 0x1f, 0xfc, 0x00, 0x48, 0x00, 0xff, 0xfe, 0x80, /* ...H.... */
207 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0xec, /* ........ */
208 0x4b, 0xff, 0xfe, 0x68, 0xd1, 0xfe, 0xff, 0x02, /* K..h.... */
209 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
210 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, /* ........ */
211 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x00, /* ......:. */
212 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x86, 0x00, /* ........ */
213 0xca, 0xef, 0x40, 0x00, 0x00, 0x5a, 0x00, 0x00, /* ..@..Z.. */
214 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, /* ........ */
215 0x40, 0xc0, 0x00, 0x01, 0x51, 0x80, 0x00, 0x00, /* @...Q... */
216 0x38, 0x40, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, /* 8@.... . */
217 0x04, 0x70, 0xf8, 0x1e, 0x30, 0x00, 0x00, 0x00, /* .p..0... */
218 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, /* ........ */
219 0x8c, 0xec, 0x4b, 0x68, 0xd1, 0xfe              /* ..Kh.. */
220 };
221 
222 /* Frame (102 bytes) */
223 /* RA packet with invalid option type (0). */
224 static char pkt13[] = {
225 0x33, 0x33, 0x00, 0x00, 0x00, 0x01, 0x8c, 0xec, /* 33...... */
226 0x4b, 0x68, 0xd1, 0xfe, 0x86, 0xdd, 0x60, 0x07, /* Kh....`. */
227 0x1f, 0xfc, 0x00, 0x30, 0x3a, 0xff, 0xfe, 0x80, /* ...0:... */
228 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8e, 0xec, /* ........ */
229 0x4b, 0xff, 0xfe, 0x68, 0xd1, 0xfe, 0xff, 0x02, /* K..h.... */
230 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* ........ */
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x86, 0x00, /* ........ */
232 0x79, 0x4c, 0x40, 0x00, 0x00, 0x5a, 0x00, 0x00, /* yL@..Z.. */
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, /* ........ */
234 0x40, 0xc0, 0x00, 0x01, 0x51, 0x80, 0x00, 0x00, /* @...Q... */
235 0x38, 0x40, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, /* 8@.... . */
236 0x04, 0x70, 0xf8, 0x1e, 0x30, 0x00, 0x00, 0x00, /* .p..0... */
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00              /* ...... */
238 };
239 
240 /* Frame (74 bytes) */
241 /* IPv4 pakcet with invalid header length. */
242 static char pkt14[74] = {
243 0x20, 0x0b, 0xc7, 0x94, 0x44, 0x96, 0x18, 0x03, /*  ...E... */
244 0x73, 0x29, 0x5f, 0x66, 0x08, 0x00, 0x44, 0x00, /* s)_f..E. */
245 0x00, 0x3c, 0x6c, 0x31, 0x00, 0x00, 0x40, 0x01, /* .<l1..@, */
246 0x10, 0x8e, 0x7f, 0x00, 0x00, 0x01, 0x7f, 0x00, /* .c...... */
247 0x00, 0x01, 0x08, 0x00, 0x4d, 0x4a, 0x00, 0x01, /* ....MJ.. */
248 0x00, 0x11, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, /* ..abcdef */
249 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, /* ghijklmn */
250 0x6f, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, /* opqrstuv */
251 0x77, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* wabcdefg */
252 0x68, 0x69                                      /* hi */
253 };
254 
255 
256 /* Define what the initial system looks like.  */
257 
258 #ifdef CTEST
test_application_define(void * first_unused_memory)259 VOID test_application_define(void *first_unused_memory)
260 #else
261 void           netx_ip_abnormal_packet_test_application_define(void *first_unused_memory)
262 #endif
263 {
264 CHAR       *pointer;
265 UINT       status;
266 
267     /* Setup the working pointer.  */
268     pointer = (CHAR *) first_unused_memory;
269 
270     /* Initialize the value.  */
271     error_counter = 0;
272 
273     /* Create the main thread.  */
274     tx_thread_create(&thread_0, "thread 0", thread_0_entry, 0,
275         pointer, DEMO_STACK_SIZE,
276         4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
277 
278     pointer = pointer + DEMO_STACK_SIZE;
279 
280     /* Initialize the NetX system.  */
281     nx_system_initialize();
282 
283     /* Create a packet pool.  */
284     status = nx_packet_pool_create(&pool_0, "NetX Main Packet Pool", 1536, pointer, 1536*16);
285     pointer = pointer + 1536*16;
286 
287     if(status)
288         error_counter++;
289 
290     /* Create an IP instance.  */
291     status = nx_ip_create(&ip_0, "NetX IP Instance 0", IP_ADDRESS(1,2,3,4), 0xFFFFFF00UL, &pool_0, _nx_ram_network_driver_1500,
292         pointer, 2048, 1);
293     pointer = pointer + 2048;
294 
295     /* Enable IPv6 */
296     status += nxd_ipv6_enable(&ip_0);
297 
298     /* Check IPv6 enable status.  */
299     if(status)
300         error_counter++;
301 
302     /* Enable IPv6 ICMP  */
303     status += nxd_icmp_enable(&ip_0);
304 
305     /* Check IPv6 ICMP enable status.  */
306     if(status)
307         error_counter++;
308 }
309 
310 /* Define the test threads.  */
311 
thread_0_entry(ULONG thread_input)312 static void    thread_0_entry(ULONG thread_input)
313 {
314 UINT                    status;
315 NX_PACKET              *packet_ptr;
316 NX_PACKET              *ping_resp;
317 CHAR                   *pkt_data_ptr;
318 CHAR                    pkt_len;
319 
320     /* Print out test information banner.  */
321     printf("NetX Test:   IP Abnormal Packet Test...................................");
322 
323     /* Check for earlier error.  */
324     if(error_counter)
325     {
326         printf("ERROR!\n");
327         test_control_return(1);
328     }
329 
330     /* Set the linklocal address.  */
331     status = nxd_ipv6_address_set(&ip_0, 0, NX_NULL, 10, NULL);
332 
333     /* Check the status.  */
334     if(status)
335         error_counter++;
336 
337     /* Sleep 5 seconds for linklocal address DAD.  */
338     tx_thread_sleep(5 * NX_IP_PERIODIC_RATE);
339 
340     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
341 
342     /* Check status */
343     if(status)
344         error_counter++;
345 
346     /* Fill in the packet with data. Skip the MAC header.  */
347     pkt_data_ptr = pkt1;
348     pkt_len = sizeof(pkt1);
349     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
350     packet_ptr -> nx_packet_length = pkt_len - 14;
351     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
352 
353     /* Set invalid value to test destination protocol. */
354     packet_ptr -> nx_packet_destination_header = 1;
355     packet_ptr -> nx_packet_option_state = 0;
356 
357     /* Directly receive the packet.  */
358     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
359 
360     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
361 
362     /* Check status */
363     if(status)
364     {
365         error_counter++;
366     }
367     else
368     {
369         nx_packet_release(ping_resp);
370     }
371 
372 
373     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
374 
375     /* Check status */
376     if(status)
377         error_counter++;
378 
379     /* Fill in the packet with data. Skip the MAC header.  */
380     pkt_data_ptr = pkt2;
381     pkt_len = sizeof(pkt2);
382     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
383     packet_ptr -> nx_packet_length = pkt_len - 14;
384     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
385 
386     /* Set invalid value to test destination protocol. */
387     packet_ptr -> nx_packet_destination_header = 0;
388     packet_ptr -> nx_packet_option_state = ROUTING_HEADER;
389 
390     /* Directly receive the packet.  */
391     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
392 
393     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
394 
395     /* Check status */
396     if(status)
397     {
398         error_counter++;
399     }
400     else
401     {
402         nx_packet_release(ping_resp);
403     }
404 
405 
406     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
407 
408     /* Check status */
409     if(status)
410         error_counter++;
411 
412     /* Fill in the packet with data. Skip the MAC header.  */
413     pkt_data_ptr = pkt3;
414     pkt_len = sizeof(pkt3);
415     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
416     packet_ptr -> nx_packet_length = pkt_len - 14;
417     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
418 
419     /* Set invalid value to test destination protocol. */
420     packet_ptr -> nx_packet_destination_header = 0;
421     packet_ptr -> nx_packet_option_state = FRAGMENT_HEADER;
422 
423     /* Directly receive the packet.  */
424     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
425 
426     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
427 
428     /* Check status */
429     if(status)
430     {
431         error_counter++;
432     }
433     else
434     {
435         nx_packet_release(ping_resp);
436     }
437 
438 
439 #ifndef NX_IPSEC_ENABLE
440     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
441 
442     /* Check status */
443     if(status)
444         error_counter++;
445 
446     /* Fill in the packet with data. Skip the MAC header.  */
447     pkt_data_ptr = pkt4;
448     pkt_len = sizeof(pkt4);
449     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
450     packet_ptr -> nx_packet_length = pkt_len - 14;
451     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
452 
453     /* Directly receive the packet.  */
454     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
455 
456     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
457 
458     /* Check status */
459     if(status)
460     {
461         error_counter++;
462     }
463     else
464     {
465         nx_packet_release(ping_resp);
466     }
467 
468 
469     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
470 
471     /* Check status */
472     if(status)
473         error_counter++;
474 
475     /* Fill in the packet with data. Skip the MAC header.  */
476     pkt_data_ptr = pkt5;
477     pkt_len = sizeof(pkt5);
478     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
479     packet_ptr -> nx_packet_length = pkt_len - 14;
480     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
481 
482     /* Directly receive the packet.  */
483     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
484 
485     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
486 
487     /* Check status */
488     if(status)
489     {
490         error_counter++;
491     }
492     else
493     {
494         nx_packet_release(ping_resp);
495     }
496 #endif /* NX_IPSEC_ENABLE */
497 
498 
499     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
500 
501     /* Check status */
502     if(status)
503         error_counter++;
504 
505     /* Fill in the packet with data. Skip the MAC header.  */
506     pkt_data_ptr = pkt6;
507     pkt_len = sizeof(pkt6);
508     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
509     packet_ptr -> nx_packet_length = pkt_len - 14;
510     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
511 
512     /* Disable ICMP. */
513     ip_0.nx_ip_icmpv6_packet_process = NX_NULL;
514 
515     /* Directly receive the packet.  */
516     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
517 
518     /* Disable ICMP. */
519     ip_0.nx_ip_icmpv6_packet_process = _nx_icmpv6_packet_process;
520 
521     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
522 
523     /* Check status */
524     if(status)
525     {
526         error_counter++;
527     }
528     else
529     {
530         nx_packet_release(ping_resp);
531     }
532 
533 
534     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
535 
536     /* Check status */
537     if(status)
538         error_counter++;
539 
540     /* Fill in the packet with data. Skip the MAC header.  */
541     pkt_data_ptr = pkt7;
542     pkt_len = sizeof(pkt7);
543     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
544     packet_ptr -> nx_packet_length = pkt_len - 14;
545     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
546 
547     /* Disable ICMP. */
548     ip_0.nx_ip_icmp_packet_receive = NX_NULL;
549 
550     /* Directly receive the packet.  */
551     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
552 
553     /* Disable ICMP. */
554     ip_0.nx_ip_icmp_packet_receive = _nx_icmp_packet_receive;
555 
556     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
557 
558     /* Check status */
559     if(status)
560     {
561         error_counter++;
562     }
563     else
564     {
565         nx_packet_release(ping_resp);
566     }
567 
568 
569     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
570 
571     /* Check status */
572     if(status)
573         error_counter++;
574 
575     /* Fill in the packet with data. Skip the MAC header.  */
576     pkt_data_ptr = pkt8;
577     pkt_len = sizeof(pkt8);
578     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
579     packet_ptr -> nx_packet_length = pkt_len - 14;
580     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
581 
582     /* Directly receive the packet.  */
583     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
584 
585     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
586 
587     /* Check status */
588     if(status)
589     {
590         error_counter++;
591     }
592     else
593     {
594         nx_packet_release(ping_resp);
595     }
596 
597 
598     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
599 
600     /* Check status */
601     if(status)
602         error_counter++;
603 
604     /* Fill in the packet with data. Skip the MAC header.  */
605     pkt_data_ptr = pkt9;
606     pkt_len = sizeof(pkt9);
607     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
608     packet_ptr -> nx_packet_length = pkt_len - 14;
609     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
610 
611     /* Directly receive the packet.  */
612     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
613 
614     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
615 
616     /* Check status */
617     if(status)
618     {
619         error_counter++;
620     }
621     else
622     {
623         nx_packet_release(ping_resp);
624     }
625 
626 
627     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
628 
629     /* Check status */
630     if(status)
631         error_counter++;
632 
633     /* Fill in the packet with data. Skip the MAC header.  */
634     pkt_data_ptr = pkt10;
635     pkt_len = sizeof(pkt10);
636     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
637     packet_ptr -> nx_packet_length = pkt_len - 14;
638     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
639 
640     /* Directly receive the packet.  */
641     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
642 
643     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
644 
645     /* Check status */
646     if(status)
647     {
648         error_counter++;
649     }
650     else
651     {
652         nx_packet_release(ping_resp);
653     }
654 
655 
656     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
657 
658     /* Check status */
659     if(status)
660         error_counter++;
661 
662     /* Fill in the packet with data. Skip the MAC header.  */
663     pkt_data_ptr = pkt11;
664     pkt_len = sizeof(pkt11);
665     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
666     packet_ptr -> nx_packet_length = pkt_len - 14;
667     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
668 
669     /* Directly receive the packet.  */
670     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
671 
672     status = nx_icmp_ping(&ip_0, IP_ADDRESS(127, 0, 0, 1), "", 0, &ping_resp, NX_IP_PERIODIC_RATE);
673 
674     /* Check status */
675     if(status)
676     {
677         error_counter++;
678     }
679     else
680     {
681         nx_packet_release(ping_resp);
682     }
683 
684 
685     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
686 
687     /* Check status */
688     if(status)
689         error_counter++;
690 
691     /* Fill in the packet with data. Skip the MAC header.  */
692     pkt_data_ptr = pkt12;
693     pkt_len = sizeof(pkt12);
694     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
695     packet_ptr -> nx_packet_length = pkt_len - 14;
696     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
697 
698     /* Directly receive the packet.  */
699     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
700 
701 
702     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
703 
704     /* Check status */
705     if(status)
706         error_counter++;
707 
708     /* Fill in the packet with data. Skip the MAC header.  */
709     pkt_data_ptr = pkt13;
710     pkt_len = sizeof(pkt13);
711     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
712     packet_ptr -> nx_packet_length = pkt_len - 14;
713     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
714 
715     /* Directly receive the packet.  */
716     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
717 
718 
719     status = nx_packet_allocate(&pool_0, &packet_ptr, NX_PHYSICAL_HEADER, NX_WAIT_FOREVER);
720 
721     /* Check status */
722     if(status)
723         error_counter++;
724 
725     /* Fill in the packet with data. Skip the MAC header.  */
726     pkt_data_ptr = pkt14;
727     pkt_len = sizeof(pkt14);
728     memcpy(packet_ptr -> nx_packet_prepend_ptr, &pkt_data_ptr[14], pkt_len - 14);
729     packet_ptr -> nx_packet_length = pkt_len - 14;
730     packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_prepend_ptr + packet_ptr -> nx_packet_length;
731 
732     /* Directly receive the packet.  */
733     _nx_ip_packet_deferred_receive(&ip_0, packet_ptr);
734 
735     /* Check the error.  */
736     if(error_counter)
737     {
738         printf("ERROR!\n");
739         test_control_return(1);
740     }
741     else
742     {
743         printf("SUCCESS!\n");
744         test_control_return(0);
745     }
746 }
747 
748 #else
749 
750 #ifdef CTEST
test_application_define(void * first_unused_memory)751 VOID test_application_define(void *first_unused_memory)
752 #else
753 void           netx_ip_abnormal_packet_test_application_define(void *first_unused_memory)
754 #endif
755 {
756 
757     /* Print out test information banner.  */
758     printf("NetX Test:   IP Abnormal Packet Test...................................N/A\n");
759     test_control_return(3);
760 
761 }
762 #endif /* FEATURE_NX_IPV6 */
763