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_icmp.h"
30 #include "nx_ip.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _nx_icmp_ping                                       PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Yuxin Zhou, Microsoft Corporation                                   */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function finds a suitable interface and calls interface ping.  */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                Pointer to IP instance        */
50 /*    ip_address                            IP address to ping            */
51 /*    data_ptr                              User Data pointer             */
52 /*    data_size                             Size of User Data             */
53 /*    response_ptr                          Pointer to Response Packet    */
54 /*    wait_option                           Suspension option             */
55 /*                                                                        */
56 /*  OUTPUT                                                                */
57 /*                                                                        */
58 /*    None                                                                */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _nx_ip_route_find                     Find suitable interface       */
63 /*    _nx_icmp_interface_ping               Send ping packet              */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application Code                                                    */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_nx_icmp_ping(NX_IP * ip_ptr,ULONG ip_address,CHAR * data_ptr,ULONG data_size,NX_PACKET ** response_ptr,ULONG wait_option)78 UINT  _nx_icmp_ping(NX_IP *ip_ptr, ULONG ip_address,
79                     CHAR *data_ptr, ULONG data_size,
80                     NX_PACKET **response_ptr, ULONG wait_option)
81 {
82 
83 #ifndef NX_DISABLE_IPV4
84 ULONG         next_hop_address;
85 NX_INTERFACE *interface_ptr = NX_NULL;
86 
87 
88     /* Find a suitable interface for sending the ping packet. */
89     if (_nx_ip_route_find(ip_ptr, ip_address, &interface_ptr, &next_hop_address) != NX_SUCCESS)
90     {
91 
92         /* No suitable interface configured. */
93         /* Clear the destination pointer.  */
94         *response_ptr =  NX_NULL;
95 
96         /* Return the error status. */
97         return(NX_IP_ADDRESS_ERROR);
98     }
99 
100     /* Call interface ping service. */
101     /*lint -e{644} suppress variable might not be initialized, since "interface_ptr" and "next_hop_address" were initialized in _nx_ip_route_find. */
102     return(_nx_icmp_interface_ping(ip_ptr, ip_address, interface_ptr, next_hop_address,
103                                    data_ptr, data_size, response_ptr, wait_option));
104 #else /* NX_DISABLE_IPV4  */
105     NX_PARAMETER_NOT_USED(ip_ptr);
106     NX_PARAMETER_NOT_USED(ip_address);
107     NX_PARAMETER_NOT_USED(data_ptr);
108     NX_PARAMETER_NOT_USED(data_size);
109     NX_PARAMETER_NOT_USED(response_ptr);
110     NX_PARAMETER_NOT_USED(wait_option);
111 
112     return(NX_NOT_SUPPORTED);
113 #endif /* !NX_DISABLE_IPV4  */
114 }
115 
116