igmp_common.h
Go to the documentation of this file.
1 /**
2  * @file igmp_common.h
3  * @brief Definitions common to IGMP host, router and snooping switch
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 #ifndef _IGMP_COMMON_H
32 #define _IGMP_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //IGMP tick interval
38 #ifndef IGMP_TICK_INTERVAL
39  #define IGMP_TICK_INTERVAL 200
40 #elif (IGMP_TICK_INTERVAL < 10)
41  #error IGMP_TICK_INTERVAL parameter is not valid
42 #endif
43 
44 //Robustness Variable
45 #ifndef IGMP_ROBUSTNESS_VARIABLE
46  #define IGMP_ROBUSTNESS_VARIABLE 2
47 #elif (IGMP_ROBUSTNESS_VARIABLE < 1)
48  #error IGMP_ROBUSTNESS_VARIABLE parameter is not valid
49 #endif
50 
51 //Query Interval
52 #ifndef IGMP_QUERY_INTERVAL
53  #define IGMP_QUERY_INTERVAL 125000
54 #elif (IGMP_QUERY_INTERVAL < 1000)
55  #error IGMP_QUERY_INTERVAL parameter is not valid
56 #endif
57 
58 //Query Response Interval
59 #ifndef IGMP_QUERY_RESPONSE_INTERVAL
60  #define IGMP_QUERY_RESPONSE_INTERVAL 10000
61 #elif (IGMP_QUERY_RESPONSE_INTERVAL < 1000 || IGMP_QUERY_RESPONSE_INTERVAL > IGMP_QUERY_INTERVAL)
62  #error IGMP_QUERY_RESPONSE_INTERVAL parameter is not valid
63 #endif
64 
65 //Group Membership Interval
66 #define IGMP_GROUP_MEMBERSHIP_INTERVAL ((IGMP_ROBUSTNESS_VARIABLE * \
67  IGMP_QUERY_INTERVAL) + IGMP_QUERY_RESPONSE_INTERVAL)
68 
69 //Other Querier Present Interval
70 #define IGMP_OTHER_QUERIER_PRESENT_INTERVAL ((IGMP_ROBUSTNESS_VARIABLE * \
71  IGMP_QUERY_INTERVAL) + (IGMP_QUERY_RESPONSE_INTERVAL / 2))
72 
73 //Startup Query Interval
74 #ifndef IGMP_STARTUP_QUERY_INTERVAL
75  #define IGMP_STARTUP_QUERY_INTERVAL (IGMP_QUERY_INTERVAL / 4)
76 #elif (IGMP_STARTUP_QUERY_INTERVAL < 1000)
77  #error IGMP_STARTUP_QUERY_INTERVAL parameter is not valid
78 #endif
79 
80 //Startup Query Count
81 #ifndef IGMP_STARTUP_QUERY_COUNT
82  #define IGMP_STARTUP_QUERY_COUNT IGMP_ROBUSTNESS_VARIABLE
83 #elif (IGMP_STARTUP_QUERY_COUNT < 1)
84  #error IGMP_STARTUP_QUERY_COUNT parameter is not valid
85 #endif
86 
87 //Last Member Query Interval
88 #ifndef IGMP_LAST_MEMBER_QUERY_INTERVAL
89  #define IGMP_LAST_MEMBER_QUERY_INTERVAL 1000
90 #elif (IGMP_LAST_MEMBER_QUERY_INTERVAL < 100)
91  #error IGMP_LAST_MEMBER_QUERY_INTERVAL parameter is not valid
92 #endif
93 
94 //Last Member Query Count
95 #ifndef IGMP_LAST_MEMBER_QUERY_COUNT
96  #define IGMP_LAST_MEMBER_QUERY_COUNT IGMP_ROBUSTNESS_VARIABLE
97 #elif (IGMP_LAST_MEMBER_QUERY_COUNT < 1)
98  #error IGMP_LAST_MEMBER_QUERY_COUNT parameter is not valid
99 #endif
100 
101 //Last Member Query Time
102 #define IGMP_LAST_MEMBER_QUERY_TIME (IGMP_LAST_MEMBER_QUERY_COUNT * \
103  IGMP_LAST_MEMBER_QUERY_INTERVAL)
104 
105 //Unsolicited Report Interval
106 #ifndef IGMP_UNSOLICITED_REPORT_INTERVAL
107  #define IGMP_UNSOLICITED_REPORT_INTERVAL 10000
108 #elif (IGMP_UNSOLICITED_REPORT_INTERVAL < 1000)
109  #error IGMP_UNSOLICITED_REPORT_INTERVAL parameter is not valid
110 #endif
111 
112 //Older Version Querier Present Timeout
113 #ifndef IGMP_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT
114  #define IGMP_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT 400000
115 #elif (IGMP_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT < 1000)
116  #error IGMP_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT parameter is not valid
117 #endif
118 
119 //Maximum response time for queries (IGMPv1)
120 #ifndef IGMP_V1_MAX_RESPONSE_TIME
121  #define IGMP_V1_MAX_RESPONSE_TIME 10000
122 #elif (IGMP_V1_MAX_RESPONSE_TIME < 1000)
123  #error IGMP_V1_MAX_RESPONSE_TIME parameter is not valid
124 #endif
125 
126 //Unsolicited Report Interval (IGMPv3)
127 #ifndef IGMP_V3_UNSOLICITED_REPORT_INTERVAL
128  #define IGMP_V3_UNSOLICITED_REPORT_INTERVAL 1000
129 #elif (IGMP_V3_UNSOLICITED_REPORT_INTERVAL < 1000)
130  #error IGMP_V3_UNSOLICITED_REPORT_INTERVAL parameter is not valid
131 #endif
132 
133 //Maximum size of IGMP messages
134 #ifndef IGMP_MAX_MSG_SIZE
135  #define IGMP_MAX_MSG_SIZE 1024
136 #elif (IGMP_MAX_MSG_SIZE < 1)
137  #error IGMP_MAX_MSG_SIZE parameter is not valid
138 #endif
139 
140 //TTL used by IGMP messages
141 #define IGMP_TTL 1
142 
143 //All-Systems address
144 #define IGMP_ALL_SYSTEMS_ADDR IPV4_ADDR(224, 0, 0, 1)
145 //All-Routers address
146 #define IGMP_ALL_ROUTERS_ADDR IPV4_ADDR(224, 0, 0, 2)
147 //IGMPv3 All-Routers address
148 #define IGMP_V3_ALL_ROUTERS_ADDR IPV4_ADDR(224, 0, 0, 22)
149 
150 //C++ guard
151 #ifdef __cplusplus
152 extern "C" {
153 #endif
154 
155 
156 /**
157  * @brief IGMP versions
158  **/
159 
160 typedef enum
161 {
164  IGMP_VERSION_3 = 3
166 
167 
168 /**
169  * @brief IGMP message types
170  **/
171 
172 typedef enum
173 {
180 
181 
182 /**
183  * @brief IGMPv3 group record types
184  **/
185 
186 typedef enum
187 {
195 
196 
197 //CC-RX, CodeWarrior or Win32 compiler?
198 #if defined(__CCRX__)
199  #pragma pack
200 #elif defined(__CWCC__) || defined(_WIN32)
201  #pragma pack(push, 1)
202 #endif
203 
204 
205 /**
206  * @brief IGMP message
207  **/
208 
210 {
211  uint8_t type; //0
212  uint8_t maxRespTime; //1
213  uint16_t checksum; //2-3
216 
217 
218 /**
219  * @brief IGMPv3 Membership Query message
220  **/
221 
222 typedef __packed_struct
223 {
224  uint8_t type; //0
225  uint8_t maxRespCode; //1
226  uint16_t checksum; //2-3
227  Ipv4Addr groupAddr; //4-7
228 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
229  uint8_t reserved : 4; //8
230  uint8_t s : 1;
231  uint8_t qrv : 3;
232 #else
233  uint8_t qrv : 3; //8
234  uint8_t s : 1;
235  uint8_t reserved : 4;
236 #endif
237  uint8_t qqic; //9
238  uint16_t numOfSources; //10-11
241 
242 
243 /**
244  * @brief IGMPv3 Membership Report message
245  **/
246 
247 typedef __packed_struct
248 {
249  uint8_t type; //0
250  uint8_t reserved1; //1
251  uint16_t checksum; //2-3
252  uint16_t reserved2; //4-5
253  uint16_t numOfGroupRecords; //6-7
254  uint8_t groupRecords[]; //8
256 
257 
258 /**
259  * @brief IGMPv3 group record
260  **/
261 
262 typedef __packed_struct
263 {
264  uint8_t recordType; //0
265  uint8_t auxDataLen; //1
266  uint16_t numOfSources; //2-3
268  Ipv4Addr srcAddr[]; //8
270 
271 
272 //CC-RX, CodeWarrior or Win32 compiler?
273 #if defined(__CCRX__)
274  #pragma unpack
275 #elif defined(__CWCC__) || defined(_WIN32)
276  #pragma pack(pop)
277 #endif
278 
279 //Tick counter to handle periodic operations
281 
282 //IGMP related functions
283 error_t igmpInit(NetInterface *interface);
284 void igmpTick(NetInterface *interface);
285 void igmpLinkChangeEvent(NetInterface *interface);
286 
288  NetBuffer *buffer, size_t offset);
289 
290 void igmpProcessMessage(NetInterface *interface,
291  const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer,
292  size_t offset, const NetRxAncillary *ancillary);
293 
295 
296 uint32_t igmpDecodeFloatingPointValue(uint8_t code);
297 
298 //C++ guard
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif
IgmpMembershipReportV3
Definition: igmp_common.h:255
uint8_t code
Definition: coap_common.h:179
uint8_t auxDataLen
Definition: igmp_common.h:265
Ipv4Addr destAddr
Definition: ipv4.h:329
void igmpLinkChangeEvent(NetInterface *interface)
Callback function for link change event.
Definition: igmp_common.c:139
uint8_t maxRespTime
Definition: igmp_common.h:212
IgmpMessage
Definition: igmp_common.h:215
IgmpVersion
IGMP versions.
Definition: igmp_common.h:161
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
IgmpGroupRecordType
IGMPv3 group record types.
Definition: igmp_common.h:187
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp_common.c:72
uint8_t type
Definition: coap_common.h:176
@ IGMP_TYPE_MEMBERSHIP_REPORT_V2
Definition: igmp_common.h:176
error_t igmpSendMessage(NetInterface *interface, Ipv4Addr destAddr, NetBuffer *buffer, size_t offset)
Send IGMP message.
Definition: igmp_common.c:157
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:297
Ipv4Addr srcAddr[]
Definition: igmp_common.h:239
uint8_t reserved
Definition: igmp_common.h:235
@ IGMP_TYPE_MEMBERSHIP_REPORT_V1
Definition: igmp_common.h:175
@ IGMP_TYPE_MEMBERSHIP_QUERY
Definition: igmp_common.h:174
void igmpProcessMessage(NetInterface *interface, const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Process incoming IGMP message.
Definition: igmp_common.c:292
uint16_t checksum
Definition: igmp_common.h:213
error_t
Error codes.
Definition: error.h:43
uint16_t reserved2
Definition: igmp_common.h:252
systime_t igmpGetRandomDelay(systime_t maxDelay)
Generate a random delay.
Definition: igmp_common.c:373
uint16_t numOfGroupRecords
Definition: igmp_common.h:253
@ IGMP_GROUP_RECORD_TYPE_BLOCK
Definition: igmp_common.h:193
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
void igmpTick(NetInterface *interface)
IGMP timer handler.
Definition: igmp_common.c:107
@ IGMP_GROUP_RECORD_TYPE_ALLOW
Definition: igmp_common.h:192
@ IGMP_TYPE_MEMBERSHIP_REPORT_V3
Definition: igmp_common.h:178
#define Ipv4PseudoHeader
Definition: ipv4.h:39
typedef __packed_struct
IGMP message.
Definition: igmp_common.h:210
uint8_t qqic
Definition: igmp_common.h:237
@ IGMP_GROUP_RECORD_TYPE_IS_EX
Definition: igmp_common.h:189
uint8_t qrv
Definition: igmp_common.h:233
uint32_t systime_t
System time.
@ IGMP_GROUP_RECORD_TYPE_TO_EX
Definition: igmp_common.h:191
@ IGMP_VERSION_2
Definition: igmp_common.h:163
IgmpGroupRecord
Definition: igmp_common.h:269
uint8_t reserved1
Definition: igmp_common.h:250
Ipv4Addr groupAddr
Definition: igmp_common.h:214
IgmpType
IGMP message types.
Definition: igmp_common.h:173
@ IGMP_VERSION_3
Definition: igmp_common.h:164
IgmpMembershipQueryV3
Definition: igmp_common.h:240
uint32_t igmpDecodeFloatingPointValue(uint8_t code)
Decode a floating-point value.
Definition: igmp_common.c:398
uint16_t numOfSources
Definition: igmp_common.h:238
@ IGMP_VERSION_1
Definition: igmp_common.h:162
uint8_t s
Definition: igmp_common.h:234
@ IGMP_GROUP_RECORD_TYPE_IS_IN
Definition: igmp_common.h:188
@ IGMP_GROUP_RECORD_TYPE_TO_IN
Definition: igmp_common.h:190
TCP/IP stack core.
systime_t igmpTickCounter
Definition: igmp_common.c:63
uint8_t groupRecords[]
Definition: igmp_common.h:254
uint8_t maxRespCode
Definition: igmp_common.h:225
Ipv4Addr multicastAddr
Definition: igmp_common.h:267
@ IGMP_TYPE_LEAVE_GROUP
Definition: igmp_common.h:177