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-2022 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.2.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 //CodeWarrior or Win32 compiler?
155 #if defined(__CWCC__) || defined(_WIN32)
156  #pragma pack(push, 1)
157 #endif
158 
159 
160 /**
161  * @brief General IGMP message format
162  **/
163 
164 typedef __start_packed struct
165 {
166  uint8_t type; //0
167  uint8_t maxRespTime; //1
168  uint16_t checksum; //2-3
171 
172 
173 //CodeWarrior or Win32 compiler?
174 #if defined(__CWCC__) || defined(_WIN32)
175  #pragma pack(pop)
176 #endif
177 
178 //Tick counter to handle periodic operations
180 
181 //IGMP related functions
182 error_t igmpInit(NetInterface *interface);
183 void igmpTick(NetInterface *interface);
184 void igmpLinkChangeEvent(NetInterface *interface);
185 
187  const IgmpMessage *message, size_t length);
188 
189 void igmpProcessMessage(NetInterface *interface,
190  Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer,
191  size_t offset, NetRxAncillary *ancillary);
192 
193 void igmpDumpMessage(const IgmpMessage *message);
194 
195 //C++ guard
196 #ifdef __cplusplus
197 }
198 #endif
199 
200 #endif
uint8_t length
Definition: coap_common.h:193
void igmpLinkChangeEvent(NetInterface *interface)
Callback function for link change event.
Definition: igmp_common.c:123
uint8_t maxRespTime
Definition: igmp_common.h:167
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp_common.c:59
uint8_t type
Definition: igmp_common.h:166
__start_packed struct @0 IgmpMessage
General IGMP message format.
@ IGMP_TYPE_MEMBERSHIP_REPORT_V2
Definition: igmp_common.h:148
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:261
void igmpProcessMessage(NetInterface *interface, Ipv4PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, NetRxAncillary *ancillary)
Process incoming IGMP message.
Definition: igmp_common.c:259
MacAddr destAddr
Definition: ethernet.h:217
@ IGMP_TYPE_MEMBERSHIP_REPORT_V1
Definition: igmp_common.h:147
@ IGMP_TYPE_MEMBERSHIP_QUERY
Definition: igmp_common.h:146
uint16_t checksum
Definition: igmp_common.h:168
error_t
Error codes.
Definition: error.h:43
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
void igmpTick(NetInterface *interface)
IGMP timer handler.
Definition: igmp_common.c:91
__start_packed struct _Ipv4Header __end_packed
@ IGMP_TYPE_MEMBERSHIP_REPORT_V3
Definition: igmp_common.h:150
#define Ipv4PseudoHeader
Definition: ipv4.h:39
uint32_t systime_t
System time.
error_t igmpSendMessage(NetInterface *interface, Ipv4Addr destAddr, const IgmpMessage *message, size_t length)
Send IGMP message.
Definition: igmp_common.c:141
Ipv4Addr groupAddr
Definition: igmp_common.h:169
IgmpType
IGMP message type.
Definition: igmp_common.h:145
uint8_t message[]
Definition: chap.h:152
TCP/IP stack core.
systime_t igmpTickCounter
Definition: igmp_common.c:50
void igmpDumpMessage(const IgmpMessage *message)
Dump IGMP message for debugging purpose.
Definition: igmp_common.c:339
@ IGMP_TYPE_LEAVE_GROUP
Definition: igmp_common.h:149