1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** NetX Component */
17 /** */
18 /** Internet Control Message Protocol (ICMP) */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define NX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "nx_api.h"
29 #include "nx_ip.h"
30 #include "nx_icmp.h"
31
32
33 /* Bring in externs for caller checking code. */
34
35 NX_CALLER_CHECKING_EXTERNS
36
37
38 /**************************************************************************/
39 /* */
40 /* FUNCTION RELEASE */
41 /* */
42 /* _nxde_icmp_source_ping PORTABLE C */
43 /* 6.1 */
44 /* AUTHOR */
45 /* */
46 /* Yuxin Zhou, Microsoft Corporation */
47 /* */
48 /* DESCRIPTION */
49 /* */
50 /* This function checks for errors in the dual stack (IPv4 or IPv6 */
51 /* ICMP ping service. */
52 /* */
53 /* INPUT */
54 /* */
55 /* ip_ptr Pointer to IP instance */
56 /* ip_address IP address to ping */
57 /* address_index Index of IPv4 or IPv6 address */
58 /* to use as the source address*/
59 /* data_ptr User Data pointer */
60 /* data_size Size of User Data */
61 /* response_ptr Pointer to Response Packet */
62 /* wait_option Suspension option */
63 /* */
64 /* OUTPUT */
65 /* */
66 /* None */
67 /* */
68 /* CALLS */
69 /* */
70 /* _nxd_icmp_source_ping Actual ICMP ping function */
71 /* */
72 /* CALLED BY */
73 /* */
74 /* Application Code */
75 /* */
76 /* RELEASE HISTORY */
77 /* */
78 /* DATE NAME DESCRIPTION */
79 /* */
80 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
81 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
82 /* resulting in version 6.1 */
83 /* */
84 /**************************************************************************/
_nxde_icmp_source_ping(NX_IP * ip_ptr,NXD_ADDRESS * ip_address,UINT address_index,CHAR * data_ptr,ULONG data_size,NX_PACKET ** response_ptr,ULONG wait_option)85 UINT _nxde_icmp_source_ping(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, UINT address_index,
86 CHAR *data_ptr, ULONG data_size,
87 NX_PACKET **response_ptr, ULONG wait_option)
88 {
89
90 UINT status;
91
92
93 /* Check for invalid input pointers. */
94 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (response_ptr == NX_NULL))
95 {
96 return(NX_PTR_ERROR);
97 }
98
99 /* Check for invalid IP address. */
100 if (ip_address == NX_NULL)
101 {
102 return(NX_IP_ADDRESS_ERROR);
103 }
104
105 /* Check for invalid version. */
106 if ((ip_address -> nxd_ip_version != NX_IP_VERSION_V4) &&
107 (ip_address -> nxd_ip_version != NX_IP_VERSION_V6))
108 {
109
110 return(NX_IP_ADDRESS_ERROR);
111 }
112
113 #ifndef NX_DISABLE_IPV4
114 /* Check to see if ICMP is enabled. */
115 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V4)
116 {
117 if (address_index >= NX_MAX_IP_INTERFACES)
118 {
119 return(NX_INVALID_INTERFACE);
120 }
121
122
123 /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment: */
124 /*lint -e{923} suppress cast of pointer to ULONG. */
125 if ((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv4_packet_process == NX_NULL)
126 {
127
128 return(NX_NOT_ENABLED);
129 }
130 }
131 #endif /* NX_DISABLE_IPV4 */
132
133 #ifdef FEATURE_NX_IPV6
134 if (ip_address -> nxd_ip_version == NX_IP_VERSION_V6)
135 {
136 if ((address_index >= (NX_MAX_IPV6_ADDRESSES + NX_LOOPBACK_IPV6_ENABLED)) ||
137 (ip_ptr -> nx_ipv6_address[address_index].nxd_ipv6_address_attached == NX_NULL) ||
138 (ip_ptr -> nx_ipv6_address[address_index].nxd_ipv6_address_valid == NX_FALSE))
139 {
140 return(NX_INVALID_INTERFACE);
141 }
142
143 /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment: */
144 /*lint -e{923} suppress cast of pointer to ULONG. */
145 if (((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv6_packet_process == NX_NULL) ||
146 ((ALIGN_TYPE)ip_ptr -> nx_ipv6_packet_receive == NX_NULL))
147 {
148
149 return(NX_NOT_ENABLED);
150 }
151 }
152 #endif /* FEATURE_NX_IPV6 */
153
154 /* Check for appropriate caller. */
155 NX_THREADS_ONLY_CALLER_CHECKING
156
157 /* Call actual ICMP ping function. */
158 status = _nxd_icmp_source_ping(ip_ptr, ip_address, address_index, data_ptr, data_size,
159 response_ptr, wait_option);
160
161 /* Return completion status. */
162 return(status);
163 }
164
165