Webserver+3d print

Dependents:   Nucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers icmpv6.h Source File

icmpv6.h

Go to the documentation of this file.
00001 /**
00002  * @file icmpv6.h
00003  * @brief ICMPv6 (Internet Control Message Protocol Version 6)
00004  *
00005  * @section License
00006  *
00007  * Copyright (C) 2010-2017 Oryx Embedded SARL. All rights reserved.
00008  *
00009  * This file is part of CycloneTCP Open.
00010  *
00011  * This program is free software; you can redistribute it and/or
00012  * modify it under the terms of the GNU General Public License
00013  * as published by the Free Software Foundation; either version 2
00014  * of the License, or (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software Foundation,
00023  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00024  *
00025  * @author Oryx Embedded SARL (www.oryx-embedded.com)
00026  * @version 1.7.6
00027  **/
00028 
00029 #ifndef _ICMPV6_H
00030 #define _ICMPV6_H
00031 
00032 //Dependencies
00033 #include "core/net.h"
00034 
00035 
00036 /**
00037  * @brief ICMPv6 message type
00038  *
00039  * The type field indicates the type of the message. Its
00040  * value determines the format of the remaining data
00041  *
00042  **/
00043 
00044 typedef enum
00045 {
00046    ICMPV6_TYPE_DEST_UNREACHABLE             = 1,
00047    ICMPV6_TYPE_PACKET_TOO_BIG               = 2,
00048    ICMPV6_TYPE_TIME_EXCEEDED                = 3,
00049    ICMPV6_TYPE_PARAM_PROBLEM                = 4,
00050    ICMPV6_TYPE_ECHO_REQUEST                 = 128,
00051    ICMPV6_TYPE_ECHO_REPLY                   = 129,
00052    ICMPV6_TYPE_MULTICAST_LISTENER_QUERY     = 130,
00053    ICMPV6_TYPE_MULTICAST_LISTENER_REPORT_V1 = 131,
00054    ICMPV6_TYPE_MULTICAST_LISTENER_DONE_V1   = 132,
00055    ICMPV6_TYPE_ROUTER_SOL                   = 133,
00056    ICMPV6_TYPE_ROUTER_ADV                   = 134,
00057    ICMPV6_TYPE_NEIGHBOR_SOL                 = 135,
00058    ICMPV6_TYPE_NEIGHBOR_ADV                 = 136,
00059    ICMPV6_TYPE_REDIRECT                     = 137,
00060    ICMPV6_TYPE_MULTICAST_LISTENER_REPORT_V2 = 143
00061 } Icmpv6Type;
00062 
00063 
00064 /**
00065  * @brief Destination Unreachable message codes
00066  **/
00067 
00068 typedef enum
00069 {
00070    ICMPV6_CODE_NO_ROUTE_TO_DEST         = 0,
00071    ICMPV6_CODE_ADMIN_PROHIBITED         = 1,
00072    ICMPV6_CODE_BEYOND_SCOPE_OF_SRC_ADDR = 2,
00073    ICMPV6_CODE_ADDR_UNREACHABLE         = 3,
00074    ICMPV6_CODE_PORT_UNREACHABLE         = 4
00075 } Icmpv6DestUnreachableCode;
00076 
00077 
00078 /**
00079  * @brief Time Exceeded message codes
00080  **/
00081 
00082 typedef enum
00083 {
00084    ICMPV6_CODE_HOP_LIMIT_EXCEEDED       = 0,
00085    ICMPV6_CODE_REASSEMBLY_TIME_EXCEEDED = 1
00086 } Icmpv6TimeExceededCode;
00087 
00088 
00089 /**
00090  * @brief Parameter Problem message codes
00091  **/
00092 typedef enum
00093 {
00094    ICMPV6_CODE_INVALID_HEADER_FIELD = 0,
00095    ICMPV6_CODE_UNKNOWN_NEXT_HEADER  = 1,
00096    ICMPV6_CODE_UNKNOWN_IPV6_OPTION  = 2
00097 } Icmpv6ParamProblemCode;
00098 
00099 
00100 //CodeWarrior or Win32 compiler?
00101 #if defined(__CWCC__) || defined(_WIN32)
00102    #pragma pack(push, 1)
00103 #endif
00104 
00105 
00106 /**
00107  * @brief ICMPv6 header
00108  **/
00109 
00110 typedef __start_packed struct
00111 {
00112    uint8_t type;      //0
00113    uint8_t code;      //1
00114    uint16_t checksum; //2-3
00115    uint8_t data[];    //4
00116 } __end_packed Icmpv6Header;
00117 
00118 
00119 /**
00120  * @brief ICMPv6 Error message
00121  **/
00122 
00123 typedef __start_packed struct
00124 {
00125    uint8_t type;       //0
00126    uint8_t code;       //1
00127    uint16_t checksum;  //2-3
00128    uint32_t parameter; //4-7
00129    uint8_t data[];     //8
00130 } __end_packed Icmpv6ErrorMessage;
00131 
00132 
00133 /**
00134  * @brief ICMPv6 Destination Unreachable message
00135  *
00136  * A Destination Unreachable message is generated in response to a
00137  * packet that cannot be delivered to its destination address for
00138  * reasons other than congestion
00139  *
00140  **/
00141 
00142 typedef __start_packed struct
00143 {
00144    uint8_t type;      //0
00145    uint8_t code;      //1
00146    uint16_t checksum; //2-3
00147    uint32_t unused;   //4-7
00148    uint8_t data[];    //8
00149 } __end_packed Icmpv6DestUnreachableMessage;
00150 
00151 
00152 /**
00153  * @brief ICMPv6 Packet Too Big message
00154  *
00155  * A Packet Too Big message is sent by a router in response
00156  * to a packet that it cannot forward because the packet is
00157  * larger than the MTU of the outgoing link
00158  *
00159  **/
00160 
00161 typedef __start_packed struct
00162 {
00163    uint8_t type;      //0
00164    uint8_t code;      //1
00165    uint16_t checksum; //2-3
00166    uint32_t mtu;      //4-7
00167    uint8_t data[];    //8
00168 } __end_packed Icmpv6PacketTooBigMessage;
00169 
00170 
00171 /**
00172  * @brief ICMPv6 Time Exceeded message
00173  *
00174  * A Time Exceeded message is sent by a router when it receives
00175  * a packet with a Hop Limit of zero
00176  *
00177  **/
00178 
00179 typedef __start_packed struct
00180 {
00181    uint8_t type;      //0
00182    uint8_t code;      //1
00183    uint16_t checksum; //2-3
00184    uint32_t unused;   //4-7
00185    uint8_t data[];    //8
00186 } __end_packed Icmpv6TimeExceededMessage;
00187 
00188 
00189 /**
00190  * @brief ICMPv6 Parameter Problem message
00191  *
00192  * A Parameter Problem message is sent by an IPv6 node when it finds a
00193  * problem with a field in the IPv6 header or extension headers such
00194  * that it cannot complete processing the packet
00195  *
00196  **/
00197 
00198 typedef __start_packed struct
00199 {
00200    uint8_t type;      //0
00201    uint8_t code;      //1
00202    uint16_t checksum; //2-3
00203    uint32_t pointer;  //4-7
00204    uint8_t data[];    //8
00205 } __end_packed Icmpv6ParamProblemMessage;
00206 
00207 
00208 /**
00209  * @brief ICMPv6 Echo Request and Echo Reply messages
00210  *
00211  * Every node must implement an ICMPv6 Echo responder function that
00212  * receives Echo Requests and sends corresponding Echo Replies
00213  *
00214  **/
00215 
00216 typedef __start_packed struct
00217 {
00218    uint8_t type;            //0
00219    uint8_t code;            //1
00220    uint16_t checksum;       //2-3
00221    uint16_t identifier;     //4-6
00222    uint16_t sequenceNumber; //7-8
00223    uint8_t data[];          //8
00224 } __end_packed Icmpv6EchoMessage;
00225 
00226 
00227 //CodeWarrior or Win32 compiler?
00228 #if defined(__CWCC__) || defined(_WIN32)
00229    #pragma pack(pop)
00230 #endif
00231 
00232 
00233 //ICMPv6 related functions
00234 error_t icmpv6EnableMulticastEchoRequest(NetInterface *interface, bool_t enable);
00235 
00236 void icmpv6ProcessMessage(NetInterface *interface, Ipv6PseudoHeader *pseudoHeader,
00237    const NetBuffer *buffer, size_t offset, uint8_t hopLimit);
00238 
00239 void icmpv6ProcessDestUnreachable(NetInterface *interface,
00240    Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
00241 
00242 void icmpv6ProcessPacketTooBig(NetInterface *interface,
00243    Ipv6PseudoHeader *pseudoHeader, const NetBuffer *buffer, size_t offset);
00244 
00245 void icmpv6ProcessEchoRequest(NetInterface *interface, Ipv6PseudoHeader *requestPseudoHeader,
00246    const NetBuffer *request, size_t requestOffset);
00247 
00248 error_t icmpv6SendErrorMessage(NetInterface *interface, uint8_t type, uint8_t code,
00249    uint32_t parameter, const NetBuffer *ipPacket, size_t ipPacketOffset);
00250 
00251 void icmpv6DumpMessage(const Icmpv6Header *message);
00252 void icmpv6DumpDestUnreachableMessage(const Icmpv6DestUnreachableMessage *message);
00253 void icmpv6DumpPacketTooBigMessage(const Icmpv6PacketTooBigMessage *message);
00254 void icmpv6DumpEchoMessage(const Icmpv6EchoMessage *message);
00255 void icmpv6DumpErrorMessage(const Icmpv6ErrorMessage *message);
00256 
00257 #endif
00258