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 (IPv6)                                            */
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_ipv6.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nxd_ipv6_multicast_interface_leave                 PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This service removes the specific IPv6 multicast address from the   */
45 /*    sepcific physical interface.  The link driver is also notified of   */
46 /*    the removal of the IPv6 multicast address.                          */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    ip_ptr                                IP instance pointer           */
51 /*    group_address                         IPv6 multicast address        */
52 /*    interface_index                       Index to physical interface   */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    status                                Completion status             */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    tx_mutex_get                          Obtain protection mutex       */
61 /*    tx_mutex_put                          Release protection mutex      */
62 /*    memset                                Clear the memory              */
63 /*    (ip_link_driver)                      Device driver entry point     */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    Application                                                         */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_nxd_ipv6_multicast_interface_leave(NX_IP * ip_ptr,NXD_ADDRESS * group_address,UINT interface_index)78 UINT  _nxd_ipv6_multicast_interface_leave(NX_IP *ip_ptr, NXD_ADDRESS *group_address, UINT interface_index)
79 {
80 #if defined(NX_ENABLE_IPV6_MULTICAST) && defined(FEATURE_NX_IPV6)
81 
82 UINT          i;
83 NX_IP_DRIVER  driver_request;
84 NX_INTERFACE *nx_interface;
85 
86     /* Obtain the IP mutex so we can search the multicast join list.  */
87     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
88 
89     nx_interface = &ip_ptr -> nx_ip_interface[interface_index];
90 
91     for (i = 0; i < NX_MAX_MULTICAST_GROUPS; i++)
92     {
93 
94         /* Determine if the specified entry is present.  */
95         if ((nx_interface == ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_interface_list) && (CHECK_IPV6_ADDRESSES_SAME(ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_list, group_address -> nxd_ip_address.v6)))
96         {
97 
98             /* Yes, we have found the same entry.  */
99 
100             /* Decrease the join count.  */
101             ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_count--;
102 
103             /* Determine if there are no other join requests for this group address.  */
104             if (ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_count == 0)
105             {
106 
107                 /* Clear the group join value.  */
108                 memset(ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_list, 0, 4 * sizeof(ULONG));
109 
110                 /* Decrement the MLD groups joined count.  */
111                 ip_ptr -> nx_ipv6_multicast_groups_joined--;
112 
113                 /* Un-register the new multicast group with the underlying driver.  */
114                 driver_request.nx_ip_driver_ptr =                    ip_ptr;
115                 driver_request.nx_ip_driver_command =                NX_LINK_MULTICAST_LEAVE;
116                 driver_request.nx_ip_driver_physical_address_msw =   0x00003333;
117                 driver_request.nx_ip_driver_physical_address_lsw =   group_address -> nxd_ip_address.v6[3];
118                 driver_request.nx_ip_driver_interface =              nx_interface;
119 
120                 (ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_interface_list -> nx_interface_link_driver_entry)(&driver_request);
121 
122                 /* Now clear the interface entry. */
123                 ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_interface_list = NX_NULL;
124             }
125 
126             /* Release the IP protection.  */
127             tx_mutex_put(&(ip_ptr -> nx_ip_protection));
128 
129             /* Return success!  */
130             return(NX_SUCCESS);
131         }
132     }
133 
134     /* At this point we know that the supplied entry was not found.  */
135 
136     /* Release the protection of the IP instance.  */
137     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
138 
139     /* Return an error code.  */
140     return(NX_ENTRY_NOT_FOUND);
141 
142 #else
143     NX_PARAMETER_NOT_USED(ip_ptr);
144     NX_PARAMETER_NOT_USED(group_address);
145     NX_PARAMETER_NOT_USED(interface_index);
146 
147     return(NX_NOT_SUPPORTED);
148 
149 #endif /* NX_ENABLE_IPV6_MULTICAST && FEATURE_NX_IPV6 */
150 }
151 
152