1*cfb92d14SAndroid Build Coastguard Worker /* 2*cfb92d14SAndroid Build Coastguard Worker * Copyright (c) 2016, The OpenThread Authors. 3*cfb92d14SAndroid Build Coastguard Worker * All rights reserved. 4*cfb92d14SAndroid Build Coastguard Worker * 5*cfb92d14SAndroid Build Coastguard Worker * Redistribution and use in source and binary forms, with or without 6*cfb92d14SAndroid Build Coastguard Worker * modification, are permitted provided that the following conditions are met: 7*cfb92d14SAndroid Build Coastguard Worker * 1. Redistributions of source code must retain the above copyright 8*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer. 9*cfb92d14SAndroid Build Coastguard Worker * 2. Redistributions in binary form must reproduce the above copyright 10*cfb92d14SAndroid Build Coastguard Worker * notice, this list of conditions and the following disclaimer in the 11*cfb92d14SAndroid Build Coastguard Worker * documentation and/or other materials provided with the distribution. 12*cfb92d14SAndroid Build Coastguard Worker * 3. Neither the name of the copyright holder nor the 13*cfb92d14SAndroid Build Coastguard Worker * names of its contributors may be used to endorse or promote products 14*cfb92d14SAndroid Build Coastguard Worker * derived from this software without specific prior written permission. 15*cfb92d14SAndroid Build Coastguard Worker * 16*cfb92d14SAndroid Build Coastguard Worker * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17*cfb92d14SAndroid Build Coastguard Worker * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*cfb92d14SAndroid Build Coastguard Worker * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*cfb92d14SAndroid Build Coastguard Worker * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 20*cfb92d14SAndroid Build Coastguard Worker * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21*cfb92d14SAndroid Build Coastguard Worker * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22*cfb92d14SAndroid Build Coastguard Worker * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23*cfb92d14SAndroid Build Coastguard Worker * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24*cfb92d14SAndroid Build Coastguard Worker * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25*cfb92d14SAndroid Build Coastguard Worker * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26*cfb92d14SAndroid Build Coastguard Worker * POSSIBILITY OF SUCH DAMAGE. 27*cfb92d14SAndroid Build Coastguard Worker */ 28*cfb92d14SAndroid Build Coastguard Worker 29*cfb92d14SAndroid Build Coastguard Worker /** 30*cfb92d14SAndroid Build Coastguard Worker * @file 31*cfb92d14SAndroid Build Coastguard Worker * @brief 32*cfb92d14SAndroid Build Coastguard Worker * This file defines the top-level ICMPv6 functions for the OpenThread library. 33*cfb92d14SAndroid Build Coastguard Worker */ 34*cfb92d14SAndroid Build Coastguard Worker 35*cfb92d14SAndroid Build Coastguard Worker #ifndef OPENTHREAD_ICMP6_H_ 36*cfb92d14SAndroid Build Coastguard Worker #define OPENTHREAD_ICMP6_H_ 37*cfb92d14SAndroid Build Coastguard Worker 38*cfb92d14SAndroid Build Coastguard Worker #include <openthread/ip6.h> 39*cfb92d14SAndroid Build Coastguard Worker #include <openthread/message.h> 40*cfb92d14SAndroid Build Coastguard Worker 41*cfb92d14SAndroid Build Coastguard Worker #ifdef __cplusplus 42*cfb92d14SAndroid Build Coastguard Worker extern "C" { 43*cfb92d14SAndroid Build Coastguard Worker #endif 44*cfb92d14SAndroid Build Coastguard Worker 45*cfb92d14SAndroid Build Coastguard Worker /** 46*cfb92d14SAndroid Build Coastguard Worker * @addtogroup api-icmp6 47*cfb92d14SAndroid Build Coastguard Worker * 48*cfb92d14SAndroid Build Coastguard Worker * @brief 49*cfb92d14SAndroid Build Coastguard Worker * This module includes functions that control ICMPv6 communication. 50*cfb92d14SAndroid Build Coastguard Worker * 51*cfb92d14SAndroid Build Coastguard Worker * @{ 52*cfb92d14SAndroid Build Coastguard Worker * 53*cfb92d14SAndroid Build Coastguard Worker */ 54*cfb92d14SAndroid Build Coastguard Worker 55*cfb92d14SAndroid Build Coastguard Worker /** 56*cfb92d14SAndroid Build Coastguard Worker * ICMPv6 Message Types 57*cfb92d14SAndroid Build Coastguard Worker * 58*cfb92d14SAndroid Build Coastguard Worker */ 59*cfb92d14SAndroid Build Coastguard Worker typedef enum otIcmp6Type 60*cfb92d14SAndroid Build Coastguard Worker { 61*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_DST_UNREACH = 1, ///< Destination Unreachable 62*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_PACKET_TO_BIG = 2, ///< Packet To Big 63*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_TIME_EXCEEDED = 3, ///< Time Exceeded 64*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_PARAMETER_PROBLEM = 4, ///< Parameter Problem 65*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_ECHO_REQUEST = 128, ///< Echo Request 66*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_ECHO_REPLY = 129, ///< Echo Reply 67*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_ROUTER_SOLICIT = 133, ///< Router Solicitation 68*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_ROUTER_ADVERT = 134, ///< Router Advertisement 69*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_NEIGHBOR_SOLICIT = 135, ///< Neighbor Solicitation 70*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_TYPE_NEIGHBOR_ADVERT = 136, ///< Neighbor Advertisement 71*cfb92d14SAndroid Build Coastguard Worker } otIcmp6Type; 72*cfb92d14SAndroid Build Coastguard Worker 73*cfb92d14SAndroid Build Coastguard Worker /** 74*cfb92d14SAndroid Build Coastguard Worker * ICMPv6 Message Codes 75*cfb92d14SAndroid Build Coastguard Worker * 76*cfb92d14SAndroid Build Coastguard Worker */ 77*cfb92d14SAndroid Build Coastguard Worker typedef enum otIcmp6Code 78*cfb92d14SAndroid Build Coastguard Worker { 79*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_CODE_DST_UNREACH_NO_ROUTE = 0, ///< Destination Unreachable (Type 1) - No Route 80*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_CODE_DST_UNREACH_PROHIBITED = 1, ///< Destination Unreachable (Type 1) - Administratively Prohibited 81*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_CODE_FRAGM_REAS_TIME_EX = 1, ///< Time Exceeded (Type 3) - Fragment Reassembly 82*cfb92d14SAndroid Build Coastguard Worker } otIcmp6Code; 83*cfb92d14SAndroid Build Coastguard Worker 84*cfb92d14SAndroid Build Coastguard Worker #define OT_ICMP6_HEADER_DATA_SIZE 4 ///< Size of ICMPv6 Header. 85*cfb92d14SAndroid Build Coastguard Worker #define OT_ICMP6_ROUTER_ADVERT_MIN_SIZE 16 ///< Size of a Router Advertisement message without any options. 86*cfb92d14SAndroid Build Coastguard Worker 87*cfb92d14SAndroid Build Coastguard Worker /** 88*cfb92d14SAndroid Build Coastguard Worker * @struct otIcmp6Header 89*cfb92d14SAndroid Build Coastguard Worker * 90*cfb92d14SAndroid Build Coastguard Worker * Represents an ICMPv6 header. 91*cfb92d14SAndroid Build Coastguard Worker * 92*cfb92d14SAndroid Build Coastguard Worker */ 93*cfb92d14SAndroid Build Coastguard Worker OT_TOOL_PACKED_BEGIN 94*cfb92d14SAndroid Build Coastguard Worker struct otIcmp6Header 95*cfb92d14SAndroid Build Coastguard Worker { 96*cfb92d14SAndroid Build Coastguard Worker uint8_t mType; ///< Type 97*cfb92d14SAndroid Build Coastguard Worker uint8_t mCode; ///< Code 98*cfb92d14SAndroid Build Coastguard Worker uint16_t mChecksum; ///< Checksum 99*cfb92d14SAndroid Build Coastguard Worker union OT_TOOL_PACKED_FIELD 100*cfb92d14SAndroid Build Coastguard Worker { 101*cfb92d14SAndroid Build Coastguard Worker uint8_t m8[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint8_t)]; 102*cfb92d14SAndroid Build Coastguard Worker uint16_t m16[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint16_t)]; 103*cfb92d14SAndroid Build Coastguard Worker uint32_t m32[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint32_t)]; 104*cfb92d14SAndroid Build Coastguard Worker } mData; ///< Message-specific data 105*cfb92d14SAndroid Build Coastguard Worker } OT_TOOL_PACKED_END; 106*cfb92d14SAndroid Build Coastguard Worker 107*cfb92d14SAndroid Build Coastguard Worker /** 108*cfb92d14SAndroid Build Coastguard Worker * Represents an ICMPv6 header. 109*cfb92d14SAndroid Build Coastguard Worker * 110*cfb92d14SAndroid Build Coastguard Worker */ 111*cfb92d14SAndroid Build Coastguard Worker typedef struct otIcmp6Header otIcmp6Header; 112*cfb92d14SAndroid Build Coastguard Worker 113*cfb92d14SAndroid Build Coastguard Worker /** 114*cfb92d14SAndroid Build Coastguard Worker * This callback allows OpenThread to inform the application of a received ICMPv6 message. 115*cfb92d14SAndroid Build Coastguard Worker * 116*cfb92d14SAndroid Build Coastguard Worker * @param[in] aContext A pointer to arbitrary context information. 117*cfb92d14SAndroid Build Coastguard Worker * @param[in] aMessage A pointer to the received message. 118*cfb92d14SAndroid Build Coastguard Worker * @param[in] aMessageInfo A pointer to message information associated with @p aMessage. 119*cfb92d14SAndroid Build Coastguard Worker * @param[in] aIcmpHeader A pointer to the received ICMPv6 header. 120*cfb92d14SAndroid Build Coastguard Worker * 121*cfb92d14SAndroid Build Coastguard Worker */ 122*cfb92d14SAndroid Build Coastguard Worker typedef void (*otIcmp6ReceiveCallback)(void *aContext, 123*cfb92d14SAndroid Build Coastguard Worker otMessage *aMessage, 124*cfb92d14SAndroid Build Coastguard Worker const otMessageInfo *aMessageInfo, 125*cfb92d14SAndroid Build Coastguard Worker const otIcmp6Header *aIcmpHeader); 126*cfb92d14SAndroid Build Coastguard Worker 127*cfb92d14SAndroid Build Coastguard Worker /** 128*cfb92d14SAndroid Build Coastguard Worker * Implements ICMPv6 message handler. 129*cfb92d14SAndroid Build Coastguard Worker * 130*cfb92d14SAndroid Build Coastguard Worker */ 131*cfb92d14SAndroid Build Coastguard Worker typedef struct otIcmp6Handler 132*cfb92d14SAndroid Build Coastguard Worker { 133*cfb92d14SAndroid Build Coastguard Worker otIcmp6ReceiveCallback mReceiveCallback; ///< The ICMPv6 received callback 134*cfb92d14SAndroid Build Coastguard Worker void *mContext; ///< A pointer to arbitrary context information. 135*cfb92d14SAndroid Build Coastguard Worker struct otIcmp6Handler *mNext; ///< A pointer to the next handler in the list. 136*cfb92d14SAndroid Build Coastguard Worker } otIcmp6Handler; 137*cfb92d14SAndroid Build Coastguard Worker 138*cfb92d14SAndroid Build Coastguard Worker /** 139*cfb92d14SAndroid Build Coastguard Worker * ICMPv6 Echo Reply Modes 140*cfb92d14SAndroid Build Coastguard Worker * 141*cfb92d14SAndroid Build Coastguard Worker */ 142*cfb92d14SAndroid Build Coastguard Worker typedef enum otIcmp6EchoMode 143*cfb92d14SAndroid Build Coastguard Worker { 144*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_ECHO_HANDLER_DISABLED = 0, ///< ICMPv6 Echo processing disabled 145*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_ECHO_HANDLER_UNICAST_ONLY = 1, ///< ICMPv6 Echo processing enabled only for unicast requests only 146*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_ECHO_HANDLER_MULTICAST_ONLY = 2, ///< ICMPv6 Echo processing enabled only for multicast requests only 147*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_ECHO_HANDLER_ALL = 3, ///< ICMPv6 Echo processing enabled for unicast and multicast requests 148*cfb92d14SAndroid Build Coastguard Worker OT_ICMP6_ECHO_HANDLER_RLOC_ALOC_ONLY = 4, ///< ICMPv6 Echo processing enabled for RLOC/ALOC destinations only 149*cfb92d14SAndroid Build Coastguard Worker } otIcmp6EchoMode; 150*cfb92d14SAndroid Build Coastguard Worker 151*cfb92d14SAndroid Build Coastguard Worker /** 152*cfb92d14SAndroid Build Coastguard Worker * Indicates whether or not ICMPv6 Echo processing is enabled. 153*cfb92d14SAndroid Build Coastguard Worker * 154*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 155*cfb92d14SAndroid Build Coastguard Worker * 156*cfb92d14SAndroid Build Coastguard Worker * @retval OT_ICMP6_ECHO_HANDLER_DISABLED ICMPv6 Echo processing is disabled. 157*cfb92d14SAndroid Build Coastguard Worker * @retval OT_ICMP6_ECHO_HANDLER_UNICAST_ONLY ICMPv6 Echo processing enabled for unicast requests only 158*cfb92d14SAndroid Build Coastguard Worker * @retval OT_ICMP6_ECHO_HANDLER_MULTICAST_ONLY ICMPv6 Echo processing enabled for multicast requests only 159*cfb92d14SAndroid Build Coastguard Worker * @retval OT_ICMP6_ECHO_HANDLER_ALL ICMPv6 Echo processing enabled for unicast and multicast requests 160*cfb92d14SAndroid Build Coastguard Worker * 161*cfb92d14SAndroid Build Coastguard Worker */ 162*cfb92d14SAndroid Build Coastguard Worker otIcmp6EchoMode otIcmp6GetEchoMode(otInstance *aInstance); 163*cfb92d14SAndroid Build Coastguard Worker 164*cfb92d14SAndroid Build Coastguard Worker /** 165*cfb92d14SAndroid Build Coastguard Worker * Sets whether or not ICMPv6 Echo processing is enabled. 166*cfb92d14SAndroid Build Coastguard Worker * 167*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 168*cfb92d14SAndroid Build Coastguard Worker * @param[in] aMode The ICMPv6 Echo processing mode. 169*cfb92d14SAndroid Build Coastguard Worker * 170*cfb92d14SAndroid Build Coastguard Worker */ 171*cfb92d14SAndroid Build Coastguard Worker void otIcmp6SetEchoMode(otInstance *aInstance, otIcmp6EchoMode aMode); 172*cfb92d14SAndroid Build Coastguard Worker 173*cfb92d14SAndroid Build Coastguard Worker /** 174*cfb92d14SAndroid Build Coastguard Worker * Registers a handler to provide received ICMPv6 messages. 175*cfb92d14SAndroid Build Coastguard Worker * 176*cfb92d14SAndroid Build Coastguard Worker * @note A handler structure @p aHandler has to be stored in persistent (static) memory. 177*cfb92d14SAndroid Build Coastguard Worker * OpenThread does not make a copy of handler structure. 178*cfb92d14SAndroid Build Coastguard Worker * 179*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 180*cfb92d14SAndroid Build Coastguard Worker * @param[in] aHandler A pointer to a handler containing callback that is called when 181*cfb92d14SAndroid Build Coastguard Worker * an ICMPv6 message is received. 182*cfb92d14SAndroid Build Coastguard Worker * 183*cfb92d14SAndroid Build Coastguard Worker */ 184*cfb92d14SAndroid Build Coastguard Worker otError otIcmp6RegisterHandler(otInstance *aInstance, otIcmp6Handler *aHandler); 185*cfb92d14SAndroid Build Coastguard Worker 186*cfb92d14SAndroid Build Coastguard Worker /** 187*cfb92d14SAndroid Build Coastguard Worker * Sends an ICMPv6 Echo Request via the Thread interface. 188*cfb92d14SAndroid Build Coastguard Worker * 189*cfb92d14SAndroid Build Coastguard Worker * @param[in] aInstance A pointer to an OpenThread instance. 190*cfb92d14SAndroid Build Coastguard Worker * @param[in] aMessage A pointer to the message buffer containing the ICMPv6 payload. 191*cfb92d14SAndroid Build Coastguard Worker * @param[in] aMessageInfo A reference to message information associated with @p aMessage. 192*cfb92d14SAndroid Build Coastguard Worker * @param[in] aIdentifier An identifier to aid in matching Echo Replies to this Echo Request. 193*cfb92d14SAndroid Build Coastguard Worker * May be zero. 194*cfb92d14SAndroid Build Coastguard Worker * 195*cfb92d14SAndroid Build Coastguard Worker */ 196*cfb92d14SAndroid Build Coastguard Worker otError otIcmp6SendEchoRequest(otInstance *aInstance, 197*cfb92d14SAndroid Build Coastguard Worker otMessage *aMessage, 198*cfb92d14SAndroid Build Coastguard Worker const otMessageInfo *aMessageInfo, 199*cfb92d14SAndroid Build Coastguard Worker uint16_t aIdentifier); 200*cfb92d14SAndroid Build Coastguard Worker 201*cfb92d14SAndroid Build Coastguard Worker /** 202*cfb92d14SAndroid Build Coastguard Worker * @} 203*cfb92d14SAndroid Build Coastguard Worker * 204*cfb92d14SAndroid Build Coastguard Worker */ 205*cfb92d14SAndroid Build Coastguard Worker 206*cfb92d14SAndroid Build Coastguard Worker #ifdef __cplusplus 207*cfb92d14SAndroid Build Coastguard Worker } // extern "C" 208*cfb92d14SAndroid Build Coastguard Worker #endif 209*cfb92d14SAndroid Build Coastguard Worker 210*cfb92d14SAndroid Build Coastguard Worker #endif // OPENTHREAD_ICMP6_H_ 211