igmp.h
Go to the documentation of this file.
1 /**
2  * @file igmp.h
3  * @brief IGMP (Internet Group Management Protocol)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2020 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 1.9.8
29  **/
30 
31 #ifndef _IGMP_H
32 #define _IGMP_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //IGMP support
38 #ifndef IGMP_SUPPORT
39  #define IGMP_SUPPORT DISABLED
40 #elif (IGMP_SUPPORT != ENABLED && IGMP_SUPPORT != DISABLED)
41  #error IGMP_SUPPORT parameter is not valid
42 #endif
43 
44 //IGMP tick interval
45 #ifndef IGMP_TICK_INTERVAL
46  #define IGMP_TICK_INTERVAL 1000
47 #elif (IGMP_TICK_INTERVAL < 10)
48  #error IGMP_TICK_INTERVAL parameter is not valid
49 #endif
50 
51 //Unsolicited report interval
52 #ifndef IGMP_UNSOLICITED_REPORT_INTERVAL
53  #define IGMP_UNSOLICITED_REPORT_INTERVAL 10000
54 #elif (IGMP_UNSOLICITED_REPORT_INTERVAL < 1000)
55  #error IGMP_UNSOLICITED_REPORT_INTERVAL parameter is not valid
56 #endif
57 
58 //Maximum response time for IGMPv1 queries
59 #ifndef IGMP_V1_MAX_RESPONSE_TIME
60  #define IGMP_V1_MAX_RESPONSE_TIME 10000
61 #elif (IGMP_V1_MAX_RESPONSE_TIME < 1000)
62  #error IGMP_V1_MAX_RESPONSE_TIME parameter is not valid
63 #endif
64 
65 //Older version querier present timeout
66 #ifndef IGMP_V1_ROUTER_PRESENT_TIMEOUT
67  #define IGMP_V1_ROUTER_PRESENT_TIMEOUT 400000
68 #elif (IGMP_V1_ROUTER_PRESENT_TIMEOUT < 1000)
69  #error IGMP_V1_ROUTER_PRESENT_TIMEOUT parameter is not valid
70 #endif
71 
72 //TTL used by IGMP messages
73 #define IGMP_TTL 1
74 
75 //All-Systems address
76 #define IGMP_ALL_SYSTEMS_ADDR IPV4_ADDR(224, 0, 0, 1)
77 //All-Routers address
78 #define IGMP_ALL_ROUTERS_ADDR IPV4_ADDR(224, 0, 0, 2)
79 
80 //C++ guard
81 #ifdef __cplusplus
82 extern "C" {
83 #endif
84 
85 
86 /**
87  * @brief IGMP host states
88  **/
89 
90 typedef enum
91 {
95 } IgmpState;
96 
97 
98 /**
99  * @brief IGMP message type
100  **/
101 
102 typedef enum
103 {
109 } IgmpType;
110 
111 
112 //CodeWarrior or Win32 compiler?
113 #if defined(__CWCC__) || defined(_WIN32)
114  #pragma pack(push, 1)
115 #endif
116 
117 
118 /**
119  * @brief General IGMP message format
120  **/
121 
122 typedef __start_packed struct
123 {
124  uint8_t type; //0
125  uint8_t maxRespTime; //1
126  uint16_t checksum; //2-3
129 
130 
131 //CodeWarrior or Win32 compiler?
132 #if defined(__CWCC__) || defined(_WIN32)
133  #pragma pack(pop)
134 #endif
135 
136 
137 //Tick counter to handle periodic operations
139 
140 //IGMP related functions
141 error_t igmpInit(NetInterface *interface);
144 
145 void igmpTick(NetInterface *interface);
146 void igmpLinkChangeEvent(NetInterface *interface);
147 
148 void igmpProcessMessage(NetInterface *interface,
149  const NetBuffer *buffer, size_t offset);
150 
151 void igmpProcessQueryMessage(NetInterface *interface,
152  const IgmpMessage *message, size_t length);
153 
154 void igmpProcessReportMessage(NetInterface *interface,
155  const IgmpMessage *message, size_t length);
156 
159 
160 uint32_t igmpRand(uint32_t max);
161 
162 void igmpDumpMessage(const IgmpMessage *message);
163 
164 //C++ guard
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif
uint8_t length
Definition: coap_common.h:190
__start_packed struct @67 IgmpMessage
General IGMP message format.
void igmpDumpMessage(const IgmpMessage *message)
Dump IGMP message for debugging purpose.
Definition: igmp.c:639
void igmpProcessMessage(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Process incoming IGMP message.
Definition: igmp.c:280
error_t igmpSendLeaveGroupMessage(NetInterface *interface, Ipv4Addr ipAddr)
Send Leave Group message.
Definition: igmp.c:552
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
error_t igmpSendReportMessage(NetInterface *interface, Ipv4Addr ipAddr)
Send Membership Report message.
Definition: igmp.c:476
systime_t igmpTickCounter
Definition: igmp.c:53
uint32_t igmpRand(uint32_t max)
Get a random value in the specified range.
Definition: igmp.c:627
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:239
error_t igmpJoinGroup(NetInterface *interface, Ipv4FilterEntry *entry)
Join the specified host group.
Definition: igmp.c:83
error_t
Error codes.
Definition: error.h:42
void igmpProcessQueryMessage(NetInterface *interface, const IgmpMessage *message, size_t length)
Process incoming Membership Query message.
Definition: igmp.c:349
#define NetInterface
Definition: net.h:36
error_t igmpLeaveGroup(NetInterface *interface, Ipv4FilterEntry *entry)
Leave the specified host group.
Definition: igmp.c:133
__start_packed struct _Ipv4Header __end_packed
IPv4 multicast filter entry.
Definition: ipv4.h:324
void igmpLinkChangeEvent(NetInterface *interface)
Callback function for link change event.
Definition: igmp.c:207
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp.c:62
IgmpState
IGMP host states.
Definition: igmp.h:90
void igmpTick(NetInterface *interface)
IGMP timer handler.
Definition: igmp.c:160
uint8_t message[]
Definition: chap.h:152
Ipv4Addr groupAddr
Definition: igmp.h:127
uint8_t maxRespTime
Definition: igmp.h:125
uint8_t type
Definition: igmp.h:124
TCP/IP stack core.
uint16_t checksum
Definition: igmp.h:126
void igmpProcessReportMessage(NetInterface *interface, const IgmpMessage *message, size_t length)
Process incoming Membership Report message.
Definition: igmp.c:436
uint32_t systime_t
Definition: compiler_port.h:46
uint8_t ipAddr[4]
Definition: mib_common.h:187
IgmpType
IGMP message type.
Definition: igmp.h:102