[ICMPv6] Allow application to register ICMPv6 handler. (#1380)

This commit is contained in:
Łukasz Duda
2017-02-24 12:13:59 -08:00
committed by Jonathan Hui
parent fc45943f8c
commit 4f35cdb854
18 changed files with 323 additions and 214 deletions
+1
View File
@@ -64,6 +64,7 @@ include_HEADERS = \
openthread-coap.h \
openthread-crypto.h \
openthread-diag.h \
openthread-icmp6.h \
openthread-ip6.h \
openthread-jam-detection.h \
openthread-message.h \
+111
View File
@@ -0,0 +1,111 @@
/*
* Copyright (c) 2016, The OpenThread Authors.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @file
* @brief
* This file defines the top-level icmp6 functions for the OpenThread library.
*/
#ifndef OPENTHREAD_ICMP6_H_
#define OPENTHREAD_ICMP6_H_
#include <openthread-types.h>
#include <openthread-message.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @addtogroup icmp6 ICMPv6
*
* @brief
* This module includes functions that control ICMPv6 communication.
*
* @{
*
*/
/**
* This function indicates whether or not ICMPv6 Echo processing is enabled.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @retval TRUE ICMPv6 Echo processing is enabled.
* @retval FALSE ICMPv6 Echo processing is disabled.
*
*/
bool otIcmp6IsEchoEnabled(otInstance *aInstance);
/**
* This function sets whether or not ICMPv6 Echo processing is enabled.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aEnabled TRUE to enable ICMPv6 Echo processing, FALSE otherwise.
*
*/
void otIcmp6SetEchoEnabled(otInstance *aInstance, bool aEnabled);
/**
* This function registers a handler to provide received ICMPv6 messages.
*
* @note A handler structure @p aHandler has to be stored in persistant (static) memory.
* OpenThread does not make a copy of handler structure.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aHandler A pointer to a handler conitaining callback that is called when
* an ICMPv6 message is received.
*
*/
ThreadError otIcmp6RegisterHandler(otInstance *aInstance, otIcmp6Handler *aHandler);
/**
* This function sends an ICMPv6 Echo Request via the Thread interface.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aMessage A pointer to the message buffer containing the ICMPv6 payload.
* @param[in] aMessageInfo A reference to message information associated with @p aMessage.
* @param[in] aIdentifier An identifier to aid in matching Echo Replies to this Echo Request.
* May be zero.
*
*/
ThreadError otIcmp6SendEchoRequest(otInstance *aInstance, otMessage aMessage,
const otMessageInfo *aMessageInfo, uint16_t aIdentifier);
/**
* @}
*
*/
#ifdef __cplusplus
} // extern "C"
#endif
#endif // OPENTHREAD_ICMP6_H_
-20
View File
@@ -342,26 +342,6 @@ void otSetReceiveIp6DatagramFilterEnabled(otInstance *aInstance, bool aEnabled);
*/
ThreadError otSendIp6Datagram(otInstance *aInstance, otMessage aMessage);
/**
* This function indicates whether or not ICMPv6 Echo processing is enabled.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
* @retval TRUE ICMPv6 Echo processing is enabled.
* @retval FALSE ICMPv6 Echo processing is disabled.
*
*/
bool otIsIcmpEchoEnabled(otInstance *aInstance);
/**
* This function sets whether or not ICMPv6 Echo processing is enabled.
*
* @param[in] aInstance A pointer to an OpenThread instance.
* @param[in] aEnabled TRUE to enable ICMPv6 Echo processing, FALSE otherwise.
*
*/
void otSetIcmpEchoEnabled(otInstance *aInstance, bool aEnabled);
/**
* @}
*
+95 -14
View File
@@ -329,6 +329,21 @@ struct otIp6Address
typedef struct otIp6Address otIp6Address;
/**
* This structure represents the local and peer IPv6 socket addresses.
*/
typedef struct otMessageInfo
{
otIp6Address mSockAddr; ///< The local IPv6 address.
otIp6Address mPeerAddr; ///< The peer IPv6 address.
uint16_t mSockPort; ///< The local transport-layer port.
uint16_t mPeerPort; ///< The peer transport-layer port.
int8_t mInterfaceId; ///< An IPv6 interface identifier.
uint8_t mHopLimit; ///< The IPv6 Hop Limit.
const void *mLinkInfo; ///< A pointer to link-specific information.
} otMessageInfo;
/**
* @addtogroup commands Commands
*
@@ -982,6 +997,86 @@ typedef struct
void *mData; ///< Opaque data used by the implementation.
} otMessageQueue;
/**
* @}
*
*/
/**
* @addtogroup icmp6 ICMPv6
*
* @brief
* This module includes functions that control ICMPv6 communication.
*
* @{
*
*/
/**
* ICMPv6 Message Types
*
*/
typedef enum otIcmp6Type
{
kIcmp6TypeDstUnreach = 1, ///< Destination Unreachable
kIcmp6TypeEchoRequest = 128, ///< Echo Request
kIcmp6TypeEchoReply = 129, ///< Echo Reply
} otIcmp6Type;
/**
* ICMPv6 Message Codes
*
*/
typedef enum otIcmp6Code
{
kIcmp6CodeDstUnreachNoRoute = 0, ///< Destination Unreachable No Route
} otIcmp6Code;
#define OT_ICMP6_HEADER_DATA_SIZE 4 ///< Size of an message specific data of ICMPv6 Header.
/**
* This structure represents an ICMPv6 header.
*
*/
OT_TOOL_PACKED_BEGIN
struct otIcmp6Header
{
uint8_t mType; ///< Type
uint8_t mCode; ///< Code
uint16_t mChecksum; ///< Checksum
union
{
uint8_t m8[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint8_t)];
uint16_t m16[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint16_t)];
uint32_t m32[OT_ICMP6_HEADER_DATA_SIZE / sizeof(uint32_t)];
} mData; ///< Message-specific data
} OT_TOOL_PACKED_END;
typedef struct otIcmp6Header otIcmp6Header;
/**
* This callback allows OpenThread to inform the application of a received ICMPv6 message.
*
* @param[in] aContext A pointer to arbitrary context information.
* @param[in] aMessage A pointer to the received message.
* @param[in] aMessageInfo A pointer to message information associated with @p aMessage.
* @param[in] aIcmpHeader A pointer to the received ICMPv6 header.
*
*/
typedef void (*otIcmp6ReceiveCallback)(void *aContext, otMessage aMessage, const otMessageInfo *aMessageInfo,
const otIcmp6Header *aIcmpHeader);
/**
* This structure implements ICMPv6 message handler.
*
*/
typedef struct otIcmp6Handler
{
otIcmp6ReceiveCallback mReceiveCallback;
void *mContext;
struct otIcmp6Handler *mNext;
} otIcmp6Handler;
/**
* @}
*
@@ -1007,20 +1102,6 @@ typedef struct otSockAddr
int8_t mScopeId; ///< An IPv6 scope identifier.
} otSockAddr;
/**
* This structure represents the local and peer IPv6 socket addresses.
*/
typedef struct otMessageInfo
{
otIp6Address mSockAddr; ///< The local IPv6 address.
otIp6Address mPeerAddr; ///< The peer IPv6 address.
uint16_t mSockPort; ///< The local transport-layer port.
uint16_t mPeerPort; ///< The peer transport-layer port.
int8_t mInterfaceId; ///< An IPv6 interface identifier.
uint8_t mHopLimit; ///< The IPv6 Hop Limit.
const void *mLinkInfo; ///< A pointer to link-specific information.
} otMessageInfo;
/**
* This callback allows OpenThread to inform the application of a received UDP message.
*/