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 Group Management Protocol (IGMP)                           */
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_igmp.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_igmp_info_get                                   PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function retrieves various IGMP information associated with    */
45 /*    the specified IP instance.                                          */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                IP instance pointer           */
50 /*    igmp_reports_sent                     Destination for the number    */
51 /*                                            of IGMP reports sent        */
52 /*    igmp_queries_received                 Destination for the number    */
53 /*                                            of IGMP queries received    */
54 /*    igmp_checksum_errors                  Destination for the number    */
55 /*                                            of IGMP checksum errors     */
56 /*    current_groups_joined                 Destination for the number    */
57 /*                                            of IGMP multicast groups    */
58 /*                                            currently joined            */
59 /*                                                                        */
60 /*  OUTPUT                                                                */
61 /*                                                                        */
62 /*    status                                Completion status             */
63 /*                                                                        */
64 /*  CALLS                                                                 */
65 /*                                                                        */
66 /*    tx_mutex_get                          Obtain protection mutex       */
67 /*    tx_mutex_put                          Release protection mutex      */
68 /*                                                                        */
69 /*  CALLED BY                                                             */
70 /*                                                                        */
71 /*    Application Code                                                    */
72 /*                                                                        */
73 /*  RELEASE HISTORY                                                       */
74 /*                                                                        */
75 /*    DATE              NAME                      DESCRIPTION             */
76 /*                                                                        */
77 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
78 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
79 /*                                            resulting in version 6.1    */
80 /*                                                                        */
81 /**************************************************************************/
_nx_igmp_info_get(NX_IP * ip_ptr,ULONG * igmp_reports_sent,ULONG * igmp_queries_received,ULONG * igmp_checksum_errors,ULONG * current_groups_joined)82 UINT  _nx_igmp_info_get(NX_IP *ip_ptr, ULONG *igmp_reports_sent, ULONG *igmp_queries_received,
83                         ULONG *igmp_checksum_errors, ULONG *current_groups_joined)
84 {
85 
86 #ifndef NX_DISABLE_IPV4
87 
88 
89     /* If trace is enabled, insert this event into the trace buffer.  */
90     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IGMP_INFO_GET, ip_ptr, ip_ptr -> nx_ip_igmp_reports_sent, ip_ptr -> nx_ip_igmp_queries_received, ip_ptr -> nx_ip_igmp_groups_joined, NX_TRACE_IGMP_EVENTS, 0, 0);
91 
92     /* Obtain protection on this IP instance.  */
93     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
94 
95     /* Determine if IGMP reports sent is wanted.  */
96     if (igmp_reports_sent)
97     {
98 
99         /* Return the number of IGMP reports sent by this IP instance.  */
100         *igmp_reports_sent =  ip_ptr -> nx_ip_igmp_reports_sent;
101     }
102 
103     /* Determine if IGMP queries received is wanted.  */
104     if (igmp_queries_received)
105     {
106 
107         /* Return the number of IGMP queries received by this IP instance.  */
108         *igmp_queries_received =  ip_ptr -> nx_ip_igmp_queries_received;
109     }
110 
111     /* Determine if IGMP checksum errors is wanted.  */
112     if (igmp_checksum_errors)
113     {
114 
115         /* Return the number of IGMP checksum errors by this IP instance.  */
116         *igmp_checksum_errors =  ip_ptr -> nx_ip_igmp_checksum_errors;
117     }
118 
119     /* Determine if the number of IGMP multicast groups joined is wanted.  */
120     if (current_groups_joined)
121     {
122 
123         /* Return the number of IGMP multicast groups joined is wanted.  */
124         *current_groups_joined =  ip_ptr -> nx_ip_igmp_groups_joined;
125     }
126 
127     /* Release the protection.  */
128     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
129 
130     /* Return a successful status!  */
131     return(NX_SUCCESS);
132 #else /* NX_DISABLE_IPV4  */
133     NX_PARAMETER_NOT_USED(ip_ptr);
134     NX_PARAMETER_NOT_USED(igmp_reports_sent);
135     NX_PARAMETER_NOT_USED(igmp_queries_received);
136     NX_PARAMETER_NOT_USED(igmp_checksum_errors);
137     NX_PARAMETER_NOT_USED(current_groups_joined);
138 
139     return(NX_NOT_SUPPORTED);
140 #endif /* !NX_DISABLE_IPV4  */
141 }
142 
143