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  * Copyright (C) 2010-2018 Oryx Embedded SARL. All rights reserved.
8  *
9  * This file is part of CycloneTCP Open.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software Foundation,
23  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24  *
25  * @author Oryx Embedded SARL (www.oryx-embedded.com)
26  * @version 1.9.0
27  **/
28 
29 #ifndef _IGMP_H
30 #define _IGMP_H
31 
32 //Dependencies
33 #include "core/net.h"
34 
35 //IGMP support
36 #ifndef IGMP_SUPPORT
37  #define IGMP_SUPPORT DISABLED
38 #elif (IGMP_SUPPORT != ENABLED && IGMP_SUPPORT != DISABLED)
39  #error IGMP_SUPPORT parameter is not valid
40 #endif
41 
42 //IGMP tick interval
43 #ifndef IGMP_TICK_INTERVAL
44  #define IGMP_TICK_INTERVAL 1000
45 #elif (IGMP_TICK_INTERVAL < 10)
46  #error IGMP_TICK_INTERVAL parameter is not valid
47 #endif
48 
49 //Unsolicited report interval
50 #ifndef IGMP_UNSOLICITED_REPORT_INTERVAL
51  #define IGMP_UNSOLICITED_REPORT_INTERVAL 10000
52 #elif (IGMP_UNSOLICITED_REPORT_INTERVAL < 1000)
53  #error IGMP_UNSOLICITED_REPORT_INTERVAL parameter is not valid
54 #endif
55 
56 //Maximum response time for IGMPv1 queries
57 #ifndef IGMP_V1_MAX_RESPONSE_TIME
58  #define IGMP_V1_MAX_RESPONSE_TIME 10000
59 #elif (IGMP_V1_MAX_RESPONSE_TIME < 1000)
60  #error IGMP_V1_MAX_RESPONSE_TIME parameter is not valid
61 #endif
62 
63 //Older version querier present timeout
64 #ifndef IGMP_V1_ROUTER_PRESENT_TIMEOUT
65  #define IGMP_V1_ROUTER_PRESENT_TIMEOUT 400000
66 #elif (IGMP_V1_ROUTER_PRESENT_TIMEOUT < 1000)
67  #error IGMP_V1_ROUTER_PRESENT_TIMEOUT parameter is not valid
68 #endif
69 
70 //TTL used by IGMP messages
71 #define IGMP_TTL 1
72 
73 //All-Systems address
74 #define IGMP_ALL_SYSTEMS_ADDR IPV4_ADDR(224, 0, 0, 1)
75 //All-Routers address
76 #define IGMP_ALL_ROUTERS_ADDR IPV4_ADDR(224, 0, 0, 2)
77 
78 //C++ guard
79 #ifdef __cplusplus
80  extern "C" {
81 #endif
82 
83 
84 /**
85  * @brief IGMP host states
86  **/
87 
88 typedef enum
89 {
93 } IgmpState;
94 
95 
96 /**
97  * @brief IGMP message type
98  **/
99 
100 typedef enum
101 {
107 } IgmpType;
108 
109 
110 //CodeWarrior or Win32 compiler?
111 #if defined(__CWCC__) || defined(_WIN32)
112  #pragma pack(push, 1)
113 #endif
114 
115 
116 /**
117  * @brief General IGMP message format
118  **/
119 
120 typedef __start_packed struct
121 {
122  uint8_t type; //0
123  uint8_t maxRespTime; //1
124  uint16_t checksum; //2-3
127 
128 
129 //CodeWarrior or Win32 compiler?
130 #if defined(__CWCC__) || defined(_WIN32)
131  #pragma pack(pop)
132 #endif
133 
134 
135 //Tick counter to handle periodic operations
137 
138 //IGMP related functions
139 error_t igmpInit(NetInterface *interface);
142 
143 void igmpTick(NetInterface *interface);
144 void igmpLinkChangeEvent(NetInterface *interface);
145 
146 void igmpProcessMessage(NetInterface *interface,
147  const NetBuffer *buffer, size_t offset);
148 
149 void igmpProcessQueryMessage(NetInterface *interface,
150  const IgmpMessage *message, size_t length);
151 
152 void igmpProcessReportMessage(NetInterface *interface,
153  const IgmpMessage *message, size_t length);
154 
157 
158 uint32_t igmpRand(uint32_t max);
159 
160 void igmpDumpMessage(const IgmpMessage *message);
161 
162 //C++ guard
163 #ifdef __cplusplus
164  }
165 #endif
166 
167 #endif
error_t igmpLeaveGroup(NetInterface *interface, Ipv4FilterEntry *entry)
Leave the specified host group.
Definition: igmp.c:131
void igmpDumpMessage(const IgmpMessage *message)
Dump IGMP message for debugging purpose.
Definition: igmp.c:623
uint32_t Ipv4Addr
IPv4 network address.
Definition: ipv4.h:232
uint32_t systime_t
Definition: compiler_port.h:44
uint32_t igmpRand(uint32_t max)
Get a random value in the specified range.
Definition: igmp.c:611
void igmpLinkChangeEvent(NetInterface *interface)
Callback function for link change event.
Definition: igmp.c:205
Ipv4Addr groupAddr
Definition: igmp.h:125
TCP/IP stack core.
uint8_t message[]
Definition: chap.h:150
IgmpState
IGMP host states.
Definition: igmp.h:88
uint8_t ipAddr[4]
Definition: mib_common.h:185
void igmpProcessMessage(NetInterface *interface, const NetBuffer *buffer, size_t offset)
Process incoming IGMP message.
Definition: igmp.c:278
systime_t igmpTickCounter
Definition: igmp.c:51
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
void igmpProcessReportMessage(NetInterface *interface, const IgmpMessage *message, size_t length)
Process incoming Membership Report message.
Definition: igmp.c:434
__start_packed struct _Ipv4Header __end_packed
error_t
Error codes.
Definition: error.h:40
#define NetInterface
Definition: net.h:34
void igmpProcessQueryMessage(NetInterface *interface, const IgmpMessage *message, size_t length)
Process incoming Membership Query message.
Definition: igmp.c:347
__start_packed struct @173 IgmpMessage
General IGMP message format.
void igmpTick(NetInterface *interface)
IGMP timer handler.
Definition: igmp.c:158
error_t igmpInit(NetInterface *interface)
IGMP initialization.
Definition: igmp.c:60
uint8_t type
Definition: igmp.h:122
error_t igmpSendReportMessage(NetInterface *interface, Ipv4Addr ipAddr)
Send Membership Report message.
Definition: igmp.c:474
uint8_t maxRespTime
Definition: igmp.h:123
uint8_t length
Definition: dtls_misc.h:140
IgmpType
IGMP message type.
Definition: igmp.h:100
error_t igmpSendLeaveGroupMessage(NetInterface *interface, Ipv4Addr ipAddr)
Send Leave Group message.
Definition: igmp.c:543
IPv4 multicast filter entry.
Definition: ipv4.h:303
uint16_t checksum
Definition: igmp.h:124
error_t igmpJoinGroup(NetInterface *interface, Ipv4FilterEntry *entry)
Join the specified host group.
Definition: igmp.c:81