Contiki-NG
Loading...
Searching...
No Matches
uip-icmp6.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006, Swedish Institute of Computer Science.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the Institute nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * This file is part of the Contiki operating system.
30 *
31 */
32
33/**
34 * \addtogroup uip
35 * @{
36 */
37
38/**
39 * \file
40 * Header file for ICMPv6 message and error handing (RFC 4443)
41 * \author Julien Abeille <jabeille@cisco.com>
42 * \author Mathilde Durvy <mdurvy@cisco.com>
43 */
44
45#ifndef ICMP6_H_
46#define ICMP6_H_
47
48#include "net/ipv6/uip.h"
49
50
51/** \name ICMPv6 message types */
52/** @{ */
53#define ICMP6_DST_UNREACH 1 /**< dest unreachable */
54#define ICMP6_PACKET_TOO_BIG 2 /**< packet too big */
55#define ICMP6_TIME_EXCEEDED 3 /**< time exceeded */
56#define ICMP6_PARAM_PROB 4 /**< ip6 header bad */
57#define ICMP6_ECHO_REQUEST 128 /**< Echo request */
58#define ICMP6_ECHO_REPLY 129 /**< Echo reply */
59
60#define ICMP6_RS 133 /**< Router Solicitation */
61#define ICMP6_RA 134 /**< Router Advertisement */
62#define ICMP6_NS 135 /**< Neighbor Solicitation */
63#define ICMP6_NA 136 /**< Neighbor advertisement */
64#define ICMP6_REDIRECT 137 /**< Redirect */
65
66#define ICMP6_RPL 155 /**< RPL */
67#define ICMP6_MPL 159 /**< MPL */
68#define ICMP6_PRIV_EXP_100 100 /**< Private Experimentation */
69#define ICMP6_PRIV_EXP_101 101 /**< Private Experimentation */
70#define ICMP6_PRIV_EXP_200 200 /**< Private Experimentation */
71#define ICMP6_PRIV_EXP_201 201 /**< Private Experimentation */
72#define ICMP6_ROLL_TM ICMP6_PRIV_EXP_200 /**< ROLL Trickle Multicast */
73#define ICMP6_ESMRF ICMP6_PRIV_EXP_201 /**< ESMRF Multicast */
74/** @} */
75
76
77/** \name ICMPv6 Destination Unreachable message codes*/
78/** @{ */
79#define ICMP6_DST_UNREACH_NOROUTE 0 /**< no route to destination */
80#define ICMP6_DST_UNREACH_ADMIN 1 /**< administratively prohibited */
81#define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /**< not a neighbor(obsolete) */
82#define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /**< beyond scope of source address */
83#define ICMP6_DST_UNREACH_ADDR 3 /**< address unreachable */
84#define ICMP6_DST_UNREACH_NOPORT 4 /**< port unreachable */
85/** @} */
86
87/** \name ICMPv6 Time Exceeded message codes*/
88/** @{ */
89#define ICMP6_TIME_EXCEED_TRANSIT 0 /**< ttl==0 in transit */
90#define ICMP6_TIME_EXCEED_REASSEMBLY 1 /**< ttl==0 in reass */
91/** @} */
92
93/** \name ICMPv6 Parameter Problem message codes*/
94/** @{ */
95#define ICMP6_PARAMPROB_HEADER 0 /**< erroneous header field */
96#define ICMP6_PARAMPROB_NEXTHEADER 1 /**< unrecognized next header */
97#define ICMP6_PARAMPROB_OPTION 2 /**< unrecognized option */
98/** @} */
99
100/** \brief Echo Request constant part length */
101#define UIP_ICMP6_ECHO_REQUEST_LEN 4
102
103/** \brief ICMPv6 Error message constant part length */
104#define UIP_ICMP6_ERROR_LEN 4
105
106/** \brief ICMPv6 Error message constant part */
107typedef struct uip_icmp6_error{
108 uint32_t param;
110
111/** \name ICMPv6 RFC4443 Message processing and sending */
112/** @{ */
113/**
114 * \brief Send an icmpv6 error message
115 * \param type type of the error message
116 * \param code of the error message
117 * \param param 32 bit parameter of the error message, semantic depends on error
118 */
119void
120uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param);
121
122/**
123 * \brief Send an icmpv6 message
124 * \param dest destination address of the message
125 * \param type type of the message
126 * \param code of the message
127 * \param payload_len length of the payload
128 */
129void
130uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len);
131
132
133
134typedef void (* uip_icmp6_echo_reply_callback_t)(uip_ipaddr_t *source,
135 uint8_t ttl,
136 uint8_t *data,
137 uint16_t datalen);
138struct uip_icmp6_echo_reply_notification {
139 struct uip_icmp6_echo_reply_notification *next;
140 uip_icmp6_echo_reply_callback_t callback;
141};
142
143/**
144 * \brief Add a callback function for ping replies
145 * \param n A struct uip_icmp6_echo_reply_notification that must have been allocated by the caller
146 * \param c A pointer to the callback function to be called
147 *
148 * This function adds a callback function to the list of
149 * callback functions that are called when an ICMP echo
150 * reply (ping reply) is received. This is used when
151 * implementing a ping protocol: attach a callback
152 * function to the ping reply, then send out a ping packet
153 * with uip_icmp6_send().
154 *
155 * The caller must have statically allocated a struct
156 * uip_icmp6_echo_reply_notification to hold the internal
157 * state of the callback function.
158 *
159 * When a ping reply packet is received, all registered
160 * callback functions are called. The callback functions
161 * must not modify the contents of the uIP buffer.
162 */
163void
164uip_icmp6_echo_reply_callback_add(struct uip_icmp6_echo_reply_notification *n,
165 uip_icmp6_echo_reply_callback_t c);
166
167/**
168 * \brief Remove a callback function for ping replies
169 * \param n A struct uip_icmp6_echo_reply_notification that must have been previously added with uip_icmp6_echo_reply_callback_add()
170 *
171 * This function removes a callback function from the list of
172 * callback functions that are called when an ICMP echo
173 * reply (ping reply) is received.
174 */
175void
176uip_icmp6_echo_reply_callback_rm(struct uip_icmp6_echo_reply_notification *n);
177
178/* Generic ICMPv6 input handers */
179typedef struct uip_icmp6_input_handler {
180 struct uip_icmp6_input_handler *next;
181 void (*handler)(void);
182 uint8_t type;
183 uint8_t icode;
184} uip_icmp6_input_handler_t;
185
186#define UIP_ICMP6_INPUT_SUCCESS 0
187#define UIP_ICMP6_INPUT_ERROR 1
188
189#define UIP_ICMP6_HANDLER_CODE_ANY 0xFF /* Handle all codes for this type */
190
191/*
192 * Initialise a variable of type uip_icmp6_input_handler, to be used later as
193 * the argument to uip_icmp6_register_input_handler
194 *
195 * The function pointer stored in this variable will get called and will be
196 * expected to handle incoming ICMPv6 datagrams of the specified type/code
197 *
198 * If code has a value of UIP_ICMP6_HANDLER_CODE_ANY, the same function
199 * will handle all codes for this type. In other words, the ICMPv6
200 * message's code is "don't care"
201 */
202#define UIP_ICMP6_HANDLER(name, type, code, func) \
203 static uip_icmp6_input_handler_t name = { NULL, func, type, code }
204
205/**
206 * \brief Handle an incoming ICMPv6 message
207 * \param type The ICMPv6 message type
208 * \param icode The ICMPv6 message code
209 * \return Success: UIP_ICMP6_INPUT_SUCCESS, Error: UIP_ICMP6_INPUT_ERROR
210 *
211 * Generic handler for unknown ICMPv6 types. It will lookup for a registered
212 * function capable of handing this message type. The function must have first
213 * been registered with uip_icmp6_register_input_handler. The function is in
214 * charge of setting uip_len to 0, otherwise the uIPv6 core will attempt to
215 * send whatever remains in the UIP_IP_BUF.
216 *
217 * A return value of UIP_ICMP6_INPUT_ERROR means that a handler could not be
218 * invoked. This is most likely because the ICMPv6 type does not have a valid
219 * handler associated with it.
220
221 * UIP_ICMP6_INPUT_SUCCESS signifies that a handler was found for this ICMPv6
222 * type and that it was invoked. It does NOT provide any indication whatsoever
223 * regarding whether the handler itself succeeded.
224 */
225uint8_t uip_icmp6_input(uint8_t type, uint8_t icode);
226
227/**
228 * \brief Register a handler which can handle a specific ICMPv6 message type
229 * \param handler A pointer to the handler
230 */
231void uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler);
232
233
234/**
235 * \brief Initialise the uIP ICMPv6 core
236 */
237void uip_icmp6_init(void);
238
239/** @} */
240
241#endif /*ICMP6_H_*/
242/** @} */
243
void uip_icmp6_echo_reply_callback_rm(struct uip_icmp6_echo_reply_notification *n)
Remove a callback function for ping replies.
Definition uip-icmp6.c:312
void uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param)
Send an icmpv6 error message.
Definition uip-icmp6.c:155
void uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len)
Send an icmpv6 message.
Definition uip-icmp6.c:230
uint8_t uip_icmp6_input(uint8_t type, uint8_t icode)
Handle an incoming ICMPv6 message.
Definition uip-icmp6.c:85
void uip_icmp6_init()
Initialise the uIP ICMPv6 core.
Definition uip-icmp6.c:323
struct uip_icmp6_error uip_icmp6_error
ICMPv6 Error message constant part.
void uip_icmp6_register_input_handler(uip_icmp6_input_handler_t *handler)
Register a handler which can handle a specific ICMPv6 message type.
Definition uip-icmp6.c:102
void uip_icmp6_echo_reply_callback_add(struct uip_icmp6_echo_reply_notification *n, uip_icmp6_echo_reply_callback_t c)
Add a callback function for ping replies.
Definition uip-icmp6.c:302
ICMPv6 Error message constant part.
Definition uip-icmp6.h:107
Header file for the uIP TCP/IP stack.