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 
24 /**************************************************************************/
25 /*                                                                        */
26 /*  COMPONENT DEFINITION                                   RELEASE        */
27 /*                                                                        */
28 /*    nx_igmp.h                                           PORTABLE C      */
29 /*                                                           6.1.9        */
30 /*  AUTHOR                                                                */
31 /*                                                                        */
32 /*    Yuxin Zhou, Microsoft Corporation                                   */
33 /*                                                                        */
34 /*  DESCRIPTION                                                           */
35 /*                                                                        */
36 /*    This file defines the NetX Internet Group Management Protocol (IGMP)*/
37 /*    component, including all data types and external references.  It is */
38 /*    assumed that nx_api.h and nx_port.h have already been included.     */
39 /*                                                                        */
40 /*  RELEASE HISTORY                                                       */
41 /*                                                                        */
42 /*    DATE              NAME                      DESCRIPTION             */
43 /*                                                                        */
44 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
45 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
46 /*                                            resulting in version 6.1    */
47 /*  10-15-2021     Yuxin Zhou               Modified comment(s), included */
48 /*                                            necessary header file,      */
49 /*                                            resulting in version 6.1.9  */
50 /*                                                                        */
51 /**************************************************************************/
52 
53 #ifndef NX_IGMP_H
54 #define NX_IGMP_H
55 
56 #include "nx_api.h"
57 
58 
59 #ifndef NX_DISABLE_IPV4
60 /* Define IGMP types and codes.  */
61 
62 /* IGMPv2 combines version field with the type field ffectively, and calls the 8 bit
63    field the Type field.  IGMPv2 uses Type 0x11, 0x16, and 0x17 in this field, while
64    IGMPv1 uses Type 1 and 2 in the lower 4 bits, combined with version 1 in the upper 4 bits
65    for 0x11 and 0x12 as the possible values. */
66 
67 
68 /* Define the IGMP version in the IGMP header.  */
69 
70 #define NX_IGMP_VERSION            0x10000000
71 
72 
73 /* Define the numeric version of IGMP protocol used by NetX. */
74 
75 #define NX_IGMP_HOST_VERSION_1     1
76 #define NX_IGMP_HOST_VERSION_2     2
77 
78 
79 /* Define the IGMP query message type and mask in the IGMP header.  */
80 
81 #define NX_IGMP_ROUTER_QUERY_TYPE  0x01000000
82 #define NX_IGMP_TYPE_MASK          0x0F000000
83 
84 
85 /* Define the IGMPv1 type for membership join reports. */
86 
87 #define NX_IGMP_HOST_RESPONSE_TYPE 0x02000000
88 
89 
90 /* Define IGMPv2 types for membership join and leave reports. */
91 
92 #define NX_IGMP_HOST_V2_JOIN_TYPE  0x16000000
93 #define NX_IGMP_HOST_V2_LEAVE_TYPE 0x17000000
94 
95 
96 /* Define the IGMPv2 type mask in the IGMP header.  */
97 
98 #define NX_IGMPV2_TYPE_MASK        0xFF000000
99 
100 
101 /* Define the IGMPv2 maximum response time mask in the IGMP header.  Max value is 0x64,
102    left intentionally blank in IGMPv1 queries and all IGMP reports. Maximum response time
103    is in tenth's of a second. */
104 
105 #define NX_IGMP_MAX_RESP_TIME_MASK 0x00FF0000
106 
107 
108 /* For IGMPv1 only, define the IGMP maximum delay time to 10 seconds as per RFC 1112.  This is achieved if
109    the slow NetX IP periodic thread timer executes every second (e.g. NX_IP_PERIODIC_RATE is set to 100)
110    and the threadx timer interrupt occurs every 10 ms). */
111 
112 #define NX_IGMP_MAX_UPDATE_TIME    10
113 
114 
115 /* Define the time to live for IGMP packets. RFC 1112 and 2236 specify
116    time to live should be set at 1. */
117 
118 #define NX_IGMP_TTL                1
119 
120 
121 /* Define the IP "all hosts" multicast address.  */
122 
123 #define NX_ALL_HOSTS_ADDRESS       IP_ADDRESS(224, 0, 0, 1)
124 
125 
126 /* Define the IP "all routers" multicast address.  */
127 
128 #define NX_ALL_ROUTERS_ADDRESS     IP_ADDRESS(224, 0, 0, 2)
129 
130 
131 /* Define Basic IGMP packet header data type.  This will be used to
132    build new IGMP packets and to examine incoming IGMP queries sent
133    to NetX.  */
134 
135 typedef  struct NX_IGMP_HEADER_STRUCT
136 {
137     /* Define the first 32-bit word of the IGMP header.  This word contains
138        the following information:
139 
140             bits 31-28  IGMP 4-bit version (Version 1)
141 
142             bits 27-24  IGMP 4-bit type defined as follows:
143 
144                                         Type Field      IGMP Message Type
145 
146                                             1           Router Query Request
147                                             2           Host Query Response
148 
149             bits 15-0   IGMP 16-bit checksum
150 
151      */
152 
153     ULONG nx_igmp_header_word_0;
154 
155     /* Define the second and final word of the IGMP header.  This word contains
156        the following information:
157 
158             bits 31-0   32-bit group address (class D IP address)
159      */
160     ULONG nx_igmp_header_word_1;
161 } NX_IGMP_HEADER;
162 
163 
164 /* Define the IGMP query response message size.  */
165 
166 #define NX_IGMP_HEADER_SIZE sizeof(NX_IGMP_HEADER)
167 
168 
169 
170 /* Define IGMP internal function prototypes.  */
171 UINT _nx_igmp_multicast_interface_join_internal(NX_IP *ip_ptr, ULONG group_address, UINT interface_index, UINT update_time);
172 UINT _nx_igmp_multicast_interface_leave_internal(NX_IP *ip_ptr, ULONG group_address, UINT interface_index);
173 UINT _nx_igmp_interface_report_send(NX_IP *ip_ptr, ULONG group_address, UINT interface_index, UINT is_joining);
174 VOID _nx_igmp_periodic_processing(NX_IP *ip_ptr);
175 VOID _nx_igmp_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
176 VOID _nx_igmp_packet_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr);
177 VOID _nx_igmp_queue_process(NX_IP *ip_ptr);
178 UINT _nx_igmp_multicast_check(NX_IP *ip_ptr, ULONG group_address, NX_INTERFACE *nx_interface);
179 #endif /* NX_DISABLE_IPV4 */
180 
181 
182 /* Define IGMP function prototypes.  */
183 
184 UINT _nx_igmp_enable(NX_IP *ip_ptr);
185 UINT _nx_igmp_info_get(NX_IP *ip_ptr, ULONG *igmp_reports_sent, ULONG *igmp_queries_received,
186                        ULONG *igmp_checksum_errors, ULONG *current_groups_joined);
187 UINT _nx_igmp_loopback_disable(NX_IP *ip_ptr);
188 UINT _nx_igmp_loopback_enable(NX_IP *ip_ptr);
189 UINT _nx_igmp_multicast_join(NX_IP *ip_ptr, ULONG group_address);
190 UINT _nx_igmp_multicast_interface_join(NX_IP *ip_ptr, ULONG group_address, UINT interface_index);
191 UINT _nx_igmp_multicast_leave(NX_IP *ip_ptr, ULONG group_address);
192 UINT _nx_igmp_multicast_interface_leave(NX_IP *ip_ptr, ULONG group_address, UINT interface_index);
193 
194 /* Define error checking shells for API services.  These are only referenced by the
195    application.  */
196 
197 UINT _nxe_igmp_enable(NX_IP *ip_ptr);
198 UINT _nxe_igmp_info_get(NX_IP *ip_ptr, ULONG *igmp_reports_sent, ULONG *igmp_queries_received,
199                         ULONG *igmp_checksum_errors, ULONG *current_groups_joined);
200 UINT _nxe_igmp_loopback_disable(NX_IP *ip_ptr);
201 UINT _nxe_igmp_loopback_enable(NX_IP *ip_ptr);
202 UINT _nxe_igmp_multicast_join(NX_IP *ip_ptr, ULONG group_address);
203 UINT _nxe_igmp_multicast_interface_join(NX_IP *ip_ptr, ULONG group_address, UINT interface_index);
204 UINT _nxe_igmp_multicast_leave(NX_IP *ip_ptr, ULONG group_address);
205 UINT _nxe_igmp_multicast_interface_leave(NX_IP *ip_ptr, ULONG group_address, UINT interface_index);
206 
207 
208 #endif
209 
210