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 #ifndef NX_DISABLE_IPV4
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_igmp_periodic_processing                        PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function handles the sending of periodic processing of IGMP    */
45 /*    join report messages.                                               */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                IP instance pointer           */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    nx_igmp_interface_report_send         Send IGMP group report        */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    _nx_ip_thread_entry                   IP helper thread              */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
68 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_nx_igmp_periodic_processing(NX_IP * ip_ptr)72 VOID  _nx_igmp_periodic_processing(NX_IP *ip_ptr)
73 {
74 
75 UINT          i;
76 UINT          status;
77 UINT          sent_count = 0;
78 NX_INTERFACE *interface_ptr;
79 UINT          interface_index;
80 
81 
82     /* Search the multicast join list for pending IGMP responses.  */
83     for (i = 0; i < NX_MAX_MULTICAST_GROUPS; i++)
84     {
85 
86         /* Determine if the specified entry is active.  */
87         if (ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_join_list)
88         {
89 
90             /* Now determine if a response is pending.  */
91             if ((ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_update_time > 0) &&
92                 (ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_update_time != NX_WAIT_FOREVER))
93             {
94 
95                 /* Yes, it is active.  Decrement and check for expiration.  */
96                 ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_update_time--;
97 
98                 /* We don't want to decrement a join group if we cannot send it. Check
99                    if we've already sent a packet on this periodic. */
100                 if ((ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_update_time == 0) && (sent_count > 0))
101                 {
102 
103                     /* Restore the timeout to 1 second because we cannot send on this periodic; we've already sent out a packet. */
104                     ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_update_time = 1;
105                 }
106 
107                 /* Has time expired and have we not sent an IGMP report in this period?  */
108                 if (ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_update_time == 0)
109                 {
110 
111                     /* Yes, time has expired and we have not yet sent a packet out on this periodic. */
112 
113                     /* Build and send the join report packet. */
114                     interface_ptr = ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_join_interface_list;
115 
116                     interface_index = (UINT)interface_ptr -> nx_interface_index;
117 
118                     /* Build a IGMP host response packet for a join report and send it!  */
119                     status = _nx_igmp_interface_report_send(ip_ptr, ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_join_list,
120                                                             interface_index, NX_TRUE);
121 
122                     if (status == NX_SUCCESS)
123                     {
124 
125                         /* Update the sent count. Only one report sent per IP periodic. */
126                         sent_count++;
127                     }
128                 }
129             }
130         }
131     }
132 }
133 #endif /* !NX_DISABLE_IPV4  */
134 
135