ncp: Remove deprecated flen encoding. (#1213)

This commit is contained in:
Martin Turon
2017-01-26 17:59:29 -08:00
committed by Jonathan Hui
parent 5ba516f960
commit 9301cf12d7
6 changed files with 4 additions and 347 deletions
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="openthread.configuration.props" />
<PropertyGroup Label="Globals">
@@ -54,7 +54,6 @@
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\..\src\ncp\flen.cpp" />
<ClCompile Include="..\..\src\ncp\hdlc.cpp" />
<ClCompile Include="..\..\src\ncp\ncp_base.cpp" />
<ClCompile Include="..\..\src\ncp\ncp_buffer.cpp" />
@@ -62,7 +61,6 @@
<ClCompile Include="..\..\src\ncp\spinel.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ncp\flen.hpp" />
<ClInclude Include="..\..\src\ncp\hdlc.hpp" />
<ClInclude Include="..\..\src\ncp\ncp_base.hpp" />
<ClInclude Include="..\..\src\ncp\ncp_buffer.hpp" />
@@ -72,4 +70,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
@@ -15,9 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="..\..\src\ncp\flen.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ncp\hdlc.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@@ -35,9 +32,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\src\ncp\flen.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ncp\hdlc.hpp">
<Filter>Header Files</Filter>
</ClInclude>
@@ -54,4 +48,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
</Project>
-2
View File
@@ -73,8 +73,6 @@ if OPENTHREAD_ENABLE_NCP_UART
libopenthread_ncp_a_SOURCES += \
hdlc.cpp \
hdlc.hpp \
flen.cpp \
flen.hpp \
ncp_uart.cpp \
ncp_uart.hpp \
$(NULL)
-170
View File
@@ -1,170 +0,0 @@
/*
* 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 an FLEN encoder and decoder.
*/
#include <common/code_utils.hpp>
#include <ncp/flen.hpp>
namespace Thread {
namespace Flen {
enum
{
kFlagSequence = 0x7e, ///< FLen Flag value
};
ThreadError Encoder::Init(uint8_t *aOutBuf, uint16_t &aOutLength)
{
ThreadError error = kThreadError_None;
mOutBuf = aOutBuf;
VerifyOrExit(aOutLength >= 3, error = kThreadError_NoBufs);
aOutBuf[0] = kFlagSequence;
// Leave the next two bytes empty.
aOutLength = 3;
mOutLength = 0;
exit:
return error;
}
ThreadError Encoder::Encode(uint8_t aInByte, uint8_t *aOutBuf, uint16_t aOutLength)
{
ThreadError error = kThreadError_None;
VerifyOrExit(mOutOffset + 1 < aOutLength, error = kThreadError_NoBufs);
aOutBuf[mOutOffset++] = aInByte;
exit:
return error;
}
ThreadError Encoder::Encode(const uint8_t *aInBuf, uint16_t aInLength, uint8_t *aOutBuf, uint16_t &aOutLength)
{
ThreadError error = kThreadError_None;
mOutOffset = 0;
for (int i = 0; i < aInLength; i++)
{
SuccessOrExit(error = Encode(aInBuf[i], aOutBuf, aOutLength));
}
exit:
aOutLength = mOutOffset;
mOutLength += aOutLength;
return error;
}
ThreadError Encoder::Finalize(uint8_t *aOutBuf, uint16_t &aOutLength)
{
ThreadError error = kThreadError_None;
VerifyOrExit(mOutOffset < aOutLength, error = kThreadError_NoBufs);
mOutBuf[1] = (mOutLength >> 8);
mOutBuf[2] = (mOutLength & 0xFF);
aOutLength = 0;
exit:
(void)aOutBuf;
return error;
}
Decoder::Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, void *aContext):
mState(kStateNeedFlag),
mFrameHandler(aFrameHandler),
mContext(aContext),
mOutBuf(aOutBuf),
mOutOffset(0),
mOutLength(aOutLength),
mReadLength(0)
{
}
void Decoder::Decode(const uint8_t *aInBuf, uint16_t aInLength)
{
uint8_t byte;
for (int i = 0; i < aInLength; i++)
{
byte = aInBuf[i];
switch (mState)
{
case kStateNeedFlag:
if (byte == kFlagSequence)
{
mState = kStateNeedLenH;
mOutOffset = 0;
}
break;
case kStateNeedLenH:
mReadLength = static_cast<uint16_t>(byte << 8);
mState = kStateNeedLenL;
break;
case kStateNeedLenL:
mReadLength += byte;
if (mReadLength > mOutLength)
{
// Too big.
mState = kStateNeedFlag;
}
else
{
mState = kStateNeedData;
}
break;
case kStateNeedData:
mOutBuf[mOutOffset++] = byte;
if (mOutOffset >= mReadLength)
{
mState = kStateNeedFlag;
mFrameHandler(mContext, mOutBuf, mReadLength);
}
break;
}
}
}
} // namespace Flen
} // namespace Thread
-162
View File
@@ -1,162 +0,0 @@
/*
* 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 includes definitions for an FLEN (flag/length) encoder and decoder.
*/
#ifndef FLEN_HPP_
#define FLEN_HPP_
#include <openthread-types.h>
#include <common/message.hpp>
namespace Thread {
/**
* @namespace Thread::Flen
*
* @brief
* This namespace includes definitions for the FLEN encoder and decoder.
*
*/
namespace Flen {
/**
* This class implements the FLEN encoder.
*
*/
class Encoder
{
public:
/**
* This method begins an FLEN frame and puts the initial bytes into @p aOutBuf.
*
* @param[in] aOutBuf A pointer to the output buffer.
* @param[inout] aOutLength On entry, the output buffer size; On exit, the output length.
*
* @retval kThreadError_None Successfully started the FLEN frame.
* @retval kThreadError_NoBufs Insufficient buffer space available to start the FLEN frame.
*
*/
ThreadError Init(uint8_t *aOutBuf, uint16_t &aOutLength);
/**
* This method encodes the frame.
*
* @param[in] aInBuf A pointer to the input buffer.
* @param[in] aInLength The number of bytes in @p aInBuf to encode.
* @param[out] aOutBuf A pointer to the output buffer.
* @param[out] aOutLength On exit, the number of bytes placed in @p aOutBuf.
*
* @retval kThreadError_None Successfully encoded the FLEN frame.
* @retval kThreadError_NoBufs Insufficient buffer space available to encode the FLEN frame.
*
*/
ThreadError Encode(const uint8_t *aInBuf, uint16_t aInLength, uint8_t *aOutBuf, uint16_t &aOutLength);
/**
* This method ends an FLEN frame and puts the initial bytes into @p aOutBuf.
*
* @param[in] aOutBuf A pointer to the output buffer.
* @param[inout] aOutLength On entry, the output buffer size; On exit, the output length.
*
* @retval kThreadError_None Successfully ended the FLEN frame.
* @retval kThreadError_NoBufs Insufficient buffer space available to end the FLEN frame.
*
*/
ThreadError Finalize(uint8_t *aOutBuf, uint16_t &aOutLength);
private:
ThreadError Encode(uint8_t aInByte, uint8_t *aOutBuf, uint16_t aOutLength);
uint8_t *mOutBuf;
uint16_t mOutOffset;
uint16_t mOutLength;
};
/**
* This class implements the FLEN decoder.
*
*/
class Decoder
{
public:
/**
* This function pointer is called when a complete frame has been formed.
*
* @param[in] aContext A pointer to arbitrary context information.
* @param[in] aFrame A pointer to the frame.
* @param[in] aFrameLength The frame length in bytes.
*
*/
typedef void (*FrameHandler)(void *aContext, uint8_t *aFrame, uint16_t aFrameLength);
/**
* This constructor initializes the decoder.
*
* @param[in] aOutBuf A pointer to the output buffer.
* @param[in] aOutLength Size of the output buffer in bytes.
* @param[in] aFrameHandler A pointer to a function that is called when a complete frame is received.
* @param[in] aContext A pointer to arbitrary context information.
*
*/
Decoder(uint8_t *aOutBuf, uint16_t aOutLength, FrameHandler aFrameHandler, void *aContext);
/**
* This method streams bytes into the decoder.
*
* @param[in] aInBuf A pointer to the input buffer.
* @param[in] aInLength The number of bytes in @p aInBuf.
*
*/
void Decode(const uint8_t *aInBuf, uint16_t aInLength);
private:
enum State
{
kStateNeedFlag = 0,
kStateNeedLenH,
kStateNeedLenL,
kStateNeedData,
};
State mState;
FrameHandler mFrameHandler;
void *mContext;
uint8_t *mOutBuf;
uint16_t mOutOffset;
uint16_t mOutLength;
uint16_t mReadLength;
};
} // namespace Flen
} // namespace Thread
#endif // FLEN_HPP_
-1
View File
@@ -40,7 +40,6 @@
#endif
#include <ncp/ncp_base.hpp>
#include <ncp/flen.hpp>
#include <ncp/hdlc.hpp>
#include <ncp/ncp_buffer.hpp>