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 /* Bring in externs for caller checking code.  */
32 NX_CALLER_CHECKING_EXTERNS
33 
34 
35 /**************************************************************************/
36 /*                                                                        */
37 /*  FUNCTION                                               RELEASE        */
38 /*                                                                        */
39 /*    _nxe_tcp_socket_info_get                            PORTABLE C      */
40 /*                                                           6.1          */
41 /*  AUTHOR                                                                */
42 /*                                                                        */
43 /*    Yuxin Zhou, Microsoft Corporation                                   */
44 /*                                                                        */
45 /*  DESCRIPTION                                                           */
46 /*                                                                        */
47 /*    This function checks for errors in the socket information get       */
48 /*    function call.                                                      */
49 /*                                                                        */
50 /*  INPUT                                                                 */
51 /*                                                                        */
52 /*    socket_ptr                            Pointer to the TCP socket     */
53 /*    tcp_packets_sent                      Destination for number of     */
54 /*                                            packets sent                */
55 /*    tcp_bytes_sent                        Destination for number of     */
56 /*                                            bytes sent                  */
57 /*    tcp_packets_received                  Destination for number of     */
58 /*                                            packets received            */
59 /*    tcp_bytes_received                    Destination for number of     */
60 /*                                            bytes received              */
61 /*    tcp_retransmit_packets                Destination for number of     */
62 /*                                            retransmit packets          */
63 /*    tcp_packets_queued                    Destination for number of     */
64 /*                                            receive packets queued      */
65 /*    tcp_checksum_errors                   Destination for number of     */
66 /*                                            checksum errors             */
67 /*    tcp_socket_state                      Destination for the current   */
68 /*                                            socket state                */
69 /*    tcp_transmit_queue_depth              Destination for number of     */
70 /*                                            sockets still in transmit   */
71 /*                                            queue                       */
72 /*    tcp_transmit_window                   Destination for number of     */
73 /*                                            bytes in transmit window    */
74 /*    tcp_receive_window                    Destination for number of     */
75 /*                                            bytes in receive window     */
76 /*                                                                        */
77 /*  OUTPUT                                                                */
78 /*                                                                        */
79 /*    status                                Completion status             */
80 /*                                                                        */
81 /*  CALLS                                                                 */
82 /*                                                                        */
83 /*    _nx_tcp_socket_info_get               Actual socket information get */
84 /*                                            function                    */
85 /*                                                                        */
86 /*  CALLED BY                                                             */
87 /*                                                                        */
88 /*    Application Code                                                    */
89 /*                                                                        */
90 /*  RELEASE HISTORY                                                       */
91 /*                                                                        */
92 /*    DATE              NAME                      DESCRIPTION             */
93 /*                                                                        */
94 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
95 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
96 /*                                            resulting in version 6.1    */
97 /*                                                                        */
98 /**************************************************************************/
_nxe_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)99 UINT  _nxe_tcp_socket_info_get(NX_TCP_SOCKET *socket_ptr, ULONG *tcp_packets_sent, ULONG *tcp_bytes_sent,
100                                ULONG *tcp_packets_received, ULONG *tcp_bytes_received,
101                                ULONG *tcp_retransmit_packets, ULONG *tcp_packets_queued,
102                                ULONG *tcp_checksum_errors, ULONG *tcp_socket_state,
103                                ULONG *tcp_transmit_queue_depth, ULONG *tcp_transmit_window,
104                                ULONG *tcp_receive_window)
105 {
106 
107 UINT status;
108 
109 
110     /* Check for invalid input pointers.  */
111     if ((socket_ptr == NX_NULL) || (socket_ptr -> nx_tcp_socket_id != NX_TCP_ID))
112     {
113         return(NX_PTR_ERROR);
114     }
115 
116     /* Check to see if TCP is enabled.  */
117     if (!(socket_ptr -> nx_tcp_socket_ip_ptr) -> nx_ip_tcp_packet_receive)
118     {
119         return(NX_NOT_ENABLED);
120     }
121 
122     /* Check for appropriate caller.  */
123     NX_INIT_AND_THREADS_CALLER_CHECKING
124 
125     /* Call actual TCP socket information get function.  */
126     status =  _nx_tcp_socket_info_get(socket_ptr, tcp_packets_sent, tcp_bytes_sent, tcp_packets_received,
127                                       tcp_bytes_received, tcp_retransmit_packets, tcp_packets_queued,
128                                       tcp_checksum_errors, tcp_socket_state, tcp_transmit_queue_depth,
129                                       tcp_transmit_window, tcp_receive_window);
130 
131     /* Return completion status.  */
132     return(status);
133 }
134 
135