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 /**   Transmission Control Protocol (TCP)                                 */
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_tcp.h"
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nx_tcp_info_get                                    PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function retrieves TCP information for the specified IP        */
44 /*    instance.                                                           */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    ip_ptr                                Pointer to the IP instance    */
49 /*    tcp_packets_sent                      Destination for number of     */
50 /*                                            packets sent                */
51 /*    tcp_bytes_sent                        Destination for number of     */
52 /*                                            bytes sent                  */
53 /*    tcp_packets_received                  Destination for number of     */
54 /*                                            packets received            */
55 /*    tcp_bytes_received                    Destination for number of     */
56 /*                                            bytes received              */
57 /*    tcp_invalid_packets                   Destination for number of     */
58 /*                                            invalid packets             */
59 /*    tcp_receive_packets_dropped           Destination for number of     */
60 /*                                            receive packets dropped     */
61 /*    tcp_checksum_errors                   Destination for number of     */
62 /*                                            checksum errors             */
63 /*    tcp_connections                       Destination for number of     */
64 /*                                            connections                 */
65 /*    tcp_disconnections                    Destination for number of     */
66 /*                                            disconnections              */
67 /*    tcp_connections_dropped               Destination for number of     */
68 /*                                            connections dropped         */
69 /*    tcp_retransmit_packets                Destination for number of     */
70 /*                                            retransmit packets          */
71 /*                                                                        */
72 /*  OUTPUT                                                                */
73 /*                                                                        */
74 /*    status                                Completion status             */
75 /*                                                                        */
76 /*  CALLS                                                                 */
77 /*                                                                        */
78 /*    tx_mutex_get                          Obtain protection             */
79 /*    tx_mutex_put                          Release protection            */
80 /*                                                                        */
81 /*  CALLED BY                                                             */
82 /*                                                                        */
83 /*    Application Code                                                    */
84 /*                                                                        */
85 /*  RELEASE HISTORY                                                       */
86 /*                                                                        */
87 /*    DATE              NAME                      DESCRIPTION             */
88 /*                                                                        */
89 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
90 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
91 /*                                            resulting in version 6.1    */
92 /*                                                                        */
93 /**************************************************************************/
_nx_tcp_info_get(NX_IP * ip_ptr,ULONG * tcp_packets_sent,ULONG * tcp_bytes_sent,ULONG * tcp_packets_received,ULONG * tcp_bytes_received,ULONG * tcp_invalid_packets,ULONG * tcp_receive_packets_dropped,ULONG * tcp_checksum_errors,ULONG * tcp_connections,ULONG * tcp_disconnections,ULONG * tcp_connections_dropped,ULONG * tcp_retransmit_packets)94 UINT  _nx_tcp_info_get(NX_IP *ip_ptr, ULONG *tcp_packets_sent, ULONG *tcp_bytes_sent,
95                        ULONG *tcp_packets_received, ULONG *tcp_bytes_received,
96                        ULONG *tcp_invalid_packets, ULONG *tcp_receive_packets_dropped,
97                        ULONG *tcp_checksum_errors, ULONG *tcp_connections,
98                        ULONG *tcp_disconnections, ULONG *tcp_connections_dropped,
99                        ULONG *tcp_retransmit_packets)
100 {
101 
102     /* Obtain the IP mutex so we can examine the bound port.  */
103     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
104 
105     /* Determine if packets sent is wanted.  */
106     if (tcp_packets_sent)
107     {
108 
109         /* Return the number of packets sent by this IP instance.  */
110         *tcp_packets_sent =  ip_ptr -> nx_ip_tcp_packets_sent;
111     }
112 
113     /* Determine if bytes sent is wanted.  */
114     if (tcp_bytes_sent)
115     {
116 
117         /* Return the number of bytes sent by this IP instance.  */
118         *tcp_bytes_sent =  ip_ptr -> nx_ip_tcp_bytes_sent;
119     }
120 
121     /* Determine if packets received is wanted.  */
122     if (tcp_packets_received)
123     {
124 
125         /* Return the number of packets received by this IP instance.  */
126         *tcp_packets_received =  ip_ptr -> nx_ip_tcp_packets_received;
127     }
128 
129     /* Determine if bytes received is wanted.  */
130     if (tcp_bytes_received)
131     {
132 
133         /* Return the number of bytes received by this IP instance.  */
134         *tcp_bytes_received =  ip_ptr -> nx_ip_tcp_bytes_received;
135     }
136 
137     /* Determine if invalid packets is wanted.  */
138     if (tcp_invalid_packets)
139     {
140 
141         /* Return the number of invalid packets by this IP instance.  */
142         *tcp_invalid_packets =  ip_ptr -> nx_ip_tcp_invalid_packets;
143     }
144 
145     /* Determine if receive packets dropped is wanted.  */
146     if (tcp_receive_packets_dropped)
147     {
148 
149         /* Return the number of receive packets dropped by this IP instance.  */
150         *tcp_receive_packets_dropped =  ip_ptr -> nx_ip_tcp_receive_packets_dropped;
151     }
152 
153     /* Determine if checksum errors is wanted.  */
154     if (tcp_checksum_errors)
155     {
156 
157         /* Return the number of checksum errors by this IP instance.  */
158         *tcp_checksum_errors =  ip_ptr -> nx_ip_tcp_checksum_errors;
159     }
160 
161     /* Determine if connections is wanted.  */
162     if (tcp_connections)
163     {
164 
165         /* Return the number of connections by this IP instance.  */
166         *tcp_connections =  ip_ptr -> nx_ip_tcp_connections;
167     }
168 
169     /* Determine if disconnections is wanted.  */
170     if (tcp_disconnections)
171     {
172 
173         /* Return the number of disconnections by this IP instance.  */
174         *tcp_disconnections =  ip_ptr -> nx_ip_tcp_disconnections;
175     }
176 
177     /* Determine if connections dropped is wanted.  */
178     if (tcp_connections_dropped)
179     {
180 
181         /* Return the number of connections dropped by this IP instance.  */
182         *tcp_connections_dropped =  ip_ptr -> nx_ip_tcp_connections_dropped;
183     }
184 
185     /* Determine if retransmit packets is wanted.  */
186     if (tcp_retransmit_packets)
187     {
188 
189         /* Return the number of retransmit packets by this IP instance.  */
190         *tcp_retransmit_packets =  ip_ptr -> nx_ip_tcp_retransmit_packets;
191     }
192 
193     /* Release protection.  */
194     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
195 
196     /* Return successful completion status.  */
197     return(NX_SUCCESS);
198 }
199 
200