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_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 /* type_of_service Type of service for packet */
59 /* */
60 /* OUTPUT */
61 /* */
62 /* status Completion status */
63 /* */
64 /* CALLS */
65 /* */
66 /* _nx_ip_raw_packet_send Actual IP raw packet send */
67 /* function */
68 /* */
69 /* CALLED BY */
70 /* */
71 /* Application */
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_ip_raw_packet_send(NX_IP * ip_ptr,NX_PACKET ** packet_ptr_ptr,ULONG destination_ip,ULONG type_of_service)82 UINT _nxe_ip_raw_packet_send(NX_IP *ip_ptr, NX_PACKET **packet_ptr_ptr,
83 ULONG destination_ip, ULONG type_of_service)
84 {
85
86 #ifndef NX_DISABLE_IPV4
87 UINT status;
88 NX_PACKET *packet_ptr;
89
90
91 /* Setup packet pointer. */
92 packet_ptr = *packet_ptr_ptr;
93
94 /* Check for invalid input pointers. */
95 /*lint -e{923} suppress cast of ULONG to pointer. */
96 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) ||
97 (packet_ptr == NX_NULL) || (packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_ALLOCATED)))
98 {
99 return(NX_PTR_ERROR);
100 }
101
102 /* Check to see if IP raw packet processing is enabled. */
103 if (!ip_ptr -> nx_ip_raw_ip_processing)
104 {
105 return(NX_NOT_ENABLED);
106 }
107
108 /* Check for invalid IP address. */
109 if (!destination_ip)
110 {
111 return(NX_IP_ADDRESS_ERROR);
112 }
113
114 /* Check for valid type of service. */
115 if (type_of_service & ~(NX_IP_TOS_MASK))
116 {
117 return(NX_OPTION_ERROR);
118 }
119
120 /* Check for an invalid packet prepend pointer. */
121 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
122 if ((packet_ptr -> nx_packet_prepend_ptr - sizeof(NX_IPV4_HEADER)) < packet_ptr -> nx_packet_data_start)
123 {
124 return(NX_UNDERFLOW);
125 }
126
127 /* Check for an invalid packet append pointer. */
128 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
129 if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
130 {
131 return(NX_OVERFLOW);
132 }
133
134 /* Check for appropriate caller. */
135 NX_THREADS_ONLY_CALLER_CHECKING
136
137 /* Call actual IP raw packet send function. */
138 status = _nx_ip_raw_packet_send(ip_ptr, packet_ptr, destination_ip, type_of_service);
139
140 /* Determine if the raw packet send was successful. */
141 if (status == NX_SUCCESS)
142 {
143
144 /* Yes, now clear the application's packet pointer so it can't be accidentally
145 used again by the application. This is only done when error checking is
146 enabled. */
147 *packet_ptr_ptr = NX_NULL;
148 }
149
150 /* Return completion status. */
151 return(status);
152 #else /* NX_DISABLE_IPV4 */
153 NX_PARAMETER_NOT_USED(ip_ptr);
154 NX_PARAMETER_NOT_USED(packet_ptr_ptr);
155 NX_PARAMETER_NOT_USED(destination_ip);
156 NX_PARAMETER_NOT_USED(type_of_service);
157
158 return(NX_NOT_SUPPORTED);
159 #endif /* !NX_DISABLE_IPV4 */
160 }
161
162