mld_common.h
Go to the documentation of this file.
1 /**
2  * @file mld_common.h
3  * @brief Definitions common to MLD node, 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 _MLD_COMMON_H
32 #define _MLD_COMMON_H
33 
34 //Dependencies
35 #include "core/net.h"
36 
37 //MLD tick interval
38 #ifndef MLD_TICK_INTERVAL
39  #define MLD_TICK_INTERVAL 200
40 #elif (MLD_TICK_INTERVAL < 10)
41  #error MLD_TICK_INTERVAL parameter is not valid
42 #endif
43 
44 //Robustness Variable
45 #ifndef MLD_ROBUSTNESS_VARIABLE
46  #define MLD_ROBUSTNESS_VARIABLE 2
47 #elif (MLD_ROBUSTNESS_VARIABLE < 1)
48  #error MLD_ROBUSTNESS_VARIABLE parameter is not valid
49 #endif
50 
51 //Unsolicited report interval
52 #ifndef MLD_UNSOLICITED_REPORT_INTERVAL
53  #define MLD_UNSOLICITED_REPORT_INTERVAL 10000
54 #elif (MLD_UNSOLICITED_REPORT_INTERVAL < 1000)
55  #error MLD_UNSOLICITED_REPORT_INTERVAL parameter is not valid
56 #endif
57 
58 //Older Version Querier Present Timeout
59 #ifndef MLD_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT
60  #define MLD_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT 400000
61 #elif (MLD_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT < 1000)
62  #error MLD_OLDER_VERSION_QUERIER_PRESENT_TIMEOUT parameter is not valid
63 #endif
64 
65 //Unsolicited Report Interval (MLDv2)
66 #ifndef MLD_V2_UNSOLICITED_REPORT_INTERVAL
67  #define MLD_V2_UNSOLICITED_REPORT_INTERVAL 1000
68 #elif (MLD_V2_UNSOLICITED_REPORT_INTERVAL < 1000)
69  #error MLD_V2_UNSOLICITED_REPORT_INTERVAL parameter is not valid
70 #endif
71 
72 //Maximum size of MLD messages
73 #ifndef MLD_MAX_MSG_SIZE
74  #define MLD_MAX_MSG_SIZE 1024
75 #elif (MLD_MAX_MSG_SIZE < 1)
76  #error MLD_MAX_MSG_SIZE parameter is not valid
77 #endif
78 
79 //Hop Limit used by MLD messages
80 #define MLD_HOP_LIMIT 1
81 
82 //C++ guard
83 #ifdef __cplusplus
84 extern "C" {
85 #endif
86 
87 
88 /**
89  * @brief MLD versions
90  **/
91 
92 typedef enum
93 {
95  MLD_VERSION_2 = 2
97 
98 
99 /**
100  * @brief MLDv2 multicast address record types
101  **/
102 
103 typedef enum
104 {
112 
113 
114 //CC-RX, CodeWarrior or Win32 compiler?
115 #if defined(__CCRX__)
116  #pragma pack
117 #elif defined(__CWCC__) || defined(_WIN32)
118  #pragma pack(push, 1)
119 #endif
120 
121 
122 /**
123  * @brief MLD message
124  **/
125 
127 {
128  uint8_t type; //0
129  uint8_t code; //1
130  uint16_t checksum; //2-3
131  uint16_t maxRespDelay; //4-5
132  uint16_t reserved; //6-7
135 
136 
137 /**
138  * @brief MLDv2 Query message
139  **/
140 
141 typedef __packed_struct
142 {
143  uint8_t type; //0
144  uint8_t code; //1
145  uint16_t checksum; //2-3
146  uint16_t maxRespCode; //4-5
147  uint16_t reserved1; //6-7
148  Ipv6Addr multicastAddr; //8-23
149 #if defined(_CPU_BIG_ENDIAN) && !defined(__ICCRX__)
150  uint8_t reserved2 : 4; //24
151  uint8_t s : 1;
152  uint8_t qrv : 3;
153 #else
154  uint8_t qrv : 3; //24
155  uint8_t s : 1;
156  uint8_t reserved2 : 4;
157 #endif
158  uint8_t qqic; //25
159  uint16_t numOfSources; //26-27
162 
163 
164 /**
165  * @brief MLDv2 Report message
166  **/
167 
168 typedef __packed_struct
169 {
170  uint8_t type; //0
171  uint8_t reserved1; //1
172  uint16_t checksum; //2-3
173  uint16_t reserved2; //4-5
174  uint16_t numOfMcastAddrRecords; //6-7
175  uint8_t mcastAddrRecords[]; //8
177 
178 
179 /**
180  * @brief MLDv2 multicast address record
181  **/
182 
183 typedef __packed_struct
184 {
185  uint8_t recordType; //0
186  uint8_t auxDataLen; //1
187  uint16_t numOfSources; //2-3
188  Ipv6Addr multicastAddr; //4-19
189  Ipv6Addr srcAddr[]; //20
191 
192 
193 //CC-RX, CodeWarrior or Win32 compiler?
194 #if defined(__CCRX__)
195  #pragma unpack
196 #elif defined(__CWCC__) || defined(_WIN32)
197  #pragma pack(pop)
198 #endif
199 
200 //MLD related constants
201 extern const Ipv6Addr MLD_V2_ALL_ROUTERS_ADDR;
202 
203 //Tick counter to handle periodic operations
205 
206 //MLD related functions
207 error_t mldInit(NetInterface *interface);
208 void mldTick(NetInterface *interface);
209 void mldLinkChangeEvent(NetInterface *interface);
210 
212  NetBuffer *buffer, size_t offset);
213 
214 void mldProcessMessage(NetInterface *interface,
215  const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer,
216  size_t offset, const NetRxAncillary *ancillary);
217 
219 
220 uint32_t mldDecodeFloatingPointValue8(uint8_t code);
221 uint32_t mldDecodeFloatingPointValue16(uint16_t code);
222 
223 //C++ guard
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 #endif
MldMcastAddrRecordType
MLDv2 multicast address record types.
Definition: mld_common.h:104
Ipv4Addr destAddr
Definition: ipv4.h:329
void mldProcessMessage(NetInterface *interface, const Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, const NetRxAncillary *ancillary)
Process incoming MLD message.
Definition: mld_common.c:226
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:89
uint32_t mldDecodeFloatingPointValue8(uint8_t code)
Decode a floating-point value (8-bit code)
Definition: mld_common.c:294
MldMessage
Definition: mld_common.h:134
uint8_t qqic
Definition: mld_common.h:158
Ipv6Addr
Definition: ipv6.h:260
@ MLD_MCAST_ADDR_RECORD_TYPE_IS_EX
Definition: mld_common.h:106
uint8_t type
Definition: coap_common.h:176
systime_t mldGetRandomDelay(systime_t maxDelay)
Generate a random delay.
Definition: mld_common.c:269
@ MLD_MCAST_ADDR_RECORD_TYPE_IS_IN
Definition: mld_common.h:105
@ MLD_VERSION_1
Definition: mld_common.h:94
uint8_t code
Definition: mld_common.h:129
MldMcastAddrRecord
Definition: mld_common.h:190
@ MLD_MCAST_ADDR_RECORD_TYPE_TO_IN
Definition: mld_common.h:107
uint16_t reserved1
Definition: mld_common.h:147
uint16_t reserved
Definition: mld_common.h:132
uint16_t maxRespDelay
Definition: mld_common.h:131
error_t
Error codes.
Definition: error.h:43
error_t mldInit(NetInterface *interface)
MLD initialization.
Definition: mld_common.c:72
error_t mldSendMessage(NetInterface *interface, const Ipv6Addr *destAddr, NetBuffer *buffer, size_t offset)
Send MLD message.
Definition: mld_common.c:136
#define Ipv6PseudoHeader
Definition: ipv6.h:42
Ipv6Addr srcAddr[]
Definition: mld_common.h:160
uint8_t auxDataLen
Definition: mld_common.h:186
#define NetRxAncillary
Definition: net_misc.h:40
#define NetInterface
Definition: net.h:36
typedef __packed_struct
MLD message.
Definition: mld_common.h:127
uint16_t maxRespCode
Definition: mld_common.h:146
uint16_t numOfMcastAddrRecords
Definition: mld_common.h:174
MldListenerReportV2
Definition: mld_common.h:176
Ipv6Addr multicastAddr
Definition: mld_common.h:133
uint8_t mcastAddrRecords[]
Definition: mld_common.h:175
uint32_t systime_t
System time.
uint8_t qrv
Definition: mld_common.h:154
uint32_t mldDecodeFloatingPointValue16(uint16_t code)
Decode a floating-point value (16-bit code)
Definition: mld_common.c:315
@ MLD_MCAST_ADDR_RECORD_TYPE_TO_EX
Definition: mld_common.h:108
void mldLinkChangeEvent(NetInterface *interface)
Callback function for link change event.
Definition: mld_common.c:118
MldVersion
MLD versions.
Definition: mld_common.h:93
@ MLD_MCAST_ADDR_RECORD_TYPE_BLOCK
Definition: mld_common.h:110
void mldTick(NetInterface *interface)
MLD node timer handler.
Definition: mld_common.c:104
systime_t mldTickCounter
Definition: mld_common.c:63
MldListenerQueryV2
Definition: mld_common.h:161
TCP/IP stack core.
@ MLD_VERSION_2
Definition: mld_common.h:95
@ MLD_MCAST_ADDR_RECORD_TYPE_ALLOW
Definition: mld_common.h:109
uint8_t s
Definition: mld_common.h:155
const Ipv6Addr MLD_V2_ALL_ROUTERS_ADDR
Definition: mld_common.c:59
uint16_t numOfSources
Definition: mld_common.h:159
uint8_t reserved2
Definition: mld_common.h:156
uint16_t checksum
Definition: mld_common.h:130