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 #include "nx_packet.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_ip_raw_packet_source_send 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 IP raw packet send */
51 /* function call. */
52 /* */
53 /* INPUT */
54 /* */
55 /* ip_ptr Pointer to IP control block */
56 /* packet_ptr Pointer to packet to send */
57 /* destination_ip Destination IP address */
58 /* address_index Index of IPv4 or IPv6 address */
59 /* to use as the source address*/
60 /* type_of_service Type of service for packet */
61 /* */
62 /* OUTPUT */
63 /* */
64 /* status Completion status */
65 /* */
66 /* CALLS */
67 /* */
68 /* _nx_ip_raw_packet_source_send Actual IP raw packet send */
69 /* function */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Application */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
80 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* */
83 /**************************************************************************/
_nxe_ip_raw_packet_source_send(NX_IP * ip_ptr,NX_PACKET ** packet_ptr_ptr,ULONG destination_ip,UINT address_index,ULONG type_of_service)84 UINT _nxe_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET **packet_ptr_ptr,
85 ULONG destination_ip, UINT address_index, ULONG type_of_service)
86 {
87
88 #ifndef NX_DISABLE_IPV4
89 NX_PACKET *packet_ptr;
90
91
92 /* Setup packet pointer. */
93 packet_ptr = *packet_ptr_ptr;
94
95 /* Check for invalid input pointers. */
96 /*lint -e{923} suppress cast of ULONG to pointer. */
97 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) ||
98 (packet_ptr == NX_NULL) || (packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_ALLOCATED)))
99 {
100 return(NX_PTR_ERROR);
101 }
102
103 /* Check to see if IP raw packet processing is enabled. */
104 if (!ip_ptr -> nx_ip_raw_ip_processing)
105 {
106 return(NX_NOT_ENABLED);
107 }
108
109 /* Check for invalid IP address. */
110 if (!destination_ip)
111 {
112 return(NX_IP_ADDRESS_ERROR);
113 }
114
115 /* Check for valid type of service. */
116 if (type_of_service & ~(NX_IP_TOS_MASK))
117 {
118 return(NX_OPTION_ERROR);
119 }
120
121 /* Check for an invalid packet prepend pointer. */
122 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
123 if ((packet_ptr -> nx_packet_prepend_ptr - sizeof(NX_IPV4_HEADER)) < packet_ptr -> nx_packet_data_start)
124 {
125 return(NX_UNDERFLOW);
126 }
127
128 /* Check for an invalid packet append pointer. */
129 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
130 if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
131 {
132 return(NX_OVERFLOW);
133 }
134
135
136 /* Validate the interface index. */
137 if (address_index >= NX_MAX_IP_INTERFACES)
138 {
139 return(NX_INVALID_INTERFACE);
140 }
141
142 if (!(ip_ptr -> nx_ip_interface[address_index].nx_interface_valid))
143 {
144 return(NX_INVALID_INTERFACE);
145 }
146
147
148 /* Check for appropriate caller. */
149 NX_THREADS_ONLY_CALLER_CHECKING
150
151 /* Call actual IP raw packet send function. */
152 _nx_ip_raw_packet_source_send(ip_ptr, packet_ptr, destination_ip, address_index, type_of_service);
153
154 /* Now clear the application's packet pointer so it can't be accidentally
155 used again by the application. This is only done when error checking is
156 enabled. */
157 *packet_ptr_ptr = NX_NULL;
158
159 /* Return completion status. */
160 return(NX_SUCCESS);
161 #else /* NX_DISABLE_IPV4 */
162 NX_PARAMETER_NOT_USED(ip_ptr);
163 NX_PARAMETER_NOT_USED(packet_ptr_ptr);
164 NX_PARAMETER_NOT_USED(destination_ip);
165 NX_PARAMETER_NOT_USED(address_index);
166 NX_PARAMETER_NOT_USED(type_of_service);
167
168 return(NX_NOT_SUPPORTED);
169 #endif /* !NX_DISABLE_IPV4 */
170 }
171
172