icmpv6.h
Go to the documentation of this file.
1 /**
2  * @file icmpv6.h
3  * @brief ICMPv6 (Internet Control Message Protocol Version 6)
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 _ICMPV6_H
30 #define _ICMPV6_H
31 
32 //Dependencies
33 #include "core/net.h"
34 
35 //C++ guard
36 #ifdef __cplusplus
37  extern "C" {
38 #endif
39 
40 
41 /**
42  * @brief ICMPv6 message type
43  *
44  * The type field indicates the type of the message. Its
45  * value determines the format of the remaining data
46  *
47  **/
48 
49 typedef enum
50 {
66 } Icmpv6Type;
67 
68 
69 /**
70  * @brief Destination Unreachable message codes
71  **/
72 
73 typedef enum
74 {
81 
82 
83 /**
84  * @brief Time Exceeded message codes
85  **/
86 
87 typedef enum
88 {
92 
93 
94 /**
95  * @brief Parameter Problem message codes
96  **/
97 typedef enum
98 {
103 
104 
105 //CodeWarrior or Win32 compiler?
106 #if defined(__CWCC__) || defined(_WIN32)
107  #pragma pack(push, 1)
108 #endif
109 
110 
111 /**
112  * @brief ICMPv6 header
113  **/
114 
115 typedef __start_packed struct
116 {
117  uint8_t type; //0
118  uint8_t code; //1
119  uint16_t checksum; //2-3
120  uint8_t data[]; //4
122 
123 
124 /**
125  * @brief ICMPv6 Error message
126  **/
127 
128 typedef __start_packed struct
129 {
130  uint8_t type; //0
131  uint8_t code; //1
132  uint16_t checksum; //2-3
133  uint32_t parameter; //4-7
134  uint8_t data[]; //8
136 
137 
138 /**
139  * @brief ICMPv6 Destination Unreachable message
140  *
141  * A Destination Unreachable message is generated in response to a
142  * packet that cannot be delivered to its destination address for
143  * reasons other than congestion
144  *
145  **/
146 
147 typedef __start_packed struct
148 {
149  uint8_t type; //0
150  uint8_t code; //1
151  uint16_t checksum; //2-3
152  uint32_t unused; //4-7
153  uint8_t data[]; //8
155 
156 
157 /**
158  * @brief ICMPv6 Packet Too Big message
159  *
160  * A Packet Too Big message is sent by a router in response
161  * to a packet that it cannot forward because the packet is
162  * larger than the MTU of the outgoing link
163  *
164  **/
165 
166 typedef __start_packed struct
167 {
168  uint8_t type; //0
169  uint8_t code; //1
170  uint16_t checksum; //2-3
171  uint32_t mtu; //4-7
172  uint8_t data[]; //8
174 
175 
176 /**
177  * @brief ICMPv6 Time Exceeded message
178  *
179  * A Time Exceeded message is sent by a router when it receives
180  * a packet with a Hop Limit of zero
181  *
182  **/
183 
184 typedef __start_packed struct
185 {
186  uint8_t type; //0
187  uint8_t code; //1
188  uint16_t checksum; //2-3
189  uint32_t unused; //4-7
190  uint8_t data[]; //8
192 
193 
194 /**
195  * @brief ICMPv6 Parameter Problem message
196  *
197  * A Parameter Problem message is sent by an IPv6 node when it finds a
198  * problem with a field in the IPv6 header or extension headers such
199  * that it cannot complete processing the packet
200  *
201  **/
202 
203 typedef __start_packed struct
204 {
205  uint8_t type; //0
206  uint8_t code; //1
207  uint16_t checksum; //2-3
208  uint32_t pointer; //4-7
209  uint8_t data[]; //8
211 
212 
213 /**
214  * @brief ICMPv6 Echo Request and Echo Reply messages
215  *
216  * Every node must implement an ICMPv6 Echo responder function that
217  * receives Echo Requests and sends corresponding Echo Replies
218  *
219  **/
220 
221 typedef __start_packed struct
222 {
223  uint8_t type; //0
224  uint8_t code; //1
225  uint16_t checksum; //2-3
226  uint16_t identifier; //4-6
227  uint16_t sequenceNumber; //7-8
228  uint8_t data[]; //8
230 
231 
232 //CodeWarrior or Win32 compiler?
233 #if defined(__CWCC__) || defined(_WIN32)
234  #pragma pack(pop)
235 #endif
236 
237 
238 //ICMPv6 related functions
240 
241 void icmpv6ProcessMessage(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader,
242  const NetBuffer *buffer, size_t offset, uint8_t hopLimit);
243 
245  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
246 
248  Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
249 
250 void icmpv6ProcessEchoRequest(NetInterface *interface, Ipv6PseudoHeader *requestPseudoHeader,
251  const NetBuffer *request, size_t requestOffset);
252 
253 error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code,
254  uint32_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset);
255 
261 
262 //C++ guard
263 #ifdef __cplusplus
264  }
265 #endif
266 
267 #endif
__start_packed struct @179 Icmpv6PacketTooBigMessage
ICMPv6 Packet Too Big message.
void icmpv6ProcessMessage(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset, uint8_t hopLimit)
Incoming ICMPv6 message processing.
Definition: icmpv6.c:93
void icmpv6DumpDestUnreachableMessage(const Icmpv6DestUnreachableMessage *message)
Dump ICMPv6 Destination Unreachable message.
Definition: icmpv6.c:633
TCP/IP stack core.
Icmpv6Type
ICMPv6 message type.
Definition: icmpv6.h:49
uint8_t type
Definition: icmpv6.h:117
__start_packed struct @177 Icmpv6ErrorMessage
ICMPv6 Error message.
uint8_t message[]
Definition: chap.h:150
uint16_t sequenceNumber
Definition: icmpv6.h:227
uint8_t code
Definition: icmpv6.h:118
__start_packed struct @176 Icmpv6Header
ICMPv6 header.
uint32_t unused
Definition: icmpv6.h:152
void icmpv6DumpEchoMessage(const Icmpv6EchoMessage *message)
Dump ICMPv6 Echo Request or Echo Reply message.
Definition: icmpv6.c:662
uint32_t pointer
Definition: icmpv6.h:208
Icmpv6DestUnreachableCode
Destination Unreachable message codes.
Definition: icmpv6.h:73
error_t icmpv6EnableMulticastEchoRequest(NetInterface *interface, bool_t enable)
Enable support for multicast Echo Request messages.
Definition: icmpv6.c:66
Icmpv6ParamProblemCode
Parameter Problem message codes.
Definition: icmpv6.h:97
uint16_t identifier
Definition: icmpv6.h:226
uint8_t ipPacket[]
Definition: ndp.h:427
#define Ipv6PseudoHeader
Definition: ipv6.h:40
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:86
void icmpv6ProcessEchoRequest(NetInterface *interface, Ipv6PseudoHeader *requestPseudoHeader, const NetBuffer *request, size_t requestOffset)
Echo Request message processing.
Definition: icmpv6.c:336
uint32_t mtu
Definition: icmpv6.h:171
__start_packed struct @180 Icmpv6TimeExceededMessage
ICMPv6 Time Exceeded message.
__start_packed struct _Ipv4Header __end_packed
void icmpv6ProcessDestUnreachable(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Destination Unreachable message processing.
Definition: icmpv6.c:237
error_t
Error codes.
Definition: error.h:40
__start_packed struct @182 Icmpv6EchoMessage
ICMPv6 Echo Request and Echo Reply messages.
error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code, uint32_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset)
Send an ICMPv6 Error message.
Definition: icmpv6.c:462
#define NetInterface
Definition: net.h:34
__start_packed struct @181 Icmpv6ParamProblemMessage
ICMPv6 Parameter Problem message.
void icmpv6DumpPacketTooBigMessage(const Icmpv6PacketTooBigMessage *message)
Dump ICMPv6 Packet Too Big message.
Definition: icmpv6.c:647
void icmpv6DumpMessage(const Icmpv6Header *message)
Dump ICMPv6 message for debugging purpose.
Definition: icmpv6.c:619
void icmpv6ProcessPacketTooBig(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset)
Packet Too Big message processing.
Definition: icmpv6.c:272
uint32_t parameter
Definition: icmpv6.h:133
uint16_t checksum
Definition: icmpv6.h:119
uint8_t data[]
Definition: icmpv6.h:120
void icmpv6DumpErrorMessage(const Icmpv6ErrorMessage *message)
Dump generic ICMPv6 Error message.
Definition: icmpv6.c:678
__start_packed struct @178 Icmpv6DestUnreachableMessage
ICMPv6 Destination Unreachable message.
int bool_t
Definition: compiler_port.h:47
Icmpv6TimeExceededCode
Time Exceeded message codes.
Definition: icmpv6.h:87