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 /** Transmission Control Protocol (TCP) */
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_tcp.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nx_tcp_socket_info_get PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function retrieves TCP information for the specified TCP */
45 /* socket. */
46 /* */
47 /* INPUT */
48 /* */
49 /* socket_ptr Pointer to the TCP socket */
50 /* tcp_packets_sent Destination for number of */
51 /* packets sent */
52 /* tcp_bytes_sent Destination for number of */
53 /* bytes sent */
54 /* tcp_packets_received Destination for number of */
55 /* packets received */
56 /* tcp_bytes_received Destination for number of */
57 /* bytes received */
58 /* tcp_retransmit_packets Destination for number of */
59 /* retransmit packets */
60 /* tcp_packets_queued Destination for number of */
61 /* receive packets queued */
62 /* tcp_checksum_errors Destination for number of */
63 /* checksum errors */
64 /* tcp_socket_state Destination for the current */
65 /* socket state */
66 /* tcp_transmit_queue_depth Destination for number of */
67 /* sockets still in transmit */
68 /* queue */
69 /* tcp_transmit_window Destination for number of */
70 /* bytes in transmit window */
71 /* tcp_receive_window Destination for number of */
72 /* bytes in receive window */
73 /* */
74 /* OUTPUT */
75 /* */
76 /* status Completion status */
77 /* */
78 /* CALLS */
79 /* */
80 /* tx_mutex_get Obtain protection */
81 /* tx_mutex_put Release protection */
82 /* */
83 /* CALLED BY */
84 /* */
85 /* Application Code */
86 /* */
87 /* RELEASE HISTORY */
88 /* */
89 /* DATE NAME DESCRIPTION */
90 /* */
91 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
92 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
93 /* resulting in version 6.1 */
94 /* */
95 /**************************************************************************/
_nx_tcp_socket_info_get(NX_TCP_SOCKET * socket_ptr,ULONG * tcp_packets_sent,ULONG * tcp_bytes_sent,ULONG * tcp_packets_received,ULONG * tcp_bytes_received,ULONG * tcp_retransmit_packets,ULONG * tcp_packets_queued,ULONG * tcp_checksum_errors,ULONG * tcp_socket_state,ULONG * tcp_transmit_queue_depth,ULONG * tcp_transmit_window,ULONG * tcp_receive_window)96 UINT _nx_tcp_socket_info_get(NX_TCP_SOCKET *socket_ptr, ULONG *tcp_packets_sent, ULONG *tcp_bytes_sent,
97 ULONG *tcp_packets_received, ULONG *tcp_bytes_received,
98 ULONG *tcp_retransmit_packets, ULONG *tcp_packets_queued,
99 ULONG *tcp_checksum_errors, ULONG *tcp_socket_state,
100 ULONG *tcp_transmit_queue_depth, ULONG *tcp_transmit_window,
101 ULONG *tcp_receive_window)
102 {
103
104 NX_IP *ip_ptr;
105
106
107 /* Setup IP pointer. */
108 ip_ptr = socket_ptr -> nx_tcp_socket_ip_ptr;
109
110 /* If trace is enabled, insert this event into the trace buffer. */
111 NX_TRACE_IN_LINE_INSERT(NX_TRACE_TCP_SOCKET_INFO_GET, ip_ptr, socket_ptr, socket_ptr -> nx_tcp_socket_packets_sent, socket_ptr -> nx_tcp_socket_bytes_received, NX_TRACE_TCP_EVENTS, 0, 0);
112
113 /* Obtain the IP mutex so we can examine the bound port. */
114 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
115
116 /* Determine if packets sent is wanted. */
117 if (tcp_packets_sent)
118 {
119
120 /* Return the number of packets sent by this socket. */
121 *tcp_packets_sent = socket_ptr -> nx_tcp_socket_packets_sent;
122 }
123
124 /* Determine if bytes sent is wanted. */
125 if (tcp_bytes_sent)
126 {
127
128 /* Return the number of bytes sent by this socket. */
129 *tcp_bytes_sent = socket_ptr -> nx_tcp_socket_bytes_sent;
130 }
131
132 /* Determine if packets received is wanted. */
133 if (tcp_packets_received)
134 {
135
136 /* Return the number of packets received by this socket. */
137 *tcp_packets_received = socket_ptr -> nx_tcp_socket_packets_received;
138 }
139
140 /* Determine if bytes received is wanted. */
141 if (tcp_bytes_received)
142 {
143
144 /* Return the number of bytes received by this socket. */
145 *tcp_bytes_received = socket_ptr -> nx_tcp_socket_bytes_received;
146 }
147
148 /* Determine if retransmit packets is wanted. */
149 if (tcp_retransmit_packets)
150 {
151
152 /* Return the number of retransmit packets by this socket. */
153 *tcp_retransmit_packets = socket_ptr -> nx_tcp_socket_retransmit_packets;
154 }
155
156 /* Determine if packets queued is wanted. */
157 if (tcp_packets_queued)
158 {
159
160 /* Return the number of packets queued by this socket. */
161 *tcp_packets_queued = socket_ptr -> nx_tcp_socket_receive_queue_count;
162 }
163
164 /* Determine if checksum errors is wanted. */
165 if (tcp_checksum_errors)
166 {
167
168 /* Return the number of checksum errors by this socket. */
169 *tcp_checksum_errors = socket_ptr -> nx_tcp_socket_checksum_errors;
170 }
171
172 /* Determine if socket state is wanted. */
173 if (tcp_socket_state)
174 {
175
176 /* Return the state this socket. */
177 *tcp_socket_state = socket_ptr -> nx_tcp_socket_state;
178 }
179
180 /* Determine if transmit queue depth is wanted. */
181 if (tcp_transmit_queue_depth)
182 {
183
184 /* Return the transmit queue depth of this socket. */
185 *tcp_transmit_queue_depth = socket_ptr -> nx_tcp_socket_transmit_sent_count;
186 }
187
188 /* Determine if transmit window size is wanted. */
189 if (tcp_transmit_window)
190 {
191
192 /* Return the transmit window size of this socket. */
193 if (socket_ptr -> nx_tcp_socket_tx_window_advertised > socket_ptr -> nx_tcp_socket_tx_window_congestion)
194 {
195 *tcp_transmit_window = socket_ptr -> nx_tcp_socket_tx_window_congestion;
196 }
197 else
198 {
199 *tcp_transmit_window = socket_ptr -> nx_tcp_socket_tx_window_advertised;
200 }
201 if (*tcp_transmit_window > socket_ptr -> nx_tcp_socket_tx_outstanding_bytes)
202 {
203 *tcp_transmit_window = *tcp_transmit_window - socket_ptr -> nx_tcp_socket_tx_outstanding_bytes;
204 }
205 else
206 {
207 *tcp_transmit_window = 0;
208 }
209 }
210
211 /* Determine if receive window size is wanted. */
212 if (tcp_receive_window)
213 {
214
215 /* Return the receive window size of this socket. */
216 *tcp_receive_window = socket_ptr -> nx_tcp_socket_rx_window_current;
217 }
218
219 /* Release protection. */
220 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
221
222 /* Return successful completion status. */
223 return(NX_SUCCESS);
224 }
225
226