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 Protocol (IP)                                              */
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 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_ip_raw_packet_source_send                       PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function sends a raw IP packet through the specified IP        */
45 /*    source.                                                             */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                Pointer to IP control block   */
50 /*    packet_ptr                            Pointer to packet to send     */
51 /*    destination_ip                        Destination IP address        */
52 /*    address_index                         Index to the IPv6 address     */
53 /*    type_of_service                       Type of service for packet    */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    status                                Completion status             */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    nx_ip_packet_send                     Core IP packet send service   */
62 /*    nx_ip_route_find                      Find a suitable outgoing      */
63 /*                                            interface.                  */
64 /*    tx_mutex_get                          Get protection mutex          */
65 /*    tx_mutex_put                          Put protection mutex          */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    Application                                                         */
70 /*                                                                        */
71 /*  RELEASE HISTORY                                                       */
72 /*                                                                        */
73 /*    DATE              NAME                      DESCRIPTION             */
74 /*                                                                        */
75 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
76 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
77 /*                                            resulting in version 6.1    */
78 /*                                                                        */
79 /**************************************************************************/
_nx_ip_raw_packet_source_send(NX_IP * ip_ptr,NX_PACKET * packet_ptr,ULONG destination_ip,UINT address_index,ULONG type_of_service)80 UINT  _nx_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr,
81                                     ULONG destination_ip, UINT address_index, ULONG type_of_service)
82 {
83 
84 #ifndef NX_DISABLE_IPV4
85 ULONG next_hop_address;
86 
87     /* Add debug information. */
88     NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
89 
90     /* Store interface information into the packet structure. */
91     packet_ptr -> nx_packet_address.nx_packet_interface_ptr = &(ip_ptr -> nx_ip_interface[address_index]);
92 
93     /* Get mutex protection.  */
94     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
95 
96     /* Figure out a suitable outgoing interface. */
97     _nx_ip_route_find(ip_ptr, destination_ip, &packet_ptr -> nx_packet_address.nx_packet_interface_ptr, &next_hop_address);
98 
99     /* If trace is enabled, insert this event into the trace buffer.  */
100     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_RAW_PACKET_SEND, ip_ptr, packet_ptr, destination_ip, type_of_service, NX_TRACE_IP_EVENTS, 0, 0);
101 
102     /* Yes, raw packet sending and receiving is enabled send packet!  */
103     /*lint -e{644} suppress variable might not be initialized, since "next_hop_address" was initialized in _nx_ip_route_find. */
104     _nx_ip_packet_send(ip_ptr, packet_ptr, destination_ip, type_of_service, NX_IP_TIME_TO_LIVE, NX_IP_RAW, NX_FRAGMENT_OKAY, next_hop_address);
105 
106     /* Release mutex protection.  */
107     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
108 
109     /* Return a successful status!  */
110     return(NX_SUCCESS);
111 #else /* NX_DISABLE_IPV4  */
112     NX_PARAMETER_NOT_USED(ip_ptr);
113     NX_PARAMETER_NOT_USED(packet_ptr);
114     NX_PARAMETER_NOT_USED(destination_ip);
115     NX_PARAMETER_NOT_USED(address_index);
116     NX_PARAMETER_NOT_USED(type_of_service);
117 
118     return(NX_NOT_SUPPORTED);
119 #endif /* !NX_DISABLE_IPV4  */
120 }
121 
122