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.0
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 1000
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 //Version 1 Router Present Timeout
113 #ifndef IGMP_V1_ROUTER_PRESENT_TIMEOUT
114  #define IGMP_V1_ROUTER_PRESENT_TIMEOUT 400000
115 #elif (IGMP_V1_ROUTER_PRESENT_TIMEOUT < 1000)
116  #error IGMP_V1_ROUTER_PRESENT_TIMEOUT parameter is not valid
117 #endif
118 
119 //Maximum response time for IGMPv1 queries
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 //TTL used by IGMP messages
127 #define IGMP_TTL 1
128 
129 //All-Systems address
130 #define IGMP_ALL_SYSTEMS_ADDR IPV4_ADDR(224, 0, 0, 1)
131 //All-Routers address
132 #define IGMP_ALL_ROUTERS_ADDR IPV4_ADDR(224, 0, 0, 2)
133 
134 //C++ guard
135 #ifdef __cplusplus
136 extern "C" {
137 #endif
138 
139 
140 /**
141  * @brief IGMP message type
142  **/
143 
144 typedef enum
145 {
152 
153 
154 //CC-RX, CodeWarrior or Win32 compiler?
155 #if defined(__CCRX__)
156  #pragma pack
157 #elif defined(__CWCC__) || defined(_WIN32)
158  #pragma pack(push, 1)
159 #endif
160 
161 
162 /**
163  * @brief General IGMP message format
164  **/
165 
167 {
168  uint8_t type; //0
169  uint8_t maxRespTime; //1
170  uint16_t checksum; //2-3
173 
174 
175 //CC-RX, CodeWarrior or Win32 compiler?
176 #if defined(__CCRX__)
177  #pragma unpack
178 #elif defined(__CWCC__) || defined(_WIN32)
179  #pragma pack(pop)
180 #endif
181 
182 //Tick counter to handle periodic operations
184 
185 //IGMP related functions
186 error_t igmpInit(NetInterface *interface);
187 void igmpTick(NetInterface *interface);
188 void igmpLinkChangeEvent(NetInterface *interface);
189 
191  const IgmpMessage *message, size_t length);
192 
193 void igmpProcessMessage(NetInterface *interface,
194  const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer,
195  size_t offset, const NetRxAncillary *ancillary);
196 
197 void igmpDumpMessage(const IgmpMessage *message);
198 
199 //C++ guard
200 #ifdef __cplusplus
201 }
202 #endif
203 
204 #endif
uint8_t message[]
Definition: chap.h:154
uint8_t type
Definition: coap_common.h:176
error_t
Error codes.
Definition: error.h:43
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp_common.c:59
systime_t igmpTickCounter
Definition: igmp_common.c:50
void igmpLinkChangeEvent(NetInterface *interface)
Callback function for link change event.
Definition: igmp_common.c:123
IgmpMessage
Definition: igmp_common.h:172
uint16_t checksum
Definition: igmp_common.h:170
IgmpType
IGMP message type.
Definition: igmp_common.h:145
@ IGMP_TYPE_MEMBERSHIP_REPORT_V3
Definition: igmp_common.h:150
@ IGMP_TYPE_LEAVE_GROUP
Definition: igmp_common.h:149
@ IGMP_TYPE_MEMBERSHIP_REPORT_V2
Definition: igmp_common.h:148
@ IGMP_TYPE_MEMBERSHIP_REPORT_V1
Definition: igmp_common.h:147
@ IGMP_TYPE_MEMBERSHIP_QUERY
Definition: igmp_common.h:146
void igmpDumpMessage(const IgmpMessage *message)
Dump IGMP message for debugging purpose.
Definition: igmp_common.c:339
Ipv4Addr groupAddr
Definition: igmp_common.h:171
void igmpProcessMessage(NetInterface *interface, const Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Process incoming IGMP message.
Definition: igmp_common.c:259
typedef __packed_struct
General IGMP message format.
Definition: igmp_common.h:167
uint8_t maxRespTime
Definition: igmp_common.h:169
error_t igmpSendMessage(NetInterface *interface, Ipv4Addr destAddr, const IgmpMessage *message, size_t length)
Send IGMP message.
Definition: igmp_common.c:141
void igmpTick(NetInterface *interface)
IGMP timer handler.
Definition: igmp_common.c:91
#define Ipv4PseudoHeader
Definition: ipv4.h:39
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:267
Ipv4Addr destAddr
Definition: ipv4.h:299
TCP/IP stack core.
#define NetInterface
Definition: net.h:36
#define NetRxAncillary
Definition: net_misc.h:40
uint32_t systime_t
System time.
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint8_t length
Definition: tcp.h:368