Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_icmp.h"
#include "nx_packet.h"
#include "nx_ip.h"
#include "tx_thread.h"
#include "nx_icmpv6.h"
#include "nx_ipv6.h"
#include "nx_ipsec.h"
...
Files
loading...
SourceVuSTM32 Libraries and Samplesnetxduocommon/src/nx_icmp_interface_ping6.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Internet Control Message Protocol (ICMP) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_icmp.h" #include "nx_packet.h" #include "nx_ip.h" #include "tx_thread.h" #include "nx_icmpv6.h" #include "nx_ipv6.h" 7 includes #ifdef FEATURE_NX_IPV6 #ifdef NX_IPSEC_ENABLE #include "nx_ipsec.h" #endif /* NX_IPSEC_ENABLE */ /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_icmp_interface_ping6 PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function handles ICMPv6 ping requests and calls the associated */ /* network driver to send it out on the network. The function will */ /* then suspend for the specified time waiting for the ICMP ping */ /* response. */ /* */ /* INPUT */ /* */ /* ip_ptr Pointer to IP instance */ /* dest_ip_address IPv6 address to ping */ /* data_ptr Pointer to user data to */ /* include in ping packet */ /* data_size Size of user data */ /* address_index Source IPv6 address to use */ /* response_ptr Pointer to response packet */ /* wait_option Time out on packet allocate */ /* and sending packet */ /* */ /* OUTPUT */ /* */ /* status Actual completion status */ /* NX_OVERFLOW Data exceeds packet payload */ /* NX_IPSEC_REJECTED IPSec check failed */ /* NX_NO_RESPONSE No response to ping message */ /* */ /* CALLS */ /* */ /* _nx_icmp_checksum_compute Computes ICMP checksum */ /* _nx_ipv6_packet_send Send IPv6 packet function */ /* _nx_packet_allocate Allocate a packet for the */ /* ICMP ping request */ /* _nx_packet_release Release packet on error */ /* tx_mutex_get Obtain protection mutex */ /* tx_mutex_put Release protection mutex */ /* _tx_thread_system_suspend Suspend thread */ /* _tx_thread_system_preempt_check Check for preemption */ /* */ /* CALLED BY */ /* */ /* _nx_icmp_ping6 */ /* Application Send ping on the specified */ /* interface */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ UINT _nx_icmp_interface_ping6(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, CHAR *data_ptr, ULONG data_size, NXD_IPV6_ADDRESS *ipv6_address, NX_PACKET **response_ptr, ULONG wait_option) { TX_INTERRUPT_SAVE_AREA UINT status; NX_PACKET *request_ptr; NX_ICMPV6_ECHO *echo_header_ptr; ULONG checksum; ULONG sequence; TX_THREAD *thread_ptr; #ifdef TX_ENABLE_EVENT_TRACE ULONG ip_address_lsw; #endif /* TX_ENABLE_EVENT_TRACE */ #ifdef NX_IPSEC_ENABLE VOID *sa = NX_NULL; NXD_ADDRESS src_addr; UINT ret = 0;/* ... */ #endif /* NX_IPSEC_ENABLE */ #if defined(NX_DISABLE_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE) UINT compute_checksum = 1; #endif /* defined(NX_DISABLE_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE) */ #ifdef TX_ENABLE_EVENT_TRACE ip_address_lsw = ip_address -> nxd_ip_address.v6[3]; /* If trace is enabled, insert this event into the trace buffer. */ NX_TRACE_IN_LINE_INSERT(NX_TRACE_ICMP_PING6, ip_ptr, ip_address_lsw, data_ptr, data_size, NX_TRACE_ICMP_EVENTS, 0, 0);/* ... */ #endif /* TX_ENABLE_EVENT_TRACE */ /* Clear the destination pointer. */ *response_ptr = NX_NULL; #ifdef NX_IPSEC_ENABLE src_addr.nxd_ip_version = NX_IP_VERSION_V6; COPY_IPV6_ADDRESS(ipv6_address -> nxd_ipv6_address, src_addr.nxd_ip_address.v6); /* Check if the IPsec is enabled. */ if (ip_ptr -> nx_ip_packet_egress_sa_lookup != NX_NULL) { /* Yes it is. Check for possible SA match. */ ret = ip_ptr -> nx_ip_packet_egress_sa_lookup(ip_ptr, /* IP ptr */ &src_addr, /* src_addr */ ip_address, /* dest_addr */ NX_PROTOCOL_ICMPV6, /* protocol */ 0, /* src_port */ 0, /* dest_port */ NX_NULL, &sa, (NX_ICMPV6_ECHO_REQUEST_TYPE << 8)); /* Check if the SA rules allow us to send this packet. */ if (ret == NX_IPSEC_TRAFFIC_BYPASS) { /* They do. Ok to send the ping6 packet. */ sa = NX_NULL; }if (ret == NX_IPSEC_TRAFFIC_BYPASS) { ... } else if (ret == NX_IPSEC_TRAFFIC_DROP || ret == NX_IPSEC_TRAFFIC_PENDING_IKEV2) { /* No we cannot. Set the error status and return.*/ return(NX_IPSEC_REJECTED); }else if (ret == NX_IPSEC_TRAFFIC_DROP || ret == NX_IPSEC_TRAFFIC_PENDING_IKEV2) { ... } }if (ip_ptr -> nx_ip_packet_egress_sa_lookup != NX_NULL) { ... } /* ... */ #endif /* NX_IPSEC_ENABLE */ /* Determine if the size of the data and the ICMP header is larger than the packet payload area. *//* ... */ /* Allocate a packet to place the ICMP echo request message in. */ status = _nx_packet_allocate(ip_ptr -> nx_ip_default_packet_pool, &request_ptr, NX_ICMP_PACKET + sizeof(NX_ICMPV6_ECHO), wait_option); if (status) { /* Error getting packet, so just get out! */ return(status); }if (status) { ... } /* Add debug information. */ NX_PACKET_DEBUG(__FILE__, __LINE__, request_ptr); /* Mark the packet as IPv6 */ /*lint -e{644} suppress variable might not be initialized, since "request_ptr" was initialized in _nx_packet_allocate. */ request_ptr -> nx_packet_ip_version = NX_IP_VERSION_V6; #ifdef NX_IPSEC_ENABLE request_ptr -> nx_packet_ipsec_sa_ptr = sa; /* ... */ #endif /* NX_IPSEC_ENABLE */ /* Copy the data into the packet payload area. */ status = _nx_packet_data_append(request_ptr, (VOID *)data_ptr, data_size, ip_ptr -> nx_ip_default_packet_pool, wait_option); /* Check return status. */ if (status) { /* Release the packet. */ _nx_packet_release(request_ptr); /* Error, the data area is too big for the default packet payload. */ return(NX_OVERFLOW); }if (status) { ... } /* Set the outgoing address. */ request_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr = ipv6_address; #ifndef NX_DISABLE_ICMP_INFO /* Increment the ICMP ping count. */ ip_ptr -> nx_ip_pings_sent++;/* ... */ #endif #ifdef TX_ENABLE_EVENT_TRACE /* If trace is enabled, insert this event into the trace buffer. */ /* NX_TRACE_IN_LINE_INSERT(NX_TRACE_INTERNAL_ICMP_SEND, ip_ptr, dest_ip_byte3, request_ptr, (((ULONG) NX_ICMP_ECHO_REQUEST_TYPE) << 24), NX_TRACE_INTERNAL_EVENTS, 0, 0) *//* ... */ #endif /* TX_ENABLE_EVENT_TRACE */ /* Calculate the ICMP echo request message size and store it in the packet header. *//* ... */ request_ptr -> nx_packet_length += (ULONG)sizeof(NX_ICMPV6_ECHO); /* Adjust the nx_packet_prepend_ptr for ICMP header. */ request_ptr -> nx_packet_prepend_ptr -= sizeof(NX_ICMPV6_ECHO); /* Build the ICMP request packet. */ /* Setup the pointer to the message area. */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ echo_header_ptr = (NX_ICMPV6_ECHO *)request_ptr -> nx_packet_prepend_ptr; /* Write the ICMP type into the message. Use the lower 16-bits of the IP address for the ICMP identifier. *//* ... */ echo_header_ptr -> nx_icmpv6_echo_header.nx_icmpv6_header_type = NX_ICMPV6_ECHO_REQUEST_TYPE; echo_header_ptr -> nx_icmpv6_echo_header.nx_icmpv6_header_code = 0; echo_header_ptr -> nx_icmpv6_echo_header.nx_icmpv6_header_checksum = 0; echo_header_ptr -> nx_icmpv6_echo_identifier = (USHORT)(ipv6_address -> nxd_ipv6_address[3] & NX_LOWER_16_MASK); NX_CHANGE_USHORT_ENDIAN(echo_header_ptr -> nx_icmpv6_echo_identifier); sequence = (ip_ptr -> nx_ip_icmp_sequence++ & NX_LOWER_16_MASK); echo_header_ptr -> nx_icmpv6_echo_sequence_num = (USHORT)(sequence); NX_CHANGE_USHORT_ENDIAN(echo_header_ptr -> nx_icmpv6_echo_sequence_num); #ifdef NX_DISABLE_ICMPV6_TX_CHECKSUM compute_checksum = 0; #endif /* NX_DISABLE_ICMPV6_TX_CHECKSUM */ #ifdef NX_ENABLE_INTERFACE_CAPABILITY if (ipv6_address -> nxd_ipv6_address_attached -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM) { compute_checksum = 0; }if (ipv6_address -> nxd_ipv6_address_attached -> nx_interface_capability_flag & NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM) { ... } /* ... */#endif /* NX_ENABLE_INTERFACE_CAPABILITY */ #ifdef NX_IPSEC_ENABLE if (sa != NX_NULL) { if (((NX_IPSEC_SA *)sa) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE) { compute_checksum = 1; }if (((NX_IPSEC_SA *)sa) -> nx_ipsec_sa_encryption_method != NX_CRYPTO_NONE) { ... } }if (sa != NX_NULL) { ... } /* ... */ #endif /* NX_IPSEC_ENABLE */ #if defined(NX_DISABLE_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE) if (compute_checksum) #endif /* defined(NX_DISABLE_ICMPV6_TX_CHECKSUM) || defined(NX_ENABLE_INTERFACE_CAPABILITY) || defined(NX_IPSEC_ENABLE) */ { /* Compute the checksum of the ICMP packet. */ checksum = _nx_ip_checksum_compute(request_ptr, NX_PROTOCOL_ICMPV6, (UINT)request_ptr -> nx_packet_length, ipv6_address -> nxd_ipv6_address, ip_address -> nxd_ip_address.v6); echo_header_ptr -> nx_icmpv6_echo_header.nx_icmpv6_header_checksum = (USHORT) ~checksum; /* Endian swap */ NX_CHANGE_USHORT_ENDIAN(echo_header_ptr -> nx_icmpv6_echo_header.nx_icmpv6_header_checksum); ...} #ifdef NX_ENABLE_INTERFACE_CAPABILITY else { request_ptr -> nx_packet_interface_capability_flag |= NX_INTERFACE_CAPABILITY_ICMPV6_TX_CHECKSUM; }else { ... } /* ... */#endif /* Obtain the IP internal mutex to prevent against possible suspension later in the call to IP packet send. *//* ... */ tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER); /* Disable interrupts. */ TX_DISABLE /* Temporarily disable preemption. */ _tx_thread_preempt_disable++; /* Pickup thread pointer. */ thread_ptr = _tx_thread_current_ptr; /* Determine if the request specifies suspension. */ if (wait_option) { /* Prepare for suspension of this thread. */ /* Setup cleanup routine pointer. */ thread_ptr -> tx_thread_suspend_cleanup = _nx_icmp_cleanup; thread_ptr -> tx_thread_suspend_status = NX_NO_RESPONSE; /* Setup cleanup information, i.e. this pool control block. *//* ... */ thread_ptr -> tx_thread_suspend_control_block = (void *)ip_ptr; /* Save the return packet pointer address as well. */ thread_ptr -> tx_thread_additional_suspend_info = (void *)response_ptr; /* Save the sequence number so this can be matched up with an ICMP response later. *//* ... */ thread_ptr -> tx_thread_suspend_info = sequence; /* Setup suspension list. */ if (ip_ptr -> nx_ip_icmp_ping_suspension_list) { /* This list is not NULL, add current thread to the end. */ thread_ptr -> tx_thread_suspended_next = ip_ptr -> nx_ip_icmp_ping_suspension_list; thread_ptr -> tx_thread_suspended_previous = (ip_ptr -> nx_ip_icmp_ping_suspension_list) -> tx_thread_suspended_previous; ((ip_ptr -> nx_ip_icmp_ping_suspension_list) -> tx_thread_suspended_previous) -> tx_thread_suspended_next = thread_ptr; (ip_ptr -> nx_ip_icmp_ping_suspension_list) -> tx_thread_suspended_previous = thread_ptr; }if (ip_ptr -> nx_ip_icmp_ping_suspension_list) { ... } else { /* No other threads are suspended. Setup the head pointer and just setup this threads pointers to itself. *//* ... */ ip_ptr -> nx_ip_icmp_ping_suspension_list = thread_ptr; thread_ptr -> tx_thread_suspended_next = thread_ptr; thread_ptr -> tx_thread_suspended_previous = thread_ptr; }else { ... } /* Increment the suspended thread count. */ ip_ptr -> nx_ip_icmp_ping_suspended_count++; /* Set the state to suspended. */ thread_ptr -> tx_thread_state = TX_TCP_IP; /* Set the suspending flag. */ thread_ptr -> tx_thread_suspending = TX_TRUE; /* Save the timeout value. */ thread_ptr -> tx_thread_timer.tx_timer_internal_remaining_ticks = wait_option; }if (wait_option) { ... } /* Restore interrupts. */ TX_RESTORE /* Send the ICMP packet to the IP component. */ _nx_ipv6_packet_send(ip_ptr, request_ptr, NX_PROTOCOL_ICMPV6, request_ptr -> nx_packet_length, ip_ptr -> nx_ipv6_hop_limit, ipv6_address -> nxd_ipv6_address, ip_address -> nxd_ip_address.v6); /* If wait option is requested, suspend the thread. */ if (wait_option) { /* Release the protection on the ARP list. */ tx_mutex_put(&(ip_ptr -> nx_ip_protection)); /* Call actual thread suspension routine. */ _tx_thread_system_suspend(thread_ptr); if (thread_ptr -> tx_thread_suspend_status == NX_SUCCESS) { /* Add debug information. */ NX_PACKET_DEBUG(__FILE__, __LINE__, *response_ptr); }if (thread_ptr -> tx_thread_suspend_status == NX_SUCCESS) { ... } /* Return the status from the thread control block. */ return(thread_ptr -> tx_thread_suspend_status); }if (wait_option) { ... } else { /* Disable interrupts. */ TX_DISABLE /* Release preemption disable. */ _tx_thread_preempt_disable--; /* Restore interrupts. */ TX_RESTORE /* Release the protection mutex. */ tx_mutex_put(&(ip_ptr -> nx_ip_protection)); /* Check for preemption. */ _tx_thread_system_preempt_check(); /* Immediate return, return error completion. */ return(NX_NO_RESPONSE); }else { ... } }_nx_icmp_interface_ping6 (NX_IP *ip_ptr, NXD_ADDRESS *ip_address, CHAR *data_ptr, ULONG data_size, NXD_IPV6_ADDRESS *ipv6_address, NX_PACKET **response_ptr, ULONG wait_option) { ... } /* ... */ #endif /* FEATURE_NX_IPV6 */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.