1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Component */
16 /** */
17 /** Internet Protocol (IP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_ip.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_ip_info_get PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Yuxin Zhou, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function retrieves information about the specified IP */
44 /* instance. */
45 /* */
46 /* INPUT */
47 /* */
48 /* ip_ptr Pointer to IP instance */
49 /* ip_total_packets_sent Destination for number of */
50 /* packets sent */
51 /* ip_total_bytes_sent Destination for number of */
52 /* bytes sent */
53 /* ip_total_packets_received Destination for number of */
54 /* packets received */
55 /* ip_total_bytes_received Destination for number of */
56 /* bytes received */
57 /* ip_invalid_packets Destination for number of */
58 /* invalid packets */
59 /* ip_receive_packets_dropped Destination for number of */
60 /* packets dropped */
61 /* ip_receive_checksum_errors Destination for number of */
62 /* checksum errors */
63 /* ip_send_packets_dropped Destination for number of */
64 /* send packets dropped */
65 /* ip_total_fragments_sent Destination for number of */
66 /* fragments sent */
67 /* ip_total_fragments_received Destination for number of */
68 /* fragments received */
69 /* */
70 /* OUTPUT */
71 /* */
72 /* status Completion status */
73 /* */
74 /* CALLS */
75 /* */
76 /* tx_mutex_get Obtain protection mutex */
77 /* tx_mutex_put Release protection mutex */
78 /* */
79 /* CALLED BY */
80 /* */
81 /* Application */
82 /* */
83 /* RELEASE HISTORY */
84 /* */
85 /* DATE NAME DESCRIPTION */
86 /* */
87 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
88 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
89 /* resulting in version 6.1 */
90 /* */
91 /**************************************************************************/
_nx_ip_info_get(NX_IP * ip_ptr,ULONG * ip_total_packets_sent,ULONG * ip_total_bytes_sent,ULONG * ip_total_packets_received,ULONG * ip_total_bytes_received,ULONG * ip_invalid_packets,ULONG * ip_receive_packets_dropped,ULONG * ip_receive_checksum_errors,ULONG * ip_send_packets_dropped,ULONG * ip_total_fragments_sent,ULONG * ip_total_fragments_received)92 UINT _nx_ip_info_get(NX_IP *ip_ptr, ULONG *ip_total_packets_sent, ULONG *ip_total_bytes_sent,
93 ULONG *ip_total_packets_received, ULONG *ip_total_bytes_received,
94 ULONG *ip_invalid_packets, ULONG *ip_receive_packets_dropped,
95 ULONG *ip_receive_checksum_errors, ULONG *ip_send_packets_dropped,
96 ULONG *ip_total_fragments_sent, ULONG *ip_total_fragments_received)
97 {
98
99 /* If trace is enabled, insert this event into the trace buffer. */
100 NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_INFO_GET, ip_ptr, ip_ptr -> nx_ip_total_bytes_sent, ip_ptr -> nx_ip_total_bytes_received, ip_ptr -> nx_ip_receive_packets_dropped, NX_TRACE_IP_EVENTS, 0, 0);
101
102 /* Obtain protection on this IP instance. */
103 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
104
105 /* Determine if IP total packets sent is wanted. */
106 if (ip_total_packets_sent)
107 {
108
109 /* Return the number of IP total packets sent by this IP instance. */
110 *ip_total_packets_sent = ip_ptr -> nx_ip_total_packets_sent;
111 }
112
113 /* Determine if IP total bytes sent is wanted. */
114 if (ip_total_bytes_sent)
115 {
116
117 /* Return the number of IP total bytes sent by this IP instance. */
118 *ip_total_bytes_sent = ip_ptr -> nx_ip_total_bytes_sent;
119 }
120
121 /* Determine if IP total packets received is wanted. */
122 if (ip_total_packets_received)
123 {
124
125 /* Return the number of IP total packets received by this IP instance. */
126 *ip_total_packets_received = ip_ptr -> nx_ip_total_packets_received;
127 }
128
129 /* Determine if IP total bytes received is wanted. */
130 if (ip_total_bytes_received)
131 {
132
133 /* Return the number of IP total bytes received by this IP instance. */
134 *ip_total_bytes_received = ip_ptr -> nx_ip_total_bytes_received;
135 }
136
137 /* Determine if IP invalid packets is wanted. */
138 if (ip_invalid_packets)
139 {
140
141 /* Return the number of IP invalid packets received by this IP instance. */
142 *ip_invalid_packets = ip_ptr -> nx_ip_invalid_packets;
143 }
144
145 /* Determine if IP receive packets dropped is wanted. */
146 if (ip_receive_packets_dropped)
147 {
148
149 /* Return the number of IP receive packets dropped by this IP instance. */
150 *ip_receive_packets_dropped = ip_ptr -> nx_ip_receive_packets_dropped;
151 }
152
153 /* Determine if IP receive checksum errors is wanted. */
154 if (ip_receive_checksum_errors)
155 {
156
157 /* Return the number of IP receive checksum errors by this IP instance. */
158 *ip_receive_checksum_errors = ip_ptr -> nx_ip_receive_checksum_errors;
159 }
160
161 /* Determine if IP send packets dropped is wanted. */
162 if (ip_send_packets_dropped)
163 {
164
165 /* Return the number of IP send packets dropped by this IP instance. */
166 *ip_send_packets_dropped = ip_ptr -> nx_ip_send_packets_dropped;
167 }
168
169 #ifndef NX_DISABLE_FRAGMENTATION
170 /* Determine if IP total fragments sent is wanted. */
171 if (ip_total_fragments_sent)
172 {
173
174 /* Return the number of IP total fragments sent by this IP instance. */
175 *ip_total_fragments_sent = ip_ptr -> nx_ip_total_fragments_sent;
176 }
177
178 /* Determine if IP total fragments received is wanted. */
179 if (ip_total_fragments_received)
180 {
181
182 /* Return the number of IP total fragments received by this IP instance. */
183 *ip_total_fragments_received = ip_ptr -> nx_ip_total_fragments_received;
184 }
185 #else /* NX_DISABLE_FRAGMENTATION */
186 /* Set IP Total Framgnets Sent to zero */
187 if (ip_total_fragments_sent)
188 {
189
190 *ip_total_fragments_sent = 0;
191 }
192
193 /* Set IP Total Framgnets Received to zero */
194 if (ip_total_fragments_received)
195 {
196
197 *ip_total_fragments_received = 0;
198 }
199
200 #endif /* NX_DISABLE_FRAGMENTATION */
201
202 /* Release the protection. */
203 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
204
205 /* Return success to the caller. */
206 return(NX_SUCCESS);
207 }
208
209