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 /*    _nxe_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 ICMP ping function call.     */
51 /*                                                                        */
52 /*  INPUT                                                                 */
53 /*                                                                        */
54 /*    ip_ptr                                Pointer to IP instance        */
55 /*    ip_address                            IP address to ping            */
56 /*    data_ptr                              User Data pointer             */
57 /*    data_size                             Size of User Data             */
58 /*    response_ptr                          Pointer to Response Packet    */
59 /*    wait_option                           Suspension option             */
60 /*                                                                        */
61 /*  OUTPUT                                                                */
62 /*                                                                        */
63 /*    None                                                                */
64 /*                                                                        */
65 /*  CALLS                                                                 */
66 /*                                                                        */
67 /*    _nx_icmp_ping                         Actual ICMP ping function     */
68 /*                                                                        */
69 /*  CALLED BY                                                             */
70 /*                                                                        */
71 /*    Application Code                                                    */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
78 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
79 /*                                            resulting in version 6.1    */
80 /*                                                                        */
81 /**************************************************************************/
_nxe_icmp_ping(NX_IP * ip_ptr,ULONG ip_address,CHAR * data_ptr,ULONG data_size,NX_PACKET ** response_ptr,ULONG wait_option)82 UINT  _nxe_icmp_ping(NX_IP *ip_ptr, ULONG ip_address,
83                      CHAR *data_ptr, ULONG data_size,
84                      NX_PACKET **response_ptr, ULONG wait_option)
85 {
86 
87 #ifndef NX_DISABLE_IPV4
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)
99     {
100         return(NX_IP_ADDRESS_ERROR);
101     }
102 
103     /* Check to see if ICMP is enabled.  */
104     if (!ip_ptr -> nx_ip_icmp_packet_receive)
105     {
106         return(NX_NOT_ENABLED);
107     }
108 
109     /* Check for appropriate caller.  */
110     NX_THREADS_ONLY_CALLER_CHECKING
111 
112     /* Call actual ICMP ping function.  */
113     status =  _nx_icmp_ping(ip_ptr, ip_address, data_ptr, data_size,
114                             response_ptr, wait_option);
115 
116     /* Return completion status.  */
117     return(status);
118 #else /* NX_DISABLE_IPV4  */
119     NX_PARAMETER_NOT_USED(ip_ptr);
120     NX_PARAMETER_NOT_USED(ip_address);
121     NX_PARAMETER_NOT_USED(data_ptr);
122     NX_PARAMETER_NOT_USED(data_size);
123     NX_PARAMETER_NOT_USED(response_ptr);
124     NX_PARAMETER_NOT_USED(wait_option);
125 
126     return(NX_NOT_SUPPORTED);
127 #endif /* !NX_DISABLE_IPV4  */
128 }
129 
130