summaryrefslogtreecommitdiff
path: root/common/src/nx_tcp_socket_info_get.c
blob: 9689bab1be26a1824f4aadb9d86f28b48fea635f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2025-present Eclipse ThreadX Contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** NetX Component                                                        */
/**                                                                       */
/**   Transmission Control Protocol (TCP)                                 */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define NX_SOURCE_CODE


/* Include necessary system files.  */

#include "nx_api.h"
#include "nx_tcp.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_tcp_socket_info_get                             PORTABLE C      */
/*                                                           6.4.3        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function retrieves TCP information for the specified TCP       */
/*    socket.                                                             */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    socket_ptr                            Pointer to the TCP socket     */
/*    tcp_packets_sent                      Destination for number of     */
/*                                            packets sent                */
/*    tcp_bytes_sent                        Destination for number of     */
/*                                            bytes sent                  */
/*    tcp_packets_received                  Destination for number of     */
/*                                            packets received            */
/*    tcp_bytes_received                    Destination for number of     */
/*                                            bytes received              */
/*    tcp_retransmit_packets                Destination for number of     */
/*                                            retransmit packets          */
/*    tcp_packets_queued                    Destination for number of     */
/*                                            receive packets queued      */
/*    tcp_checksum_errors                   Destination for number of     */
/*                                            checksum errors             */
/*    tcp_socket_state                      Destination for the current   */
/*                                            socket state                */
/*    tcp_transmit_queue_depth              Destination for number of     */
/*                                            sockets still in transmit   */
/*                                            queue                       */
/*    tcp_transmit_window                   Destination for number of     */
/*                                            bytes in transmit window    */
/*    tcp_receive_window                    Destination for number of     */
/*                                            bytes in receive window     */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    status                                Completion status             */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    tx_mutex_get                          Obtain protection             */
/*    tx_mutex_put                          Release protection            */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application Code                                                    */
/*                                                                        */
/**************************************************************************/
UINT  _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)
{

NX_IP *ip_ptr;


    /* Setup IP pointer.  */
    ip_ptr =  socket_ptr -> nx_tcp_socket_ip_ptr;

    /* If trace is enabled, insert this event into the trace buffer.  */
    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);

    /* Obtain the IP mutex so we can examine the bound port.  */
    tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);

    /* Determine if packets sent is wanted.  */
    if (tcp_packets_sent)
    {

        /* Return the number of packets sent by this socket.  */
        *tcp_packets_sent =  socket_ptr -> nx_tcp_socket_packets_sent;
    }

    /* Determine if bytes sent is wanted.  */
    if (tcp_bytes_sent)
    {

        /* Return the number of bytes sent by this socket.  */
        *tcp_bytes_sent =  socket_ptr -> nx_tcp_socket_bytes_sent;
    }

    /* Determine if packets received is wanted.  */
    if (tcp_packets_received)
    {

        /* Return the number of packets received by this socket.  */
        *tcp_packets_received =  socket_ptr -> nx_tcp_socket_packets_received;
    }

    /* Determine if bytes received is wanted.  */
    if (tcp_bytes_received)
    {

        /* Return the number of bytes received by this socket.  */
        *tcp_bytes_received =  socket_ptr -> nx_tcp_socket_bytes_received;
    }

    /* Determine if retransmit packets is wanted.  */
    if (tcp_retransmit_packets)
    {

        /* Return the number of retransmit packets by this socket.  */
        *tcp_retransmit_packets =  socket_ptr -> nx_tcp_socket_retransmit_packets;
    }

    /* Determine if packets queued is wanted.  */
    if (tcp_packets_queued)
    {

        /* Return the number of packets queued by this socket.  */
        *tcp_packets_queued =  socket_ptr -> nx_tcp_socket_receive_queue_count;
    }

    /* Determine if checksum errors is wanted.  */
    if (tcp_checksum_errors)
    {

        /* Return the number of checksum errors by this socket.  */
        *tcp_checksum_errors =  socket_ptr -> nx_tcp_socket_checksum_errors;
    }

    /* Determine if socket state is wanted.  */
    if (tcp_socket_state)
    {

        /* Return the state this socket.  */
        *tcp_socket_state =  socket_ptr -> nx_tcp_socket_state;
    }

    /* Determine if transmit queue depth is wanted.  */
    if (tcp_transmit_queue_depth)
    {

        /* Return the transmit queue depth of this socket.  */
        *tcp_transmit_queue_depth =  socket_ptr -> nx_tcp_socket_transmit_sent_count;
    }

    /* Determine if transmit window size is wanted.  */
    if (tcp_transmit_window)
    {

        /* Return the transmit window size of this socket.  */
        if (socket_ptr -> nx_tcp_socket_tx_window_advertised > socket_ptr -> nx_tcp_socket_tx_window_congestion)
        {
            *tcp_transmit_window = socket_ptr -> nx_tcp_socket_tx_window_congestion;
        }
        else
        {
            *tcp_transmit_window = socket_ptr -> nx_tcp_socket_tx_window_advertised;
        }
        if (*tcp_transmit_window > socket_ptr -> nx_tcp_socket_tx_outstanding_bytes)
        {
            *tcp_transmit_window =  *tcp_transmit_window - socket_ptr -> nx_tcp_socket_tx_outstanding_bytes;
        }
        else
        {
            *tcp_transmit_window = 0;
        }
    }

    /* Determine if receive window size is wanted.  */
    if (tcp_receive_window)
    {

        /* Return the receive window size of this socket.  */
        *tcp_receive_window =  socket_ptr -> nx_tcp_socket_rx_window_current;
    }

    /* Release protection.  */
    tx_mutex_put(&(ip_ptr -> nx_ip_protection));

    /* Return successful completion status.  */
    return(NX_SUCCESS);
}