Message API cleanup.

This commit is contained in:
Jonathan Hui
2017-03-02 10:24:55 -08:00
parent 77bc491c56
commit 1455b612f9
27 changed files with 323 additions and 304 deletions
+1
View File
@@ -56,6 +56,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\core\api\link_raw_api.cpp" />
<ClCompile Include="..\..\src\core\api\message_api.cpp" />
<ClCompile Include="..\..\src\core\api\tasklet_api.cpp" />
<ClCompile Include="..\..\src\core\coap\coap_base.cpp" />
<ClCompile Include="..\..\src\core\coap\coap_client.cpp" />
@@ -63,6 +63,9 @@
<ClCompile Include="..\..\src\core\api\link_raw_api.cpp">
<Filter>Source Files\api</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\api\message_api.cpp">
<Filter>Source Files\api</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\api\tasklet_api.cpp">
<Filter>Source Files\api</Filter>
</ClCompile>
@@ -64,6 +64,7 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\core\api\message_api.cpp" />
<ClCompile Include="..\..\src\core\api\tasklet_api.cpp" />
<ClCompile Include="..\..\src\core\coap\coap_base.cpp" />
<ClCompile Include="..\..\src\core\coap\coap_client.cpp" />
@@ -63,6 +63,9 @@
<ClCompile Include="..\..\src\core\api\link_raw_api.cpp">
<Filter>Source Files\api</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\api\message_api.cpp">
<Filter>Source Files\api</Filter>
</ClCompile>
<ClCompile Include="..\..\src\core\api\tasklet_api.cpp">
<Filter>Source Files\api</Filter>
</ClCompile>
+1 -1
View File
@@ -3164,7 +3164,7 @@ otGetMacCounters(
OTAPI
void
OTCALL
otGetMessageBufferInfo(
otMessageGetBufferInfo(
_In_ otInstance *,
_Out_ otBufferInfo *aBufferInfo
)
+3 -3
View File
@@ -425,7 +425,7 @@ otLwfReceiveIp6DatagramCallback(
)
{
PMS_FILTER pFilter = (PMS_FILTER)aContext;
uint16_t messageLength = otGetMessageLength(aMessage);
uint16_t messageLength = otMessageGetLength(aMessage);
PNET_BUFFER_LIST NetBufferList = NULL;
PNET_BUFFER NetBuffer = NULL;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
@@ -487,7 +487,7 @@ otLwfReceiveIp6DatagramCallback(
}
// Read the bytes to the buffer
BytesRead = otReadMessage(aMessage, 0, DataBuffer, messageLength);
BytesRead = otMessageRead(aMessage, 0, DataBuffer, messageLength);
NT_ASSERT(BytesRead == (int)messageLength);
if (BytesRead != (int)messageLength)
{
@@ -563,7 +563,7 @@ otLwfReceiveIp6DatagramCallback(
error:
otFreeMessage(aMessage);
otMessageFree(aMessage);
}
// Called in response to receiving a Spinel Ip6 packet command
@@ -908,11 +908,11 @@ otLwfEventWorkerThread(
if (message)
{
// Write to the message
error = otAppendMessage(message, MessageBuffer, (uint16_t)NET_BUFFER_DATA_LENGTH(CurrNb));
error = otMessageAppend(message, MessageBuffer, (uint16_t)NET_BUFFER_DATA_LENGTH(CurrNb));
if (error != kThreadError_None)
{
LogError(DRIVER_DATA_PATH, "otAppendMessage failed with %!otError!", error);
otFreeMessage(message);
otMessageFree(message);
}
else
{
-1
View File
@@ -69,7 +69,6 @@ include_HEADERS = \
openthread-icmp6.h \
openthread-ip6.h \
openthread-jam-detection.h \
openthread-message.h \
openthread-types.h \
$(NULL)
+1 -1
View File
@@ -36,7 +36,7 @@
#define OPENTHREAD_ICMP6_H_
#include <openthread-types.h>
#include <openthread-message.h>
#include <openthread/message.h>
#ifdef __cplusplus
extern "C" {
+1 -1
View File
@@ -35,7 +35,7 @@
#ifndef OPENTHREAD_IP6_H_
#define OPENTHREAD_IP6_H_
#include <openthread-message.h>
#include "openthread/message.h"
#include <platform/radio.h>
#ifdef __cplusplus
+5 -28
View File
@@ -344,6 +344,11 @@ typedef struct otMessageInfo
const void *mLinkInfo; ///< A pointer to link-specific information.
} otMessageInfo;
/**
* This type points to an OpenThread message buffer.
*/
typedef void *otMessage;
/**
* @addtogroup commands Commands
*
@@ -974,34 +979,6 @@ typedef struct
uint16_t mSecretKeyLength; ///< Secret key length in bytes. Should be at least 16 bytes == 128 bits.
} otSemanticallyOpaqueIidGeneratorData;
/**
* @addtogroup messages Message Buffers
*
* @brief
* This module includes functions that manipulate OpenThread message buffers
*
* @{
*
*/
/**
* This type points to an OpenThread message buffer.
*/
typedef void *otMessage;
/**
* This structure represents an OpenThread message queue.
*/
typedef struct
{
void *mData; ///< Opaque data used by the implementation.
} otMessageQueue;
/**
* @}
*
*/
/**
* @addtogroup icmp6 ICMPv6
*
+1 -9
View File
@@ -37,6 +37,7 @@
#include <openthread-types.h>
#include "openthread/message.h"
#include "openthread/tasklet.h"
#ifdef __cplusplus
@@ -2004,15 +2005,6 @@ OTAPI ThreadError OTCALL otSendDiagnosticReset(otInstance *aInstance, const otIp
*/
OTAPI const otMacCounters *OTCALL otGetMacCounters(otInstance *aInstance);
/**
* Get the Message Buffer information.
*
* @param[in] aInstance A pointer to the OpenThread instance.
* @param[out] aBufferInfo A pointer where the message buffer information is written.
*
*/
OTAPI void OTCALL otGetMessageBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo);
/**
* @}
*
+1
View File
@@ -30,6 +30,7 @@ include $(abs_top_nlbuild_autotools_dir)/automake/pre.am
openthread_headers = \
coap.h \
message.h \
tasklet.h \
udp.h \
$(NULL)
+1
View File
@@ -44,6 +44,7 @@
#include <stdint.h>
#include "openthread-types.h"
#include "openthread/message.h"
#ifdef __cplusplus
extern "C" {
@@ -35,32 +35,12 @@
#ifndef OPENTHREAD_MESSAGE_H_
#define OPENTHREAD_MESSAGE_H_
#include <openthread-types.h>
#include "openthread-types.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup api API
* @brief
* This module includes the application programming interface to the OpenThread stack.
*
* @{
*
* @defgroup execution Execution
* @defgroup commands Commands
* @defgroup config Configuration
* @defgroup diags Diagnostics
* @defgroup messages Message Buffers
* @defgroup ip6 IPv6
* @defgroup udp UDP
* @defgroup coap CoAP
*
* @}
*
*/
/**
* @addtogroup messages Message Buffers
*
@@ -78,16 +58,15 @@ extern "C" {
*
* @retval kThreadErrorNone Successfully freed the message buffer.
*
* @sa otNewUdpMessage
* @sa otAppendMessage
* @sa otGetMessageLength
* @sa otSetMessageLength
* @sa otGetMessageOffset
* @sa otSetMessageOffset
* @sa otReadMessage
* @sa otWriteMessage
* @sa otMessageAppend
* @sa otMessageGetLength
* @sa otMessageSetLength
* @sa otMessageGetOffset
* @sa otMessageSetOffset
* @sa otMessageRead
* @sa otMessageWrite
*/
ThreadError otFreeMessage(otMessage aMessage);
ThreadError otMessageFree(otMessage aMessage);
/**
* Get the message length in bytes.
@@ -96,17 +75,16 @@ ThreadError otFreeMessage(otMessage aMessage);
*
* @returns The message length in bytes.
*
* @sa otNewUdpMessage
* @sa otFreeMessage
* @sa otAppendMessage
* @sa otSetMessageLength
* @sa otGetMessageOffset
* @sa otSetMessageOffset
* @sa otReadMessage
* @sa otWriteMessage
* @sa otSetMessageLength
* @sa otMessageFree
* @sa otMessageAppend
* @sa otMessageSetLength
* @sa otMessageGetOffset
* @sa otMessageSetOffset
* @sa otMessageRead
* @sa otMessageWrite
* @sa otMessageSetLength
*/
uint16_t otGetMessageLength(otMessage aMessage);
uint16_t otMessageGetLength(otMessage aMessage);
/**
* Set the message length in bytes.
@@ -117,16 +95,15 @@ uint16_t otGetMessageLength(otMessage aMessage);
* @retval kThreadErrorNone Successfully set the message length.
* @retval kThreadErrorNoBufs No available buffers to grow the message.
*
* @sa otNewUdpMessage
* @sa otFreeMessage
* @sa otAppendMessage
* @sa otGetMessageLength
* @sa otGetMessageOffset
* @sa otSetMessageOffset
* @sa otReadMessage
* @sa otWriteMessage
* @sa otMessageFree
* @sa otMessageAppend
* @sa otMessageGetLength
* @sa otMessageGetOffset
* @sa otMessageSetOffset
* @sa otMessageRead
* @sa otMessageWrite
*/
ThreadError otSetMessageLength(otMessage aMessage, uint16_t aLength);
ThreadError otMessageSetLength(otMessage aMessage, uint16_t aLength);
/**
* Get the message offset in bytes.
@@ -135,16 +112,15 @@ ThreadError otSetMessageLength(otMessage aMessage, uint16_t aLength);
*
* @returns The message offset value.
*
* @sa otNewUdpMessage
* @sa otFreeMessage
* @sa otAppendMessage
* @sa otGetMessageLength
* @sa otSetMessageLength
* @sa otSetMessageOffset
* @sa otReadMessage
* @sa otWriteMessage
* @sa otMessageFree
* @sa otMessageAppend
* @sa otMessageGetLength
* @sa otMessageSetLength
* @sa otMessageSetOffset
* @sa otMessageRead
* @sa otMessageWrite
*/
uint16_t otGetMessageOffset(otMessage aMessage);
uint16_t otMessageGetOffset(otMessage aMessage);
/**
* Set the message offset in bytes.
@@ -155,16 +131,15 @@ uint16_t otGetMessageOffset(otMessage aMessage);
* @retval kThreadErrorNone Successfully set the message offset.
* @retval kThreadErrorInvalidArg The offset is beyond the message length.
*
* @sa otNewUdpMessage
* @sa otFreeMessage
* @sa otAppendMessage
* @sa otGetMessageLength
* @sa otSetMessageLength
* @sa otGetMessageOffset
* @sa otReadMessage
* @sa otWriteMessage
* @sa otMessageFree
* @sa otMessageAppend
* @sa otMessageGetLength
* @sa otMessageSetLength
* @sa otMessageGetOffset
* @sa otMessageRead
* @sa otMessageWrite
*/
ThreadError otSetMessageOffset(otMessage aMessage, uint16_t aOffset);
ThreadError otMessageSetOffset(otMessage aMessage, uint16_t aOffset);
/**
* This function indicates whether or not link security is enabled for the message.
@@ -175,7 +150,7 @@ ThreadError otSetMessageOffset(otMessage aMessage, uint16_t aOffset);
* @retval FALSE If link security is not enabled.
*
*/
bool otIsMessageLinkSecurityEnabled(otMessage aMessage);
bool otMessageIsLinkSecurityEnabled(otMessage aMessage);
/**
* This function sets/forces the message to be forwarded using direct transmission.
@@ -198,16 +173,15 @@ void otMessageSetDirectTransmission(otMessage aMessage, bool aEnabled);
* @retval kThreadErrorNone Successfully appended to the message
* @retval kThreadErrorNoBufs No available buffers to grow the message.
*
* @sa otNewUdpMessage
* @sa otFreeMessage
* @sa otGetMessageLength
* @sa otSetMessageLength
* @sa otGetMessageOffset
* @sa otSetMessageOffset
* @sa otReadMessage
* @sa otWriteMessage
* @sa otMessageFree
* @sa otMessageGetLength
* @sa otMessageSetLength
* @sa otMessageGetOffset
* @sa otMessageSetOffset
* @sa otMessageRead
* @sa otMessageWrite
*/
ThreadError otAppendMessage(otMessage aMessage, const void *aBuf, uint16_t aLength);
ThreadError otMessageAppend(otMessage aMessage, const void *aBuf, uint16_t aLength);
/**
* Read bytes from a message.
@@ -219,16 +193,15 @@ ThreadError otAppendMessage(otMessage aMessage, const void *aBuf, uint16_t aLeng
*
* @returns The number of bytes read.
*
* @sa otNewUdpMessage
* @sa otFreeMessage
* @sa otAppendMessage
* @sa otGetMessageLength
* @sa otSetMessageLength
* @sa otGetMessageOffset
* @sa otSetMessageOffset
* @sa otWriteMessage
* @sa otMessageFree
* @sa otMessageAppend
* @sa otMessageGetLength
* @sa otMessageSetLength
* @sa otMessageGetOffset
* @sa otMessageSetOffset
* @sa otMessageWrite
*/
int otReadMessage(otMessage aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength);
int otMessageRead(otMessage aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength);
/**
* Write bytes to a message.
@@ -240,16 +213,23 @@ int otReadMessage(otMessage aMessage, uint16_t aOffset, void *aBuf, uint16_t aLe
*
* @returns The number of bytes written.
*
* @sa otNewUdpMessage
* @sa otFreeMessage
* @sa otAppendMessage
* @sa otGetMessageLength
* @sa otSetMessageLength
* @sa otGetMessageOffset
* @sa otSetMessageOffset
* @sa otReadMessage
* @sa otMessageFree
* @sa otMessageAppend
* @sa otMessageGetLength
* @sa otMessageSetLength
* @sa otMessageGetOffset
* @sa otMessageSetOffset
* @sa otMessageRead
*/
int otWriteMessage(otMessage aMessage, uint16_t aOffset, const void *aBuf, uint16_t aLength);
int otMessageWrite(otMessage aMessage, uint16_t aOffset, const void *aBuf, uint16_t aLength);
/**
* This structure represents an OpenThread message queue.
*/
typedef struct
{
void *mData; ///< Opaque data used by the implementation.
} otMessageQueue;
/**
*
@@ -310,6 +290,15 @@ otMessage otMessageQueueGetHead(otMessageQueue *aQueue);
*/
otMessage otMessageQueueGetNext(otMessageQueue *aQueue, const otMessage aMessage);
/**
* Get the Message Buffer information.
*
* @param[in] aInstance A pointer to the OpenThread instance.
* @param[out] aBufferInfo A pointer where the message buffer information is written.
*
*/
OTAPI void OTCALL otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo);
/**
* @}
*
+1 -1
View File
@@ -36,7 +36,7 @@
#define OPENTHREAD_UDP_H_
#include "openthread-types.h"
#include "openthread-message.h"
#include "openthread/message.h"
#ifdef __cplusplus
extern "C" {
+4 -4
View File
@@ -412,7 +412,7 @@ void Interpreter::ProcessBufferInfo(int argc, char *argv[])
(void)argc;
(void)argv;
otGetMessageBufferInfo(mInstance, &bufferInfo);
otMessageGetBufferInfo(mInstance, &bufferInfo);
sServer->OutputFormat("total: %d\r\n", bufferInfo.mTotalBuffers);
sServer->OutputFormat("free: %d\r\n", bufferInfo.mFreeBuffers);
@@ -1443,8 +1443,8 @@ void Interpreter::HandlePingTimer()
const otMessageInfo *messageInfo = static_cast<const otMessageInfo *>(&sMessageInfo);
VerifyOrExit((message = otNewIp6Message(mInstance, true)) != NULL, error = kThreadError_NoBufs);
SuccessOrExit(error = otAppendMessage(message, &timestamp, sizeof(timestamp)));
SuccessOrExit(error = otSetMessageLength(message, sLength));
SuccessOrExit(error = otMessageAppend(message, &timestamp, sizeof(timestamp)));
SuccessOrExit(error = otMessageSetLength(message, sLength));
SuccessOrExit(error = otIcmp6SendEchoRequest(mInstance, message, messageInfo, 1));
sCount--;
@@ -1453,7 +1453,7 @@ exit:
if (error != kThreadError_None && message != NULL)
{
otFreeMessage(message);
otMessageFree(message);
}
if (sCount)
+5 -5
View File
@@ -72,11 +72,11 @@ void Udp::HandleUdpReceive(void *aContext, otMessage aMessage, const otMessageIn
void Udp::HandleUdpReceive(otMessage aMessage, const otMessageInfo *aMessageInfo)
{
uint16_t payloadLength = otGetMessageLength(aMessage) - otGetMessageOffset(aMessage);
uint16_t payloadLength = otMessageGetLength(aMessage) - otMessageGetOffset(aMessage);
char buf[512];
VerifyOrExit(payloadLength <= sizeof(buf), ;);
otReadMessage(aMessage, otGetMessageOffset(aMessage), buf, payloadLength);
otMessageRead(aMessage, otMessageGetOffset(aMessage), buf, payloadLength);
if (buf[payloadLength - 1] == '\n')
{
@@ -102,15 +102,15 @@ int Udp::Output(const char *aBuf, uint16_t aBufLength)
otMessage message;
VerifyOrExit((message = otUdpNewMessage(mInstance, true)) != NULL, error = kThreadError_NoBufs);
SuccessOrExit(error = otSetMessageLength(message, aBufLength));
otWriteMessage(message, 0, aBuf, aBufLength);
SuccessOrExit(error = otMessageSetLength(message, aBufLength));
otMessageWrite(message, 0, aBuf, aBufLength);
SuccessOrExit(error = otUdpSend(&mSocket, message, &mPeer));
exit:
if (error != kThreadError_None && message != NULL)
{
otFreeMessage(message);
otMessageFree(message);
aBufLength = 0;
}
+1
View File
@@ -40,6 +40,7 @@ CPPFLAGS_COMMON = \
SOURCES_COMMON = \
openthread.cpp \
api/message_api.cpp \
api/tasklet_api.cpp \
api/udp_api.cpp \
coap/coap_base.cpp \
+180
View File
@@ -0,0 +1,180 @@
/*
* 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
* This file implements the OpenThread Message API.
*/
#include "openthread/message.h"
#include "openthread-instance.h"
using namespace Thread;
#ifdef __cplusplus
extern "C" {
#endif
ThreadError otMessageFree(otMessage aMessage)
{
return static_cast<Message *>(aMessage)->Free();
}
uint16_t otMessageGetLength(otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
return message->GetLength();
}
ThreadError otMessageSetLength(otMessage aMessage, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->SetLength(aLength);
}
uint16_t otMessageGetOffset(otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
return message->GetOffset();
}
ThreadError otMessageSetOffset(otMessage aMessage, uint16_t aOffset)
{
Message *message = static_cast<Message *>(aMessage);
return message->SetOffset(aOffset);
}
bool otMessageIsLinkSecurityEnabled(otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
return message->IsLinkSecurityEnabled();
}
void otMessageSetDirectTransmission(otMessage aMessage, bool aEnabled)
{
Message *message = static_cast<Message *>(aMessage);
if (aEnabled)
{
message->SetDirectTransmission();
}
else
{
message->ClearDirectTransmission();
}
}
ThreadError otMessageAppend(otMessage aMessage, const void *aBuf, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->Append(aBuf, aLength);
}
int otMessageRead(otMessage aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->Read(aOffset, aLength, aBuf);
}
int otMessageWrite(otMessage aMessage, uint16_t aOffset, const void *aBuf, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->Write(aOffset, aLength, aBuf);
}
void otMessageQueueInit(otMessageQueue *aQueue)
{
aQueue->mData = NULL;
}
ThreadError otMessageQueueEnqueue(otMessageQueue *aQueue, otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
return queue->Enqueue(*message);
}
ThreadError otMessageQueueDequeue(otMessageQueue *aQueue, otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
return queue->Dequeue(*message);
}
otMessage otMessageQueueGetHead(otMessageQueue *aQueue)
{
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
return queue->GetHead();
}
otMessage otMessageQueueGetNext(otMessageQueue *aQueue, otMessage aMessage)
{
Message *next;
Message *message = static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
VerifyOrExit(message != NULL, next = NULL);
VerifyOrExit(message->GetMessageQueue() == queue, next = NULL);
next = message->GetNext();
exit:
return next;
}
void otMessageGetBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo)
{
aBufferInfo->mTotalBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS;
aBufferInfo->mFreeBuffers = aInstance->mThreadNetif.GetIp6().mMessagePool.GetFreeBufferCount();
aInstance->mThreadNetif.GetMeshForwarder().GetSendQueue().GetInfo(aBufferInfo->m6loSendMessages,
aBufferInfo->m6loSendBuffers);
aInstance->mThreadNetif.GetMeshForwarder().GetReassemblyQueue().GetInfo(aBufferInfo->m6loReassemblyMessages,
aBufferInfo->m6loReassemblyBuffers);
aInstance->mThreadNetif.GetMeshForwarder().GetResolvingQueue().GetInfo(aBufferInfo->mArpMessages,
aBufferInfo->mArpBuffers);
aInstance->mThreadNetif.GetIp6().GetSendQueue().GetInfo(aBufferInfo->mIp6Messages,
aBufferInfo->mIp6Buffers);
aInstance->mThreadNetif.GetIp6().mMpl.GetBufferedMessageSet().GetInfo(aBufferInfo->mMplMessages,
aBufferInfo->mMplBuffers);
aInstance->mThreadNetif.GetMle().GetMessageQueue().GetInfo(aBufferInfo->mMleMessages,
aBufferInfo->mMleBuffers);
aInstance->mThreadNetif.GetCoapClient().GetRequestMessages().GetInfo(aBufferInfo->mCoapClientMessages,
aBufferInfo->mCoapClientBuffers);
}
#ifdef __cplusplus
} // extern "C"
#endif
+2
View File
@@ -43,6 +43,8 @@
#include <stdint.h>
#include <string.h>
#include "openthread/message.h"
#include <openthread-core-config.h>
#include <openthread-types.h>
#include <common/code_utils.hpp>
-134
View File
@@ -955,34 +955,6 @@ const otMacCounters *otGetMacCounters(otInstance *aInstance)
return &aInstance->mThreadNetif.GetMac().GetCounters();
}
void otGetMessageBufferInfo(otInstance *aInstance, otBufferInfo *aBufferInfo)
{
aBufferInfo->mTotalBuffers = OPENTHREAD_CONFIG_NUM_MESSAGE_BUFFERS;
aBufferInfo->mFreeBuffers = aInstance->mThreadNetif.GetIp6().mMessagePool.GetFreeBufferCount();
aInstance->mThreadNetif.GetMeshForwarder().GetSendQueue().GetInfo(aBufferInfo->m6loSendMessages,
aBufferInfo->m6loSendBuffers);
aInstance->mThreadNetif.GetMeshForwarder().GetReassemblyQueue().GetInfo(aBufferInfo->m6loReassemblyMessages,
aBufferInfo->m6loReassemblyBuffers);
aInstance->mThreadNetif.GetMeshForwarder().GetResolvingQueue().GetInfo(aBufferInfo->mArpMessages,
aBufferInfo->mArpBuffers);
aInstance->mThreadNetif.GetIp6().GetSendQueue().GetInfo(aBufferInfo->mIp6Messages,
aBufferInfo->mIp6Buffers);
aInstance->mThreadNetif.GetIp6().mMpl.GetBufferedMessageSet().GetInfo(aBufferInfo->mMplMessages,
aBufferInfo->mMplBuffers);
aInstance->mThreadNetif.GetMle().GetMessageQueue().GetInfo(aBufferInfo->mMleMessages,
aBufferInfo->mMleBuffers);
aInstance->mThreadNetif.GetCoapClient().GetRequestMessages().GetInfo(aBufferInfo->mCoapClientMessages,
aBufferInfo->mCoapClientBuffers);
}
#if OPENTHREAD_ENABLE_JAM_DETECTION
ThreadError otSetJamDetectionRssiThreshold(otInstance *aInstance, int8_t aRssiThreshold)
{
@@ -1574,112 +1546,6 @@ otMessage otNewIp6Message(otInstance *aInstance, bool aLinkSecurityEnabled)
return message;
}
ThreadError otFreeMessage(otMessage aMessage)
{
return static_cast<Message *>(aMessage)->Free();
}
uint16_t otGetMessageLength(otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
return message->GetLength();
}
ThreadError otSetMessageLength(otMessage aMessage, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->SetLength(aLength);
}
uint16_t otGetMessageOffset(otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
return message->GetOffset();
}
ThreadError otSetMessageOffset(otMessage aMessage, uint16_t aOffset)
{
Message *message = static_cast<Message *>(aMessage);
return message->SetOffset(aOffset);
}
bool otIsMessageLinkSecurityEnabled(otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
return message->IsLinkSecurityEnabled();
}
void otMessageSetDirectTransmission(otMessage aMessage, bool aEnabled)
{
Message *message = static_cast<Message *>(aMessage);
if (aEnabled)
{
message->SetDirectTransmission();
}
else
{
message->ClearDirectTransmission();
}
}
ThreadError otAppendMessage(otMessage aMessage, const void *aBuf, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->Append(aBuf, aLength);
}
int otReadMessage(otMessage aMessage, uint16_t aOffset, void *aBuf, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->Read(aOffset, aLength, aBuf);
}
int otWriteMessage(otMessage aMessage, uint16_t aOffset, const void *aBuf, uint16_t aLength)
{
Message *message = static_cast<Message *>(aMessage);
return message->Write(aOffset, aLength, aBuf);
}
void otMessageQueueInit(otMessageQueue *aQueue)
{
aQueue->mData = NULL;
}
ThreadError otMessageQueueEnqueue(otMessageQueue *aQueue, otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
return queue->Enqueue(*message);
}
ThreadError otMessageQueueDequeue(otMessageQueue *aQueue, otMessage aMessage)
{
Message *message = static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
return queue->Dequeue(*message);
}
otMessage otMessageQueueGetHead(otMessageQueue *aQueue)
{
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
return queue->GetHead();
}
otMessage otMessageQueueGetNext(otMessageQueue *aQueue, otMessage aMessage)
{
Message *next;
Message *message = static_cast<Message *>(aMessage);
MessageQueue *queue = static_cast<MessageQueue *>(aQueue);
VerifyOrExit(message != NULL, next = NULL);
VerifyOrExit(message->GetMessageQueue() == queue, next = NULL);
next = message->GetNext();
exit:
return next;
}
bool otIcmp6IsEchoEnabled(otInstance *aInstance)
{
return aInstance->mIp6.mIcmp.IsEchoEnabled();
+12 -9
View File
@@ -37,6 +37,9 @@
#endif
#include <stdlib.h>
#include "openthread/message.h"
#include <common/code_utils.hpp>
#include <common/debug.hpp>
#include <ncp/ncp.h>
@@ -581,8 +584,8 @@ void NcpBase::HandleDatagramFromStack(otMessage aMessage, void *aContext)
void NcpBase::HandleDatagramFromStack(otMessage aMessage)
{
ThreadError errorCode = kThreadError_None;
bool isSecure = otIsMessageLinkSecurityEnabled(aMessage);
uint16_t length = otGetMessageLength(aMessage);
bool isSecure = otMessageIsLinkSecurityEnabled(aMessage);
uint16_t length = otMessageGetLength(aMessage);
SuccessOrExit(errorCode = OutboundFrameBegin());
@@ -612,7 +615,7 @@ exit:
if (aMessage != NULL)
{
otFreeMessage(aMessage);
otMessageFree(aMessage);
}
if (errorCode != kThreadError_None)
@@ -1454,7 +1457,7 @@ exit:
if (aMessage != NULL)
{
otFreeMessage(aMessage);
otMessageFree(aMessage);
}
return errorCode;
@@ -3082,7 +3085,7 @@ ThreadError NcpBase::GetPropertyHandler_MSG_BUFFER_COUNTERS(uint8_t header, spin
ThreadError errorCode = kThreadError_None;
otBufferInfo bufferInfo;
otGetMessageBufferInfo(mInstance, &bufferInfo);
otMessageGetBufferInfo(mInstance, &bufferInfo);
SuccessOrExit(errorCode = OutboundFrameBegin());
SuccessOrExit(errorCode = OutboundFrameFeedPacked("Cii", header, SPINEL_CMD_PROP_VALUE_IS, key));
@@ -4357,7 +4360,7 @@ ThreadError NcpBase::SetPropertyHandler_STREAM_NET_INSECURE(uint8_t header, spin
(void)meta_len;
(void)parsedLength;
errorCode = otAppendMessage(message, frame_ptr, static_cast<uint16_t>(frame_len));
errorCode = otMessageAppend(message, frame_ptr, static_cast<uint16_t>(frame_len));
}
if (errorCode == kThreadError_None)
@@ -4369,7 +4372,7 @@ ThreadError NcpBase::SetPropertyHandler_STREAM_NET_INSECURE(uint8_t header, spin
}
else if (message)
{
otFreeMessage(message);
otMessageFree(message);
}
if (errorCode == kThreadError_None)
@@ -4430,7 +4433,7 @@ ThreadError NcpBase::SetPropertyHandler_STREAM_NET(uint8_t header, spinel_prop_k
(void)meta_len;
(void)parsedLength;
errorCode = otAppendMessage(message, frame_ptr, static_cast<uint16_t>(frame_len));
errorCode = otMessageAppend(message, frame_ptr, static_cast<uint16_t>(frame_len));
}
if (errorCode == kThreadError_None)
@@ -4439,7 +4442,7 @@ ThreadError NcpBase::SetPropertyHandler_STREAM_NET(uint8_t header, spinel_prop_k
}
else if (message)
{
otFreeMessage(message);
otMessageFree(message);
}
if (errorCode == kThreadError_None)
+1 -1
View File
@@ -40,7 +40,7 @@
#endif
#include <openthread-types.h>
#include <openthread-message.h>
#include "openthread/message.h"
#include <openthread-ip6.h>
#include <common/tasklet.hpp>
#include <ncp/ncp.h>
+7 -7
View File
@@ -81,13 +81,13 @@ void NcpFrameBuffer::Clear(void)
while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != NULL)
{
otMessageQueueDequeue(&mWriteFrameMessageQueue, message);
otFreeMessage(message);
otMessageFree(message);
}
while ((message = otMessageQueueGetHead(&mMessageQueue)) != NULL)
{
otMessageQueueDequeue(&mMessageQueue, message);
otFreeMessage(message);
otMessageFree(message);
}
if (!wasEmpty)
@@ -252,7 +252,7 @@ void NcpFrameBuffer::InFrameDiscard(void)
while ((message = otMessageQueueGetHead(&mWriteFrameMessageQueue)) != NULL)
{
otMessageQueueDequeue(&mWriteFrameMessageQueue, message);
otFreeMessage(message);
otMessageFree(message);
}
}
@@ -433,10 +433,10 @@ ThreadError NcpFrameBuffer::OutFrameFillMessageBuffer(void)
VerifyOrExit(mReadMessage != NULL, error = kThreadError_NotFound);
VerifyOrExit(mReadMessageOffset < otGetMessageLength(mReadMessage), error = kThreadError_NotFound);
VerifyOrExit(mReadMessageOffset < otMessageGetLength(mReadMessage), error = kThreadError_NotFound);
// Read portion of current message from the offset into message buffer.
readLength = otReadMessage(mReadMessage, mReadMessageOffset, mMessageBuffer, sizeof(mMessageBuffer));
readLength = otMessageRead(mReadMessage, mReadMessageOffset, mMessageBuffer, sizeof(mMessageBuffer));
VerifyOrExit(readLength > 0, error = kThreadError_NotFound);
@@ -577,7 +577,7 @@ ThreadError NcpFrameBuffer::OutFrameRemove(void)
if ((message = otMessageQueueGetHead(&mMessageQueue)) != NULL)
{
otMessageQueueDequeue(&mMessageQueue, message);
otFreeMessage(message);
otMessageFree(message);
}
}
@@ -644,7 +644,7 @@ uint16_t NcpFrameBuffer::OutFrameGetLength(void)
if (message != NULL)
{
frameLength += otGetMessageLength(message);
frameLength += otMessageGetLength(message);
}
}
+1 -1
View File
@@ -34,7 +34,7 @@
#define NCP_FRAME_BUFFER_HPP_
#include <openthread-types.h>
#include <openthread-message.h>
#include "openthread/message.h"
namespace Thread {
+1 -1
View File
@@ -29,7 +29,7 @@
#include "test_util.h"
#include <openthread.h>
#include <openthread-message.h>
#include "openthread/message.h"
#include <openthread-ip6.h>
#include <common/debug.hpp>