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 for IPv6 (ICMPv6)                 */
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_icmpv6.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _nxd_icmp_source_ping                               PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Yuxin Zhou, Microsoft Corporation                                   */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    Depending on the destination IP address, this function performs     */
46 /*    ICMP ping or ICMPv6 ping. using specified source address.           */
47 /*    For ICMPv6 ping, the sender address is set to the IPv6 indexed      */
48 /*    by address_index.  The parameter address_index is ignored for       */
49 /*    IPv4 ping operations.                                               */
50 /*                                                                        */
51 /*  INPUT                                                                 */
52 /*                                                                        */
53 /*    ip_ptr                                Pointer to IP instance        */
54 /*    ip_address                            IP address to ping            */
55 /*    address_index                         Index to the IPv6 address     */
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 /*    NX_SUCCESS                            Successful completion         */
64 /*    NX_NOT_SUPPORTED                      IPv6 or ICMP not enabled      */
65 /*    status                                Actual completion status      */
66 /*                                                                        */
67 /*  CALLS                                                                 */
68 /*                                                                        */
69 /*    _nx_ip_route_find                     Find suitable interface       */
70 /*    _nx_icmp_interface_ping               IPv4 ICMP ping routine.       */
71 /*    _nx_icmp_interface_ping6              IPv6 ICMP ping routine.       */
72 /*                                                                        */
73 /*  CALLED BY                                                             */
74 /*                                                                        */
75 /*    Application Code                                                    */
76 /*                                                                        */
77 /*  RELEASE HISTORY                                                       */
78 /*                                                                        */
79 /*    DATE              NAME                      DESCRIPTION             */
80 /*                                                                        */
81 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
82 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
83 /*                                            resulting in version 6.1    */
84 /*                                                                        */
85 /**************************************************************************/
_nxd_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)86 UINT  _nxd_icmp_source_ping(NX_IP *ip_ptr, NXD_ADDRESS *ip_address, UINT address_index,
87                             CHAR *data_ptr, ULONG data_size,
88                             NX_PACKET **response_ptr, ULONG wait_option)
89 {
90 
91 UINT          status = NX_NOT_SUPPORTED;
92 #ifndef NX_DISABLE_IPV4
93 ULONG         next_hop_address;
94 NX_INTERFACE *interface_ptr;
95 #endif /* !NX_DISABLE_IPV4  */
96 
97 #ifndef NX_DISABLE_IPV4
98     if (ip_address -> nxd_ip_version == NX_IP_VERSION_V4)
99     {
100 
101         /* Set the outgoing interface. */
102         interface_ptr = &ip_ptr -> nx_ip_interface[address_index];
103 
104         /* Find the next hop address. . */
105         _nx_ip_route_find(ip_ptr, ip_address -> nxd_ip_address.v4, &interface_ptr, &next_hop_address);
106 
107         /*lint -e{644} suppress variable might not be initialized, since "next_hop_address" was initialized in _nx_ip_route_find. */
108         status = _nx_icmp_interface_ping(ip_ptr, ip_address -> nxd_ip_address.v4, interface_ptr, next_hop_address,
109                                          data_ptr, data_size, response_ptr, wait_option);
110     }
111 #endif /* !NX_DISABLE_IPV4  */
112 
113 #ifdef FEATURE_NX_IPV6
114     if (ip_address -> nxd_ip_version == NX_IP_VERSION_V6)
115     {
116 
117         status = _nx_icmp_interface_ping6(ip_ptr, ip_address, data_ptr, data_size,
118                                           &ip_ptr -> nx_ipv6_address[address_index], response_ptr, wait_option);
119     }
120 #endif /* FEATURE_NX_IPV6 */
121 
122     return(status);
123 }
124 
125