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 /**   Internet Protocol (IP)                                              */
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_ip.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_ip_info_get                                     PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves information about the specified IP          */
45 /*    instance.                                                           */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                Pointer to IP instance        */
50 /*    ip_total_packets_sent                 Destination for number of     */
51 /*                                            packets sent                */
52 /*    ip_total_bytes_sent                   Destination for number of     */
53 /*                                            bytes sent                  */
54 /*    ip_total_packets_received             Destination for number of     */
55 /*                                            packets received            */
56 /*    ip_total_bytes_received               Destination for number of     */
57 /*                                            bytes received              */
58 /*    ip_invalid_packets                    Destination for number of     */
59 /*                                            invalid packets             */
60 /*    ip_receive_packets_dropped            Destination for number of     */
61 /*                                            packets dropped             */
62 /*    ip_receive_checksum_errors            Destination for number of     */
63 /*                                            checksum errors             */
64 /*    ip_send_packets_dropped               Destination for number of     */
65 /*                                            send packets dropped        */
66 /*    ip_total_fragments_sent               Destination for number of     */
67 /*                                            fragments sent              */
68 /*    ip_total_fragments_received           Destination for number of     */
69 /*                                            fragments received          */
70 /*                                                                        */
71 /*  OUTPUT                                                                */
72 /*                                                                        */
73 /*    status                                Completion status             */
74 /*                                                                        */
75 /*  CALLS                                                                 */
76 /*                                                                        */
77 /*    tx_mutex_get                          Obtain protection mutex       */
78 /*    tx_mutex_put                          Release protection mutex      */
79 /*                                                                        */
80 /*  CALLED BY                                                             */
81 /*                                                                        */
82 /*    Application                                                         */
83 /*                                                                        */
84 /*  RELEASE HISTORY                                                       */
85 /*                                                                        */
86 /*    DATE              NAME                      DESCRIPTION             */
87 /*                                                                        */
88 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
89 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
90 /*                                            resulting in version 6.1    */
91 /*                                                                        */
92 /**************************************************************************/
_nx_ip_info_get(NX_IP * ip_ptr,ULONG * ip_total_packets_sent,ULONG * ip_total_bytes_sent,ULONG * ip_total_packets_received,ULONG * ip_total_bytes_received,ULONG * ip_invalid_packets,ULONG * ip_receive_packets_dropped,ULONG * ip_receive_checksum_errors,ULONG * ip_send_packets_dropped,ULONG * ip_total_fragments_sent,ULONG * ip_total_fragments_received)93 UINT  _nx_ip_info_get(NX_IP *ip_ptr, ULONG *ip_total_packets_sent, ULONG *ip_total_bytes_sent,
94                       ULONG *ip_total_packets_received, ULONG *ip_total_bytes_received,
95                       ULONG *ip_invalid_packets, ULONG *ip_receive_packets_dropped,
96                       ULONG *ip_receive_checksum_errors, ULONG *ip_send_packets_dropped,
97                       ULONG *ip_total_fragments_sent, ULONG *ip_total_fragments_received)
98 {
99 
100     /* If trace is enabled, insert this event into the trace buffer.  */
101     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_INFO_GET, ip_ptr, ip_ptr -> nx_ip_total_bytes_sent, ip_ptr -> nx_ip_total_bytes_received, ip_ptr -> nx_ip_receive_packets_dropped, NX_TRACE_IP_EVENTS, 0, 0);
102 
103     /* Obtain protection on this IP instance.  */
104     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
105 
106     /* Determine if IP total packets sent is wanted.  */
107     if (ip_total_packets_sent)
108     {
109 
110         /* Return the number of IP total packets sent by this IP instance.  */
111         *ip_total_packets_sent =  ip_ptr -> nx_ip_total_packets_sent;
112     }
113 
114     /* Determine if IP total bytes sent is wanted.  */
115     if (ip_total_bytes_sent)
116     {
117 
118         /* Return the number of IP total bytes sent by this IP instance.  */
119         *ip_total_bytes_sent =  ip_ptr -> nx_ip_total_bytes_sent;
120     }
121 
122     /* Determine if IP total packets received is wanted.  */
123     if (ip_total_packets_received)
124     {
125 
126         /* Return the number of IP total packets received by this IP instance.  */
127         *ip_total_packets_received =  ip_ptr -> nx_ip_total_packets_received;
128     }
129 
130     /* Determine if IP total bytes received is wanted.  */
131     if (ip_total_bytes_received)
132     {
133 
134         /* Return the number of IP total bytes received by this IP instance.  */
135         *ip_total_bytes_received =  ip_ptr -> nx_ip_total_bytes_received;
136     }
137 
138     /* Determine if IP invalid packets is wanted.  */
139     if (ip_invalid_packets)
140     {
141 
142         /* Return the number of IP invalid packets received by this IP instance.  */
143         *ip_invalid_packets =  ip_ptr -> nx_ip_invalid_packets;
144     }
145 
146     /* Determine if IP receive packets dropped is wanted.  */
147     if (ip_receive_packets_dropped)
148     {
149 
150         /* Return the number of IP receive packets dropped by this IP instance.  */
151         *ip_receive_packets_dropped =  ip_ptr -> nx_ip_receive_packets_dropped;
152     }
153 
154     /* Determine if IP receive checksum errors is wanted.  */
155     if (ip_receive_checksum_errors)
156     {
157 
158         /* Return the number of IP receive checksum errors by this IP instance.  */
159         *ip_receive_checksum_errors =  ip_ptr -> nx_ip_receive_checksum_errors;
160     }
161 
162     /* Determine if IP send packets dropped is wanted.  */
163     if (ip_send_packets_dropped)
164     {
165 
166         /* Return the number of IP send packets dropped by this IP instance.  */
167         *ip_send_packets_dropped =  ip_ptr -> nx_ip_send_packets_dropped;
168     }
169 
170 #ifndef NX_DISABLE_FRAGMENTATION
171     /* Determine if IP total fragments sent is wanted.  */
172     if (ip_total_fragments_sent)
173     {
174 
175         /* Return the number of IP total fragments sent by this IP instance.  */
176         *ip_total_fragments_sent =  ip_ptr -> nx_ip_total_fragments_sent;
177     }
178 
179     /* Determine if IP total fragments received is wanted.  */
180     if (ip_total_fragments_received)
181     {
182 
183         /* Return the number of IP total fragments received by this IP instance.  */
184         *ip_total_fragments_received =  ip_ptr -> nx_ip_total_fragments_received;
185     }
186 #else /* NX_DISABLE_FRAGMENTATION */
187     /* Set IP Total Framgnets Sent to zero */
188     if (ip_total_fragments_sent)
189     {
190 
191         *ip_total_fragments_sent =  0;
192     }
193 
194     /* Set IP Total Framgnets Received to zero */
195     if (ip_total_fragments_received)
196     {
197 
198         *ip_total_fragments_received =  0;
199     }
200 
201 #endif /* NX_DISABLE_FRAGMENTATION */
202 
203     /* Release the protection.  */
204     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
205 
206     /* Return success to the caller.  */
207     return(NX_SUCCESS);
208 }
209 
210