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 /** User Datagram Protocol (UDP) */
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_udp.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_udp_socket_info_get PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Yuxin Zhou, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function retrieves UDP information from the specified socket. */
44 /* */
45 /* INPUT */
46 /* */
47 /* ip_ptr Pointer to IP control block */
48 /* udp_packets_sent Destination to the number of */
49 /* packets sent */
50 /* udp_bytes_sent Destination to the number of */
51 /* bytes sent */
52 /* udp_packets_received Destination to the number of */
53 /* packets received */
54 /* udp_bytes_received Destination to the number of */
55 /* bytes received */
56 /* udp_packets_queued Destination to the number of */
57 /* receive packets queued */
58 /* udp_receive_packets_dropped Destination to the number of */
59 /* receive packets dropped */
60 /* udp_checksum_errors Destination to the number of */
61 /* checksum errors */
62 /* */
63 /* OUTPUT */
64 /* */
65 /* status Completion status */
66 /* */
67 /* CALLS */
68 /* */
69 /* None */
70 /* */
71 /* CALLED BY */
72 /* */
73 /* Application */
74 /* */
75 /* RELEASE HISTORY */
76 /* */
77 /* DATE NAME DESCRIPTION */
78 /* */
79 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
80 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
81 /* resulting in version 6.1 */
82 /* */
83 /**************************************************************************/
_nx_udp_socket_info_get(NX_UDP_SOCKET * socket_ptr,ULONG * udp_packets_sent,ULONG * udp_bytes_sent,ULONG * udp_packets_received,ULONG * udp_bytes_received,ULONG * udp_packets_queued,ULONG * udp_receive_packets_dropped,ULONG * udp_checksum_errors)84 UINT _nx_udp_socket_info_get(NX_UDP_SOCKET *socket_ptr, ULONG *udp_packets_sent, ULONG *udp_bytes_sent,
85 ULONG *udp_packets_received, ULONG *udp_bytes_received, ULONG *udp_packets_queued,
86 ULONG *udp_receive_packets_dropped, ULONG *udp_checksum_errors)
87 {
88
89 TX_INTERRUPT_SAVE_AREA
90
91
92 /* If trace is enabled, insert this event into the trace buffer. */
93 NX_TRACE_IN_LINE_INSERT(NX_TRACE_UDP_SOCKET_INFO_GET, socket_ptr -> nx_udp_socket_ip_ptr, socket_ptr, socket_ptr -> nx_udp_socket_bytes_sent, socket_ptr -> nx_udp_socket_bytes_received, NX_TRACE_UDP_EVENTS, 0, 0);
94
95 /* Disable interrupts. */
96 TX_DISABLE
97
98 /* Determine if packets sent is wanted. */
99 if (udp_packets_sent)
100 {
101
102 /* Return the number of packets sent by this socket. */
103 *udp_packets_sent = socket_ptr -> nx_udp_socket_packets_sent;
104 }
105
106 /* Determine if bytes sent is wanted. */
107 if (udp_bytes_sent)
108 {
109
110 /* Return the number of bytes sent by this socket. */
111 *udp_bytes_sent = socket_ptr -> nx_udp_socket_bytes_sent;
112 }
113
114 /* Determine if packets received is wanted. */
115 if (udp_packets_received)
116 {
117
118 /* Return the number of packets received by this socket. */
119 *udp_packets_received = socket_ptr -> nx_udp_socket_packets_received;
120 }
121
122 /* Determine if bytes received is wanted. */
123 if (udp_bytes_received)
124 {
125
126 /* Return the number of bytes received by this socket. */
127 *udp_bytes_received = socket_ptr -> nx_udp_socket_bytes_received;
128 }
129
130 /* Determine if receive packets queued is wanted. */
131 if (udp_packets_queued)
132 {
133
134 /* Return the number of queued receive packets by this socket. */
135 *udp_packets_queued = socket_ptr -> nx_udp_socket_receive_count;
136 }
137
138 /* Determine if receive packets dropped is wanted. */
139 if (udp_receive_packets_dropped)
140 {
141
142 /* Return the number of receive packets dropped by this socket. */
143 *udp_receive_packets_dropped = socket_ptr -> nx_udp_socket_packets_dropped;
144 }
145
146 /* Determine if checksum errors is wanted. */
147 if (udp_checksum_errors)
148 {
149
150 /* Return the number of checksum errors by this socket. */
151 *udp_checksum_errors = socket_ptr -> nx_udp_socket_checksum_errors;
152 }
153
154 /* Restore interrupts. */
155 TX_RESTORE
156
157 /* Return successful completion. */
158 return(NX_SUCCESS);
159 }
160
161