Contiki-Inga 3.x
uip-icmp6.h
Go to the documentation of this file.
1 /**
2  * \addtogroup uip6
3  * @{
4  */
5 
6 /**
7  * \file
8  * ICMPv6 echo request and error messages (RFC 4443)
9  * \author Julien Abeille <jabeille@cisco.com>
10  * \author Mathilde Durvy <mdurvy@cisco.com>
11  */
12 
13 /*
14  * Copyright (c) 2006, Swedish Institute of Computer Science.
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution.
25  * 3. Neither the name of the Institute nor the names of its contributors
26  * may be used to endorse or promote products derived from this software
27  * without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  * This file is part of the Contiki operating system.
42  *
43  */
44 
45 
46 #ifndef ICMP6_H_
47 #define ICMP6_H_
48 
49 #include "net/ip/uip.h"
50 
51 
52 /** \name ICMPv6 message types */
53 /** @{ */
54 #define ICMP6_DST_UNREACH 1 /**< dest unreachable */
55 #define ICMP6_PACKET_TOO_BIG 2 /**< packet too big */
56 #define ICMP6_TIME_EXCEEDED 3 /**< time exceeded */
57 #define ICMP6_PARAM_PROB 4 /**< ip6 header bad */
58 #define ICMP6_ECHO_REQUEST 128 /**< Echo request */
59 #define ICMP6_ECHO_REPLY 129 /**< Echo reply */
60 
61 #define ICMP6_RS 133 /**< Router Solicitation */
62 #define ICMP6_RA 134 /**< Router Advertisement */
63 #define ICMP6_NS 135 /**< Neighbor Solicitation */
64 #define ICMP6_NA 136 /**< Neighbor advertisement */
65 #define ICMP6_REDIRECT 137 /**< Redirect */
66 
67 #define ICMP6_RPL 155 /**< RPL */
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 /** @} */
74 
75 
76 /** \name ICMPv6 Destination Unreachable message codes*/
77 /** @{ */
78 #define ICMP6_DST_UNREACH_NOROUTE 0 /**< no route to destination */
79 #define ICMP6_DST_UNREACH_ADMIN 1 /**< administratively prohibited */
80 #define ICMP6_DST_UNREACH_NOTNEIGHBOR 2 /**< not a neighbor(obsolete) */
81 #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 /**< beyond scope of source address */
82 #define ICMP6_DST_UNREACH_ADDR 3 /**< address unreachable */
83 #define ICMP6_DST_UNREACH_NOPORT 4 /**< port unreachable */
84 /** @} */
85 
86 /** \name ICMPv6 Time Exceeded message codes*/
87 /** @{ */
88 #define ICMP6_TIME_EXCEED_TRANSIT 0 /**< ttl==0 in transit */
89 #define ICMP6_TIME_EXCEED_REASSEMBLY 1 /**< ttl==0 in reass */
90 /** @} */
91 
92 /** \name ICMPv6 Parameter Problem message codes*/
93 /** @{ */
94 #define ICMP6_PARAMPROB_HEADER 0 /**< erroneous header field */
95 #define ICMP6_PARAMPROB_NEXTHEADER 1 /**< unrecognized next header */
96 #define ICMP6_PARAMPROB_OPTION 2 /**< unrecognized option */
97 /** @} */
98 
99 /** \brief Echo Request constant part length */
100 #define UIP_ICMP6_ECHO_REQUEST_LEN 4
101 
102 /** \brief ICMPv6 Error message constant part length */
103 #define UIP_ICMP6_ERROR_LEN 4
104 
105 /** \brief ICMPv6 Error message constant part */
106 typedef struct uip_icmp6_error{
107  uint32_t param;
109 
110 /** \name ICMPv6 RFC4443 Message processing and sending */
111 /** @{ */
112 /** \
113  * brief Process an echo request
114  *
115  * Perform a few checks, then send an Echo reply. The reply is
116  * built here.
117  */
118 void
120 
121 /** \
122  * brief Process an echo reply
123  *
124  * Perform a few checks, then call applications to inform that an echo
125  * reply has been received.
126  */
127 void
129 
130 /**
131  * \brief Send an icmpv6 error message
132  * \param type type of the error message
133  * \param code of the error message
134  * \param type 32 bit parameter of the error message, semantic depends on error
135  */
136 void
137 uip_icmp6_error_output(uint8_t type, uint8_t code, uint32_t param);
138 
139 /**
140  * \brief Send an icmpv6 message
141  * \param dest destination address of the message
142  * \param type type of the message
143  * \param code of the message
144  * \param payload_len length of the payload
145  */
146 void
147 uip_icmp6_send(const uip_ipaddr_t *dest, int type, int code, int payload_len);
148 
149 
150 
151 typedef void (* uip_icmp6_echo_reply_callback_t)(uip_ipaddr_t *source,
152  uint8_t ttl,
153  uint8_t *data,
154  uint16_t datalen);
155 struct uip_icmp6_echo_reply_notification {
156  struct uip_icmp6_echo_reply_notification *next;
157  uip_icmp6_echo_reply_callback_t callback;
158 };
159 
160 /**
161  * \brief Add a callback function for ping replies
162  * \param n A struct uip_icmp6_echo_reply_notification that must have been allocated by the caller
163  * \param c A pointer to the callback function to be called
164  *
165  * This function adds a callback function to the list of
166  * callback functions that are called when an ICMP echo
167  * reply (ping reply) is received. This is used when
168  * implementing a ping protocol: attach a callback
169  * function to the ping reply, then send out a ping packet
170  * with uip_icmp6_send().
171  *
172  * The caller must have statically allocated a struct
173  * uip_icmp6_echo_reply_notification to hold the internal
174  * state of the callback function.
175  *
176  * When a ping reply packet is received, all registered
177  * callback functions are called. The callback functions
178  * must not modify the contents of the uIP buffer.
179  */
180 void
181 uip_icmp6_echo_reply_callback_add(struct uip_icmp6_echo_reply_notification *n,
182  uip_icmp6_echo_reply_callback_t c);
183 
184 /**
185  * \brief Remove a callback function for ping replies
186  * \param n A struct uip_icmp6_echo_reply_notification that must have been previously added with uip_icmp6_echo_reply_callback_add()
187  *
188  * This function removes a callback function from the list of
189  * callback functions that are called when an ICMP echo
190  * reply (ping reply) is received.
191  */
192 void
193 uip_icmp6_echo_reply_callback_rm(struct uip_icmp6_echo_reply_notification *n);
194 
195 
196 
197 
198 /** @} */
199 
200 #endif /*ICMP6_H_*/
201 /** @} */
202