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_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 ICMP*/
51 /*    ping function call.                                                 */
52 /*                                                                        */
53 /*  INPUT                                                                 */
54 /*                                                                        */
55 /*    ip_ptr                                Pointer to IP instance        */
56 /*    ip_address                            IP address to ping            */
57 /*    data_ptr                              User Data pointer             */
58 /*    data_size                             Size of User Data             */
59 /*    response_ptr                          Pointer to Response Packet    */
60 /*    wait_option                           Suspension option             */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    None                                                                */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    _nxd_icmp_ping                        Actual ICMP ping function     */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application Code                                                    */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
79 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*                                                                        */
82 /**************************************************************************/
_nxde_icmp_ping(NX_IP * ip_ptr,NXD_ADDRESS * ip_address,CHAR * data_ptr,ULONG data_size,NX_PACKET ** response_ptr,ULONG wait_option)83 UINT  _nxde_icmp_ping(NX_IP *ip_ptr, NXD_ADDRESS *ip_address,
84                       CHAR *data_ptr, ULONG data_size,
85                       NX_PACKET **response_ptr, ULONG wait_option)
86 {
87 
88 UINT status;
89 
90 
91     /* Check for invalid input pointers.  */
92     if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (response_ptr == NX_NULL))
93     {
94         return(NX_PTR_ERROR);
95     }
96 
97     /* Check for invalid IP address.  */
98     if (ip_address == NX_NULL)
99     {
100         return(NX_IP_ADDRESS_ERROR);
101     }
102 
103     /* Check for invalid version. */
104     if ((ip_address -> nxd_ip_version != NX_IP_VERSION_V4) &&
105         (ip_address -> nxd_ip_version != NX_IP_VERSION_V6))
106     {
107 
108         return(NX_IP_ADDRESS_ERROR);
109     }
110 
111 #ifndef NX_DISABLE_IPV4
112     /* Check to see if ICMP is enabled.  */
113     /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment:  */
114     /*lint -e{923} suppress cast of pointer to ULONG.  */
115     if ((ip_address -> nxd_ip_version == NX_IP_VERSION_V4) &&
116         ((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv4_packet_process == NX_NULL))
117     {
118 
119         return(NX_NOT_ENABLED);
120     }
121 #endif /* !NX_DISABLE_IPV4  */
122 
123 #ifdef FEATURE_NX_IPV6
124 
125     if (ip_address -> nxd_ip_version == NX_IP_VERSION_V6)
126     {
127 
128         /* Cast the function pointer into a ULONG. Since this is exactly what we wish to do, disable the lint warning with the following comment:  */
129         /*lint -e{923} suppress cast of pointer to ULONG.  */
130         if (((ALIGN_TYPE)ip_ptr -> nx_ip_icmpv6_packet_process == NX_NULL) ||
131             ((ALIGN_TYPE)ip_ptr -> nx_ipv6_packet_receive == NX_NULL))
132         {
133 
134             return(NX_NOT_ENABLED);
135         }
136     }
137 
138 #endif /* FEATURE_NX_IPV6 */
139 
140     /* Check for appropriate caller.  */
141     NX_THREADS_ONLY_CALLER_CHECKING
142 
143     /* Call actual ICMP ping function.  */
144     status =  _nxd_icmp_ping(ip_ptr, ip_address, data_ptr, data_size,
145                              response_ptr, wait_option);
146 
147     /* Return completion status.  */
148     return(status);
149 }
150 
151