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